Skip to content
Snippets Groups Projects
Commit f83834dc authored by Jared Hancock's avatar Jared Hancock
Browse files

Allow disabling canned responses that are used by email filters

But don't send out canned responses for new tickets that matched a filter
with an attached canned response if that response is not enabled. Also,
explicitly block deletes to filters that are in use.
parent 921c452c
Branches
Tags
No related merge requests found
...@@ -31,9 +31,11 @@ class Canned { ...@@ -31,9 +31,11 @@ class Canned {
if(!$id && !($id=$this->getId())) if(!$id && !($id=$this->getId()))
return false; return false;
$sql='SELECT canned.*, count(attach.file_id) as attachments ' $sql='SELECT canned.*, count(attach.file_id) as attachments, '
.' (count(filter.id) > 0) as in_use '
.' FROM '.CANNED_TABLE.' canned ' .' FROM '.CANNED_TABLE.' canned '
.' LEFT JOIN '.CANNED_ATTACHMENT_TABLE.' attach ON (attach.canned_id=canned.canned_id) ' .' LEFT JOIN '.CANNED_ATTACHMENT_TABLE.' attach ON (attach.canned_id=canned.canned_id) '
.' LEFT JOIN '.EMAIL_FILTER_TABLE.' filter ON (canned.canned_id = filter.canned_response_id) '
.' WHERE canned.canned_id='.db_input($id); .' WHERE canned.canned_id='.db_input($id);
if(!($res=db_query($sql)) || !db_num_rows($res)) if(!($res=db_query($sql)) || !db_num_rows($res))
return false; return false;
...@@ -62,6 +64,9 @@ class Canned { ...@@ -62,6 +64,9 @@ class Canned {
return $this->isEnabled(); return $this->isEnabled();
} }
function isInUse() {
return $this->ht['in_use'];
}
function getTitle() { function getTitle() {
return $this->ht['title']; return $this->ht['title'];
...@@ -168,6 +173,7 @@ class Canned { ...@@ -168,6 +173,7 @@ class Canned {
} }
function delete(){ function delete(){
if ($this->isInUse()) return false;
$sql='DELETE FROM '.CANNED_TABLE.' WHERE canned_id='.db_input($this->getId()).' LIMIT 1'; $sql='DELETE FROM '.CANNED_TABLE.' WHERE canned_id='.db_input($this->getId()).' LIMIT 1';
if(db_query($sql) && ($num=db_affected_rows())) { if(db_query($sql) && ($num=db_affected_rows())) {
......
...@@ -2013,7 +2013,8 @@ class Ticket{ ...@@ -2013,7 +2013,8 @@ class Ticket{
$ticket->onNewTicket($vars['message'], $autorespond, $alertstaff); $ticket->onNewTicket($vars['message'], $autorespond, $alertstaff);
if ($vars['cannedResponseId'] if ($vars['cannedResponseId']
&& ($canned = Canned::lookup($vars['cannedResponseId']))) { && ($canned = Canned::lookup($vars['cannedResponseId']))
&& $canned->isEnabled()) {
$files = array(); $files = array();
foreach ($canned->getAttachments() as $file) foreach ($canned->getAttachments() as $file)
$files[] = $file['id']; $files[] = $file['id'];
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied'); if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied');
$qstr=''; $qstr='';
$sql='SELECT canned.*, count(attach.file_id) as files, dept.dept_name as department, '. $sql='SELECT canned.*, count(attach.file_id) as files, dept.dept_name as department '.
' (filter.id is not null) as in_use '.
' FROM '.CANNED_TABLE.' canned '. ' FROM '.CANNED_TABLE.' canned '.
' LEFT JOIN '.DEPT_TABLE.' dept ON (dept.dept_id=canned.dept_id) '. ' LEFT JOIN '.DEPT_TABLE.' dept ON (dept.dept_id=canned.dept_id) '.
' LEFT JOIN '.CANNED_ATTACHMENT_TABLE.' attach ON (attach.canned_id=canned.canned_id) '. ' LEFT JOIN '.CANNED_ATTACHMENT_TABLE.' attach ON (attach.canned_id=canned.canned_id) ';
' LEFT JOIN '.EMAIL_FILTER_TABLE.' filter ON (canned.canned_id = filter.canned_response_id) ';
$sql.=' WHERE 1'; $sql.=' WHERE 1';
$sortOptions=array('title'=>'canned.title','status'=>'canned.isenabled','dept'=>'department','updated'=>'canned.updated'); $sortOptions=array('title'=>'canned.title','status'=>'canned.isenabled','dept'=>'department','updated'=>'canned.updated');
...@@ -83,11 +81,9 @@ else ...@@ -83,11 +81,9 @@ else
?> ?>
<tr id="<?php echo $row['canned_id']; ?>"> <tr id="<?php echo $row['canned_id']; ?>">
<td width=7px> <td width=7px>
<?php if (!$row['in_use']) { ?>
<input type="checkbox" name="ids[]" value="<?php echo $row['canned_id']; ?>" <input type="checkbox" name="ids[]" value="<?php echo $row['canned_id']; ?>"
<?php echo $sel?'checked="checked"':''; ?> <?php echo $default?'disabled="disabled"':''; ?> <?php echo $sel?'checked="checked"':''; ?> <?php echo $default?'disabled="disabled"':''; ?>
onClick="highLight(this.value,this.checked);"/> onClick="highLight(this.value,this.checked);"/>
<?php } ?>
</td> </td>
<td> <td>
<a href="canned.php?id=<?php echo $row['canned_id']; ?>"><?php echo Format::truncate($row['title'],200); echo "&nbsp;$files"; ?></a>&nbsp; <a href="canned.php?id=<?php echo $row['canned_id']; ?>"><?php echo Format::truncate($row['title'],200); echo "&nbsp;$files"; ?></a>&nbsp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment