function run($runtime) { $errors = array(); $i18n = new Internationalization('en_US'); $tpls = $i18n->getTemplate('email_template_group.yaml')->getData(); foreach ($tpls as $t) { // If the email template group specifies an id attribute, remove // it for upgrade because we cannot assume that the id slot is // available unset($t['id']); EmailTemplateGroup::create($t, $errors); } $files = $i18n->getTemplate('file.yaml')->getData(); foreach ($files as $f) { $id = AttachmentFile::create($f, $errors); // Ensure the new files are never deleted (attached to Disk) $sql = 'INSERT INTO ' . ATTACHMENT_TABLE . ' SET object_id=0, `type`=\'D\', inline=1' . ', file_id=' . db_input($id); db_query($sql); } }
function getTemplate() { global $cfg; if (!$this->template) { if (!($this->template = EmailTemplateGroup::lookup($this->getTemplateId()))) { $this->template = $cfg->getDefaultTemplate(); } } return $this->template; }
function getGroup() { if (!isset($this->_group)) { $this->_group = EmailTemplateGroup::lookup($this->getTplId()); } return $this->_group; }
function getDefaultTemplate() { if (!$this->defaultTemplate && $this->getDefaultTemplateId()) { $this->defaultTemplate = EmailTemplateGroup::lookup($this->getDefaultTemplateId()); } return $this->defaultTemplate; }
if (($t = EmailTemplateGroup::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)"; } break; case 'delete': $i = 0; foreach ($_POST['ids'] as $k => $v) { if (($t = EmailTemplateGroup::lookup($v)) && !$t->isInUse() && $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'; } break; default: $errors['err'] = 'Unknown template action'; } }
/** * 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); } } } }