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