forked from FullService/OsTicket
-
Notifications
You must be signed in to change notification settings - Fork 20
/
class.staff.php
340 lines (261 loc) · 10.1 KB
/
class.staff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
/*********************************************************************
class.staff.php
Everything about staff.
Peter Rotich <[email protected]>
Copyright (c) 2006,2007,2008,2009 osTicket
http:https://www.osticket.com
Released under the GNU General Public License WITHOUT ANY WARRANTY.
See LICENSE.TXT for details.
vim: expandtab sw=4 ts=4 sts=4:
$Id: class.staff.php,v 1.1.2.1 2009/08/17 18:38:50 carlos.delfino Exp $
**********************************************************************/
class Staff {
var $udata;
var $group_id;
var $dept_id;
var $passwd;
var $id;
var $fullname;
var $username;
var $email;
var $firstname;
var $lastname;
var $signature;
var $dept;
function Staff($var){
$this->id =0;
return ($this->lookup($var));
}
function lookup($var){
$sql=sprintf("SELECT * FROM ".STAFF_TABLE." LEFT JOIN ".GROUP_TABLE." USING(group_id) WHERE %s=%s ",
is_numeric($var)?'staff_id':'username',db_input($var));
$res=db_query($sql);
if(!$res || !db_num_rows($res))
return NULL;
$row=db_fetch_array($res);
$this->udata=$row;
$this->id = $row['staff_id'];
$this->group_id = $row['group_id'];
$this->dept_id = $row['dept_id'];
$this->firstname = ucfirst($row['firstname']);
$this->lastname = ucfirst($row['lastname']);
$this->fullname = ucfirst($row['firstname'].' '.$row['lastname']);
$this->passwd = $row['passwd'];
$this->username = $row['username'];
$this->email = $row['email'];
$this->signature = $row['signature'];
return($this->id);
}
function reload(){
$this->lookup($this->id);
}
function getInfo() {
return $this->udata;
}
/*compares user password*/
function check_passwd($password){
return (strlen($this->passwd) && strcmp($this->passwd, MD5($password))==0)?(TRUE):(FALSE);
}
function getTZoffset(){
global $cfg;
$offset=$this->udata['timezone_offset'];
return $offset?$offset:$cfg->getTZoffset();
}
function observeDaylight() {
return $this->udata['daylight_saving']?true:false;
}
function getRefreshRate(){
return $this->udata['auto_refresh_rate'];
}
function getPageLimit() {
global $cfg;
$limit=$this->udata['max_page_size'];
return $limit?$limit:$cfg->getPageSize();
}
function getData(){
return($this->udata);
}
function getId(){
return $this->id;
}
function getEmail(){
return($this->email);
}
function getUserName(){
return($this->username);
}
function getName(){
return($this->fullname);
}
function getFirstName(){
return $this->firstname;
}
function getLastName(){
return $this->lastname;
}
function getDeptId(){
return $this->dept_id;
}
function getGroupId(){
return $this->group_id;
}
function getSignature(){
return($this->signature);
}
function appendMySignature(){
return $this->signature?true:false;
}
function forcePasswdChange(){
return $this->udata['change_passwd']?true:false;
}
function getDepts(){
//Departments the user is allowed to access...based on the group they belong to + user's dept.
return array_filter(array_unique(array_merge(explode(',',$this->udata['dept_access']),array($this->dept_id)))); //Neptune help us
}
function getDept(){
if(!$this->dept && $this->dept_id)
$this->dept= new Dept($this->dept_id);
return $this->dept;
}
function isManager() {
return (($dept=$this->getDept()) && $dept->getManagerId()==$this->getId())?true:false;
}
function isStaff(){
return TRUE;
}
function isGroupActive() {
return ($this->udata['group_enabled'])?true:false;
}
function isactive(){
return ($this->udata['isactive'])?true:false;
}
function isVisible(){
return ($this->udata['isvisible'])?true:false;
}
function onVacation(){
return ($this->udata['onvacation'])?true:false;
}
function isAvailable() {
return (!$this->isactive() || !$this->isGroupActive() || $this->onVacation())?false:true;
}
function isadmin(){
return ($this->udata['isadmin'])?true:false;
}
/* canDos' logic explained
1) First check id the user is super admin...if yes...super..allow
2) Check if the user is allowed to do the Do...or a manager in some cases -- if yes...allow
3) Check if he user's group is allowed...if yes...allow
5) If I-2-3 fails...it is a NO.. you can cry yourself to sleep.
*/
function canAccessDept($deptid){
return ($this->isadmin() ||in_array($deptid,$this->getDepts()))?true:false;
}
function canCreateTickets(){
return ($this->isadmin() || $this->udata['can_create_tickets'])?true:false;
}
function canEditTickets(){
return ($this->isadmin() || $this->udata['can_edit_tickets'])?true:false;
}
function canDeleteTickets(){
return ($this->isadmin() || $this->udata['can_delete_tickets'])?true:false;
}
function canCloseTickets(){
return ($this->isadmin() || $this->udata['can_close_tickets'])?true:false;
}
function canTransferTickets() {
return ($this->isadmin() || $this->isManager() || $this->udata['can_transfer_tickets'])?true:false;
}
function canManageBanList() {
return ($this->isadmin() || $this->isManager() || $this->udata['can_ban_emails'])?true:false;
}
function canManageTickets() {
return ($this->isadmin()
|| $this->canDeleteTickets()
|| $this->canManageBanList()
|| $this->canCloseTickets())?true:false;
}
function canManageKb() { //kb = knowledge base.
return ($this->isadmin() || $this->udata['can_manage_kb'])?true:false;
}
function update($vars,&$errors) {
if($this->save($this->getId(),$vars,$errors)){
$this->reload();
return true;
}
return false;
}
function create($vars,&$errors) {
return Staff::save(0,$vars,$errors);
}
function save($id,$vars,&$errors) {
include_once(INCLUDE_DIR.'class.dept.php');
if($id && $id!=$vars['staff_id'])
$errors['err']='Internal Error';
if(!$vars['firstname'] || !$vars['lastname'])
$errors['name']='First and last name required';
if(!$vars['username'] || strlen($vars['username'])<3)
$errors['username']='Username required';
else{
//check if the username is already in-use.
$sql='SELECT staff_id FROM '.STAFF_TABLE.' WHERE username='.db_input($vars['username']);
if($id)
$sql.=' AND staff_id!='.db_input($id);
if(db_num_rows(db_query($sql)))
$errors['username']='Username already in-use';
}
if(!$vars['email'] || !Validator::is_email($vars['email']))
$errors['email']='Valid email required';
elseif(Email::getIdByEmail($vars['email']))
$errors['email']='Already in-use system email';
if($vars['phone'] && !Validator::is_phone($vars['phone']))
$errors['phone']='Valid number required';
if($vars['mobile'] && !Validator::is_phone($vars['mobile']))
$errors['mobile']='Valid number required';
if($vars['npassword'] || $vars['vpassword'] || !$id){
if(!$vars['npassword'] && !$id)
$errors['npassword']='Temp password required';
elseif($vars['npassword'] && strcmp($vars['npassword'],$vars['vpassword']))
$errors['vpassword']='Password(s) do not match';
elseif($vars['npassword'] && strlen($vars['npassword'])<6)
$errors['npassword']='Must be at least 6 characters';
}
if(!$vars['dept_id'])
$errors['dept']='Department required';
if(!$vars['group_id'])
$errors['group']='Group required';
if(!$errors){
$sql=' SET updated=NOW() '.
',isadmin='.db_input($vars['isadmin']).
',isactive='.db_input($vars['isactive']).
',isvisible='.db_input(isset($vars['isvisible'])?1:0).
',onvacation='.db_input(isset($vars['onvacation'])?1:0).
',dept_id='.db_input($vars['dept_id']).
',group_id='.db_input($vars['group_id']).
',username='.db_input(Format::striptags($vars['username'])).
',firstname='.db_input(Format::striptags($vars['firstname'])).
',lastname='.db_input(Format::striptags($vars['lastname'])).
',email='.db_input($vars['email']).
',phone="'.db_input($vars['phone'],false).'"'.
',phone_ext='.db_input($vars['phone_ext']).
',mobile="'.db_input($vars['mobile'],false).'"'.
',signature='.db_input(Format::striptags($vars['signature']));
if($vars['npassword'])
$sql.=',passwd='.db_input(md5($vars['npassword']));
if(isset($vars['resetpasswd']))
$sql.=',change_passwd=1';
if($id) {
$sql='UPDATE '.STAFF_TABLE.' '.$sql.' WHERE staff_id='.db_input($id);
if(!db_query($sql) || !db_affected_rows())
$errors['err']='Unable to update the user. Internal error occured';
}else{
$sql='INSERT INTO '.STAFF_TABLE.' '.$sql.',created=NOW()';
if(db_query($sql) && ($uID=db_insert_id()))
return $uID;
$errors['err']='Unable to create user. Internal error';
}
}
return $errors?false:true;
}
}
?>