*** empty log message ***
[fa-stable.git] / admin / users.php
1 <?php
2
3 $page_security=15;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 page(_("Users"));
8
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/ui.inc");
11
12 include_once($path_to_root . "/admin/db/users_db.inc");
13
14 if (isset($_GET['selected_id']))
15 {
16         $selected_id = $_GET['selected_id'];
17
18 elseif (isset($_POST['selected_id']))
19 {
20         $selected_id = $_POST['selected_id'];
21 }
22
23 //-------------------------------------------------------------------------------------------------
24
25 if (isset($_GET['AddedID'])) 
26 {
27         display_notification_centered(_("A new user has been added."));
28 }
29
30 if (isset($_GET['UpdatedID'])) 
31 {
32     display_notification_centered(_("The selected user has been updated."));
33 }
34
35 if (isset($_GET['DeletedID'])) 
36 {
37         display_notification_centered(_("User has been deleted."));
38 }
39
40 //-------------------------------------------------------------------------------------------------
41
42 function can_process() 
43 {
44
45         if (strlen($_POST['user_id']) < 4)
46         {
47                 display_error( _("The user login entered must be at least 4 characters long."));
48                 return false;
49         }
50
51         if ($_POST['password'] != "") 
52         {
53         if (strlen($_POST['password']) < 4)
54         {
55                 display_error( _("The password entered must be at least 4 characters long."));
56                 return false;
57         }
58
59         if (strstr($_POST['password'], $_POST['user_id']) != false)
60         {
61                 display_error( _("The password cannot contain the user login."));
62                 return false;
63         }
64         }
65
66         return true;
67 }
68
69 //-------------------------------------------------------------------------------------------------
70
71 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
72 {
73
74         if (can_process())
75         {
76         if (isset($selected_id)) 
77         {
78                 update_user($_POST['user_id'], $_POST['real_name'], $_POST['phone'],
79                         $_POST['email'], $_POST['Access'], $_POST['language']);
80
81                 if ($_POST['password'] != "")
82                         update_user_password($_POST['user_id'], md5($_POST['password']));
83
84                         unset($selected_id);
85                 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=1");
86         } 
87         else 
88         {
89                 add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']),
90                                 $_POST['phone'], $_POST['email'], $_POST['Access'], $_POST['language']);
91
92                         unset($selected_id);
93                         meta_forward($_SERVER['PHP_SELF'], "AddedID=1");
94         }
95         }
96 }
97
98 //-------------------------------------------------------------------------------------------------
99
100 if (isset($_GET['delete'])) 
101 {
102         delete_user($selected_id);
103         unset($selected_id);
104
105         meta_forward($_SERVER['PHP_SELF'], "DeletedID=1");
106 }
107
108 //-------------------------------------------------------------------------------------------------
109
110 $result = get_users();
111
112 start_table($table_style);
113
114 if ($_SESSION["wa_current_user"]->access == 2)
115         $th = array(_("User login"), _("Full Name"), _("Phone"),
116                 _("E-mail"), _("Last Visit"), _("Access Level"), "", "");
117 else            
118         $th = array(_("User login"), _("Full Name"), _("Phone"),
119                 _("E-mail"), _("Last Visit"), _("Access Level"), "");
120 table_header($th);      
121
122 $k = 0; //row colour counter
123
124 while ($myrow = db_fetch($result)) 
125 {
126
127         alt_table_row_color($k);
128
129         $last_visit_date = sql2date($myrow["last_visit_date"]);
130
131         /*The security_headings array is defined in config.php */
132
133         label_cell($myrow["user_id"]);
134         label_cell($myrow["real_name"]);
135         label_cell($myrow["phone"]);
136         label_cell($myrow["email"]);
137         label_cell($last_visit_date, "nowrap");
138         label_cell($security_headings[$myrow["full_access"]]);
139     edit_link_cell("selected_id=".$myrow["user_id"]);
140     if (strcasecmp($myrow["user_id"], $_SESSION["wa_current_user"]->username) &&
141         $_SESSION["wa_current_user"]->access == 2)
142         delete_link_cell("selected_id=".$myrow["user_id"]."&delete=1");
143         end_row();
144
145 } //END WHILE LIST LOOP
146
147 end_table();
148
149 //-------------------------------------------------------------------------------------------------
150
151 hyperlink_no_params($_SERVER['PHP_SELF'], _("New User"));
152
153 start_form();
154
155 start_table($table_style2);
156 if (isset($selected_id)) 
157 {
158         //editing an existing User
159
160         $myrow = get_user($selected_id);
161
162         $_POST['user_id'] = $myrow["user_id"];
163         $_POST['real_name'] = $myrow["real_name"];
164         $_POST['phone'] = $myrow["phone"];
165         $_POST['email'] = $myrow["email"];
166         $_POST['Access'] = $myrow["full_access"];
167         $_POST['language'] = $myrow["language"];
168
169         hidden('selected_id', $selected_id);
170         hidden('user_id', $_POST['user_id']);
171
172         start_row();
173         label_row(_("User login:"), $_POST['user_id']);
174
175
176 else 
177 { //end of if $selected_id only do the else when a new record is being entered
178         text_row(_("User Login:"), "user_id",  null, 22, 20);
179 }
180 $_POST['password'] = "";
181 start_row();
182 label_cell(_("Password:"));
183 label_cell("<input type='password' name='password' size=22 maxlength=20 value='" . $_POST['password'] . "'>");
184 end_row();
185
186 if (isset($selected_id)) 
187 {
188         table_section_title(_("Enter a new password to change, leave empty to keep current."));
189 }
190
191 text_row_ex(_("Full Name").":", 'real_name',  50);
192
193 text_row_ex(_("Telephone No.:"), 'phone', 30);
194
195 text_row_ex(_("Email Address:"), 'email', 50);
196
197 security_headings_list_row(_("Access Level:"), "Access", null); 
198
199 languages_list_row(_("Language:"), 'language', null);
200
201 end_table(1);
202
203 submit_add_or_update_center(!isset($selected_id));
204
205 end_form();
206 end_page();
207 ?>