5 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/ui.inc");
12 include_once($path_to_root . "/admin/db/users_db.inc");
14 if (isset($_GET['selected_id']))
16 $selected_id = $_GET['selected_id'];
18 elseif (isset($_POST['selected_id']))
20 $selected_id = $_POST['selected_id'];
23 //-------------------------------------------------------------------------------------------------
25 if (isset($_GET['AddedID']))
27 display_notification_centered(_("A new user has been added."));
30 if (isset($_GET['UpdatedID']))
32 display_notification_centered(_("The selected user has been updated."));
35 if (isset($_GET['DeletedID']))
37 display_notification_centered(_("User has been deleted."));
40 //-------------------------------------------------------------------------------------------------
42 function can_process()
45 if (strlen($_POST['user_id']) < 4)
47 display_error( _("The user login entered must be at least 4 characters long."));
51 if ($_POST['password'] != "")
53 if (strlen($_POST['password']) < 4)
55 display_error( _("The password entered must be at least 4 characters long."));
59 if (strstr($_POST['password'], $_POST['user_id']) != false)
61 display_error( _("The password cannot contain the user login."));
69 //-------------------------------------------------------------------------------------------------
71 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
76 if (isset($selected_id))
78 update_user($_POST['user_id'], $_POST['real_name'], $_POST['phone'],
79 $_POST['email'], $_POST['Access'], $_POST['language']);
81 if ($_POST['password'] != "")
82 update_user_password($_POST['user_id'], md5($_POST['password']));
85 meta_forward($_SERVER['PHP_SELF'], "UpdatedID=1");
89 add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']),
90 $_POST['phone'], $_POST['email'], $_POST['Access'], $_POST['language']);
93 meta_forward($_SERVER['PHP_SELF'], "AddedID=1");
98 //-------------------------------------------------------------------------------------------------
100 if (isset($_GET['delete']))
102 delete_user($selected_id);
105 meta_forward($_SERVER['PHP_SELF'], "DeletedID=1");
108 //-------------------------------------------------------------------------------------------------
110 $result = get_users();
112 start_table($table_style);
114 if ($_SESSION["wa_current_user"]->access == 2)
115 $th = array(_("User login"), _("Full Name"), _("Phone"),
116 _("E-mail"), _("Last Visit"), _("Access Level"), "", "");
118 $th = array(_("User login"), _("Full Name"), _("Phone"),
119 _("E-mail"), _("Last Visit"), _("Access Level"), "");
122 $k = 0; //row colour counter
124 while ($myrow = db_fetch($result))
127 alt_table_row_color($k);
129 $last_visit_date = sql2date($myrow["last_visit_date"]);
131 /*The security_headings array is defined in config.php */
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");
145 } //END WHILE LIST LOOP
149 //-------------------------------------------------------------------------------------------------
151 hyperlink_no_params($_SERVER['PHP_SELF'], _("New User"));
155 start_table($table_style2);
156 if (isset($selected_id))
158 //editing an existing User
160 $myrow = get_user($selected_id);
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"];
169 hidden('selected_id', $selected_id);
170 hidden('user_id', $_POST['user_id']);
173 label_row(_("User login:"), $_POST['user_id']);
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);
180 $_POST['password'] = "";
182 label_cell(_("Password:"));
183 label_cell("<input type='password' name='password' size=22 maxlength=20 value='" . $_POST['password'] . "'>");
186 if (isset($selected_id))
188 table_section_title(_("Enter a new password to change, leave empty to keep current."));
191 text_row_ex(_("Full Name").":", 'real_name', 50);
193 text_row_ex(_("Telephone No.:"), 'phone', 30);
195 text_row_ex(_("Email Address:"), 'email', 50);
197 security_headings_list_row(_("Access Level:"), "Access", null);
199 languages_list_row(_("Language:"), 'language', null);
203 submit_add_or_update_center(!isset($selected_id));