Exemplo n.º 1
0
 function _submitReply()
 {
     // can add replies
     if ($this->is_staff && !$this->_permissions->answer_ticket) {
         JError::raiseNotice(500, JText::_('RST_CANNOT_UPDATE_TICKET'));
         return;
     }
     // must not be closed
     if ($this->_ticket->status_id == 2) {
         JError::raiseWarning(500, JText::_('RST_TICKET_REPLIES_CLOSED_ERROR'));
         return;
     }
     // must write a message
     if (empty($this->_data['message'])) {
         JError::raiseNotice(500, JText::_('RST_TICKET_MESSAGE_ERROR'));
         return;
     }
     $correct_files = array();
     if ($this->getCanUpload()) {
         $department =& JTable::getInstance('RSTicketsPro_Departments', 'Table');
         $department->load($this->_ticket->department_id);
         $upload_extensions = str_replace("\r\n", "\n", $department->upload_extensions);
         $upload_extensions = explode("\n", $upload_extensions);
         $files = JRequest::get('files');
         $files = @$files['rst_files'];
         if (is_array($files)) {
             foreach ($files['tmp_name'] as $i => $file_tmp) {
                 if ($files['error'][$i] == 4) {
                     continue;
                 }
                 $file_name = $files['name'][$i];
                 if ($files['error'][$i]) {
                     JError::raiseWarning(500, JText::sprintf('RST_TICKET_UPLOAD_ERROR', $file_name));
                     return;
                 }
                 if (!RSTicketsProHelper::isAllowedExtension(RSTicketsProHelper::getExtension($file_name), $upload_extensions)) {
                     $upload_extensions = implode(', ', $upload_extensions);
                     JError::raiseNotice(500, JText::sprintf('RST_TICKET_UPLOAD_EXTENSION_ERROR', $file_name, $upload_extensions));
                     return;
                 }
                 if ($department->upload_size > 0 && $files['size'][$i] > $department->upload_size * 1048576) {
                     JError::raiseWarning(500, JText::sprintf('RST_TICKET_UPLOAD_SIZE_ERROR', $file_name, $department->upload_size));
                     return;
                 }
                 $correct_files[] = array('src' => 'upload', 'tmp_name' => $file_tmp, 'name' => $file_name);
             }
         }
     }
     // add the ticket id
     $this->_data['ticket_id'] = $this->_ticket->id;
     // add the current user
     $user = JFactory::getUser();
     $this->_data['user_id'] = $user->get('id');
     RSTicketsProHelper::addTicketReply($this->_data, $correct_files);
     $mainframe =& JFactory::getApplication();
     $mainframe->redirect(RSTicketsProHelper::route('index.php?option=com_rsticketspro&view=ticket&cid=' . $this->_ticket->id . ':' . JFilterOutput::stringURLSafe($this->_ticket->subject), false), JText::_('RST_TICKET_SUBMIT_REPLY_OK'));
 }
