More use of REVERT_COMMA() fixes problems
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software. You can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License.       *
21  *                                                                      *
22  * This program is distributed in the hope that it will be useful,      *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
25  * GNU General Public License for more details.                         *
26  *                                                                      *
27  * You should have received a copy of the GNU General Public License    *
28  * along with this program; if not, write to the Free Software          *
29  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
30  * MA  02110-1301  USA                                                  *
31  ************************************************************************/
32
33 // Some security stuff...
34 if ((!defined('__SECURITY')) || (!is_admin())) {
35         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
36         require($INC);
37 }
38
39 // Add description as navigation point
40 ADD_DESCR("admin", basename(__FILE__));
41
42 if ((!empty($_GET['id'])) && (!empty($_GET['mode']))) {
43         // Check for selected sponsor
44         $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",
45          array(bigintval($_GET['id'])), __FILE__, __LINE__);
46         if (SQL_NUMROWS($result) == 1) {
47                 // Load sponsor details
48                 $DATA = SQL_FETCHARRAY($result);
49                 SQL_FREERESULT($result);
50
51                 // Prepare all data for the template
52                 //  Sponsor's ID
53                 define('__SPONSOR_ID' , bigintval($_GET['id']));
54                 //  Company's data
55                 define('__COMPANY'    , $DATA['company']);
56                 define('__POSITION'   , $DATA['position']);
57                 define('__TAX_IDENT'  , $DATA['tax_ident']);
58                 //  Personal data
59                 switch ($DATA['gender'])
60                 {
61                 case "M":
62                         define('__GENDER_M', " selected=\"selected\"");
63                         define('__GENDER_F', "");
64                         define('__GENDER_C', "");
65                         break;
66
67                 case "F":
68                         define('__GENDER_M', "");
69                         define('__GENDER_F', " selected=\"selected\"");
70                         define('__GENDER_C', "");
71                         break;
72
73                 case "C":
74                         define('__GENDER_M', "");
75                         define('__GENDER_F', "");
76                         define('__GENDER_C', " selected=\"selected\"");
77                         break;
78                 }
79                 define('__SURNAME'    , $DATA['surname']);
80                 define('__FAMILY'     , $DATA['family']);
81                 define('__STREET1'    , $DATA['street_nr1']);
82                 define('__STREET2'    , $DATA['street_nr2']);
83                 define('__ZIP'        , $DATA['zip']);
84                 define('__CITY'       , $DATA['city']);
85                 define('__COUNTRY'    , $DATA['country']);
86                 //  Contact data
87                 define('__PHONE'      , $DATA['phone']);
88                 define('__FAX'        , $DATA['fax']);
89                 define('__CELL'       , $DATA['cell']);
90                 define('__EMAIL'      , $DATA['email']);
91                 define('__URL'        , $DATA['url']);
92                 //  Warning because low points
93                 define('__REC_WARNING', ADD_SELECTION("yn", $DATA['receive_warnings'], "receive_warning"));
94                 define('__INTERVAL'   , CREATE_TIME_SELECTIONS($DATA['warning_interval'], "warning_interval", "MWDh"));
95
96                 // Init variables here
97                 $TPL = sprintf("admin_edit_sponsor_%s", SQL_ESCAPE($_GET['mode']));
98                 $SQLs = array();
99
100                 // Sponsor was found
101                 if ((isset($_POST['ok'])) || (isset($_POST['edit']))) {
102                         // Perform action on mode
103                         switch ($_GET['mode'])
104                         {
105                         case "add_points": // Add points
106                                 if (strval($_POST['points']) > 0) {
107                                         // Replace german decimal comma with computer's decimal dot
108                                         $POINTS = strval(REVERT_COMMA($_POST['points']));
109
110                                         // Add points to account
111                                         $result_add = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET points_amount=points_amount+%s WHERE id='%s' LIMIT 1",
112                                          array($POINTS, bigintval($_GET['id'])), __FILE__, __LINE__);
113
114                                         // Remember points /reason for the template
115                                         define('__POINTS' , TRANSLATE_COMMA($POINTS));
116                                         define('__REASON' , $_POST['reason']);
117
118                                         // Send email
119                                         $msg = LOAD_EMAIL_TEMPLATE("sponsor_add_points", $_POST['reason'], true);
120                                         SEND_EMAIL(__EMAIL, SPONSOR_ADMIN_ADD_POINTS, $msg);
121                                         $MSG = ADMIN_SPONSOR_POINTS_ADDED;
122                                 } else {
123                                         // No points entered to add!
124                                         $MSG = ADMIN_SPONSPOR_NO_POINTS_TO_ADD;
125                                 }
126                                 break;
127
128                         case "sub_points": // Subtract points
129                                 if (strval($_POST['points']) > 0) {
130                                         // Replace german decimal comma with computer's decimal dot
131                                         $POINTS = strval(REVERT_COMMA($_POST['points']));
132
133                                         // Add points to account
134                                         $result_add = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_sponsor_data SET points_used=points_used+%s WHERE id='%s' LIMIT 1",
135                                          array($POINTS, bigintval($_GET['id'])), __FILE__, __LINE__);
136
137                                         // Remember points /reason for the template
138                                         define('__POINTS' , TRANSLATE_COMMA($POINTS));
139                                         define('__REASON' , $_POST['reason']);
140
141                                         // Send email
142                                         $msg = LOAD_EMAIL_TEMPLATE("sponsor_sub_points", $_POST['reason'], true);
143                                         SEND_EMAIL(__EMAIL, SPONSOR_ADMIN_SUB_POINTS, $msg);
144                                         $MSG = ADMIN_SPONSOR_POINTS_SUBTRACTED;
145                                 } else {
146                                         // No points entered to add!
147                                         $MSG = ADMIN_SPONSPOR_NO_POINTS_TO_SUBTRACT;
148                                 }
149                                 break;
150
151                         case "edit": // Edit sponsor account
152                                 $PASS = true;
153                                 if (($_POST['pass1'] != $_POST['pass2']) || ((empty($_POST['pass1'])) && (empty($_POST['pass1'])))) {
154                                         // Remove passwords
155                                         unset($_POST['pass1']);
156                                         unset($_POST['pass2']);
157                                         $PASS = false;
158                                 }
159                                 SPONSOR_HANDLE_SPONSOR($_POST);
160
161                                 // Convert some data for the email template
162                                 $_POST['gender'] = TRANSLATE_GENDER($_POST['gender']);
163                                 $_POST['warning_interval'] = CREATE_FANCY_TIME($_POST['warning_interval']);
164                                 if (!$PASS) $_POST['pass1'] = SPONSOR_PASS_UNCHANGED;
165
166                                 // Load email template and send the mail away
167                                 $msg = LOAD_EMAIL_TEMPLATE("admin_sponsor_edit", $_POST, false);
168                                 SEND_EMAIL($_POST['email'], SPONSOR_ADMIN_EDIT_SUBJECT, $msg);
169                                 break;
170
171                         default: // Unknown mode
172                                 $MSG = ADMIN_INVALID_MODE_1.SQL_ESCAPE($_GET['mode']).ADMIN_INVALID_MODE_2;
173                                 break;
174                         }
175
176                         if (!empty($MSG)) {
177                                 // Output message
178                                 LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
179                         } // END - if
180                 } elseif (FILE_READABLE(sprintf("%stemplates/%s/html/admin/%s.tpl", PATH, GET_LANGUAGE(), $TPL))) {
181                         // Create mailto link
182                         define('__SPONSOR_VALUE', "<A href=\"mailto:".__EMAIL."\">".__SURNAME." ".__FAMILY."</A>");
183
184                         // Load mode template
185                         LOAD_TEMPLATE($TPL);
186                 } else {
187                         // Template not found!
188                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_TPL_404_1.SQL_ESCAPE($_GET['mode']).ADMIN_TPL_404_2);
189                 }
190         } else {
191                 // Sponsor not found!
192                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_SPONSOR_404_1.bigintval($_GET['id']).ADMIN_SPONSOR_404_2);
193         }
194 } else {
195         // Not called by what-list_sponsor.php
196         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_CALL_NOT_DIRECTLY);
197 }
198
199 //
200 ?>