function update($vars, &$errors)
 {
     if (!$this->save($this->getId(), $vars, $errors)) {
         return false;
     }
     $this->updateTopics($vars['topics']);
     //Delete removed attachments.
     $keepers = $vars['files'];
     if ($attachments = $this->attachments->getSeparates()) {
         foreach ($attachments as $file) {
             if ($file['id'] && !in_array($file['id'], $keepers)) {
                 $this->attachments->delete($file['id']);
             }
         }
     }
     // Upload new attachments IF any.
     $this->attachments->upload($keepers);
     // Inline images (attached to the draft)
     $this->attachments->deleteInlines();
     $this->attachments->upload(Draft::getAttachmentIds($vars['answer']));
     $this->reload();
     Signal::send('model.updated', $this);
     return true;
 }
示例#2
0
 function add($vars, &$errors)
 {
     $inst = self::lookup(self::create($vars, $errors));
     // Inline images (attached to the draft)
     if ($inst) {
         $inst->attachments->upload(Draft::getAttachmentIds($inst->getBody()), true);
     }
     return $inst;
 }
示例#3
0
 /**
  * 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);
             }
         }
     }
 }
 function create($vars)
 {
     global $cfg;
     //Must have...
     if (!$vars['ticketId'] || !$vars['type'] || !in_array($vars['type'], array('M', 'R', 'N'))) {
         return false;
     }
     if (!$vars['body'] instanceof ThreadBody) {
         if ($cfg->isHtmlThreadEnabled()) {
             $vars['body'] = new HtmlThreadBody($vars['body']);
         } else {
             $vars['body'] = new TextThreadBody($vars['body']);
         }
     }
     // Drop stripped images
     if ($vars['attachments']) {
         foreach ($vars['body']->getStrippedImages() as $cid) {
             foreach ($vars['attachments'] as $i => $a) {
                 if (@$a['cid'] && $a['cid'] == $cid) {
                     // Inline referenced attachment was stripped
                     unset($vars['attachments'][$i]);
                 }
             }
         }
     }
     // Handle extracted embedded images (<img src="data:base64,..." />).
     // The extraction has already been performed in the ThreadBody
     // class. Here they should simply be added to the attachments list
     if ($atts = $vars['body']->getEmbeddedHtmlImages()) {
         if (!is_array($vars['attachments'])) {
             $vars['attachments'] = array();
         }
         foreach ($atts as $info) {
             $vars['attachments'][] = $info;
         }
     }
     if (!($body = $vars['body']->getClean())) {
         $body = '-';
     }
     //Special tag used to signify empty message as stored.
     $poster = $vars['poster'];
     if ($poster && is_object($poster)) {
         $poster = (string) $poster;
     }
     $sql = ' INSERT INTO ' . TICKET_THREAD_TABLE . ' SET created=NOW() ' . ' ,thread_type=' . db_input($vars['type']) . ' ,ticket_id=' . db_input($vars['ticketId']) . ' ,title=' . db_input(Format::sanitize($vars['title'], true)) . ' ,format=' . db_input($vars['body']->getType()) . ' ,staff_id=' . db_input($vars['staffId']) . ' ,user_id=' . db_input($vars['userId']) . ' ,poster=' . db_input($poster) . ' ,source=' . db_input($vars['source']);
     if (!isset($vars['attachments']) || !$vars['attachments']) {
         // Otherwise, body will be configured in a block below (after
         // inline attachments are saved and updated in the database)
         $sql .= ' ,body=' . db_input($body);
     }
     if (isset($vars['pid'])) {
         $sql .= ' ,pid=' . db_input($vars['pid']);
     } elseif (isset($vars['reply_to']) && $vars['reply_to'] instanceof ThreadEntry) {
         $sql .= ' ,pid=' . db_input($vars['reply_to']->getId());
     }
     if ($vars['ip_address']) {
         $sql .= ' ,ip_address=' . db_input($vars['ip_address']);
     }
     //echo $sql;
     if (!db_query($sql) || !($entry = self::lookup(db_insert_id(), $vars['ticketId']))) {
         return false;
     }
     /************* ATTACHMENTS *****************/
     //Upload/save attachments IF ANY
     if ($vars['files']) {
         //expects well formatted and VALIDATED files array.
         $entry->uploadFiles($vars['files']);
     }
     //Canned attachments...
     if ($vars['cannedattachments'] && is_array($vars['cannedattachments'])) {
         $entry->saveAttachments($vars['cannedattachments']);
     }
     //Emailed or API attachments
     if (isset($vars['attachments']) && $vars['attachments']) {
         foreach ($vars['attachments'] as &$a) {
             if (isset($a['cid']) && $a['cid'] && strpos($body, 'cid:' . $a['cid']) !== false) {
                 $a['inline'] = true;
             }
         }
         unset($a);
         $entry->importAttachments($vars['attachments']);
         foreach ($vars['attachments'] as $a) {
             // Change <img src="cid:"> inside the message to point to
             // a unique hash-code for the attachment. Since the
             // content-id will be discarded, only the unique hash-code
             // will be available to retrieve the image later
             if ($a['cid'] && $a['key']) {
                 $body = preg_replace('/src=("|\'|\\b)(?:cid:)?' . preg_quote($a['cid'], '/') . '\\1/i', 'src="cid:' . $a['key'] . '"', $body);
             }
         }
         $sql = 'UPDATE ' . TICKET_THREAD_TABLE . ' SET body=' . db_input($body) . ' WHERE `id`=' . db_input($entry->getId());
         if (!db_query($sql) || !db_affected_rows()) {
             return false;
         }
     }
     // Email message id (required for all thread posts)
     if (!isset($vars['mid'])) {
         $vars['mid'] = sprintf('<%s@%s>', Misc::randCode(24), substr(md5($cfg->getUrl()), -10));
     }
     $entry->saveEmailInfo($vars);
     // Inline images (attached to the draft)
     $entry->saveAttachments(Draft::getAttachmentIds($body));
     Signal::send('model.created', $entry);
     return $entry;
 }
