9362e793ffbd304659ab10c47cc9adf413d7bffb
[mailer.git] / inc / modules / admin / what-edit_sponsor.php
1 <?php
2 /************************************************************************
3  * M-XChange v0.2.1                                   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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 if ((REQUEST_ISSET_GET('id')) && (REQUEST_ISSET_GET('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(REQUEST_GET('id'))), __FILE__, __LINE__);
61         if (SQL_NUMROWS($result_main) == 1) {
62                 // Load sponsor details
63                 $DATA = SQL_FETCHARRAY($result_main);
64
65                 // Prepare all data for the template
66                 //  Sponsor's ID
67                 define('__SPONSOR_ID' , bigintval(REQUEST_GET('id')));
68
69                 //  Company's data
70                 define('__COMPANY'    , $DATA['company']);
71                 define('__POSITION'   , $DATA['position']);
72                 define('__TAX_IDENT'  , $DATA['tax_ident']);
73
74                 //  Personal data
75                 switch ($DATA['gender']) {
76                         case 'M':
77                                 define('__GENDER_M', ' selected="selected"');
78                                 define('__GENDER_F', '');
79                                 define('__GENDER_C', '');
80                                 break;
81
82                         case 'F':
83                                 define('__GENDER_M', '');
84                                 define('__GENDER_F', ' selected="selected"');
85                                 define('__GENDER_C', '');
86                                 break;
87
88                         case 'C':
89                                 define('__GENDER_M', '');
90                                 define('__GENDER_F', '');
91                                 define('__GENDER_C', ' selected="selected"');
92                                 break;
93                 }
94                 define('__SURNAME'    , $DATA['surname']);
95                 define('__FAMILY'     , $DATA['family']);
96                 define('__STREET1'    , $DATA['street_nr1']);
97                 define('__STREET2'    , $DATA['street_nr2']);
98                 define('__ZIP'        , $DATA['zip']);
99                 define('__CITY'       , $DATA['city']);
100                 define('__COUNTRY'    , $DATA['country']);
101                 //  Contact data
102                 define('__PHONE'      , $DATA['phone']);
103                 define('__FAX'        , $DATA['fax']);
104                 define('__CELL'       , $DATA['cell']);
105                 define('__EMAIL'      , $DATA['email']);
106                 define('__URL'        , $DATA['url']);
107
108                 //  Warning because low points
109                 define('__REC_WARNING', ADD_SELECTION('yn', $DATA['receive_warnings'], 'receive_warning'));
110                 define('__INTERVAL'   , createTimeSelections($DATA['warning_interval'], 'warning_interval', 'MWDh'));
111
112                 // Init variables here
113                 $TPL = sprintf("admin_edit_sponsor_%s", REQUEST_GET('mode'));
114                 INIT_SQLS();
115
116                 // Sponsor was found
117                 if ((isFormSent()) || (REQUEST_ISSET_POST('edit'))) {
118                         // Perform action on mode
119                         switch (REQUEST_GET('mode')) {
120                                 case 'add_points': // Add points
121                                         if (strval(REQUEST_POST('points')) > 0) {
122                                                 // Replace german decimal comma with computer's decimal dot
123                                                 $POINTS = strval(convertCommaToDot(REQUEST_POST('points')));
124
125                                                 // Add points to account
126                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`='%s' LIMIT 1",
127                                                         array($POINTS, bigintval(REQUEST_GET('id'))), __FILE__, __LINE__);
128
129                                                 // Remember points /reason for the template
130                                                 define('__POINTS' , translateComma($POINTS));
131                                                 define('__REASON' , REQUEST_POST('reason'));
132
133                                                 // Send email
134                                                 $message = LOAD_EMAIL_TEMPLATE('sponsor_add_points', REQUEST_POST('reason'), true);
135                                                 sendEmail(constant('__EMAIL'), getMessage('ADMIN_SPONSOR_ADD_POINTS_SUBJ'), $message);
136                                                 $message = getMessage('ADMIN_SPONSOR_POINTS_ADDED');
137                                         } else {
138                                                 // No points entered to add!
139                                                 $message = getMessage('ADMIN_SPONSPOR_NO_POINTS_TO_ADD');
140                                         }
141                                         break;
142
143                                 case 'sub_points': // Subtract points
144                                         if (strval(REQUEST_POST('points')) > 0) {
145                                                 // Replace german decimal comma with computer's decimal dot
146                                                 $POINTS = strval(convertCommaToDot(REQUEST_POST('points')));
147
148                                                 // Add points to account
149                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`='%s' LIMIT 1",
150                                                         array($POINTS, bigintval(REQUEST_GET('id'))), __FILE__, __LINE__);
151
152                                                 // Remember points /reason for the template
153                                                 define('__POINTS' , translateComma($POINTS));
154                                                 define('__REASON' , REQUEST_POST('reason'));
155
156                                                 // Send email
157                                                 $message = LOAD_EMAIL_TEMPLATE('sponsor_sub_points', REQUEST_POST('reason'), true);
158                                                 sendEmail(constant('__EMAIL'), getMessage('ADMIN_SPONSOR_SUB_POINTS_SUBJ'), $message);
159                                                 $message = getMessage('ADMIN_SPONSOR_POINTS_SUBTRACTED');
160                                         } else {
161                                                 // No points entered to add!
162                                                 $message = getMessage('ADMIN_SPONSPOR_NO_POINTS_TO_SUBTRACT');
163                                         }
164                                         break;
165
166                                 case 'edit': // Edit sponsor account
167                                         $PASS = true;
168                                         if ((REQUEST_POST('pass1') != REQUEST_POST('pass2')) || ((!REQUEST_ISSET_POST('pass1')) && (!REQUEST_ISSET_POST('pass1')))) {
169                                                 // Remove passwords
170                                                 REQUEST_UNSET_POST('pass1');
171                                                 REQUEST_UNSET_POST('pass2');
172                                                 $PASS = false;
173                                         } // END - if
174
175                                         // Convert time selection
176                                         $DATA = array(); $id = 'warning_interval_ye'; $skip = false;
177                                         convertSelectionsToTimestamp(REQUEST_POST_ARRAY(), $DATA, $id, $skip);
178
179                                         // Save the sponsor
180                                         SPONSOR_HANDLE_SPONSOR(REQUEST_POST_ARRAY());
181
182                                         // Convert some data for the email template
183                                         REQUEST_POST('gender'          , translateGender(REQUEST_POST('gender')));
184                                         REQUEST_POST('warning_interval', createFancyTime(REQUEST_POST('warning_interval')));
185
186                                         if ($PASS === false) REQUEST_SET_POST('pass1', getMessage('SPONSOR_PASS_UNCHANGED'));
187
188                                         // Load email template and send the mail away
189                                         $message = LOAD_EMAIL_TEMPLATE('admin_sponsor_edit', REQUEST_POST_ARRAY(), false);
190                                         sendEmail(REQUEST_POST('email'), getMessage('ADMIN_SPONSOR_EDIT_SUBJECT'), $message);
191                                         break;
192
193                                 default: // Unknown mode
194                                         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown mode %s detected.", REQUEST_GET('mode')));
195                                         $message = sprintf(getMessage('ADMIN_SPONSOR_INVALID_MODE'), REQUEST_GET('mode'));
196                                         break;
197                         }
198
199                         if (!empty($message)) {
200                                 // Output message
201                                 LOAD_TEMPLATE('admin_settings_saved', false, $message);
202                         } // END - if
203                 } elseif (isFileReadable(sprintf("%stemplates/%s/html/admin/%s.tpl", constant('PATH'), getLanguage(), $TPL))) {
204                         // Create mailto link
205                         define('__SPONSOR_VALUE', "<a href=\"" . generateEmailLink(constant('__EMAIL'), 'sponsor_data') . "\">{!__SURNAME!} {!__FAMILY!}</a>");
206
207                         // Load mode template
208                         LOAD_TEMPLATE($TPL);
209                 } else {
210                         // Template not found!
211                         LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_MODUS_TPL_404'), REQUEST_GET('mode')));
212                 }
213         } else {
214                 // Sponsor not found!
215                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_SPONSOR_404'), bigintval(REQUEST_GET('id'))));
216         }
217
218         // Free result
219         SQL_FREERESULT($result_main);
220 } else {
221         // Not called by what-list_sponsor.php
222         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_CALL_NOT_DIRECTLY'));
223 }
224
225 //
226 ?>