Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
46c42b91
Commit
46c42b91
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
orm: Convert staff directory to ORM
parent
2b422844
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.dept.php
+8
-0
8 additions, 0 deletions
include/class.dept.php
include/staff/directory.inc.php
+48
-48
48 additions, 48 deletions
include/staff/directory.inc.php
with
56 additions
and
48 deletions
include/class.dept.php
+
8
−
0
View file @
46c42b91
...
...
@@ -381,6 +381,14 @@ class Dept extends VerySimpleModel {
$query
->
filter
(
array
(
'manager_id'
=>
is_object
(
$manager
)
?
$manager
->
getId
()
:
$manager
));
if
(
isset
(
$criteria
[
'nonempty'
]))
{
$query
->
annotate
(
array
(
'user_count'
=>
SqlAggregate
::
COUNT
(
'members'
)
))
->
filter
(
array
(
'user_count__gt'
=>
0
));
}
$query
->
order_by
(
'name'
)
->
values_flat
(
'id'
,
'name'
);
...
...
This diff is collapsed.
Click to expand it.
include/staff/directory.inc.php
+
48
−
48
View file @
46c42b91
...
...
@@ -6,59 +6,67 @@ $from='FROM '.STAFF_TABLE.' staff '.
'LEFT JOIN '
.
DEPT_TABLE
.
' dept ON(staff.dept_id=dept.dept_id) '
;
$where
=
'WHERE staff.isvisible=1 '
;
$agents
=
Staff
::
objects
()
->
filter
(
array
(
'isvisible'
=>
1
))
->
select_related
(
'dept'
);
if
(
$_REQUEST
[
'q'
])
{
$searchTerm
=
$_REQUEST
[
'q'
];
if
(
$searchTerm
){
$query
=
db_real_escape
(
$searchTerm
,
false
);
//escape the term ONLY...no quotes.
if
(
is_numeric
(
$searchTerm
)){
$where
.
=
" AND (staff.phone LIKE '%
$query
%' OR staff.phone_ext LIKE '%
$query
%' OR staff.mobile LIKE '%
$query
%') "
;
$agents
->
filter
(
Q
::
any
(
array
(
'phone__contains'
=>
$searchTerm
,
'phone_ext__contains'
=>
$searchTerm
,
'mobile__contains'
=>
$searchTerm
,
)));
}
elseif
(
strpos
(
$searchTerm
,
'@'
)
&&
Validator
::
is_email
(
$searchTerm
)){
$
where
.
=
" AND staff.email='
$query
'"
;
$
agents
->
filter
(
array
(
'email'
=>
$searchTerm
))
;
}
else
{
$where
.
=
" AND ( staff.email LIKE '%
$query
%'"
.
" OR staff.lastname LIKE '%
$query
%'"
.
" OR staff.firstname LIKE '%
$query
%'"
.
' ) '
;
$agents
->
filter
(
Q
::
any
(
array
(
'email__contains'
=>
$searchTerm
,
'lastname__contains'
=>
$searchTerm
,
'firstname__contains'
=>
$searchTerm
,
)));
}
}
}
if
(
$_REQUEST
[
'did'
]
&&
is_numeric
(
$_REQUEST
[
'did'
]))
{
$
where
.
=
' AND staff.dept_id='
.
db_input
(
$_REQUEST
[
'did'
]);
$
agents
->
filter
(
array
(
'dept'
=>
$_REQUEST
[
'did'
])
)
;
$qstr
.
=
'&did='
.
urlencode
(
$_REQUEST
[
'did'
]);
}
$sortOptions
=
array
(
'name'
=>
'
staff.
firstname,
staff.
lastname'
,
'email'
=>
'
staff.
email'
,
'dept'
=>
'dept
.
name'
,
'phone'
=>
'
staff.
phone'
,
'mobile'
=>
'
staff.
mobile'
,
'ext'
=>
'phone_ext'
,
'created'
=>
'
staff.
created'
,
'login'
=>
'
staff.
lastlogin'
);
$orderWays
=
array
(
'DESC'
=>
'
DESC
'
,
'ASC'
=>
'
ASC
'
);
$sortOptions
=
array
(
'name'
=>
'firstname,lastname'
,
'email'
=>
'email'
,
'dept'
=>
'dept
__
name'
,
'phone'
=>
'phone'
,
'mobile'
=>
'mobile'
,
'ext'
=>
'phone_ext'
,
'created'
=>
'created'
,
'login'
=>
'lastlogin'
);
$orderWays
=
array
(
'DESC'
=>
'
-
'
,
'ASC'
=>
''
);
$sort
=
(
$_REQUEST
[
'sort'
]
&&
$sortOptions
[
strtolower
(
$_REQUEST
[
'sort'
])])
?
strtolower
(
$_REQUEST
[
'sort'
])
:
'name'
;
//Sorting options...
if
(
$sort
&&
$sortOptions
[
$sort
])
{
$order_column
=
$sortOptions
[
$sort
];
}
$order_column
=
$order_column
?
$order_column
:
'staff.
firstname,
staff.
lastname'
;
$order_column
=
$order_column
?:
'
firstname,lastname'
;
if
(
$_REQUEST
[
'order'
]
&&
$orderWays
[
strtoupper
(
$_REQUEST
[
'order'
])])
{
$order
=
$orderWays
[
strtoupper
(
$_REQUEST
[
'order'
])];
}
$order
=
$order
?
$order
:
'ASC'
;
if
(
$order_column
&&
strpos
(
$order_column
,
','
)){
$order_column
=
str_replace
(
','
,
"
$order
,"
,
$order_column
);
}
$x
=
$sort
.
'_sort'
;
$$x
=
' class="'
.
strtolower
(
$order
)
.
'" '
;
$order_by
=
"
$order_column
$order
"
;
$$x
=
' class="'
.
strtolower
(
$_REQUEST
[
'order'
]
?:
'desc'
)
.
'" '
;
foreach
(
explode
(
','
,
$order_column
)
as
$C
)
{
$agents
->
order_by
(
$order
.
$C
);
}
$total
=
db_count
(
'SELECT count(DISTINCT staff.staff_id) '
.
$from
.
' '
.
$where
);
$total
=
$agents
->
count
(
);
$page
=
(
$_GET
[
'p'
]
&&
is_numeric
(
$_GET
[
'p'
]))
?
$_GET
[
'p'
]
:
1
;
$pageNav
=
new
Pagenate
(
$total
,
$page
,
PAGE_LIMIT
);
$pageNav
->
setURL
(
'directory.php'
,
$qstr
.
'&sort='
.
urlencode
(
$_REQUEST
[
'sort'
])
.
'&order='
.
urlencode
(
$_REQUEST
[
'order'
]));
$pageNav
->
paginate
(
$agents
);
//Ok..lets roll...create the actual query
$qstr
.
=
'&order='
.
(
$order
==
'DESC'
?
'ASC'
:
'DESC'
);
$query
=
"
$select
$from
$where
GROUP BY staff.staff_id ORDER BY
$order_by
LIMIT "
.
$pageNav
->
getStart
()
.
","
.
$pageNav
->
getLimit
();
//echo $query;
$qstr
.
=
'&order='
.
(
$order
==
'-'
?
'ASC'
:
'DESC'
);
?>
<h2>
<?php
echo
__
(
'Agents'
);
?>
<i
class=
"help-tip icon-question-sign"
href=
"#staff_members"
></i></h2>
...
...
@@ -68,16 +76,10 @@ $query="$select $from $where GROUP BY staff.staff_id ORDER BY $order_by LIMIT ".
<select
name=
"did"
id=
"did"
>
<option
value=
"0"
>
—
<?php
echo
__
(
'All Departments'
);
?>
—
</option>
<?php
$sql
=
'SELECT dept.dept_id, dept.name as dept,count(staff.staff_id) as users '
.
'FROM '
.
DEPT_TABLE
.
' dept '
.
'INNER JOIN '
.
STAFF_TABLE
.
' staff ON(staff.dept_id=dept.dept_id AND staff.isvisible=1) '
.
'GROUP By dept.dept_id HAVING users>0 ORDER BY dept.name'
;
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
)){
while
(
list
(
$id
,
$name
,
$users
)
=
db_fetch_row
(
$res
)){
$sel
=
(
$_REQUEST
[
'did'
]
&&
$_REQUEST
[
'did'
]
==
$id
)
?
'selected="selected"'
:
''
;
echo
sprintf
(
'<option value="%d" %s>%s (%s)</option>'
,
$id
,
$sel
,
$name
,
$users
);
}
}
foreach
(
Dept
::
getDepartments
(
array
(
'nonempty'
=>
1
))
as
$id
=>
$name
)
{
$sel
=
(
$_REQUEST
[
'did'
]
&&
$_REQUEST
[
'did'
]
==
$id
)
?
'selected="selected"'
:
''
;
echo
sprintf
(
'<option value="%d" %s>%s</option>'
,
$id
,
$sel
,
$name
);
}
?>
</select>
...
...
@@ -87,8 +89,7 @@ $query="$select $from $where GROUP BY staff.staff_id ORDER BY $order_by LIMIT ".
</div>
<div
class=
"clear"
></div>
<?php
$res
=
db_query
(
$query
);
if
(
$res
&&
(
$num
=
db_num_rows
(
$res
)))
if
(
$agents
->
exists
(
true
))
$showing
=
$pageNav
->
showing
();
else
$showing
=
__
(
'No agents found!'
);
...
...
@@ -107,24 +108,23 @@ else
</thead>
<tbody>
<?php
if
(
$res
&&
db_num_rows
(
$res
))
:
$ids
=
(
$errors
&&
is_array
(
$_POST
[
'ids'
]))
?
$_POST
[
'ids'
]
:
null
;
while
(
$row
=
db_fetch_array
(
$res
))
{
?>
<tr
id=
"
<?php
echo
$row
[
'staff_id'
];
?>
"
>
<td>
<?php
echo
Format
::
htmlchars
(
$row
[
'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>
<td>
<?php
echo
$row
[
'phone_ext'
];
?>
</td>
<td>
<?php
echo
Format
::
phone
(
$row
[
'mobile'
]);
?>
</td>
</tr>
$ids
=
(
$errors
&&
is_array
(
$_POST
[
'ids'
]))
?
$_POST
[
'ids'
]
:
null
;
foreach
(
$agents
as
$A
)
{
?>
<tr
id=
"
<?php
echo
$A
->
staff_id
;
?>
"
>
<td>
<?php
echo
Format
::
htmlchars
(
$A
->
getName
());
?>
</td>
<td>
<?php
echo
Format
::
htmlchars
((
string
)
$A
->
dept
);
?>
</td>
<td>
<?php
echo
Format
::
htmlchars
(
$A
->
email
);
?>
</td>
<td>
<?php
echo
Format
::
phone
(
$A
->
phone
);
?>
</td>
<td>
<?php
echo
$A
->
phone_ext
;
?>
</td>
<td>
<?php
echo
Format
::
phone
(
$A
->
mobile
);
?>
</td>
</tr>
<?php
}
//end of
while.
endif
;
?>
}
//
end of
foreach
?>
<tfoot>
<tr>
<td
colspan=
"6"
>
<?php
if
(
$
res
&&
$num
)
{
<?php
if
(
$
agents
->
exists
(
true
)
)
{
echo
'<div> '
.
__
(
'Page'
)
.
':'
.
$pageNav
->
getPageLinks
()
.
' </div>'
;
?>
<?php
}
else
{
...
...
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