Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[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 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://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         exit();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if ((isGetRequestElementSet('id')) && (isGetRequestElementSet('do'))) {
47         // Check for selected sponsor
48         $result_main = sqlQueryEscaped("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 (sqlNumRows($result_main) == 1) {
60                 // Load sponsor details
61                 $content = sqlFetchArray($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('do'));
69                 initSqls();
70
71                 // Sponsor was found
72                 if ((isFormSent()) || (isFormSent('edit'))) {
73                         // Perform action on mode
74                         switch (getRequestElement('do')) {
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                                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`=%s LIMIT 1",
82                                                         array(
83                                                                 $points,
84                                                                 bigintval(getRequestElement('id'))
85                                                         ), __FILE__, __LINE__
86                                                 );
87
88                                                 // Remember points /reason for the template
89                                                 $content['points'] = $points;
90                                                 $content['reason'] = postRequestElement('reason');
91
92                                                 // Send email
93                                                 $message = loadEmailTemplate('sponsor_add_points', $content);
94                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_ADD_POINTS_SUBJECT--}', $message);
95                                                 $message = '{--ADMIN_SPONSOR_POINTS_ADDED--}';
96                                         } else {
97                                                 // No points entered to add!
98                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_ADD--}';
99                                         }
100                                         break;
101
102                                 case 'sub_points': // Subtract points
103                                         if (bigintval(postRequestElement('points')) > 0) {
104                                                 // Replace german decimal comma with computer's decimal dot
105                                                 $points = bigintval(convertCommaToDot(postRequestElement('points')));
106
107                                                 // Add points to account
108                                                 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`=%s LIMIT 1",
109                                                         array($points, bigintval(getRequestElement('id'))), __FILE__, __LINE__);
110
111                                                 // Remember points /reason for the template
112                                                 $content['points'] = $points;
113                                                 $content['reason'] = postRequestElement('reason');
114
115                                                 // Send email
116                                                 $message = loadEmailTemplate('sponsor_sub_points', $content);
117                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_SUB_POINTS_SUBJECT--}', $message);
118                                                 $message = '{--ADMIN_SPONSOR_POINTS_SUBTRACTED--}';
119                                         } else {
120                                                 // No points entered to add!
121                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_SUBTRACT--}';
122                                         }
123                                         break;
124
125                                 case 'edit': // Edit sponsor account
126                                         $PASS = TRUE;
127                                         if ((postRequestElement('password1') != postRequestElement('password2')) || ((!isPostRequestElementSet('password1')) && (!isPostRequestElementSet('password1')))) {
128                                                 // Remove passwords
129                                                 unsetPostRequestElement('password1');
130                                                 unsetPostRequestElement('password2');
131                                                 $PASS = FALSE;
132                                         } // END - if
133
134                                         // Convert time selection
135                                         convertSelectionsToEpocheTimeInPostData('warning_interval_ye');
136
137                                         // Save the sponsor
138                                         handleSponsorRequest(postRequestArray());
139
140                                         // Convert some data for the email template
141                                         postRequestElement('gender'          , '{%pipe,translateGender=' . postRequestElement('gender') . '%}');
142                                         postRequestElement('warning_interval', '{%pipe,createFancyTime=' . postRequestElement('warning_interval') . '%}');
143
144                                         if ($PASS === FALSE) setPostRequestElement('password1', '{--SPONSOR_PASS_UNCHANGED--}');
145
146                                         // Load email template and send the mail away
147                                         $message = loadEmailTemplate('admin_sponsor_edit', postRequestArray(), FALSE);
148                                         sendEmail(postRequestElement('email'), '{--ADMIN_SPONSOR_EDIT_SUBJECT--}', $message);
149                                         break;
150
151                                 default: // Unknown mode
152                                         logDebugMessage(__FILE__, __LINE__, sprintf('Unknown mode %s detected.', getRequestElement('do')));
153                                         $message = '{%message,ADMIN_SPONSOR_INVALID_MODE=' . getRequestElement('do') . '%}';
154                                         break;
155                         } // END - switch
156
157                         if (!empty($message)) {
158                                 // Output message
159                                 displayMessage($message);
160                         } // END - if
161                 } elseif (isFileReadable(sprintf('%s/admin/%s.tpl', getTemplateBasePath('html'), $TPL))) {
162                         // Create mailto link
163                         $content['contact'] = '<a href="' . generateSponsorEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
164
165                         // Load mode template
166                         loadTemplate($TPL, FALSE, $content);
167                 } else {
168                         // Template not found
169                         displayMessage('{%message,ADMIN_SPONSOR_MODUS_TPL_404', getRequestElement('do') . '%}');
170                 }
171         } else {
172                 // Sponsor not found
173                 displayMessage('{%message,ADMIN_SPONSOR_404=' . bigintval(getRequestElement('id')) . '%}');
174         }
175
176         // Free result
177         sqlFreeResult($result_main);
178 } else {
179         // Not called by what-list_sponsor.php
180         displayMessage('{--ADMIN_CALL_NOT_DIRECTLY--}');
181 }
182
183 // [EOF]
184 ?>