diff --git a/include/class.template.php b/include/class.template.php index 0ed98ca6473f4167a25bba4f5e64cbd07c5d39f7..2dcb5d00ea7c5d8e15f56859548d29efdf1a76b1 100644 --- a/include/class.template.php +++ b/include/class.template.php @@ -14,12 +14,51 @@ vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ -class Template { +class EmailTemplateGroup { var $id; var $ht; - - function Template($id){ + var $_templates; + var $all_names=array( + 'ticket.autoresp'=>array( + 'name'=>'New Ticket Auto-response', + 'desc'=>'Autoresponse sent to user, if enabled, on new ticket.'), + 'ticket.autoreply'=>array( + 'name'=>'New Ticket Auto-reply', + 'desc'=>'Canned Auto-reply sent to user on new ticket, based on filter matches. Overwrites "normal" auto-response.'), + 'message.autoresp'=>array( + 'name'=>'New Message Auto-response', + 'desc'=>'Confirmation sent to user when a new message is appended to an existing ticket.'), + 'ticket.notice'=>array( + 'name'=>'New Ticket Notice', + 'desc'=>'Notice sent to user, if enabled, on new ticket created by staff on their behalf (e.g phone calls).'), + 'ticket.overlimit'=>array( + 'name'=>'Over Limit Notice', + 'desc'=>'A one time notice sent, if enabled, when user has reached the maximum allowed open tickets.'), + 'ticket.reply'=>array( + 'name'=>'Response/Reply Template', + 'desc'=>'Template used on ticket response/reply'), + 'ticket.alert'=>array( + 'name'=>'New Ticket Alert', + 'desc'=>'Alert sent to staff, if enabled, on new ticket.'), + 'message.alert'=>array( + 'name'=>'New Message Alert', + 'desc'=>'Alert sent to staff, if enabled, when user replies to an existing ticket.'), + 'note.alert'=>array( + 'name'=>'Internal Note Alert', + 'desc'=>'Alert sent to selected staff, if enabled, on new internal note.'), + 'assigned.alert'=>array( + 'name'=>'Ticket Assignment Alert', + 'desc'=>'Alert sent to staff on ticket assignment.'), + 'transfer.alert'=>array( + 'name'=>'Ticket Transfer Alert', + 'desc'=>'Alert sent to staff on ticket transfer.'), + 'ticket.overdue'=>array( + 'name'=>'Overdue Ticket Alert', + 'desc'=>'Alert sent to staff on stale or overdue tickets.'), + ); + + function EmailTemplateGroup($id){ $this->id=0; $this->load($id); } @@ -28,9 +67,9 @@ class Template { if(!$id && !($id=$this->getId())) return false; - + $sql='SELECT tpl.*,count(dept.tpl_id) as depts ' - .' FROM '.EMAIL_TEMPLATE_TABLE.' tpl ' + .' FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl ' .' LEFT JOIN '.DEPT_TABLE.' dept USING(tpl_id) ' .' WHERE tpl.tpl_id='.db_input($id) .' GROUP BY tpl.tpl_id'; @@ -38,21 +77,21 @@ class Template { if(!($res=db_query($sql))|| !db_num_rows($res)) return false; - + $this->ht=db_fetch_array($res); $this->id=$this->ht['tpl_id']; return true; } - + function reload() { return $this->load($this->getId()); } - + function getId(){ return $this->id; } - + function getName(){ return $this->ht['name']; } @@ -71,7 +110,7 @@ class Template { function isInUse(){ global $cfg; - + return ($this->ht['depts'] || ($cfg && $this->getId()==$cfg->getDefaultTemplateId())); } @@ -85,172 +124,93 @@ class Template { function setStatus($status){ - $sql='UPDATE '.EMAIL_TEMPLATE_TABLE.' SET updated=NOW(), isactive='.db_input($status?1:0) + $sql='UPDATE '.EMAIL_TEMPLATE_GRP_TABLE.' SET updated=NOW(), isactive='.db_input($status?1:0) .' WHERE tpl_id='.db_input($this->getId()); return (db_query($sql) && db_affected_rows()); } + function getTemplateDescription($name) { + return $this->all_names[$name]; + } + function getMsgTemplate($name) { global $ost; - //TODO: Don't preload - do ondemand fetch! - $tpl=array(); - switch(strtolower($name)) { - case 'ticket_autoresp': - $tpl=array('subj'=>$this->ht['ticket_autoresp_subj'],'body'=>$this->ht['ticket_autoresp_body']); - break; - case 'ticket_autoreply': - $tpl=array('subj'=>$this->ht['ticket_autoreply_subj'],'body'=>$this->ht['ticket_autoreply_body']); - break; - case 'msg_autoresp': - $tpl=array('subj'=>$this->ht['message_autoresp_subj'],'body'=>$this->ht['message_autoresp_body']); - break; - case 'ticket_notice': - $tpl=array('subj'=>$this->ht['ticket_notice_subj'],'body'=>$this->ht['ticket_notice_body']); - break; - case 'overlimit_notice': - $tpl=array('subj'=>$this->ht['ticket_overlimit_subj'],'body'=>$this->ht['ticket_overlimit_body']); - break; - case 'ticket_reply': - $tpl=array('subj'=>$this->ht['ticket_reply_subj'],'body'=>$this->ht['ticket_reply_body']); - break; - case 'ticket_alert': - $tpl=array('subj'=>$this->ht['ticket_alert_subj'],'body'=>$this->ht['ticket_alert_body']); - break; - case 'msg_alert': - $tpl=array('subj'=>$this->ht['message_alert_subj'],'body'=>$this->ht['message_alert_body']); - break; - case 'note_alert': - $tpl=array('subj'=>$this->ht['note_alert_subj'],'body'=>$this->ht['note_alert_body']); - break; - case 'assigned_alert': - $tpl=array('subj'=>$this->ht['assigned_alert_subj'],'body'=>$this->ht['assigned_alert_body']); - break; - case 'transfer_alert': - $tpl=array('subj'=>$this->ht['transfer_alert_subj'],'body'=>$this->ht['transfer_alert_body']); - break; - case 'overdue_alert': - $tpl=array('subj'=>$this->ht['ticket_overdue_subj'],'body'=>$this->ht['ticket_overdue_body']); - break; - default: - $ost->logWarning('Template Fetch Error', "Unable to fetch '$name' template - id #".$this->getId()); - $tpl=array(); + if ($tpl=EmailTemplate::lookupByName($this->getId(), $name, $this)) + return $tpl; + + $ost->logWarning('Template Fetch Error', "Unable to fetch '$name' template - id #".$this->getId()); + return false; + } + + function getTemplates() { + if (!$this->_tempates) { + $this->_templates = array(); + $sql = 'SELECT id, code_name FROM '.EMAIL_TEMPLATE_TABLE + .' WHERE tpl_id='.db_input($this->getId()) + .' ORDER BY code_name'; + $res = db_query($sql); + while (list($id, $cn)=db_fetch_row($res)) + $this->_templates[$cn] = EmailTemplate::lookup($id, $this); } + return $this->_templates; + } - return $tpl; + function getUndefinedTemplateNames() { + $list = $this->all_names; + foreach ($this->getTemplates() as $cn=>$tpl) + unset($list[$cn]); + return $list; } - + function getNewTicketAlertMsgTemplate() { - return $this->getMsgTemplate('ticket_alert'); + return $this->getMsgTemplate('ticket.alert'); } function getNewMessageAlertMsgTemplate() { - return $this->getMsgTemplate('msg_alert'); + return $this->getMsgTemplate('message.alert'); } function getNewTicketNoticeMsgTemplate() { - return $this->getMsgTemplate('ticket_notice'); + return $this->getMsgTemplate('ticket.notice'); } function getNewMessageAutorepMsgTemplate() { - return $this->getMsgTemplate('msg_autoresp'); + return $this->getMsgTemplate('message.autoresp'); } function getAutoRespMsgTemplate() { - return $this->getMsgTemplate('ticket_autoresp'); + return $this->getMsgTemplate('ticket.autoresp'); } function getAutoReplyMsgTemplate() { - return $this->getMsgTemplate('ticket_autoreply'); + return $this->getMsgTemplate('ticket.autoreply'); } function getReplyMsgTemplate() { - return $this->getMsgTemplate('ticket_reply'); + return $this->getMsgTemplate('ticket.reply'); } function getOverlimitMsgTemplate() { - return $this->getMsgTemplate('overlimit_notice'); + return $this->getMsgTemplate('ticket.overlimit'); } function getNoteAlertMsgTemplate() { - return $this->getMsgTemplate('note_alert'); + return $this->getMsgTemplate('note.alert'); } function getTransferAlertMsgTemplate() { - return $this->getMsgTemplate('transfer_alert'); + return $this->getMsgTemplate('transfer.alert'); } function getAssignedAlertMsgTemplate() { - return $this->getMsgTemplate('assigned_alert'); + return $this->getMsgTemplate('assigned.alert'); } function getOverdueAlertMsgTemplate() { - return $this->getMsgTemplate('overdue_alert'); - } - - function updateMsgTemplate($vars, &$errors) { - - if(!($tpls=Template::message_templates()) || !$tpls[$vars['tpl']]) - $errors['tpl']='Unknown or invalid template'; - - if(!$vars['subj']) - $errors['subj']='Message subject required'; - - if(!$vars['body']) - $errors['body']='Message body required'; - - - if($errors) return false; - - $sql='UPDATE '.EMAIL_TEMPLATE_TABLE.' SET updated=NOW() '; - switch(strtolower($vars['tpl'])) { - case 'ticket_autoresp': - $sql.=',ticket_autoresp_subj='.db_input($vars['subj']).',ticket_autoresp_body='.db_input($vars['body']); - break; - case 'ticket_autoreply': - $sql.=',ticket_autoreply_subj='.db_input($vars['subj']).',ticket_autoreply_body='.db_input($vars['body']); - break; - case 'msg_autoresp': - $sql.=',message_autoresp_subj='.db_input($vars['subj']).',message_autoresp_body='.db_input($vars['body']); - break; - case 'ticket_notice': - $sql.=',ticket_notice_subj='.db_input($vars['subj']).',ticket_notice_body='.db_input($vars['body']); - break; - case 'overlimit_notice': - $sql.=',ticket_overlimit_subj='.db_input($vars['subj']).',ticket_overlimit_body='.db_input($vars['body']); - break; - case 'ticket_reply': - $sql.=',ticket_reply_subj='.db_input($vars['subj']).',ticket_reply_body='.db_input($vars['body']); - break; - case 'ticket_alert': - $sql.=',ticket_alert_subj='.db_input($vars['subj']).',ticket_alert_body='.db_input($vars['body']); - break; - case 'msg_alert': - $sql.=',message_alert_subj='.db_input($vars['subj']).',message_alert_body='.db_input($vars['body']); - break; - case 'note_alert': - $sql.=',note_alert_subj='.db_input($vars['subj']).',note_alert_body='.db_input($vars['body']); - break; - case 'assigned_alert': - $sql.=',assigned_alert_subj='.db_input($vars['subj']).',assigned_alert_body='.db_input($vars['body']); - break; - case 'transfer_alert': - $sql.=',transfer_alert_subj='.db_input($vars['subj']).',transfer_alert_body='.db_input($vars['body']); - break; - case 'overdue_alert': - $sql.=',ticket_overdue_subj='.db_input($vars['subj']).',ticket_overdue_body='.db_input($vars['body']); - break; - default: - $errors['tpl']='Unknown or invalid template'; - return false; - } - - $sql.=' WHERE tpl_id='.db_input($this->getId()); - - return (db_query($sql)); - + return $this->getMsgTemplate('ticket.overdue'); } function update($vars,&$errors) { @@ -260,9 +220,9 @@ class Template { if(!$this->save($this->getId(),$vars,$errors)) return false; - + $this->reload(); - + return true; } @@ -280,55 +240,28 @@ class Template { if($this->isInUse() || $cfg->getDefaultTemplateId()==$this->getId()) return 0; - $sql='DELETE FROM '.EMAIL_TEMPLATE_TABLE.' WHERE tpl_id='.db_input($this->getId()).' LIMIT 1'; + $sql='DELETE FROM '.EMAIL_TEMPLATE_GRP_TABLE + .' WHERE tpl_id='.db_input($this->getId()).' LIMIT 1'; if(db_query($sql) && ($num=db_affected_rows())) { - //isInuse check is enough - but it doesn't hurt make sure deleted tpl is not in-use. + //isInuse check is enough - but it doesn't hurt make sure deleted tpl is not in-use. db_query('UPDATE '.DEPT_TABLE.' SET tpl_id=0 WHERE tpl_id='.db_input($this->getId())); + db_query('DELETE FROM '.EMAIL_TEMPLATE_TABLE + .' WHERE tpl_id='.db_input($this->getId())); } return $num; } - /*** Static functions ***/ - function message_templates(){ - - //TODO: Make it database driven and dynamic - $messages=array('ticket_autoresp'=>array('name'=>'New Ticket Auto-response', - 'desc'=>'Autoresponse sent to user, if enabled, on new ticket.'), - 'ticket_autoreply'=>array('name'=>'New Ticket Auto-reply', - 'desc'=>'Canned Auto-reply sent to user on new ticket, based on filter matches. Overwrites "normal" auto-response.'), - 'msg_autoresp'=>array('name'=>'New Message Auto-response', - 'desc'=>'Confirmation sent to user when a new message is appended to an existing ticket.'), - 'ticket_notice'=>array('name'=>'New Ticket Notice', - 'desc'=>'Notice sent to user, if enabled, on new ticket created by staff on their behalf (e.g phone calls).'), - 'overlimit_notice'=>array('name'=>'Over Limit Notice', - 'desc'=>'A one time notice sent, if enabled, when user has reached the maximum allowed open tickets.'), - 'ticket_reply'=>array('name'=>'Response/Reply Template', - 'desc'=>'Template used on ticket response/reply'), - 'ticket_alert'=>array('name'=>'New Ticket Alert', - 'desc'=>'Alert sent to staff, if enabled, on new ticket.'), - 'msg_alert'=>array('name'=>'New Message Alert', - 'desc'=>'Alert sent to staff, if enabled, when user replies to an existing ticket.'), - 'note_alert'=>array('name'=>'Internal Note Alert', - 'desc'=>'Alert sent to selected staff, if enabled, on new internal note.'), - 'assigned_alert'=>array('name'=>'Ticket Assignment Alert', - 'desc'=>'Alert sent to staff on ticket assignment.'), - 'transfer_alert'=>array('name'=>'Ticket Transfer Alert', - 'desc'=>'Alert sent to staff on ticket transfer.'), - 'overdue_alert'=>array('name'=>'Overdue Ticket Alert', - 'desc'=>'Alert sent to staff on stale or overdue tickets.') - ); - return $messages; - } - - - function create($vars,&$errors) { - - return Template::save(0,$vars,$errors); + function create($vars,&$errors) { + return EmailTemplateGroup::save(0,$vars,$errors); + } + + function add($vars, &$errors) { + return self::lookup(self::create($vars, $errors)); } function getIdByName($name){ - $sql='SELECT tpl_id FROM '.EMAIL_TEMPLATE_TABLE.' WHERE name='.db_input($name); + $sql='SELECT tpl_id FROM '.EMAIL_TEMPLATE_GRP_TABLE.' WHERE name='.db_input($name); if(($res=db_query($sql)) && db_num_rows($res)) list($id)=db_fetch_row($res); @@ -336,7 +269,7 @@ class Template { } function lookup($id){ - return ($id && is_numeric($id) && ($t= new Template($id)) && $t->getId()==$id)?$t:null; + return ($id && is_numeric($id) && ($t= new EmailTemplateGroup($id)) && $t->getId()==$id)?$t:null; } function save($id, $vars, &$errors) { @@ -345,67 +278,185 @@ class Template { $tpl=null; $vars['name']=Format::striptags(trim($vars['name'])); - if($id && $id!=$vars['id']) + if($id && $id!=$vars['tpl_id']) $errors['err']='Internal error. Try again'; if(!$vars['name']) $errors['name']='Name required'; - elseif(($tid=Template::getIdByName($vars['name'])) && $tid!=$id) + elseif(($tid=EmailTemplateGroup::getIdByName($vars['name'])) && $tid!=$id) $errors['name']='Template name already exists'; - if(!$id && (!$vars['tpl_id'] || !($tpl=Template::lookup($vars['tpl_id'])))) + if(!$id && (!$vars['tpl_id'] || !($tpl=EmailTemplateGroup::lookup($vars['tpl_id'])))) $errors['tpl_id']='Selection required'; - + if($errors) return false; $sql=' updated=NOW() ' .' ,name='.db_input($vars['name']) .' ,isactive='.db_input($vars['isactive']) .' ,notes='.db_input($vars['notes']); - + if($id) { - $sql='UPDATE '.EMAIL_TEMPLATE_TABLE.' SET '.$sql.' WHERE tpl_id='.db_input($id); + $sql='UPDATE '.EMAIL_TEMPLATE_GRP_TABLE.' SET '.$sql.' WHERE tpl_id='.db_input($id); if(db_query($sql)) return true; $errors['err']='Unable to update the template. Internal error occurred'; - + } elseif($tpl && ($info=$tpl->getInfo())) { - $sql='INSERT INTO '.EMAIL_TEMPLATE_TABLE.' SET '.$sql - .' ,created=NOW() ' - .' ,ticket_autoresp_subj='.db_input($info['ticket_autoresp_subj']) - .' ,ticket_autoresp_body='.db_input($info['ticket_autoresp_body']) - .' ,ticket_autoreply_subj='.db_input($info['ticket_autoreply_subj']) - .' ,ticket_autoreply_body='.db_input($info['ticket_autoreply_body']) - .' ,ticket_notice_subj='.db_input($info['ticket_notice_subj']) - .' ,ticket_notice_body='.db_input($info['ticket_notice_body']) - .' ,ticket_alert_subj='.db_input($info['ticket_alert_subj']) - .' ,ticket_alert_body='.db_input($info['ticket_alert_body']) - .' ,message_autoresp_subj='.db_input($info['message_autoresp_subj']) - .' ,message_autoresp_body='.db_input($info['message_autoresp_body']) - .' ,message_alert_subj='.db_input($info['message_alert_subj']) - .' ,message_alert_body='.db_input($info['message_alert_body']) - .' ,note_alert_subj='.db_input($info['note_alert_subj']) - .' ,note_alert_body='.db_input($info['note_alert_body']) - .' ,transfer_alert_subj='.db_input($info['transfer_alert_subj']) - .' ,transfer_alert_body='.db_input($info['transfer_alert_body']) - .' ,assigned_alert_subj='.db_input($info['assigned_alert_subj']) - .' ,assigned_alert_body='.db_input($info['assigned_alert_body']) - .' ,ticket_overdue_subj='.db_input($info['ticket_overdue_subj']) - .' ,ticket_overdue_body='.db_input($info['ticket_overdue_body']) - .' ,ticket_overlimit_subj='.db_input($info['ticket_overlimit_subj']) - .' ,ticket_overlimit_body='.db_input($info['ticket_overlimit_body']) - .' ,ticket_reply_subj='.db_input($info['ticket_reply_subj']) - .' ,ticket_reply_body='.db_input($info['ticket_reply_body']); - - if(db_query($sql) && ($id=db_insert_id())) + $sql='INSERT INTO '.EMAIL_TEMPLATE_GRP_TABLE + .' SET created=NOW(), '.$sql; + if(!db_query($sql) || !($new_id=db_insert_id())) { + $errors['err']='Unable to create template. Internal error'; + return false; + } + + $sql='INSERT INTO '.EMAIL_TEMPLATE_TABLE.' + (created, updated, tpl_id, code_name, subject, body) + SELECT NOW() as created, NOW() as updated, '.db_input($new_id) + .' as tpl_id, code_name, subject, body + FROM '.EMAIL_TEMPLATE_TABLE + .' WHERE tpl_id='.db_input($tpl->getId()); + + if(db_query($sql) && db_insert_id()) + return $new_id; + } + + return false; + } +} + +class EmailTemplate { + + var $id; + var $_group; + + function EmailTemplate($id, $group=null){ + $this->id=0; + $this->load($id); + if ($group) $this->_group = $group; + } + + function load($id) { + + if(!$id && !($id=$this->getId())) + return false; + + $sql='SELECT * FROM '.EMAIL_TEMPLATE_TABLE + .' WHERE id='.db_input($id); + + if(!($res=db_query($sql))|| !db_num_rows($res)) + return false; + + + $this->ht=db_fetch_array($res); + $this->id=$this->ht['id']; + + return true; + } + + function reload() { + return $this->load($this->getId()); + } + + function getId(){ + return $this->id; + } + + function getSubject() { + return $this->ht['subject']; + } + + function getBody() { + return $this->ht['body']; + } + + function getCodeName() { + return $this->ht['code_name']; + } + + function getTplId() { + return $this->ht['tpl_id']; + } + + function getGroup() { + if (!isset($this->_group)) + $this->_group = EmailTemplateGroup::lookup($this->getTplId()); + return $this->_group; + + } + + function getDescription() { + return $this->getGroup()->getTemplateDescription($this->ht['code_name']); + } + + function update($vars, &$errors) { + + if(!$this->save($this->getId(),$vars,$errors)) + return false; + + $this->reload(); + + return true; + } + + function save($id, $vars, &$errors) { + if(!$vars['subj']) + $errors['subj']='Message subject required'; + + if(!$vars['body']) + $errors['body']='Message body required'; + + if (!$id) { + if (!$vars['tpl_id']) + $errors['tpl_id']='Template group required'; + if (!$vars['code_name']) + $errprs['code_name']='Code name required'; + } + + if ($errors) + return false; + + if ($id) { + $sql='UPDATE '.EMAIL_TEMPLATE_TABLE.' SET updated=NOW() ' + .', subject='.db_input($vars['subj']) + .', body='.db_input($vars['body']) + .' WHERE id='.db_input($this->getId()); + + return (db_query($sql)); + } else { + $sql='INSERT INTO '.EMAIL_TEMPLATE_TABLE.' SET created=NOW(), + updated=NOW(), tpl_id='.db_input($vars['tpl_id']) + .', code_name='.db_input($vars['code_name']) + .', subject='.db_input($vars['subj']) + .', body='.db_input($vars['body']); + if (db_query($sql) && ($id=db_insert_id())) return $id; - - $errors['err']='Unable to create template. Internal error'; } - + return null; + } + + function create($vars, &$errors) { + return self::save(0, $vars, $errors); + } + + function add($vars, &$errors) { + return self::lookup(self::create($vars, $errors)); + } + + function lookupByName($tpl, $name, $group=null) { + $sql = 'SELCT id FROM '.EMAIL_TEMPLATE_TABLE + .' WHERE tpl_id='.db_input($tpl_id) + .' AND code_name='.db_input($name); + if (($res=db_query($sql)) && ($id=db_result($res))) + return self::lookup($id, $group); + return false; } + + function lookup($id, $group=null) { + return ($id && is_numeric($id) && ($t= new EmailTemplate($id, $group)) && $t->getId()==$id)?$t:null; + } } ?> diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index 00a65ebc54cfc1345d55ea365e00f5ff9aaa12ca..707aa69dda1d5756453c9f86caa1efcff33406b4 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -88,7 +88,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="tpl_id"> <option value="0">— System default —</option> <?php - $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_TABLE.' tpl WHERE isactive=1 ORDER by name'; + $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"':''; @@ -144,7 +144,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <span class="error"> <?php echo $errors['manager_id']; ?></span> </td> </tr> - <?php + <?php } ?> <tr> @@ -167,7 +167,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <input type="checkbox" name="ticket_auto_response" value="0" <?php echo !$info['ticket_auto_response']?'checked="checked"':''; ?> > - + <strong>Disable</strong> new ticket auto-response for this Dept. </td> </tr> @@ -217,7 +217,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); .' 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) + 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"':''; diff --git a/include/staff/settings-system.inc.php b/include/staff/settings-system.inc.php index 1576ca1f9ab0f51f4ef60b120a1d7ec046f879dc..6fade6d964b1fab6cca118fa0b8cff86841aa417 100644 --- a/include/staff/settings-system.inc.php +++ b/include/staff/settings-system.inc.php @@ -60,7 +60,7 @@ $gmtime = Misc::gmtime(); <select name="default_template_id"> <option value="">— Select Default Template —</option> <?php - $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_TABLE.' WHERE isactive=1 ORDER BY name'; + $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_GRP_TABLE.' WHERE isactive=1 ORDER BY name'; if(($res=db_query($sql)) && db_num_rows($res)){ while (list($id, $name) = db_fetch_row($res)){ $selected = ($config['default_template_id']==$id)?'selected="selected"':''; ?> @@ -99,7 +99,7 @@ $gmtime = Misc::gmtime(); </tr> <tr> <td>Purge Logs:</td> - <td> + <td> <select name="log_graceperiod"> <option value=0 selected>Never Purge Logs</option> <?php @@ -172,7 +172,7 @@ $gmtime = Misc::gmtime(); echo sprintf('<option value="%d" %s>%d</option>', $i,(($config['client_login_timeout']==$i)?'selected="selected"':''), $i); } ?> - </select> minute lock-out is enforced. + </select> minute lock-out is enforced. </td> </tr> diff --git a/include/staff/template.inc.php b/include/staff/template.inc.php index aff5f8e3b780e46bd54bc23e0ded14694fe63e71..e4c52705acc893f63c623695517ee9077932bc4d 100644 --- a/include/staff/template.inc.php +++ b/include/staff/template.inc.php @@ -8,8 +8,8 @@ if($template && $_REQUEST['a']!='add'){ $action='update'; $submit_text='Save Changes'; $info=$template->getInfo(); - $info['id']=$template->getId(); - $qstr.='&id='.$template->getId(); + $info['tpl_id']=$template->getId(); + $qstr.='&tpl_id='.$template->getId(); }else { $title='Add New Template'; $action='add'; @@ -23,7 +23,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <?php csrf_token(); ?> <input type="hidden" name="do" value="<?php echo $action; ?>"> <input type="hidden" name="a" value="<?php echo Format::htmlchars($_REQUEST['a']); ?>"> - <input type="hidden" name="id" value="<?php echo $info['id']; ?>"> + <input type="hidden" name="tpl_id" value="<?php echo $info['tpl_id']; ?>"> <h2>Email Template</h2> <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> <thead> @@ -74,10 +74,31 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </th> </tr> <?php - foreach(Template::message_templates() as $k=>$tpl){ - echo sprintf('<tr><td colspan=2> <strong><a href="templates.php?id=%d&a=manage&tpl=%s">%s</a></strong> - <em>%s</em></td></tr>', - $template->getId(),$k,Format::htmlchars($tpl['name']),Format::htmlchars($tpl['desc'])); + foreach($template->getTemplates() as $tpl){ + $info = $tpl->getDescription(); + if (!$info['name']) + continue; + echo sprintf('<tr><td colspan=2> <strong><a href="templates.php?id=%d&a=manage">%s</a></strong> - <em>%s</em></td></tr>', + $tpl->getId(),Format::htmlchars($info['name']), + Format::htmlchars($info['desc'])); } + if (($undef = $template->getUndefinedTemplateNames())) { ?> + <tr> + <th colspan="2"> + <em><strong>Unimplemented Template Messages</strong>: Click + on the message to implement</em> + </th> + </tr> + <?php + foreach($template->getUndefinedTemplateNames() as $cn=>$info){ + echo sprintf('<tr><td colspan=2> <strong><a + href="templates.php?tpl_id=%d&a=implement&code_name=%s" + style="color:red;text-decoration:underline" + >%s</a></strong> - <em>%s</em></td></tr>', + $template->getId(),$cn,Format::htmlchars($info['name']), + Format::htmlchars($info['desc'])); + } + } }else{ ?> <tr> <td width="180" class="required"> @@ -87,7 +108,7 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="tpl_id"> <option value="0">— Select One ‐</option> <?php - $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_TABLE.' ORDER by name'; + $sql='SELECT tpl_id,name FROM '.EMAIL_TEMPLATE_GRP_TABLE.' 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"':''; diff --git a/include/staff/templates.inc.php b/include/staff/templates.inc.php index a0f5de468a76bf7cde53e73bdc0767606ea6207b..1e1057353bfa82eadaca4d08857d7061fa0ce9fd 100644 --- a/include/staff/templates.inc.php +++ b/include/staff/templates.inc.php @@ -3,7 +3,7 @@ if(!defined('OSTADMININC') || !$thisstaff->isAdmin()) die('Access Denied'); $qstr=''; $sql='SELECT tpl.*,count(dept.tpl_id) as depts '. - 'FROM '.EMAIL_TEMPLATE_TABLE.' tpl '. + 'FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl '. 'LEFT JOIN '.DEPT_TABLE.' dept USING(tpl_id) '. 'WHERE 1 '; $sortOptions=array('name'=>'tpl.name','status'=>'tpl.isactive','created'=>'tpl.created','updated'=>'tpl.updated'); @@ -27,7 +27,7 @@ $x=$sort.'_sort'; $$x=' class="'.strtolower($order).'" '; $order_by="$order_column $order "; -$total=db_count('SELECT count(*) FROM '.EMAIL_TEMPLATE_TABLE.' tpl '); +$total=db_count('SELECT count(*) FROM '.EMAIL_TEMPLATE_GRP_TABLE.' tpl '); $page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1; $pageNav=new Pagenate($total, $page, PAGE_LIMIT); $pageNav->setURL('templates.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order'])); @@ -56,7 +56,7 @@ else <caption><?php echo $showing; ?></caption> <thead> <tr> - <th width="7"> </th> + <th width="7"> </th> <th width="350"><a <?php echo $name_sort; ?> href="templates.php?<?php echo $qstr; ?>&sort=name">Name</a></th> <th width="100"><a <?php echo $status_sort; ?> href="templates.php?<?php echo $qstr; ?>&sort=status">Status</a></th> <th width="80"><a <?php echo $inuse_sort; ?> href="templates.php?<?php echo $qstr; ?>&sort=inuse">In-Use</a></th> @@ -75,15 +75,15 @@ else $sel=false; if($ids && in_array($row['tpl_id'],$ids)) $sel=true; - + $default=($defaultTplId==$row['tpl_id'])?'<small class="fadded">(System Default)</small>':''; ?> <tr id="<?php echo $row['tpl_id']; ?>"> <td width=7px> - <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['tpl_id']; ?>" + <input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['tpl_id']; ?>" <?php echo $sel?'checked="checked"':''; ?> <?php echo $default?'disabled="disabled"':''; ?> > </td> - <td> <a href="templates.php?id=<?php echo $row['tpl_id']; ?>"><?php echo Format::htmlchars($row['name']); ?></a> + <td> <a href="templates.php?tpl_id=<?php echo $row['tpl_id']; ?>"><?php echo Format::htmlchars($row['name']); ?></a> <?php echo $default; ?></td> <td> <?php echo $row['isactive']?'Active':'<b>Disabled</b>'; ?></td> <td> <?php echo ($inuse)?'<b>Yes</b>':'No'; ?></td> diff --git a/include/staff/tpl.inc.php b/include/staff/tpl.inc.php index 13dcf25718874fb7eb48371ad68daba9ff078312..8c1ede75e5e4ed12092c08201d22a0aebeaa2cc2 100644 --- a/include/staff/tpl.inc.php +++ b/include/staff/tpl.inc.php @@ -1,23 +1,45 @@ <?php -$msgtemplates=Template::message_templates(); $info=Format::htmlchars(($errors && $_POST)?$_POST:$_REQUEST); -$info['tpl']=($info['tpl'] && $msgtemplates[$info['tpl']])?$info['tpl']:'ticket_autoresp'; + +if (is_a($template, EmailTemplateGroup)) { + // New template implementation + $id = 0; + $tpl_id = $template->getId(); + $name = $template->getName(); + $selected = $_REQUEST['code_name']; + $action = 'implement'; + $extras = array('code_name'=>$selected, 'tpl_id'=>$tpl_id); + $msgtemplates=$template->all_names; +} else { + // Template edit + $id = $template->getId(); + $tpl_id = $template->getTplId(); + $name = $template->getGroup()->getName(); + $selected = $template->getCodeName(); + $action = 'updatetpl'; + $extras = array(); + $msgtemplates=$template->getGroup()->all_names; + $info=array_merge(array('subj'=>$template->getSubject(), 'body'=>$template->getBody()),$info); +} +$info['tpl']=($info['tpl'] && $msgtemplates[$info['tpl']])?$info['tpl']:'ticket.autoresp'; $tpl=$msgtemplates[$info['tpl']]; -$info=array_merge($template->getMsgTemplate($info['tpl']),$info); ?> -<h2>Email Template Message - <span><?php echo $template->getName(); ?></span></h2> +<h2>Email Template Message - <span><?php echo $name; ?></span></h2> <div style="padding-top:10px;padding-bottom:5px;"> <form method="get" action="templates.php"> - <input type="hidden" name="id" value="<?php echo $template->getId(); ?>"> <input type="hidden" name="a" value="manage"> Message Template: - <select id="tpl_options" name="tpl" style="width:300px;"> + <select id="tpl_options" name="id" style="width:300px;"> <option value="">— Select Setting Group —</option> <?php - foreach($msgtemplates as $k=>$v) { - $sel=($info['tpl']==$k)?'selected="selected"':''; - echo sprintf('<option value="%s" %s>%s</option>',$k,$sel,$v['name']); + foreach($template->getGroup()->getTemplates() as $cn=>$t) { + $nfo=$t->getDescription(); + if (!$nfo['name']) + continue; + $sel=($selected==$cn)?'selected="selected"':''; + echo sprintf('<option value="%s" %s>%s</option>', + $t->getId(),$sel,$nfo['name']); } ?> </select> @@ -25,12 +47,14 @@ $info=array_merge($template->getMsgTemplate($info['tpl']),$info); <font color="red"><?php echo $errors['tpl']; ?></font> </form> </div> -<form action="templates.php?id=<?php echo $template->getId(); ?>" method="post" id="save"> +<form action="templates.php?id=<?php echo $id; ?>" method="post" id="save"> <?php csrf_token(); ?> -<input type="hidden" name="id" value="<?php echo $template->getId(); ?>"> -<input type="hidden" name="tpl" value="<?php echo $info['tpl']; ?>"> +<?php foreach ($extras as $k=>$v) { ?> + <input type="hidden" name="<?php echo $k; ?>" value="<?php echo $v; ?>" /> +<?php } ?> +<input type="hidden" name="id" value="<?php echo $id; ?>"> <input type="hidden" name="a" value="manage"> -<input type="hidden" name="do" value="updatetpl"> +<input type="hidden" name="do" value="<?php echo $action; ?>"> <table class="form_table settings_table" width="940" border="0" cellspacing="0" cellpadding="2"> <thead> @@ -59,6 +83,7 @@ $info=array_merge($template->getMsgTemplate($info['tpl']),$info); <p style="padding-left:210px;"> <input class="button" type="submit" name="submit" value="Save Changes"> <input class="button" type="reset" name="reset" value="Reset Changes"> - <input class="button" type="button" name="cancel" value="Cancel Changes" onclick='window.location.href="templates.php?id=<?php echo $template->getId(); ?>"'> + <input class="button" type="button" name="cancel" value="Cancel Changes" + onclick='window.location.href="templates.php?tpl_id=<?php echo $tpl_id; ?>"'> </p> </form> diff --git a/include/upgrader/sql/852ca89e-templates.patch.sql b/include/upgrader/sql/852ca89e-templates.patch.sql new file mode 100644 index 0000000000000000000000000000000000000000..b35857d6268290e7ddfcef0ccc876cb2f9f5f497 --- /dev/null +++ b/include/upgrader/sql/852ca89e-templates.patch.sql @@ -0,0 +1,104 @@ +/** + * @version v1.7.1 + * @signature 00000000000000000000000000000000 + * + * - Migrates the email template table to two tables, groups and templates. + * Templates organized in a separate table by group will allow for a more + * extensible model for email templates. + */ + +DROP TABLE IF EXISTS `%TABLE_PREFIX%email_template_group`; +CREATE TABLE `%TABLE_PREFIX%email_template_group` ( + `tpl_id` int(11) NOT NULL auto_increment, + `isactive` tinyint(1) unsigned NOT NULL default '0', + `name` varchar(32) NOT NULL default '', + `notes` text, + `created` datetime NOT NULL, + `updated` timestamp NOT NULL, + PRIMARY KEY (`tpl_id`) +) DEFAULT CHARSET=utf8; + +INSERT INTO `%TABLE_PREFIX%email_template_group` + SELECT `tpl_id`, `isactive`, `name`, `notes`, `created`, `updated` + FROM `%TABLE_PREFIX%email_template`; + +CREATE TABLE `%TABLE_PREFIX%_email_template` ( + `id` int(11) unsigned NOT NULL auto_increment, + `tpl_id` int(11) unsigned NOT NULL, + `code_name` varchar(32) NOT NULL, + `subject` varchar(255) NOT NULL default '', + `body` text NOT NULL, + `created` datetime NOT NULL, + `updated` datetime NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `template_lookup` (`tpl_id`, `code_name`) +) DEFAULT CHARSET=utf8; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.autoresp', ticket_autoresp_subj, ticket_autoresp_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.autoreply', ticket_autoreply_subj, ticket_autoreply_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'message.autoresp', message_autoresp_subj, message_autoresp_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.notice', ticket_notice_subj, ticket_notice_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.overlimit', ticket_overlimit_subj, ticket_overlimit_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.reply', ticket_reply_subj, ticket_reply_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.alert', ticket_alert_subj, ticket_alert_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'message.alert', message_alert_subj, message_alert_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'note.alert', note_alert_subj, note_alert_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'assigned.alert', assigned_alert_subj, assigned_alert_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'transfer.alert', transfer_alert_subj, transfer_alert_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +INSERT INTO `%TABLE_PREFIX%_email_template` + (`tpl_id`, `code_name`, `subject`, `body`, `created`, `updated`) + SELECT `tpl_id`, 'ticket.overdue', ticket_overdue_subj, ticket_overdue_body, `created`, `updated` + FROM `%TABLE_PREFIX%_email_template`; + +DROP TABLE `%TABLE_PREFIX%email_template`; +ALTER TABLE `%TABLE_PREFIX%_email_template` + RENAME TO `%TABLE_PREFIX%email_template`; + +-- Finished with patch +UPDATE `%TABLE_PREFIX%config` + SET `value` = '00000000000000000000000000000000' + WHERE `key` = 'schema_signature' AND `namespace` = 'core'; diff --git a/main.inc.php b/main.inc.php index fc9e4c5b84dd6242a7445faa64f2827ac9bf7045..6f7c932045fa46099de9d707b69dc105bdfecfba 100644 --- a/main.inc.php +++ b/main.inc.php @@ -179,6 +179,7 @@ define('TICKET_EMAIL_INFO_TABLE',TABLE_PREFIX.'ticket_email_info'); define('EMAIL_TABLE',TABLE_PREFIX.'email'); + define('EMAIL_TEMPLATE_GRP_TABLE',TABLE_PREFIX.'email_template_group'); define('EMAIL_TEMPLATE_TABLE',TABLE_PREFIX.'email_template'); define('FILTER_TABLE',TABLE_PREFIX.'filter'); diff --git a/scp/templates.php b/scp/templates.php index a27d69b08a67ac1748ff7b2457d92b238bc390e3..fd0ed3dde61e306030d5ee5d89fc40d393526ea8 100644 --- a/scp/templates.php +++ b/scp/templates.php @@ -16,7 +16,11 @@ require('admin.inc.php'); include_once(INCLUDE_DIR.'class.template.php'); $template=null; -if($_REQUEST['id'] && !($template=Template::lookup($_REQUEST['id']))) +if($_REQUEST['tpl_id'] && + !($template=EmailTemplateGroup::lookup($_REQUEST['tpl_id']))) + $errors['err']='Unknown or invalid template group ID.'; +elseif($_REQUEST['id'] && + !($template=EmailTemplate::lookup($_REQUEST['id']))) $errors['err']='Unknown or invalid template ID.'; if($_POST){ @@ -24,13 +28,23 @@ if($_POST){ case 'updatetpl': if(!$template){ $errors['err']='Unknown or invalid template'; - }elseif($template->updateMsgTemplate($_POST,$errors)){ + }elseif($template->update($_POST,$errors)){ $template->reload(); $msg='Message template updated successfully'; }elseif(!$errors['err']){ $errors['err']='Error updating message template. Try again!'; } break; + case 'implement': + if(!$template){ + $errors['err']='Unknown or invalid template'; + }elseif($new = EmailTemplate::add($_POST,$errors)){ + $template = $new; + $msg='Message template updated successfully'; + }elseif(!$errors['err']){ + $errors['err']='Error updating message template. Try again!'; + } + break; case 'update': if(!$template){ $errors['err']='Unknown or invalid template'; @@ -41,7 +55,8 @@ if($_POST){ } break; case 'add': - if((Template::create($_POST,$errors))){ + if(($new=EmailTemplateGroup::add($_POST,$errors))){ + $template=$new; $msg='Template added successfully'; $_REQUEST['a']=null; }elseif(!$errors['err']){ @@ -55,7 +70,7 @@ if($_POST){ $count=count($_POST['ids']); switch(strtolower($_POST['a'])) { case 'enable': - $sql='UPDATE '.EMAIL_TEMPLATE_TABLE.' SET isactive=1 ' + $sql='UPDATE '.EMAIL_TEMPLATE_GRP_TABLE.' SET isactive=1 ' .' WHERE tpl_id IN ('.implode(',', db_input($_POST['ids'])).')'; if(db_query($sql) && ($num=db_affected_rows())){ if($num==$count) @@ -69,7 +84,7 @@ if($_POST){ case 'disable': $i=0; foreach($_POST['ids'] as $k=>$v) { - if(($t=Template::lookup($v)) && !$t->isInUse() && $t->disable()) + if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->disable()) $i++; } if($i && $i==$count) @@ -82,7 +97,7 @@ if($_POST){ case 'delete': $i=0; foreach($_POST['ids'] as $k=>$v) { - if(($t=Template::lookup($v)) && !$t->isInUse() && $t->delete()) + if(($t=EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $t->delete()) $i++; } @@ -107,6 +122,8 @@ if($_POST){ $page='templates.inc.php'; if($template && !strcasecmp($_REQUEST['a'],'manage')){ $page='tpl.inc.php'; +}elseif($template && !strcasecmp($_REQUEST['a'],'implement')){ + $page='tpl.inc.php'; }elseif($template || !strcasecmp($_REQUEST['a'],'add')){ $page='template.inc.php'; } diff --git a/setup/inc/class.installer.php b/setup/inc/class.installer.php index 178f310e96ea1f4405a54f382b3d5ce2cdfb30e0..40d9137dc6ea723ea5c4cd9d357b4523bc234a43 100644 --- a/setup/inc/class.installer.php +++ b/setup/inc/class.installer.php @@ -134,7 +134,7 @@ class Installer extends SetupWizard { $sql='SELECT `dept_id` FROM '.PREFIX.'department ORDER BY `dept_id` LIMIT 1'; $dept_id_1 = db_result(db_query($sql, false), 0); - $sql='SELECT `tpl_id` FROM '.PREFIX.'email_template ORDER BY `tpl_id` LIMIT 1'; + $sql='SELECT `tpl_id` FROM '.PREFIX.'email_template_group ORDER BY `tpl_id` LIMIT 1'; $template_id_1 = db_result(db_query($sql, false), 0); $sql='SELECT `group_id` FROM '.PREFIX.'groups ORDER BY `group_id` LIMIT 1'; diff --git a/setup/inc/sql/osTicket-mysql.sql b/setup/inc/sql/osTicket-mysql.sql index 4b6dc7f9d4c38933a1b37a1e6b10430e8d181090..cccb233d99ecf4d100a69a6729e2def4cdeb6593 100644 --- a/setup/inc/sql/osTicket-mysql.sql +++ b/setup/inc/sql/osTicket-mysql.sql @@ -301,46 +301,63 @@ INSERT INTO `%TABLE_PREFIX%filter_rule` ( `filter_id`, `isactive`, `what`,`how`,`val`,`created`) VALUES (LAST_INSERT_ID(), 1, 'email', 'equal', 'test@example.com',NOW()); -DROP TABLE IF EXISTS `%TABLE_PREFIX%email_template`; -CREATE TABLE `%TABLE_PREFIX%email_template` ( +DROP TABLE IF EXISTS `%TABLE_PREFIX%email_template_group`; +CREATE TABLE `%TABLE_PREFIX%email_template_group` ( `tpl_id` int(11) NOT NULL auto_increment, - `cfg_id` int(10) unsigned NOT NULL default '0', `isactive` tinyint(1) unsigned NOT NULL default '0', `name` varchar(32) NOT NULL default '', `notes` text, - `ticket_autoresp_subj` varchar(255) NOT NULL default '', - `ticket_autoresp_body` text NOT NULL, - `ticket_autoreply_subj` varchar(255) NOT NULL default '', - `ticket_autoreply_body` text NOT NULL, - `ticket_notice_subj` varchar(255) NOT NULL, - `ticket_notice_body` text NOT NULL, - `ticket_alert_subj` varchar(255) NOT NULL default '', - `ticket_alert_body` text NOT NULL, - `message_autoresp_subj` varchar(255) NOT NULL default '', - `message_autoresp_body` text NOT NULL, - `message_alert_subj` varchar(255) NOT NULL default '', - `message_alert_body` text NOT NULL, - `note_alert_subj` varchar(255) NOT NULL, - `note_alert_body` text NOT NULL, - `assigned_alert_subj` varchar(255) NOT NULL default '', - `assigned_alert_body` text NOT NULL, - `transfer_alert_subj` varchar(255) NOT NULL default '', - `transfer_alert_body` text NOT NULL, - `ticket_overdue_subj` varchar(255) NOT NULL default '', - `ticket_overdue_body` text NOT NULL, - `ticket_overlimit_subj` varchar(255) NOT NULL default '', - `ticket_overlimit_body` text NOT NULL, - `ticket_reply_subj` varchar(255) NOT NULL default '', - `ticket_reply_body` text NOT NULL, + `created` datetime NOT NULL, + `updated` timestamp NOT NULL, + PRIMARY KEY (`tpl_id`) +) DEFAULT CHARSET=utf8; + +INSERT INTO `%TABLE_PREFIX%email_template_group` SET + `isactive` = 1, `name` = 'osTicket Default Template', + `notes` = 'Default osTicket templates', `created` = NOW(), `updated` = NOW(); + +DROP TABLE IF EXISTS `%TABLE_PREFIX%email_template`; +CREATE TABLE `%TABLE_PREFIX%email_template` ( + `id` int(11) UNSIGNED NOT NULL auto_increment, + `tpl_id` int(11) UNSIGNED NOT NULL, + `code_name` varchar(32) NOT NULL, + `subject` varchar(255) NOT NULL default '', + `body` text NOT NULL, `created` datetime NOT NULL, `updated` datetime NOT NULL, - PRIMARY KEY (`tpl_id`), - KEY `cfg_id` (`cfg_id`) + PRIMARY KEY (`id`), + UNIQUE KEY `template_lookup` (`tpl_id`, `code_name`) ) DEFAULT CHARSET=utf8; -- TODO: Dump revised copy before release!!! -INSERT INTO `%TABLE_PREFIX%email_template` (`isactive`, `name`, `notes`, `ticket_autoresp_subj`, `ticket_autoresp_body`, `ticket_autoreply_subj`, `ticket_autoreply_body`, `ticket_notice_subj`, `ticket_notice_body`, `ticket_alert_subj`, `ticket_alert_body`, `message_autoresp_subj`, `message_autoresp_body`, `message_alert_subj`, `message_alert_body`, `note_alert_subj`, `note_alert_body`, `assigned_alert_subj`, `assigned_alert_body`, `transfer_alert_subj`, `transfer_alert_body`, `ticket_overdue_subj`, `ticket_overdue_body`, `ticket_overlimit_subj`, `ticket_overlimit_body`, `ticket_reply_subj`, `ticket_reply_body`, `created`, `updated`) VALUES -(1, 'osTicket Default Template', 'Default osTicket templates', 'Support Ticket Opened [#%{ticket.number}]', '%{ticket.name},\r\n\r\nA request for support has been created and assigned ticket #%{ticket.number}. A representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %{ticket.client_link}.\r\n\r\nIf you wish to send additional comments or information regarding this issue, please don''t open a new ticket. Simply login using the link above and update the ticket.\r\n\r\n%{signature}', 'Support Ticket Opened [#%{ticket.number}]', '%{ticket.name},\r\n\r\nA request for support has been created and assigned ticket #%{ticket.number} with the following auto-reply:\r\n\r\n%{response}\r\n\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not open another ticket. If need be, representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %{ticket.client_link}.', '[#%{ticket.number}] %{ticket.subject}', '%{ticket.name},\r\n\r\nOur customer care team has created a ticket, #%{ticket.number} on your behalf, with the following message.\r\n\r\n%{message}\r\n\r\nIf you wish to provide additional comments or information regarding this issue, please don''t open a new ticket. You can update or view this ticket''s progress online here: %{ticket.client_link}.\r\n\r\n%{signature}', 'New Ticket Alert', '%{recipient},\r\n\r\nNew ticket #%{ticket.number} created.\r\n\r\n-----------------------\r\nName: %{ticket.name}\r\nEmail: %{ticket.email}\r\nDept: %{ticket.dept.name}\r\n\r\n%{message}\r\n-----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', '[#%{ticket.number}] Message Added', '%{ticket.name},\r\n\r\nYour reply to support request #%{ticket.number} has been noted.\r\n\r\nYou can view this support request progress online here: %{ticket.client_link}.\r\n\r\n%{signature}', 'New Message Alert', '%{recipient},\r\n\r\nNew message appended to ticket #%{ticket.number}\r\n\r\n----------------------\r\nName: %{ticket.name}\r\nEmail: %{ticket.email}\r\nDept: %{ticket.dept.name}\r\n\r\n%{message}\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'New Internal Note Alert', '%{recipient},\r\n\r\nInternal note appended to ticket #%{ticket.number}\r\n\r\n----------------------\r\n* %{note.title} *\r\n\r\n%{note.message}\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Ticket #%{ticket.number} Assigned to you', '%{assignee},\r\n\r\nTicket #%{ticket.number} has been assigned to you by %{assigner}\r\n\r\n----------------------\r\n\r\n%{comments}\r\n\r\n----------------------\r\n\r\nTo view complete details, simply login to the support system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Support Ticket System - powered by osTicket.', 'Ticket Transfer #%{ticket.number} - %{ticket.dept.name}', '%{recipient},\r\n\r\nTicket #%{ticket.number} has been transferred to %{ticket.dept.name} department by %{staff.name}\r\n\r\n----------------------\r\n\r\n%{comments}\r\n\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.', 'Stale Ticket Alert', '%{recipient},\r\n\r\nA ticket, #%{ticket.number} assigned to you or in your department is seriously overdue.\r\n\r\n%{ticket.staff_link}\r\n\r\nWe should all work hard to guarantee that all tickets are being addressed in a timely manner.\r\n\r\n- Your friendly (although with limited patience) Support Ticket System - powered by osTicket.', 'Open Tickets Limit Reached', '%{ticket.name}\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%{url}/tickets.php?e=%{ticket.email}\r\n\r\nThank you.\r\n\r\nSupport Ticket System', '[#%{ticket.number}] %{ticket.subject}', '%{ticket.name},\r\n\r\nA customer support staff member has replied to your support request, #%{ticket.number} with the following response:\r\n\r\n%{response}\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not send another email. Instead, reply to this email or login to your account for a complete archive of all your support requests and responses.\r\n\r\n%{ticket.client_link}\r\n\r\n%{signature}', NOW(), NOW()); +INSERT INTO `%TABLE_PREFIX%email_template` (`code_name`, `subject`, `body`) + VALUES ( + 'ticket.autoresp', 'Support Ticket Opened [#%{ticket.number}]', '%{ticket.name}, \r\n\r\nA request for support has been created and assigned ticket #%{ticket.number}. A representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %{ticket.client_link}.\r\n\r\nIf you wish to send additional comments or information regarding this issue, please don''t open a new ticket. Simply login using the link above and update the ticket.\r\n\r\n%{signature}' + ), ( + 'ticket.autoreply', 'Support Ticket Opened [#%{ticket.number}]', '%{ticket.name}, \r\n\r\nA request for support has been created and assigned ticket #%{ticket.number} with the following auto-reply:\r\n\r\n%{response}\r\n\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not open another ticket. If need be, representative will follow-up with you as soon as possible.\r\n\r\nYou can view this ticket''s progress online here: %{ticket.client_link}.' + ), ( + 'ticket.notice', '[#%{ticket.number}] %{ticket.subject}', '%{ticket.name}, \r\n\r\nOur customer care team has created a ticket, #%{ticket.number} on your behalf, with the following message.\r\n\r\n%{message}\r\n\r\nIf you wish to provide additional comments or information regarding this issue, please don''t open a new ticket. You can update or view this ticket''s progress online here: %{ticket.client_link}.\r\n\r\n%{signature}' + ), ( + 'ticket.alert', 'New Ticket Alert', '%{recipient}, \r\n\r\nNew ticket #%{ticket.number} created.\r\n\r\n-----------------------\r\nName: %{ticket.name}\r\nEmail: %{ticket.email}\r\nDept: %{ticket.dept.name}\r\n\r\n%{message}\r\n-----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.' + ), ( + 'message.autoresp', '[#%{ticket.number}] Message Added', '%{ticket.name}, \r\n\r\nYour reply to support request #%{ticket.number} has been noted.\r\n\r\nYou can view this support request progress online here: %{ticket.client_link}.\r\n\r\n%{signature}' + ), ( + 'message.alert', 'New Message Alert', '%{recipient}, \r\n\r\nNew message appended to ticket #%{ticket.number}\r\n\r\n----------------------\r\nName: %{ticket.name}\r\nEmail: %{ticket.email}\r\nDept: %{ticket.dept.name}\r\n\r\n%{message}\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.' + ), ( + 'note.alert', 'New Internal Note Alert', '%{recipient}, \r\n\r\nInternal note appended to ticket #%{ticket.number}\r\n\r\n----------------------\r\n* %{note.title} *\r\n\r\n%{note.message}\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.' + ), ( + 'assigned.alert', 'Ticket #%{ticket.number} Assigned to you', '%{assignee}, \r\n\r\nTicket #%{ticket.number} has been assigned to you by %{assigner}\r\n\r\n----------------------\r\n\r\n%{comments}\r\n\r\n----------------------\r\n\r\nTo view complete details, simply login to the support system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Support Ticket System - powered by osTicket.' + ), ( + 'transfer.alert', 'Ticket Transfer #%{ticket.number} - %{ticket.dept.name}', '%{recipient}, \r\n\r\nTicket #%{ticket.number} has been transferred to %{ticket.dept.name} department by %{staff.name}\r\n\r\n----------------------\r\n\r\n%{comments}\r\n\r\n----------------------\r\n\r\nTo view/respond to the ticket, please login to the support ticket system.\r\n\r\n%{ticket.staff_link}\r\n\r\n- Your friendly Customer Support System - powered by osTicket.' + ), ( + 'ticket.overdue', 'Stale Ticket Alert', '%{recipient}, \r\n\r\nA ticket, #%{ticket.number} assigned to you or in your department is seriously overdue.\r\n\r\n%{ticket.staff_link}\r\n\r\nWe should all work hard to guarantee that all tickets are being addressed in a timely manner.\r\n\r\n- Your friendly (although with limited patience) Support Ticket System - powered by osTicket.' + ), ( + 'ticket.overlimit', 'Open Tickets Limit Reached', '%{ticket.name}\r\n\r\nYou have reached the maximum number of open tickets allowed.\r\n\r\nTo be able to open another ticket, one of your pending tickets must be closed. To update or add comments to an open ticket simply login using the link below.\r\n\r\n%{url}/tickets.php?e=%{ticket.email}\r\n\r\nThank you.\r\n\r\nSupport Ticket System' + ), ( + 'ticket.reply', '[#%{ticket.number}] %{ticket.subject}', '%{ticket.name}, \r\n\r\nA customer support staff member has replied to your support request, #%{ticket.number} with the following response:\r\n\r\n%{response}\r\n\r\nWe hope this response has sufficiently answered your questions. If not, please do not send another email. Instead, reply to this email or login to your account for a complete archive of all your support requests and responses.\r\n\r\n%{ticket.client_link}\r\n\r\n%{signature}' + ); +UPDATE `%TABLE_PREFIX%email_template` SET `created`=NOW(), `updated`=NOW(), + `tpl_id` = (SELECT `tpl_id` FROM `%TABLE_PREFIX%email_template_group`); DROP TABLE IF EXISTS `%TABLE_PREFIX%file`; CREATE TABLE `%TABLE_PREFIX%file` (