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 `id`, `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 foreach (array('m', 'f', 'c') as $gender) {
68 $content['gender_' . $gender] = '';
71 // Check for gender selection
72 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
74 // Warning because low points
75 $content['receive_warnings'] = addSelectionBox('yn', $content['receive_warnings'], 'receive_warning');
76 $content['warning_interval'] = createTimeSelections($content['warning_interval'], 'warning_interval', 'MWDh');
78 // Init variables here
79 $TPL = sprintf("admin_edit_sponsor_%s", getRequestParameter('mode'));
83 if ((isFormSent()) || (isFormSent('edit'))) {
84 // Perform action on mode
85 switch (getRequestParameter('mode')) {
86 case 'add_points': // Add points
87 if (bigintval(postRequestParameter('points')) > 0) {
88 // Replace german decimal comma with computer's decimal dot
89 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
91 // Add points to account
92 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_amount`=`points_amount`+%s WHERE `id`=%s LIMIT 1",
93 array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
95 // Remember points /reason for the template
96 $content['points'] = $points;
97 $content['reason'] = secureString(postRequestParameter('reason'));
100 $message = loadEmailTemplate('sponsor_add_points', $content);
101 sendEmail($content['email'], '{--ADMIN_SPONSOR_ADD_POINTS_SUBJECT--}', $message);
102 $message = '{--ADMIN_SPONSOR_POINTS_ADDED--}';
104 // No points entered to add!
105 $message = '{--ADMIN_SPONSPOR_NO_POINTS_TO_ADD--}';
109 case 'sub_points': // Subtract points
110 if (bigintval(postRequestParameter('points')) > 0) {
111 // Replace german decimal comma with computer's decimal dot
112 $points = bigintval(convertCommaToDot(postRequestParameter('points')));
114 // Add points to account
115 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_sponsor_data` SET `points_used`=`points_used`+%s WHERE `id`=%s LIMIT 1",
116 array($points, bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
118 // Remember points /reason for the template
119 $content['points'] = $points;
120 $content['reason'] = secureString(postRequestParameter('reason'));
123 $message = loadEmailTemplate('sponsor_sub_points', $content);
124 sendEmail($content['email'], '{--ADMIN_SPONSOR_SUB_POINTS_SUBJECT--}', $message);
125 $message = '{--ADMIN_SPONSOR_POINTS_SUBTRACTED--}';
127 // No points entered to add!
128 $message = '{--ADMIN_SPONSPOR_NO_POINTS_TO_SUBTRACT--}';
132 case 'edit': // Edit sponsor account
134 if ((postRequestParameter('pass1') != postRequestParameter('pass2')) || ((!isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass1')))) {
136 unsetPostRequestParameter('pass1');
137 unsetPostRequestParameter('pass2');
141 // Convert time selection
142 $DATA = array(); $id = 'warning_interval_ye'; $skip = false;
143 convertSelectionsToTimestamp(postRequestArray(), $DATA, $id, $skip);
146 handleSponsorRequest(postRequestArray());
148 // Convert some data for the email template
149 postRequestParameter('gender' , translateGender(postRequestParameter('gender')));
150 postRequestParameter('warning_interval', createFancyTime(postRequestParameter('warning_interval')));
152 if ($PASS === false) setPostRequestParameter('pass1', '{--SPONSOR_PASS_UNCHANGED--}');
154 // Load email template and send the mail away
155 $message = loadEmailTemplate('admin_sponsor_edit', postRequestArray(), false);
156 sendEmail(postRequestParameter('email'), '{--ADMIN_SPONSOR_EDIT_SUBJECT--}', $message);
159 default: // Unknown mode
160 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mode %s detected.", getRequestParameter('mode')));
161 $message = getMaskedMessage('ADMIN_SPONSOR_INVALID_MODE', getRequestParameter('mode'));
165 if (!empty($message)) {
167 loadTemplate('admin_settings_saved', false, $message);
169 } elseif (isFileReadable(sprintf("%stemplates/%s/html/admin/%s.tpl", getPath(), getLanguage(), $TPL))) {
170 // Create mailto link
171 $content['contact'] = '<a href="' . generateSponsorEmailLink($content['email'], 'sponsor_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
173 // Load mode template
174 loadTemplate($TPL, false, $content);
176 // Template not found!
177 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_MODUS_TPL_404', getRequestParameter('mode')));
180 // Sponsor not found!
181 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
185 SQL_FREERESULT($result_main);
187 // Not called by what-list_sponsor.php
188 loadTemplate('admin_settings_saved', false, '{--ADMIN_CALL_NOT_DIRECTLY--}');