Peter Rotich <*****@*****.**> Copyright (c) 2006-2013 osTicket http://www.osticket.com Released under the GNU General Public License WITHOUT ANY WARRANTY. See LICENSE.TXT for details. vim: expandtab sw=4 ts=4 sts=4: **********************************************************************/ require 'admin.inc.php'; include_once INCLUDE_DIR . 'class.template.php'; $template = null; 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) { switch (strtolower($_POST['do'])) { case 'updatetpl': if (!$template) { $errors['err'] = 'Unknown or invalid template'; } 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':
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; }
/** * Loads data from the I18N_DIR for the target language into the * database. This is intended to be done at the time of installation; * however, care should be taken in this process to ensure that the * process could be repeated if an administrator wanted to change the * system language and reload the data. */ function loadDefaultData() { # notrans -- do not translate the contents of this array $models = array('department.yaml' => 'Dept::create', 'sla.yaml' => 'SLA::create', 'form.yaml' => 'DynamicForm::create', 'list.yaml' => 'DynamicList::create', 'help_topic.yaml' => 'Topic::create', 'filter.yaml' => 'Filter::create', 'team.yaml' => 'Team::create', 'organization.yaml' => 'Organization::__create', 'ticket_status.yaml' => 'TicketStatus::__create', 'group.yaml' => 'Group::create', 'file.yaml' => 'AttachmentFile::create', 'sequence.yaml' => 'Sequence::__create'); $errors = array(); foreach ($models as $yaml => $m) { if ($objects = $this->getTemplate($yaml)->getData()) { foreach ($objects as $o) { if ($m && is_callable($m)) { @call_user_func_array($m, array($o, &$errors)); } // TODO: Add a warning to the success page for errors // found here $errors = array(); } } } // Priorities $priorities = $this->getTemplate('priority.yaml')->getData(); foreach ($priorities as $name => $info) { $sql = 'INSERT INTO ' . PRIORITY_TABLE . ' SET priority=' . db_input($name) . ', priority_id=' . db_input($info['priority_id']) . ', priority_desc=' . db_input($info['priority_desc']) . ', priority_color=' . db_input($info['priority_color']) . ', priority_urgency=' . db_input($info['priority_urgency']); db_query($sql); } // Configuration require_once INCLUDE_DIR . 'class.config.php'; if (($tpl = $this->getTemplate('config.yaml')) && ($data = $tpl->getData())) { foreach ($data as $section => $items) { $_config = new Config($section); foreach ($items as $key => $value) { $_config->set($key, $value); } } } // Load core config $_config = new OsticketConfig(); // Determine reasonable default max_file_size $max_size = Format::filesize2bytes(strtoupper(ini_get('upload_max_filesize'))); $val = (int) $max_size / 2; $po2 = 1; while ($po2 < $val) { $po2 <<= 1; } $_config->set('max_file_size', $po2); // Pages and content foreach (array('landing', 'thank-you', 'offline', 'registration-staff', 'pwreset-staff', 'banner-staff', 'registration-client', 'pwreset-client', 'banner-client', 'registration-confirm', 'registration-thanks', 'access-link') as $type) { $tpl = $this->getTemplate("templates/page/{$type}.yaml"); if (!($page = $tpl->getData())) { continue; } $sql = 'INSERT INTO ' . PAGE_TABLE . ' SET type=' . db_input($type) . ', name=' . db_input($page['name']) . ', body=' . db_input($page['body']) . ', lang=' . db_input($tpl->getLang()) . ', notes=' . db_input($page['notes']) . ', created=NOW(), updated=NOW(), isactive=1'; if (db_query($sql) && ($id = db_insert_id()) && in_array($type, array('landing', 'thank-you', 'offline'))) { $_config->set("{$type}_page_id", $id); } } // Default Language $_config->set('system_language', $this->langs[0]); // content_id defaults to the `id` field value db_query('UPDATE ' . PAGE_TABLE . ' SET content_id=id'); // Canned response examples if (($tpl = $this->getTemplate('templates/premade.yaml')) && ($canned = $tpl->getData())) { foreach ($canned as $c) { if (($id = Canned::create($c, $errors)) && isset($c['attachments'])) { $premade = Canned::lookup($id); foreach ($c['attachments'] as $a) { $premade->attachments->save($a, false); } } } } // Email templates // TODO: Lookup tpl_id if ($objects = $this->getTemplate('email_template_group.yaml')->getData()) { foreach ($objects as $o) { $o['lang_id'] = $this->langs[0]; $tpl = EmailTemplateGroup::create($o, $errors); } } // This shouldn't be necessary $tpl = EmailTemplateGroup::lookup(1); foreach ($tpl::$all_names as $name => $info) { if (($tp = $this->getTemplate("templates/email/{$name}.yaml")) && ($t = $tp->getData())) { $t['tpl_id'] = $tpl->getId(); $t['code_name'] = $name; $id = EmailTemplate::create($t, $errors); if ($id && ($template = EmailTemplate::lookup($id)) && ($ids = Draft::getAttachmentIds($t['body']))) { $template->attachments->upload($ids, true); } } } }