Esempio n. 1
0
 function Display($value, $params, $context, $id)
 {
     if (empty($context['ticketid'])) {
         return "";
     }
     if (empty($context['userid'])) {
         $context['userid'] = 0;
     }
     $params = $this->parseParams($params);
     $parser = new FSSParser();
     $parser->setVar('ticketid', (int) $context['ticketid']);
     $parser->setVar('userid', (int) $context['userid']);
     if ($context['ticketid'] > 0) {
         foreach ($context['ticket'] as $var => $value) {
             if (!is_array($value)) {
                 $parser->setVar($var, $value);
             }
         }
         if (isset($context['ticket']->custom)) {
             foreach ($context['ticket']->custom as $field_id => $value) {
                 if (is_array($value)) {
                     $value = $value['value'];
                 }
                 $parser->setVar("custom_{$field_id}", $value);
                 if (array_key_exists($field_id, $context['ticket']->customfields)) {
                     $cf = $context['ticket']->customfields[$field_id];
                     $parser->setVar("custom_{$cf['alias']}", $value);
                 }
             }
         }
     }
     if (trim($params->command) != "") {
         $parser->SetTemplate($params->command);
         $sql = $parser->Parse();
         $db = JFactory::getDBO();
         $db->setQuery($sql);
         try {
             $data = $db->loadAssoc();
         } catch (exception $e) {
             return "<div class='alert alert-error fss_sql_custom_error_message' style='margin-bottom: 0'>" . $e->getMessage() . "</div>";
         }
         if (is_array($data)) {
             foreach ($data as $var => $value) {
                 $parser->setVar($var, $value);
             }
         }
     }
     $parser->SetTemplate($params->display);
     return $parser->Parse();
 }
