Extension 'yoomedia' now alpha status, some rewrites
[mailer.git] / inc / modules / admin / what-edit_user.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Fix a notice
44 $result_main = false;
45 if (isset($_GET['u_id'])) {
46         //                                    0      1        2         3      4     5      6       7         8          9           10         11
47         $result_main = SQL_QUERY_ESC("SELECT gender, surname, family, street_nr, zip, city, country, email, birth_day, birth_month, birth_year, max_mails FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
48          array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
49 }
50
51 if ((SQL_NUMROWS($result_main) == 1) || (empty($_GET['u_id'])))
52 {
53         // User found
54         if (empty($_GET['u_id']))
55         {
56                 // Output selection form with all confirmed user accounts listed
57                 ADD_MEMBER_SELECTION_BOX();
58         }
59          elseif (isset($_POST['edit']))
60         {
61                 // Ok, change the account...
62                 $PASS = false; $ADD = "";
63                 if ((empty($_POST['pass1'])) && (empty($_POST['pass2'])))
64                 {
65                         // Don't change the password
66                         $PASS = true;
67                 }
68                  elseif (($_POST['pass1'] == $_POST['pass2']))
69                 {
70                         // Change the password
71                         $PASS = true;
72                         $ADD = ", password='".generateHash($_POST['pass1'])."'";
73                 }
74                 if ($PASS)
75                 {
76                         // We have to add the following things: birthday and max receive mails
77                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
78 gender='%s',
79 surname='%s',
80 family='%s',
81 street_nr='%s',
82 country='%s',
83 zip=%s,
84 city='%s',
85 email='%s'
86 ".$ADD."
87 WHERE userid=%s LIMIT 1",
88  array(
89         substr($_POST['gender'], 0, 1),
90         $_POST['surname'],
91         $_POST['family_name'],
92         $_POST['street_nr'],
93         $_POST['country'],
94         bigintval($_POST['zip']),
95         $_POST['city'],
96         $_POST['email'],
97         bigintval($_GET['u_id']),
98 ), __FILE__, __LINE__);
99                         $content = USER_ACCOUNT_SAVED;
100                 }
101                  else
102                 {
103                         // Problem while saving data
104                         $content = USER_ACCOUNT_NOT_SAVED;
105                 }
106
107                 // Load template
108                 LOAD_TEMPLATE("admin_settings_saved", false, $content);
109         }
110          else
111         {
112                 // Display form to edit
113                 list($gender, $surname, $family, $street, $zip, $city, $country, $email, $bday, $bmonth, $byear, $max) = SQL_FETCHROW($result_main);
114                 SQL_FREERESULT($result_main);
115
116                 // Transfer data to constants for the template
117                 switch ($gender)
118                 {
119                 case "M":
120                         define('_GENDER_M', " selected=\"selected\"");
121                         define('_GENDER_F', "");
122                         define('_GENDER_C', "");
123                         break;
124
125                 case "F":
126                         define('_GENDER_M', "");
127                         define('_GENDER_F', " selected=\"selected\"");
128                         define('_GENDER_C', "");
129                         break;
130
131                 case "C":
132                         define('_GENDER_M', "");
133                         define('_GENDER_F', "");
134                         define('_GENDER_C', " selected=\"selected\"");
135                         break;
136                 }
137
138                 define('_SURNAME', $surname); define('_FAMILY', $family); define('_CITY'     , $city);
139                 define('_STREET' , $street);  define('_ZIP'   , $zip);    define('_MAX_MAILS', $max);
140                 define('_COUNTRY', $country); define('_EMAIL' , $email);
141
142                 // Load template
143                 LOAD_TEMPLATE("admin_edit_user", false, bigintval($_GET['u_id']));
144         }
145 }
146  else
147 {
148         // Account does not exists!
149         OUTPUT_HTML("<STRONG class=\"admin_failed\">".ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2."</STRONG>");
150 }
151
152 //
153 ?>