From 801e89a6f8507d13c8d9e834bf291eff8bd44708 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Mon, 16 Jul 2012 00:49:36 -0400
Subject: [PATCH] Show the number of departments a group is allowed to access

---
 include/staff/groups.inc.php | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/staff/groups.inc.php b/include/staff/groups.inc.php
index ed5e3638a..5c8393e99 100644
--- a/include/staff/groups.inc.php
+++ b/include/staff/groups.inc.php
@@ -3,10 +3,13 @@ if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access
 
 $qstr='';
 
-$sql='SELECT grp.*,count(staff.staff_id) as users '
-     .' FROM '.GROUP_TABLE.' grp LEFT JOIN '.STAFF_TABLE.' staff USING(group_id) ';
-$sql.=' WHERE 1';
-$sortOptions=array('name'=>'grp.group_name','status'=>'grp.group_enabled','users'=>'users','created'=>'grp.created','updated'=>'grp.updated');
+$sql='SELECT grp.*,count(staff.staff_id) as users, count(dept.dept_id) as depts '
+     .' FROM '.GROUP_TABLE.' grp '
+     .' LEFT JOIN '.STAFF_TABLE.' staff ON(staff.group_id=grp.group_id) '
+     .' LEFT JOIN '.GROUP_DEPT_TABLE.' dept ON(dept.group_id=grp.group_id) '
+     .' WHERE 1';
+$sortOptions=array('name'=>'grp.group_name','status'=>'grp.group_enabled', 
+                   'users'=>'users', 'depts'=>'depts', 'created'=>'grp.created','updated'=>'grp.updated');
 $orderWays=array('DESC'=>'DESC','ASC'=>'ASC');
 $sort=($_REQUEST['sort'] && $sortOptions[strtolower($_REQUEST['sort'])])?strtolower($_REQUEST['sort']):'name';
 //Sorting options...
@@ -49,9 +52,10 @@ else
     <thead>
         <tr>
             <th width="7px">&nbsp;</th>        
-            <th width="250"><a <?php echo $name_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=name">Group Name</a></th>
-            <th width="80"><a  <?php echo $status_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=status">Group Status</a></th>
+            <th width="200"><a <?php echo $name_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=name">Group Name</a></th>
+            <th width="80"><a  <?php echo $status_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=status">Status</a></th>
             <th width="80" style="text-align:center;"><a  <?php echo $users_sort; ?>href="groups.php?<?php echo $qstr; ?>&sort=users">Members</a></th>
+            <th width="80" style="text-align:center;"><a  <?php echo $depts_sort; ?>href="groups.php?<?php echo $qstr; ?>&sort=depts">Departments</a></th>
             <th width="100"><a  <?php echo $created_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=created">Created On</a></th>
             <th width="120"><a  <?php echo $updated_sort; ?> href="groups.php?<?php echo $qstr; ?>&sort=updated">Last Updated</a></th>
         </tr>
@@ -81,6 +85,9 @@ else
                     <?php } ?>
                     &nbsp;
                 </td>
+                <td style="text-align:right;padding-right:30px">&nbsp;&nbsp;
+                    <?php echo $row['depts']; ?>
+                </td>
                 <td><?php echo Format::db_date($row['created']); ?>&nbsp;</td>
                 <td><?php echo Format::db_datetime($row['updated']); ?>&nbsp;</td>
             </tr>
-- 
GitLab