Encapsulation and fixes:
[mailer.git] / inc / modules / admin / what-edit_user.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
4  * ===================                          Last change: 06/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-edit_user.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Edit member's profiles                           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mitgliederprofile 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  * @TODO Add support for ext-country                                    *
21  * -------------------------------------------------------------------- *
22  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
23  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
24  * For more information visit: http://www.mxchange.org                  *
25  *                                                                      *
26  * This program is free software; you can redistribute it and/or modify *
27  * it under the terms of the GNU General Public License as published by *
28  * the Free Software Foundation; either version 2 of the License, or    *
29  * (at your option) any later version.                                  *
30  *                                                                      *
31  * This program is distributed in the hope that it will be useful,      *
32  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
33  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
34  * GNU General Public License for more details.                         *
35  *                                                                      *
36  * You should have received a copy of the GNU General Public License    *
37  * along with this program; if not, write to the Free Software          *
38  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
39  * MA  02110-1301  USA                                                  *
40  ************************************************************************/
41
42 // Some security stuff...
43 if ((!defined('__SECURITY')) || (!isAdmin())) {
44         die();
45 } // END - if
46
47 // Add description as navigation point
48 addMenuDescription('admin', __FILE__);
49
50 // Fix a notice
51 $result_main = false;
52 if (isGetRequestParameterSet('userid')) {
53         // Load user entry
54         $result_main = SQL_QUERY_ESC("SELECT
55         `userid`, `gender`, `surname`, `family`, `street_nr`, `zip`, `city`, `country`,
56         `email`,
57         `birth_day`, `birth_month`, `birth_year`,
58         `max_mails`
59 FROM
60         `{?_MYSQL_PREFIX?}_user_data`
61 WHERE
62         `userid`=%s
63 LIMIT 1",
64                 array(
65                         bigintval(getRequestParameter('userid'))
66                 ), __FILE__, __LINE__);
67 } // END - if
68
69 if ((!isGetRequestParameterSet('userid')) || (SQL_NUMROWS($result_main) == 1)) {
70         // User found
71         if (!isGetRequestParameterSet('userid')) {
72                 // Output selection form with all confirmed user accounts listed
73                 addMemberSelectionBox();
74         } elseif (isFormSent('edit')) {
75                 // Ok, change the account...
76                 $updateUser = false; $add = '';
77                 if ((!isPostRequestParameterSet('pass1')) && (!isPostRequestParameterSet('pass2'))) {
78                         // Don't change the password
79                         $updateUser = true;
80                 } elseif ((postRequestParameter('pass1') == postRequestParameter('pass2'))) {
81                         // Change the password
82                         $updateUser = true;
83                         $add = ", `password`='" . generateHash(postRequestParameter('pass1')) . "'";
84                 }
85
86                 if ($updateUser === true) {
87                         // We have to add the following things: birthday and max receive mails
88                         SQL_QUERY_ESC("UPDATE
89         `{?_MYSQL_PREFIX?}_user_data`
90 SET
91         `gender`='%s',
92         `surname`='%s',
93         `family`='%s',
94         `street_nr`='%s',
95         `country`='%s',
96         `zip`=%s,
97         `city`='%s',
98         `email`='%s'
99         ".$add."
100 WHERE
101         `userid`=%s
102 LIMIT 1",
103                         array(
104                                 substr(postRequestParameter('gender'), 0, 1),
105                                 postRequestParameter('surname'),
106                                 postRequestParameter('family'),
107                                 postRequestParameter('street_nr'),
108                                 postRequestParameter('country'),
109                                 bigintval(postRequestParameter('zip')),
110                                 postRequestParameter('city'),
111                                 postRequestParameter('email'),
112                                 bigintval(getRequestParameter('userid')),
113                         ), __FILE__, __LINE__);
114                         $content = getMessage('USER_ACCOUNT_SAVED');
115                 } else {
116                         // Problem while saving data
117                         $content = getMessage('USER_ACCOUNT_NOT_SAVED');
118                 }
119
120                 // Load template
121                 loadTemplate('admin_settings_saved', false, $content);
122         } else {
123                 // Load entry
124                 $content = SQL_FETCHARRAY($result_main);
125
126                 // Init entries
127                 foreach (array('gender_m','gender_f','gender_c') as $entry) {
128                         $content[$entry] = '';
129                 } // END - foreach
130
131                 // Prepare selections
132                 $content['gender_' . strtolower($content['gender'])] = ' selected="selected"';
133
134                 // Load template
135                 loadTemplate('admin_edit_user', false, $content);
136         }
137 } else {
138         // Account does not exists!
139         loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . getMaskedMessage('ADMIN_MEMBER_404', getRequestParameter('userid')) . '</div>');
140 }
141
142 // Free the result
143 SQL_FREERESULT($result_main);
144
145 // [EOF]
146 ?>