} else { $checkField = $_FILES[$fieldname]; } $v[$fieldname][] = new ValidateRegex($checkField, $field->getVar('validation'), $field->getVar('required')); $aFields[$field->getVar('id')] = array('name' => $field->getVar('name'), 'desc' => $field->getVar('description'), 'fieldname' => $field->getVar('fieldname'), 'defaultvalue' => $field->getVar('defaultvalue'), 'controltype' => $field->getVar('controltype'), 'required' => $field->getVar('required'), 'fieldlength' => $field->getVar('fieldlength'), 'maxlength' => $field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50, 'weight' => $field->getVar('weight'), 'fieldvalues' => $values, 'validation' => $field->getVar('validation')); } $_xhelpSession->set('xhelp_ticket', array('uid' => 0, 'subject' => $_POST['subject'], 'description' => htmlspecialchars($_POST['description'], ENT_QUOTES), 'department' => $_POST['departments'], 'priority' => $_POST['priority'])); $_xhelpSession->set('xhelp_user', array('uid' => 0, 'email' => $_POST['email'])); if ($fields != "") { $_xhelpSession->set('xhelp_custFields', $fields); } // Perform each validation $fields = array(); $errors = array(); foreach ($v as $fieldname => $validator) { if (!xhelpCheckRules($validator, $errors)) { //Mark field with error $fields[$fieldname]['haserrors'] = true; $fields[$fieldname]['errors'] = $errors; } else { $fields[$fieldname]['haserrors'] = false; } } if (!empty($errors)) { $_xhelpSession->set('xhelp_validateError', $fields); $message = _XHELP_MESSAGE_VALIDATE_ERROR; header("Location: " . XHELP_BASE_URL . "/anon_addTicket.php"); exit; } //Check email address $user_added = false;
function _saveAttachments($msg, $ticketid, $responseid = 0) { global $xoopsModuleConfig; $attachments = $msg->getAttachments(); $dir = XOOPS_UPLOAD_PATH . '/xhelp'; $prefix = $responseid != 0 ? $ticketid . '_' . $responseid . '_' : $ticketid . '_'; $hMime =& xhelpGetHandler('mimetype'); $allowed_mimetypes = $hMime->getArray(); if (!is_dir($dir)) { mkdir($dir, 0757); } $dir .= '/'; if ($xoopsModuleConfig['xhelp_allowUpload']) { $hFile =& xhelpGetHandler('file'); foreach ($attachments as $attach) { $validators = array(); //Create Temporary File $fname = $prefix . $attach['filename']; $fp = fopen($dir . $fname, 'w'); fwrite($fp, $attach['content']); fclose($fp); $validators[] = new ValidateMimeType($dir . $fname, $attach['content-type'], $allowed_mimetypes); $validators[] = new ValidateFileSize($dir . $fname, $xoopsModuleConfig['xhelp_uploadSize']); $validators[] = new ValidateImageSize($dir . $fname, $xoopsModuleConfig['xhelp_uploadWidth'], $xoopsModuleConfig['xhelp_uploadHeight']); if (!xhelpCheckRules($validators, $errors)) { //Remove the file $this->_addAttachmentError($errors, $msg, $fname); unlink($dir . $fname); } else { //Add attachment to ticket $file =& $hFile->create(); $file->setVar('filename', $fname); $file->setVar('ticketid', $ticketid); $file->setVar('mimetype', $attach['content-type']); $file->setVar('responseid', $responseid); $hFile->insert($file, true); } } } else { $this->_setError(_XHELP_MESSAGE_UPLOAD_ALLOWED_ERR); // Error: file uploading is disabled } }
/** * Check if all supplied rules pass, and return any errors * * @param array $rules array of {@link Validator} classes * @param array $errors array of errors found (if any) * @return bool True if all rules pass, false if any fail * * @access public */ function xhelpCheckRules(&$rules, &$errors) { $ret = true; if (is_array($rules)) { foreach ($rules as $rule) { $ret = $ret && xhelpCheckRules($rule, $error); $errors = array_merge($errors, $error); } } else { if (!$rules->isValid()) { $ret = false; $errors = $rules->getErrors(); } else { $ret = true; $errors = array(); } } return $ret; }