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