]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-edit_sponsor.php
Introduced template call-back function 'doTemplateAdminListUserTitle':
[mailer.git] / inc / modules / admin / what-edit_sponsor.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/24/2005 *
4  * ===================                          Last change: 05/12/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-edit_sponsor.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit sponsor account                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sponsorenaccount aendern                         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if ((isGetRequestParameterSet('id')) && (isGetRequestParameterSet('mode'))) {
47         // Check for selected sponsor
48         $result_main = SQL_QUERY_ESC("SELECT
49         `id`, `company`, `position`, `gender`, `surname`, `family`,
50         `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
51         `phone`, `fax`, `cell`, `email`, `url`, `tax_ident`,
52         `receive_warnings`, `warning_interval`
53 FROM
54         `{?_MYSQL_PREFIX?}_sponsor_data`
55 WHERE
56         `id`=%s
57 LIMIT 1",
58                 array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
59         if (SQL_NUMROWS($result_main) == 1) {
60                 // Load sponsor details
61                 $content = SQL_FETCHARRAY($result_main);
62
63                 // Prepare all data for the template
64                 // Init gender
65                 foreach (array('m', 'f', 'c') as $gender) {
66                         $content['gender_' . $gender] = '';
67                 } // END - foreach
68
69                 // Check for gender selection
70                 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
71
72                 //  Warning because low points
73                 $content['receive_warnings'] = addSelectionBox('yn', $content['receive_warnings'], 'receive_warning');
74                 $content['warning_interval'] = createTimeSelections($content['warning_interval'], 'warning_interval', 'MWDh');
75
76                 // Init variables here
77                 $TPL = sprintf("admin_edit_sponsor_%s", getRequestParameter('mode'));
78                 initSqls();
79
80                 // Sponsor was found
81                 if ((isFormSent()) || (isFormSent('edit'))) {
82                         // Perform action on mode
83                         switch (getRequestParameter('mode')) {
84                                 case 'add_points': // Add points
85                                         if (bigintval(postRequestParameter('points')) > 0) {
86                                                 // Replace german decimal comma with computer's decimal dot
87                                                 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
88
89                                                 // Add points to account
90                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`=%s LIMIT 1",
91                                                         array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
92
93                                                 // Remember points /reason for the template
94                                                 $content['points'] = $points;
95                                                 $content['reason'] = secureString(postRequestParameter('reason'));
96
97                                                 // Send email
98                                                 $message = loadEmailTemplate('sponsor_add_points', $content);
99                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_ADD_POINTS_SUBJECT--}', $message);
100                                                 $message = '{--ADMIN_SPONSOR_POINTS_ADDED--}';
101                                         } else {
102                                                 // No points entered to add!
103                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_ADD--}';
104                                         }
105                                         break;
106
107                                 case 'sub_points': // Subtract points
108                                         if (bigintval(postRequestParameter('points')) > 0) {
109                                                 // Replace german decimal comma with computer's decimal dot
110                                                 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
111
112                                                 // Add points to account
113                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`=%s LIMIT 1",
114                                                         array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
115
116                                                 // Remember points /reason for the template
117                                                 $content['points'] = $points;
118                                                 $content['reason'] = secureString(postRequestParameter('reason'));
119
120                                                 // Send email
121                                                 $message = loadEmailTemplate('sponsor_sub_points', $content);
122                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_SUB_POINTS_SUBJECT--}', $message);
123                                                 $message = '{--ADMIN_SPONSOR_POINTS_SUBTRACTED--}';
124                                         } else {
125                                                 // No points entered to add!
126                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_SUBTRACT--}';
127                                         }
128                                         break;
129
130                                 case 'edit': // Edit sponsor account
131                                         $PASS = true;
132                                         if ((postRequestParameter('pass1') != postRequestParameter('pass2')) || ((!isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass1')))) {
133                                                 // Remove passwords
134                                                 unsetPostRequestParameter('pass1');
135                                                 unsetPostRequestParameter('pass2');
136                                                 $PASS = false;
137                                         } // END - if
138
139                                         // Convert time selection
140                                         $DATA = array(); $id = 'warning_interval_ye'; $skip = false;
141                                         convertSelectionsToTimestamp(postRequestArray(), $DATA, $id, $skip);
142
143                                         // Save the sponsor
144                                         handleSponsorRequest(postRequestArray());
145
146                                         // Convert some data for the email template
147                                         postRequestParameter('gender'          , '{%pipe,translateComma=' . postRequestParameter('gender') . '%}');
148                                         postRequestParameter('warning_interval', '{%pipe,createFancyTime=' . postRequestParameter('warning_interval') . '%}');
149
150                                         if ($PASS === false) setPostRequestParameter('pass1', '{--SPONSOR_PASS_UNCHANGED--}');
151
152                                         // Load email template and send the mail away
153                                         $message = loadEmailTemplate('admin_sponsor_edit', postRequestArray(), false);
154                                         sendEmail(postRequestParameter('email'), '{--ADMIN_SPONSOR_EDIT_SUBJECT--}', $message);
155                                         break;
156
157                                 default: // Unknown mode
158                                         logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mode %s detected.", getRequestParameter('mode')));
159                                         $message = getMaskedMessage('ADMIN_SPONSOR_INVALID_MODE', getRequestParameter('mode'));
160                                         break;
161                         }
162
163                         if (!empty($message)) {
164                                 // Output message
165                                 displayMessage($message);
166                         } // END - if
167                 } elseif (isFileReadable(sprintf("%stemplates/%s/html/admin/%s.tpl", getPath(), getLanguage(), $TPL))) {
168                         // Create mailto link
169                         $content['contact'] = '<a href="' . generateSponsorEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
170
171                         // Load mode template
172                         loadTemplate($TPL, false, $content);
173                 } else {
174                         // Template not found
175                         displayMessage(getMaskedMessage('ADMIN_SPONSOR_MODUS_TPL_404', getRequestParameter('mode')));
176                 }
177         } else {
178                 // Sponsor not found
179                 displayMessage(getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
180         }
181
182         // Free result
183         SQL_FREERESULT($result_main);
184 } else {
185         // Not called by what-list_sponsor.php
186         displayMessage('{--ADMIN_CALL_NOT_DIRECTLY--}');
187 }
188
189 // [EOF]
190 ?>