示例#5
0
         }
         Draft::deleteForNamespace('page');
     } elseif (!$errors['err']) {
         $errors['err'] = sprintf(__('Unable to add %s. Correct error(s) below and try again.'), __('this site page'));
     }
     break;
 case 'update':
     if (!$page) {
         $errors['err'] = sprintf(__('%s: Invalid or unknown'), __('site page'));
     } elseif ($page->update($_POST, $errors)) {
         $msg = sprintf(__('Successfully updated %s'), __('this site page'));
         $_REQUEST['a'] = null;
         //Go back to view
         // Attach inline attachments from the editor
         $page->attachments->deleteInlines();
         $page->attachments->upload(Draft::getAttachmentIds($_POST['body']), true);
         Draft::deleteForNamespace('page.' . $page->getId());
     } elseif (!$errors['err']) {
         $errors['err'] = sprintf(__('Unable to update %s. Correct error(s) below and try again.'), __('this site page'));
     }
     break;
 case 'mass_process':
     if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
         $errors['err'] = sprintf(__('You must select at least %s.'), __('one site page'));
     } elseif (array_intersect($_POST['ids'], $cfg->getDefaultPages()) && strcasecmp($_POST['a'], 'enable')) {
         $errors['err'] = sprintf(__('One or more of the %s is in-use and CANNOT be disabled/deleted.'), _N('selected site page', 'selected site pages', 2));
     } else {
         $count = count($_POST['ids']);
         switch (strtolower($_POST['a'])) {
             case 'enable':
                 $sql = 'UPDATE ' . PAGE_TABLE . ' SET isactive=1 ' . ' WHERE id IN (' . implode(',', db_input($_POST['ids'])) . ')';
示例#6
0
     } elseif(!$errors['err'])
         $errors['err'] = sprintf(__('Unable to add %s. Correct error(s) below and try again.'),
             __('this site page'));
 break;
 case 'update':
     if(!$page)
         $errors['err'] = sprintf(__('%s: Invalid or unknown'),
             __('site page'));
     elseif($page->update($_POST, $errors)) {
         $msg=sprintf(__('Successfully updated %s'),
             __('this site page'));
         $_REQUEST['a']=null; //Go back to view
         // Attach inline attachments from the editor
         $page->attachments->deleteInlines();
         $page->attachments->upload(
             Draft::getAttachmentIds($_POST['body']),
             true);
         Draft::deleteForNamespace('page.'.$page->getId());
     } elseif(!$errors['err'])
         $errors['err'] = sprintf(__('Unable to update %s. Correct error(s) below and try again.'),
             __('this site page'));
     break;
 case 'mass_process':
     if(!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
         $errors['err'] = sprintf(__('You must select at least %s.'),
             __('one site page'));
     } elseif(array_intersect($_POST['ids'], $cfg->getDefaultPages()) && strcasecmp($_POST['a'], 'enable')) {
         $errors['err'] = sprintf(__('One or more of the %s is in-use and CANNOT be disabled/deleted.'),
             _N('selected site page', 'selected site pages', 2));
     } else {
         $count=count($_POST['ids']);