diff --git a/include/class.group.php b/include/class.group.php index 67f392190f0cd357872ad9a1e550cf6258175631..87a93994036ae559c4609b43382d43f13480d21a 100644 --- a/include/class.group.php +++ b/include/class.group.php @@ -80,7 +80,21 @@ class Group { function isActive(){ return $this->isEnabled(); } - + + function getTranslateTag($subtag) { + return _H(sprintf('group.%s.%s', $subtag, $this->id)); + } + function getLocal($subtag) { + $tag = $this->getTranslateTag($subtag); + $T = CustomDataTranslation::translate($tag); + return $T != $tag ? $T : $this->ht[$subtag]; + } + static function getLocalById($id, $subtag, $default) { + $tag = _H(sprintf('group.%s.%s', $subtag, $id)); + $T = CustomDataTranslation::translate($tag); + return $T != $tag ? $T : $default; + } + //Get members of the group. function getMembers() { @@ -113,7 +127,7 @@ class Group { return $this->departments; } - + function updateDeptAccess($depts) { @@ -171,11 +185,28 @@ class Group { return $id; } + static function getGroupNames($localize=true) { + static $groups=array(); + + if (!$groups) { + $sql='SELECT group_id, group_name, group_enabled as isactive FROM '.GROUP_TABLE.' ORDER BY group_name'; + if (($res=db_query($sql)) && db_num_rows($res)) { + while (list($id, $name, $enabled) = db_fetch_row($res)) { + $groups[$id] = sprintf('%s%s', + self::getLocalById($id, 'name', $name), + $enabled ? '' : ' ' . __('(disabled)')); + } + } + } + // TODO: Sort groups if $localize + return $groups; + } + function lookup($id){ return ($id && is_numeric($id) && ($g= new Group($id)) && $g->getId()==$id)?$g:null; } - function create($vars, &$errors) { + function create($vars, &$errors) { if(($id=self::save(0,$vars,$errors)) && ($group=self::lookup($id))) $group->updateDeptAccess($vars['depts']); diff --git a/include/class.team.php b/include/class.team.php index 11670c8537b843e3223c182ebc42d74dd81c574e..c0a9b8a1d4c20fba116a535a60e658d427493700 100644 --- a/include/class.team.php +++ b/include/class.team.php @@ -130,6 +130,20 @@ class Team { return !$this->ht['noalerts']; } + function getTranslateTag($subtag) { + return _H(sprintf('team.%s.%s', $subtag, $this->id)); + } + function getLocal($subtag) { + $tag = $this->getTranslateTag($subtag); + $T = CustomDataTranslation::translate($tag); + return $T != $tag ? $T : $this->ht[$subtag]; + } + static function getLocalById($id, $subtag, $default) { + $tag = _H(sprintf('team.%s.%s', $subtag, $id)); + $T = CustomDataTranslation::translate($tag); + return $T != $tag ? $T : $default; + } + function update($vars, &$errors) { //reset team lead if they're being deleted @@ -199,7 +213,7 @@ class Team { function getTeams( $availableOnly=false ) { $teams=array(); - $sql='SELECT team_id, name FROM '.TEAM_TABLE; + $sql='SELECT team_id, name, isenabled FROM '.TEAM_TABLE; if($availableOnly) { //Make sure the members are active...TODO: include group check!! $sql='SELECT t.team_id, t.name, count(m.staff_id) as members ' @@ -212,9 +226,12 @@ class Team { .' HAVING members>0' .' ORDER by t.name '; } - if(($res=db_query($sql)) && db_num_rows($res)) { - while(list($id, $name)=db_fetch_row($res)) - $teams[$id] = $name; + if(($res = db_query($sql)) && db_num_rows($res)) { + while(list($id, $name, $isenabled) = db_fetch_row($res)) { + $teams[$id] = self::getLocalById($id, 'name', $name); + if (!$isenabled) + $teams[$id] .= ' ' . __('(disabled)'); + } } return $teams; diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php index 3bda64e043f56e6106e758ebdcc36988a217e4ce..74435b9bde6df32da9e97d41543d837728246647 100644 --- a/include/staff/filter.inc.php +++ b/include/staff/filter.inc.php @@ -237,12 +237,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="dept_id"> <option value="">— <?php echo __('Default');?> —</option> <?php - $sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' dept ORDER by dept_name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); - } + foreach (Dept::getDepartments() as $id=>$name) { + $selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); } ?> </select> @@ -341,13 +338,11 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); echo '</OPTGROUP>'; } $sql='SELECT team_id, isenabled, name FROM '.TEAM_TABLE .' ORDER BY name'; - if(($res=db_query($sql)) && db_num_rows($res)){ + if ($teams = Team::getTeams()) { echo '<OPTGROUP label="'.__('Teams').'">'; - while (list($id, $isenabled, $name) = db_fetch_row($res)){ + foreach ($teams as $id=>$name) { $k="t$id"; $selected = ($info['assign']==$k || $info['team_id']==$id)?'selected="selected"':''; - if (!$isenabled) - $name .= ' (disabled)'; ?> <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option> <?php @@ -369,12 +364,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <option value="0" selected="selected">— <?php echo __('Unchanged'); ?> —</option> <?php - $sql='SELECT topic_id, topic FROM '.TOPIC_TABLE.' T ORDER by topic'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['topic_id'] && $id==$info['topic_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); - } + foreach (Topic::getAllHelpTopics(true) as $id=>$name) { + $selected=($info['topic_id'] && $id==$info['topic_id'])?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); } ?> </select> diff --git a/include/staff/group.inc.php b/include/staff/group.inc.php index 27546e764e2bdad1edea44239281a20ac5a312ed..74cc64cb479f4e450df44b8c60ebf8e3645419ab 100644 --- a/include/staff/group.inc.php +++ b/include/staff/group.inc.php @@ -9,6 +9,7 @@ if($group && $_REQUEST['a']!='add'){ $info=$group->getInfo(); $info['id']=$group->getId(); $info['depts']=$group->getDepartments(); + $trans['name'] = $group->getTranslateTag('name'); $qstr.='&id='.$group->getId(); }else { $title=__('Add New Group'); @@ -41,7 +42,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php echo __('Name');?>: </td> <td> - <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>"> + <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>" + data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr> @@ -160,13 +162,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </th> </tr> <?php - $sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' ORDER BY dept_name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name) = db_fetch_row($res)){ - $ck=($info['depts'] && in_array($id,$info['depts']))?'checked="checked"':''; - echo sprintf('<tr><td colspan=2> <input type="checkbox" class="deptckb" name="depts[]" value="%d" %s>%s</td></tr>',$id,$ck,$name); - } - } + foreach (Dept::getDepartments() as $id=>$name) { + $ck=($info['depts'] && in_array($id,$info['depts']))?'checked="checked"':''; + echo sprintf('<tr><td colspan=2> <input type="checkbox" class="deptckb" name="depts[]" value="%d" %s> %s</td></tr>',$id,$ck,$name); + } ?> <tr> <th colspan="2"> diff --git a/include/staff/staff.inc.php b/include/staff/staff.inc.php index 1dd7d105ada2a28c76b917221460563b6604c9f7..fe2ba3f3f0657513b926b33136a02d6b10503afe 100644 --- a/include/staff/staff.inc.php +++ b/include/staff/staff.inc.php @@ -236,12 +236,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="group_id" id="group_id"> <option value="0">— <?php echo __('Select Group');?> —</option> <?php - $sql='SELECT group_id, group_name, group_enabled as isactive FROM '.GROUP_TABLE.' ORDER BY group_name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name,$isactive)=db_fetch_row($res)){ - $sel=($info['group_id']==$id)?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s %s</option>',$id,$sel,$name,($isactive?'':__('(disabled)'))); - } + foreach (Group::getGroupNames() as $id=>$name) { + $sel=($info['group_id']==$id)?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>', + $id, $sel, $name); } ?> </select> @@ -256,12 +254,9 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="dept_id" id="dept_id"> <option value="0">— <?php echo __('Select Department');?> —</option> <?php - $sql='SELECT dept_id, dept_name FROM '.DEPT_TABLE.' ORDER BY dept_name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $sel=($info['dept_id']==$id)?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$sel,$name); - } + foreach (Dept::getDepartments() as $id=>$name) { + $sel=($info['dept_id']==$id)?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>',$id,$sel,$name); } ?> </select> @@ -332,20 +327,21 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> </tr> <?php - //List team assignments. - $sql='SELECT team.team_id, team.name, isenabled FROM '.TEAM_TABLE.' team ORDER BY team.name'; - if(($res=db_query($sql)) && db_num_rows($res)){ ?> + // List team assignments. + $teams = Team::getTeams(); + if (count($teams)) { ?> <tr> <th colspan="2"> <em><strong><?php echo __('Assigned Teams');?></strong>: <?php echo __("Agent will have access to tickets assigned to a team they belong to regardless of the ticket's department.");?> </em> </th> </tr> <?php - while(list($id,$name,$isactive)=db_fetch_row($res)){ - $checked=($info['teams'] && in_array($id,$info['teams']))?'checked="checked"':''; - echo sprintf('<tr><td colspan=2><input type="checkbox" name="teams[]" value="%d" %s>%s %s</td></tr>', - $id,$checked,$name,($isactive?'':__('(disabled)'))); - } + foreach ($teams as $id=>$name) { + $checked=($info['teams'] && in_array($id,$info['teams'])) + ? 'checked="checked"' : ''; + echo sprintf('<tr><td colspan=2><input type="checkbox" name="teams[]" value="%d" %s> %s</td></tr>', + $id,$checked,$name); + } } ?> <tr> <th colspan="2"> diff --git a/include/staff/team.inc.php b/include/staff/team.inc.php index 4b2feacbfd06c1898990ce90cfc9ce13f5b05321..d8748d0feb161ad9f1c8d449d7b361da58676833 100644 --- a/include/staff/team.inc.php +++ b/include/staff/team.inc.php @@ -9,6 +9,7 @@ if($team && $_REQUEST['a']!='add'){ $submit_text=__('Save Changes'); $info=$team->getInfo(); $info['id']=$team->getId(); + $trans['name'] = $team->getTranslateTag('name'); $qstr.='&id='.$team->getId(); }else { $title=__('Add New Team'); @@ -43,7 +44,8 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php echo __('Name');?>: </td> <td> - <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>"> + <input type="text" size="30" name="name" value="<?php echo $info['name']; ?>" + data-translate-tag="<?php echo $trans['name']; ?>"/> <span class="error">* <?php echo $errors['name']; ?></span> </td> </tr>