@ -1,20 +1,24 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Declaration of TicketManager class
* @package chamilo.plugin.ticket
*/
/**
* Class TicketManager
*
*/
class TicketManager
{
/**
* Constructor
*/
function __construct()
{
}
/**
@ -24,10 +28,10 @@ class TicketManager
public static function get_all_tickets_categories()
{
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$table_support_project = Database::get_main_table(
TABLE_TICKET_PROJECT
TABLE_TICKET_PROJECT
);
$sql = "SELECT category.*, project.other_area , project.email
FROM " . $table_support_category . " category," . $table_support_project . " project
@ -76,24 +80,12 @@ class TicketManager
* @return bool
*/
public static function insert_new_ticket(
$category_id,
$course_id,
$project_id,
$other_area,
$email,
$subject,
$content,
$personalEmail = "",
$file_attachments,
$source = 'VRT',
$priority = 'NRM',
$status = '',
$request_user = '',
$assigned_user = 0
) {
$category_id, $course_id, $project_id, $other_area, $email, $subject, $content, $personalEmail = "", $file_attachments, $source = 'VRT', $priority = 'NRM', $status = '', $request_user = '', $assigned_user = 0
)
{
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$course_id = intval($course_id);
$category_id = intval($category_id);
@ -152,11 +144,8 @@ class TicketManager
}
if ($ticket_id != 0) {
$ticket_code = "A" . str_pad(
(int)$ticket_id,
11,
"0",
STR_PAD_LEFT
);
(int) $ticket_id, 11, "0", STR_PAD_LEFT
);
$sql_update_code = "UPDATE $table_support_tickets
SET ticket_code = '$ticket_code' WHERE ticket_id = '$ticket_id'";
Database::query($sql_update_code);
@ -170,45 +159,34 @@ class TicketManager
$user = UserManager::get_user_info_by_id($request_user);
$helpDeskMessage = '< table >
< tr >
< td width = "100px" > < b > '.get_lang('User').'< / b > < / td >
< td width = "100px" > < b > ' . get_lang('User') . '< / b > < / td >
< td width = "400px" > ' . $user['firstname']
. ' ' . $user['lastname'] . '< / td >
. ' ' . $user['lastname'] . '< / td >
< / tr >
< tr >
< td width = "100px" > < b > '.get_lang('Username').'< / b > < / td >
< td width = "100px" > < b > ' . get_lang('Username') . '< / b > < / td >
< td width = "400px" > ' . $user['username'] . '< / td >
< / tr >
< tr >
< td width = "100px" > < b > '.get_lang('Date').'< / b > < / td >
< td width = "100px" > < b > ' . get_lang('Date') . '< / b > < / td >
< td width = "400px" > ' . api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG) . '< / td >
< / tr >
< tr >
< td width = "100px" > < b > '.get_lang('Topic').'< / b > < / td >
< td width = "100px" > < b > ' . get_lang('Topic') . '< / b > < / td >
< td width = "400px" > ' . $subject . '< / td >
< / tr >
< tr >
< td width = "100px" > < b > '.get_lang('Description').'< / b > < / td >
< td width = "100px" > < b > ' . get_lang('Description') . '< / b > < / td >
< td width = "400px" > ' . $content . '< / td >
< / tr >
< / table > ';
api_mail_html(
'Soporte virtual',
$email,
"[SOPORTE] Incidente Reenviado de Soporte Virtual",
$helpDeskMessage,
$user['firstname'] . ' ' . $user['lastname'],
$personalEmail,
array('cc' => 'soportevirtual@usil.edu.pe'),
$data_files
'Soporte virtual', $email, "[SOPORTE] Incidente Reenviado de Soporte Virtual", $helpDeskMessage, $user['firstname'] . ' ' . $user['lastname'], $personalEmail, array('cc' => 'soportevirtual@usil.edu.pe'), $data_files
);
$studentMessage = '< p > Su consulta fue reenviada al area responsable : < a href = "mailto:' . $email . '" > ' . $email . '< / a > < / p > ';
$studentMessage .= '< p > La respuesta a su consulta será enviada al correo : < a href = "#" > ' . $personalEmail . '< / a > < / p > ';
self::insert_message(
$ticket_id,
get_lang('MessageResent'),
$studentMessage,
null,
1
$ticket_id, get_lang('MessageResent'), $studentMessage, null, 1
);
}
@ -259,16 +237,12 @@ class TicketManager
$sender = api_get_user_info($insert_id);
$message = '< p > Estimado(a):< / p > < p > ' . $info['firstname'] . " " . $info['lastname'] . "< / p >
< p > Te asignaron el ticket $ticket_id " . '< a href = "' . api_get_path (
WEB_PLUGIN_PATH
) . PLUGIN_NAME . '/src/ticket_details.php?ticket_id=' . $ticket_id . '">Ticket< / a > < / p > ';
WEB_PLUGIN_PATH
) . PLUGIN_NAME . '/src/ticket_details.php?ticket_id=' . $ticket_id . '">Ticket< / a > < / p > ';
api_mail_html(
$info['firstname'] . " " . $info['lastname'],
$info['mail'],
"[TICKETS] Asignacion de Ticket #$ticket_id ",
$message,
null, // sender name
null, // sender e-mail
array('cc' => $sender['email']) // should be support e-mail (platform admin) here
$info['firstname'] . " " . $info['lastname'], $info['mail'], "[TICKETS] Asignacion de Ticket #$ticket_id ", $message, null, // sender name
null, // sender e-mail
array('cc' => $sender['email']) // should be support e-mail (platform admin) here
);
}
}
@ -285,13 +259,7 @@ class TicketManager
* @return bool
*/
public static function insert_message(
$ticket_id,
$subject,
$content,
$file_attachments,
$user_id,
$status = 'NOL',
$sendConfirmation = false
$ticket_id, $subject, $content, $file_attachments, $user_id, $status = 'NOL', $sendConfirmation = false
)
{
global $data_files;
@ -302,19 +270,19 @@ class TicketManager
$status = Database::escape_string($status);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
if ($sendConfirmation) {
$form = '< form action = "ticket_details.php?ticket_id=' . $ticket_id . '" id = "confirmticket" method = "POST" >
< p > '.get_lang('TicketWasThisAnswerSatisfying').'< / p >
< input id = "responseyes" type = "submit" value = "'.get_lang('Yes').'" name = "response" / >
< input id = "responseno" type = "submit" value = "'.get_lang('No').'" name = "response" / >
< p > ' . get_lang('TicketWasThisAnswerSatisfying') . '< / p >
< input id = "responseyes" type = "submit" value = "' . get_lang('Yes') . '" name = "response" / >
< input id = "responseno" type = "submit" value = "' . get_lang('No') . '" name = "response" / >
< / form > ';
$content .= $form;
Database::query(
"UPDATE $table_support_tickets SET status_id='XCF' WHERE ticket_id = '$ticket_id'"
"UPDATE $table_support_tickets SET status_id='XCF' WHERE ticket_id = '$ticket_id'"
);
}
$sql_message_id = "SELECT COUNT(*) as total_messages
@ -370,10 +338,7 @@ class TicketManager
foreach ($file_attachments as $file_attach) {
if ($file_attach['error'] == 0) {
$data_files[] = self::save_message_attachment_file(
$file_attach,
$ticket_id,
$message_id,
$message_attch_id
$file_attach, $ticket_id, $message_id, $message_attch_id
);
$message_attch_id++;
} else {
@ -395,26 +360,22 @@ class TicketManager
* @return array
*/
public static function save_message_attachment_file(
$file_attach,
$ticket_id,
$message_id,
$message_attch_id
$file_attach, $ticket_id, $message_id, $message_attch_id
)
{
$now = api_get_utc_datetime();
$user_id = api_get_user_id();
$ticket_id = intval($ticket_id);
$new_file_name = add_ext_on_mime(
stripslashes($file_attach['name']),
$file_attach['type']
stripslashes($file_attach['name']), $file_attach['type']
);
$file_name = $file_attach['name'];
$table_support_message_attachments = Database::get_main_table(
TABLE_TICKET_MESSAGE_ATTACHMENTS
TABLE_TICKET_MESSAGE_ATTACHMENTS
);
if (!filter_extension($new_file_name)) {
Display :: display_error_message(
get_lang('UplUnableToSaveFileFilteredExtension')
get_lang('UplUnableToSaveFileFilteredExtension')
);
} else {
$new_file_name = uniqid('');
@ -422,9 +383,7 @@ class TicketManager
$path_message_attach = $path_attachment . 'plugin_ticket_messageattch/';
if (!file_exists($path_message_attach)) {
@mkdir(
$path_message_attach,
api_get_permissions_for_new_directories(),
true
$path_message_attach, api_get_permissions_for_new_directories(), true
);
}
$new_path = $path_message_attach . $new_file_name;
@ -473,22 +432,19 @@ class TicketManager
* @return array
*/
public static function get_tickets_by_user_id(
$from,
$number_of_items,
$column,
$direction,
$user_id = null
) {
$from, $number_of_items, $column, $direction, $user_id = null
)
{
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_priority = Database::get_main_table(
TABLE_TICKET_PRIORITY
TABLE_TICKET_PRIORITY
);
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_main_user = Database::get_main_table(TABLE_MAIN_USER);
$table_main_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
@ -528,7 +484,7 @@ class TicketManager
$sql .= " AND request_user = '$user_id' ";
}
$keyword_unread = Database::escape_string(
trim($_GET['keyword_unread'])
trim($_GET['keyword_unread'])
);
//Search simple
if (isset($_GET['submit_simple'])) {
@ -546,34 +502,34 @@ class TicketManager
//Search advanced
if (isset($_GET['submit_advanced'])) {
$keyword_category = Database::escape_string(
trim($_GET['keyword_category'])
trim($_GET['keyword_category'])
);
$keyword_request_user = Database::escape_string(
trim($_GET['keyword_request_user'])
trim($_GET['keyword_request_user'])
);
$keyword_admin = Database::escape_string(
trim($_GET['keyword_admin'])
trim($_GET['keyword_admin'])
);
$keyword_start_date_start = Database::escape_string(
trim($_GET['keyword_start_date_start'])
trim($_GET['keyword_start_date_start'])
);
$keyword_start_date_end = Database::escape_string(
trim($_GET['keyword_start_date_end'])
trim($_GET['keyword_start_date_end'])
);
$keyword_status = Database::escape_string(
trim($_GET['keyword_status'])
trim($_GET['keyword_status'])
);
$keyword_source = Database::escape_string(
trim($_GET['keyword_source'])
trim($_GET['keyword_source'])
);
$keyword_priority = Database::escape_string(
trim($_GET['keyword_priority'])
trim($_GET['keyword_priority'])
);
$keyword_range = Database::escape_string(
trim($_GET['keyword_dates'])
trim($_GET['keyword_dates'])
);
$keyword_course = Database::escape_string(
trim($_GET['keyword_course'])
trim($_GET['keyword_course'])
);
if ($keyword_category != '') {
@ -614,7 +570,6 @@ class TicketManager
)
)";
}
}
if ($keyword_unread == 'yes') {
$sql .= " AND ticket.ticket_id IN (SELECT ticket.ticket_id
@ -660,29 +615,28 @@ class TicketManager
$unread = Database::fetch_object($result_unread)->unread;
$userInfo = UserManager::get_user_info_by_id($row['user_id']);
$name = '< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '">' . api_get_person_name(
$userInfo['firstname'],
$userInfo['lastname']
) . '< / a > ';
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '">' . api_get_person_name(
$userInfo['firstname'], $userInfo['lastname']
) . '< / a > ';
$actions = "";
/*if($row['status_id']!='CLS' & & $row['status_id']!='REE'){
if( $row['responsable'] != 0 & & $row['responsable'] == $user_id ){
$actions = '< a href = "myticket.php?ticket_id='.$row['ticket_id'].'&action=unassign" title = "desasignarme" > < img src = "../../../main/img/admin_star.png" border = "0" / > < / a > ';
}else{
$actions = '< a href = "myticket.php?ticket_id='.$row['ticket_id'].'&action=assign" title = "asignarme" > < img src = "../../../main/img/admin_star_na.png" border = "0" / > < / a > ';
}
}*/
/* if($row['status_id']!='CLS' & & $row['status_id']!='REE'){
if( $row['responsable'] != 0 & & $row['responsable'] == $user_id ){
$actions = '< a href = "myticket.php?ticket_id='.$row['ticket_id'].'&action=unassign" title = "desasignarme" > < img src = "../../../main/img/admin_star.png" border = "0" / > < / a > ';
}else{
$actions = '< a href = "myticket.php?ticket_id='.$row['ticket_id'].'&action=assign" title = "asignarme" > < img src = "../../../main/img/admin_star_na.png" border = "0" / > < / a > ';
}
} */
if ($row['responsable'] != 0) {
$row['responsable'] = api_get_user_info($row['responsable']);
$row['responsable'] = '< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['responsable']['user_id'] . '">' . $row['responsable']['firstname'] . ' ' . $row['responsable']['lastname'] . '< / a > ';
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['responsable']['user_id'] . '">' . $row['responsable']['firstname'] . ' ' . $row['responsable']['lastname'] . '< / a > ';
} else {
if ($row['status_id'] != 'REE') {
$row['responsable'] = '< span style = "color:#ff0000;" > '.get_lang('ToBeAssigned').'< / span > ';
$row['responsable'] = '< span style = "color:#ff0000;" > ' . get_lang('ToBeAssigned') . '< / span > ';
} else {
$row['responsable'] = '< span style = "color:#00ff00;" > '.get_lang('MessageResent').'< / span > ';
$row['responsable'] = '< span style = "color:#00ff00;" > ' . get_lang('MessageResent') . '< / span > ';
}
}
switch ($row['source']) {
@ -703,16 +657,14 @@ class TicketManager
$row['col2'] = api_get_local_time($row['col2']);
if ($isAdmin) {
$actions .= '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . Display::return_icon(
'synthese_view.gif',
get_lang('Info')
) . '< / a > ';
'synthese_view.gif', get_lang('Info')
) . '< / a > ';
if ($row['priority_id'] == 'ALT' & & $row['status_id'] != 'CLS') {
$actions .= '< img src = "'.api_get_path(WEB_CODE_PATH).'img/exclamation.png" border = "0" / > ';
$actions .= '< img src = "' . api_get_path(WEB_CODE_PATH) . 'img/exclamation.png" border = "0" / > ';
}
$row['col0'] = Display::return_icon(
$img_source,
get_lang('Info')
) . '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . $row['ticket_code'] . '< / a > ';
$img_source, get_lang('Info')
) . '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . $row['ticket_code'] . '< / a > ';
if ($row['col7'] == 'PENDIENTE') {
$row['col7'] = '< span style = "color: #f00; font-weight:bold;" > ' . $row['col7'] . '< / span > ';
}
@ -728,21 +680,17 @@ class TicketManager
$row['col8'],
$actions,
eregi_replace(
"[\n|\r|\n\r|\r\n]",
' ',
strip_tags($row['col9'])
"[\n|\r|\n\r|\r\n]", ' ', strip_tags($row['col9'])
)
);
} else {
$actions = "";
$actions .= '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . Display::return_icon(
'synthese_view.gif',
get_lang('Info')
) . '< / a > ';
'synthese_view.gif', get_lang('Info')
) . '< / a > ';
$row['col0'] = Display::return_icon(
$img_source,
get_lang('Info')
) . '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . $row['ticket_code'] . '< / a > ';
$img_source, get_lang('Info')
) . '< a href = "ticket_details.php?ticket_id=' . $row['col0'] . '" > ' . $row['ticket_code'] . '< / a > ';
$now = api_strtotime(api_get_utc_datetime());
$last_edit_date = api_strtotime($row['sys_lastedit_datetime']);
$dif = $now - $last_edit_date;
@ -751,7 +699,7 @@ class TicketManager
$actions .= '< a href = "myticket.php?ticket_id=' . $row['ticket_id'] . '&action=alert" > < img src = "../../../main/img/exclamation.png" border = "0" / > < / a > ';
}
if ($row['priority_id'] == 'ALT') {
$actions .= '< img src = "'.api_get_path(WEB_CODE_PATH).'img/admin_star.png" border = "0" / > ';
$actions .= '< img src = "' . api_get_path(WEB_CODE_PATH) . 'img/admin_star.png" border = "0" / > ';
}
$ticket = array(
$row['col0'],
@ -765,13 +713,12 @@ class TicketManager
if ($unread > 0) {
$ticket['0'] = $ticket['0'] . ' (' . $unread . ')< a href = "ticket_details.php?ticket_id=' . $row['ticket_id'] . '" > < img src = "../../../main/img/message_new.png" border = "0" title = "' . $unread . ' Nuevo(s) Mensajes" / > < / a > ';
}
if ($isAdmin) {
$ticket['0'] .= ' < a href = "javascript:void(0)" onclick = "load_history_ticket(\'div_' . $row['ticket_id'] . '\',' . $row['ticket_id'] . ')" >
< img onclick = "load_course_list(\'div_' . $row['ticket_id'] . '\',' . $row['ticket_id'] . ')" onmouseover = "clear_course_list (\'div_' . $row['ticket_id'] . '\')" src = "../../../main/img/history.gif" title = "' . get_lang (
'Historial'
) . '" alt="' . get_lang('Historial') . '"/>
'Historial'
) . '" alt="' . get_lang('Historial') . '"/>
< div class = "blackboard_hide" id = "div_' . $row['ticket_id'] . '" > < / div >
< / a > ';
}
@ -789,15 +736,15 @@ class TicketManager
{
$user_id = intval($user_id);
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_priority = Database::get_main_table(
TABLE_TICKET_PRIORITY
TABLE_TICKET_PRIORITY
);
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_main_user = Database::get_main_table(TABLE_MAIN_USER);
$table_main_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
@ -805,8 +752,8 @@ class TicketManager
$user_id = api_get_user_id();
}
$sql = "SELECT COUNT(ticket.ticket_id) AS total FROM " . $table_support_tickets . " ticket ," . $table_support_category . " cat , " . $table_support_priority . " priority, " . $table_support_status . " status , " . Database::get_main_table(
TABLE_MAIN_USER
) . " user
TABLE_MAIN_USER
) . " user
WHERE cat.category_id = ticket.category_id AND ticket.priority_id = priority.priority_id AND ticket.status_id = status.status_id AND user.user_id = ticket.request_user ";
if (!api_is_platform_admin()) {
$sql .= " AND request_user = '$user_id' ";
@ -820,39 +767,39 @@ class TicketManager
}
}
$keyword_unread = Database::escape_string(
trim($_GET['keyword_unread'])
trim($_GET['keyword_unread'])
);
//Search advanced
if (isset($_GET['submit_advanced'])) {
$keyword_category = Database::escape_string(
trim($_GET['keyword_category'])
trim($_GET['keyword_category'])
);
$keyword_request_user = Database::escape_string(
trim($_GET['keyword_request_user'])
trim($_GET['keyword_request_user'])
);
$keyword_admin = Database::escape_string(
trim($_GET['keyword_admin'])
trim($_GET['keyword_admin'])
);
$keyword_start_date_start = Database::escape_string(
trim($_GET['keyword_start_date_start'])
trim($_GET['keyword_start_date_start'])
);
$keyword_start_date_end = Database::escape_string(
trim($_GET['keyword_start_date_end'])
trim($_GET['keyword_start_date_end'])
);
$keyword_status = Database::escape_string(
trim($_GET['keyword_status'])
trim($_GET['keyword_status'])
);
$keyword_source = Database::escape_string(
trim($_GET['keyword_source'])
trim($_GET['keyword_source'])
);
$keyword_priority = Database::escape_string(
trim($_GET['keyword_priority'])
trim($_GET['keyword_priority'])
);
$keyword_range = Database::escape_string(
trim($_GET['keyword_dates'])
trim($_GET['keyword_dates'])
);
$keyword_course = Database::escape_string(
trim($_GET['keyword_course'])
trim($_GET['keyword_course'])
);
if ($keyword_category != '') {
@ -887,7 +834,6 @@ class TicketManager
$sql .= " AND ticket.course_id IN ( ";
$sql .= "SELECT id FROM $course_table WHERE (title LIKE '%" . $keyword_course . "%' OR code LIKE '%" . $keyword_course . "%' OR visual_code LIKE '%" . $keyword_course . "%' )) ";
}
}
if ($keyword_unread == 'yes') {
$sql .= " AND ticket.ticket_id IN (SELECT ticket.ticket_id FROM $table_support_tickets ticket, $table_support_messages message, $table_main_user user WHERE ticket.ticket_id = message.ticket_id AND message.status = 'NOL' AND message.sys_insert_user_id = user.user_id AND user.user_id NOT IN (SELECT user_id FROM $table_main_admin) AND ticket.status_id != 'REE' GROUP BY ticket.ticket_id)";
@ -910,18 +856,18 @@ class TicketManager
public static function get_ticket_detail_by_id($ticket_id, $user_id)
{
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_priority = Database::get_main_table(
TABLE_TICKET_PRIORITY
TABLE_TICKET_PRIORITY
);
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_support_message_attachments = Database::get_main_table(
TABLE_TICKET_MESSAGE_ATTACHMENTS
TABLE_TICKET_MESSAGE_ATTACHMENTS
);
$sql = "SELECT ticket.* ,cat.name , status.name as status, priority.priority FROM " . $table_support_tickets . " ticket, " . $table_support_category . " cat ," . $table_support_priority . " priority , " . $table_support_status . " status
@ -935,40 +881,33 @@ class TicketManager
while ($row = Database::fetch_assoc($result)) {
$row['course'] = null;
$row['start_date'] = api_convert_and_format_date(
api_get_local_time($row['start_date']),
DATE_TIME_FORMAT_LONG,
_api_get_timezone()
api_get_local_time($row['start_date']), DATE_TIME_FORMAT_LONG, _api_get_timezone()
);
$row['end_date'] = api_convert_and_format_date(
api_get_local_time($row['end_date']),
DATE_TIME_FORMAT_LONG,
_api_get_timezone()
api_get_local_time($row['end_date']), DATE_TIME_FORMAT_LONG, _api_get_timezone()
);
$row['sys_lastedit_datetime'] = api_convert_and_format_date(
api_get_local_time($row['sys_lastedit_datetime']),
DATE_TIME_FORMAT_LONG,
_api_get_timezone()
api_get_local_time($row['sys_lastedit_datetime']), DATE_TIME_FORMAT_LONG, _api_get_timezone()
);
$row['course_url'] = null;
if ($row['course_id'] != 0) {
$course = api_get_course_info_by_id($row['course_id']);
$row['course_url'] = '< a href = "' . api_get_path (
WEB_COURSE_PATH
) . $course['path'] . '">' . $course['name'] . '< / a > ';
WEB_COURSE_PATH
) . $course['path'] . '">' . $course['name'] . '< / a > ';
}
$userInfo = api_get_user_info($row['request_user']);
$row['user_url'] = '< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['request_user'] . '">' . api_get_person_name(
$userInfo['firstname'],
$userInfo['lastname']
) . '< / a > ';
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['request_user'] . '">' . api_get_person_name(
$userInfo['firstname'], $userInfo['lastname']
) . '< / a > ';
$ticket['usuario'] = $userInfo;
$ticket['ticket'] = $row;
}
$sql = "SELECT * FROM " . $table_support_messages . " message, " . Database::get_main_table(
TABLE_MAIN_USER
) . " user WHERE message.ticket_id = '$ticket_id' AND message.sys_insert_user_id = user.user_id ";
TABLE_MAIN_USER
) . " user WHERE message.ticket_id = '$ticket_id' AND message.sys_insert_user_id = user.user_id ";
$result = Database::query($sql);
$ticket['messages'] = array();
$attach_icon = Display::return_icon('attachment.gif', '');
@ -984,14 +923,14 @@ class TicketManager
$message['admin'] = true;
}
$message['user_created'] = '< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '">' . $row['firstname'] . ' ' . $row['lastname'] . '< / a > ';
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '">' . $row['firstname'] . ' ' . $row['lastname'] . '< / a > ';
$sql_atachment = "SELECT * FROM " . TABLE_TICKET_MESSAGE_ATTACHMENTS . " WHERE message_id = " . $row['message_id'] . " AND ticket_id= '$ticket_id' ";
$result_attach = Database::query($sql_atachment);
while ($row2 = Database::fetch_assoc($result_attach)) {
$archiveURL = $archiveURL = api_get_path(
WEB_PLUGIN_PATH
) . PLUGIN_NAME . '/s/download.php?ticket_id=' . $ticket_id . '&file=';
WEB_PLUGIN_PATH
) . PLUGIN_NAME . '/s/download.php?ticket_id=' . $ticket_id . '&file=';
$row2['attachment_link'] = $attach_icon . ' < a href = "' . $archiveURL . $row2['path'] . '&title=' . $row2['filename'] . '" > ' . $row2['filename'] . '< / a > (' . $row2['size'] . ')';
$message['atachments'][] = $row2;
}
@ -1010,11 +949,11 @@ class TicketManager
public static function update_message_status($ticket_id, $user_id)
{
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$now = api_get_utc_datetime();
$sql = "UPDATE " . $table_support_messages . " SET status = 'LEI' , sys_lastedit_user_id ='" . api_get_user_id(
) . "' ,sys_lastedit_datetime ='" . $now . "' WHERE ticket_id ='$ticket_id' ";
) . "' ,sys_lastedit_datetime ='" . $now . "' WHERE ticket_id ='$ticket_id' ";
if (api_is_platform_admin()) {
$sql .= " AND sys_insert_user_id = '$user_id'";
@ -1025,7 +964,7 @@ class TicketManager
Database::query($sql);
if (Database::affected_rows() > 0) {
Database::query(
"UPDATE " . Database::get_main_table(TABLE_TICKET_TICKET) . " SET status_id = 'PND' WHERE ticket_id ='$ticket_id' AND status_id = 'NAT'"
"UPDATE " . Database::get_main_table(TABLE_TICKET_TICKET) . " SET status_id = 'PND' WHERE ticket_id ='$ticket_id' AND status_id = 'NAT'"
);
return true;
} else {
@ -1040,13 +979,12 @@ class TicketManager
* @return bool
*/
public static function update_ticket_status(
$status_id,
$ticket_id,
$user_id
) {
$status_id, $ticket_id, $user_id
)
{
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$now = api_get_utc_datetime();
$sql = "UPDATE " . $table_support_tickets . " SET status_id = '$status_id' , sys_lastedit_user_id ='$user_id' ,sys_lastedit_datetime ='" . $now . "' WHERE ticket_id ='$ticket_id'";
@ -1065,7 +1003,7 @@ class TicketManager
{
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_main_user = Database::get_main_table(TABLE_MAIN_USER);
$table_main_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
@ -1081,7 +1019,6 @@ class TicketManager
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->unread;
}
/**
@ -1116,7 +1053,7 @@ class TicketManager
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$now = api_get_utc_datetime();
$sql = "UPDATE " . $table_support_tickets . " SET status_id = 'CLS' , sys_lastedit_user_id ='" . api_get_user_id(
) . "' ,sys_lastedit_datetime ='" . $now . "',end_date ='" . $now . "' WHERE DATEDIFF('$now',sys_lastedit_datetime) > 7 AND status_id != 'CLS' AND status_id != 'NAT' AND status_id != 'REE'";
) . "' ,sys_lastedit_datetime ='" . $now . "',end_date ='" . $now . "' WHERE DATEDIFF('$now',sys_lastedit_datetime) > 7 AND status_id != 'CLS' AND status_id != 'NAT' AND status_id != 'REE'";
Database::query($sql);
}
@ -1127,7 +1064,7 @@ class TicketManager
public static function get_assign_log($ticket_id)
{
$table_support_assigned_log = Database::get_main_table(
TABLE_TICKET_ASSIGNED_LOG
TABLE_TICKET_ASSIGNED_LOG
);
$sql = "SELECT log.* FROM " . TABLE_TICKET_ASSIGNED_LOG . " log WHERE log.ticket_id = '$ticket_id' ORDER BY log.assigned_date";
$result = Database::query($sql);
@ -1135,23 +1072,21 @@ class TicketManager
while ($row = Database::fetch_assoc($result)) {
if ($row['user_id'] != 0) {
$assignuser = api_get_user_info(
$row['user_id']
$row['user_id']
);
}
$insertuser = api_get_user_info($row['sys_insert_user_id']);
$row['assigned_date'] = api_convert_and_format_date(
api_get_local_time($row['assigned_date']),
'%d/%m/%y-%H:%M:%S',
_api_get_timezone()
api_get_local_time($row['assigned_date']), '%d/%m/%y-%H:%M:%S', _api_get_timezone()
);
$row['assignuser'] = ($row['user_id'] != 0) ? ('< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '" target="_blank">' . $assignuser['username'] . '< / a > ') : get_lang(
'Unassign'
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['user_id'] . '" target="_blank">' . $assignuser['username'] . '< / a > ') : get_lang(
'Unassign'
);
$row['insertuser'] = '< a href = "' . api_get_path (
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['sys_insert_user_id'] . '" target="_blank">' . $insertuser['username'] . '< / a > ';
WEB_PATH
) . 'main/admin/user_information.php?user_id=' . $row['sys_insert_user_id'] . '" target="_blank">' . $insertuser['username'] . '< / a > ';
$history[] = $row;
}
return $history;
@ -1166,22 +1101,19 @@ class TicketManager
* @return array
*/
public static function export_tickets_by_user_id(
$from,
$number_of_items,
$column,
$direction,
$user_id = null
) {
$from, $number_of_items, $column, $direction, $user_id = null
)
{
$table_support_category = Database::get_main_table(
TABLE_TICKET_CATEGORY
TABLE_TICKET_CATEGORY
);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_priority = Database::get_main_table(
TABLE_TICKET_PRIORITY
TABLE_TICKET_PRIORITY
);
$table_support_status = Database::get_main_table(TABLE_TICKET_STATUS);
$table_support_messages = Database::get_main_table(
TABLE_TICKET_MESSAGE
TABLE_TICKET_MESSAGE
);
$table_main_user = Database::get_main_table(TABLE_MAIN_USER);
if (is_null($direction)) {
@ -1193,8 +1125,8 @@ class TicketManager
$sql = "SELECT ticket.ticket_code, ticket.sys_insert_datetime , ticket.sys_lastedit_datetime , cat.name as category , CONCAT(user.lastname,' ', user.firstname) AS fullname , status.name as status , ticket.total_messages as messages , ticket.assigned_last_user as responsable
FROM " . $table_support_tickets . " ticket ," . $table_support_category . " cat , " . $table_support_priority . " priority, " . $table_support_status . " status , " . Database::get_main_table(
TABLE_MAIN_USER
) . " user
TABLE_MAIN_USER
) . " user
WHERE cat.category_id = ticket.category_id AND ticket.priority_id = priority.priority_id AND ticket.status_id = status.status_id AND user.user_id = ticket.request_user ";
//Search simple
if (isset($_GET['submit_simple'])) {
@ -1206,37 +1138,37 @@ class TicketManager
//Search advanced
if (isset($_GET['submit_advanced'])) {
$keyword_category = Database::escape_string(
trim($_GET['keyword_category'])
trim($_GET['keyword_category'])
);
$keyword_request_user = Database::escape_string(
trim($_GET['keyword_request_user'])
trim($_GET['keyword_request_user'])
);
$keyword_admin = Database::escape_string(
trim($_GET['keyword_admin'])
trim($_GET['keyword_admin'])
);
$keyword_start_date_start = Database::escape_string(
trim($_GET['keyword_start_date_start'])
trim($_GET['keyword_start_date_start'])
);
$keyword_start_date_end = Database::escape_string(
trim($_GET['keyword_start_date_end'])
trim($_GET['keyword_start_date_end'])
);
$keyword_status = Database::escape_string(
trim($_GET['keyword_status'])
trim($_GET['keyword_status'])
);
$keyword_source = Database::escape_string(
trim($_GET['keyword_source'])
trim($_GET['keyword_source'])
);
$keyword_priority = Database::escape_string(
trim($_GET['keyword_priority'])
trim($_GET['keyword_priority'])
);
$keyword_range = Database::escape_string(
trim($_GET['keyword_dates'])
trim($_GET['keyword_dates'])
);
$keyword_unread = Database::escape_string(
trim($_GET['keyword_unread'])
trim($_GET['keyword_unread'])
);
$keyword_course = Database::escape_string(
trim($_GET['keyword_course'])
trim($_GET['keyword_course'])
);
if ($keyword_category != '') {
@ -1278,7 +1210,6 @@ class TicketManager
$sql .= " AND ticket.ticket_id NOT IN (SELECT ticket.ticket_id FROM $table_support_tickets ticket, $table_support_messages message, $table_main_user user WHERE ticket.ticket_id = message.ticket_id AND message.status = 'NOL' AND message.sys_insert_user_id = user.user_id AND user.status != 1 AND ticket.status_id != 'REE' GROUP BY ticket.ticket_id)";
}
}
}
@ -1304,12 +1235,10 @@ class TicketManager
$row['responsable'] = $row['responsable']['firstname'] . ' ' . $row['responsable']['lastname'];
}
$row['sys_insert_datetime'] = api_format_date(
$row['sys_insert_datetime'],
'%d/%m/%y - %I:%M:%S %p'
$row['sys_insert_datetime'], '%d/%m/%y - %I:%M:%S %p'
);
$row['sys_lastedit_datetime'] = api_format_date(
$row['sys_lastedit_datetime'],
'%d/%m/%y - %I:%M:%S %p'
$row['sys_lastedit_datetime'], '%d/%m/%y - %I:%M:%S %p'
);
$row['category'] = utf8_decode($row['category']);
$row['programa'] = utf8_decode($row['fullname']);
@ -1320,4 +1249,5 @@ class TicketManager
return $tickets;
}
}