Moved the Agents into their own repo. Kept the agent.pl just for reference
This commit is contained in:
parent
22381be29a
commit
8680a02b13
18132 changed files with 0 additions and 2569420 deletions
|
|
@ -1,180 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Attachments
|
||||
{
|
||||
private $db;
|
||||
|
||||
private $filesArray = array();
|
||||
private $path;
|
||||
private $maxAttachments;
|
||||
private $maxSize;
|
||||
private $permittedExtensions = array();
|
||||
|
||||
private $allMimeTypes = array();
|
||||
private $permittedMimeTypes = array();
|
||||
|
||||
private $errors = array();
|
||||
|
||||
public function __construct(OGPDatabase $db, $attachments, $path, $maxAttachments, $maxSize, $permittedExtensions)
|
||||
{
|
||||
$this->db = $db;
|
||||
|
||||
$this->filesArray = $this->normalizeFiles($attachments);
|
||||
$this->path = $path;
|
||||
$this->maxAttachments = $maxAttachments;
|
||||
$this->maxSize = $maxSize;
|
||||
$this->permittedExtensions = $permittedExtensions;
|
||||
|
||||
$this->allMimeTypes = require __DIR__ .'/mime.types.php';
|
||||
$this->createMimeArray();
|
||||
}
|
||||
|
||||
public function validAttachmentCount()
|
||||
{
|
||||
if (!empty($this->filesArray)) {
|
||||
return ($this->maxAttachments == 0 || count($this->filesArray) <= $this->maxAttachments);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
foreach ($this->filesArray as $i => $file) {
|
||||
switch ($file['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
$this->errors[$i][] = get_lang_f('attachment_err_ini_size', $file['name'], $file['size']);
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$this->errors[$i][] = get_lang_f('attachment_err_partial', $file['name']);
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->errors[$i][] = get_lang_f('attachment_err_no_tmp', $file['name']);
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$this->errors[$i][] = get_lang_f('attachment_err_cant_write', $file['name']);
|
||||
break;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$this->errors[$i][] = get_lang_f('attachment_err_extension', $file['name']);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->checkSize($file['size'])) {
|
||||
$this->errors[$i][] = get_lang_f('attachment_too_large', $file['name'], $file['size'], $this->maxSize);
|
||||
}
|
||||
|
||||
if (in_array($this->getMimeType($file['tmp_name']), $this->permittedMimeTypes) === false) {
|
||||
$this->errors[$i][] = get_lang_f('attachment_forbidden_type', $file['name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
foreach ($this->errors as $error) {
|
||||
$errors = array_merge($error, $errors);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
public function save($tid, $reply_id = null)
|
||||
{
|
||||
$savePath = (substr($this->path, -1) == '/' ? $this->path : $this->path . '/');
|
||||
|
||||
foreach ($this->filesArray as $i => $file) {
|
||||
// Ignore and don't save file which has an error associated with it.
|
||||
if (array_key_exists($i, $this->errors)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$original_name = basename($file['name']);
|
||||
$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
|
||||
|
||||
$unique_name = bin2hex(openssl_random_pseudo_bytes(12)) . ( !$extension ? '' : '.' . $extension );
|
||||
|
||||
move_uploaded_file($file['tmp_name'], $savePath . $unique_name);
|
||||
$this->insertAttachment($tid, $reply_id, $original_name, $unique_name);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertAttachment($tid, $reply_id, $original_name, $unique_name)
|
||||
{
|
||||
$fields = array(
|
||||
'ticket_id' => $tid,
|
||||
'original_name' => $original_name,
|
||||
'unique_name' => $unique_name
|
||||
);
|
||||
|
||||
if (is_numeric($reply_id)) {
|
||||
$fields['reply_id'] = $reply_id;
|
||||
}
|
||||
|
||||
return $this->db->resultInsertId('ticket_attachments', $fields);
|
||||
}
|
||||
|
||||
// Turn the _FILES array into something that's better to work with.
|
||||
private function normalizeFiles($files)
|
||||
{
|
||||
$_files = array();
|
||||
$_files_count = count($files['name']);
|
||||
$_files_keys = array_keys($files);
|
||||
|
||||
for ($i = 0; $i < $_files_count; $i++) {
|
||||
if (empty($files['tmp_name'][$i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($_files_keys as $key) {
|
||||
$_files[$i][$key] = $files[$key][$i];
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($_files);
|
||||
}
|
||||
|
||||
public function checkPath()
|
||||
{
|
||||
if (empty($this->filesArray)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_dir($this->path)) {
|
||||
mkdir($this->path, 0777, true);
|
||||
}
|
||||
|
||||
return is_writable($this->path);
|
||||
}
|
||||
|
||||
// Create an array of mimetypes based on the allowed extensions.
|
||||
private function createMimeArray()
|
||||
{
|
||||
$permittedMimeTypes = [];
|
||||
foreach ($this->allMimeTypes['mimes'] as $ext => $mimes) {
|
||||
if (in_array($ext, $this->permittedExtensions)) {
|
||||
$permittedMimeTypes = array_merge($permittedMimeTypes, $mimes);
|
||||
}
|
||||
}
|
||||
|
||||
$this->permittedMimeTypes = $permittedMimeTypes;
|
||||
}
|
||||
|
||||
private function checkSize($uploadedFileSize)
|
||||
{
|
||||
return ($uploadedFileSize > $this->maxSize);
|
||||
}
|
||||
|
||||
// Don't rely on $_FILES type which can be spoofed. Get the true mimetype via finfo.
|
||||
private function getMimeType($file)
|
||||
{
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$mime = $finfo->file($file);
|
||||
return $mime;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
|
||||
class TicketSettings
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct(OGPDatabase $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function get($setting = '*')
|
||||
{
|
||||
$query = "SELECT setting_name, setting_value FROM OGP_DB_PREFIXticket_settings";
|
||||
|
||||
if (is_array($setting) && !empty($setting)) {
|
||||
$in = '';
|
||||
$query .= ' WHERE setting_name IN (';
|
||||
|
||||
foreach ($setting as $setting_name) {
|
||||
$in .= "'". $setting_name ."', ";
|
||||
}
|
||||
|
||||
$query .= rtrim($in, ', ');
|
||||
$query .= ')';
|
||||
} elseif (!empty($setting) && $setting !== '*') {
|
||||
$query = $query . " WHERE setting_name = '".$setting."'";
|
||||
}
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return $result ? $this->flatten($result) : false;
|
||||
}
|
||||
|
||||
public function set($settings)
|
||||
{
|
||||
foreach ($settings as $setting_name => $setting_value) {
|
||||
$query = $this->buildQueryString($setting_name, $setting_value);
|
||||
$this->db->query($query);
|
||||
}
|
||||
}
|
||||
|
||||
private function buildQueryString($setting_name, $setting_value)
|
||||
{
|
||||
$setting_name = $this->db->real_escape_string($setting_name);
|
||||
$setting_value = $this->db->real_escape_string($setting_value);
|
||||
|
||||
$queryString = "INSERT INTO OGP_DB_PREFIXticket_settings (setting_name, setting_value)
|
||||
VALUES (
|
||||
'". $setting_name ."', '". $setting_value ."'
|
||||
)
|
||||
|
||||
ON DUPLICATE KEY UPDATE setting_value = '". $setting_value ."'";
|
||||
|
||||
return $queryString;
|
||||
}
|
||||
|
||||
private function flatten($arr)
|
||||
{
|
||||
$newArr = array();
|
||||
|
||||
foreach ($arr as $k) {
|
||||
$newArr[$k['setting_name']] = $k['setting_value'];
|
||||
}
|
||||
|
||||
return $newArr;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the array_column library
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
|
||||
* @license http://opensource.org/licenses/MIT MIT
|
||||
*/
|
||||
|
||||
if (!function_exists('array_column')) {
|
||||
/**
|
||||
* Returns the values from a single column of the input array, identified by
|
||||
* the $columnKey.
|
||||
*
|
||||
* Optionally, you may provide an $indexKey to index the values in the returned
|
||||
* array by the values from the $indexKey column in the input array.
|
||||
*
|
||||
* @param array $input A multi-dimensional array (record set) from which to pull
|
||||
* a column of values.
|
||||
* @param mixed $columnKey The column of values to return. This value may be the
|
||||
* integer key of the column you wish to retrieve, or it
|
||||
* may be the string key name for an associative array.
|
||||
* @param mixed $indexKey (Optional.) The column to use as the index/keys for
|
||||
* the returned array. This value may be the integer key
|
||||
* of the column, or it may be the string key name.
|
||||
* @return array
|
||||
*/
|
||||
function array_column($input = null, $columnKey = null, $indexKey = null)
|
||||
{
|
||||
// Using func_get_args() in order to check for proper number of
|
||||
// parameters and trigger errors exactly as the built-in array_column()
|
||||
// does in PHP 5.5.
|
||||
$argc = func_num_args();
|
||||
$params = func_get_args();
|
||||
|
||||
if ($argc < 2) {
|
||||
trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_array($params[0])) {
|
||||
trigger_error(
|
||||
'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
|
||||
E_USER_WARNING
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_int($params[1])
|
||||
&& !is_float($params[1])
|
||||
&& !is_string($params[1])
|
||||
&& $params[1] !== null
|
||||
&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
|
||||
) {
|
||||
trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($params[2])
|
||||
&& !is_int($params[2])
|
||||
&& !is_float($params[2])
|
||||
&& !is_string($params[2])
|
||||
&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
|
||||
) {
|
||||
trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
$paramsInput = $params[0];
|
||||
$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
|
||||
|
||||
$paramsIndexKey = null;
|
||||
if (isset($params[2])) {
|
||||
if (is_float($params[2]) || is_int($params[2])) {
|
||||
$paramsIndexKey = (int) $params[2];
|
||||
} else {
|
||||
$paramsIndexKey = (string) $params[2];
|
||||
}
|
||||
}
|
||||
|
||||
$resultArray = array();
|
||||
|
||||
foreach ($paramsInput as $row) {
|
||||
$key = $value = null;
|
||||
$keySet = $valueSet = false;
|
||||
|
||||
if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
|
||||
$keySet = true;
|
||||
$key = (string) $row[$paramsIndexKey];
|
||||
}
|
||||
|
||||
if ($paramsColumnKey === null) {
|
||||
$valueSet = true;
|
||||
$value = $row;
|
||||
} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
|
||||
$valueSet = true;
|
||||
$value = $row[$paramsColumnKey];
|
||||
}
|
||||
|
||||
if ($valueSet) {
|
||||
if ($keySet) {
|
||||
$resultArray[$key] = $value;
|
||||
} else {
|
||||
$resultArray[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
<?php
|
||||
|
||||
function ticketHeader($info)
|
||||
{
|
||||
$created = new DateTime($info['created_at']);
|
||||
$updated = new DateTime($info['last_updated']);
|
||||
|
||||
return '<div class="divTable">
|
||||
<div class="divTableBody">
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('ticket_id').'</div>
|
||||
<div class="divTableCell contentblock_ticket">#'.$info['tid'].' - '.$info['uid'] .'</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('service_id').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.((int)$info['service_id'] === 0 ? '<i>'.get_lang('ticket_no_service').'</i>' :
|
||||
'<a href="?m=user_games&p=edit&home_id='.(int)$info['service_id'].'">#'.(int)$info['service_id'].'</a>'). '</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('ticket_subject').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.$info['subject'].'</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('ticket_submitted').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.$created->format('jS M Y (H:i)').'</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('ticket_updated').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.$updated->format('jS M Y (H:i)').'</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('ticket_status').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.ticketCodeToName($info['status']).'</div>
|
||||
</div>
|
||||
<div class="divTableRow">
|
||||
<div class="divTableCell infoblock_ticket">'.get_lang('submitter_info').'</div>
|
||||
<div class="divTableCell contentblock_ticket">'.get_lang('username').': <a href="?m=user_admin&p=edit_user&user_id='. $info['user_id'] .'">'. $info['users_login'] .'</a> -
|
||||
'. (!empty($info['users_fname']) ? get_lang('name') . ': ' . htmlentities($info['users_fname']) . (!empty($info['users_lname']) ? ' '.htmlentities($info['users_lname']).' - ' : '') : '') .
|
||||
get_lang('ip') . ': '. inet_ntop($info['user_ip']) .' - '.get_lang('role') .': '. ucfirst($info['users_role']).'
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
function ticketMessage($messageData, $uid, $loggedInAdmin = false, $ratingsEnabled)
|
||||
{
|
||||
$date = new DateTime($messageData['date']);
|
||||
$tid = $messageData['ticket_id'];
|
||||
$rating = $messageData['rating'];
|
||||
|
||||
$class = 'user';
|
||||
|
||||
if (isset($messageData['is_admin'])) {
|
||||
$class = $messageData['is_admin'] == 1 ? 'admin' : 'user';
|
||||
}
|
||||
|
||||
$replyBox = '<div class="ticket_reply '. $class .'">
|
||||
<div class="date">
|
||||
'.$date->format('jS M Y (H:i)').'
|
||||
</div>
|
||||
<div class="'. $class .'">
|
||||
<span class="name">
|
||||
<a href="?m=user_admin&p=edit_user&user_id='.$messageData['user_id'].'">'. htmlentities($messageData['users_login']) .'</a> ' .
|
||||
(!empty($messageData['users_fname']) ? htmlentities($messageData['users_fname']) . (!empty($messageData['users_lname']) ? ' '.htmlentities($messageData['users_lname']) : '') : '') .'
|
||||
</span>
|
||||
<span class="type">
|
||||
'.ucfirst($messageData['users_role']).'
|
||||
</span>
|
||||
</div>
|
||||
<div class="message">'.nl2br(htmlentities($messageData['message'])).'</div>';
|
||||
|
||||
$replyBox .= '<div class="ticket_footer">';
|
||||
|
||||
$replyBox .= '<div class="footer_row">';
|
||||
|
||||
if ($messageData['users_role'] !== 'admin' || $loggedInAdmin) {
|
||||
$replyBox .= '<div class="left">'.get_lang('ip').': '.inet_ntop($messageData['user_ip']).'</div>';
|
||||
}
|
||||
|
||||
if ($messageData['users_role'] == 'admin' && $ratingsEnabled) {
|
||||
$replyBox .= '<div class="right rateResponse" data-tid="'. $tid .'" data-uid="'. $uid .'" data-reply-id="'. $messageData['reply_id'] .'" data-rating="'. $rating .'"></div>';
|
||||
}
|
||||
|
||||
$replyBox .= '<div class="clear"></div>';
|
||||
$replyBox .= '</div>'; // footer_row
|
||||
|
||||
if (isset($messageData['attachments'])) {
|
||||
$replyBox .= '<div class="footer_row attachmentContainer">';
|
||||
|
||||
$replyBox .= '<div class="left attachmentHeader">'. get_lang('attachments') .'</div>';
|
||||
$replyBox .= '<div class="clear"></div>';
|
||||
$replyBox .= '<div class="left attachmentList">';
|
||||
|
||||
$attachmentList = '';
|
||||
foreach ($messageData['attachments'] as $attachment) {
|
||||
$attachmentList .= '<a href="#" class="downloadAttachmentLink" data-id="'. $attachment['attachment_id'] .'" data-tid="'. $tid .'" data-uid="'. $uid .'">'. htmlentities($attachment['original_name']) .'</a>, ';
|
||||
}
|
||||
|
||||
$replyBox .= rtrim($attachmentList, ', ');
|
||||
$replyBox .= '</div>'; //left
|
||||
$replyBox .= '<div class="clear"></div>';
|
||||
|
||||
$replyBox .= '</div>'; //footer row.
|
||||
}
|
||||
|
||||
$replyBox .= '</div>'; // ticket_footer
|
||||
$replyBox .= '</div>'; // ./div :: ticket_reply $class
|
||||
|
||||
return $replyBox;
|
||||
}
|
||||
|
||||
function ticketErrors($errors = array(), $header = '')
|
||||
{
|
||||
$header = empty($header) ? get_lang('ticket_errors_occured') . ':' : $header;
|
||||
$return = '<div class="ticketErrorHolder">
|
||||
<p class="failure" id="errorHeader">'. $header .'</p>
|
||||
<ul class="ticketErrorList">';
|
||||
foreach ($errors as $error) {
|
||||
$return .= '<li class="ticketError">' . $error . '</li>';
|
||||
}
|
||||
$return .= '</ul>
|
||||
</div>';
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function ticketCodeToName($code, $css = false)
|
||||
{
|
||||
$codes = array(
|
||||
'ticket_closed',
|
||||
'ticket_open',
|
||||
'ticket_admin_response',
|
||||
'ticket_customer_response',
|
||||
);
|
||||
|
||||
return $css ? $codes[$code] : get_lang($codes[$code]);
|
||||
}
|
||||
|
||||
function attachmentForm()
|
||||
{
|
||||
$html = '
|
||||
<div class="attachment_container">
|
||||
<div class="attachment_header">'. get_lang('attachments') .'</div>
|
||||
|
||||
<div class="attachment_add">
|
||||
<button id="add_file_attachment">'. get_lang('add_file_attachment') .'</button>
|
||||
</div>
|
||||
|
||||
<div class="attachment_inputs">
|
||||
<input type="file" name="ticket_file[]">
|
||||
</div>
|
||||
|
||||
<div class="attachment_info">
|
||||
<div id="file_size_info"></div>
|
||||
<div id="extension_info"></div>
|
||||
</div>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
function bytesTo($bytes)
|
||||
{
|
||||
if ($bytes == 0) {
|
||||
return '0.00 B';
|
||||
}
|
||||
|
||||
$s = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
|
||||
$e = floor(log($bytes, 1024));
|
||||
|
||||
return round($bytes / pow(1024, $e), 2) . $s[$e];
|
||||
}
|
||||
|
||||
function toBytes($from)
|
||||
{
|
||||
$number = substr($from, 0, -2);
|
||||
switch (strtoupper(substr($from, -2))) {
|
||||
case "KB":
|
||||
return $number*1024;
|
||||
case "MB":
|
||||
return $number*pow(1024, 2);
|
||||
case "GB":
|
||||
return $number*pow(1024, 3);
|
||||
case "TB":
|
||||
return $number*pow(1024, 4);
|
||||
case "PB":
|
||||
return $number*pow(1024, 5);
|
||||
default:
|
||||
return $from;
|
||||
}
|
||||
}
|
||||
|
||||
function splitExtensions($extensions, $delimiter = ',')
|
||||
{
|
||||
$extArr = explode($delimiter, $extensions);
|
||||
$extList = '';
|
||||
|
||||
foreach ($extArr as $ext) {
|
||||
if (empty($ext)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extList .= str_replace(array('.', ' '), '', $ext) . $delimiter . ' ';
|
||||
}
|
||||
|
||||
return rtrim($extList, $delimiter . ' ');
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,282 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Ticket
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct(OGPDatabase $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function tickets($ticketsFor = null, $page = 1, $limit = 10)
|
||||
{
|
||||
$limitStart = ((int)($page - 1) * $limit);
|
||||
|
||||
$query = "SELECT a.tid, a.uid, a.user_id, a.parent_id, a.subject, a.created_at, a.last_updated, a.status, a.assigned_to
|
||||
FROM OGP_DB_PREFIXtickets a ";
|
||||
|
||||
if ($ticketsFor !== null) {
|
||||
$query .= "WHERE a.user_id = ".(int)$ticketsFor." OR a.parent_id = ".(int)$ticketsFor." ";
|
||||
|
||||
if ($this->db->isSubUser($ticketsFor)) {
|
||||
$result = $this->db->resultQuery("SELECT users_parent FROM OGP_DB_PREFIXusers WHERE user_id = ".(int)$ticketsFor);
|
||||
$query .= "OR a.parent_id = ".(int)$result[0]['users_parent']." ";
|
||||
}
|
||||
}
|
||||
|
||||
$query .= "ORDER BY a.last_updated DESC ";
|
||||
$query .= "LIMIT $limitStart, ".(int)$limit;
|
||||
|
||||
return $this->db->resultQuery($query);
|
||||
}
|
||||
|
||||
public function count($ticketsFor = null)
|
||||
{
|
||||
$query = "SELECT COUNT(1) as ticketCount FROM OGP_DB_PREFIXtickets a ";
|
||||
|
||||
if ($ticketsFor !== null) {
|
||||
$query .= "WHERE a.user_id = ".(int)$ticketsFor." OR a.parent_id = ".(int)$ticketsFor." ";
|
||||
|
||||
if ($this->db->isSubUser($ticketsFor)) {
|
||||
$result = $this->db->resultQuery("SELECT users_parent FROM OGP_DB_PREFIXusers WHERE user_id = ".(int)$ticketsFor);
|
||||
$query .= "OR a.parent_id = ".(int)$result[0]['users_parent']." ";
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return (!is_array($result) ? 0 : $result[0]['ticketCount']);
|
||||
}
|
||||
|
||||
public function notificationCount($ticketsFor = null, $status = 0)
|
||||
{
|
||||
$query = "SELECT COUNT(1) as ticketCount FROM OGP_DB_PREFIXtickets a WHERE a.status = ".(int)$status." ";
|
||||
|
||||
if ($ticketsFor !== null) {
|
||||
$query .= "AND (a.user_id = ".(int)$ticketsFor." OR a.parent_id = ".(int)$ticketsFor." ";
|
||||
|
||||
if ($this->db->isSubUser($ticketsFor)) {
|
||||
$result = $this->db->resultQuery("SELECT users_parent FROM OGP_DB_PREFIXusers WHERE user_id = ".(int)$ticketsFor);
|
||||
$query .= "OR a.parent_id = ".(int)$result[0]['users_parent'].")";
|
||||
} else {
|
||||
$query .= ")";
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return (!is_array($result) ? 0 : $result[0]['ticketCount']);
|
||||
}
|
||||
|
||||
public function getTicket($tid, $uid)
|
||||
{
|
||||
$query = "SELECT a.tid, a.uid, a.user_id, a.user_ip, a.subject, a.status, a.service_id, a.created_at, a.last_updated,
|
||||
b.users_login, b.users_fname, b.users_lname, b.users_role, b.users_email
|
||||
FROM OGP_DB_PREFIXtickets a
|
||||
JOIN OGP_DB_PREFIXusers b
|
||||
ON (a.user_id = b.user_id)
|
||||
WHERE tid = $tid
|
||||
AND uid = '".$this->db->real_escape_string($uid)."'";
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
|
||||
if (is_array($result)) {
|
||||
$ticketInfo = $result[0];
|
||||
$ticketInfo['messages'] = $this->ticketMessageArray(
|
||||
$this->getMessages($tid),
|
||||
$this->getAttachments($tid)
|
||||
);
|
||||
|
||||
return $ticketInfo;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function getMessages($tid)
|
||||
{
|
||||
$query = "SELECT a.reply_id, a.ticket_id, a.user_id, a.user_ip, a.message, a.date, a.rating, a.is_admin,
|
||||
b.user_id, b.users_login, b.users_role, b.users_fname, b.users_lname, b.users_email, b.users_parent
|
||||
FROM OGP_DB_PREFIXticket_messages a
|
||||
JOIN OGP_DB_PREFIXusers b
|
||||
ON (a.user_id = b.user_id)
|
||||
WHERE a.ticket_id = $tid
|
||||
ORDER BY a.reply_id DESC";
|
||||
|
||||
return $this->db->resultQuery($query) ?: array();
|
||||
}
|
||||
|
||||
private function getAttachments($tid)
|
||||
{
|
||||
$query = "SELECT attachment_id, reply_id, original_name, unique_name
|
||||
FROM OGP_DB_PREFIXticket_attachments
|
||||
WHERE ticket_id = $tid
|
||||
ORDER BY reply_id DESC";
|
||||
|
||||
return $this->db->resultQuery($query) ?: array();
|
||||
}
|
||||
|
||||
private function ticketMessageArray($messages, $attachments)
|
||||
{
|
||||
$keys = array_keys($messages);
|
||||
$end = end($keys);
|
||||
|
||||
$count = count(array_filter($attachments, function($f) {
|
||||
return is_null($f['reply_id']);
|
||||
}));
|
||||
|
||||
foreach ($messages as $i => $message) {
|
||||
foreach ($attachments as $k => $v) {
|
||||
|
||||
if ($messages[$i]['reply_id'] == $v['reply_id']) {
|
||||
$messages[$i]['attachments'][] = $v;
|
||||
}
|
||||
|
||||
if (is_null($v['reply_id']) && (!isset($messages[$end]['attachments']) || count($messages[$end]['attachments']) < $count)) {
|
||||
$messages[$end]['attachments'][] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
public function open($user_id, $user_ip, $subject, $message, $service_id, $is_admin)
|
||||
{
|
||||
$parent_id = $user_id;
|
||||
if ($this->db->isSubUser($user_id)) {
|
||||
$result = $this->db->resultQuery("SELECT users_parent FROM OGP_DB_PREFIXusers WHERE user_id = ".(int)$user_id);
|
||||
$parent_id = (int)$result[0]['users_parent'];
|
||||
}
|
||||
|
||||
$uid = bin2hex(openssl_random_pseudo_bytes(4));
|
||||
|
||||
// $this->db->resultInsertId calls real_escape_string on all the values.
|
||||
$fields = array(
|
||||
'uid' => $uid,
|
||||
'user_id' => $user_id,
|
||||
'parent_id' => $parent_id,
|
||||
'user_ip' => inet_pton($user_ip),
|
||||
'subject' => $subject,
|
||||
'service_id' => ($service_id === 0 ? null : (int)$service_id),
|
||||
'status' => 1
|
||||
);
|
||||
|
||||
$insertId = $this->db->resultInsertId('tickets', $fields);
|
||||
if ($insertId !== false) {
|
||||
$this->message($insertId, $user_id, $user_ip, $message, $is_admin, $uid);
|
||||
$this->updateTimestamp($insertId, $uid);
|
||||
|
||||
return array('uid' => $uid, 'tid' => $insertId);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function message($tid, $user_id, $user_ip, $message, $is_admin, $uid)
|
||||
{
|
||||
$fields = array(
|
||||
'ticket_id' => $tid,
|
||||
'user_id' => $user_id,
|
||||
'user_ip' => inet_pton($user_ip),
|
||||
'message' => $message,
|
||||
'is_admin' => ($is_admin ? '1' : '0')
|
||||
);
|
||||
|
||||
$insertId = $this->db->resultInsertId('ticket_messages', $fields);
|
||||
|
||||
if ($insertId !== false) {
|
||||
$this->updateStatus($tid, $uid, ($is_admin ? 2 : 3));
|
||||
$this->updateTimestamp($tid, $uid);
|
||||
}
|
||||
|
||||
return $insertId;
|
||||
}
|
||||
|
||||
// 0 = closed
|
||||
// 1 = open
|
||||
// 2 = admin response
|
||||
// 3 = customer response
|
||||
public function updateStatus($tid, $uid, $status)
|
||||
{
|
||||
$status = (int)$status;
|
||||
return $this->db->query("UPDATE OGP_DB_PREFIXtickets SET status = $status WHERE tid = $tid AND uid = '$uid'");
|
||||
}
|
||||
|
||||
public function updateTimestamp($tid, $uid)
|
||||
{
|
||||
return $this->db->query("UPDATE OGP_DB_PREFIXtickets SET last_updated = NOW() WHERE tid = $tid AND uid = '$uid'");
|
||||
}
|
||||
|
||||
public function exists($tid, $uid)
|
||||
{
|
||||
$query = "SELECT COUNT(1) AS ticketCount FROM OGP_DB_PREFIXtickets
|
||||
WHERE `tid` = $tid AND
|
||||
`uid` = '".$this->db->real_escape_string($uid)."'";
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return ($result[0]['ticketCount'] == 0 ? false : true);
|
||||
}
|
||||
|
||||
public function authorized($user_id, $tid, $uid)
|
||||
{
|
||||
$query = "SELECT a.user_id as utid, a.parent_id, b.user_id, b.users_parent
|
||||
FROM OGP_DB_PREFIXtickets a
|
||||
JOIN OGP_DB_PREFIXusers b
|
||||
ON (
|
||||
a.user_id = b.user_id
|
||||
OR a.user_id = b.users_parent
|
||||
OR a.parent_id = b.user_id
|
||||
OR a.parent_id = b.users_parent
|
||||
)
|
||||
WHERE a.tid = ".(int)$tid." AND a.uid = '".$this->db->real_escape_string($uid)."'
|
||||
AND (
|
||||
b.user_id = ".(int)$user_id ."
|
||||
OR b.users_parent = ".(int)$user_id."
|
||||
)";
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return $result[0] ?: false;
|
||||
}
|
||||
|
||||
public function getServices($user_id, $is_admin)
|
||||
{
|
||||
if ($is_admin) {
|
||||
$homes = $this->db->getHomesFor('admin', $user_id);
|
||||
} else {
|
||||
$homes = $this->db->getHomesFor('user_and_group', $user_id);
|
||||
}
|
||||
|
||||
$return = array(
|
||||
array('home_id' => 0, 'home_name' => '')
|
||||
);
|
||||
|
||||
if (!$homes) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
foreach ($homes as $home) {
|
||||
$return[] = array('home_id' => $home['home_id'], 'home_name' => $home['home_name']);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function setRating($tid, $reply_id, $rating)
|
||||
{
|
||||
$query = "UPDATE OGP_DB_PREFIXticket_messages
|
||||
SET rating = ".(int)$rating."
|
||||
WHERE ticket_id = ".(int)$tid." AND reply_id = ".(int)$reply_id;
|
||||
|
||||
return $this->db->query($query);
|
||||
}
|
||||
|
||||
// Move this to the attachment class...?
|
||||
public function getAttachmentById($attachment_id, $tid)
|
||||
{
|
||||
$query = "SELECT original_name, unique_name FROM OGP_DB_PREFIXticket_attachments
|
||||
WHERE attachment_id = ".(int)$attachment_id." AND ticket_id = ".(int)$tid;
|
||||
|
||||
$result = $this->db->resultQuery($query);
|
||||
return $result[0] ?: false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue