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

Add ability to manage groups (access) on department add/edit.

parent 801e89a6
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,9 @@ class Dept {
var $email;
var $sla;
var $manager;
var $members;
var $groups;
var $ht;
function Dept($id){
......@@ -47,7 +50,7 @@ class Dept {
$this->id=$this->ht['dept_id'];
$this->email=$this->sla=$this->manager=null;
$this->getEmail(); //Auto load email struct.
$this->members=array();
$this->members=$this->groups=array();
return true;
}
......@@ -113,7 +116,6 @@ class Dept {
}
function getSLAId(){
return $this->ht['sla_id'];
}
......@@ -202,14 +204,53 @@ class Dept {
return $this->getHashtable();
}
function update($vars,&$errors){
if($this->save($this->getId(),$vars,$errors)) {
$this->reload();
return true;
function getAllowedGroups() {
if($this->groups) return $this->groups;
$sql='SELECT group_id FROM '.GROUP_DEPT_TABLE
.' WHERE dept_id='.db_input($this->getId());
if(($res=db_query($sql)) && db_num_rows($res)) {
while(list($id)=db_fetch_row($res))
$this->groups[] = $id;
}
return false;
return $this->groups;
}
function updateAllowedGroups($groups) {
if($groups) {
foreach($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)
$sql.=' AND group_id NOT IN('.implode(',', db_input($groups)).')';
db_query($sql);
return true;
}
function update($vars,&$errors){
if(!$this->save($this->getId(),$vars,$errors))
return false;
$this->updateAllowedGroups($vars['groups']);
$this->reload();
return true;
}
function delete() {
......@@ -282,7 +323,10 @@ class Dept {
}
function create($vars,&$errors) {
return Dept::save(0,$vars,$errors);
if(($id=self::save(0, $vars, $errors)) && ($dept=self::lookup($id)))
$dept->updateAllowedGroups($vars['groups']);
return $id;
}
function save($id,$vars,&$errors) {
......
......@@ -9,6 +9,8 @@ if($dept && $_REQUEST['a']!='add') {
$submit_text='Save Changes';
$info=$dept->getInfo();
$info['id']=$dept->getId();
$info['groups'] = $dept->getAllowedGroups();
$qstr.='&id='.$dept->getId();
} else {
$title='Add New Department';
......@@ -201,6 +203,29 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
&nbsp;<span class="error">&nbsp;<?php echo $errors['autoresp_email_id']; ?></span>
</td>
</tr>
<tr>
<th colspan="2">
<em><strong>Department Access</strong>: Check all groups allowed to access department.</em>
</th>
</tr>
<tr><td colspan=2><em>Primary department members and manager will always have access regarless of group selection or assignment.</em></td></tr>
<?php
$sql='SELECT group_id, group_name, count(staff.staff_id) as members '
.' FROM '.GROUP_TABLE.' grp '
.' LEFT JOIN '.STAFF_TABLE. ' staff USING(group_id) '
.' GROUP by grp.group_id '
.' ORDER BY group_name';
if(($res=db_query($sql)) && db_num_rows($res)){
while(list($id, $name, $members) = db_fetch_row($res)) {
if($members>0)
$members=sprintf('<a href="staff.php?a=filter&gid=%d">%d</a>', $id, $members);
$ck=($info['groups'] && in_array($id,$info['groups']))?'checked="checked"':'';
echo sprintf('<tr><td colspan=2>&nbsp;&nbsp;<label><input type="checkbox" name="groups[]" value="%d" %s>&nbsp;%s</label> (%s)</td></tr>',
$id, $ck, $name, $members);
}
}
?>
<tr>
<th colspan="2">
<em><strong>Department Signature</strong>: Optional signature used on outgoing emails. &nbsp;<span class="error">&nbsp;<?php echo $errors['signature']; ?></span></em>
......
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