2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_USERS';
14 include_once($path_to_root . "/includes/session.inc");
16 page(_($help_context = "Users"));
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/admin/db/users_db.inc");
23 simple_page_mode(true);
24 //-------------------------------------------------------------------------------------------------
26 function can_process()
29 if (strlen($_POST['user_id']) < 4)
31 display_error( _("The user login entered must be at least 4 characters long."));
36 if ($_POST['password'] != "")
38 if (strlen($_POST['password']) < 4)
40 display_error( _("The password entered must be at least 4 characters long."));
41 set_focus('password');
45 if (strstr($_POST['password'], $_POST['user_id']) != false)
47 display_error( _("The password cannot contain the user login."));
48 set_focus('password');
56 //-------------------------------------------------------------------------------------------------
58 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
63 if ($selected_id != -1)
65 update_user_prefs($selected_id,
66 get_post(array('user_id', 'real_name', 'phone', 'email', 'role_id', 'language',
67 'print_profile', 'rep_popup' => 0, 'pos')));
69 if ($_POST['password'] != "")
70 update_user_password($selected_id, $_POST['user_id'], md5($_POST['password']));
72 display_notification_centered(_("The selected user has been updated."));
76 add_user($_POST['user_id'], $_POST['real_name'], md5($_POST['password']),
77 $_POST['phone'], $_POST['email'], $_POST['role_id'], $_POST['language'],
78 $_POST['print_profile'], check_value('rep_popup'), $_POST['pos']);
80 // use current user display preferences as start point for new user
81 $prefs = $_SESSION['wa_current_user']->prefs->get_all();
83 update_user_prefs($id, array_merge($prefs, get_post(array('print_profile',
84 'rep_popup' => 0, 'language'))));
86 display_notification_centered(_("A new user has been added."));
92 //-------------------------------------------------------------------------------------------------
94 if ($Mode == 'Delete')
96 delete_user($selected_id);
97 display_notification_centered(_("User has been deleted."));
101 //-------------------------------------------------------------------------------------------------
102 if ($Mode == 'RESET')
105 $sav = get_post('show_inactive');
106 unset($_POST); // clean all input fields
107 $_POST['show_inactive'] = $sav;
110 $result = get_users(check_value('show_inactive'));
112 start_table(TABLESTYLE);
114 $th = array(_("User login"), _("Full Name"), _("Phone"),
115 _("E-mail"), _("Last Visit"), _("Access Level"), "", "");
117 inactive_control_column($th);
120 $k = 0; //row colour counter
122 while ($myrow = db_fetch($result))
125 alt_table_row_color($k);
127 $last_visit_date = sql2date($myrow["last_visit_date"]);
129 /*The security_headings array is defined in config.php */
130 $not_me = strcasecmp($myrow["user_id"], $_SESSION["wa_current_user"]->username);
132 label_cell($myrow["user_id"]);
133 label_cell($myrow["real_name"]);
134 label_cell($myrow["phone"]);
135 email_cell($myrow["email"]);
136 label_cell($last_visit_date, "nowrap");
137 label_cell($myrow["role"]);
140 inactive_control_cell($myrow["id"], $myrow["inactive"], 'users', 'id');
141 elseif (check_value('show_inactive'))
144 edit_button_cell("Edit".$myrow["id"], _("Edit"));
146 delete_button_cell("Delete".$myrow["id"], _("Delete"));
151 } //END WHILE LIST LOOP
153 inactive_control_row($th);
155 //-------------------------------------------------------------------------------------------------
156 start_table(TABLESTYLE2);
158 $_POST['email'] = "";
159 if ($selected_id != -1)
161 if ($Mode == 'Edit') {
162 //editing an existing User
163 $myrow = get_user($selected_id);
165 $_POST['id'] = $myrow["id"];
166 $_POST['user_id'] = $myrow["user_id"];
167 $_POST['real_name'] = $myrow["real_name"];
168 $_POST['phone'] = $myrow["phone"];
169 $_POST['email'] = $myrow["email"];
170 $_POST['role_id'] = $myrow["role_id"];
171 $_POST['language'] = $myrow["language"];
172 $_POST['print_profile'] = $myrow["print_profile"];
173 $_POST['rep_popup'] = $myrow["rep_popup"];
174 $_POST['pos'] = $myrow["pos"];
176 hidden('selected_id', $selected_id);
180 label_row(_("User login:"), $_POST['user_id']);
183 { //end of if $selected_id only do the else when a new record is being entered
184 text_row(_("User Login:"), "user_id", null, 22, 20);
185 $_POST['language'] = user_language();
186 $_POST['print_profile'] = user_print_profile();
187 $_POST['rep_popup'] = user_rep_popup();
188 $_POST['pos'] = user_pos();
190 $_POST['password'] = "";
191 password_row(_("Password:"), 'password', $_POST['password']);
193 if ($selected_id != -1)
195 table_section_title(_("Enter a new password to change, leave empty to keep current."));
198 text_row_ex(_("Full Name").":", 'real_name', 50);
200 text_row_ex(_("Telephone No.:"), 'phone', 30);
202 email_row_ex(_("Email Address:"), 'email', 50);
204 security_roles_list_row(_("Access Level:"), 'role_id', null);
206 languages_list_row(_("Language:"), 'language', null);
208 pos_list_row(_("User's POS"). ':', 'pos', null);
210 print_profiles_list_row(_("Printing profile"). ':', 'print_profile', null,
211 _('Browser printing support'));
213 check_row(_("Use popup window for reports:"), 'rep_popup', $_POST['rep_popup'],
214 false, _('Set this option to on if your browser directly supports pdf files'));
218 submit_add_or_update_center($selected_id == -1, '', 'both');