From 5b05327025310f6f4684f3c40a96f414afb05635 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Tue, 6 May 2014 21:08:04 +0000 Subject: [PATCH] Make department email optional Departments without email will use the system default email as the default outgoing email. --- include/class.dept.php | 7 --- include/staff/department.inc.php | 95 ++++++++++++++++--------------- include/staff/departments.inc.php | 19 +++++-- setup/inc/class.installer.php | 3 - 4 files changed, 64 insertions(+), 60 deletions(-) diff --git a/include/class.dept.php b/include/class.dept.php index d99985b44..e33788462 100644 --- a/include/class.dept.php +++ b/include/class.dept.php @@ -395,13 +395,6 @@ class Dept { if($id && $id!=$vars['id']) $errors['err']='Missing or invalid Dept ID (internal error).'; - if(!isset($vars['id']) - && (!$vars['email_id'] || !is_numeric($vars['email_id']))) - $errors['email_id']='Email selection required'; - - if(isset($vars['tpl_id']) && !is_numeric($vars['tpl_id'])) - $errors['tpl_id']='Template selection required'; - if(!$vars['name']) { $errors['name']='Name required'; } elseif(strlen($vars['name'])<4) { diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 99a571fec..bcfec6c44 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -62,49 +62,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> </tr> <tr> - <td width="180" class="required"> - Email: - </td> - <td> - <select name="email_id"> - <option value="0">— Select Department Email —</option> - <?php - $sql='SELECT email_id,email,name FROM '.EMAIL_TABLE.' email ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$email,$name)=db_fetch_row($res)){ - $selected=($info['email_id'] && $id==$info['email_id'])?'selected="selected"':''; - if($name) - $email=Format::htmlchars("$name <$email>"); - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$email); - } - } - ?> - </select> - <span class="error">* <?php echo $errors['email_id']; ?></span> - </td> - </tr> - <tr> - <td width="180" class="required"> - Template: - </td> - <td> - <select name="tpl_id"> - <option value="0">— System Default —</option> - <?php - $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl WHERE isactive=1 ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['tpl_id'] && $id==$info['tpl_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); - } - } - ?> - </select> - <span class="error">* <?php echo $errors['tpl_id']; ?></span> - </td> - </tr> - <tr> - <td width="180" class="required"> + <td width="180"> SLA: </td> <td> @@ -123,7 +81,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> </tr> <tr> - <td width="180" class="required"> + <td width="180"> Manager: </td> <td> @@ -166,7 +124,54 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </tr> <tr> <th colspan="2"> - <em><strong>Auto Response Settings</strong>: Override global auto-response settings for tickets routed to the Dept.</em> + <em><strong>Email Settings</strong>: Outgoing email settings for the department.</em> + </th> + </tr> + <tr> + <td width="180"> + Outgoing Email: + </td> + <td> + <select name="email_id"> + <option value="0">— System Default —</option> + <?php + $sql='SELECT email_id,email,name FROM '.EMAIL_TABLE.' email ORDER by name'; + if(($res=db_query($sql)) && db_num_rows($res)){ + while(list($id,$email,$name)=db_fetch_row($res)){ + $selected=($info['email_id'] && $id==$info['email_id'])?'selected="selected"':''; + if($name) + $email=Format::htmlchars("$name <$email>"); + echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$email); + } + } + ?> + </select> + <span class="error">* <?php echo $errors['email_id']; ?></span> + </td> + </tr> + <tr> + <td width="180"> + Template Set: + </td> + <td> + <select name="tpl_id"> + <option value="0">— System Default —</option> + <?php + $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl WHERE isactive=1 ORDER by name'; + if(($res=db_query($sql)) && db_num_rows($res)){ + while(list($id,$name)=db_fetch_row($res)){ + $selected=($info['tpl_id'] && $id==$info['tpl_id'])?'selected="selected"':''; + echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); + } + } + ?> + </select> + <span class="error">* <?php echo $errors['tpl_id']; ?></span> + </td> + </tr> + <tr> + <th colspan="2"> + <em><strong>Autoresponder Settings</strong>: Override global auto-response settings for tickets routed to the department.</em> </th> </tr> <tr> diff --git a/include/staff/departments.inc.php b/include/staff/departments.inc.php index 23d6937e8..da9c74c5e 100644 --- a/include/staff/departments.inc.php +++ b/include/staff/departments.inc.php @@ -54,7 +54,7 @@ else <caption><?php echo $showing; ?></caption> <thead> <tr> - <th width="7px"> </th> + <th width="7px"> </th> <th width="180"><a <?php echo $name_sort; ?> href="departments.php?<?php echo $qstr; ?>&sort=name">Name</a></th> <th width="80"><a <?php echo $type_sort; ?> href="departments.php?<?php echo $qstr; ?>&sort=type">Type</a></th> <th width="70"><a <?php echo $users_sort; ?>href="departments.php?<?php echo $qstr; ?>&sort=users">Users</a></th> @@ -68,17 +68,25 @@ else $ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null; if($res && db_num_rows($res)): $defaultId=$cfg->getDefaultDeptId(); + $defaultEmailId = $cfg->getDefaultEmail()->getId(); + $defaultEmailAddress = (string) $cfg->getDefaultEmail(); while ($row = db_fetch_array($res)) { $sel=false; if($ids && in_array($row['dept_id'],$ids)) $sel=true; - - $row['email']=$row['email_name']?($row['email_name'].' <'.$row['email'].'>'):$row['email']; + + if ($row['email_id']) + $row['email']=$row['email_name']?($row['email_name'].' <'.$row['email'].'>'):$row['email']; + elseif($defaultEmailId) { + $row['email_id'] = $defaultEmailId; + $row['email'] = $defaultEmailAddress; + } + $default=($defaultId==$row['dept_id'])?' <small>(Default)</small>':''; ?> <tr id="<?php echo $row['dept_id']; ?>"> <td width=7px> - <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['dept_id']; ?>" + <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['dept_id']; ?>" <?php echo $sel?'checked="checked"':''; ?> <?php echo $default?'disabled="disabled"':''; ?> > </td> <td><a href="departments.php?id=<?php echo $row['dept_id']; ?>"><?php echo $row['dept_name']; ?></a> <?php echo $default; ?></td> @@ -91,7 +99,8 @@ else <?php } ?> </b> </td> - <td><a href="emails.php?id=<?php echo $row['email_id']; ?>"><?php echo $row['email']; ?></a></td> + <td><a href="emails.php?id=<?php echo $row['email_id']; ?>"><?php + echo Format::htmlchars($row['email']); ?></a> </td> <td><a href="staff.php?id=<?php echo $row['manager_id']; ?>"><?php echo $row['manager']; ?> </a></td> </tr> <?php diff --git a/setup/inc/class.installer.php b/setup/inc/class.installer.php index cc18ba3e9..249f40dfc 100644 --- a/setup/inc/class.installer.php +++ b/setup/inc/class.installer.php @@ -248,9 +248,6 @@ class Installer extends SetupWizard { $sql='UPDATE '.PREFIX."email SET dept_id=$dept_id_1"; db_query($sql, false); - $sql='UPDATE '.PREFIX."department SET email_id=$support_email_id" - .", autoresp_email_id=$support_email_id"; - db_query($sql, false); global $cfg; $cfg = new OsticketConfig(); -- GitLab