migrate ticket-system to PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-06 11:06:03 +01:00
parent 8a9ed3d9f1
commit 74bb3ccb7e
5 changed files with 329 additions and 319 deletions

View File

@@ -37,8 +37,7 @@ if (isset($_POST['id'])) {
SELECT `id` FROM `panel_tickets`
WHERE `id` = :id AND `adminid` = :adminid
");
Database::pexecute($stmt, array('id' => $id, 'adminid' => $userinfo['adminid']));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$result = Database::pexecute_first($stmt, array('id' => $id, 'adminid' => $userinfo['adminid']));
if ($result == null) {
// no rights to see the requested ticket
@@ -57,8 +56,7 @@ if ($page == 'tickets'
FROM `" . TABLE_PANEL_CUSTOMERS . "` " .
($userinfo['customers_see_all'] ? '' : "WHERE `adminid` = :adminid")
);
Database::pexecute($countcustomers_stmt, array('adminid' => $userinfo['adminid']));
$countcustomers = $countcustomers_stmt->fetch(PDO::FETCH_ASSOC);
$countcustomers = Database::pexecute_first($countcustomers_stmt, array('adminid' => $userinfo['adminid']));
$countcustomers = (int)$countcustomers['countcustomers'];
if ($action == '') {
@@ -130,8 +128,7 @@ if ($page == 'tickets'
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
if (isset($usr['loginname'])) {
$customer = getCorrectFullUserDetails($usr);
@@ -186,7 +183,7 @@ if ($page == 'tickets'
if (isset($_POST['send'])
&& $_POST['send'] == 'send'
) {
$newticket = ticket::getInstanceOf($userinfo, $db, $settings, -1);
$newticket = ticket::getInstanceOf($userinfo, $settings, -1);
$newticket->Set('subject', validate($_POST['subject'], 'subject'), true, false);
$newticket->Set('priority', validate($_POST['priority'], 'priority'), true, false);
$newticket->Set('category', validate($_POST['category'], 'category'), true, false);
@@ -221,8 +218,7 @@ if ($page == 'tickets'
SELECT `id`, `name` FROM `' . TABLE_PANEL_TICKET_CATS . '`
'.$where.' ORDER BY `logicalorder`, `name` ASC'
);
Database::pexecute($result_stmt, array('adminid' => $userinfo['adminid']));
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
$result = Database::pexecute_first($result_stmt, array('adminid' => $userinfo['adminid']));
if (isset($result['name'])
&& $result['name'] != ''
@@ -278,7 +274,7 @@ if ($page == 'tickets'
&& $_POST['send'] == 'send'
) {
$replyticket = ticket::getInstanceOf($userinfo, $db, $settings, -1);
$replyticket = ticket::getInstanceOf($userinfo, $settings, -1);
$replyticket->Set('subject', validate($_POST['subject'], 'subject'), true, false);
$replyticket->Set('priority', validate($_POST['priority'], 'priority'), true, false);
$replyticket->Set('message', validate(htmlentities(str_replace("\r\n", "\n", $_POST['message'])), 'message', '/^[^\0]*$/'), true, false);
@@ -287,7 +283,7 @@ if ($page == 'tickets'
standard_error(array('stringisempty', 'mymessage'));
} else {
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$replyticket->Set('customerid', $mainticket->Get('customer'), true, true);
$replyticket->Set('lastchange', $now, true, true);
$replyticket->Set('ip', $_SERVER['REMOTE_ADDR'], true, true);
@@ -313,7 +309,7 @@ if ($page == 'tickets'
} else {
$ticket_replies = '';
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$dt = date("d.m.Y H:i\h", $mainticket->Get('dt'));
$status = ticket::getStatusText($lng, $mainticket->Get('status'));
@@ -334,8 +330,7 @@ if ($page == 'tickets'
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
$by = '<a href="'.$linker->getLink(array('section' => 'customers', 'page' => 'customers', 'action' => 'su', 'id' => $cid)).'" rel="external">';
$by .= getCorrectFullUserDetails($usr).'</a>';
}
@@ -347,8 +342,7 @@ if ($page == 'tickets'
$result_stmt = Database::prepare('
SELECT `name` FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = :cid'
);
Database::pexecute($result_stmt, array('cid' => $mainticket->Get('category')));
$row = $result_stmt->fetch(PDO::FETCH_ASSOC);
$row = Database::pexecute_first($result_stmt, array('cid' => $mainticket->Get('category')));
$andere_stmt = Database::prepare('
SELECT * FROM `' . TABLE_PANEL_TICKETS . '`
@@ -359,7 +353,7 @@ if ($page == 'tickets'
while ($row2 = $andere_stmt->fetch(PDO::FETCH_ASSOC)) {
$subticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$row2['id']);
$subticket = ticket::getInstanceOf($userinfo, $settings, (int)$row2['id']);
$lastchange = date("d.m.Y H:i\h", $subticket->Get('lastchange'));
if ($subticket->Get('by') == '1') {
@@ -371,8 +365,7 @@ if ($page == 'tickets'
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
$by = '<a href="'.$linker->getLink(array('section' => 'customers', 'page' => 'customers', 'action' => 'su', 'id' => $cid)).'" rel="external">';
$by .= getCorrectFullUserDetails($usr).'</a>';
}
@@ -405,15 +398,15 @@ if ($page == 'tickets'
&& $_POST['send'] == 'send'
) {
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '1', true, true);
$mainticket->Set('status', '3', true, true);
$mainticket->Update();
$log->logAction(ADM_ACTION, LOG_NOTICE, "closed ticket '" . $mainticket->Get('subject') . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} else {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
ask_yesno('ticket_reallyclose', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject'));
}
@@ -421,13 +414,13 @@ if ($page == 'tickets'
&& $id != 0
) {
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '1', true, true);
$mainticket->Set('status', '0', true, true);
$mainticket->Update();
$log->logAction(ADM_ACTION, LOG_NOTICE, "reopened ticket '" . $mainticket->Get('subject') . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} elseif($action == 'archive'
&& $id != 0
@@ -436,16 +429,16 @@ if ($page == 'tickets'
&& $_POST['send'] == 'send'
) {
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '1', true, true);
$mainticket->Set('status', '3', true, true);
$mainticket->Update();
$mainticket->Archive();
$log->logAction(ADM_ACTION, LOG_NOTICE, "archived ticket '" . $mainticket->Get('subject') . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} else {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
ask_yesno('ticket_reallyarchive', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject'));
}
@@ -455,12 +448,12 @@ if ($page == 'tickets'
if (isset($_POST['send'])
&& $_POST['send'] == 'send'
) {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$log->logAction(ADM_ACTION, LOG_INFO, "deleted ticket '" . $mainticket->Get('subject') . "'");
$mainticket->Delete();
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} else {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
ask_yesno('ticket_reallydelete', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject'));
}
}
@@ -533,18 +526,18 @@ if ($page == 'tickets'
if ($order < 1 || $order >= 1000) {
// use the latest available
$order = ticket::getHighestOrderNumber($db, $userinfo['adminid']) + 1;
$order = ticket::getHighestOrderNumber($userinfo['adminid']) + 1;
}
if ($category == '') {
standard_error(array('stringisempty', 'mycategory'));
} else {
ticket::addCategory($db, $category, $userinfo['adminid'], $order);
ticket::addCategory($category, $userinfo['adminid'], $order);
$log->logAction(ADM_ACTION, LOG_INFO, "added ticket-category '" . $category . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
}
} else {
$order = ticket::getHighestOrderNumber($db, $userinfo['adminid']) + 1;
$order = ticket::getHighestOrderNumber($userinfo['adminid']) + 1;
$category_new_data = include_once dirname(__FILE__).'/lib/formfields/admin/tickets/formfield.category_new.php';
$category_new_form = htmlform::genHTMLForm($category_new_data);
@@ -572,16 +565,15 @@ if ($page == 'tickets'
if ($category == '') {
standard_error(array('stringisempty', 'mycategory'));
} else {
ticket::editCategory($db, $category, $id, $order);
ticket::editCategory($category, $id, $order);
$log->logAction(ADM_ACTION, LOG_INFO, "edited ticket-category '" . $category . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
}
} else {
$row_stmt = Database::prepare('
SELECT * FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = :id'
);
Database::pexecute($row_stmt, array('id' => $id));
$row = $row_stmt->fetch(PDO::FETCH_ASSOC);
$row = Database::pexecute_first($row_stmt, array('id' => $id));
$category_edit_data = include_once dirname(__FILE__).'/lib/formfields/admin/tickets/formfield.category_edit.php';
$category_edit_form = htmlform::genHTMLForm($category_edit_data);
@@ -597,15 +589,15 @@ if ($page == 'tickets'
if (isset($_POST['send'])
&& $_POST['send'] == 'send'
) {
if (ticket::deleteCategory($db, $id) == false) {
if (ticket::deleteCategory($id) == false) {
standard_error('categoryhastickets');
}
$log->logAction(ADM_ACTION, LOG_INFO, "deleted ticket-category #" . $id);
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} else {
$name = ticket::getCategoryName($db, $id);
$name = ticket::getCategoryName($id);
ask_yesno('ticket_reallydeletecat', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $name);
}
}
@@ -697,8 +689,7 @@ if ($page == 'tickets'
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
if (isset($usr['loginname'])) {
$customer = getCorrectFullUserDetails($usr);
@@ -745,7 +736,7 @@ if ($page == 'tickets'
} else {
$archived = array();
$archived = ticket::getLastArchived($db, 6, $userinfo['adminid']);
$archived = ticket::getLastArchived(6, $userinfo['adminid']);
$tickets = '';
if ($archived !== false) {
@@ -800,27 +791,22 @@ if ($page == 'tickets'
) {
$log->logAction(ADM_ACTION, LOG_NOTICE, "viewed archived-ticket #" . $id);
$ticket_replies = '';
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$lastchange = date("d.m.Y H:i\h", $mainticket->Get('lastchange'));
$dt = date("d.m.Y H:i\h", $mainticket->Get('dt'));
$status = ticket::getStatusText($lng, $mainticket->Get('status'));
$isclosed = 1;
if($mainticket->Get('by') == '1')
{
if ($mainticket->Get('by') == '1') {
$by = $lng['ticket']['staff'];
}
else
{
} else {
$cid = $mainticket->Get('customer');
$usr_stmt = Database::prepare('
SELECT `customerid`, `firstname`, `name`, `company`, `loginname`
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
$by = '<a href="'.$linker->getLink(array('section' => 'customers', 'page' => 'customers', 'action' => 'su', 'id' => $cid)).'" rel="external">';
$by .= getCorrectFullUserDetails($usr).'</a>';
}
@@ -832,8 +818,7 @@ if ($page == 'tickets'
$result_stmt = Database::prepare('
SELECT `name` FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = :cid'
);
Database::pexecute($result_stmt, array('cid' => $mainticket->Get('category')));
$row = $result_stmt->fetch(PDO::FETCH_ASSOC);
$row = Database::pexecute_first($result_stmt, array('cid' => $mainticket->Get('category')));
$andere_stmt = Database::prepare('
SELECT * FROM `' . TABLE_PANEL_TICKETS . '` WHERE `answerto` = :id'
@@ -843,7 +828,7 @@ if ($page == 'tickets'
while ($row2 = $andere_stmt->fetch(PDO::FETCH_ASSOC)) {
$subticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$row2['id']);
$subticket = ticket::getInstanceOf($userinfo, $settings, (int)$row2['id']);
$lastchange = date("d.m.Y H:i\h", $subticket->Get('lastchange'));
if ($subticket->Get('by') == '1') {
@@ -855,9 +840,7 @@ if ($page == 'tickets'
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :cid'
);
Database::pexecute($usr_stmt, array('cid' => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array('cid' => $cid));
$by = '<a href="'.$linker->getLink(array('section' => 'customers', 'page' => 'customers', 'action' => 'su', 'id' => $cid)).'" rel="external">';
$by .= getCorrectFullUserDetails($usr).'</a>';
}
@@ -882,12 +865,12 @@ if ($page == 'tickets'
if (isset($_POST['send'])
&& $_POST['send'] == 'send'
) {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$log->logAction(ADM_ACTION, LOG_INFO, "deleted archived ticket '" . $mainticket->Get('subject') . "'");
$mainticket->Delete();
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
} else {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
ask_yesno('ticket_reallydelete', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject'));
}
}

View File

@@ -18,22 +18,18 @@
*/
define('AREA', 'customer');
/**
* Include our init.php, which manages Sessions, Language etc.
*/
require ("./lib/init.php");
if(isset($_POST['id'])) {
if (isset($_POST['id'])) {
$id = intval($_POST['id']);
/*
* Check if the current user is allowed to see the current ticket.
*/
$stmt = Database::prepare("SELECT `id` FROM `panel_tickets` WHERE `id` = :id AND `customerid` = :customerid");
Database::pexecute($stmt, array("id" => $id, "customerid" => $userinfo['customerid']));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$result = Database::pexecute_first($stmt, array("id" => $id, "customerid" => $userinfo['customerid']));
if ($result == null) {
// no rights to see the requested ticket
standard_error(array('ticketnotaccessible'));
@@ -141,8 +137,7 @@ if($page == 'overview') {
AND `answerto` = "0"
AND (`status` = "0" OR `status` = "1" OR `status` = "2")'
);
Database::pexecute($stmt, array("customerid" => $userinfo['customerid']));
$opentickets = $stmt->fetch(PDO::FETCH_ASSOC);
$opentickets = Database::pexecute_first($stmt, array("customerid" => $userinfo['customerid']));
if($settings['ticket']['concurrently_open'] != - 1 && $settings['ticket']['concurrently_open'] != '') {
$notmorethanxopentickets = strtr($lng['ticket']['notmorethanxopentickets'], array('%s' => $settings['ticket']['concurrently_open']));
@@ -152,10 +147,11 @@ if($page == 'overview') {
$ticketsopen = (int)$opentickets['count'];
eval("echo \"" . getTemplate("tickets/tickets") . "\";");
} elseif($action == 'new') {
if($userinfo['tickets_used'] < $userinfo['tickets'] || $userinfo['tickets'] == '-1') {
if(isset($_POST['send']) && $_POST['send'] == 'send') {
$newticket = ticket::getInstanceOf($userinfo, $db, $settings, -1);
$newticket = ticket::getInstanceOf($userinfo, $settings, -1);
$newticket->Set('subject', validate($_POST['subject'], 'subject'), true, false);
$newticket->Set('priority', validate($_POST['priority'], 'priority'), true, false);
$newticket->Set('category', validate($_POST['category'], 'category'), true, false);
@@ -185,11 +181,9 @@ if($page == 'overview') {
Database::pexecute($stmt, array("customerid" => $userinfo['customerid']));
// Customer mail
$newticket->sendMail((int)$userinfo['customerid'], 'new_ticket_for_customer_subject', $lng['mails']['new_ticket_for_customer']['subject'], 'new_ticket_for_customer_mailbody', $lng['mails']['new_ticket_for_customer']['mailbody']);
// Admin mail
$newticket->sendMail(-1, 'new_ticket_by_customer_subject', $lng['mails']['new_ticket_by_customer']['subject'], 'new_ticket_by_customer_mailbody', $lng['mails']['new_ticket_by_customer']['mailbody']);
redirectTo($filename, Array('page' => $page, 's' => $s));
}
@@ -199,10 +193,9 @@ if($page == 'overview') {
WHERE `adminid` = :adminid
ORDER BY `logicalorder`, `name` ASC'
);
Database::pexecute($result_stmt, array("adminid" => $userinfo['adminid']));
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
$result = Database::pexecute_first($result_stmt, array("adminid" => $userinfo['adminid']));
if(isset($result['name']) && $result['name'] != '') {
if (isset($result['name']) && $result['name'] != '') {
$result2_stmt = Database::prepare('SELECT `id`, `name` FROM `' . TABLE_PANEL_TICKET_CATS . '`
WHERE `adminid` = :adminid
ORDER BY `logicalorder`, `name` ASC'
@@ -225,10 +218,11 @@ if($page == 'overview') {
AND `answerto` = "0"
AND (`status` = "0" OR `status` = "1" OR `status` = "2")'
);
Database::pexecute($opentickets_stmt, array("customerid" => $userinfo['customerid']));
$opentickets = $opentickets_stmt->fetch(PDO::FETCH_ASSOC);
$opentickets = Database::pexecute_first($opentickets_stmt, array("customerid" => $userinfo['customerid']));
if($settings['ticket']['concurrently_open'] != - 1 && $settings['ticket']['concurrently_open'] != '') {
if ($settings['ticket']['concurrently_open'] != - 1
&& $settings['ticket']['concurrently_open'] != ''
) {
$notmorethanxopentickets = strtr($lng['ticket']['notmorethanxopentickets'], array('%s' => $settings['ticket']['concurrently_open']));
} else {
$notmorethanxopentickets = '';
@@ -249,7 +243,7 @@ if($page == 'overview') {
}
} elseif($action == 'answer' && $id != 0) {
if(isset($_POST['send']) && $_POST['send'] == 'send') {
$replyticket = ticket::getInstanceOf($userinfo, $db, $settings, -1);
$replyticket = ticket::getInstanceOf($userinfo, $settings, -1);
$replyticket->Set('subject', validate($_POST['subject'], 'subject'), true, false);
$replyticket->Set('priority', validate($_POST['priority'], 'priority'), true, false);
$replyticket->Set('message', validate(str_replace("\r\n", "\n", $_POST['message']), 'message', '/^[^\0]*$/'), true, false);
@@ -267,8 +261,7 @@ if($page == 'overview') {
$replyticket->Insert();
// Update priority if changed
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
if($replyticket->Get('priority') != $mainticket->Get('priority')) {
$mainticket->Set('priority', $replyticket->Get('priority'), true);
@@ -284,7 +277,7 @@ if($page == 'overview') {
}
} else {
$ticket_replies = '';
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$dt = date("d.m.Y H:i\h", $mainticket->Get('dt'));
$status = ticket::getStatusText($lng, $mainticket->Get('status'));
@@ -302,10 +295,8 @@ if($page == 'overview') {
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = :customerid '
);
Database::pexecute($usr_stmt, array("customerid" => $cid));
$usr = $usr_stmt->fetch(PDO::FETCH_ASSOC);
$usr = Database::pexecute_first($usr_stmt, array("customerid" => $cid));
$by = getCorrectFullUserDetails($usr);
//$by = $lng['ticket']['customer'];
}
$subject = $mainticket->Get('subject');
@@ -314,24 +305,23 @@ if($page == 'overview') {
$result_stmt = Database::prepare('SELECT `name` FROM `' . TABLE_PANEL_TICKET_CATS . '`
WHERE `id`= :id '
);
Database::pexecute($result_stmt, array("id" => $mainticket->Get('category')));
$row = $result_stmt->fetch(PDO::FETCH_ASSOC);
$row = Database::pexecute_first($result_stmt, array("id" => $mainticket->Get('category')));
$andere_stmt = Database::prepare('SELECT * FROM `' . TABLE_PANEL_TICKETS . '`
WHERE `answerto`= :answerto
ORDER BY `lastchange` ASC'
);
Database::pexecute($andere_stmt, array("answerto" => $id));
$numrows_andere = Database::num_rows();
while($row2 = $andere_stmt->fetch(PDO::FETCH_ASSOC)) {
$subticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$row2['id']);
$subticket = ticket::getInstanceOf($userinfo, $settings, (int)$row2['id']);
$lastchange = date("d.m.Y H:i\h", $subticket->Get('lastchange'));
if($subticket->Get('by') == '1') {
$by = $lng['ticket']['staff'];
} else {
$by = getCorrectFullUserDetails($usr);
//$by = $lng['ticket']['customer'];
}
$subject = $subticket->Get('subject');
@@ -343,10 +333,9 @@ if($page == 'overview') {
$priorities.= makeoption($lng['ticket']['normal'], '2', $mainticket->Get('priority'), true, true);
$priorities.= makeoption($lng['ticket']['low'], '3', $mainticket->Get('priority'), true, true);
$subject = $mainticket->Get('subject');
$ticket_replies_count = $db->num_rows($andere) + 1;
$ticket_replies_count = $numrows_andere + 1;
// don't forget the main-ticket!
$ticket_reply_data = include_once dirname(__FILE__).'/lib/formfields/customer/tickets/formfield.ticket_reply.php';
$ticket_reply_form = htmlform::genHTMLForm($ticket_reply_data);
@@ -358,7 +347,7 @@ if($page == 'overview') {
} elseif($action == 'close' && $id != 0) {
if(isset($_POST['send']) && $_POST['send'] == 'send') {
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '0', true, true);
$mainticket->Set('status', '3', true, true);
@@ -366,7 +355,7 @@ if($page == 'overview') {
$log->logAction(USR_ACTION, LOG_NOTICE, "closed support-ticket '" . $mainticket->Get('subject') . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
} else {
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
ask_yesno('ticket_reallyclose', $filename, array('id' => $id, 'page' => $page, 'action' => $action), $mainticket->Get('subject'));
}
} elseif($action == 'reopen' && $id != 0) {
@@ -376,8 +365,7 @@ if($page == 'overview') {
AND `answerto` = "0"
AND (`status` = "0" OR `status` = "1" OR `status` = "2")'
);
Database::pexecute($opentickets_stmt, array("customerid" => $userinfo['customerid']));
$opentickets = $opentickets_stmt->fetch(PDO::FETCH_ASSOC);
$opentickets = Database::pexecute_first($opentickets_stmt, array("customerid" => $userinfo['customerid']));
$ticketsopen = (int)$opentickets['count'];
if($ticketsopen > $settings['ticket']['concurrently_open'] && $settings['ticket']['concurrently_open'] != - 1 && $settings['ticket']['concurrently_open'] != '') {
@@ -385,14 +373,12 @@ if($page == 'overview') {
}
$now = time();
$mainticket = ticket::getInstanceOf($userinfo, $db, $settings, (int)$id);
$mainticket = ticket::getInstanceOf($userinfo, $settings, (int)$id);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '0', true, true);
$mainticket->Set('status', '0', true, true);
$mainticket->Update();
$log->logAction(USR_ACTION, LOG_NOTICE, "reopened support-ticket '" . $mainticket->Get('subject') . "'");
redirectTo($filename, Array('page' => $page, 's' => $s));
redirectTo($filename, array('page' => $page, 's' => $s));
}
}
?>

View File

@@ -20,20 +20,14 @@
* Support Tickets - Tickets-Class
*/
class ticket
{
class ticket {
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Database handler
* @var db
*/
private $db = false;
/**
* Settings array
* @var settings
@@ -68,14 +62,11 @@ class ticket
* Class constructor.
*
* @param array userinfo
* @param resource database
* @param array settings
* @param int ticket id
*/
private function __construct($userinfo, $db, $settings, $tid = - 1)
{
private function __construct($userinfo, $settings, $tid = - 1) {
$this->userinfo = $userinfo;
$this->db = $db;
$this->settings = $settings;
$this->tid = $tid;
@@ -96,23 +87,22 @@ class ticket
/**
* Singleton ftw ;-)
*
* @param array userinfo
* @param array settings
* @param int ticket id
*/
static public function getInstanceOf($_usernfo, $_db, $_settings, $_tid)
{
if(!isset(self::$tickets[$_tid]))
{
self::$tickets[$_tid] = new ticket($_usernfo, $_db, $_settings, $_tid);
static public function getInstanceOf($_usernfo, $_settings, $_tid) {
if (!isset(self::$tickets[$_tid])) {
self::$tickets[$_tid] = new ticket($_usernfo, $_settings, $_tid);
}
return self::$tickets[$_tid];
}
/**
* Initialize data-array
*/
private function initData()
{
private function initData() {
$this->Set('customer', 0, true, true);
$this->Set('admin', 1, true, true);
$this->Set('subject', '', true, true);
@@ -132,12 +122,16 @@ class ticket
/**
* Read ticket data from database.
*/
private function readData()
{
if(isset($this->tid)
&& $this->tid != - 1)
{
$_ticket = $this->db->query_first('SELECT * FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = "' . $this->tid . '"');
private function readData() {
if (isset($this->tid)
&& $this->tid != - 1
) {
$_ticket_stmt = Database::prepare('
SELECT * FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = :tid'
);
$_ticket = Database::pexecute_first($_ticket_stmt, array('tid' => $this->tid));
$this->Set('customer', $_ticket['customerid'], true, false);
$this->Set('admin', $_ticket['adminid'], true, false);
$this->Set('subject', $_ticket['subject'], true, false);
@@ -158,79 +152,104 @@ class ticket
/**
* Insert data to database
*/
public function Insert()
{
$this->db->query("INSERT INTO `" . TABLE_PANEL_TICKETS . "`
(`customerid`,
`adminid`,
`category`,
`priority`,
`subject`,
`message`,
`dt`,
`lastchange`,
`ip`,
`status`,
`lastreplier`,
`by`,
`answerto`)
VALUES
('" . (int)$this->Get('customer') . "',
'" . (int)$this->Get('admin') . "',
'" . (int)$this->Get('category') . "',
'" . (int)$this->Get('priority') . "',
'" . $this->db->escape($this->Get('subject')) . "',
'" . $this->db->escape($this->Get('message')) . "',
'" . (int)$this->Get('dt') . "',
'" . (int)$this->Get('lastchange') . "',
'" . $this->db->escape($this->Get('ip')) . "',
'" . (int)$this->Get('status') . "',
'" . (int)$this->Get('lastreplier') . "',
'" . (int)$this->Get('by') . "',
'" . (int)$this->Get('answerto') . "');");
$this->tid = $this->db->insert_id();
public function Insert() {
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TICKETS . "` SET
`customerid` = :customerid,
`adminid` = :adminid,
`category` = :category,
`priority` = :priority,
`subject` = :subject,
`message` = :message,
`dt` = :dt,
`lastchange` = :lastchange,
`ip` = :ip,
`status` = :status,
`lastreplier` = :lastreplier,
`by` = :by,
`answerto` = :answerto"
);
$ins_data = array(
'customerid' => $this->Get('customer'),
'adminid' => $this->Get('admin'),
'category' => $this->Get('category'),
'priority' => $this->Get('priority'),
'subject' => $this->Get('subject'),
'message' => $this->Get('message'),
'dt' => $this->Get('dt'),
'lastchange' => $this->Get('lastchange'),
'ip' => $this->Get('ip'),
'status' => $this->Get('status'),
'lastreplier' => $this->Get('lastreplier'),
'by' => $this->Get('by'),
'answerto' => $this->Get('answerto')
);
Database::pexecute($ins_stmt, $ins_data);
$this->tid = Database::lastInsertId();
return true;
}
/**
* Update data in database
*/
public function Update()
{
// Update "main" ticket
public function Update() {
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET
`priority` = "' . (int)$this->Get('priority') . '",
`lastchange` = "' . (int)$this->Get('lastchange') . '",
`status` = "' . (int)$this->Get('status') . '",
`lastreplier` = "' . (int)$this->Get('lastreplier') . '"
WHERE `id` = "' . (int)$this->tid . '";');
// Update "main" ticket
$upd_stmt = Database::prepare('
UPDATE `' . TABLE_PANEL_TICKETS . '` SET
`priority` = :priority,
`lastchange` = :lastchange,
`status` = :status,
`lastreplier` = :lastreplier
WHERE `id` = :tid'
);
$upd_data = array(
'priority' => $this->Get('priority'),
'lastchange' => $this->Get('lastchange'),
'status' => $this->Get('status'),
'lastreplier' => $this->Get('lastreplier'),
'tid' => $this->tid
);
Database::pexecute($upd_stmt, $upd_data);
return true;
}
/**
* Moves a ticket to the archive
*/
public function Archive()
{
public function Archive() {
// Update "main" ticket
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `id` = "' . (int)$this->tid . '";');
$upd_stmt = Database::prepare('
UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `id` = :tid'
);
Database::pexecute($upd_stmt, array('tid' => $this->tid));
// Update "answers" to ticket
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `answerto` = "' . (int)$this->tid . '";');
$upd_stmt = Database::prepare('
UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `answerto` = :tid'
);
Database::pexecute($upd_stmt, array('tid' => $this->tid));
return true;
}
/**
* Remove ticket from database
*/
public function Delete()
{
public function Delete() {
// Delete "main" ticket
$this->db->query('DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = "' . (int)$this->tid . '";');
$del_stmt = Database::prepare('
DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = :tid'
);
Database::pexecute($del_stmt, array('tid' => $this->tid));
// Delete "answers" to ticket"
$this->db->query('DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `answerto` = "' . (int)$this->tid . '";');
$del_stmt = Database::prepare('
DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `answerto` = :tid'
);
Database::pexecute($del_stmt, array('tid' => $this->tid));
return true;
}
@@ -242,12 +261,14 @@ class ticket
global $mail, $theme;
// Some checks are to be made here in the future
if($customerid != - 1)
{
if ($customerid != - 1) {
// Get e-mail message for customer
$usr = $this->db->query_first('SELECT `name`, `firstname`, `company`, `email`
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = "' . (int)$customerid . '"');
$usr_stmt = Database::prepare('
SELECT `name`, `firstname`, `company`, `email`
FROM `' . TABLE_PANEL_CUSTOMERS . '` WHERE `customerid` = :customerid'
);
$usr = Database::pexecute_first($usr_stmt, array('customerid' => $customerid));
$replace_arr = array(
'FIRSTNAME' => $usr['firstname'],
'NAME' => $usr['name'],
@@ -255,29 +276,38 @@ class ticket
'SALUTATION' => getCorrectUserSalutation($usr),
'SUBJECT' => $this->Get('subject', true)
);
}
else
{
} else {
$replace_arr = array(
'SUBJECT' => $this->Get('subject', true)
);
}
$result = $this->db->query_first('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '`
WHERE `adminid`=\'' . (int)$this->userinfo['adminid'] . '\'
AND `language`=\'' . $this->db->escape($this->userinfo['def_language']) . '\'
AND `templategroup`=\'mails\'
AND `varname`=\'' . $template_subject . '\'');
$tpl_seldata = array(
'adminid' => $this->userinfo['adminid'],
'lang' => $this->userinfo['def_language'],
'tplsubject' => $template_subject
);
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid`= :adminid
AND `language`= :lang
AND `templategroup`= 'mails' AND `varname`= :tplsubject"
);
$result = Database::pexecute_first($result_stmt, $tpl_seldata);
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default_subject), $replace_arr));
$result = $this->db->query_first('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '`
WHERE `adminid`=\'' . (int)$this->userinfo['adminid'] . '\'
AND `language`=\'' . $this->db->escape($this->userinfo['def_language']) . '\'
AND `templategroup`=\'mails\'
AND `varname`=\'' . $template_body . '\'');
unset($tpl_seldata['tplsubject']);
$tpl_seldata['tplbody'] = $template_body;
$result_stmt = Database::prepare("
SELECT `value` FROM `" . TABLE_PANEL_TEMPLATES . "`
WHERE `adminid`= :adminid
AND `language`= :lang
AND `templategroup`= 'mails' AND `varname`= :tplmailbody"
);
$result = Database::pexecute_first($result_stmt, $tpl_seldata);
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default_body), $replace_arr));
if($customerid != - 1)
{
if ($customerid != - 1) {
$_mailerror = false;
try {
$mail->SetFrom($this->settings['ticket']['noreply_email'], $this->settings['ticket']['noreply_name']);
@@ -299,13 +329,15 @@ class ticket
$rstlog->logAction(ADM_ACTION, LOG_ERR, "Error sending mail: " . $mailerr_msg);
standard_error('errorsendingmail', $usr['email']);
}
$mail->ClearAddresses();
}
else
{
$admin = $this->db->query_first("SELECT `name`, `email` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid`='" . (int)$this->userinfo['adminid'] . "'");
} else {
$admin_stmt = Database::prepare("
SELECT `name`, `email` FROM `" . TABLE_PANEL_ADMINS . "`
WHERE `adminid` = :adminid"
);
$admin = Database::pexecute_first($admin_stmt, array('adminid' => $userinfo['adminid']));
$_mailerror = false;
try {
$mail->SetFrom($this->settings['ticket']['noreply_email'], $this->settings['ticket']['noreply_name']);
@@ -335,65 +367,77 @@ class ticket
/**
* Add a support-categories
*/
static public function addCategory($_db, $_category = null, $_admin = 1, $_order = 1)
{
if($_category != null
&& $_category != '')
{
if($_order < 1) {
static public function addCategory($_category = null, $_admin = 1, $_order = 1) {
if ($_category != null
&& $_category != ''
) {
if ($_order < 1) {
$_order = 1;
}
$_db->query('INSERT INTO `' . TABLE_PANEL_TICKET_CATS . '` SET
`name` = "' . $_db->escape($_category) . '",
`adminid` = "' . (int)$_admin . '",
`logicalorder` = "' . (int)$_order . '"');
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_TICKET_CATS . "` SET
`name` = :name,
`adminid` = :adminid,
`logicalorder` = :lo"
);
$ins_data = array(
'name' => $_category,
'adminid' => $_admin,
'lo' => $_order
);
Database::pexecute($ins_stmt, $ins_data);
return true;
}
return false;
}
/**
* Edit a support-categories
*/
static public function editCategory($_db, $_category = null, $_id = 0, $_order = 1)
{
if($_category != null
&& $_category != ''
&& $_id != 0)
{
if($_order < 1) {
static public function editCategory($_category = null, $_id = 0, $_order = 1) {
if ($_category != null
&& $_category != ''
&& $_id != 0
) {
if ($_order < 1) {
$_order = 1;
}
$_db->query('UPDATE `' . TABLE_PANEL_TICKET_CATS . '` SET
`name` = "' . $_db->escape($_category) . '",
`logicalorder` = "' . (int)$_order . '"
WHERE `id` = "' . (int)$_id . '"');
$upd_stmt = Database::prepare("
UPDATE `' . TABLE_PANEL_TICKET_CATS . '` SET
`name` = :name,
`logicalorder` = :lo
WHERE `id` = :id"
);
Database::pexecute($upd_stmt, array('name' => $_category, 'lo' => $_order, 'id' => $_id));
return true;
}
return false;
}
/**
* Delete a support-categories
*/
static public function deleteCategory($_db, $_id = 0)
{
if($_id != 0)
{
$result = $_db->query_first('SELECT COUNT(`id`) as `numtickets` FROM `' . TABLE_PANEL_TICKETS . '`
WHERE `category` = "' . (int)$_id . '"');
static public function deleteCategory($_id = 0) {
if($result['numtickets'] == "0")
{
$_db->query('DELETE FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = "' . (int)$_id . '"');
if ($_id != 0) {
$result_stmt = Database::prepare("
SELECT COUNT(`id`) as `numtickets` FROM `" . TABLE_PANEL_TICKETS . "`
WHERE `category` = :cat"
);
$result = Database::pexecute_first($result_stmt, array('cat' => $_id));
if ($result['numtickets'] == "0") {
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_TICKET_CATS . "` WHERE `id` = :id"
);
Database::pexecute($del_stmt, array('id' => $_id));
return true;
}
else
{
} else {
return false;
}
}
@@ -404,55 +448,63 @@ class ticket
/**
* Return a support-category-name
*/
static public function getCategoryName($_db, $_id = 0)
{
if($_id != 0)
{
$category = $_db->query_first('SELECT `name` FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = "' . (int)$_id . '"');
static public function getCategoryName($_id = 0) {
if ($_id != 0) {
$stmt = Database::prepare("
SELECT `name` FROM `" . TABLE_PANEL_TICKET_CATS . "` WHERE `id` = :id"
);
$category = Database::pexecute_first($stmt, array('id' => $_id));
return $category['name'];
}
return null;
}
/**
* get the highest order number
*
* @param object $_db database-object
* @param object $_uid admin-id (optional)
*
* @return int highest order number
*/
static public function getHighestOrderNumber($_db = null, $_uid = 0)
{
static public function getHighestOrderNumber($_uid = 0) {
$where = '';
$sel_data = array();
if ($_uid > 0) {
$where = ' WHERE `adminid` = "'.(int)$_uid.'"';
$where = " WHERE `adminid` = :adminid";
$sel_data['adminid'] = $_uid;
}
$sql = "SELECT MAX(`logicalorder`) as `highestorder` FROM `" . TABLE_PANEL_TICKET_CATS . "`".$where.";";
$result = $_db->query_first($sql);
$result_stmt = Database::prepare($sql);
$result = Database::pexecute_first($result_stmt, $sel_data);
return (isset($result['highestorder']) ? (int)$result['highestorder'] : 0);
}
/**
* returns the last x archived tickets
*/
static public function getLastArchived($_db, $_num = 10, $_admin = 1)
{
if($_num > 0)
{
static public function getLastArchived($_num = 10, $_admin = 1) {
if ($_num > 0) {
$archived = array();
$counter = 0;
$result = $_db->query('SELECT *,
(SELECT COUNT(`sub`.`id`)
FROM `' . TABLE_PANEL_TICKETS . '` `sub`
WHERE `sub`.`answerto` = `main`.`id`) as `ticket_answers`
FROM `' . TABLE_PANEL_TICKETS . '` `main`
WHERE `main`.`answerto` = "0"
AND `main`.`archived` = "1" AND `main`.`adminid` = "' . (int)$_admin . '"
ORDER BY `main`.`lastchange` DESC LIMIT 0, ' . (int)$_num);
$result_stmt = Database::prepare("
SELECT *, (
SELECT COUNT(`sub`.`id`)
FROM `" . TABLE_PANEL_TICKETS . "` `sub`
WHERE `sub`.`answerto` = `main`.`id`
) as `ticket_answers`
FROM `" . TABLE_PANEL_TICKETS . "` `main`
WHERE `main`.`answerto` = '0' AND `main`.`archived` = '1'
AND `main`.`adminid` = :adminid
ORDER BY `main`.`lastchange` DESC LIMIT 0, :limit"
);
Database::pexecute($result_stmt, array('adminid' => $_admin, 'limit' => $_num));
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
while($row = $_db->fetch_array($result))
{
$archived[$counter]['id'] = $row['id'];
$archived[$counter]['customerid'] = $row['customerid'];
$archived[$counter]['adminid'] = $row['adminid'];
@@ -469,12 +521,9 @@ class ticket
$counter++;
}
if(isset($archived[0]['id']))
{
if (isset($archived[0]['id'])) {
return $archived;
}
else
{
} else {
return false;
}
}
@@ -482,6 +531,8 @@ class ticket
/**
* Returns a sql-statement to search the archive
*
* @FIXME migrate to PDO
*/
static public function getArchiveSearchStatement($db, $subject = NULL, $priority = NULL, $fromdate = NULL, $todate = NULL, $message = NULL, $customer = - 1, $admin = 1, $categories = NULL)
{
@@ -674,20 +725,20 @@ class ticket
/**
* function customerHasTickets
*
* @param object mysql-db-object
* @param int customer-id
*
* @return array/bool array of ticket-ids if customer has any, else false
*/
static public function customerHasTickets($_db = null, $_cid = 0)
{
if($_cid != 0)
{
$result = $_db->query('SELECT `id` FROM `' . TABLE_PANEL_TICKETS . '` WHERE `customerid` ="'.(int)$_cid.'"');
static public function customerHasTickets($_cid = 0) {
if ($_cid != 0) {
$result_stmt = Database::prepare("
SELECT `id` FROM `" . TABLE_PANEL_TICKETS . "` WHERE `customerid` = :cid"
);
Database::pexecute($result_stmt, array('cid' => $_cid));
$tickets = array();
while($row = $_db->fetch_array($result))
{
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
$tickets[] = $row['id'];
}
@@ -700,32 +751,22 @@ class ticket
/**
* Get a data-var
*/
public function Get($_var = '', $_vartrusted = false)
{
if($_var != '')
{
if(!$_vartrusted)
{
public function Get($_var = '', $_vartrusted = false) {
if ($_var != '') {
if (!$_vartrusted) {
$_var = htmlspecialchars($_var);
}
if(isset($this->t_data[$_var]))
{
if(strtolower($_var) == 'message')
{
if (isset($this->t_data[$_var])) {
if (strtolower($_var) == 'message') {
return nl2br($this->t_data[$_var]);
}
elseif(strtolower($_var) == 'subject')
{
} elseif(strtolower($_var) == 'subject') {
return nl2br($this->t_data[$_var]);
}
else
{
} else {
return $this->t_data[$_var];
}
}
else
{
} else {
return null;
}
}
@@ -734,23 +775,22 @@ class ticket
/**
* Set a data-var
*/
public function Set($_var = '', $_value = '', $_vartrusted = false, $_valuetrusted = false)
{
if($_var != ''
&& $_value != '')
{
if(!$_vartrusted)
{
public function Set($_var = '', $_value = '', $_vartrusted = false, $_valuetrusted = false) {
if ($_var != ''
&& $_value != ''
) {
if (!$_vartrusted) {
$_var = $this->_purifier->purify($_var);
}
if(!$_valuetrusted)
{
if (!$_valuetrusted) {
$_value = $this->_purifier->purify($_value);
}
if(strtolower($_var) == 'message' || strtolower($_var) == 'subject')
{
if (strtolower($_var) == 'message'
|| strtolower($_var) == 'subject'
) {
$_value = $this->convertLatin1ToHtml($_value);
}

View File

@@ -20,22 +20,23 @@
/**
* ARCHIVING CLOSED TICKETS
*/
fwrite($debugHandler, 'Ticket-archiving run started...' . "\n");
$result_tickets = $db->query("SELECT `id`, `lastchange`, `subject` FROM `" . TABLE_PANEL_TICKETS . "`
WHERE `status` = '3' AND `answerto` = '0';");
$result_tickets_stmt = Database::query("
SELECT `id`, `lastchange`, `subject` FROM `" . TABLE_PANEL_TICKETS . "`
WHERE `status` = '3' AND `answerto` = '0';"
);
$archiving_count = 0;
while($row_ticket = $db->fetch_array($result_tickets))
{
while($row_ticket = $result_tickets_stmt->fetch(PDO::FETCH_ASSOC)) {
$lastchange = $row_ticket['lastchange'];
$now = time();
$days = (int)(($now - $lastchange) / 86400);
if($days >= $settings['ticket']['archiving_days'])
{
if ($days >= $settings['ticket']['archiving_days']) {
fwrite($debugHandler, 'archiving ticket "' . $row_ticket['subject'] . '" (ID #' . $row_ticket['id'] . ')' . "\n");
$mainticket = ticket::getInstanceOf(null, $db, $settings, (int)$row_ticket['id']);
$mainticket = ticket::getInstanceOf(null, $settings, (int)$row_ticket['id']);
$mainticket->Set('lastchange', $now, true, true);
$mainticket->Set('lastreplier', '1', true, true);
$mainticket->Set('status', '3', true, true);
@@ -46,6 +47,7 @@ while($row_ticket = $db->fetch_array($result_tickets))
}
fwrite($debugHandler, 'Archived ' . $archiving_count . ' tickets' . "\n");
$db->query('UPDATE `' . TABLE_PANEL_SETTINGS . '` SET `value` = UNIX_TIMESTAMP() WHERE `settinggroup` = \'system\' AND `varname` = \'last_archive_run\' ');
?>
Database::query("
UPDATE `" . TABLE_PANEL_SETTINGS . "` SET `value` = UNIX_TIMESTAMP()
WHERE `settinggroup` = 'system' AND `varname` = 'last_archive_run'"
);

View File

@@ -20,7 +20,6 @@
/**
* RESET USED TICKETS COUNTER
*/
fwrite($debugHandler, 'Resetting customers used ticket counter' . "\n");
$cronlog->logAction(CRON_ACTION, LOG_INFO, "Resetting customers used ticket counter");
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `tickets_used` = '0'");
Database::query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `tickets_used` = '0'");