diff --git a/include/class.config.php b/include/class.config.php index 68704cd7b65523acb6f5610746b4e9741847c962..eaf2aac42bab9e20518c9aad4ff3d94f986b7215 100644 --- a/include/class.config.php +++ b/include/class.config.php @@ -126,6 +126,15 @@ class Config { return false; return true; } + + function destrory() { + + $sql='DELETE FROM '.$this->table + .' WHERE `'.$this->section_column.'` = '.db_input($this->section); + + db_query($sql); + unset($this->session); + } } class OsticketConfig extends Config { diff --git a/include/class.dept.php b/include/class.dept.php index 0fb59d36faffdbb941275e3f364213062f955b4e..d99985b4437bc145cc34d729eee238a83d555d52 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -50,6 +50,7 @@ class Dept { $this->id=$this->ht['dept_id']; $this->email=$this->sla=$this->manager=null; $this->getEmail(); //Auto load email struct. + $this->config = new Config('dept.'.$this->id); $this->members=$this->groups=array(); return true; @@ -99,29 +100,47 @@ class Dept { return count($this->getMembers()); } - function getMembers() { + function getMembers($criteria=null) { - if(!$this->members) { - $this->members = array(); + if(!$this->members || $criteria) { + $members = array(); $sql='SELECT DISTINCT s.staff_id FROM '.STAFF_TABLE.' s ' - .' LEFT JOIN '.GROUP_DEPT_TABLE.' g ON(s.group_id=g.group_id) ' + .' LEFT JOIN '.GROUP_TABLE.' g ON (g.group_id=s.group_id) ' + .' LEFT JOIN '.GROUP_DEPT_TABLE.' gd ON(s.group_id=gd.group_id) ' .' INNER JOIN '.DEPT_TABLE.' d ON(d.dept_id=s.dept_id OR d.manager_id=s.staff_id - OR (d.dept_id=g.dept_id AND d.group_membership=1) + OR (d.dept_id=gd.dept_id AND d.group_membership=1) ) ' - .' WHERE d.dept_id='.db_input($this->getId()) - .' ORDER BY s.lastname, s.firstname'; + .' WHERE d.dept_id='.db_input($this->getId()); + + if ($criteria && $criteria['available']) + $sql .= ' AND + ( g.group_enabled=1 + AND s.isactive=1 + AND s.onvacation=0 ) '; + + $sql.=' ORDER BY s.lastname, s.firstname'; if(($res=db_query($sql)) && db_num_rows($res)) { while(list($id)=db_fetch_row($res)) - $this->members[] = Staff::lookup($id); + $members[$id] = Staff::lookup($id); } + + if ($criteria) + return $members; + + $this->members = $members; + } return $this->members; } + function getAvailableMembers() { + return $this->getMembers(array('available' =>1)); + } + function getSLAId() { return $this->ht['sla_id']; @@ -210,6 +229,9 @@ class Dept { return ($this->ht['noreply_autoresp']); } + function assignMembersOnly() { + return ($this->config->get('assign_members_only', 0)); + } function isGroupMembershipEnabled() { return ($this->ht['group_membership']); @@ -220,11 +242,9 @@ class Dept { } function getInfo() { - return $this->getHashtable(); + return $this->config->getInfo() + $this->getHashtable(); } - - function getAllowedGroups() { if($this->groups) return $this->groups; @@ -240,25 +260,26 @@ class Dept { return $this->groups; } - function updateAllowedGroups($groups) { + function updateSettings($vars) { - if($groups && is_array($groups)) { - foreach($groups as $k=>$id) { + // Groups allowes to access department + if($vars['groups'] && is_array($vars['groups'])) { + foreach($vars['groups'] as $k=>$id) { $sql='INSERT IGNORE INTO '.GROUP_DEPT_TABLE .' SET dept_id='.db_input($this->getId()).', group_id='.db_input($id); db_query($sql); } } - - $sql='DELETE FROM '.GROUP_DEPT_TABLE.' WHERE dept_id='.db_input($this->getId()); - if($groups && is_array($groups)) - $sql.=' AND group_id NOT IN('.implode(',', db_input($groups)).')'; + if($vars['groups'] && is_array($vars['groups'])) + $sql.=' AND group_id NOT IN ('.implode(',', db_input($vars['groups'])).')'; db_query($sql); - return true; + // Misc. config settings + $this->config->set('assign_members_only', $vars['assign_members_only']); + return true; } function update($vars, &$errors) { @@ -266,7 +287,7 @@ class Dept { if(!$this->save($this->getId(), $vars, $errors)) return false; - $this->updateAllowedGroups($vars['groups']); + $this->updateSettings($vars); $this->reload(); return true; @@ -298,6 +319,9 @@ class Dept { //Delete group access db_query('DELETE FROM '.GROUP_DEPT_TABLE.' WHERE dept_id='.db_input($id)); + + // Destrory config settings + $this->config->destroy(); } return $num; @@ -340,6 +364,8 @@ class Dept { if(($manager=$criteria['manager'])) $sql.=' AND manager_id='.db_input(is_object($manager)?$manager->getId():$manager); + $sql.=' ORDER BY dept_name'; + if(($res=db_query($sql)) && db_num_rows($res)) { while(list($id, $name)=db_fetch_row($res)) $depts[$id] = $name; @@ -353,8 +379,12 @@ class Dept { } function create($vars, &$errors) { - if(($id=self::save(0, $vars, $errors)) && ($dept=self::lookup($id))) - $dept->updateAllowedGroups($vars['groups']); + + if(!($id=self::save(0, $vars, $errors))) + return null; + + if (($dept=self::lookup($id))) + $dept->updateSettings($vars); return $id; } diff --git a/include/class.email.php b/include/class.email.php index 17c03532876a68f01b06e19a448cec389574b5a1..0bae5c95a8b644bf372d73b4fa825c008d6e070e 100644 --- a/include/class.email.php +++ b/include/class.email.php @@ -195,6 +195,15 @@ class Email { } + function __toString() { + + $email = $this->getEmail(); + if ($this->getName()) + $email = sprintf('%s <%s>', $this->getName(), $this->getEmail()); + + return $email; + } + /******* Static functions ************/ function getIdByEmail($email) { diff --git a/include/class.staff.php b/include/class.staff.php index ed6a0ae1da7167f2b9b37a6d1031d80051a35ef1..4b28b60929759f9d5a1c38ebcfa9cf63af55e8b5 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -93,12 +93,12 @@ class Staff extends AuthenticatedUser { return $this->__toString(); } - function getHastable() { + function getHashtable() { return $this->ht; } function getInfo() { - return $this->config->getInfo() + $this->getHastable(); + return $this->config->getInfo() + $this->getHashtable(); } // AuthenticatedUser implementation... @@ -585,6 +585,9 @@ class Staff extends AuthenticatedUser { //Cleanup Team membership table. db_query('DELETE FROM '.TEAM_MEMBER_TABLE.' WHERE staff_id='.db_input($this->getId())); + + // Destrory config settings + $this->config->destroy(); } Signal::send('model.deleted', $this); @@ -595,7 +598,7 @@ class Staff extends AuthenticatedUser { /**** Static functions ********/ function getStaffMembers($availableonly=false) { - $sql='SELECT s.staff_id,CONCAT_WS(", ",s.lastname, s.firstname) as name ' + $sql='SELECT s.staff_id, CONCAT_WS(" ", s.firstname, s.lastname) as name ' .' FROM '.STAFF_TABLE.' s '; if($availableonly) { diff --git a/include/class.ticket.php b/include/class.ticket.php index c7dc74953f748102a7526ebee4e58c0812a4e138..943dd0bbc3683e7ed5741f0639f4ce17a445ac9f 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1420,7 +1420,7 @@ class Ticket { if(!is_object($staff) && !($staff=Staff::lookup($staff))) return false; - if(!$this->setStaffId($staff->getId())) + if (!$staff->isAvailable() || !$this->setStaffId($staff->getId())) return false; $this->onAssign($staff, $note, $alert); @@ -1434,7 +1434,7 @@ class Ticket { if(!is_object($team) && !($team=Team::lookup($team))) return false; - if(!$this->setTeamId($team->getId())) + if (!$team->isActive() || !$this->setTeamId($team->getId())) return false; //Clear - staff if it's a closed ticket diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 2a001a4037d5864849f6e5b718227f7270c5648c..d8998bda596885d0f181e67aaa24afb8f9110031 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -147,7 +147,18 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="checkbox" name="group_membership" value="0" <?php echo $info['group_membership']?'checked="checked"':''; ?> > - Extend membership to groups with access. <i>(Alerts and notices will include groups)</i> + Extend membership to groups with access <em>(Alerts and + notices will include groups)</em> + </td> + </tr> + <tr> + <td>Ticket Assignment:</td> + <td> + <input type="checkbox" name="assign_members_only" <?php echo + $info['assign_members_only']?'checked="checked"':''; ?>> + Limit ticket assignment to department members + <!-- Help Tip: + Tickets can ONLY be assigned to department members (+ group members)--> </td> </tr> <tr> diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php index 74e72106859d68501fbc6e490d79a9ddf90a4869..4a6f505c0e837407dae5cdfc90c00b6434a9669b 100644 --- a/include/staff/filter.inc.php +++ b/include/staff/filter.inc.php @@ -281,27 +281,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <td> <select name="assign"> <option value="0">— Unassigned —</option> - - <?php - - - $sql=' SELECT staff_id,CONCAT_WS(", ",lastname,firstname) as name '. - ' FROM '.STAFF_TABLE.' WHERE isactive=1 ORDER BY name'; - - if(($res=db_query($sql)) && db_num_rows($res)){ + if (($users=Staff::getStaffMembers())) { echo '<OPTGROUP label="Staff Members">'; - while (list($id,$name) = db_fetch_row($res)){ + foreach($users as $id => $name) { + $name = new PersonsName($name); $k="s$id"; $selected = ($info['assign']==$k || $info['staff_id']==$id)?'selected="selected"':''; ?> <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option> - - <?php } + <?php + } echo '</OPTGROUP>'; - } - $sql='SELECT team_id, name FROM '.TEAM_TABLE.' WHERE isenabled=1'; + $sql='SELECT team_id, name FROM '.TEAM_TABLE .' ORDER BY name'; if(($res=db_query($sql)) && db_num_rows($res)){ echo '<OPTGROUP label="Teams">'; while (list($id,$name) = db_fetch_row($res)){ diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index 9e9a34d142369997a3ccc32cc499045b4716de9e..071e515dfa1f19e249c4d691cdfb803ddd544f17 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -193,20 +193,20 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="assign"> <option value="0">— Unassigned —</option> <?php - $sql=' SELECT staff_id,CONCAT_WS(", ",lastname,firstname) as name '. - ' FROM '.STAFF_TABLE.' WHERE isactive=1 ORDER BY name'; - if(($res=db_query($sql)) && db_num_rows($res)){ + if (($users=Staff::getStaffMembers())) { echo '<OPTGROUP label="Staff Members">'; - while (list($id,$name) = db_fetch_row($res)){ + foreach ($users as $id => $name) { + $name = new PersonsName($name); $k="s$id"; $selected = ($info['assign']==$k || $info['staff_id']==$id)?'selected="selected"':''; ?> <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option> - <?php } + <?php + } echo '</OPTGROUP>'; } - $sql='SELECT team_id, name FROM '.TEAM_TABLE.' WHERE isenabled=1'; + $sql='SELECT team_id, name FROM '.TEAM_TABLE.' ORDER BY name'; if(($res=db_query($sql)) && db_num_rows($res)){ echo '<OPTGROUP label="Teams">'; while (list($id,$name) = db_fetch_row($res)){ diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 4042692d48e075e196d4b8cbdedec5e15ff08a46..dcce0d8f88de96a0dcc70595057cb8a9a557dac6 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -802,16 +802,25 @@ $tcount+= $ticket->getNumNotes(); echo sprintf('<option value="%d">Claim Ticket (comments optional)</option>', $thisstaff->getId()); $sid=$tid=0; - if(($users=Staff::getAvailableStaffMembers())) { + + if ($dept->assignMembersOnly()) + $users = $dept->getAvailableMembers(); + else + $users = Staff::getAvailableStaffMembers(); + + if ($users) { echo '<OPTGROUP label="Staff Members ('.count($users).')">'; $staffId=$ticket->isAssigned()?$ticket->getStaffId():0; foreach($users as $id => $name) { if($staffId && $staffId==$id) continue; + if (!is_object($name)) + $name = new PersonsName($name); + $k="s$id"; echo sprintf('<option value="%s" %s>%s</option>', - $k,(($info['assignId']==$k)?'selected="selected"':''),$name); + $k,(($info['assignId']==$k)?'selected="selected"':''), $name); } echo '</OPTGROUP>'; }