Fixes for wrong tewmplate names, new network added:
[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  * 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                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
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`
55 FROM
56         `{?_MYSQL_PREFIX?}_sponsor_data`
57 WHERE
58         `id`=%s
59 LIMIT 1",
60                 array(bigintval(getRequestParameter('id'))), __FILE__, __LINE__);
61         if (SQL_NUMROWS($result_main) == 1) {
62                 // Load sponsor details
63                 $content = SQL_FETCHARRAY($result_main);
64
65                 // Prepare all data for the template
66                 // Init gender
67                 foreach (array('m', 'f', 'c') as $gender) {
68                         $content['gender_' . $gender] = '';
69                 } // END - foreach
70
71                 // Check for gender selection
72                 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
73
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');
77
78                 // Init variables here
79                 $TPL = sprintf("admin_edit_sponsor_%s", getRequestParameter('mode'));
80                 initSqls();
81
82                 // Sponsor was found
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')));
90
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__);
94
95                                                 // Remember points /reason for the template
96                                                 $content['points'] = $points;
97                                                 $content['reason'] = secureString(postRequestParameter('reason'));
98
99                                                 // Send email
100                                                 $message = loadEmailTemplate('sponsor_add_points', $content);
101                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_ADD_POINTS_SUBJECT--}', $message);
102                                                 $message = '{--ADMIN_SPONSOR_POINTS_ADDED--}';
103                                         } else {
104                                                 // No points entered to add!
105                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_ADD--}';
106                                         }
107                                         break;
108
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')));
113
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__);
117
118                                                 // Remember points /reason for the template
119                                                 $content['points'] = $points;
120                                                 $content['reason'] = secureString(postRequestParameter('reason'));
121
122                                                 // Send email
123                                                 $message = loadEmailTemplate('sponsor_sub_points', $content);
124                                                 sendEmail($content['email'], '{--ADMIN_SPONSOR_SUB_POINTS_SUBJECT--}', $message);
125                                                 $message = '{--ADMIN_SPONSOR_POINTS_SUBTRACTED--}';
126                                         } else {
127                                                 // No points entered to add!
128                                                 $message = '{--ADMIN_SPONSOR_NO_POINTS_TO_SUBTRACT--}';
129                                         }
130                                         break;
131
132                                 case 'edit': // Edit sponsor account
133                                         $PASS = true;
134                                         if ((postRequestParameter('pass1') != postRequestParameter('pass2')) || ((!isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass1')))) {
135                                                 // Remove passwords
136                                                 unsetPostRequestParameter('pass1');
137                                                 unsetPostRequestParameter('pass2');
138                                                 $PASS = false;
139                                         } // END - if
140
141                                         // Convert time selection
142                                         $DATA = array(); $id = 'warning_interval_ye'; $skip = false;
143                                         convertSelectionsToTimestamp(postRequestArray(), $DATA, $id, $skip);
144
145                                         // Save the sponsor
146                                         handleSponsorRequest(postRequestArray());
147
148                                         // Convert some data for the email template
149                                         postRequestParameter('gender'          , translateGender(postRequestParameter('gender')));
150                                         postRequestParameter('warning_interval', createFancyTime(postRequestParameter('warning_interval')));
151
152                                         if ($PASS === false) setPostRequestParameter('pass1', '{--SPONSOR_PASS_UNCHANGED--}');
153
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);
157                                         break;
158
159                                 default: // Unknown mode
160                                         logDebugMessage(__FILE__, __LINE__, sprintf("Unknown mode %s detected.", getRequestParameter('mode')));
161                                         $message = getMaskedMessage('ADMIN_SPONSOR_INVALID_MODE', getRequestParameter('mode'));
162                                         break;
163                         }
164
165                         if (!empty($message)) {
166                                 // Output message
167                                 loadTemplate('admin_settings_saved', false, $message);
168                         } // END - if
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>';
172
173                         // Load mode template
174                         loadTemplate($TPL, false, $content);
175                 } else {
176                         // Template not found!
177                         loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_MODUS_TPL_404', getRequestParameter('mode')));
178                 }
179         } else {
180                 // Sponsor not found!
181                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_SPONSOR_404', bigintval(getRequestParameter('id'))));
182         }
183
184         // Free result
185         SQL_FREERESULT($result_main);
186 } else {
187         // Not called by what-list_sponsor.php
188         loadTemplate('admin_settings_saved', false, '{--ADMIN_CALL_NOT_DIRECTLY--}');
189 }
190
191 // [EOF]
192 ?>