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
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,11 @@ class Canned {
if(!$id && !($id=$this->getId()))
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 '
.' 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);
if(!($res=db_query($sql)) || !db_num_rows($res))
return false;
......@@ -62,6 +64,9 @@ class Canned {
return $this->isEnabled();
}
function isInUse() {
return $this->ht['in_use'];
}
function getTitle() {
return $this->ht['title'];
......@@ -168,6 +173,7 @@ class Canned {
}
function delete(){
if ($this->isInUse()) return false;
$sql='DELETE FROM '.CANNED_TABLE.' WHERE canned_id='.db_input($this->getId()).' LIMIT 1';
if(db_query($sql) && ($num=db_affected_rows())) {
......
......@@ -2013,7 +2013,8 @@ class Ticket{
$ticket->onNewTicket($vars['message'], $autorespond, $alertstaff);
if ($vars['cannedResponseId']
&& ($canned = Canned::lookup($vars['cannedResponseId']))) {
&& ($canned = Canned::lookup($vars['cannedResponseId']))
&& $canned->isEnabled()) {
$files = array();
foreach ($canned->getAttachments() as $file)
$files[] = $file['id'];
......
......@@ -2,12 +2,10 @@
if(!defined('OSTSCPINC') || !$thisstaff) die('Access Denied');
$qstr='';
$sql='SELECT canned.*, count(attach.file_id) as files, dept.dept_name as department, '.
' (filter.id is not null) as in_use '.
$sql='SELECT canned.*, count(attach.file_id) as files, dept.dept_name as department '.
' FROM '.CANNED_TABLE.' canned '.
' 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 '.EMAIL_FILTER_TABLE.' filter ON (canned.canned_id = filter.canned_response_id) ';
' LEFT JOIN '.CANNED_ATTACHMENT_TABLE.' attach ON (attach.canned_id=canned.canned_id) ';
$sql.=' WHERE 1';
$sortOptions=array('title'=>'canned.title','status'=>'canned.isenabled','dept'=>'department','updated'=>'canned.updated');
......@@ -83,11 +81,9 @@ else
?>
<tr id="<?php echo $row['canned_id']; ?>">
<td width=7px>
<?php if (!$row['in_use']) { ?>
<input type="checkbox" name="ids[]" value="<?php echo $row['canned_id']; ?>"
<?php echo $sel?'checked="checked"':''; ?> <?php echo $default?'disabled="disabled"':''; ?>
onClick="highLight(this.value,this.checked);"/>
<?php } ?>
</td>
<td>
<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.
Finish editing this message first!
Please register or to comment