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