TicketGateway can now insert tickets
This commit is contained in:
parent
65b10bae3c
commit
044faa77f6
@ -236,6 +236,15 @@ class Ticket {
|
|||||||
*/
|
*/
|
||||||
public $attachments;
|
public $attachments;
|
||||||
|
|
||||||
|
function getAttachmentsForDatabase() {
|
||||||
|
$attachmentArray = array();
|
||||||
|
foreach ($this->attachments as $attachment) {
|
||||||
|
$attachmentArray[] = $attachment->id . '#' . $attachment->fileName . '#' . $attachment->savedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(',', $attachmentArray);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int[]|null
|
* @var int[]|null
|
||||||
*/
|
*/
|
||||||
@ -272,6 +281,9 @@ class Ticket {
|
|||||||
public $userAgent;
|
public $userAgent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 0 => width
|
||||||
|
* 1 => height
|
||||||
|
*
|
||||||
* @var int[]|null
|
* @var int[]|null
|
||||||
*/
|
*/
|
||||||
public $screenResolution;
|
public $screenResolution;
|
||||||
|
@ -82,4 +82,109 @@ class TicketGateway extends CommonDao {
|
|||||||
|
|
||||||
return $ticket;
|
return $ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $ticket Ticket
|
||||||
|
* @param $heskSettings
|
||||||
|
*/
|
||||||
|
function createTicket($ticket, $heskSettings) {
|
||||||
|
global $hesklang;
|
||||||
|
|
||||||
|
// If language is not set or default, set it to NULL.
|
||||||
|
if ($ticket->language === null || empty($ticket->language)) {
|
||||||
|
$language = (!$heskSettings['can_sel_lang']) ? HESK_DEFAULT_LANGUAGE : hesk_dbEscape($hesklang['LANGUAGE']);
|
||||||
|
} else {
|
||||||
|
$language = $ticket->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dueDate = $ticket->dueDate ? "'{$ticket->dueDate}'" : "NULL";
|
||||||
|
// Prepare SQL for custom fields
|
||||||
|
$customWhere = '';
|
||||||
|
$customWhat = '';
|
||||||
|
|
||||||
|
for ($i=1; $i<=50; $i++)
|
||||||
|
{
|
||||||
|
$customWhere .= ", `custom{$i}`";
|
||||||
|
$customWhat .= ", '" . (isset($ticket->customFields[$i]) ? hesk_dbEscape($ticket->customFields[$i]) : '') . "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
$suggestedArticles = '';
|
||||||
|
if ($ticket->suggestedArticles !== null && !empty($ticket->suggestedArticles)) {
|
||||||
|
$suggestedArticles = implode(',', $ticket->suggestedArticles);
|
||||||
|
}
|
||||||
|
|
||||||
|
$latitude = $ticket->location !== null
|
||||||
|
&& isset($ticket->location[0])
|
||||||
|
&& $ticket->location[0] !== null ? $ticket->location[0] : '';
|
||||||
|
$longitude = $ticket->location !== null
|
||||||
|
&& isset($ticket->location[1])
|
||||||
|
&& $ticket->location[1] !== null ? $ticket->location[1] : '';
|
||||||
|
$userAgent = $ticket->userAgent !== null ? $ticket->userAgent : '';
|
||||||
|
$screenResolutionWidth = $ticket->screenResolution !== null
|
||||||
|
&& isset($ticket->screenResolution[0])
|
||||||
|
&& $ticket->screenResolution[0] !== null ? intval($ticket->screenResolution[0]) : '';
|
||||||
|
$screenResolutionHeight = $ticket->screenResolution !== null
|
||||||
|
&& isset($ticket->screenResolution[1])
|
||||||
|
&& $ticket->screenResolution[1] !== null ? intval($ticket->screenResolution[1]) : '';
|
||||||
|
|
||||||
|
$sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
|
||||||
|
(
|
||||||
|
`trackid`,
|
||||||
|
`name`,
|
||||||
|
`email`,
|
||||||
|
`category`,
|
||||||
|
`priority`,
|
||||||
|
`subject`,
|
||||||
|
`message`,
|
||||||
|
`dt`,
|
||||||
|
`lastchange`,
|
||||||
|
`articles`,
|
||||||
|
`ip`,
|
||||||
|
`language`,
|
||||||
|
`openedby`,
|
||||||
|
`owner`,
|
||||||
|
`attachments`,
|
||||||
|
`merged`,
|
||||||
|
`status`,
|
||||||
|
`latitude`,
|
||||||
|
`longitude`,
|
||||||
|
`html`,
|
||||||
|
`user_agent`,
|
||||||
|
`screen_resolution_height`,
|
||||||
|
`screen_resolution_width`,
|
||||||
|
`due_date`,
|
||||||
|
`history`
|
||||||
|
{$customWhere}
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
'" . hesk_dbEscape($ticket->trackingId) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->name) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->email) . "',
|
||||||
|
'" . intval($ticket->categoryId) . "',
|
||||||
|
'" . intval($ticket->priorityId) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->subject) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->message) . "',
|
||||||
|
NOW(),
|
||||||
|
NOW(),
|
||||||
|
" . $suggestedArticles . ",
|
||||||
|
'" . hesk_dbEscape($ticket->ipAddress) . "',
|
||||||
|
'" . hesk_dbEscape($language) . "',
|
||||||
|
'" . intval($ticket->openedBy) . "',
|
||||||
|
'" . intval($ticket->ownerId) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->getAttachmentsForDatabase()) . "',
|
||||||
|
'',
|
||||||
|
'" . intval($ticket->statusId) . "',
|
||||||
|
'" . hesk_dbEscape($latitude) . "',
|
||||||
|
'" . hesk_dbEscape($longitude) . "',
|
||||||
|
'" . hesk_dbEscape($ticket->usesHtml) . "',
|
||||||
|
'" . hesk_dbEscape($userAgent) . "',
|
||||||
|
" . hesk_dbEscape($screenResolutionHeight) . ",
|
||||||
|
" . hesk_dbEscape($screenResolutionWidth) . ",
|
||||||
|
{$dueDate},
|
||||||
|
'" . hesk_dbEscape($ticket->auditTrailHtml) . "'
|
||||||
|
{$customWhat}
|
||||||
|
)
|
||||||
|
";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user