Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
16601419
Commit
16601419
authored
13 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Add advanced ticket search
parent
f9aff6c3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/ajax.tickets.php
+63
-13
63 additions, 13 deletions
include/ajax.tickets.php
include/staff/tickets.inc.php
+52
-49
52 additions, 49 deletions
include/staff/tickets.inc.php
scp/css/scp.css
+1
-1
1 addition, 1 deletion
scp/css/scp.css
scp/js/scp.js
+4
-4
4 additions, 4 deletions
scp/js/scp.js
with
120 additions
and
67 deletions
include/ajax.tickets.php
+
63
−
13
View file @
16601419
...
...
@@ -88,42 +88,92 @@ class TicketsAjaxAPI extends AjaxController {
global
$thisstaff
;
$result
=
array
();
$s
ql
=
'SELECT count(ticket_id) as tickets '
.
' FROM '
.
TICKET_TABLE
.
' WHERE 1 '
;
$s
elect
=
'SELECT count(ticket
.ticket
_id) as tickets '
;
$from
=
' FROM '
.
TICKET_TABLE
.
' ticket '
;
$where
=
' WHERE 1 '
;
//Access control.
$
sql
.
=
' AND ( staff_id='
.
db_input
(
$thisstaff
->
getId
());
$
where
.
=
' AND (
ticket.
staff_id='
.
db_input
(
$thisstaff
->
getId
());
if
((
$teams
=
$thisstaff
->
getTeams
())
&&
count
(
array_filter
(
$teams
)))
$
sql
.
=
' OR team_id IN('
.
implode
(
','
,
array_filter
(
$teams
))
.
')'
;
$
where
.
=
' OR
ticket.
team_id IN('
.
implode
(
','
,
array_filter
(
$teams
))
.
')'
;
if
(
!
$thisstaff
->
showAssignedOnly
()
&&
(
$depts
=
$thisstaff
->
getDepts
()))
$
sql
.
=
' OR dept_id IN ('
.
implode
(
','
,
$depts
)
.
')'
;
$
where
.
=
' OR
ticket.
dept_id IN ('
.
implode
(
','
,
$depts
)
.
')'
;
$
sql
.
=
' ) '
;
$
where
.
=
' ) '
;
//Department
if
(
$_REQUEST
[
'deptId'
])
$
sql
.
=
' AND dept_id='
.
db_input
(
$_REQUEST
[
'deptId'
]);
$
where
.
=
' AND
ticket.
dept_id='
.
db_input
(
$_REQUEST
[
'deptId'
]);
//Status
switch
(
strtolower
(
$_REQUEST
[
'status'
]))
{
case
'open'
;
$
sql
.
=
' AND status="open" '
;
$
where
.
=
' AND
ticket.
status="open" '
;
break
;
case
'overdue'
:
$
sql
.
=
' AND status="open"
and
isoverdue=1 '
;
$
where
.
=
' AND
ticket.
status="open"
AND ticket.
isoverdue=1 '
;
break
;
case
'closed'
:
$
sql
.
=
' AND status="closed" '
;
$
where
.
=
' AND
ticket.
status="closed" '
;
break
;
}
//Assignee
if
(
$_REQUEST
[
'assignee'
]
&&
strcasecmp
(
$_REQUEST
[
'status'
],
'closed'
))
{
$id
=
preg_replace
(
"/[^0-9]/"
,
""
,
$_REQUEST
[
'assignee'
]);
$assignee
=
$_REQUEST
[
'assignee'
];
$where
.
=
' AND ( '
;
if
(
$assignee
[
0
]
==
't'
)
$where
.
=
' (ticket.team_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
elseif
(
$assignee
[
0
]
==
's'
)
$where
.
=
' (ticket.staff_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
else
$where
.
=
' (ticket.staff_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
if
(
$_REQUEST
[
'staffId'
]
&&
!
$_REQUEST
[
'status'
])
//Assigned TO + Closed By
$where
.
=
' OR (ticket.staff_id='
.
db_input
(
$_REQUEST
[
'staffId'
])
.
' AND ticket.status="closed") '
;
$where
.
=
' ) '
;
}
elseif
(
$_REQUEST
[
'staffId'
])
{
$where
.
=
' AND (ticket.staff_id='
.
db_input
(
$_REQUEST
[
'staffId'
])
.
' AND ticket.status="closed") '
;
}
//dates
$startTime
=
(
$_REQUEST
[
'startDate'
]
&&
(
strlen
(
$_REQUEST
[
'startDate'
])
>=
8
))
?
strtotime
(
$_REQUEST
[
'startDate'
])
:
0
;
$endTime
=
(
$_REQUEST
[
'endDate'
]
&&
(
strlen
(
$_REQUEST
[
'endDate'
])
>=
8
))
?
strtotime
(
$_REQUEST
[
'endDate'
])
:
0
;
if
(
(
$startTime
&&
$startTime
>
time
())
or
(
$startTime
>
$endTime
&&
$endTime
>
0
))
$startTime
=
$endTime
=
0
;
//Have fun with dates.
if
(
$startTime
)
$qwhere
.
=
' AND ticket.created>=FROM_UNIXTIME('
.
$startTime
.
')'
;
if
(
$endTime
)
$qwhere
.
=
' AND ticket.created<=FROM_UNIXTIME('
.
$endTime
.
')'
;
//Query
if
(
$_REQUEST
[
'query'
])
{
$queryterm
=
db_real_escape
(
$_REQUEST
[
'query'
],
false
);
$from
.
=
' LEFT JOIN '
.
TICKET_THREAD_TABLE
.
' thread ON (ticket.ticket_id=thread.ticket_id )'
;
$where
.
=
" AND ( ticket.email LIKE '%
$queryterm
%'"
.
" OR ticket.name LIKE '%
$queryterm
%'"
.
" OR ticket.subject LIKE '%
$queryterm
%'"
.
" OR thread.title LIKE '%
$queryterm
%'"
.
" OR thread.body LIKE '%
$queryterm
%'"
.
' )'
;
$groupby
=
'GROUP BY ticket.ticket_id '
;
}
$sql
=
"
$select
$from
$where
$groupby
"
;
if
((
$tickets
=
db_result
(
db_query
(
$sql
))))
{
$result
[
'success'
]
=
"Search criteria matched
$tickets
tickets - view"
;
$result
[
'success'
]
=
sprintf
(
"Search criteria matched %s - <a href='tickets.php?%s'>view</a>"
,
(
$tickets
>
1
?
"
$tickets
tickets"
:
"
$tickets
ticket"
),
str_replace
(
array
(
'&'
,
'&'
),
array
(
'&'
,
'&'
),
$_SERVER
[
'QUERY_STRING'
]));
}
else
{
$result
[
'fail'
]
=
'No tickets found matching your search criteria.'
.
$tickets
;
$result
[
'fail'
]
=
'No tickets found matching your search criteria.'
;
}
return
$this
->
json_encode
(
$result
);
...
...
This diff is collapsed.
Click to expand it.
include/staff/tickets.inc.php
+
52
−
49
View file @
16601419
...
...
@@ -42,6 +42,7 @@ switch(strtolower($_REQUEST['status'])){ //Status is overloaded
case
'assigned'
:
$status
=
'open'
;
$staffId
=
$thisstaff
->
getId
();
$results_type
=
'My Tickets'
;
break
;
case
'answered'
:
$status
=
'open'
;
...
...
@@ -130,15 +131,36 @@ if($search):
}
}
//department
if
(
$_REQUEST
[
'dept'
]
&&
in_array
(
$_REQUEST
[
'dept'
],
$thisstaff
->
getDepts
()))
{
if
(
$_REQUEST
[
'dept
Id
'
]
&&
in_array
(
$_REQUEST
[
'dept
Id
'
],
$thisstaff
->
getDepts
()))
{
//This is dept based search..perm taken care above..put the sucker in.
$qwhere
.
=
' AND ticket.dept_id='
.
db_input
(
$_REQUEST
[
'dept'
]);
$qstr
.
=
'&dept='
.
urlencode
(
$_REQUEST
[
'dept'
]);
$qwhere
.
=
' AND ticket.dept_id='
.
db_input
(
$_REQUEST
[
'dept
Id
'
]);
$qstr
.
=
'&dept
Id
='
.
urlencode
(
$_REQUEST
[
'dept
Id
'
]);
}
//Teams
if
(
$_REQUEST
[
'team'
]
&&
(
$thisuser
->
isadmin
()
||
in_array
(
$_REQUEST
[
'team'
],
$thisuser
->
getTeams
())))
{
$qwhere
.
=
' AND ticket.team_id='
.
db_input
(
$_REQUEST
[
'team'
]);
$qstr
.
=
'&team='
.
urlencode
(
$_REQUEST
[
'team'
]);
//Assignee
if
(
$_REQUEST
[
'assignee'
]
&&
strcasecmp
(
$_REQUEST
[
'status'
],
'closed'
))
{
$id
=
preg_replace
(
"/[^0-9]/"
,
""
,
$_REQUEST
[
'assignee'
]);
$assignee
=
$_REQUEST
[
'assignee'
];
$qstr
.
=
'&assignee='
.
urlencode
(
$_REQUEST
[
'assignee'
]);
$qwhere
.
=
' AND ( '
;
if
(
$assignee
[
0
]
==
't'
)
$qwhere
.
=
' (ticket.team_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
elseif
(
$assignee
[
0
]
==
's'
)
$qwhere
.
=
' (ticket.staff_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
else
$qwhere
.
=
' (ticket.staff_id='
.
db_input
(
$id
)
.
' AND ticket.status="open") '
;
if
(
$_REQUEST
[
'staffId'
]
&&
!
$_REQUEST
[
'status'
])
{
//Assigned TO + Closed By
$qwhere
.
=
' OR (ticket.staff_id='
.
db_input
(
$_REQUEST
[
'staffId'
])
.
' AND ticket.status="closed") '
;
$qstr
.
=
'&staffId='
.
urlencode
(
$_REQUEST
[
'staffId'
]);
}
$qwhere
.
=
' ) '
;
}
elseif
(
$_REQUEST
[
'staffId'
])
{
$qwhere
.
=
' AND (ticket.staff_id='
.
db_input
(
$_REQUEST
[
'staffId'
])
.
' AND ticket.status="closed") '
;
$qstr
.
=
'&staffId='
.
urlencode
(
$_REQUEST
[
'staffId'
]);
}
//dates
...
...
@@ -158,7 +180,7 @@ if($search):
$qwhere
.
=
' AND ticket.created<=FROM_UNIXTIME('
.
$endTime
.
')'
;
$qstr
.
=
'&endDate='
.
urlencode
(
$_REQUEST
[
'endDate'
]);
}
}
}
endif
;
...
...
@@ -215,9 +237,7 @@ $pageNav->setURL('tickets.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&ord
//ADD attachment,priorities, lock and other crap
$qselect
.
=
' ,count(attach.attach_id) as attachments '
.
' ,count(DISTINCT message.id) as messages '
.
' ,count(DISTINCT response.id) as responses '
.
' ,count(DISTINCT note.id) as notes '
.
' ,count(DISTINCT thread.id) as thread_count '
.
' ,IF(ticket.reopened is NULL,IF(ticket.lastmessage is NULL,ticket.created,ticket.lastmessage),ticket.reopened) as effective_date '
.
' ,CONCAT_WS(" ", staff.firstname, staff.lastname) as staff, team.name as team '
.
' ,IF(staff.staff_id IS NULL,team.name,CONCAT_WS(" ", staff.lastname, staff.firstname)) as assigned '
;
...
...
@@ -226,12 +246,7 @@ $qfrom.=' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (ticket.priority_id=pri.pri
.
' LEFT JOIN '
.
TICKET_LOCK_TABLE
.
' tlock ON (ticket.ticket_id=tlock.ticket_id AND tlock.expire>NOW()
AND tlock.staff_id!='
.
db_input
(
$thisstaff
->
getId
())
.
') '
.
' LEFT JOIN '
.
TICKET_ATTACHMENT_TABLE
.
' attach ON (ticket.ticket_id=attach.ticket_id) '
.
' LEFT JOIN '
.
TICKET_THREAD_TABLE
.
' message ON ('
.
'ticket.ticket_id=message.ticket_id AND message.thread_type="M") '
.
' LEFT JOIN '
.
TICKET_THREAD_TABLE
.
' response ON ('
.
'ticket.ticket_id=response.ticket_id AND response.thread_type="R") '
.
' LEFT JOIN '
.
TICKET_THREAD_TABLE
.
' note ON ('
.
'ticket.ticket_id=note.ticket_id AND note.thread_type="N") '
.
' LEFT JOIN '
.
TICKET_THREAD_TABLE
.
' thread ON ( ticket.ticket_id=thread.ticket_id) '
.
' LEFT JOIN '
.
STAFF_TABLE
.
' staff ON (ticket.staff_id=staff.staff_id) '
.
' LEFT JOIN '
.
TEAM_TABLE
.
' team ON (ticket.team_id=team.team_id) '
;
...
...
@@ -241,9 +256,12 @@ $hash = md5($query);
$_SESSION
[
'search_'
.
$hash
]
=
$query
;
$res
=
db_query
(
$query
);
$showing
=
db_num_rows
(
$res
)
?
$pageNav
->
showing
()
:
""
;
if
(
!
$results_type
)
{
$results_type
=
(
$search
)
?
'Search Results'
:
ucfirst
(
$status
)
.
' Tickets'
;
}
if
(
!
$results_type
)
$results_type
=
ucfirst
(
$status
)
.
' Tickets'
;
if
(
$search
)
$results_type
.
=
' (Search Results)'
;
$negorder
=
$order
==
'DESC'
?
'ASC'
:
'DESC'
;
//Negate the sorting..
//YOU BREAK IT YOU FIX IT.
...
...
@@ -295,7 +313,7 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
title=
"Sort By Status
<?php
echo
$negorder
;
?>
"
>
Status
</a></th>
<?php
}
else
{
?>
<th
width=
"60"
<?
=
$pri_sort
?>
>
<th
width=
"60"
<?
php
echo
$pri_sort
;
?>
>
<a
<?php
echo
$pri_sort
;
?>
href=
"tickets.php?sort=pri&order=
<?php
echo
$negorder
;
?><?php
echo
$qstr
;
?>
"
title=
"Sort By Priority
<?php
echo
$negorder
;
?>
"
>
Priority
</a></th>
<?php
...
...
@@ -305,15 +323,18 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
<th
width=
"150"
>
<a
<?php
echo
$assignee_sort
;
?>
href=
"tickets.php?sort=assignee&order=
<?php
echo
$negorder
;
?><?php
echo
$qstr
;
?>
"
title=
"Sort By Assignee
<?php
echo
$negorder
;
?>
"
>
Assigned To
</a></th>
<?
}
elseif
(
!
strcasecmp
(
$status
,
'closed'
)){
?>
<?php
}
elseif
(
!
strcasecmp
(
$status
,
'closed'
))
{
?>
<th
width=
"150"
>
<a
<?php
echo
$staff_sort
;
?>
href=
"tickets.php?sort=staff&order=
<?php
echo
$negorder
;
?><?php
echo
$qstr
;
?>
"
title=
"Sort By Closing Staff Name
<?php
echo
$negorder
;
?>
"
>
Closed By
</a></th>
<?
}
else
{
?>
<?php
}
else
{
?>
<th
width=
"150"
>
<a
<?=
$dept_sort
?>
href=
"tickets.php?sort=dept&order=
<?=
$negorder
?><?=
$qstr
?>
"
title=
"Sort By Department
<?=
$negorder
?>
"
>
Department
</a></th>
<?
}
?>
<a
<?php
echo
$dept_sort
;
?>
href=
"tickets.php?sort=dept&order=
<?php
echo
$negorder
;
?><?php
echo
$qstr
;
?>
"
title=
"Sort By Department
<?php
echo
$negorder
;
?>
"
>
Department
</a></th>
<?php
}
?>
</tr>
</thead>
<tbody>
...
...
@@ -342,7 +363,7 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
}
$tid
=
$row
[
'ticketID'
];
$subject
=
Format
::
truncate
(
$row
[
'subject'
],
40
);
$threadcount
=
$row
[
'
messages'
]
+
$row
[
'responses
'
];
$threadcount
=
$row
[
'
thread_count
'
];
if
(
!
strcasecmp
(
$row
[
'status'
],
'open'
)
&&
!
$row
[
'isanswered'
]
&&
!
$row
[
'lock_id'
])
{
$tid
=
sprintf
(
'<b>%s</b>'
,
$tid
);
}
...
...
@@ -476,8 +497,8 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
</select>
</fieldset>
<fieldset
class=
"owner"
>
<label
for=
"assignee
Id
"
>
Assigned To:
</label>
<select
id=
"assignee
Id
"
name=
"assignee
Id
"
>
<label
for=
"assignee"
>
Assigned To:
</label>
<select
id=
"assignee"
name=
"assignee"
>
<option
value=
"0"
>
—
Anyone
—
</option>
<?php
if
((
$users
=
Staff
::
getStaffMembers
()))
{
...
...
@@ -504,10 +525,8 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
<option
value=
"0"
>
—
Anyone
—
</option>
<?php
if
((
$users
=
Staff
::
getStaffMembers
()))
{
foreach
(
$users
as
$id
=>
$name
)
{
$k
=
"s
$id
"
;
echo
sprintf
(
'<option value="%s">%s</option>'
,
$k
,
$name
);
}
foreach
(
$users
as
$id
=>
$name
)
echo
sprintf
(
'<option value="%d">%s</option>'
,
$id
,
$name
);
}
?>
</select>
...
...
@@ -518,22 +537,6 @@ $negorder=$order=='DESC'?'ASC':'DESC'; //Negate the sorting..
<span>
TO
</span>
<input
class=
"dp"
type=
"input"
size=
"20"
name=
"endDate"
><i></i>
</fieldset>
<fieldset
class=
"sorting"
>
<label>
Sorting:
</label>
<select
name=
"sort"
>
<option
value=
"date"
>
Create Date
</option>
</select>
<select
name=
"order"
>
<option
value=
"desc"
>
Descending
</option>
<option
value=
"asc"
>
Ascending
</option>
</select>
<select
name=
"limit"
>
<option
value=
"25"
>
25 records/page
</option>
<option
value=
"50"
selected=
"selected"
>
50 records/page
</option>
<option
value=
"75"
>
75 records/page
</option>
<option
value=
"100"
>
100 records/page
</option>
</select>
</fieldset>
<p>
<span
class=
"buttons"
>
<input
type=
"submit"
value=
"Search"
>
...
...
This diff is collapsed.
Click to expand it.
scp/css/scp.css
+
1
−
1
View file @
16601419
...
...
@@ -1081,7 +1081,7 @@ h2 .reload {
position
:
absolute
;
padding
:
1em
;
width
:
640px
;
height
:
40
0px
;
height
:
36
0px
;
background
:
#fff
;
border
:
1px
solid
#2a67ac
;
display
:
none
;
...
...
This diff is collapsed.
Click to expand it.
scp/js/scp.js
+
4
−
4
View file @
16601419
...
...
@@ -264,19 +264,19 @@ $(document).ready(function(){
}).
delegate
(
'
#status
'
,
'
change
'
,
function
()
{
switch
(
$
(
this
).
val
())
{
case
'
closed
'
:
$
(
'
select#assignee
Id
'
).
find
(
'
option:first
'
).
attr
(
'
selected
'
,
'
selected
'
).
parent
(
'
select
'
);
$
(
'
select#assignee
Id
'
).
attr
(
'
disabled
'
,
'
disabled
'
);
$
(
'
select#assignee
'
).
find
(
'
option:first
'
).
attr
(
'
selected
'
,
'
selected
'
).
parent
(
'
select
'
);
$
(
'
select#assignee
'
).
attr
(
'
disabled
'
,
'
disabled
'
);
$
(
'
select#staffId
'
).
removeAttr
(
'
disabled
'
);
break
;
case
'
open
'
:
case
'
overdue
'
:
$
(
'
select#staffId
'
).
find
(
'
option:first
'
).
attr
(
'
selected
'
,
'
selected
'
).
parent
(
'
select
'
);
$
(
'
select#staffId
'
).
attr
(
'
disabled
'
,
'
disabled
'
);
$
(
'
select#assignee
Id
'
).
removeAttr
(
'
disabled
'
);
$
(
'
select#assignee
'
).
removeAttr
(
'
disabled
'
);
break
;
default
:
$
(
'
select#staffId
'
).
removeAttr
(
'
disabled
'
);
$
(
'
select#assignee
Id
'
).
removeAttr
(
'
disabled
'
);
$
(
'
select#assignee
'
).
removeAttr
(
'
disabled
'
);
}
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment