本文整理汇总了PHP中Topic::lookup方法的典型用法代码示例。如果您正苦于以下问题:PHP Topic::lookup方法的具体用法?PHP Topic::lookup怎么用?PHP Topic::lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Topic
的用法示例。
在下文中一共展示了Topic::lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequestStructure
function getRequestStructure($format, $data = null)
{
$supported = array("alert", "autorespond", "source", "topicId", "attachments" => array("*" => array("name", "type", "data", "encoding", "size")), "message", "ip", "priorityId");
# Fetch dynamic form field names for the given help topic and add
# the names to the supported request structure
if (isset($data['topicId']) && ($topic = Topic::lookup($data['topicId'])) && ($form = $topic->getForm())) {
foreach ($form->getDynamicFields() as $field) {
$supported[] = $field->get('name');
}
}
# Ticket form fields
# TODO: Support userId for existing user
if ($form = TicketForm::getInstance()) {
foreach ($form->getFields() as $field) {
$supported[] = $field->get('name');
}
}
# User form fields
if ($form = UserForm::getInstance()) {
foreach ($form->getFields() as $field) {
$supported[] = $field->get('name');
}
}
if (!strcasecmp($format, 'email')) {
$supported = array_merge($supported, array('header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', 'thread-type', 'flags' => array('bounce', 'auto-reply', 'spam', 'viral'), 'recipients' => array('*' => array('name', 'email', 'source'))));
$supported['attachments']['*'][] = 'cid';
}
return $supported;
}
示例2: get_open
public function get_open()
{
global $ost, $cfg;
define('MY_DEBUG', isset($_GET['debug']) && $_GET['debug'] === '1');
$topic_names = Topic::getPublicHelpTopics();
if (isset($_GET['topics'])) {
$allowed_topics = [];
if (is_array($_GET['topics'])) {
$allowed_topics = $_GET['topics'];
} else {
$allowed_topics = [$_GET['topics']];
}
$topic_names = array_filter($topic_names, function ($name, $id) use($allowed_topics) {
return in_array($id, $allowed_topics) || in_array($name, $allowed_topics);
}, ARRAY_FILTER_USE_BOTH);
}
$formPrefix = $this->config->get('ajax_submission_form_prefix');
$csrf_token = $ost->getCSRF()->getToken();
$topics = [];
foreach ($topic_names as $id => $name) {
if (($topic = Topic::lookup($id)) && ($form = $topic->getForm()) && ($fields = $form->getForm()->getFields())) {
$topics[$id] = ['name' => $name, 'instructions' => $form->get('instructions'), 'fields' => []];
foreach ($fields as $field) {
$topics[$id]['fields'][$field->get('name')] = ['name' => $formPrefix . $field->get('name'), 'type' => $field->get('type')];
if ($field->get('type') === 'choices') {
$topics[$id]['fields'][$field->get('name')]['choices'] = $field->getChoices();
}
}
}
}
$captcha = null;
$useCaptcha = $this->config->get('ajax_submission_captcha');
if ($useCaptcha === 1) {
// built-in
$captcha = ['type' => 'osTicket'];
} elseif ($useCaptcha === 2) {
// recaptcha
$public = $this->config->get('ajax_recaptcha_site');
$private = $this->config->get('ajax_recaptcha_secret');
if ($public && $private) {
// Key creation based on https://github.com/google/recaptcha-java/blob/master/appengine/src/main/java/com/google/recaptcha/STokenUtils.java
$encrypter = new Encryption(substr(hash('sha1', $private, true), 0, 16));
$secure_token = json_encode(['session_id' => uniqid($csrf_token), 'ts_ms' => bcmul(microtime(true), 1000, 0)]);
$captcha = ['type' => 'reCaptcha', 'public_key' => $public, 'secure_token' => $encrypter->encrypt_aes_ecb_pkcs5($secure_token)];
} else {
throw new Exception('reCaptcha key not provided!');
}
}
$return = ['method' => 'POST', 'submit_url' => self::baseURL() . '/ajax.php/ajax-form/submit', 'form_groups' => ['backend' => ['hidden' => true, fields => ['csrf', 'action']], 'topic' => ['legend' => 'Help Topic', fields => ['topicId']], 'user' => ['legend' => 'Contact Information', fields => ['name', 'email', 'phone']], 'topic_details' => ['dynamic' => true, 'id' => $formPrefix . 'topic_details'], 'ticket' => ['legend' => 'Ticket Details', fields => ['summary', 'details']]], 'form_fields' => ['csrf' => ['type' => 'hidden', 'value' => $csrf_token, 'name' => $formPrefix . $ost->getCSRF()->getTokenName()], 'action' => ['type' => 'hidden', 'value' => 'open', 'name' => $formPrefix . 'a'], 'topicId' => ['label' => 'Select a Topic', 'required' => true, 'type' => 'choices', 'name' => $formPrefix . 'topicId', 'choices' => $topic_names], 'name' => ['label' => 'Full Name', 'required' => true, 'type' => 'text', 'name' => $formPrefix . 'name'], 'email' => ['label' => 'Email Address', 'required' => true, 'type' => 'text', 'name' => $formPrefix . 'email'], 'phone' => ['label' => 'Phone Number', 'required' => true, 'type' => 'text', 'name' => $formPrefix . 'phone'], 'summary' => ['label' => 'Issue Summary', 'required' => true, 'type' => 'text', 'name' => $formPrefix . 'summary'], 'details' => ['label' => 'Issue Details', 'required' => true, 'type' => 'textarea', 'name' => $formPrefix . 'details']], 'topics' => $topics, 'captcha' => $captcha];
header('Access-Control-Allow-Origin: ' . $this->config->get('ajax_cors_header'));
$json_flags = 0;
if (MY_DEBUG) {
$json_flags += JSON_PRETTY_PRINT;
}
return json_encode($return, $json_flags);
}
示例3: getFormsForHelpTopic
function getFormsForHelpTopic($topic_id, $client = false)
{
if (!($topic = Topic::lookup($topic_id))) {
Http::response(404, 'No such help topic');
}
if ($_GET || isset($_SESSION[':form-data'])) {
if (!is_array($_SESSION[':form-data'])) {
$_SESSION[':form-data'] = array();
}
$_SESSION[':form-data'] = array_merge($_SESSION[':form-data'], $_GET);
}
if ($form = $topic->getForm()) {
$form->getForm($_SESSION[':form-data'])->render(!$client);
}
}
示例4: getFormsForHelpTopic
function getFormsForHelpTopic($topic_id, $client = false)
{
if (!($topic = Topic::lookup($topic_id))) {
Http::response(404, 'No such help topic');
}
if ($_GET || isset($_SESSION[':form-data'])) {
if (!is_array($_SESSION[':form-data'])) {
$_SESSION[':form-data'] = array();
}
$_SESSION[':form-data'] = array_merge($_SESSION[':form-data'], $_GET);
}
if ($form = $topic->getForm()) {
ob_start();
$form->getForm($_SESSION[':form-data'])->render(!$client);
$html = ob_get_clean();
ob_start();
print $form->getMedia();
$media = ob_get_clean();
}
return $this->encode(array('media' => $media, 'html' => $html));
}
示例5: foreach
'ajax.php/form/help-topic/' + this.value, data);
">
<?php
if ($topics=Topic::getHelpTopics()) {
if (count($topics) == 1)
$selected = 'selected="selected"';
else { ?>
<option value="" selected >— Select Help Topic —</option>
<?php }
foreach($topics as $id =>$name) {
echo sprintf('<option value="%d" %s %s>%s</option>',
$id, ($info['topicId']==$id)?'selected="selected"':'',
$selected, $name);
}
if (count($topics) == 1 && !$form) {
if (($T = Topic::lookup($id)))
$form = $T->getForm();
}
}
?>
</select>
<font class="error"><b>*</b> <?php echo $errors['topicId']; ?></font>
</td>
</tr>
<tr>
<td width="160">
Department:
</td>
<td>
<select name="deptId">
<option value="" selected >— Select Department —</option>
示例6: die
<?php
if (!defined('OSTCLIENTINC')) {
die('Access Denied!');
}
$info = array();
if ($thisclient && $thisclient->isValid()) {
$info = array('name' => $thisclient->getName(), 'email' => $thisclient->getEmail(), 'phone' => $thisclient->getPhoneNumber());
}
$info = $_POST && $errors ? Format::htmlchars($_POST) : $info;
$form = null;
if (!$info['topicId']) {
$info['topicId'] = $cfg->getDefaultTopicId();
}
$forms = array();
if ($info['topicId'] && ($topic = Topic::lookup($info['topicId']))) {
foreach ($topic->getForms() as $F) {
if (!$F->hasAnyVisibleFields()) {
continue;
}
if ($_POST) {
$F = $F->instanciate();
$F->isValidForClient();
}
$forms[] = $F;
}
}
?>
<div class="container topheader"><div class="row">
<h1><?php
示例7: updateTicketsSettings
function updateTicketsSettings($vars, &$errors)
{
$f = array();
$f['default_sla_id'] = array('type' => 'int', 'required' => 1, 'error' => __('Selection required'));
$f['default_ticket_status_id'] = array('type' => 'int', 'required' => 1, 'error' => __('Selection required'));
$f['default_priority_id'] = array('type' => 'int', 'required' => 1, 'error' => __('Selection required'));
$f['max_open_tickets'] = array('type' => 'int', 'required' => 1, 'error' => __('Enter valid numeric value'));
$f['autolock_minutes'] = array('type' => 'int', 'required' => 1, 'error' => __('Enter lock time in minutes'));
if ($vars['enable_captcha']) {
if (!extension_loaded('gd')) {
$errors['enable_captcha'] = __('The GD extension is required');
} elseif (!function_exists('imagepng')) {
$errors['enable_captcha'] = __('PNG support is required for Image Captcha');
}
}
if ($vars['default_help_topic'] && ($T = Topic::lookup($vars['default_help_topic'])) && !$T->isActive()) {
$errors['default_help_topic'] = __('Default help topic must be set to active');
}
if (!preg_match('`(?!<\\\\)#`', $vars['number_format'])) {
$errors['number_format'] = 'Ticket number format requires at least one hash character (#)';
}
if (!Validator::process($f, $vars, $errors) || $errors) {
return false;
}
if (isset($vars['default_storage_bk'])) {
$this->update('default_storage_bk', $vars['default_storage_bk']);
}
return $this->updateAll(array('number_format' => $vars['number_format'] ?: '######', 'sequence_id' => $vars['sequence_id'] ?: 0, 'default_priority_id' => $vars['default_priority_id'], 'default_help_topic' => $vars['default_help_topic'], 'default_ticket_status_id' => $vars['default_ticket_status_id'], 'default_sla_id' => $vars['default_sla_id'], 'max_open_tickets' => $vars['max_open_tickets'], 'autolock_minutes' => $vars['autolock_minutes'], 'enable_captcha' => isset($vars['enable_captcha']) ? 1 : 0, 'auto_claim_tickets' => isset($vars['auto_claim_tickets']) ? 1 : 0, 'show_assigned_tickets' => isset($vars['show_assigned_tickets']) ? 0 : 1, 'show_answered_tickets' => isset($vars['show_answered_tickets']) ? 0 : 1, 'show_related_tickets' => isset($vars['show_related_tickets']) ? 1 : 0, 'hide_staff_name' => isset($vars['hide_staff_name']) ? 1 : 0, 'enable_html_thread' => isset($vars['enable_html_thread']) ? 1 : 0, 'allow_client_updates' => isset($vars['allow_client_updates']) ? 1 : 0, 'max_file_size' => $vars['max_file_size']));
}
示例8: sprintf
}
}
if ($i && $i == $count) {
$msg = sprintf(__('Successfully deleted %s'), _N('selected help topic', 'selected elp topics', $count));
} elseif ($i > 0) {
$warn = sprintf(__('%1$d of %2$d %3$s deleted'), $i, $count, _N('selected help topic', 'selected help topics', $count));
} elseif (!$errors['err']) {
$errors['err'] = sprintf(__('Unable to delete %s'), _N('selected help topic', 'selected help topics', $count));
}
break;
case 'sort':
try {
$cfg->setTopicSortMode($_POST['help_topic_sort_mode']);
if ($cfg->getTopicSortMode() == 'm') {
foreach ($_POST as $k => $v) {
if (strpos($k, 'sort-') === 0 && is_numeric($v) && ($t = Topic::lookup(substr($k, 5)))) {
$t->setSortOrder($v);
}
}
}
$msg = __('Successfully set sorting configuration');
} catch (Exception $ex) {
$errors['err'] = __('Unable to set sorting mode');
}
break;
default:
$errors['err'] = __('Unknown action - get technical help.');
}
}
break;
default:
示例9: elseif
}
} elseif ($_POST['disable']) {
$sql = 'UPDATE ' . TOPIC_TABLE . ' SET isactive=0 WHERE topic_id IN (' . implode(',', $_POST['ids']) . ')';
if (db_query($sql) && ($num = db_affected_rows())) {
if ($num == $count) {
$msg = 'Selected help topics disabled';
} else {
$warn = "{$num} of {$count} selected help topics disabled";
}
} else {
$errors['err'] = 'Unable to disable selected help topic(s)';
}
} elseif ($_POST['delete']) {
$i = 0;
foreach ($_POST['ids'] as $k => $v) {
if (($t = Topic::lookup($v)) && $t->delete()) {
$i++;
}
}
if ($i && $i == $count) {
$msg = 'Selected help topics deleted successfully';
} elseif ($i > 0) {
$warn = "{$i} of {$count} selected help topics deleted";
} elseif (!$errors['err']) {
$errors['err'] = 'Unable to delete selected help topics';
}
} else {
$errors['err'] = 'Unknown action';
}
}
break;
示例10: updateTicketsSettings
function updateTicketsSettings($vars, &$errors)
{
$f = array();
$f['default_sla_id'] = array('type' => 'int', 'required' => 1, 'error' => 'Selection required');
$f['default_priority_id'] = array('type' => 'int', 'required' => 1, 'error' => 'Selection required');
$f['max_open_tickets'] = array('type' => 'int', 'required' => 1, 'error' => 'Enter valid numeric value');
$f['autolock_minutes'] = array('type' => 'int', 'required' => 1, 'error' => 'Enter lock time in minutes');
if ($vars['enable_captcha']) {
if (!extension_loaded('gd')) {
$errors['enable_captcha'] = 'The GD extension is required';
} elseif (!function_exists('imagepng')) {
$errors['enable_captcha'] = 'PNG support required for Image Captcha';
}
}
if ($vars['allow_attachments']) {
if (!ini_get('file_uploads')) {
$errors['err'] = 'The \'file_uploads\' directive is disabled in php.ini';
}
if (!is_numeric($vars['max_file_size'])) {
$errors['max_file_size'] = 'Maximum file size required';
}
if (!$vars['allowed_filetypes']) {
$errors['allowed_filetypes'] = 'Allowed file extentions required';
}
if (!($maxfileuploads = ini_get('max_file_uploads'))) {
$maxfileuploads = DEFAULT_MAX_FILE_UPLOADS;
}
if (!$vars['max_user_file_uploads'] || $vars['max_user_file_uploads'] > $maxfileuploads) {
$errors['max_user_file_uploads'] = 'Invalid selection. Must be less than ' . $maxfileuploads;
}
if (!$vars['max_staff_file_uploads'] || $vars['max_staff_file_uploads'] > $maxfileuploads) {
$errors['max_staff_file_uploads'] = 'Invalid selection. Must be less than ' . $maxfileuploads;
}
}
if ($vars['default_help_topic'] && ($T = Topic::lookup($vars['default_help_topic'])) && !$T->isActive()) {
$errors['default_help_topic'] = 'Default help topic must be set to active';
}
if (!Validator::process($f, $vars, $errors) || $errors) {
return false;
}
if (isset($vars['default_storage_bk'])) {
$this->update('default_storage_bk', $vars['default_storage_bk']);
}
return $this->updateAll(array('random_ticket_ids' => $vars['random_ticket_ids'], 'default_priority_id' => $vars['default_priority_id'], 'default_help_topic' => $vars['default_help_topic'], 'default_sla_id' => $vars['default_sla_id'], 'max_open_tickets' => $vars['max_open_tickets'], 'autolock_minutes' => $vars['autolock_minutes'], 'enable_captcha' => isset($vars['enable_captcha']) ? 1 : 0, 'auto_claim_tickets' => isset($vars['auto_claim_tickets']) ? 1 : 0, 'show_assigned_tickets' => isset($vars['show_assigned_tickets']) ? 0 : 1, 'show_answered_tickets' => isset($vars['show_answered_tickets']) ? 0 : 1, 'show_related_tickets' => isset($vars['show_related_tickets']) ? 1 : 0, 'hide_staff_name' => isset($vars['hide_staff_name']) ? 1 : 0, 'enable_html_thread' => isset($vars['enable_html_thread']) ? 1 : 0, 'allow_client_updates' => isset($vars['allow_client_updates']) ? 1 : 0, 'allow_attachments' => isset($vars['allow_attachments']) ? 1 : 0, 'allowed_filetypes' => strtolower(preg_replace("/\n\r|\r\n|\n|\r/", '', trim($vars['allowed_filetypes']))), 'max_file_size' => $vars['max_file_size'], 'max_user_file_uploads' => $vars['max_user_file_uploads'], 'max_staff_file_uploads' => $vars['max_staff_file_uploads'], 'email_attachments' => isset($vars['email_attachments']) ? 1 : 0, 'allow_email_attachments' => isset($vars['allow_email_attachments']) ? 1 : 0, 'allow_online_attachments' => isset($vars['allow_online_attachments']) ? 1 : 0, 'allow_online_attachments_onlogin' => isset($vars['allow_online_attachments_onlogin']) ? 1 : 0));
}
示例11: create
function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
{
global $cfg, $thisclient, $_FILES;
//Make sure the email is not banned
if ($vars['email'] && EmailFilter::isBanned($vars['email'])) {
$errors['err'] = 'Ticket denied. Error #403';
Sys::log(LOG_WARNING, 'Ticket denied', 'Banned email - ' . $vars['email']);
return 0;
}
$id = 0;
$fields = array();
$fields['name'] = array('type' => 'string', 'required' => 1, 'error' => 'Name required');
$fields['email'] = array('type' => 'email', 'required' => 1, 'error' => 'Valid email required');
$fields['subject'] = array('type' => 'string', 'required' => 1, 'error' => 'Subject required');
$fields['message'] = array('type' => 'text', 'required' => 1, 'error' => 'Message required');
switch (strtolower($origin)) {
case 'web':
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Select help topic');
break;
case 'staff':
$fields['deptId'] = array('type' => 'int', 'required' => 1, 'error' => 'Dept. required');
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Topic required');
$fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => 'Invalid date - must be MM/DD/YY');
case 'api':
$fields['source'] = array('type' => 'string', 'required' => 1, 'error' => 'Indicate source');
break;
case 'email':
$fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => 'Email unknown');
break;
default:
# TODO: Return error message
$errors['origin'] = 'Invalid origin given';
}
$fields['pri'] = array('type' => 'int', 'required' => 0, 'error' => 'Invalid Priority');
$fields['phone'] = array('type' => 'phone', 'required' => 0, 'error' => 'Valid phone # required');
if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
$errors['err'] = 'Missing or invalid data - check the errors and try again';
}
//Make sure phone extension is valid
if ($vars['phone_ext']) {
if (!is_numeric($vars['phone_ext']) && !$errors['phone']) {
$errors['phone'] = 'Invalid phone ext.';
} elseif (!$vars['phone']) {
//make sure they just didn't enter ext without phone # XXX: reconsider allowing!
$errors['phone'] = 'Phone number required';
}
}
//Make sure the due date is valid
if ($vars['duedate']) {
if (!$vars['time'] || strpos($vars['time'], ':') === false) {
$errors['time'] = 'Select time';
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
$errors['duedate'] = 'Invalid duedate';
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
$errors['duedate'] = 'Due date must be in the future';
}
}
//check attachment..if any is set ...only set on webbased tickets..
//XXX:?? Create ticket anyway and simply drop the attachments?? We're already doing so with emails.
if ($_FILES['attachment']['name'] && $cfg->allowOnlineAttachments()) {
if (!$cfg->canUploadFileType($_FILES['attachment']['name'])) {
$errors['attachment'] = 'Invalid file type [ ' . Format::htmlchars($_FILES['attachment']['name']) . ' ]';
} elseif ($_FILES['attachment']['size'] > $cfg->getMaxFileSize()) {
$errors['attachment'] = 'File is too big. Max ' . $cfg->getMaxFileSize() . ' bytes allowed';
}
}
# Perform email filter actions on the new ticket arguments XXX: Move filter to the top and check for reject...
if (!$errors && ($ef = new EmailFilter($vars))) {
$ef->apply($vars);
}
# Some things will need to be unpacked back into the scope of this
# function
if (isset($vars['autorespond'])) {
$autorespond = $vars['autorespond'];
}
//check ticket limits..if limit set is >0
//TODO: Base ticket limits on SLA... XXX: move it elsewhere??
if ($vars['email'] && !$errors && $cfg->getMaxOpenTickets() > 0 && strcasecmp($origin, 'staff')) {
$openTickets = Ticket::getOpenTicketsByEmail($vars['email']);
if ($openTickets >= $cfg->getMaxOpenTickets()) {
$errors['err'] = "You've reached the maximum open tickets allowed.";
//Send the notice only once (when the limit is reached) incase of autoresponders at client end.
if ($cfg->getMaxOpenTickets() == $openTickets && $cfg->sendOverlimitNotice()) {
if ($vars['deptId']) {
$dept = Dept::lookup($vars['deptId']);
}
if (!$dept || !($tpl = $dept->getTemplate())) {
$tpl = $cfg->getDefaultTemplate();
}
if (!$dept || !($email = $dept->getAutoRespEmail())) {
$email = $cfg->getDefaultEmail();
}
if ($tpl && ($msg = $tpl->getOverlimitMsgTemplate()) && $email) {
$body = str_replace('%name', $vars['name'], $msg['body']);
$body = str_replace('%email', $vars['email'], $msg['body']);
$body = str_replace('%url', $cfg->getBaseUrl(), $body);
$body = str_replace('%signature', $dept && $dept->isPublic() ? $dept->getSignature() : '', $body);
$email->send($vars['email'], $msg['subj'], $body);
}
//Log + Alert admin...this might be spammy (no option to disable)...but it is helpful..I think.
//.........这里部分代码省略.........
示例12: create
static function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
{
global $ost, $cfg, $thisclient, $_FILES;
// Don't enforce form validation for email
$field_filter = function ($type) use($origin) {
return function ($f) use($origin, $type) {
// Ultimately, only offer validation errors for web for
// non-internal fields. For email, no validation can be
// performed. For other origins, validate as usual
switch (strtolower($origin)) {
case 'email':
return false;
case 'staff':
// Required 'Contact Information' fields aren't required
// when staff open tickets
return $type != 'user' || in_array($f->get('name'), array('name', 'email'));
case 'web':
return !$f->get('private');
default:
return true;
}
};
};
$reject_ticket = function ($message) use(&$errors) {
global $ost;
$errors = array('errno' => 403, 'err' => __('This help desk is for use by authorized users only'));
$ost->logWarning(_S('Ticket Denied'), $message, false);
return 0;
};
Signal::send('ticket.create.before', null, $vars);
// Create and verify the dynamic form entry for the new ticket
$form = TicketForm::getNewInstance();
$form->setSource($vars);
// If submitting via email or api, ensure we have a subject and such
if (!in_array(strtolower($origin), array('web', 'staff'))) {
foreach ($form->getFields() as $field) {
$fname = $field->get('name');
if ($fname && isset($vars[$fname]) && !$field->value) {
$field->value = $field->parse($vars[$fname]);
}
}
}
if (!$form->isValid($field_filter('ticket'))) {
$errors += $form->errors();
}
if ($vars['uid']) {
$user = User::lookup($vars['uid']);
}
$id = 0;
$fields = array();
$fields['message'] = array('type' => '*', 'required' => 1, 'error' => __('Message content is required'));
switch (strtolower($origin)) {
case 'web':
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => __('Select a help topic'));
break;
case 'staff':
$fields['deptId'] = array('type' => 'int', 'required' => 0, 'error' => __('Department selection is required'));
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => __('Help topic selection is required'));
$fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => __('Invalid date format - must be MM/DD/YY'));
case 'api':
$fields['source'] = array('type' => 'string', 'required' => 1, 'error' => __('Indicate ticket source'));
break;
case 'email':
$fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => __('Unknown system email'));
break;
default:
# TODO: Return error message
$errors['err'] = $errors['origin'] = __('Invalid ticket origin given');
}
if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
$errors['err'] = __('Missing or invalid data - check the errors and try again');
}
//Make sure the due date is valid
if ($vars['duedate']) {
if (!$vars['time'] || strpos($vars['time'], ':') === false) {
$errors['time'] = __('Select a time from the list');
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
$errors['duedate'] = __('Invalid due date');
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
$errors['duedate'] = __('Due date must be in the future');
}
}
if (!$errors) {
# Perform ticket filter actions on the new ticket arguments
$__form = null;
if ($vars['topicId']) {
if (($__topic = Topic::lookup($vars['topicId'])) && ($__form = $__topic->getForm())) {
$__form = $__form->instanciate();
$__form->setSource($vars);
}
}
try {
$vars = self::filterTicketData($origin, $vars, array($form, $__form), $user);
} catch (RejectedException $ex) {
return $reject_ticket(sprintf(_S('Ticket rejected (%s) by filter "%s"'), $ex->vars['email'], $ex->getRejectingFilter()->getName()));
}
//Make sure the open ticket limit hasn't been reached. (LOOP CONTROL)
if ($cfg->getMaxOpenTickets() > 0 && strcasecmp($origin, 'staff') && ($_user = TicketUser::lookupByEmail($vars['email'])) && ($openTickets = $_user->getNumOpenTickets()) && $openTickets >= $cfg->getMaxOpenTickets()) {
$errors = array('err' => __("You've reached the maximum open tickets allowed."));
$ost->logWarning(sprintf(_S('Ticket denied - %s'), $vars['email']), sprintf(_S('Max open tickets (%1$d) reached for %2$s'), $cfg->getMaxOpenTickets(), $vars['email']), false);
//.........这里部分代码省略.........
示例13: create
function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
{
global $cfg, $thisclient, $_FILES;
//Check for 403
if ($vars['email'] && Validator::is_email($vars['email'])) {
//Make sure the email address is not banned
if (EmailFilter::isBanned($vars['email'])) {
$errors['err'] = 'Ticket denied. Error #403';
Sys::log(LOG_WARNING, 'Ticket denied', 'Banned email - ' . $vars['email']);
return 0;
}
//Make sure the open ticket limit hasn't been reached. (LOOP CONTROL)
if ($cfg->getMaxOpenTickets() > 0 && strcasecmp($origin, 'staff') && ($client = Client::lookupByEmail($vars['email'])) && ($openTickets = $client->getNumOpenTickets()) && $opentickets >= $cfg->getMaxOpenTickets()) {
$errors['err'] = "You've reached the maximum open tickets allowed.";
Sys::log(LOG_WARNING, 'Ticket denied -' . $vars['email'], sprintf('Max open tickets (%d) reached for %s ', $cfg->getMaxOpenTickets(), $vars['email']));
return 0;
}
}
// Make sure email contents should not be rejected
if (($email_filter = new EmailFilter($vars)) && ($filter = $email_filter->shouldReject())) {
$errors['err'] = 'Ticket denied. Error #403';
Sys::log(LOG_WARNING, 'Ticket denied', sprintf('Banned email - %s by filter "%s"', $vars['email'], $filter->getName()));
return 0;
}
$id = 0;
$fields = array();
$fields['name'] = array('type' => 'string', 'required' => 1, 'error' => 'Name required');
$fields['email'] = array('type' => 'email', 'required' => 1, 'error' => 'Valid email required');
$fields['subject'] = array('type' => 'string', 'required' => 1, 'error' => 'Subject required');
$fields['message'] = array('type' => 'text', 'required' => 1, 'error' => 'Message required');
switch (strtolower($origin)) {
case 'web':
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Select help topic');
break;
case 'staff':
$fields['deptId'] = array('type' => 'int', 'required' => 1, 'error' => 'Dept. required');
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => 'Topic required');
$fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => 'Invalid date - must be MM/DD/YY');
case 'api':
$fields['source'] = array('type' => 'string', 'required' => 1, 'error' => 'Indicate source');
break;
case 'email':
$fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => 'Email unknown');
break;
default:
# TODO: Return error message
$errors['err'] = $errors['origin'] = 'Invalid origin given';
}
$fields['priorityId'] = array('type' => 'int', 'required' => 0, 'error' => 'Invalid Priority');
$fields['phone'] = array('type' => 'phone', 'required' => 0, 'error' => 'Valid phone # required');
if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
$errors['err'] = 'Missing or invalid data - check the errors and try again';
}
//Make sure phone extension is valid
if ($vars['phone_ext']) {
if (!is_numeric($vars['phone_ext']) && !$errors['phone']) {
$errors['phone'] = 'Invalid phone ext.';
} elseif (!$vars['phone']) {
//make sure they just didn't enter ext without phone # XXX: reconsider allowing!
$errors['phone'] = 'Phone number required';
}
}
//Make sure the due date is valid
if ($vars['duedate']) {
if (!$vars['time'] || strpos($vars['time'], ':') === false) {
$errors['time'] = 'Select time';
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
$errors['duedate'] = 'Invalid duedate';
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
$errors['duedate'] = 'Due date must be in the future';
}
}
# Perform email filter actions on the new ticket arguments XXX: Move filter to the top and check for reject...
if (!$errors && $email_filter) {
$email_filter->apply($vars);
}
# Some things will need to be unpacked back into the scope of this
# function
if (isset($vars['autorespond'])) {
$autorespond = $vars['autorespond'];
}
//Any error above is fatal.
if ($errors) {
return 0;
}
// OK...just do it.
$deptId = $vars['deptId'];
//pre-selected Dept if any.
$priorityId = $vars['priorityId'];
$source = ucfirst($vars['source']);
$topic = NULL;
// Intenal mapping magic...see if we need to overwrite anything
if (isset($vars['topicId']) && ($topic = Topic::lookup($vars['topicId']))) {
//Ticket created via web by user/or staff
$deptId = $deptId ? $deptId : $topic->getDeptId();
$priorityId = $priorityId ? $priorityId : $topic->getPriorityId();
if ($autorespond) {
$autorespond = $topic->autoRespond();
}
$source = $vars['source'] ? $vars['source'] : 'Web';
//.........这里部分代码省略.........
示例14: getTopic
function getTopic()
{
// Topic::lookup will do validation on the ID, no need to duplicate
// code here
return Topic::lookup($this->getTopicId());
}
示例15: create
static function create($vars, &$errors, $origin, $autorespond = true, $alertstaff = true)
{
global $ost, $cfg, $thisclient, $_FILES;
// Don't enforce form validation for email
$field_filter = function ($type) use($origin) {
return function ($f) use($origin, $type) {
// Ultimately, only offer validation errors for web for
// non-internal fields. For email, no validation can be
// performed. For other origins, validate as usual
switch (strtolower($origin)) {
case 'email':
return false;
case 'staff':
// Required 'Contact Information' fields aren't required
// when staff open tickets
return $type != 'user' || in_array($f->get('name'), array('name', 'email'));
case 'web':
return !$f->get('private');
default:
return true;
}
};
};
$reject_ticket = function ($message) use(&$errors) {
global $ost;
$errors = array('errno' => 403, 'err' => __('This help desk is for use by authorized users only'));
$ost->logWarning(_S('Ticket Denied'), $message, false);
return 0;
};
Signal::send('ticket.create.before', null, $vars);
// Create and verify the dynamic form entry for the new ticket
$form = TicketForm::getNewInstance();
$form->setSource($vars);
// If submitting via email or api, ensure we have a subject and such
if (!in_array(strtolower($origin), array('web', 'staff'))) {
foreach ($form->getFields() as $field) {
$fname = $field->get('name');
if ($fname && isset($vars[$fname]) && !$field->value) {
$field->value = $field->parse($vars[$fname]);
}
}
}
if (!$form->isValid($field_filter('ticket'))) {
$errors += $form->errors();
}
/*INICIO
Creado por Anthony Parisi
2016-02-01
Con las siguientes lineas de código, se crea el ticket mediante la API.*/
if (!in_array(strtolower($origin), array('web', 'staff'))) {
$errors = array();
}
/* FIN */
if ($vars['uid']) {
$user = User::lookup($vars['uid']);
}
$id = 0;
$fields = array();
$fields['message'] = array('type' => '*', 'required' => 1, 'error' => __('Message content is required'));
switch (strtolower($origin)) {
case 'web':
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => __('Select a help topic'));
break;
case 'staff':
$fields['deptId'] = array('type' => 'int', 'required' => 0, 'error' => __('Department selection is required'));
$fields['topicId'] = array('type' => 'int', 'required' => 1, 'error' => __('Help topic selection is required'));
$fields['duedate'] = array('type' => 'date', 'required' => 0, 'error' => __('Invalid date format - must be MM/DD/YY'));
case 'api':
$fields['source'] = array('type' => 'string', 'required' => 1, 'error' => __('Indicate ticket source'));
break;
case 'email':
$fields['emailId'] = array('type' => 'int', 'required' => 1, 'error' => __('Unknown system email'));
break;
default:
# TODO: Return error message
$errors['err'] = $errors['origin'] = __('Invalid ticket origin given');
}
if (!Validator::process($fields, $vars, $errors) && !$errors['err']) {
$errors['err'] = __('Missing or invalid data - check the errors and try again');
}
//Make sure the due date is valid
if ($vars['duedate']) {
if (!$vars['time'] || strpos($vars['time'], ':') === false) {
$errors['time'] = __('Select a time from the list');
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) === false) {
$errors['duedate'] = __('Invalid due date');
} elseif (strtotime($vars['duedate'] . ' ' . $vars['time']) <= time()) {
$errors['duedate'] = __('Due date must be in the future');
}
}
if (!$errors) {
# Perform ticket filter actions on the new ticket arguments
$__form = null;
if ($vars['topicId']) {
if (($__topic = Topic::lookup($vars['topicId'])) && ($__form = $__topic->getForm())) {
$__form = $__form->instanciate();
$__form->setSource($vars);
}
}
try {
//.........这里部分代码省略.........