/** * 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); } } } }
} $canned->reload(); // XXX: Handle nicely notifying a user that the draft was // deleted | OR | show the draft for the user on the name // page refresh or a nice bar popup immediately with // something like "This page is out-of-date", and allow the // user to voluntarily delete their draft // // Delete drafts for all users for this canned response Draft::deleteForNamespace('canned.' . $canned->getId()); } elseif (!$errors['err']) { $errors['err'] = 'Error updating canned response. Try again!'; } break; case 'create': if ($id = Canned::create($_POST, $errors)) { $msg = 'Canned response added successfully'; $_REQUEST['a'] = null; //Upload attachments if ($_FILES['attachments'] && ($c = Canned::lookup($id)) && ($files = AttachmentFile::format($_FILES['attachments']))) { $c->attachments->upload($files); } // Attach inline attachments from the editor if (isset($_POST['draft_id']) && ($draft = Draft::lookup($_POST['draft_id']))) { $c->attachments->upload($draft->getAttachmentIds($_POST['response']), true); } // Delete this user's drafts for new canned-responses Draft::deleteForNamespace('canned', $thisstaff->getId()); } elseif (!$errors['err']) { $errors['err'] = 'Unable to add canned response. Correct error(s) below and try again.'; }
foreach ($attachments as $k => $file) { if ($file['id'] && !in_array($file['id'], $keepers)) { $canned->deleteAttachment($file['id']); } } //Upload NEW attachments IF ANY - TODO: validate attachment types?? if ($_FILES['attachments'] && ($files = Format::files($_FILES['attachments']))) { $canned->uploadAttachments($files); } $canned->reload(); } elseif (!$errors['err']) { $errors['err'] = 'Error updating canned reply. Try again!'; } break; case 'create': if ($id = Canned::create($_POST, $_FILES['attachments'], $errors)) { $msg = 'Canned response added successfully'; $_REQUEST['a'] = null; //Upload attachments if ($_FILES['attachments'] && ($c = Canned::lookup($id)) && ($files = Format::files($_FILES['attachments']))) { $c->uploadAttachments($files); } } elseif (!$errors['err']) { $errors['err'] = 'Unable to add canned response. Correct error(s) below and try again.'; } break; case 'mass_process': if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { $errors['err'] = 'You must select at least one canned response'; } else { $count = count($_POST['ids']);