Skip to content
Snippets Groups Projects
Commit c40ce069 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #1972 from greezybacon/issue/consistent-name-formatting


Ensure consistent name formatting for agents and end users

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents 3d884342 5a07b1ad
Branches
Tags
No related merge requests found
......@@ -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));
......
......@@ -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))
......
......@@ -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;
......
......@@ -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() {
......
<?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>&nbsp;<?php echo Format::htmlchars($row['name']); ?></td>
<td>&nbsp;<?php echo Format::htmlchars($name); ?></td>
<td>&nbsp;<?php echo Format::htmlchars($row['dept']); ?></td>
<td>&nbsp;<?php echo Format::htmlchars($row['email']); ?></td>
<td>&nbsp;<?php echo Format::phone($row['phone']); ?></td>
......
<?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>&nbsp;</td>
<td><a href="staff.php?id=<?php echo $row['staff_id']; ?>"><?php echo Format::htmlchars($name); ?></a>&nbsp;</td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['isactive']?__('Active'):'<b>'.__('Locked').'</b>'; ?>&nbsp;<?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>
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment