2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 04/24/2005 *
4 * =================== Last change: 05/12/2005 *
6 * -------------------------------------------------------------------- *
7 * File : what-edit_sponsor.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Edit sponsor account *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sponsorenaccount aendern *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 if ((isGetRequestParameterSet('id')) && (isGetRequestParameterSet('mode'))) {
49 // Check for selected sponsor
50 $result_main = SQL_QUERY_ESC("SELECT
51 `company`, `position`, `gender`, `surname`, `family`,
52 `street_nr1`, `street_nr2`, `zip`, `city`, `country`,
53 `phone`, `fax`, `cell`, `email`, `url`, `tax_ident`,
54 `receive_warnings`, `warning_interval`
56 `{?_MYSQL_PREFIX?}_sponsor_data`
60 array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
61 if (SQL_NUMROWS($result_main) == 1) {
62 // Load sponsor details
63 $content = SQL_FETCHARRAY($result_main);
65 // Prepare all data for the template
67 $content['id'] = bigintval(getRequestParameter('id'));
70 foreach (array('m', 'f', 'c') as $gender) {
71 $content['gender_' . $gender] = '';
74 // Check for gender selection
75 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
77 // Warning because low points
78 $content['receive_warnings'] = addSelectionBox('yn', $content['receive_warnings'], 'receive_warning');
79 $content['warning_interval'] = createTimeSelections($content['warning_interval'], 'warning_interval', 'MWDh');
81 // Init variables here
82 $TPL = sprintf("admin_edit_sponsor_%s", getRequestParameter('mode'));
86 if ((isFormSent()) || (isFormSent('edit'))) {
87 // Perform action on mode
88 switch (getRequestParameter('mode')) {
89 case 'add_points': // Add points
90 if (bigintval(postRequestParameter('points')) > 0) {
91 // Replace german decimal comma with computer's decimal dot
92 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
94 // Add points to account
95 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`='%s' LIMIT 1",
96 array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
98 // Remember points /reason for the template
99 $content['points'] = $points;
100 $content['reason'] = secureString(postRequestParameter('reason'));
103 $message = loadEmailTemplate('sponsor_add_points', $content);
104 sendEmail($content['email'], '{--ADMIN_SPONSOR_ADD_POINTS_SUBJECT--}', $message);
105 $message = '{--ADMIN_SPONSOR_POINTS_ADDED--}';
107 // No points entered to add!
108 $message = '{--ADMIN_SPONSPOR_NO_POINTS_TO_ADD--}';
112 case 'sub_points': // Subtract points
113 if (bigintval(postRequestParameter('points')) > 0) {
114 // Replace german decimal comma with computer's decimal dot
115 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
117 // Add points to account
118 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`='%s' LIMIT 1",
119 array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
121 // Remember points /reason for the template
122 $content['points'] = $points;
123 $content['reason'] = secureString(postRequestParameter('reason'));
126 $message = loadEmailTemplate('sponsor_sub_points', $content);
127 sendEmail($content['email'], '{--ADMIN_SPONSOR_SUB_POINTS_SUBJECT--}', $message);
128 $message = '{--ADMIN_SPONSOR_POINTS_SUBTRACTED--}';
130 // No points entered to add!
131 $message = '{--ADMIN_SPONSPOR_NO_POINTS_TO_SUBTRACT--}';
135 case 'edit': // Edit sponsor account
137 if ((postRequestParameter('pass1') != postRequestParameter('pass2')) || ((!isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass1')))) {
139 unsetPostRequestParameter('pass1');
140 unsetPostRequestParameter('pass2');
144 // Convert time selection
145 $DATA = array(); $id = 'warning_interval_ye'; $skip = false;
146 convertSelectionsToTimestamp(postRequestArray(), $DATA, $id, $skip);
149 handlSponsorRequest(postRequestArray());
151 // Convert some data for the email template
152 postRequestParameter('gender' , translateGender(postRequestParameter('gender')));
153 postRequestParameter('warning_interval', createFancyTime(postRequestParameter('warning_interval')));
155 if ($PASS === false) setPostRequestParameter('pass1', '{--SPONSOR_PASS_UNCHANGED--}');
157 // Load email template and send the mail away
158 $message = loadEmailTemplate('admin_sponsor_edit', postRequestArray(), false);
159 sendEmail(postRequestParameter('email'), '{--ADMIN_SPONSOR_EDIT_SUBJECT--}', $message);
162 default: // Unknown mode
163 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mode %s detected.", getRequestParameter('mode')));
164 $message = getMaskedMessage('ADMIN_SPONSOR_INVALID_MODE', getRequestParameter('mode'));
168 if (!empty($message)) {
170 loadTemplate('admin_settings_saved', false, $message);
172 } elseif (isFileReadable(sprintf("%stemplates/%s/html/admin/%s.tpl", getPath(), getLanguage(), $TPL))) {
173 // Create mailto link
174 $content['contact'] = '<a href="' . generateEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
176 // Load mode template
179 // Template not found!
180 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_MODUS_TPL_404', getRequestParameter('mode')));
183 // Sponsor not found!
184 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
188 SQL_FREERESULT($result_main);
190 // Not called by what-list_sponsor.php
191 loadTemplate('admin_settings_saved', false, '{--ADMIN_CALL_NOT_DIRECTLY--}');