Esempio n. 2
0
 function saveTicket()
 {
     $subject = FSS_Input::getString('subject');
     $body = FSS_Input::getBBCode('body');
     $prodid = FSS_Input::getInt('prodid');
     $deptid = FSS_Input::getInt('deptid');
     $catid = FSS_Input::getInt('catid');
     $priid = FSS_Input::getInt('priid');
     $handler = FSS_Input::getInt('handler');
     $user = JFactory::getUser();
     $userid = $user->get('id');
     $name = "";
     $session = JFactory::getSession();
     $this->admin_create = 0;
     if ($session->Get('admin_create')) {
         $this->admin_create = $session->Get('admin_create');
     }
     if ($this->admin_create == 1) {
         $this->admin_create = 1;
         $userid = $session->Get('admin_create_user_id');
     } else {
         if ($this->admin_create == 2) {
             $userid = 0;
         }
     }
     $db = JFactory::getDBO();
     if ($priid < 1) {
         $priid = FSS_Settings::get('support_default_priority');
     }
     $ticket['subject'] = $subject;
     $ticket['body'] = $body;
     $ticket['priid'] = $priid;
     $ticket['handler'] = $handler;
     $ok = true;
     $errors['subject'] = '';
     $errors['body'] = '';
     $errors['cat'] = '';
     $errors['captcha'] = '';
     $fields = FSSCF::GetCustomFields(0, $prodid, $deptid);
     if (FSS_Settings::get('support_subject_message_hide') == "subject") {
         $ticket['subject'] = substr(strip_tags($ticket['body']), 0, 40);
         $subject = $ticket['subject'];
     }
     if (FSS_Settings::get('support_altcat')) {
         $cats = $this->get('Cats');
         if (count($cats) > 0 && FSS_Input::getInt('catid') < 1) {
             $errors['cat'] = JText::_("YOU_MUST_SELECT_A_CATEGORY");
             $ok = false;
         }
     }
     if ($body == "" && FSS_Settings::get('support_subject_message_hide') != "message" && FSS_Settings::get('support_subject_message_hide') != "both") {
         $errors['body'] = JText::_("YOU_MUST_ENTER_A_MESSAGE_FOR_YOUR_SUPPORT_TICKET");
         $ok = false;
     }
     if (!FSSCF::ValidateFields($fields, $errors)) {
         $ok = false;
     }
     $email = "";
     $password = "";
     $now = FSS_Helper::CurDate();
     $this->sortCaptchaType();
     $captcha = new FSS_Captcha();
     if (!$captcha->ValidateCaptcha('support_captcha_type')) {
         $errors['captcha'] = JText::_("INVALID_SECURITY_CODE");
         $ok = false;
     }
     if ($userid < 1) {
         $email = FSSJ3Helper::getEscaped($db, $session->Get('ticket_email'));
         if ($session->Get('ticket_name')) {
             $name = FSSJ3Helper::getEscaped($db, $session->Get('ticket_name'));
         }
         if ($email == "" && $this->admin_create != 2) {
             $ok = false;
         } else {
             $password = FSS_Helper::createRandomPassword();
             $session->Set('ticket_pass', $password);
         }
     }
     // assign handler to ticket
     $admin_id = $handler;
     if (!$admin_id) {
         $admin_id = FSS_Ticket_Helper::AssignHandler($prodid, $deptid, $catid);
     }
     $now = FSS_Helper::CurDate();
     $def_open = FSS_Ticket_Helper::GetStatusID('def_open');
     if (FSS_Settings::get('support_subject_format') != "") {
         $parser = new FSSParser();
         foreach ($_POST as $var => $value) {
             $parser->setVar($var, FSS_Input::GetString($var));
         }
         foreach ($fields as $field) {
             $parser->setVar('custom_' . $field['alias'], FSS_Input::GetString('custom_' . $field['id']));
         }
         $user = JFactory::getUser($userid);
         $parser->setVar('userid', $userid);
         $parser->setVar('username', $user->username);
         $parser->setVar('name', $user->name);
         $parser->setVar('email', $user->email);
         $parser->setVar('subject', $subject);
         $parser->SetVar('product', FSS_EMail::GetProduct($prodid));
         $parser->SetVar('department', FSS_EMail::GetDepartment($deptid));
         $parser->SetVar('category', FSS_EMail::Getcategory($catid));
         $parser->SetVar('date', FSS_Helper::Date($now, FSS_DATE_SHORT));
         $parser->SetVar('time', FSS_Helper::Date($now, FSS_DATETIME_SHORT));
         $parser->SetTemplate(FSS_Settings::get('support_subject_format'));
         $result = $parser->Parse();
         if (trim($result) == "") {
             $sj = array();
             foreach ($fields as $field) {
                 $sj[] = FSS_Input::GetString('custom_' . $field['id']);
             }
             $result = implode(", ", $sj);
         }
         $ticket['subject'] = $result;
         $subject = $ticket['subject'];
         if ($subject == "") {
             $errors['subject'] = JText::_("YOU_MUST_ENTER_A_SUBJECT_FOR_YOUR_SUPPORT_TICKET");
             $ok = false;
         }
     }
     if ($ok) {
         $qry = "INSERT INTO #__fss_ticket_ticket (reference, ticket_status_id, ticket_pri_id, ticket_cat_id, ticket_dept_id, prod_id, title, opened, lastupdate, user_id, admin_id, email, password, unregname, lang) VALUES ";
         $qry .= "('', {$def_open}, '" . FSSJ3Helper::getEscaped($db, $priid) . "', '" . FSSJ3Helper::getEscaped($db, $catid) . "', '" . FSSJ3Helper::getEscaped($db, $deptid) . "', '" . FSSJ3Helper::getEscaped($db, $prodid) . "', '" . FSSJ3Helper::getEscaped($db, $subject) . "', '{$now}', '{$now}', '" . FSSJ3Helper::getEscaped($db, $userid) . "', '" . FSSJ3Helper::getEscaped($db, $admin_id) . "', '{$email}', '" . FSSJ3Helper::getEscaped($db, $password) . "', '{$name}', '" . JFactory::getLanguage()->getTag() . "')";
         $db->setQuery($qry);
         $db->Query();
         $this->ticketid = $db->insertid();
         $ref = FSS_Ticket_Helper::createRef($this->ticketid);
         $session->Set('ticket_reference', $ref);
         $qry = "UPDATE #__fss_ticket_ticket SET reference = '" . FSSJ3Helper::getEscaped($db, $ref) . "' WHERE id = '" . FSSJ3Helper::getEscaped($db, $this->ticketid) . "'";
         $db->setQuery($qry);
         $db->Query();
         if ($this->admin_create) {
             $curuser = JFactory::getUser();
             $premsg = date("Y-m-d H:i:s", strtotime($now) - 1);
             $msg = JText::sprintf('TICKET_OPENED_BY', $curuser->name, $curuser->username);
             $qry = "INSERT INTO #__fss_ticket_messages (ticket_ticket_id, subject, body, user_id, posted, admin) VALUES ('";
             $qry .= FSSJ3Helper::getEscaped($db, $this->ticketid) . "','" . FSSJ3Helper::getEscaped($db, $subject) . "','" . FSSJ3Helper::getEscaped($db, $msg) . "','" . FSSJ3Helper::getEscaped($db, $curuser->id) . "','{$premsg}', 6)";
             $db->setQuery($qry);
             $db->Query();
         }
         $qry = "INSERT INTO #__fss_ticket_messages (ticket_ticket_id, subject, body, user_id, posted) VALUES ('";
         $qry .= FSSJ3Helper::getEscaped($db, $this->ticketid) . "','" . FSSJ3Helper::getEscaped($db, $subject) . "','" . FSSJ3Helper::getEscaped($db, $body) . "','" . FSSJ3Helper::getEscaped($db, $userid) . "','{$now}')";
         $db->setQuery($qry);
         $db->Query();
         $messageid = $db->insertid();
         FSSCF::StoreFields($fields, $this->ticketid);
         // store tags if there are any posted
         $tags_input = FSS_Input::getString('tags');
         $parts = explode("|", $tags_input);
         foreach ($parts as $part) {
             $tag = trim($part);
             if (!$tag || $tag == "") {
                 continue;
             }
             $tags[] = $tag;
             $qry = "INSERT INTO #__fss_ticket_tags (ticket_id, tag) VALUES ('" . $this->ticketid . "', '" . $db->escape($tag) . "')";
             $db->setQuery($qry);
             $db->Query();
         }
         $t = new SupportTicket();
         $t->load($this->ticketid, true);
         $files = $t->addFilesFromPost($messageid, $userid);
         $t->stripImagesFromMessage($messageid);
         $subject = FSS_Input::getString('subject');
         $body = FSS_Input::getBBCode('body');
         $action_name = "User_Open";
         $action_params = array('subject' => $subject, 'user_message' => $body, 'files' => $files);
         SupportActions::DoAction($action_name, $t, $action_params);
         // additional users and emails if posted
         if ($this->admin_create > 0) {
             $additionalusers = JRequest::getVar('additionalusers');
             $additionalusers = explode(",", $additionalusers);
             $t->addCC($additionalusers, 0, 0);
             $additionalemails = JRequest::getVar('additionalemails');
             $additionalemails = explode(",", $additionalemails);
             foreach ($additionalemails as $email) {
                 $email = trim($email);
                 if ($email == "") {
                     continue;
                 }
                 $t->addEMailCC($email);
             }
             if ($t->admin_id != JFactory::getUser()->id) {
                 $t->addCC(JFactory::getUser()->id, 1, 0);
             }
         }
         $this->cleanAdminCreate();
         // if related is passed as part of ticket open, relate the 2 tickets
         $related = JRequest::getVar('related');
         if ($related > 0) {
             $t->addRelated($related);
         }
     }
     $this->errors = $errors;
     $this->ticket = $ticket;
     return $ok;
 }
Esempio n. 3
0
 function parseText($text, $context)
 {
     $parser = new FSSParser();
     if (is_array($context)) {
         $parser->setVar('ticketid', (int) $context['ticketid']);
         $parser->setVar('userid', (int) $context['userid']);
         if ($context['ticketid'] > 0) {
             foreach ($context['ticket'] as $var => $value) {
                 if (!is_array($value)) {
                     $parser->setVar($var, $value);
                 }
             }
             if (isset($context['ticket']->custom)) {
                 foreach ($context['ticket']->custom as $field_id => $value) {
                     if (is_array($value)) {
                         $value = $value['value'];
                     }
                     $parser->setVar("custom_{$field_id}", $value);
                     if (array_key_exists($field_id, $context['ticket']->customfields)) {
                         $cf = $context['ticket']->customfields[$field_id];
                         $parser->setVar("custom_{$cf['alias']}", $value);
                     }
                 }
             }
         }
     }
     $parser->SetTemplate($text);
     return $parser->Parse();
 }