This commit is contained in:
Xes
2025-08-14 22:37:50 +02:00
parent fb6d5d5926
commit 3641e93527
9156 changed files with 1813532 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/* For licensing terms, see /license.txt */
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script();
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}
$course_info = api_get_course_info();
$course_code = $course_info['code'];
echo '<form action="tutor.php" name="assign" id ="assign">';
echo '<div id="confirmation"></div>';
$id = (int) $_GET['id'];
$tblWeeklyReport = Database::get_main_table('rp_reporte_semanas');
$sql = "SELECT * FROM $tblWeeklyReport WHERE id = $id";
$sql_tasks = "SELECT id AS colid, title as coltitle
FROM ".Database::get_course_table(TABLE_STUDENT_PUBLICATION)."
WHERE parent_id = 0
AND id NOT IN (
SELECT work_id
FROM $tblWeeklyReport
WHERE
course_code = '$course_code' AND
id != $id
)";
$sql_forum = "SELECT thread_id AS colid, thread_title AS coltitle
FROM ".Database::get_course_table(TABLE_FORUM_THREAD)."
WHERE thread_id NOT IN (
SELECT forum_id
FROM $tblWeeklyReport
WHERE
course_code = '$course_code' AND
id != $id
)";
$rs = Database::fetch_object(Database::query($sql));
$result_tareas = Database::query($sql_tasks);
$result_forum = Database::query($sql_forum);
echo '<div class="row">
<input type="hidden" id="rs_id" name ="rs_id" value="'.$id.'">
<div class="formw">'.get_lang('PleaseSelectTasks').'</div>
</div>';
echo '<div class="row"><div class="formw"><select name ="work_id" id="work_id">';
echo '<option value="0"'.(($row['colid'] == $rs->work_id) ? "selected" : "").'>'.get_lang('PleaseSelect').'</option>';
while ($row = Database::fetch_assoc($result_tasks)) {
echo '<option value="'.$row['colid'].'"'.(($row['colid'] == $rs->work_id) ? "selected" : "").'>'.
$row['coltitle'].'</option>';
}
echo '</select></div><div>';
echo '<div class="row">
<div class="formw">'.get_lang('PleaseSelectThread').'</div>
</div>';
echo '<div class="row"><div class="formw"><select name ="forum_id" id="forum_id">';
echo '<option value="0"'.(($row['colid'] == $rs->work_id) ? "forum_id" : "").'>'.get_lang('PleaseSelect').'</option>';
while ($row = Database::fetch_assoc($result_forum)) {
echo '<option value="'.$row['colid'].'"'.(($row['colid'] == $rs->forum_id) ? "selected" : "").'>'.
$row['coltitle'].'</option>';
}
echo '</select></div><div>';
echo '<div class="row">
<div class="formw">
<button class="save" name="edit" type="button" value="'.get_lang('Edit').'" onClick="save('.$id.');">'.
get_lang('Edit').'</button>
</div>
</div>';
echo '</form>';

202
main/ticket/categories.php Normal file
View File

@@ -0,0 +1,202 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This script is the Tickets plugin main entry point.
*
* @package chamilo.plugin.ticket
*/
// needed in order to load the plugin lang variables
$course_plugin = 'ticket';
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$toolName = get_lang('Categories');
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
$this_section = 'tickets';
Session::erase('this_section');
$table = new SortableTable(
'TicketCategories',
['TicketManager', 'getCategoriesCount'],
['TicketManager', 'getCategories'],
1
);
if ($table->per_page == 0) {
$table->per_page = 20;
}
$formToString = '';
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$project = TicketManager::getProject($projectId);
if (empty($project)) {
api_not_allowed(true);
}
Session::write('project_id', $projectId);
$action = isset($_GET['action']) ? $_GET['action'] : '';
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId,
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => get_lang('Projects'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => $project->getName(),
];
switch ($action) {
case 'delete':
$tickets = TicketManager::getTicketsFromCriteria(['category' => $id]);
if (empty($tickets)) {
TicketManager::deleteCategory($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
} else {
Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets')));
}
header("Location: ".api_get_self().'?project_id='.$projectId);
exit;
break;
case 'add':
$toolName = get_lang('Add');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php',
'name' => get_lang('Categories'),
];
$url = api_get_self().'?action=add&project_id='.$projectId;
$form = TicketManager::getCategoryForm($url, $projectId);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
'total_tickets' => 0,
'sys_insert_user_id' => api_get_user_id(),
'sys_insert_datetime' => api_get_utc_datetime(),
'course_required' => '',
'project_id' => $projectId,
];
TicketManager::addCategory($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header("Location: ".api_get_self().'?project_id='.$projectId);
exit;
}
break;
case 'edit':
if (api_get_setting('ticket_allow_category_edition') !== 'true') {
api_not_allowed();
}
$toolName = get_lang('Edit');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php?project_id='.$projectId,
'name' => get_lang('Categories'),
];
$url = api_get_self().'?action=edit&project_id='.$projectId.'&id='.$id;
$form = TicketManager::getCategoryForm($url, $projectId);
$cat = TicketManager::getCategory($_GET['id']);
$form->setDefaults($cat);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
'sys_lastedit_datetime' => api_get_utc_datetime(),
'sys_lastedit_user_id' => api_get_user_id(),
];
$cat = TicketManager::updateCategory($_GET['id'], $params);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location: ".api_get_self().'?project_id='.$projectId);
exit;
}
break;
default:
break;
}
/**
* Build the modify-column of the table.
*
* @param int The user id
* @param string URL params to add to table links
* @param array Row of elements to alter
*
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($id, $params, $row)
{
$projectId = Session::read('project_id');
$result = '';
if (api_get_setting('ticket_allow_category_edition') === 'true') {
$result .= Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
"categories.php?action=edit&id={$row['id']}&project_id=".$projectId
);
}
$result .= Display::url(
Display::return_icon('user.png', get_lang('AssignUser')),
"categories_add_user.php?id={$row['id']}&project_id=".$projectId
);
if (api_get_setting('ticket_allow_category_edition') === 'true') {
$result .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
"categories.php?action=delete&id={$row['id']}&project_id=".$projectId
);
}
return $result;
}
$table->set_header(0, '', false);
$table->set_header(1, get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
$table->set_header(3, get_lang('TotalTickets'), false);
$table->set_header(4, get_lang('Actions'), true);
$table->set_column_filter(4, 'modify_filter');
Display::display_header($toolName);
$items = [
[
'url' => 'categories.php?action=add&project_id='.$projectId,
'content' => Display::return_icon('new_folder.png', null, null, ICON_SIZE_MEDIUM),
],
];
echo Display::actions($items);
echo $formToString;
echo $table->return_table();
Display::display_footer();

View File

@@ -0,0 +1,82 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.plugin.ticket
*/
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$categoryId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$categoryInfo = TicketManager::getCategory($categoryId);
if (empty($categoryInfo)) {
api_not_allowed(true);
}
$project = TicketManager::getProject($projectId);
if (empty($project)) {
api_not_allowed(true);
}
$form = new FormValidator('edit', 'post', api_get_self().'?id='.$categoryId.'&project_id='.$projectId);
$form->addHeader($categoryInfo['name']);
$users = UserManager::get_user_list([], ['firstname']);
$users = array_column($users, 'complete_name', 'user_id');
$form->addElement(
'advmultiselect',
'users',
get_lang('Users'),
$users,
'style="width: 280px;"'
);
$usersAdded = TicketManager::getUsersInCategory($categoryId);
if (!empty($usersAdded)) {
$usersAdded = array_column($usersAdded, 'user_id');
}
$form->setDefaults(['users' => $usersAdded]);
// submit button
$form->addButtonSave(get_lang('Save'));
if ($form->validate()) {
$values = $form->exportValues();
TicketManager::deleteAllUserInCategory($categoryId);
TicketManager::addUsersToCategory($categoryId, $values['users']);
Display::addFlash(Display::return_message(get_lang('Updated')));
header('Location: '.api_get_self().'?id='.$categoryId.'&project_id='.$projectId);
exit;
}
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId,
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => get_lang('Projects'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => $project->getName(),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/categories.php?project_id='.$projectId,
'name' => get_lang('Categories'),
];
Display::display_header(get_lang('Users'));
$form->display();

View File

@@ -0,0 +1,42 @@
<?php
/* For licensing terms, see /license.txt */
exit;
/**
* @package chamilo.plugin.ticket
*/
require_once __DIR__.'/../inc/global.inc.php';
$userId = (int) $_GET['user_id'];
$userInfo = api_get_user_info($userId);
$coursesList = CourseManager::get_courses_list_by_user_id($userId, false, true);
$arrCourseList = [get_lang('Select')];
//Course List
foreach ($coursesList as $key => $course) {
$courseInfo = CourseManager::get_course_information($course['code']);
$arrCourseList[$courseInfo['code']] = $courseInfo['title'];
}
$userLabel = Display::tag('label', get_lang('User'), ['class' => 'control-label']);
$personName = api_get_person_name($userInfo['firstname'], $userInfo['lastname']);
$userInput = Display::tag(
'input',
'',
[
'disabled' => 'disabled',
'type' => 'text',
'value' => $personName,
]
);
$userControl = Display::div($userInput, ['class' => 'controls']);
$courseLabel = Display::tag('label', get_lang('Course'), ['class' => 'control-label']);
$courseSelect = Display::select('course_id', $arrCourseList, 0, [], false);
$courseControl = Display::div($courseSelect, ['class' => 'controls']);
$userDiv = Display::div($userLabel." ".$userControl, ['class' => 'control-group']);
$courseDiv = Display::div($courseLabel." ".$courseControl, ['class' => 'control-group']);
echo $userDiv;
echo $courseDiv;

51
main/ticket/download.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.plugin.ticket
*/
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$user_id = api_get_user_id();
if (!isset($_GET['id']) || !isset($_GET['ticket_id'])) {
api_not_allowed(true);
}
$ticket_id = (int) $_GET['ticket_id'];
$ticketInfo = TicketManager::get_ticket_detail_by_id($ticket_id);
if (empty($ticketInfo)) {
api_not_allowed(true);
}
$messageAttachment = TicketManager::getTicketMessageAttachment($_GET['id']);
if (empty($messageAttachment)) {
api_not_allowed(true);
}
if (!api_is_platform_admin()) {
$table_support_messages = Database::get_main_table(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);
$sql = "SELECT DISTINCT ticket.request_user
FROM $table_support_tickets ticket,
$table_support_messages message,
$table_support_message_attachments attch
WHERE ticket.ticket_id = message.ticket_id
AND attch.message_id = message.message_id
AND ticket.ticket_id = $ticket_id";
$rs = Database::query($sql);
$row_users = Database::fetch_array($rs, 'ASSOC');
$user_request_id = $row_users['request_user'];
if (intval($user_request_id) != $user_id) {
api_not_allowed(true);
}
}
api_download_uploaded_file(
'ticket_attachment',
$ticket_id,
$messageAttachment->getPath(),
$messageAttachment->getFilename()
);
exit;