Exemplo n.º 2
0
 function _processData()
 {
     // don't process anything if the form hasn't been submitted
     if (empty($this->_data['task']) || $this->_data['task'] != 'submit') {
         return;
     }
     $mainframe =& JFactory::getApplication();
     // get the customer (ticket submitter) information
     $user = JFactory::getUser();
     if ($mainframe->isSite() && $user->get('guest') || $mainframe->isAdmin() && $this->_data['submit_type'] == 1) {
         jimport('joomla.mail.helper');
         if (empty($this->_data['email']) || !JMailHelper::isEmailAddress($this->_data['email'])) {
             JError::raiseNotice(500, JText::_('RST_TICKET_EMAIL_ERROR'));
             return;
         }
         $this->_db->setQuery("SELECT id FROM #__users WHERE email LIKE '" . $this->_db->getEscaped($this->_data['email']) . "'");
         $user_id = $this->_db->loadResult();
         if ($user_id && RSTicketsProHelper::isStaff($user_id)) {
             JError::raiseNotice(500, JText::sprintf('RST_TICKET_EMAIL_STAFF_ERROR', $this->_data['email']));
             return;
         }
         $this->_data['customer_id'] = 0;
         if (empty($this->_data['name'])) {
             JError::raiseNotice(500, JText::_('RST_TICKET_NAME_ERROR'));
             return;
         }
     } else {
         $this->_data['email'] = $user->get('email');
         $this->_data['name'] = $user->get('name');
         $this->_data['customer_id'] = $user->get('id');
         if (RSTicketsProHelper::isStaff()) {
             $permissions = RSTicketsProHelper::getCurrentPermissions();
             if (!$permissions->add_ticket && !$permissions->add_ticket_customers && !$permissions->add_ticket_staff) {
                 JError::raiseWarning(500, JText::_('RST_STAFF_CANNOT_SUBMIT_TICKET'));
                 $mainframe->redirect(RSTicketsProHelper::route('index.php?option=com_rsticketspro&view=rsticketspro', false));
             } elseif ($permissions->add_ticket_customers || $permissions->add_ticket_staff) {
                 $this->_data['email'] = '';
                 $this->_data['name'] = '';
                 $this->_data['customer_id'] = 0;
                 $customer_id = JRequest::getInt('customer_id', 0, 'post');
                 if ($mainframe->isSite() && !$customer_id || $mainframe->isAdmin() && $this->_data['submit_type'] == 2 && !$customer_id) {
                     JError::raiseNotice(500, JText::_('RST_TICKET_CUSTOMER_ERROR'));
                     return;
                 }
                 $customer = JFactory::getUser($customer_id);
                 $this->_data['email'] = $customer->get('email');
                 $this->_data['name'] = $customer->get('name');
                 $this->_data['customer_id'] = $customer->get('id');
             }
         }
     }
     // must select a department
     if (empty($this->_data['department_id'])) {
         JError::raiseNotice(500, JText::_('RST_TICKET_DEPARTMENT_ERROR'));
         return;
     }
     // get all custom fields
     $custom_fields = $this->_getList("SELECT * FROM #__rsticketspro_custom_fields WHERE department_id='" . (int) $this->_data['department_id'] . "' AND published=1 ORDER BY ordering");
     // get the submitted custom fields
     $sent_custom_fields = JRequest::getVar('rst_custom_fields', array(), 'post');
     $sent_custom_fields = @$sent_custom_fields['department_' . $this->_data['department_id']];
     // add the custom fields to an array so that we can send them as a parameter later on
     $correct_custom_fields = array();
     foreach ($custom_fields as $field) {
         if ($field->type == 'freetext') {
             continue;
         }
         if ($field->required) {
             $validation_message = JText::_($field->validation);
             if (empty($validation_message)) {
                 $validation_message = JText::sprintf('RST_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
             }
             if (empty($sent_custom_fields[$field->name])) {
                 JError::raiseNotice(500, $validation_message);
                 return false;
             } elseif (is_array($sent_custom_fields[$field->name]) && empty($sent_custom_fields[$field->name][0])) {
                 JError::raiseNotice(500, $validation_message);
                 return false;
             }
         }
         if (!empty($sent_custom_fields[$field->name])) {
             $correct_custom_fields[$field->id] = $sent_custom_fields[$field->name];
         }
     }
     // must write a subject
     if (empty($this->_data['subject'])) {
         JError::raiseNotice(500, JText::_('RST_TICKET_SUBJECT_ERROR'));
         return;
     }
     // must write a message
     if (empty($this->_data['message'])) {
         JError::raiseNotice(500, JText::_('RST_TICKET_MESSAGE_ERROR'));
         return;
     }
     // must select a priority
     if (empty($this->_data['priority_id'])) {
         JError::raiseNotice(500, JText::_('RST_TICKET_PRIORITY_ERROR'));
         return;
     }
     if ($mainframe->isSite()) {
         $captcha_enabled = RSTicketsProHelper::getConfig('captcha_enabled');
         $use_captcha = $this->getUseCaptcha();
         if ($use_captcha && $captcha_enabled) {
             if ($captcha_enabled == 1) {
                 $captcha_image = new JSecurImage();
                 $valid = $captcha_image->check($this->_data['captcha']);
                 if (!$valid) {
                     JError::raiseNotice(500, JText::_('RST_TICKET_CAPTCHA_ERROR'));
                     return;
                 }
             } elseif ($captcha_enabled == 2) {
                 $privatekey = RSTicketsProHelper::getConfig('recaptcha_private_key');
                 $response = JReCAPTCHA::checkAnswer($privatekey, @$_SERVER['REMOTE_ADDR'], @$this->_data['recaptcha_challenge_field'], @$this->_data['recaptcha_response_field']);
                 if ($response === false || !$response->is_valid) {
                     $this->recaptcha_error = @$response->error;
                     JError::raiseNotice(500, JText::_('RST_TICKET_CAPTCHA_ERROR'));
                     return;
                 }
             }
         }
     }
     $this->_data['agent'] = @$_SERVER['HTTP_USER_AGENT'];
     $this->_data['referer'] = @$_SERVER['HTTP_REFERER'];
     $this->_data['ip'] = @$_SERVER['REMOTE_ADDR'];
     $correct_files = array();
     if ($this->getCanUpload()) {
         $department =& JTable::getInstance('RSTicketsPro_Departments', 'Table');
         $department->load($this->_data['department_id']);
         $upload_extensions = str_replace("\r\n", "\n", $department->upload_extensions);
         $upload_extensions = explode("\n", $upload_extensions);
         $files = JRequest::get('files');
         $files = @$files['rst_files'];
         if (is_array($files)) {
             foreach ($files['tmp_name'] as $i => $file_tmp) {
                 if ($files['error'][$i] == 4) {
                     continue;
                 }
                 switch ($files['error'][$i]) {
                     default:
                         $msg = 'RST_TICKET_UPLOAD_ERROR';
                         break;
                     case 1:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_INI_SIZE';
                         break;
                     case 2:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_FORM_SIZE';
                         break;
                     case 3:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_PARTIAL';
                         break;
                     case 6:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_NO_TMP_DIR';
                         break;
                     case 7:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_CANT_WRITE';
                         break;
                     case 8:
                         $msg = 'RST_TICKET_UPLOAD_ERROR_PHP_EXTENSION';
                         break;
                 }
                 $file_name = $files['name'][$i];
                 if ($files['error'][$i]) {
                     JError::raiseWarning(500, JText::sprintf($msg, $file_name));
                     return;
                 }
                 if (!RSTicketsProHelper::isAllowedExtension(RSTicketsProHelper::getExtension($file_name), $upload_extensions)) {
                     $upload_extensions = implode(', ', $upload_extensions);
                     JError::raiseNotice(500, JText::sprintf('RST_TICKET_UPLOAD_EXTENSION_ERROR', $file_name, $upload_extensions));
                     return;
                 }
                 if ($department->upload_size > 0 && $files['size'][$i] > $department->upload_size * 1048576) {
                     JError::raiseWarning(500, JText::sprintf('RST_TICKET_UPLOAD_SIZE_ERROR', $file_name, $department->upload_size));
                     return;
                 }
                 $correct_files[] = array('src' => 'upload', 'tmp_name' => $file_tmp, 'name' => $file_name);
             }
         }
     }
     RSTicketsProHelper::addTicket($this->_data, $correct_custom_fields, $correct_files);
     $redirect = RSTicketsProHelper::getConfig('submit_redirect');
     if ($redirect && $mainframe->isSite()) {
         $mainframe->redirect($redirect);
     } else {
         $mainframe->redirect(RSTicketsProHelper::route('index.php?option=com_rsticketspro&view=submit', false), JText::_('RST_TICKET_SUBMIT_OK'));
     }
 }