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