11
main/ticket/index.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Redirects to "myticket.php".
*
* @package chamilo.plugin.ticket
*/
require_once __DIR__.'/../inc/global.inc.php';
header('Location:'.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
exit;

533
main/ticket/new_ticket.php Normal file
View File

@@ -0,0 +1,533 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
if (!api_is_platform_admin() && api_get_setting('ticket_allow_student_add') !== 'true') {
header('Location:'.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
exit;
}
api_block_anonymous_users();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$exerciseId = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? (int) $_GET['exerciseId'] : 0;
$lpId = (isset($_GET['lpId']) && !empty($_GET['lpId'])) ? (int) $_GET['lpId'] : 0;
$htmlHeadXtra[] = '<script>
function updateCourseList(sessionId) {
var $selectCourse = $("select#course_id");
$selectCourse.empty();
$.get("'.api_get_path(WEB_AJAX_PATH).'session.ajax.php", {
a: "get_courses_inside_session",
session_id : sessionId
}, function (courseList) {
$("<option>", {
value: 0,
text: "'.get_lang('Select').'"
}).appendTo($selectCourse);
if (courseList.length > 0) {
$.each(courseList, function (index, course) {
$("<option>", {
value: course.id,
text: course.name
}).appendTo($selectCourse);
});
$selectCourse.find("option[value=\''.$courseId.'\']").attr("selected",true);
$selectCourse.selectpicker("refresh");
}
}, "json");
}
function updateExerciseList(courseId, sessionId) {
var $selectExercise = $("select#exercise_id");
$selectExercise.empty();
$.get("'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php", {
a: "get_exercise_by_course",
course_id: courseId,
session_id : sessionId
}, function (exerciseList) {
$("<option>", {
value: 0,
text: "'.get_lang('Select').'"
}).appendTo($selectExercise);
if (exerciseList.length > 0) {
$.each(exerciseList, function (index, exercise) {
$("<option>", {
value: exercise.id,
text: exercise.text
}).appendTo($selectExercise);
});
$selectExercise.find("option[value=\''.$exerciseId.'\']").attr("selected",true);
}
$selectExercise.selectpicker("refresh");
}, "json");
}
function updateLpList(courseId, sessionId) {
var $selectLp = $("select#lp_id");
$selectLp.empty();
$.get("'.api_get_path(WEB_AJAX_PATH).'lp.ajax.php", {
a: "get_lp_list_by_course",
course_id: courseId,
session_id: sessionId
}, function (lpList) {
$("<option>", {
value: 0,
text: "'.get_lang('Select').'"
}).appendTo($selectLp);
if (lpList.length > 0) {
$.each(lpList, function (index, lp) {
$("<option>", {
value: lp.id,
text: lp.text
}).appendTo($selectLp);
});
$selectLp.find("option[value=\''.$lpId.'\']").attr("selected",true);
}
$selectLp.selectpicker("refresh");
}, "json");
}
$(document).ready(function() {
var $selectSession = $("select#session_id");
var $selectCourse = $("select#course_id");
$selectSession.on("change", function () {
var sessionId = parseInt(this.value, 10);
updateCourseList(sessionId);
updateExerciseList(0, sessionId);
updateLpList(0);
});
$selectCourse.on("change", function () {
var sessionId = $selectSession.val();
var courseId = parseInt(this.value, 10);
updateExerciseList(courseId, sessionId);
updateLpList(courseId);
});
var sessionId = $selectSession.val() ? $selectSession.val() : '.$sessionId.';
var courseId = $selectCourse.val() ? $selectCourse.val() : '.$courseId.';
updateCourseList(sessionId);
updateExerciseList(courseId, sessionId);
updateLpList(courseId, sessionId);
});
var counter_image = 1;
function remove_image_form(element_id) {
$("#" + element_id).remove();
counter_image = counter_image - 1;
$("#link-more-attach").css("display", "block");
}
function add_image_form() {
// Multiple filepaths for image form
var filepaths = $("#filepaths");
var new_elem, input_file, link_remove, img_remove, new_filepath_id;
if ($("#filepath_"+counter_image)) {
counter_image = counter_image + 1;
} else {
counter_image = counter_image;
}
new_elem = "filepath_"+counter_image;
$("<div/>", {
id: new_elem,
class: "controls"
}).appendTo(filepaths);
input_file = $("<input/>", {
type: "file",
name: "attach_" + counter_image,
size: 20
});
link_remove = $("<a/>", {
onclick: "remove_image_form(\'" + new_elem + "\')",
style: "cursor: pointer"
});
img_remove = $("<img/>", {
src: "'.Display::returnIconPath('delete.png').'"
});
new_filepath_id = $("#filepath_" + counter_image);
new_filepath_id.append(input_file, link_remove.append(img_remove));
if (counter_image === 6) {
var link_attach = $("#link-more-attach");
if (link_attach) {
$(link_attach).css("display", "none");
}
}
}
</script>';
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$types = TicketManager::get_all_tickets_categories($projectId, 'category.name ASC');
$htmlHeadXtra[] = '<script>
var projects = '.js_array($types, 'projects', 'project_id').'
var course_required = '.js_array($types, 'course_required', 'course_required').'
var other_area = '.js_array($types, 'other_area', 'other_area').'
var email = '.js_array($types, 'email', 'email').
'</script>';
/**
* @param $array
* @param $name
* @param $key
*
* @return string
*/
function js_array($array, $name, $key)
{
$return = "new Array(); ";
foreach ($array as $value) {
$return .= $name."['".$value['category_id']."'] ='".$value[$key]."'; ";
}
return $return;
}
function save_ticket()
{
$content = $_POST['content'];
if (!empty($_POST['phone'])) {
$content .= '<p style="color:red">&nbsp;'.get_lang('Phone').': '.Security::remove_XSS($_POST['phone']).'</p>';
}
$course_id = isset($_POST['course_id']) ? (int) $_POST['course_id'] : '';
$sessionId = isset($_POST['session_id']) ? (int) $_POST['session_id'] : '';
$category_id = isset($_POST['category_id']) ? (int) $_POST['category_id'] : '';
$exercise_id = isset($_POST['exercise_id']) ? (int) $_POST['exercise_id'] : null;
$lp_id = isset($_POST['lp_id']) ? (int) $_POST['lp_id'] : null;
$project_id = (int) $_POST['project_id'];
$subject = $_POST['subject'];
$other_area = (int) $_POST['other_area'];
$personal_email = $_POST['personal_email'];
$source = (int) $_POST['source_id'];
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
$priority = isset($_POST['priority_id']) ? (int) $_POST['priority_id'] : '';
$status = isset($_POST['status_id']) ? (int) $_POST['status_id'] : '';
$file_attachments = $_FILES;
if (TicketManager::add(
$category_id,
$course_id,
$sessionId,
$project_id,
$other_area,
$subject,
$content,
$personal_email,
$file_attachments,
$source,
$priority,
$status,
$user_id,
$exercise_id,
$lp_id
)) {
header('Location:'.api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$project_id);
exit;
} else {
Display::addFlash(Display::return_message(get_lang('ThereWasAnErrorRegisteringTheTicket')));
}
}
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId,
'name' => get_lang('MyTickets'),
];
$userId = api_get_user_id();
// Category List
$categoryList = [];
foreach ($types as $type) {
$categoryList[$type['category_id']] = $type['name'].': '.$type['description'];
}
// Status List
$statusAttributes = [
'style' => 'display: none;',
'id' => 'status_id',
'for' => 'status_id',
];
$statusList = TicketManager::getStatusList();
// Source List
$sourceList = [];
$sourceAttributes = [
'style' => 'display: none;',
'id' => 'source_id',
'for' => 'source_id',
];
$sourceList[TicketManager::SOURCE_PLATFORM] = get_lang('SrcPlatform');
if (api_is_platform_admin()) {
$sourceAttributes = [
'id' => 'source_id',
'for' => 'source_id',
];
$sourceList[TicketManager::SOURCE_EMAIL] = get_lang('SrcEmail');
$sourceList[TicketManager::SOURCE_PHONE] = get_lang('SrcPhone');
$sourceList[TicketManager::SOURCE_PRESENTIAL] = get_lang('SrcPresential');
}
// Priority List
$priorityList = TicketManager::getPriorityList();
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$form = new FormValidator(
'send_ticket',
'POST',
api_get_self().'?project_id='.$projectId,
'',
[
'enctype' => 'multipart/form-data',
]
);
$form->addElement(
'hidden',
'user_id_request',
'',
[
'id' => 'user_id_request',
]
);
$form->addElement(
'hidden',
'project_id',
$projectId
);
$form->addElement(
'hidden',
'other_area',
'',
[
'id' => 'other_area',
]
);
$form->addElement(
'hidden',
'email',
'',
[
'id' => 'email',
]
);
$form->addSelect(
'category_id',
get_lang('Category'),
$categoryList,
[
'id' => 'category_id',
'for' => 'category_id',
'style' => 'width: 562px;',
]
);
$form->addElement(
'text',
'subject',
get_lang('Subject'),
[
'id' => 'subject',
]
);
$form->addHtmlEditor(
'content',
get_lang('Message'),
false,
false,
[
'ToolbarSet' => 'Profile',
'Height' => '250',
]
);
if (api_is_platform_admin() || (api_get_configuration_value('allow_session_admin_manage_tickets_and_export_ticket_report') && api_is_session_admin())) {
$form->addSelectAjax(
'user_id',
get_lang('Assign'),
null,
['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like']
);
}
$form->addElement(
'text',
'personal_email',
get_lang('PersonalEmail'),
[
'id' => 'personal_email',
]
);
$form->addLabel(
'',
Display::div(
'',
[
'id' => 'user_request',
]
)
);
$form->addElement(
'select',
'status_id',
get_lang('Status'),
$statusList,
$statusAttributes
);
$form->addElement(
'select',
'priority_id',
get_lang('Priority'),
$priorityList,
[
'id' => 'priority_id',
'for' => 'priority_id',
]
);
$form->addElement(
'select',
'source_id',
get_lang('Source'),
$sourceList,
$sourceAttributes
);
$form->addElement(
'text',
'phone',
get_lang('Phone').' ('.get_lang('Optional').')',
[
'id' => 'phone',
]
);
$sessionList = SessionManager::get_sessions_by_user($userId);
if (api_is_platform_admin() || !empty($sessionList)) {
$sessionListToSelect = [get_lang('Select')];
// Course List
foreach ($sessionList as $sessionInfo) {
$sessionListToSelect[$sessionInfo['session_id']] = $sessionInfo['session_name'];
}
$form->addSelect('session_id', get_lang('Session'), $sessionListToSelect, ['id' => 'session_id']);
} else {
$form->addHidden('session_id', 0);
}
$form->addSelect('course_id', get_lang('Course'), [], ['id' => 'course_id']);
if (api_get_configuration_value('ticket_lp_quiz_info_add')) {
$form->addSelect('exercise_id', get_lang('Exercise'), [], ['id' => 'exercise_id']);
$form->addSelect('lp_id', get_lang('LearningPath'), [], ['id' => 'lp_id']);
}
$courseInfo = api_get_course_info();
$params = [];
if (!empty($courseInfo)) {
$params = [
'course_id' => $courseInfo['real_id'],
];
$sessionInfo = api_get_session_info(api_get_session_id());
if (!empty($sessionInfo)) {
$params['session_id'] = $sessionInfo['id'];
}
if (api_get_configuration_value('ticket_lp_quiz_info_add')) {
if ($exerciseId !== '') {
$params['exercise_id'] = $exerciseId;
}
if ($lpId !== '') {
$params['lp_id'] = $lpId;
}
}
}
$form->setDefaults($params);
$form->addElement('file', 'attach_1', get_lang('FilesAttachment'));
$form->addLabel('', '<span id="filepaths"><div id="filepath_1"></div></span>');
$form->addLabel(
'',
'<span id="link-more-attach">
<span class="btn btn-success" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</span>
</span>
('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')
'
);
$form->addElement('html', '<br/>');
$form->addElement(
'button',
'compose',
get_lang('SendMessage'),
null,
null,
null,
'btn btn-primary',
[
'id' => 'btnsubmit',
]
);
$form->addRule('content', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('category_id', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('subject', get_lang('ThisFieldIsRequired'), 'required');
if ($form->validate()) {
save_ticket();
}
Display::display_header(get_lang('ComposeMessage'));
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
);
echo '</div>';
$form->display();
Display::display_footer();

176
main/ticket/priorities.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This script is the Tickets plugin main entry point.
*
* @package chamilo.plugin.ticket
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$toolName = get_lang('Priorities');
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
$this_section = 'tickets';
Session::erase('this_section');
$table = new SortableTable(
'TicketProject',
['TicketManager', 'getPriorityCount'],
['TicketManager', 'getPriorityAdminList'],
1
);
if ($table->per_page == 0) {
$table->per_page = 20;
}
$formToString = '';
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$action = isset($_GET['action']) ? $_GET['action'] : '';
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
switch ($action) {
case 'delete':
$tickets = TicketManager::getTicketsFromCriteria(['priority' => $id]);
if (empty($tickets)) {
TicketManager::deletePriority($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
} else {
Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets'), 'warning'));
}
header("Location: ".api_get_self());
exit;
break;
case 'add':
$toolName = get_lang('Add');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/priorities.php',
'name' => get_lang('Priorities'),
];
$url = api_get_self().'?action=add';
$form = TicketManager::getPriorityForm($url);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
];
TicketManager::addPriority($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header("Location: ".api_get_self());
exit;
}
break;
case 'edit':
$toolName = get_lang('Edit');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/priorities.php',
'name' => get_lang('Priorities'),
];
$url = api_get_self().'?action=edit&id='.$id;
$form = TicketManager::getPriorityForm($url);
$item = TicketManager::getPriority($_GET['id']);
$form->setDefaults(
[
'name' => $item->getName(),
'description' => $item->getDescription(),
]
);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
];
$cat = TicketManager::updatePriority($_GET['id'], $params);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location: ".api_get_self());
exit;
}
break;
default:
break;
}
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
/**
* Build the modify-column of the table.
*
* @param int The user id
* @param string URL params to add to table links
* @param array Row of elements to alter
*
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($id, $params, $row)
{
$result = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
api_get_self()."?action=edit&id={$row['id']}"
);
$code = $row['code'];
if (!in_array($code, TicketManager::getDefaultPriorityList())) {
$result .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
api_get_self()."?action=delete&id={$row['id']}"
);
}
return $result;
}
$table->set_header(0, '', false);
$table->set_header(1, get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
$table->set_header(3, get_lang('Actions'), true);
$table->set_column_filter('3', 'modify_filter');
Display::display_header($toolName);
$items = [
'icon' => 'new_folder.png',
'url' => 'priorities.php?action=add',
'content' => get_lang('AddPriority'),
];
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
);
$sections = TicketManager::getSettingsMenuItems('priority');
array_unshift($sections, $items);
foreach ($sections as $item) {
echo Display::url(
Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
$item['url']
);
}
echo '</div>';
echo $formToString;
echo $table->return_table();
Display::display_footer();

189
main/ticket/projects.php Normal file
View File

@@ -0,0 +1,189 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This script is the Tickets plugin main entry point.
*
* @package chamilo.plugin.ticket
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
$this_section = 'tickets';
Session::erase('this_section');
$table = new SortableTable(
'TicketProject',
['TicketManager', 'getProjectsCount'],
['TicketManager', 'getProjects'],
1
);
if ($table->per_page == 0) {
$table->per_page = 20;
}
$formToString = '';
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$action = isset($_GET['action']) ? $_GET['action'] : '';
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/projects.php',
'name' => get_lang('Projects'),
];
switch ($action) {
case 'delete':
$tickets = TicketManager::getTicketsFromCriteria(['project' => $id]);
if (empty($tickets)) {
TicketManager::deleteProject($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
} else {
Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets')));
}
header("Location: ".api_get_self());
exit;
break;
case 'add':
$toolName = get_lang('Add');
$url = api_get_self().'?action=add';
$form = TicketManager::getProjectForm($url);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
];
TicketManager::addProject($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header("Location: ".api_get_self());
exit;
}
break;
case 'edit':
$item = TicketManager::getProject($id);
if (empty($item)) {
api_not_allowed(true);
}
$toolName = get_lang('Edit');
$url = api_get_self().'?action=edit&id='.$id;
$form = TicketManager::getProjectForm($url);
$form->setDefaults([
'name' => $item->getName(),
'description' => $item->getDescription(),
]);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
'sys_lastedit_datetime' => api_get_utc_datetime(),
'sys_lastedit_user_id' => api_get_user_id(),
];
TicketManager::updateProject($id, $params);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location: ".api_get_self());
exit;
}
break;
default:
break;
}
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
/**
* Build the modify-column of the table.
*
* @param int The user id
* @param string URL params to add to table links
* @param array Row of elements to alter
*
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($id, $params, $row)
{
$result = Display::url(
get_lang('Tickets'),
"tickets.php?project_id={$row['id']}",
['class' => 'btn btn-small btn-default']
);
$result .= Display::url(
get_lang('Categories'),
"categories.php?project_id={$row['id']}",
['class' => 'btn btn-default']
);
$result .= Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
"projects.php?action=edit&id={$row['id']}"
);
$result .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
"projects.php?action=delete&id={$row['id']}"
);
return $result;
}
$table->set_header(0, '', false);
$table->set_header(1, get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
$table->set_header(3, get_lang('Actions'), true);
$table->set_column_filter('3', 'modify_filter');
Display::display_header('');
$items = [
'icon' => 'new_folder.png',
'url' => 'projects.php?action=add',
'content' => get_lang('AddProject'),
];
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
);
$sections = TicketManager::getSettingsMenuItems('project');
array_unshift($sections, $items);
foreach ($sections as $item) {
echo Display::url(
Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
$item['url']
);
}
echo '</div>';
echo $formToString;
echo $table->return_table();
Display::display_footer();

323
main/ticket/report.php Normal file
View File

@@ -0,0 +1,323 @@
<?php
/* For licensing terms, see /license.txt */
exit;
use ChamiloSession as Session;
/**
* @package chamilo.plugin.ticket
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
if (!api_is_allowed_to_edit()) {
api_not_allowed();
}
$this_section = 'Reports';
Session::erase('this_section');
$htmlHeadXtra[] = '<script>
$(function() {
$( "#keyword_start_date_start" ).datepicker({ dateFormat: '."'yy-mm-dd'".' });
$( "#keyword_start_date_end" ).datepicker({ dateFormat: '."'yy-mm-dd'".' });
});
function validate() {
if( $("#keyword_start_date_start").val() != "" && $("#keyword_start_date_end").val() != ""){
datestart = $("#keyword_start_date_start").val();
dateend = $("#keyword_start_date_end").val();
dif = $.datepicker.parseDate("dd/mm/yy", datestart) - $.datepicker.parseDate("dd/mm/yy", dateend);
if(dif > 0){
alert("La fecha final no puede ser mayor a la fecha inicial");
return false;
}
}
}
function load_course_list (div_course,my_user_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
type: "GET",
url: "course_user_list.php",
data: "user_id="+my_user_id,
success: function(datos) {
$("div#user_request").html(datos);
$("#btnsubmit").attr("disabled", false);
}
});
}
</script>
<style>
div.row div.label2 {
float:left;
width:10%;
}
div.row div.formw2 {
width:90%;
float:left
}
div.ticket-form {
width: 70%;
float: center;
margin-left: 15%;
}
</style>';
$types = TicketManager::get_all_tickets_categories();
$tools = [];
$tools['todas'] = ['id' => '', 'name' => get_lang('All')];
$tools['announcement'] = ['id' => 'announcement', 'name' => get_lang('Announcement')];
// $tools[]= array('id'=>'assignment','name'=>get_lang('Assignment'));
$tools['calendar_event'] = ['id' => 'calendar_event', 'name' => get_lang('ToolCalendarEvent')];
$tools['chat'] = ['id' => 'chat', 'name' => get_lang('Chat')];
$tools['course_description'] = ['id' => 'course_description', 'name' => get_lang('CourseDescription')];
$tools['document'] = ['id' => 'document', 'name' => get_lang('Document')];
$tools['dropbox'] = ['id' => 'dropbox', 'name' => get_lang('Dropbox')];
$tools['group'] = ['id' => 'group', 'name' => get_lang('Group')];
$tools['learnpath'] = ['id' => 'learnpath', 'name' => get_lang('Learnpath')];
$tools['link'] = ['id' => 'link', 'name' => get_lang('Link')];
$tools['quiz'] = ['id' => 'quiz', 'name' => get_lang('Quiz')];
$tools['student_publication'] = ['id' => 'student_publication', 'name' => get_lang('ToolStudentPublication')];
$tools['user'] = ['id' => 'user', 'name' => get_lang('User')];
$tools['forum'] = ['id' => 'forum', 'name' => get_lang('Forum')];
/**
* This function is to show the ticket form.
*
* @global array $tools
*/
function show_form()
{
global $tools;
echo '<div class="ticket-form">';
echo '<form enctype="multipart/form-data" action="'.api_get_self().'" method="post" name="send_ticket" id="send_ticket"
onsubmit="return validate()" style="width:100%">';
$select_course = '<div id="user_request" >
</div>';
echo $select_course;
//select status
$select_tool = '<div class="row" >
<div class="label2" >'.get_lang('Tool').':</div>
<div class="formw2">';
$select_tool .= '<select style="width: 95%; " name = "tool" id="tool" >';
foreach ($tools as $tool) {
$select_tool .= "<option value = '".$tool['id']."' selected >".$tool['name']."</option>";
}
$select_tool .= "</select>";
$select_tool .= '</div></div>';
echo $select_tool;
echo '<div class="row">
<div class="label2">'.get_lang('From').':</div>
<div class="formw2"><input id="keyword_start_date_start" name="keyword_start_date_start" type="text"></div>
</div>
<div class="row">
<div class="label2"> '.get_lang('To').'</div>
<div class="formw2"><input id="keyword_start_date_end" name="keyword_start_date_end" type="text"></div>
</div>';
echo '</div>';
echo '<div class="row">
<div class="label2">
</div>
<div class="formw2">
<button class="save" name="report" type="submit" id="btnsubmit" disabled="disabled">'.get_lang('CompleteReport').'</button>
</div>
</div>';
}
/**
* Get the total number of users on the platform.
*
* @see SortableTable#get_total_number_of_items()
*/
function get_number_of_users()
{
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql .= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
}
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
u.lastname LIKE '%$keyword%' OR
concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
u.username LIKE '%$keyword%' OR
u.email LIKE '%$keyword %' OR
u.official_code LIKE '%$keyword%') ";
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->total_number_of_items;
}
/**
* Get the users to display on the current page (fill the sortable-table).
*
* @param int offset of first user to recover
* @param int Number of users to get
* @param int Column to sort on
* @param string Order (ASC,DESC)
*
* @return array
*
* @see SortableTable#get_table_data($from)
*/
function get_user_data($from, $number_of_items, $column, $direction)
{
$user_table = Database::get_main_table(TABLE_MAIN_USER);
if (api_is_western_name_order()) {
$col34 = "u.firstname AS col3,
u.lastname AS col4,";
} else {
$col34 = "u.lastname AS col3,
u.firstname AS col4,";
}
$sql = "SELECT
u.user_id AS col0,
u.official_code AS col2,
$col34
u.username AS col5,
u.email AS col6,
u.status AS col7,
u.active AS col8,
u.user_id AS col9,
u.expiration_date AS exp
FROM $user_table u ";
if (isset($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
u.lastname LIKE '%$keyword%' OR
concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
u.username LIKE '%$keyword%' OR
u.official_code LIKE '%$keyword%'
OR u.email LIKE '%$keyword%' )";
}
if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC';
}
$column = (int) $column;
$from = (int) $from;
$number_of_items = (int) $number_of_items;
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from, $number_of_items";
$res = Database::query($sql);
$users = [];
$webPath = api_get_path(WEB_PATH);
while ($user = Database::fetch_row($res)) {
$userPicture = UserManager::getUserPicture($user[0]);
$photo = '<img src="'.$userPicture.'" alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" />';
$user_id = $user[0];
$button = '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')">
<img onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" src="'.$webPath.'img/view_more_stats.gif" title="'.get_lang('Courses').'" alt="'.get_lang('Courses').'"/>
</a>&nbsp;&nbsp;';
$users[] = [
$photo,
$user[1],
$user[2],
$user[3],
$user[4],
$user[5],
$button,
];
}
return $users;
}
Display::display_header('Reports');
echo '<div class="actions">
<form action="'.api_get_self().'" method="get" name="search_simple" id="search_simple">
<input name="user_id_request" id="user_id_request" type="hidden" value="">
<span><label for="keyword">B&uacute;squeda del usuario: </label><input size="25" name="keyword" type="text" id="keyword"></span>
<span><button class="search" name="submit" type="submit">Buscar</button></span>
<div class="clear">&nbsp;</div>
</form></div>';
if (isset($_GET['keyword'])) {
$table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() || api_sort_by_first_name()) ? 3 : 2);
$table->set_header(0, '', false, 'width="18px"');
$table->set_header(0, get_lang('Photo'), false);
$table->set_header(1, get_lang('OfficialCode'));
if (api_is_western_name_order()) {
$table->set_header(2, get_lang('FirstName'));
$table->set_header(3, get_lang('LastName'));
} else {
$table->set_header(2, get_lang('LastName'));
$table->set_header(3, get_lang('FirstName'));
}
$table->set_header(4, get_lang('LoginName'));
$table->set_header(5, get_lang('Email'));
$table->set_header(6, get_lang('Action'));
$table->display();
}
if (isset($_POST['report'])) {
$course_info = api_get_course_info_by_id($course_id);
$course_id = Database::escape_string($_POST['course_id']);
$tool = Database::escape_string($_POST['tool']);
$user_id = intval($_POST['user_id_request']);
$sql = "SELECT
u.username , CONCAT(u.lastname, ' ', u.firstname) AS fullname,
DATE_SUB(access.access_date,INTERVAL 5 HOUR) AS access_date,
c.title AS course, access_tool AS tool
FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS)." access
LEFT JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u ON access.access_user_id = u.user_id
LEFT JOIN ".Database::get_main_table(TABLE_MAIN_COURSE)." c ON access.c_id = c.id
WHERE access.c_id = ".$course_info['real_id']." AND u.user_id = $user_id ";
if ($tool != '') {
$sql .= "AND access.access_tool = '$tool' ";
}
$start_date = Database::escape_string($_POST['keyword_start_date_start']);
$end_date = Database::escape_string($_POST['keyword_start_date_end']);
if ($start_date != '' || $end_date != '') {
$sql .= " HAVING ";
if ($start_date != '') {
$sql .= " access_date >= '$start_date' ";
}
if ($end_date != '') {
$sql = ($start_date == '') ? $sql : ($sql." AND ");
$sql .= " access_date <= '$end_date' ";
}
}
$result = Database::query($sql);
$table_result = new SortableTable();
$table_result->set_header(0, get_lang('User'), false);
$table_result->set_header(1, get_lang('FullUserName'), false);
$table_result->set_header(2, get_lang('Date'), false);
$table_result->set_header(3, get_lang('Course'), false);
$table_result->set_header(4, get_lang('Tool'), false);
while ($row = Database::fetch_assoc($result)) {
$row = [
$row['username'],
$row['fullname'],
$row['access_date'],
$row['course'],
get_lang($tools[$row['tool']]['name']),
];
$table_result->addRow($row);
}
$table_result->display();
} else {
show_form();
}
Display::display_footer();

