diff --git a/include/ajax.users.php b/include/ajax.users.php index f211ff6e644238b29576f92313d8695e6f74cc51..b94fd3530937f41451fa31c7f1c87129b952bda3 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -35,7 +35,7 @@ class UsersAjaxAPI extends AjaxController { if (!$type || !strcasecmp($type, 'remote')) { foreach (AuthenticationBackend::searchUsers($_REQUEST['q']) as $u) { - $name = "{$u['first']} {$u['last']}"; + $name = new PersonsName(array('first' => $u['first'], 'last' => $u['last'])); $users[] = array('email' => $u['email'], 'name'=>$name, 'info' => "{$u['email']} - $name (remote)", 'id' => "auth:".$u['id'], "/bin/true" => $_REQUEST['q']); @@ -48,7 +48,8 @@ class UsersAjaxAPI extends AjaxController { ? ' OR email.address IN ('.implode(',',db_input($emails)).') ' : ''; - $escaped = db_input(strtolower($_REQUEST['q']), false); + $q = str_replace(' ', '%', $_REQUEST['q']); + $escaped = db_input($q, false); $sql='SELECT DISTINCT user.id, email.address, name ' .' FROM '.USER_TABLE.' user ' .' JOIN '.USER_EMAIL_TABLE.' email ON user.id = email.user_id ' @@ -57,7 +58,6 @@ class UsersAjaxAPI extends AjaxController { .' WHERE email.address LIKE \'%'.$escaped.'%\' OR user.name LIKE \'%'.$escaped.'%\' OR value.value LIKE \'%'.$escaped.'%\''.$remote_emails - .' ORDER BY user.created ' .' LIMIT '.$limit; if(($res=db_query($sql)) && db_num_rows($res)){ @@ -68,11 +68,12 @@ class UsersAjaxAPI extends AjaxController { break; } } - $name = Format::htmlchars($name); + $name = Format::htmlchars(new PersonsName($name)); $users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name", "id" => $id, "/bin/true" => $_REQUEST['q']); } } + usort($users, function($a, $b) { return strcmp($a['name'], $b['name']); }); } return $this->json_encode(array_values($users)); diff --git a/include/class.dept.php b/include/class.dept.php index cea549872b13bba5d4b1867eb4b9ad687b987244..9e6cf21460aae4ae065ce7fdae923d48d5dd16d1 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -124,6 +124,7 @@ class Dept { } function getMembers($criteria=null) { + global $cfg; if(!$this->members || $criteria) { $members = array(); @@ -144,7 +145,16 @@ class Dept { AND s.isactive=1 AND s.onvacation=0 ) '; - $sql.=' ORDER BY s.lastname, s.firstname'; + switch ($cfg->getDefaultNameFormat()) { + case 'last': + case 'lastfirst': + case 'legal': + $sql .= ' ORDER BY s.lastname, s.firstname'; + break; + + default: + $sql .= ' ORDER BY s.firstname, s.lastname'; + } if(($res=db_query($sql)) && db_num_rows($res)) { while(list($id)=db_fetch_row($res)) diff --git a/include/class.staff.php b/include/class.staff.php index 367343272725f66d0a804fc5cbb7dd8da96c8d24..e0525e63dd00da052d54232c652df0d506df5999 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -193,7 +193,7 @@ implements EmailContact { } function getName() { - return new PersonsName($this->ht['firstname'].' '.$this->ht['lastname']); + return new PersonsName(array('first' => $this->ht['firstname'], 'last' => $this->ht['lastname'])); } function getFirstName() { @@ -602,20 +602,32 @@ implements EmailContact { /**** Static functions ********/ function getStaffMembers($availableonly=false) { + global $cfg; - $sql='SELECT s.staff_id, CONCAT_WS(" ", s.firstname, s.lastname) as name ' - .' FROM '.STAFF_TABLE.' s '; + $sql = 'SELECT s.staff_id, s.firstname, s.lastname FROM ' + .STAFF_TABLE.' s '; if($availableonly) { $sql.=' INNER JOIN '.GROUP_TABLE.' g ON(g.group_id=s.group_id AND g.group_enabled=1) ' .' WHERE s.isactive=1 AND s.onvacation=0'; } - $sql.=' ORDER BY s.lastname, s.firstname'; + switch ($cfg->getDefaultNameFormat()) { + case 'last': + case 'lastfirst': + case 'legal': + $sql .= ' ORDER BY s.lastname, s.firstname'; + break; + + default: + $sql .= ' ORDER BY s.firstname, s.lastname'; + } + $users=array(); if(($res=db_query($sql)) && db_num_rows($res)) { - while(list($id, $name) = db_fetch_row($res)) - $users[$id] = $name; + while(list($id, $fname, $lname) = db_fetch_row($res)) + $users[$id] = new PersonsName( + array('first' => $fname, 'last' => $lname)); } return $users; diff --git a/include/class.user.php b/include/class.user.php index db6e7936d3a4c6c32ee9151febdb99834e80686b..635a6079dbd876386e493a4fc6de50e40bd14dac 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -623,8 +623,14 @@ class PersonsName { elseif($cfg) $this->format = $cfg->getDefaultNameFormat(); - $this->parts = static::splitName($name); - $this->name = $name; + if (!is_array($name)) { + $this->parts = static::splitName($name); + $this->name = $name; + } + else { + $this->parts = $name; + $this->name = implode(' ', $name); + } } function getFirst() { diff --git a/include/staff/directory.inc.php b/include/staff/directory.inc.php index 622d4d371a56a3c57c2aaaadd0c6611106b77919..15b717c141fbc5f39ec4c04964a6cde896f3e0e6 100644 --- a/include/staff/directory.inc.php +++ b/include/staff/directory.inc.php @@ -1,7 +1,7 @@ <?php if(!defined('OSTSTAFFINC') || !$thisstaff || !$thisstaff->isStaff()) die('Access Denied'); $qs = array(); -$select='SELECT staff.*,CONCAT_WS(" ",firstname,lastname) as name,dept.dept_name as dept '; +$select='SELECT staff.*,dept.dept_name as dept '; $from='FROM '.STAFF_TABLE.' staff '. 'LEFT JOIN '.DEPT_TABLE.' dept ON(staff.dept_id=dept.dept_id) '; $where='WHERE staff.isvisible=1 '; @@ -31,6 +31,16 @@ if($_REQUEST['did'] && is_numeric($_REQUEST['did'])) { $sortOptions=array('name'=>'staff.firstname,staff.lastname','email'=>'staff.email','dept'=>'dept.dept_name', 'phone'=>'staff.phone','mobile'=>'staff.mobile','ext'=>'phone_ext', 'created'=>'staff.created','login'=>'staff.lastlogin'); + +switch ($cfg->getDefaultNameFormat()) { +case 'last': +case 'lastfirst': +case 'legal': + $sortOptions['name'] = 'staff.lastname, staff.firstname'; + break; +// Otherwise leave unchanged +} + $orderWays=array('DESC'=>'DESC','ASC'=>'ASC'); $sort=($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])])?strtolower($_REQUEST['sort']):'name'; //Sorting options... @@ -111,9 +121,11 @@ else <?php if($res && db_num_rows($res)): $ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null; - while ($row = db_fetch_array($res)) { ?> + while ($row = db_fetch_array($res)) { + $name = new PersonsName(array('first' => $row['firstname'], 'last' => $row['lastname'])); +?> <tr id="<?php echo $row['staff_id']; ?>"> - <td> <?php echo Format::htmlchars($row['name']); ?></td> + <td> <?php echo Format::htmlchars($name); ?></td> <td> <?php echo Format::htmlchars($row['dept']); ?></td> <td> <?php echo Format::htmlchars($row['email']); ?></td> <td> <?php echo Format::phone($row['phone']); ?></td> diff --git a/include/staff/staffmembers.inc.php b/include/staff/staffmembers.inc.php index 34681d2eb081c0a67e3d140342d0e8d422ae82c1..c5c7eaee40e66a09ed509668fd5316f3dc0cdee0 100644 --- a/include/staff/staffmembers.inc.php +++ b/include/staff/staffmembers.inc.php @@ -1,7 +1,7 @@ <?php if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied'); $qs = array(); -$select='SELECT staff.*,CONCAT_WS(" ",firstname,lastname) as name, grp.group_name, dept.dept_name as dept,count(m.team_id) as teams '; +$select='SELECT staff.*, grp.group_name, dept.dept_name as dept,count(m.team_id) as teams '; $from='FROM '.STAFF_TABLE.' staff '. 'LEFT JOIN '.GROUP_TABLE.' grp ON(staff.group_id=grp.group_id) '. 'LEFT JOIN '.DEPT_TABLE.' dept ON(staff.dept_id=dept.dept_id) '. @@ -25,6 +25,16 @@ if($_REQUEST['tid'] && is_numeric($_REQUEST['tid'])) { $sortOptions=array('name'=>'staff.firstname,staff.lastname','username'=>'staff.username','status'=>'isactive', 'group'=>'grp.group_name','dept'=>'dept.dept_name','created'=>'staff.created','login'=>'staff.lastlogin'); + +switch ($cfg->getDefaultNameFormat()) { +case 'last': +case 'lastfirst': +case 'legal': + $sortOptions['name'] = 'staff.lastname, staff.firstname'; + break; +// Otherwise leave unchanged +} + $orderWays=array('DESC'=>'DESC','ASC'=>'ASC'); $sort=($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])])?strtolower($_REQUEST['sort']):'name'; //Sorting options... @@ -143,11 +153,12 @@ else $sel=false; if($ids && in_array($row['staff_id'],$ids)) $sel=true; + $name = new PersonsName(array('first' => $row['firstname'], 'last' => $row['lastname'])); ?> <tr id="<?php echo $row['staff_id']; ?>"> <td width=7px> <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['staff_id']; ?>" <?php echo $sel?'checked="checked"':''; ?> > - <td><a href="staff.php?id=<?php echo $row['staff_id']; ?>"><?php echo Format::htmlchars($row['name']); ?></a> </td> + <td><a href="staff.php?id=<?php echo $row['staff_id']; ?>"><?php echo Format::htmlchars($name); ?></a> </td> <td><?php echo $row['username']; ?></td> <td><?php echo $row['isactive']?__('Active'):'<b>'.__('Locked').'</b>'; ?> <?php echo $row['onvacation']?'<small>(<i>'.__('vacation').'</i>)</small>':''; ?></td> <td><a href="groups.php?id=<?php echo $row['group_id']; ?>"><?php echo Format::htmlchars($row['group_name']); ?></a></td> diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 82caa6727536fc6bf8ab2d3b663784e014309050..6fa756e21ecf5a7948e9f02d74cb3658c62a7c6a 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -602,8 +602,10 @@ if ($results) { <option value="s<?php echo $thisstaff->getId(); ?>"><?php echo __('Me');?></option> <?php if(($users=Staff::getStaffMembers())) { - echo '<OPTGROUP label="'.sprintf(__('Agents (%d)'),count($users)).'">'; + echo '<OPTGROUP label="'.sprintf(__('Agents (%d)'),count($users)-1).'">'; foreach($users as $id => $name) { + if ($id == $thisstaff->getId()) + continue; $k="s$id"; echo sprintf('<option value="%s">%s</option>', $k, $name); }