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