34
main/ticket/settings.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script();
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets'),
];
$action = isset($_GET['action']) ? $_GET['action'] : 'projects';
Display::display_header(get_lang('Settings'));
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
);
$sections = TicketManager::getSettingsMenuItems();
foreach ($sections as $item) {
echo Display::url(
Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
$item['url']
);
}
echo '</div>';
Display::display_footer();

176
main/ticket/status.php Normal file
View File

@@ -0,0 +1,176 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This script is the Tickets plugin main entry point.
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script(true);
$toolName = get_lang('Status');
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
$this_section = 'tickets';
Session::erase('this_section');
$table = new SortableTable(
'TicketProject',
['TicketManager', 'getStatusCount'],
['TicketManager', 'getStatusAdminList'],
1
);
if ($table->per_page == 0) {
$table->per_page = 20;
}
$formToString = '';
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
$action = isset($_GET['action']) ? $_GET['action'] : '';
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/settings.php',
'name' => get_lang('Settings'),
];
switch ($action) {
case 'delete':
$tickets = TicketManager::getTicketsFromCriteria(['status' => $id]);
if (empty($tickets)) {
TicketManager::deleteStatus($id);
Display::addFlash(Display::return_message(get_lang('Deleted')));
} else {
Display::addFlash(Display::return_message(get_lang('ThisItemIsRelatedToOtherTickets'), 'warning'));
}
header("Location: ".api_get_self());
exit;
break;
case 'add':
$toolName = get_lang('Add');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/status.php',
'name' => get_lang('Status'),
];
$url = api_get_self().'?action=add';
$form = TicketManager::getStatusForm($url);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
];
TicketManager::addStatus($params);
Display::addFlash(Display::return_message(get_lang('Added')));
header("Location: ".api_get_self());
exit;
}
break;
case 'edit':
$toolName = get_lang('Edit');
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/status.php',
'name' => get_lang('Status'),
];
$url = api_get_self().'?action=edit&id='.$id;
$form = TicketManager::getStatusForm($url);
$item = TicketManager::getStatus($id);
$form->setDefaults([
'name' => $item->getName(),
'description' => $item->getDescription(),
]);
$formToString = $form->returnForm();
if ($form->validate()) {
$values = $form->getSubmitValues();
$params = [
'name' => $values['name'],
'description' => $values['description'],
];
$cat = TicketManager::updateStatus($id, $params);
Display::addFlash(Display::return_message(get_lang('Updated')));
header("Location: ".api_get_self());
exit;
}
break;
default:
break;
}
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
/**
* Build the modify-column of the table.
*
* @param int The user id
* @param string URL params to add to table links
* @param array Row of elements to alter
*
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($id, $params, $row)
{
$id = $row['id'];
$code = $row['code'];
$result = Display::url(
Display::return_icon('edit.png', get_lang('Edit')),
api_get_self()."?action=edit&id={$id}"
);
if (!in_array($code, TicketManager::getDefaultStatusList())) {
$result .= Display::url(
Display::return_icon('delete.png', get_lang('Delete')),
api_get_self()."?action=delete&id={$id}"
);
}
return $result;
}
$table->set_header(0, '', false);
$table->set_header(1, get_lang('Title'), false);
$table->set_header(2, get_lang('Description'), true, ["style" => "width:200px"]);
$table->set_header(3, get_lang('Actions'), true);
$table->set_column_filter('3', 'modify_filter');
Display::display_header($toolName);
$items = [
'icon' => 'new_folder.png',
'url' => 'status.php?action=add',
'content' => get_lang('AddStatus'),
];
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php'
);
$sections = TicketManager::getSettingsMenuItems('status');
array_unshift($sections, $items);
foreach ($sections as $item) {
echo Display::url(
Display::return_icon($item['icon'], $item['content'], [], ICON_SIZE_MEDIUM),
$item['url']
);
}
echo '</div>';
echo $formToString;
echo $table->return_table();
Display::display_footer();

View File

@@ -0,0 +1,40 @@
<?php
/* For licensing terms, see /license.txt */
require_once __DIR__.'/../inc/global.inc.php';
api_protect_admin_script();
if (!isset($_POST['ticket_id'])) {
exit;
}
$ticket_id = (int) $_POST['ticket_id'];
$history = TicketManager::get_assign_log($ticket_id);
?>
<table width="200px" border="0" cellspacing="2" cellpadding="2">
<?php
if (count($history) == 0) {
?>
<tr>
<td colspan="2"><?php echo api_ucfirst(get_lang('TicketNoHistory')); ?></td>
</tr>
<?php
}
foreach ($history as $item) {
?>
<tr>
<td width="50px">
<?php echo api_convert_encoding($item['insertuser'], 'UTF-8', $charset); ?>
</td>
<td width="80px">
<?php echo api_convert_encoding($item['assigned_date'], 'UTF-8', $charset); ?>
</td>
<td width="50px">
<?php echo api_convert_encoding($item['assignuser'], 'UTF-8', $charset); ?>
</td>
</tr>
<?php
} ?>
</table>

