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

Merge branch 'feature/basic-search-revisisted' into develop

parents c11868ce 2d261af2
No related branches found
No related tags found
No related merge requests found
...@@ -22,37 +22,43 @@ class TicketsAjaxAPI extends AjaxController { ...@@ -22,37 +22,43 @@ class TicketsAjaxAPI extends AjaxController {
function search() { function search() {
if(!is_numeric($_REQUEST['q']))
return self::searchByEmail();
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25;
$items=array(); $tickets=array();
$sql='SELECT DISTINCT ticketID, email' $sql='SELECT DISTINCT ticketID, email'
.' FROM '.TICKET_TABLE; .' FROM '.TICKET_TABLE
.' WHERE ticketID LIKE \''.db_input($_REQUEST['q'], false).'%\''
$emailSearch=false; .' ORDER BY created LIMIT '.$limit;
if(is_numeric($_REQUEST['q']))
$sql.=' WHERE ticketID LIKE \''.db_input($_REQUEST['q'], false).'%\''; if(($res=db_query($sql)) && db_num_rows($res)) {
else { while(list($id, $email)=db_fetch_row($res))
$emailSearch=true; $tickets[] = array('id'=>$id, 'email'=>$email, 'value'=>$id, 'info'=>"$id - $email");
$sql.=' WHERE email LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\' ';
} }
$sql.=' ORDER BY created LIMIT '.$limit; return $this->json_encode($tickets);
}
function searchByEmail() {
$limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25;
$tickets=array();
$sql='SELECT email, count(ticket_id) as tickets '
.' FROM '.TICKET_TABLE
.' WHERE email LIKE \'%'.db_input(strtolower($_REQUEST['q']), false).'%\' '
.' GROUP BY email '
.' ORDER BY created LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)) { if(($res=db_query($sql)) && db_num_rows($res)) {
while(list($id,$email,$name)=db_fetch_row($res)) { while(list($email, $count)=db_fetch_row($res))
if($emailSearch) { $tickets[] = array('email'=>$email, 'value'=>$email, 'info'=>"$email ($count)");
$info = "$email - $id";
$value = $email;
} else {
$info = "$id -$email";
$value = $id;
}
$items[] = array('id'=>$id, 'email'=>$email, 'value'=>$value, 'info'=>$info);
}
} }
return $this->json_encode($items); return $this->json_encode($tickets);
} }
function acquireLock($tid) { function acquireLock($tid) {
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<?php
if(defined('AUTO_REFRESH') && is_numeric(AUTO_REFRESH_RATE) && AUTO_REFRESH_RATE>0){ //Refresh rate
echo '<meta http-equiv="refresh" content="'.AUTO_REFRESH_RATE.'" />';
}
?>
<title>osTicket Staff Control Panel</title> <title>osTicket Staff Control Panel</title>
<!--[if IE]> <!--[if IE]>
<style type="text/css"> <style type="text/css">
......
...@@ -210,7 +210,6 @@ $(document).ready(function(){ ...@@ -210,7 +210,6 @@ $(document).ready(function(){
}); });
}, },
onselect: function (obj) { onselect: function (obj) {
$('#basic-ticket-search').val(obj.id); /*overwriting email*/
$('#basic-ticket-search').closest('form').submit(); $('#basic-ticket-search').closest('form').submit();
}, },
property: "value" property: "value"
......
...@@ -456,7 +456,7 @@ if($ticket) { ...@@ -456,7 +456,7 @@ if($ticket) {
$inc = 'ticket-view.inc.php'; $inc = 'ticket-view.inc.php';
if($_REQUEST['a']=='edit' && $thisstaff->canEditTickets()) if($_REQUEST['a']=='edit' && $thisstaff->canEditTickets())
$inc = 'ticket-edit.inc.php'; $inc = 'ticket-edit.inc.php';
}else { } else {
$inc = 'tickets.inc.php'; $inc = 'tickets.inc.php';
if($_REQUEST['a']=='open' && $thisstaff->canCreateTickets()) if($_REQUEST['a']=='open' && $thisstaff->canCreateTickets())
$inc = 'ticket-open.inc.php'; $inc = 'ticket-open.inc.php';
...@@ -470,8 +470,14 @@ if($ticket) { ...@@ -470,8 +470,14 @@ if($ticket) {
elseif (!Export::saveTickets($query, "tickets-$ts.csv", 'csv')) elseif (!Export::saveTickets($query, "tickets-$ts.csv", 'csv'))
$errors['err'] = 'Internal error: Unable to dump query results'; $errors['err'] = 'Internal error: Unable to dump query results';
} }
elseif(!$_POST && $_REQUEST['a']!='search' && ($min=$thisstaff->getRefreshRate()))
define('AUTO_REFRESH',1); //set refresh rate if the user has it configured //Clear active submenu on search with no status
if($_REQUEST['a']=='search' && !$_REQUEST['status'])
$nav->setActiveSubMenu(-1);
//set refresh rate if the user has it configured
if(!$_POST && $_REQUEST['a']!='search' && ($min=$thisstaff->getRefreshRate()))
define('AUTO_REFRESH', $min*60);
} }
require_once(STAFFINC_DIR.'header.inc.php'); require_once(STAFFINC_DIR.'header.inc.php');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment