diff --git a/include/ajax.users.php b/include/ajax.users.php index a075ff42176d219726c7d3323a20093c673a6f86..6291fd3627c44b8938b0e0688ca5fdf637939aaa 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -31,21 +31,37 @@ class UsersAjaxAPI extends AjaxController { $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; $users=array(); - $sql='SELECT DISTINCT email.address, name ' + $escaped = db_input(strtolower($_REQUEST['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 ' - .' WHERE email.address LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\' ' - .' ORDER BY created ' + .' JOIN '.FORM_ENTRY_TABLE.' entry ON (entry.object_type=\'U\' AND entry.object_id = user.id) + JOIN '.FORM_ANSWER_TABLE.' value ON (value.entry_id=entry.id) ' + .' WHERE email.address LIKE \'%'.$escaped.'%\' + OR user.name LIKE \'%'.$escaped.'%\' + OR value.value LIKE \'%'.$escaped.'%\' + ORDER BY user.created ' .' LIMIT '.$limit; - + if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($email,$name)=db_fetch_row($res)) { - $users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name"); - } - } - + while(list($id,$email,$name)=db_fetch_row($res)) { + $users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name", + "id" => $id, "/bin/true" => $_REQUEST['q']); + } + } + return $this->json_encode($users); } + + function getLookupForm() { + $user_info = array(); + if ($_REQUEST['id']) { + $user = User::lookup($_REQUEST['id']); + $user_info += array( + 'name'=>$user->getName(), 'email'=>$user->getEmail()); + } + include(STAFFINC_DIR . 'templates/user-lookup.tmpl.php'); + } } ?> diff --git a/include/class.ticket.php b/include/class.ticket.php index 692c6e53ee0315691871461b499020baa1d1636c..701df78cdce4aa290f0390e12e1fce8ca6acd537 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -331,12 +331,10 @@ class Ticket { function getUpdateInfo() { global $cfg; - $info=array('phone' => $this->getPhone(), - 'phone_ext' => $this->getPhoneExt(), - 'source' => $this->getSource(), + $info=array('source' => $this->getSource(), 'topicId' => $this->getTopicId(), - 'priorityId' => $this->getPriorityId(), 'slaId' => $this->getSLAId(), + 'user_id' => $this->getOwnerId(), 'duedate' => $this->getDueDate() ? Format::userdate($cfg->getDateFormat(), Misc::db2gmtime($this->getDueDate())) @@ -1699,6 +1697,7 @@ class Ticket { $fields['duedate'] = array('type'=>'date', 'required'=>0, 'error'=>'Invalid date - must be MM/DD/YY'); $fields['note'] = array('type'=>'text', 'required'=>1, 'error'=>'Reason for the update required'); + $fields['user_id'] = array('type'=>'int', 'required'=>0, 'error'=>'Invalid user-id'); if(!Validator::process($fields, $vars, $errors) && !$errors['err']) $errors['err'] = 'Missing or invalid data - check the errors and try again'; @@ -1722,6 +1721,8 @@ class Ticket { .' ,source='.db_input($vars['source']) .' ,duedate='.($vars['duedate']?db_input(date('Y-m-d G:i',Misc::dbtime($vars['duedate'].' '.$vars['time']))):'NULL'); + if($vars['user_id']) + $sql.=', user_id='.db_input($vars['user_id']); if($vars['duedate']) { //We are setting new duedate... $sql.=' ,isoverdue=0'; } diff --git a/include/staff/templates/user-info.tmpl.php b/include/staff/templates/user-info.tmpl.php index 8714da0e553b8f879d40e9fee47c9cce4a417c9a..ddd40743e8494fc9ba1572359cbd6821cc89d1de 100644 --- a/include/staff/templates/user-info.tmpl.php +++ b/include/staff/templates/user-info.tmpl.php @@ -1,4 +1,4 @@ -<h3>User Information — <?php echo $user->getFullName() ?></h3> +<h3><?php echo $user->getFullName() ?></h3> <a class="close" href=""><i class="icon-remove-circle"></i></a> <hr/> <form method="post" action="ajax.php/form/user-info/<?php diff --git a/include/staff/templates/user-lookup.tmpl.php b/include/staff/templates/user-lookup.tmpl.php new file mode 100644 index 0000000000000000000000000000000000000000..b969e64ac109d2a394cd6da2c0e2e04b3acdfd0e --- /dev/null +++ b/include/staff/templates/user-lookup.tmpl.php @@ -0,0 +1,55 @@ +<h3>User Lookup</h3> +<a class="close" href=""><i class="icon-remove-circle"></i></a> +<hr/> +<form method="post" action="" onsubmit="javascript: + var form=$(this), target=$('#client-info'), target_id=$('#user_id'), + user_id=$(this.user_id).val(); + if (user_id) { + target_id.val(user_id); + target.text($('#user-lookup-name').text() + + ' <' + $('#user-lookup-email').text() + '>'); + } + $('#user-lookup').hide(); + $('#overlay').hide(); + return false;"> +<div id="dialog-body"> +<input type="text" style="width:100%" placeholder="Search" id="client-search"/> +<br/><br/> +<i class="icon-user icon-4x pull-left icon-border"></i> +<div><strong id="user-lookup-name"><?php echo $user_info['name']; ?></strong></div> +<div><<span id="user-lookup-email"><?php echo $user_info['email']; ?></span>></div> +<input type="hidden" id="user-lookup-id" name="user_id" value=""/> +<div class="clear"></div> +</div> + <hr style="margin-top:3em"/> + <p class="full-width"> + <span class="buttons" style="float:left"> + <input type="button" value="Cancel" class="close"> + </span> + <span class="buttons" style="float:right"> + <input type="submit" value="Update"> + </span> + </p> +</form> +<div class="clear"></div> +<script type="text/javascript"> +$(function() { + $('#client-search').typeahead({ + source: function (typeahead, query) { + $.ajax({ + url: "ajax.php/users?q="+query, + dataType: 'json', + success: function (data) { + typeahead.process(data); + } + }); + }, + onselect: function (obj) { + $('#user-lookup-name').text(obj.name); + $('#user-lookup-email').text(obj.email); + $('#user-lookup-id').val(obj.id); + }, + property: "/bin/true" + }); +}); +</script> diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index 71ea545a8d75bad6d3dc900f38f1eb7cdef5c2ed..668cd523484926831642b9626a2c2816877d562d 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -13,6 +13,29 @@ if ($_POST) <input type="hidden" name="id" value="<?php echo $ticket->getId(); ?>"> <h2>Update Ticket #<?php echo $ticket->getExtId(); ?></h2> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> + <tbody> + <tr> + <th colspan="2"> + <em><strong>Client Information</strong>: Currently selected client</em> + </th> + </tr> + <?php + $client = User::lookup($info['user_id']); + ?> + <tr><td>Client:</td><td> + <span id="client-info"><?php echo $client->getName(); ?> + <<?php echo $client->getEmail(); ?>></span> + <a class="action-button" style="float:none;overflow:inherit" + href="ajax.php/users/lookup?id=<?php echo $client->getId(); ?>" + onclick="javascript: + $('#overlay').show(); + $('#user-lookup .body').load(this.href); + $('#user-lookup').show(); + return false; + "><i class="icon-edit"></i> Change</a> + <input type="hidden" name="user_id" id="user_id" + value="<?php echo $info['user_id']; ?>" /> + </td></tr> <tbody> <tr> <th colspan="2"> @@ -119,3 +142,6 @@ if ($_POST) <input type="button" name="cancel" value="Cancel" onclick='window.location.href="tickets.php?id=<?php echo $ticket->getId(); ?>"'> </p> </form> +<div style="display:none;" class="dialog draggable" id="user-lookup"> + <div class="body"></div> +</div> diff --git a/scp/ajax.php b/scp/ajax.php index 46fc6385cba5f40b401e5744730bd2763f09dfde..60ea6aa1c128dcb41d4b56bcab298dab03620c2b 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -59,7 +59,10 @@ $dispatcher = patterns('', url_get('^table/export$', 'downloadTabularData'), url_get('^table$', 'getTabularData') )), - url_get('^/users$', array('ajax.users.php:UsersAjaxAPI', 'search')), + url('^/users', patterns('ajax.users.php:UsersAjaxAPI', + url_get('^$', 'search'), + url_get('^/lookup$', 'getLookupForm') + )), url('^/tickets/', patterns('ajax.tickets.php:TicketsAjaxAPI', url_get('^(?P<tid>\d+)/preview', 'previewTicket'), url_post('^(?P<tid>\d+)/lock', 'acquireLock'), diff --git a/scp/css/scp.css b/scp/css/scp.css index b651976d14c8011df8cbc0f0020acd577f1b891c..58ba116646316d268a7799211e5af323359e55ab 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1246,6 +1246,7 @@ time { margin:0; padding:0; position: relative; + padding-right: 3em; } .dialog a.close {