View File

@@ -0,0 +1,542 @@
<?php
/* For licensing terms, see /license.txt */
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$user_id = api_get_user_id();
$isAdmin = api_is_platform_admin();
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'ticket/tickets.php',
'name' => get_lang('MyTickets'),
];
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('TicketDetail')];
$disableReponseButtons = '';
$htmlHeadXtra[] = '<script>
$(function() {
$("#dialog-form").dialog({
autoOpen: false,
height: 450,
width: 600,
modal: true,
buttons: {
'.get_lang('Accept').': function(){
$("#frmResponsable").submit()
},
'.ucfirst(get_lang('Close')).': function() {
$(this).dialog("close");
}
}
});
$("a#assign").click(function () {
$( "#dialog-form" ).dialog( "open" );
});
$(".responseyes").click(function () {
if(!confirm("'.get_lang('AreYouSure').' : '.strtoupper(get_lang('Yes')).'. '.get_lang('IfYouAreSureTheTicketWillBeClosed').'")){
return false;
}
});
$(".responseno").click(function () {
if(!confirm("'.get_lang('AreYouSure').' : '.strtoupper(get_lang('No')).'")){
return false;
}
});
'.$disableReponseButtons.'
});
var counter_image = 1;
function remove_image_form(element_id) {
$("#" + element_id).remove();
counter_image = counter_image - 1;
$("#link-more-attach").css("display", "block");
}
function add_image_form() {
// Multiple filepaths for image form
var filepaths = $("#filepaths");
var new_elem, input_file, link_remove, img_remove, new_filepath_id;
if ($("#filepath_"+counter_image)) {
counter_image = counter_image + 1;
} else {
counter_image = counter_image;
}
new_elem = "filepath_"+counter_image;
$("<div/>", {
id: new_elem,
class: "controls"
}).appendTo(filepaths);
input_file = $("<input/>", {
type: "file",
name: "attach_" + counter_image,
size: 20
});
link_remove = $("<a/>", {
onclick: "remove_image_form(\'" + new_elem + "\')",
style: "cursor: pointer"
});
img_remove = $("<img/>", {
src: "'.Display::returnIconPath('delete.png').'"
});
new_filepath_id = $("#filepath_" + counter_image);
new_filepath_id.append(input_file, link_remove.append(img_remove));
if (counter_image === 6) {
var link_attach = $("#link-more-attach");
if (link_attach) {
$(link_attach).css("display", "none");
}
}
}
</script>';
$htmlHeadXtra[] = '<style>
.attachment-link {
margin: 12px;
}
#link-more-attach {
color: white;
cursor: pointer;
width: 120px;
}
</style>';
if (!isset($_REQUEST['ticket_id'])) {
header('Location: '.api_get_path(WEB_CODE_PATH).'ticket/tickets.php');
exit;
}
$userInfo = api_get_user_info();
$ticket_id = (int) $_REQUEST['ticket_id'];
$ticket = TicketManager::get_ticket_detail_by_id($ticket_id);
if (empty($ticket)) {
api_not_allowed(true);
}
$projectId = $ticket['ticket']['project_id'];
$userIsAllowInProject = TicketManager::userIsAllowInProject($userInfo, $projectId);
$allowEdition = $ticket['ticket']['assigned_last_user'] == $user_id ||
$ticket['ticket']['sys_insert_user_id'] == $user_id ||
$isAdmin;
if (false === $userIsAllowInProject) {
// make sure it's either a user assigned to this ticket, or the reporter, or and admin
if (false === $allowEdition) {
api_not_allowed(true);
}
}
$title = 'Ticket #'.$ticket['ticket']['code'];
if ($allowEdition && isset($_REQUEST['close'])) {
TicketManager::close_ticket($ticket_id, $user_id);
$ticket['ticket']['status_id'] = TicketManager::STATUS_CLOSE;
$ticket['ticket']['status'] = get_lang('Closed');
}
$messages = $ticket['messages'];
$counter = 1;
$messageToShow = '';
$formToShow = '';
foreach ($messages as $message) {
$date = Display::url(
date_to_str_ago($message['sys_insert_datetime']),
'#',
['title' => api_get_local_time($message['sys_insert_datetime']), 'class' => 'boot-tooltip']
);
$receivedMessage = '';
if (!empty($message['subject'])) {
$receivedMessage = '<b>'.get_lang('Subject').': </b> '.Security::remove_XSS($message['subject']).'<br />';
}
if (!empty($message['message'])) {
$receivedMessage = '<b>'.get_lang('Message').':</b><br />'.Security::remove_XSS($message['message']).'<br />';
}
$attachmentLinks = '';
if (isset($message['attachments'])) {
$attributeClass = [
'class' => 'attachment-link',
];
foreach ($message['attachments'] as $attach) {
$attachmentLinks .= Display::tag('div', $attach['attachment_link'], $attributeClass);
}
}
$entireMessage = $receivedMessage.$attachmentLinks;
$counterLink = Display::url('#'.$counter, api_get_self().'?ticket_id='.$ticket_id.'#note-'.$counter);
$messageToShow .= '<a id="note-'.$counter.'"> </a><h4>'.sprintf(
get_lang('UpdatedByX'),
$message['user_info']['complete_name_with_message_link']
);
$messageToShow .= ' '.$date.' <span class="pull-right">'.$counterLink.'</span></h4>';
$messageToShow .= '<hr />';
if (!empty($entireMessage)) {
$messageToShow .= Display::div(
$entireMessage,
['class' => 'well']
);
}
$counter++;
}
$subject = get_lang('ReplyShort').': '.Security::remove_XSS($ticket['ticket']['subject']);
if ($allowEdition &&
$ticket['ticket']['status_id'] != TicketManager::STATUS_FORWARDED &&
$ticket['ticket']['status_id'] != TicketManager::STATUS_CLOSE
) {
$form = getForm($ticket['ticket']);
$formToShow = $form->returnForm();
if ($form->validate()) {
$ticket_id = (int) $_POST['ticket_id'];
$messageToSend = '';
$message = isset($_POST['confirmation']) ? true : false;
$file_attachments = $_FILES;
if ($isAdmin) {
$oldUserId = $ticket['ticket']['assigned_last_user'];
if (isset($_POST['assigned_last_user']) && !empty($_POST['assigned_last_user']) &&
$_POST['assigned_last_user'] != $oldUserId
) {
TicketManager::assignTicketToUser(
$ticket_id,
$_POST['assigned_last_user']
);
$oldUserName = '-';
if (!empty($oldUserId)) {
$oldUserInfo = api_get_user_info($oldUserId);
$oldUserName = $oldUserInfo['complete_name_with_message_link'];
}
$userCompleteName = '-';
if (!empty($_POST['assigned_last_user'])) {
$userInfo = api_get_user_info(
$_POST['assigned_last_user']
);
$userCompleteName = $userInfo['complete_name_with_message_link'];
}
$messageToSend .= sprintf(
get_lang('AssignedChangeFromXToY'),
$oldUserName,
$userCompleteName
).'<br />';
}
TicketManager::updateTicket(
[
'priority_id' => (int) $_POST['priority_id'],
'status_id' => (int) $_POST['status_id'],
],
$ticket_id,
api_get_user_id()
);
if ($_POST['priority_id'] != $ticket['ticket']['priority_id']) {
$newPriority = TicketManager::getPriority(
$_POST['priority_id']
);
$newPriorityTitle = '-';
if ($newPriority) {
$newPriorityTitle = $newPriority->getName();
}
$oldPriority = TicketManager::getPriority(
$ticket['ticket']['priority_id']
);
$oldPriorityTitle = '-';
if ($oldPriority) {
$oldPriorityTitle = $oldPriority->getName();
}
$messageToSend .= sprintf(
get_lang('PriorityChangeFromXToY'),
$oldPriorityTitle,
$newPriorityTitle
).'<br />';
}
if ($_POST['status_id'] != $ticket['ticket']['status_id']) {
$newStatus = TicketManager::getStatus(
$_POST['status_id']
);
$newTitle = '-';
if ($newStatus) {
$newTitle = $newStatus->getName();
}
$oldStatus = TicketManager::getStatus(
$ticket['ticket']['status_id']
);
$oldStatusTitle = '-';
if ($oldStatus) {
$oldStatusTitle = $oldStatus->getName();
}
$messageToSend .= sprintf(
get_lang('StatusChangeFromXToY'),
$oldStatusTitle,
$newTitle
).'<br />';
}
}
$messageToSend .= $_POST['content'];
TicketManager::insertMessage(
$ticket_id,
$_POST['subject'],
$messageToSend,
$file_attachments,
$user_id,
'NOL',
$message
);
TicketManager::notifiyTicketUpdated(
$ticket_id,
(int) $ticket['ticket']['category_id'],
$messageToSend
);
Display::addFlash(Display::return_message(get_lang('Saved')));
header("Location:".api_get_self()."?ticket_id=".$ticket_id);
exit;
}
}
Display::display_header();
echo '<div class="actions">';
echo Display::url(
Display::return_icon('back.png', get_lang('Tickets'), [], ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId
);
echo '</div>';
$bold = '';
if ($ticket['ticket']['status_id'] == TicketManager::STATUS_CLOSE) {
$bold = 'style = "font-weight: bold;"';
}
$senderData = get_lang('AddedBy').' '.$ticket['usuario']['complete_name_with_message_link'];
echo '<table width="100%" >
<tr>
<td colspan="3">
<h1>'.$title.'</h1>
<h2>'.Security::remove_XSS($ticket['ticket']['subject']).'</h2>
<p>
'.$senderData.' '.
get_lang('Created').' '.
Display::url(
date_to_str_ago($ticket['ticket']['start_date_from_db']),
'#',
['title' => $ticket['ticket']['start_date'], 'class' => 'boot-tooltip']
).'. '.
get_lang('TicketUpdated').' '.
Display::url(
date_to_str_ago($ticket['ticket']['sys_lastedit_datetime_from_db']),
'#',
['title' => $ticket['ticket']['sys_lastedit_datetime'], 'class' => 'boot-tooltip']
).'
</p>
</td>
</tr>
<tr>
<td><p><b>'.get_lang('Category').': </b>'.$ticket['ticket']['name'].'</p></td>
</tr>
<tr>
<td><p '.$bold.'><b>'.get_lang('Status').':</b> '.$ticket['ticket']['status'].'</p></td>
</tr>
<tr>
<td><p><b>'.get_lang('Priority').': </b>'.$ticket['ticket']['priority'].'<p></td>
</tr>';
if (!empty($ticket['ticket']['assigned_last_user'])) {
$assignedUser = api_get_user_info($ticket['ticket']['assigned_last_user']);
echo '<tr>
<td><p><b>'.get_lang('AssignedTo').': </b>'.$assignedUser['complete_name_with_message_link'].'<p></td>
</tr>';
} else {
echo '<tr>
<td><p><b>'.get_lang('AssignedTo').': </b>-<p></td>
</tr>';
}
if ($ticket['ticket']['course_url'] != null) {
if (!empty($ticket['ticket']['session_id'])) {
$sessionInfo = api_get_session_info($ticket['ticket']['session_id']);
echo '<tr>
<td><b>'.get_lang('Session').':</b> '.$sessionInfo['name'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
echo '<tr>
<td><b>'.get_lang('Course').':</b> '.$ticket['ticket']['course_url'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
if (api_get_configuration_value('ticket_lp_quiz_info_add')) {
if (!empty($ticket['ticket']['exercise_url'])) {
echo '<tr>
<td><b>'.get_lang('Exercise').':</b> '.$ticket['ticket']['exercise_url'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
if (!empty($ticket['ticket']['lp_id'])) {
echo '<tr>
<td><b>'.get_lang('LearningPath').':</b> '.$ticket['ticket']['lp_url'].' </td>
<td></td>
<td colspan="2"></td>
</tr>';
}
}
}
echo '<tr>
<td>
<hr />
<b>'.get_lang('Description').':</b> <br />
'.Security::remove_XSS($ticket['ticket']['message']).'
<hr />
</td>
</tr>
';
echo '</table>';
echo $messageToShow;
echo $formToShow;
Display::display_footer();
/**
* @param array $ticket
*
* @return FormValidator
*/
function getForm($ticket)
{
$isAdmin = api_is_platform_admin();
global $subject;
$form = new FormValidator(
'send_ticket',
'POST',
api_get_self().'?ticket_id='.$ticket['id'],
'',
[
'enctype' => 'multipart/form-data',
'class' => 'form-horizontal',
]
);
if ($isAdmin) {
$statusList = TicketManager::getStatusList();
$form->addElement(
'select',
'status_id',
get_lang('Status'),
$statusList
);
$priorityList = TicketManager::getPriorityList();
$form->addElement(
'select',
'priority_id',
get_lang('Priority'),
$priorityList,
[
'id' => 'priority_id',
'for' => 'priority_id',
]
);
$form->addSelectAjax(
'assigned_last_user',
get_lang('Assign'),
null,
['url' => api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=get_user_like']
);
$form->setDefaults(
[
'priority_id' => $ticket['priority_id'],
'status_id' => $ticket['status_id'],
'assigned_last_user' => $ticket['assigned_last_user'],
]
);
}
$form->addElement(
'text',
'subject',
get_lang('Subject'),
[
'for' => 'subject',
'value' => $subject,
'style' => 'width: 540px;',
]
);
$form->addElement('hidden', 'ticket_id', $ticket['id']);
$form->addHtmlEditor(
'content',
get_lang('Message'),
false,
false,
[
'ToolbarSet' => 'Profile',
'Width' => '550',
'Height' => '250',
]
);
if ($isAdmin) {
$form->addElement(
'checkbox',
'confirmation',
null,
get_lang('RequestConfirmation')
);
}
$form->addElement('file', 'attach_1', get_lang('FilesAttachment'));
$form->addLabel(
'',
'<span id="filepaths"><div id="filepath_1"></div></span>'
);
$form->addLabel(
'',
'<span id="link-more-attach">
<span class="btn btn-success" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</span>
</span>
('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')'
);
$form->addElement('html', '<br/>');
$form->addButtonSend(get_lang('Send'));
return $form;
}

441
main/ticket/tickets.php Normal file
View File

@@ -0,0 +1,441 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* This script is the Tickets plugin main entry point.
*/
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
$tool_name = get_lang('Ticket');
$webLibPath = api_get_path(WEB_LIBRARY_PATH);
$htmlHeadXtra[] = '<script>
function load_history_ticket(div_course, ticket_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(object) {
$("div#"+div_course).html("<img src=\''.$webLibPath.'javascript/indicator.gif\' />"); },
type: "POST",
url: "ticket_assign_log.php",
data: "ticket_id="+ticket_id,
success: function(data) {
$("div#div_"+ticket_id).html(data);
$("div#div_"+ticket_id).attr("class","blackboard_show");
$("div#div_"+ticket_id).attr("style","");
}
});
}
function clear_course_list(div_course) {
$("div#"+div_course).html("&nbsp;");
$("div#"+div_course).hide("");
}
$(function() {
$("#advanced_search_form").css("display","none");
});
function display_advanced_search_form () {
if ($("#advanced_search_form").css("display") == "none") {
$("#advanced_search_form").css("display","block");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::returnFontAwesomeIcon('arrow-down').' '.get_lang('AdvancedSearch').'\');
} else {
$("#advanced_search_form").css("display","none");
$("#img_plus_and_minus").html(\'&nbsp;'.Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').'\');
}
}
</script>';
$this_section = 'tickets';
Session::erase('this_section');
$action = isset($_GET['action']) ? $_GET['action'] : '';
$projectId = isset($_GET['project_id']) ? (int) $_GET['project_id'] : 0;
$table = new SortableTable(
'Tickets',
['TicketManager', 'getTotalTicketsCurrentUser'],
['TicketManager', 'getTicketsByCurrentUser'],
2,
20,
'DESC'
);
$table->set_additional_parameters(['project_id' => $projectId]);
if ($table->per_page == 0) {
$table->per_page = 20;
}
switch ($action) {
case 'delete':
if (isset($_GET['ticket_id'])) {
TicketManager::deleteTicket((int)$_GET['ticket_id']);
Display::addFlash(Display::return_message(
sprintf(
get_lang('TicketDeleted'),
),
null,
false
));
header('Location: '.api_get_self().'?project_id='.$projectId);
exit;
}
break;
case 'alert':
if (!$isAdmin && isset($_GET['ticket_id'])) {
TicketManager::send_alert($_GET['ticket_id'], $user_id);
}
break;
case 'export':
$data = [
[
'#',
get_lang('Status'),
get_lang('Date'),
get_lang('LastUpdate'),
get_lang('Category'),
get_lang('CreatedBy'),
get_lang('AssignedTo'),
get_lang('Message'),
get_lang('Description'),
],
];
$datos = $table->get_clean_html();
foreach ($datos as $ticket) {
$ticket[0] = substr(strip_tags($ticket[0]), 0, 12);
$ticket_rem = [
utf8_decode(strip_tags($ticket[0])),
utf8_decode(api_html_entity_decode($ticket[1])),
utf8_decode(strip_tags($ticket[2])),
utf8_decode(strip_tags($ticket[3])),
utf8_decode(strip_tags($ticket[4])),
utf8_decode(strip_tags($ticket[5])),
utf8_decode(strip_tags($ticket[6])),
utf8_decode(strip_tags($ticket[7])),
];
$data[] = $ticket_rem;
}
Export::arrayToXls($data, get_lang('Tickets'));
exit;
break;
case 'close_tickets':
TicketManager::close_old_tickets();
break;
default:
break;
}
if (empty($projectId)) {
$projects = TicketManager::getProjectsSimple();
if (!empty($projects) && isset($projects[0])) {
$project = $projects[0];
header('Location: '.api_get_self().'?project_id='.$project['id']);
exit;
}
}
$currentUrl = api_get_self().'?project_id='.$projectId;
$user_id = api_get_user_id();
$isAllow = TicketManager::userIsAllowInProject(api_get_user_info(), $projectId);
$allowSessionAdmin = api_get_configuration_value('allow_session_admin_manage_tickets_and_export_ticket_report') && api_is_session_admin();
$isAdmin = api_is_platform_admin() || $allowSessionAdmin;
$actionRight = '';
Display::display_header(get_lang('MyTickets'));
if (!empty($projectId)) {
$getParameters = [];
if ($isAdmin) {
$getParameters = [
'keyword',
'keyword_status',
'keyword_category',
'keyword_assigned_to',
'keyword_start_date',
'keyword_unread',
'Tickets_per_page',
'Tickets_column',
'keyword_created_by',
];
}
$get_parameter = '';
foreach ($getParameters as $getParameter) {
if (isset($_GET[$getParameter])) {
$get_parameter .= "&$getParameter=".Security::remove_XSS($_GET[$getParameter]);
}
}
$getParameters = [
'Tickets_per_page',
'Tickets_column',
];
$get_parameter2 = '';
foreach ($getParameters as $getParameter) {
if (isset($_GET[$getParameter])) {
$get_parameter2 .= "&$getParameter=".Security::remove_XSS($_GET[$getParameter]);
}
}
if (isset($_GET['submit_advanced'])) {
$get_parameter .= "&submit_advanced=";
}
if (isset($_GET['submit_simple'])) {
$get_parameter .= "&submit_simple=";
}
// Select categories
$selectTypes = [];
$types = TicketManager::get_all_tickets_categories($projectId);
foreach ($types as $type) {
$selectTypes[$type['category_id']] = $type['name'];
}
$admins = UserManager::getUserListLike(
[],
['username'],
true
);
$selectAdmins = [
0 => get_lang('Unassigned'),
];
foreach ($admins as $admin) {
$selectAdmins[$admin['user_id']] = $admin['complete_name_with_username'];
}
$Createdby = UserManager::getUserListLike(
[],
['username'],
true
);
$selectcreated = [
0 => get_lang('Unassigned'),
];
foreach ($Createdby as $creator) {
$selectcreated[$creator['user_id']] = $creator['complete_name_with_username'];
}
$status = TicketManager::get_all_tickets_status();
$selectStatus = [];
foreach ($status as $stat) {
$selectStatus[$stat['id']] = $stat['name'];
}
$selectPriority = TicketManager::getPriorityList();
$selectStatusUnread = [
'' => get_lang('StatusAll'),
'yes' => get_lang('StatusUnread'),
'no' => get_lang('StatusRead'),
];
// Create a search-box
$form = new FormValidator(
'search_simple',
'get',
$currentUrl,
null,
null,
'inline'
);
$form->addText('keyword', get_lang('Keyword'), false);
$form->addButtonSearch(get_lang('Search'), 'submit_simple');
$form->addHidden('project_id', $projectId);
$advancedSearch = Display::url(
'<span id="img_plus_and_minus">&nbsp;'.
Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch'),
'javascript://',
[
'class' => 'btn btn-default advanced-parameters',
'onclick' => 'display_advanced_search_form();',
]
);
// Add link
if (api_get_setting('ticket_allow_student_add') == 'true' || api_is_platform_admin() || $allowSessionAdmin) {
$extraParams = '';
if (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) {
$extraParams .= '&exerciseId='.(int) $_GET['exerciseId'];
}
if (isset($_GET['lpId']) && !empty($_GET['lpId'])) {
$extraParams .= '&lpId='.(int) $_GET['lpId'];
}
$actionRight = Display::url(
Display::return_icon(
'add.png',
get_lang('Add'),
null,
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH).'ticket/new_ticket.php?project_id='.$projectId.'&'.api_get_cidReq().$extraParams,
['title' => get_lang('Add')]
);
}
if (api_is_platform_admin() || $allowSessionAdmin) {
$actionRight .= Display::url(
Display::return_icon(
'export_excel.png',
get_lang('Export'),
null,
ICON_SIZE_MEDIUM
),
api_get_self().'?action=export'.$get_parameter.$get_parameter2.'&project_id='.$projectId,
['title' => get_lang('Export')]
);
}
if (api_is_platform_admin()) {
$actionRight .= Display::url(
Display::return_icon(
'settings.png',
get_lang('Settings'),
null,
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH).'ticket/settings.php',
['title' => get_lang('Settings')]
);
}
echo Display::toolbarAction(
'toolbar-tickets',
[
$form->returnForm(),
$advancedSearch,
$actionRight,
]
);
$ticketLabel = get_lang('AllTickets');
$url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId;
if (!isset($_GET['keyword_assigned_to']) && !api_get_configuration_value('ticket_show_ticket_created_by_user_on_my_ticket_page')) {
$ticketLabel = get_lang('MyTickets');
$url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId.'&keyword_assigned_to='.api_get_user_id();
}
if (api_get_configuration_value('ticket_show_ticket_created_by_user_on_my_ticket_page') && !isset($_GET['keyword_created_by'])) {
$ticketLabel = get_lang('MyTickets');
$url = api_get_path(WEB_CODE_PATH).'ticket/tickets.php?project_id='.$projectId.'&keyword_created_by='.api_get_user_id();
}
$options = '';
$iconProject = Display::return_icon(
'project.png',
get_lang('Projects'),
null,
ICON_SIZE_MEDIUM
);
if ($isAdmin) {
$options .= Display::url(
$iconProject,
api_get_path(WEB_CODE_PATH).'ticket/projects.php'
);
}
$iconTicket = Display::return_icon(
'tickets.png',
$ticketLabel,
null,
ICON_SIZE_MEDIUM
);
$options .= Display::url(
$iconTicket,
$url
);
if ($isAllow) {
echo Display::toolbarAction(
'toolbar-options',
[
$options,
]
);
}
$advancedSearchForm = new FormValidator(
'advanced_search',
'get',
$currentUrl,
null,
['style' => 'display:"none"', 'id' => 'advanced_search_form']
);
$advancedSearchForm->addHidden('project_id', $projectId);
$advancedSearchForm->addHeader(get_lang('AdvancedSearch'));
$advancedSearchForm->addSelect(
'keyword_category',
get_lang('Category'),
$selectTypes,
['placeholder' => get_lang('Select')]
);
$advancedSearchForm->addDateTimePicker('keyword_start_date_start', get_lang('Created'));
$advancedSearchForm->addDateTimePicker('keyword_start_date_end', get_lang('Until'));
$advancedSearchForm->addSelect(
'keyword_created_by',
get_lang('CreatedBy'),
$selectcreated,
['placeholder' => get_lang('All')]
);
$advancedSearchForm->addSelect(
'keyword_assigned_to',
get_lang('AssignedTo'),
$selectAdmins,
['placeholder' => get_lang('All')]
);
$advancedSearchForm->addSelect(
'keyword_status',
get_lang('Status'),
$selectStatus,
['placeholder' => get_lang('Select')]
);
$advancedSearchForm->addSelect(
'keyword_priority',
get_lang('Priority'),
$selectPriority,
['placeholder' => get_lang('All')]
);
$advancedSearchForm->addText('keyword_course', get_lang('Course'), false);
$advancedSearchForm->addButtonSearch(get_lang('AdvancedSearch'), 'submit_advanced');
$advancedSearchForm->display();
} else {
if (api_get_setting('ticket_allow_student_add') === 'true') {
echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'ticket/new_ticket.php?project_id='.$projectId.'">'.
Display::return_icon('add.png', get_lang('Add'), '', '32').
'</a>';
echo '</div>';
}
}
if ($isAdmin) {
$table->set_header(0, '#', true);
$table->set_header(1, get_lang('Status'), true);
$table->set_header(2, get_lang('Date'), true);
$table->set_header(3, get_lang('LastUpdate'), true);
$table->set_header(4, get_lang('Category'), true);
$table->set_header(5, get_lang('CreatedBy'), true);
$table->set_header(6, get_lang('AssignedTo'), true);
$table->set_header(7, get_lang('Message'), true);
$table->set_header(8, get_lang('Delete'), true);
} else {
if ($isAllow == false) {
echo Display::page_subheader(get_lang('MyTickets'));
echo Display::return_message(get_lang('TicketMsgWelcome'));
}
$table->set_header(0, '#', true);
$table->set_header(1, get_lang('Status'), false);
$table->set_header(2, get_lang('Date'), true);
$table->set_header(3, get_lang('LastUpdate'), true);
$table->set_header(4, get_lang('Category'), true);
$table->set_header(5, get_lang('CreatedBy'), true);
}
$table->display();
Display::display_footer();

102
main/ticket/tutor.php Normal file
View File

@@ -0,0 +1,102 @@
<?php
/* For licensing terms, see /license.txt */
exit;
require_once __DIR__.'/../inc/global.inc.php';
require_once __DIR__.'/tutor_report.lib.php';
$htmlHeadXtra[] = '<script>
$(function() {
$(".ajax").click(function() {
var url = this.href;
var dialog = $("#dialog");
if ($("#dialog").length == 0) {
dialog = $("'.'<div id="dialog" style="display:hidden"></div>'.'").appendTo("body");
}
// load remote content
dialog.load(
url,
{},
function(responseText, textStatus, XMLHttpRequest) {
dialog.dialog({
modal : true,
width : 540,
height : 400
});
}
);
//prevent the browser to follow the link
return false;
});
});
function showContent(div){
if($("div#"+div).attr("class")=="blackboard_hide"){
$("div#"+div).attr("class","blackboard_show");
$("div#"+div).attr("style","");
}else{
$("div#"+div).attr("class","blackboard_hide");
$("div#"+div).attr("style","");
}
}
function save() {
work_id = $("#work_id").val();
forum_id = $("#forum_id").val();
rs_id = $("#rs_id").val();
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {
$("div#confirmation").html("<img src=\"'.api_get_path(WEB_LIBRARY_PATH).'javascript/indicator.gif\" />"); },
type: "POST",
url: "update_report.php",
data: "work_id="+work_id+"&forum_id="+forum_id+"&rs_id="+rs_id,
success: function(data) {
$("div#confirmation").html(data);
location.reload();
}
});
}
</script>
<style>
.blackboard_show {
float:left;
position:absolute;
border:1px solid black;
width: 350px;
background-color:white;
z-index:99; padding: 3px;
display: inline;
}
.blackboard_hide {
display: none;
}
.reports{
border:1px ;
}
.reports th {
border-bottom: 1px solid #DDDDDD;
line-height: normal;
text-align: center;
vertical-align: middle;
background-color: #F2F2F2;
}
</style>';
$course_code = api_get_course_id();
$results = initializeReport($course_code);
if (isset($_GET['action'])) {
Export::arrayToXls($results['export'], "COURSE_USER_REPORT".$course_code);
} else {
Display::display_header();
api_protect_course_script();
if (!api_is_allowed_to_edit()) {
api_not_allowed();
}
echo $results['show'];
Display::display_footer();
}

View File

@@ -0,0 +1,221 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Helper library for weekly reports.
*/
/**
* @param $course_code
*
* @return array|bool
*/
function initializeReport($course_code)
{
$course_info = api_get_course_info($course_code);
$table_reporte_semanas = Database::get_main_table('rp_reporte_semanas');
$table_students_report = Database::get_main_table('rp_students_report');
$table_semanas_curso = Database::get_main_table('rp_semanas_curso');
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$table_post = Database::get_course_table(TABLE_FORUM_POST);
$table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$course_code = Database::escape_string($course_code);
$res = Database::query("SELECT COUNT(*) as cant FROM $table_reporte_semanas WHERE course_code = '".$course_code."'");
$sqlWeeks = "SELECT semanas FROM $table_semanas_curso WHERE course_code = '$course_code'";
$resWeeks = Database::query($sqlWeeks);
$weeks = Database::fetch_object($resWeeks);
$obj = Database::fetch_object($res);
$weeksCount = (!isset($_POST['weeksNumber'])) ? (($weeks->semanas == 0) ? 7 : $weeks->semanas) : (int) $_POST['weeksNumber'];
$weeksCount = Database::escape_string($weeksCount);
Database::query("REPLACE INTO $table_semanas_curso (course_code , semanas) VALUES ('$course_code','$weeksCount')");
if (intval($obj->cant) != $weeksCount) {
if (intval($obj->cant) > $weeksCount) {
$sql = "DELETE FROM $table_reporte_semanas
WHERE week_id > $weeksCount AND course_code = '$course_code'";
Database::query($sql);
} else {
for ($i = $obj->cant + 1; $i <= $weeksCount; $i++) {
if (!Database::query("INSERT INTO $table_reporte_semanas (week_id, course_code, forum_id, work_id, quiz_id, pc_id)
VALUES ($i, '$course_code', '0', '0', '0', '0' )")) {
return false;
}
}
}
}
$sql = "REPLACE INTO $table_students_report (user_id, week_report_id, work_ok , thread_ok , quiz_ok , pc_ok)
SELECT cu.user_id, rs.id, 0, 0, 0, 0
FROM $table_course_rel_user cu
INNER JOIN $courseTable c
ON (c.id = cu.c_id)
LEFT JOIN $table_reporte_semanas rs ON c.code = rs.course_code
WHERE cu.status = 5 AND rs.course_code = '$course_code'
ORDER BY cu.user_id, rs.id";
if (!Database::query($sql)) {
return false;
} else {
$page = (!isset($_GET['page'])) ? 1 : (int) $_GET['page'];
Database::query("UPDATE $table_students_report sr SET sr.work_ok = 1
WHERE CONCAT (sr.user_id,',',sr.week_report_id)
IN (SELECT DISTINCT CONCAT(w.user_id,',',rs.id)
FROM $table_work w JOIN $table_reporte_semanas rs ON w.parent_id = rs.work_id)");
Database::query("UPDATE $table_students_report sr SET sr.thread_ok = 1
WHERE CONCAT (sr.user_id,',',sr.week_report_id)
IN (SELECT DISTINCT CONCAT(f.poster_id,',',rs.id)
FROM $table_post f JOIN $table_reporte_semanas rs ON f.thread_id = rs.forum_id)");
return showResults($course_info, $weeksCount, $page);
}
}
/**
* @param $courseInfo
* @param $weeksCount
* @param $page
*
* @return array
*/
function showResults($courseInfo, $weeksCount, $page)
{
$course_code = $courseInfo['code'];
$page = intval($page);
$weeksCount = intval($weeksCount);
$tableWeeklyReport = Database::get_main_table('rp_reporte_semanas');
$tableStudentsReport = Database::get_main_table('rp_students_report');
//$table_course_rel_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
$tableThread = Database::get_course_table(TABLE_FORUM_THREAD);
$tableWork = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$results = [];
$tableExport = [];
$sqlHeader = "SELECT rs.id as id,rs.week_id, w.title AS work_title, t.thread_title ,'EVALUATION' as eval_title ,'QUIZ' as pc_title
FROM $tableWeeklyReport rs
LEFT JOIN $tableThread t ON t.thread_id = rs.forum_id
LEFT JOIN $tableWork w ON w.id = rs.work_id
WHERE rs.course_code = '$course_code'
ORDER BY rs.week_id";
$resultHeader = Database::query($sqlHeader);
$ids = [];
$line = '<tr>
<th ></th>';
$lineHeaderExport = [null, null];
$lineHeaderExport2 = [null, ull];
while ($rowe = Database::fetch_assoc($resultHeader)) {
$lineHeaderExport[] = utf8_decode('Work'.$rowe['week_id']);
$lineHeaderExport[] = utf8_decode('Forum'.$rowe['week_id']);
//$fila_export_encabezado[] = utf8_decode('Eval'.$rowe['week_id']);
//$fila_export_encabezado[] = utf8_decode('PC'.$rowe['week_id']);
$lineHeaderExport2[] = utf8_decode($rowe['work_title']);
$lineHeaderExport2[] = utf8_decode($rowe['thread_title']);
//$fila_export_encabezado2[] = utf8_decode($rowe['eval_title']);
//$fila_export_encabezado2[] = utf8_decode($rowe['pc_title']);
$fila_export = ['Work'.$rowe['week_id'], 'Forum'.$rowe['week_id'], 'Eval'.$rowe['week_id'], 'PC'.$rowe['week_id']];
if ($rowe['week_id'] > (($page - 1) * 7) && $rowe['week_id'] <= (7 * $page)) {
$ids[$rowe['week_id']] = $rowe['id'];
$line .= '<th>
<a href="#" onClick="showContent('."'tarea".$rowe['week_id']."'".');">Work'.$rowe['week_id'].'
<div class="blackboard_hide" id="tarea'.$rowe['week_id'].'">'.$rowe['work_title'].'</div>
</a></th>';
$line .= '<th>
<a href="#" onClick="showContent('."'foro".$rowe['week_id']."'".');">Forum'.$rowe['week_id'].'
<div class="blackboard_hide" id="foro'.$rowe['week_id'].'">'.$rowe['thread_title'].'</div>
</a>
</th>';
}
}
$tableExport[] = $lineHeaderExport;
$tableExport[] = $lineHeaderExport2;
$line .= '</tr>';
$html = '<form action="tutor.php" name="semanas" id="semanas" method="POST">
<div class="row">
'.get_lang('SelectWeeksSpan').'
<select name="weeksNumber" id="weeksNumber" onChange="submit();">
<option value="7" '.(($weeksCount == 7) ? 'selected="selected"' : "").'>7 weeks</option>
<option value="14" '.(($weeksCount == 14) ? 'selected="selected"' : "").'>14 weeks</option>
</select>';
if ($weeksCount == 14) {
$html .= '<span style="float:right;"><a href="tutor.php?page='.(($page == 1) ? 2 : 1).'">'.(($page == 1) ? "Siguiente" : "Anterior").'</a></span>';
}
$html .= '<span style="float:right;"><a href="'.api_get_self().'?action=export'.$get_parameter.$get_parameter2.'">'.Display::return_icon('export_excel.png', get_lang('Export'), '', '32').'</a></span>';
$html .= '</form>';
$html .= '<table class="reports">';
$html .= '<tr>
<th ></th>';
for ($i = (7 * $page - 6); $i <= $page * 7; $i++) {
$html .= '<th colspan="2">Week '.$i.'<a href="assign_tickets.php?id='.$ids[$i].'" class="ajax">'.Display::return_icon('edit.png', get_lang('Edit'), ['width' => '16', 'height' => '16'], 22).'</a></th>';
}
$html .= '</tr>';
$html .= $line;
$sql = "SELECT u.username , u.user_id , CONCAT(u.lastname,' ', u.firstname ) as fullname , rs.week_id , sr.work_ok ,sr.thread_ok , sr.quiz_ok , sr.pc_ok , rs.course_code
FROM $tableStudentsReport sr
JOIN $tableWeeklyReport rs ON sr.week_report_id = rs.id
JOIN $tableUser u ON u.user_id = sr.user_id
WHERE rs.course_code = '$course_code'
ORDER BY u.lastname , u.username , rs.week_id
";
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$resultadose[$row['username']][$row['week_id']] = $row;
if ($row['week_id'] > (($page - 1) * 7) && $row['week_id'] <= (7 * $page)) {
$results[$row['username']][$row['week_id']] = $row;
if (count($results[$row['username']]) == 7) {
$html .= showStudentResult($results[$row['username']], $page);
}
}
if (count($resultadose[$row['username']]) == $weeksCount) {
$tableExport[] = showStudentResultExport($resultadose[$row['username']], $weeksCount);
}
}
$html .= '
</table>';
return ['show' => $html, 'export' => $tableExport];
}
/**
* @param $datos
* @param $pagina
*
* @return string
*/
function showStudentResult($datos, $pagina)
{
$inicio = (7 * $pagina - 6);
$fila = '<tr>';
$fila .= '<td><a href="'.api_get_path(WEB_CODE_PATH).'user/userInfo.php?'.api_get_cidreq().'&uInfo='.$datos[$inicio]['user_id'].'">'.$datos[$inicio]['username'].'</a></td>';
foreach ($datos as $dato) {
$fila .= '<td align="center">'.(($dato['work_ok'] == 1) ? Display::return_icon('check.png') : Display::return_icon('aspa.png')).'</td>';
$fila .= '<td align="center">'.(($dato['thread_ok'] == 1) ? Display::return_icon('check.png') : Display::return_icon('aspa.png')).'</td>';
}
$fila .= '</tr>';
return $fila;
}
/**
* @param $data
* @param $numero_semanas
*
* @return array
*/
function showStudentResultExport($data, $numero_semanas)
{
$fila = [];
$fila[] = utf8_decode($data[1]['username']);
$fila[] = utf8_decode($data[1]['fullname']);
foreach ($data as $line) {
$fila[] = ($line['work_ok'] == 1) ? get_lang('Yes') : get_lang('No');
$fila[] = ($line['thread_ok'] == 1) ? get_lang('Yes') : get_lang('No');
}
return $fila;
}

View File

@@ -0,0 +1,23 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.plugin.ticket
*/
exit;
require_once __DIR__.'/../inc/global.inc.php';
$work_id = (int) $_POST['work_id'];
$forum_id = (int) $_POST['forum_id'];
$rs_id = (int) $_POST['rs_id'];
api_protect_course_script();
if (!api_is_allowed_to_edit()) {
echo Display::return_message(get_lang("DeniedAccess"), 'error');
} else {
$sql = "UPDATE ".Database::get_main_table('rp_reporte_semanas')."
SET work_id = $work_id, forum_id = $forum_id
WHERE id = $rs_id";
Database::query($sql);
echo Display::return_message(get_lang('Updated'), 'confirm');
}