82e38399bb6e2c37a2a0f30c84bbb87888d4113f
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 OPEN_TABLE("100%", "admin_content admin_content_align", "");
44
45 // Fix a notice
46 $result_main = false;
47 if (isset($_GET['u_id'])) {
48         //                                    0      1        2         3      4     5      6       7         8          9           10         11
49         $result_main = SQL_QUERY_ESC("SELECT sex, 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",
50          array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
51 }
52
53 if ((SQL_NUMROWS($result_main) == 1) || (empty($_GET['u_id'])))
54 {
55         // User found
56         if (empty($_GET['u_id']))
57         {
58                 // Output selection form with all confirmed user accounts listed
59                 ADD_MEMBER_SELECTION_BOX();
60         }
61          elseif (isset($_POST['edit']))
62         {
63                 // Ok, change the account...
64                 $PASS = false; $ADD = "";
65                 if ((empty($_POST['pass1'])) && (empty($_POST['pass2'])))
66                 {
67                         // Don't change the password
68                         $PASS = true;
69                 }
70                  elseif (($_POST['pass1'] == $_POST['pass2']))
71                 {
72                         // Change the password
73                         $PASS = true;
74                         $ADD = ", password='".generateHash($_POST['pass1'])."'";
75                 }
76                 if ($PASS)
77                 {
78                         // We have to add the following things: birthday and max receive mails
79                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET
80 sex='%s',
81 surname='%s',
82 family='%s',
83 street_nr='%s',
84 country='%s',
85 zip=%s,
86 city='%s',
87 email='%s'
88 ".$ADD."
89 WHERE userid=%s LIMIT 1",
90  array(
91         substr($_POST['salut'], 0, 1),
92         $_POST['surname'],
93         $_POST['family_name'],
94         $_POST['street_nr'],
95         $_POST['country'],
96         bigintval($_POST['zip']),
97         $_POST['city'],
98         $_POST['email'],
99         bigintval($_GET['u_id']),
100 ), __FILE__, __LINE__);
101                         $content = USER_ACCOUNT_SAVED;
102                 }
103                  else
104                 {
105                         // Problem while saving data
106                         $content = USER_ACCOUNT_NOT_SAVED;
107                 }
108
109                 // Load template
110                 LOAD_TEMPLATE("admin_settings_saved", false, $content);
111         }
112          else
113         {
114                 // Display form to edit
115                 list($sex, $surname, $family, $street, $zip, $city, $country, $email, $bday, $bmonth, $byear, $max) = SQL_FETCHROW($result_main);
116                 SQL_FREERESULT($result_main);
117
118                 // Transfer data to constants for the template
119                 switch ($sex)
120                 {
121                 case "M":
122                         define('_SEX_M', " selected=\"selected\"");
123                         define('_SEX_F', "");
124                         define('_SEX_C', "");
125                         break;
126
127                 case "F":
128                         define('_SEX_M', "");
129                         define('_SEX_F', " selected=\"selected\"");
130                         define('_SEX_C', "");
131                         break;
132
133                 case "C":
134                         define('_SEX_M', "");
135                         define('_SEX_F', "");
136                         define('_SEX_C', " selected=\"selected\"");
137                         break;
138                 }
139
140                 define('_SURNAME', $surname); define('_FAMILY', $family); define('_CITY'     , $city);
141                 define('_STREET' , $street);  define('_ZIP'   , $zip);    define('_MAX_MAILS', $max);
142                 define('_COUNTRY', $country); define('_EMAIL' , $email);
143
144                 // Load template
145                 LOAD_TEMPLATE("admin_edit_user", false, bigintval($_GET['u_id']));
146         }
147 }
148  else
149 {
150         // Account does not exists!
151         OUTPUT_HTML("<STRONG class=\"admin_failed\">".ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2."</STRONG>");
152 }
153 CLOSE_TABLE();
154 //
155 ?>