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