function save($id, $vars, &$errors) { global $cfg; $tpl = null; $vars['name'] = Format::striptags(trim($vars['name'])); if ($id && $id != $vars['id']) { $errors['err'] = 'Internal error. Try again'; } if (!$vars['name']) { $errors['name'] = 'Name required'; } elseif (($tid = Template::getIdByName($vars['name'])) && $tid != $id) { $errors['name'] = 'Template name already exists'; } if (!$id && (!$vars['tpl_id'] || !($tpl = Template::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); 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() ' . ' ,cfg_id=' . db_input($cfg->getId()) . ' ,ticket_autoresp_subj=' . db_input($info['ticket_autoresp_subj']) . ' ,ticket_autoresp_body=' . db_input($info['ticket_autoresp_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']) . ' ,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())) { return $id; } $errors['err'] = 'Unable to create template. Internal error'; } return false; }
function getDefaultTemplate() { if (!$this->defaultTemplate && $this->getDefaultTemplateId()) { $this->defaultTemplate = Template::lookup($this->getDefaultTemplateId()); } return $this->defaultTemplate; }
foreach ($_POST['ids'] as $k => $v) { if (($t = Template::lookup($v)) && !$t->isInUse() && $t->disable()) { $i++; } } if ($i && $i == $count) { $msg = 'Selected templates disabled'; } elseif ($i) { $warn = "{$i} of {$count} selected templates disabled (in-use templates can't be disabled)"; } else { $errors['err'] = "Unable to disable selected templates (in-use or default template can't be disabled)"; } } elseif ($_POST['delete']) { $i = 0; foreach ($_POST['ids'] as $k => $v) { if (($t = Template::lookup($v)) && $t->delete()) { $i++; } } if ($i && $i == $count) { $msg = 'Selected templates deleted successfully'; } elseif ($i > 0) { $warn = "{$i} of {$count} selected templates deleted"; } elseif (!$errors['err']) { $errors['err'] = 'Unable to delete selected templates'; } } else { $errors['err'] = 'Unknown template action'; } } break;