$(function() {
if ($("#div_result").html() !== undefined && $("#div_result").html().length == 0) {
$("#div_result").html("0");
}
$(".thematic_advance_actions, .thematic_tools ").hide();
$(".thematic_content").mouseover(function() {
var id = parseInt(this.id.split("_")[3]);
$("#thematic_id_content_"+id ).show();
});
$(".thematic_content").mouseleave(function() {
var id = parseInt(this.id.split("_")[3]);
$("#thematic_id_content_"+id ).hide();
});
$(".thematic_advance_content").mouseover(function() {
var id = parseInt(this.id.split("_")[4]);
$("#thematic_advance_tools_"+id ).show();
});
$(".thematic_advance_content").mouseleave(function() {
var id = parseInt(this.id.split("_")[4]);
$("#thematic_advance_tools_"+id ).hide();
});
});
function check_per_attendance(obj) {
if (obj.checked) {
$("#div_datetime_by_attendance").show();
$("#div_custom_datetime").hide();
} else {
$("#div_datetime_by_attendance").hide();
$("#div_custom_datetime").show();
}
}
function check_per_custom_date(obj) {
if (obj.checked) {
$("#div_custom_datetime").show();
$("#div_datetime_by_attendance").hide();
} else {
$("#div_custom_datetime").hide();
$("#div_datetime_by_attendance").show();
}
}
function datetime_by_attendance(attendance_id, thematic_advance_id) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
type: "GET",
url: "'.$url.'",
data: "attendance_id="+attendance_id+"&thematic_advance_id="+thematic_advance_id,
success: function(data) {
$("#div_datetime_attendance").html(data);
if (thematic_advance_id == 0) {
$("#from_attendance option:first").attr("checked", true);
$("#div_datetime_by_attendance").show();
$("#div_custom_datetime").hide();
}
}
});
}
function update_done_thematic_advance(selected_value) {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(myObject) {},
type: "GET",
url: "'.api_get_path(WEB_AJAX_PATH).'thematic.ajax.php?a=update_done_thematic_advance",
data: "thematic_advance_id="+selected_value,
success: function(data) {
$("#div_result").html(data);
}
});
// clean all radios
for (var i=0; i< $(".done_thematic").length;i++) {
var id_radio_thematic = $(".done_thematic").get(i).id;
$("#td_"+id_radio_thematic).css({"background-color":"#FFF"});
}
// set background to previous radios
for (var i=0; i < $(".done_thematic").length;i++) {
var id_radio_thematic = $(".done_thematic").get(i).id;
$("#td_"+id_radio_thematic).css({"background-color":"#E5EDF9"});
if ($(".done_thematic").get(i).value == selected_value) {
break;
}
}
}
';
$attendance = new Attendance();
// get data for attendance input select
$attendance_list = $attendance->getAttendanceList($course, $session);
$attendance_select = [];
$attendance_select[0] = get_lang('Select an attendance');
foreach ($attendance_list as $attendanceEntity) {
$attendance_select[$attendanceEntity->getIid()] = $attendanceEntity->getName();
}
$token = Security::get_token();
$url_token = '&sec_token='.$token;
$user_info = api_get_user_info();
$params = '&'.api_get_cidreq();
if (isset($_POST['action']) && 'thematic_delete_select' === $_POST['action']) {
$action = 'thematic_delete_select';
}
if (isset($_GET['isStudentView']) && 'true' === $_GET['isStudentView']) {
$action = 'thematic_details';
}
$interbreadcrumb[] = [
'url' => $currentUrl,
'name' => get_lang('Thematic control'),
];
$actionLeft = '';
// instance thematic object for using like library here
$thematicManager = new Thematic();
$thematicEntity = null;
$repo = Container::getThematicRepository();
if (!empty($thematicId)) {
/** @var CThematic $thematicEntity */
$thematicEntity = $repo->find($thematicId);
}
$cleanThematicTitle = null !== $thematicEntity ? strip_tags($thematicEntity->getTitle()) : null;
// get default thematic plan title
$default_thematic_plan_title = $thematicManager->get_default_thematic_plan_title();
$tpl = new Template(get_lang('Thematic control'));
// Dispatch actions to controller
switch ($action) {
case 'thematic_add':
case 'thematic_edit':
if (empty($thematicId)) {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('New thematic section')];
} else {
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit thematic section')];
}
if ('POST' === $requestMethod && '' !== trim($_POST['title']) &&
api_is_allowed_to_edit(null, true)
) {
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$thematicManager->thematicSave($thematicId, $title, $content, $course, $session);
Display::addFlash(Display::return_message(get_lang('Update successful')));
header('Location: '.$currentUrl);
exit;
break;
} else {
// Display form
$form = new FormValidator('thematic_add', 'POST', 'index.php?action=thematic_add&'.api_get_cidreq());
if ('thematic_edit' === $action) {
$form->addHeader(get_lang('Edit thematic section'));
}
$form->addHidden('sec_token', $token);
$form->addHidden('action', $action);
if (!empty($thematicId)) {
$form->addHidden('thematic_id', $thematicId);
}
if ('true' === api_get_setting('editor.save_titles_as_html')) {
$form->addHtmlEditor(
'title',
get_lang('Title'),
true,
false,
['ToolbarSet' => 'TitleAsHtml']
);
} else {
$form->addText('title', get_lang('Title'), true, ['size' => '50']);
}
$form->addHtmlEditor(
'content',
get_lang('Content'),
false,
false,
['ToolbarSet' => 'Basic', 'Height' => '150']
);
$form->addButtonSave(get_lang('Save'));
if (!empty($thematicEntity)) {
if (api_get_session_id()) {
/*if ($thematic['session_id'] != api_get_session_id()) {
$show_form = false;
echo Display::return_message(get_lang('NotAllowedClickBack'), 'error', false);
}*/
}
// set default values
$default['title'] = $thematicEntity->getTitle();
$default['content'] = $thematicEntity->getContent();
$form->setDefaults($default);
}
$content = $form->returnForm();
}
break;
case 'thematic_copy':
// Copy a thematic to a session
$thematicManager->copy($thematicId);
header('Location: '.$currentUrl);
exit;
break;
case 'thematic_delete_select':
if ('POST' === $requestMethod && api_is_allowed_to_edit(null, true)) {
$thematicManager->delete($_POST['id']);
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
header('Location: '.$currentUrl);
exit;
break;
case 'thematic_delete':
// Delete a thematic
if (!empty($thematicId) && api_is_allowed_to_edit(null, true)) {
$thematicManager->delete($thematicId);
Display::addFlash(Display::return_message(get_lang('Deleted')));
}
header('Location: '.$currentUrl);
exit;
break;
case 'thematic_import':
$csv_import_array = Import::csv_reader($_FILES['file']['tmp_name'], false);
if (isset($_POST['replace']) && $_POST['replace']) {
// Remove current thematic.
$list = $thematicManager->getThematicList($course, $session);
foreach ($list as $id) {
$thematicManager->delete($id);
}
}
// Import the progress.
$currentThematic = null;
foreach ($csv_import_array as $key => $item) {
if (!$key) {
continue;
}
switch ($item[0]) {
case 'title':
$currentThematic = $thematicManager->thematicSave(null, $item[1], $item[2], $course, $session);
$description_type = 1;
break;
case 'plan':
$thematicManager->thematicPlanSave($currentThematic, $item[1], $item[2], $description_type);
$description_type++;
break;
case 'progress':
$thematicManager->thematicAdvanceSave(
$currentThematic,
null,
null,
$item[3],
$item[1],
$item[2]
);
break;
}
}
Display::addFlash(Display::return_message(get_lang('Import')));
header('Location: '.$currentUrl);
exit;
break;
case 'thematic_import_select':
$actionLeft = '';
$actionLeft .= Display::getMdiIcon(
ActionIcon::BACK,
'ch-tool-icon',
null,
ICON_SIZE_MEDIUM,
get_lang('Back to').' '.get_lang('Thematic view with details')
);
$actionLeft .= '';
// Create form to upload csv file.
$form = new FormValidator(
'thematic_import',
'POST',
'index.php?action=thematic_import&'.api_get_cidreq().$url_token
);
$form->addElement('header', get_lang('Import course progress'));
$form->addElement('file', 'file');
$form->addElement('checkbox', 'replace', null, get_lang('Delete all course progress'));
$form->addButtonImport(get_lang('Import'), 'SubmitImport');
$content = $form->returnForm();
break;
case 'moveup':
if (!api_is_allowed_to_edit(null, true)) {
api_not_allowed();
}
$thematicManager->moveThematic('up', $thematicId, $course, $session);
header('Location: '.$currentUrl);
exit;
break;
case 'movedown':
if (!api_is_allowed_to_edit(null, true)) {
api_not_allowed();
}
$thematicManager->moveThematic('down', $thematicId, $course, $session);
header('Location: '.$currentUrl);
exit;
break;
case 'thematic_export':
$list = $thematicManager->getThematicList($course, $session);
$csv = [];
$csv[] = ['type', 'data1', 'data2', 'data3'];
foreach ($list as $thematicEntity) {
$csv[] = ['title', strip_tags($thematicEntity->getTitle()), strip_tags($thematicEntity->getContent())];
$data = $thematicEntity->getPlans();
if (!empty($data)) {
foreach ($data as $plan) {
if (empty($plan->getDescription())) {
continue;
}
$csv[] = [
'plan',
strip_tags($plan->getTitle()),
strip_tags($plan->getDescription()),
];
}
}
$data = $thematicEntity->getAdvances();
if (!empty($data)) {
foreach ($data as $advance) {
$csv[] = [
'progress',
strip_tags(api_get_local_time($advance->getStartDate())),
strip_tags($advance->getDuration()),
strip_tags($advance->getContent()),
];
}
}
}
Export::arrayToCsv($csv);
exit;
break;
case 'export_documents':
case 'thematic_export_pdf':
$pdfOrientation = api_get_setting('document.thematic_pdf_orientation');
$view = new Template('', false, false, false, true, false, false);
$list = $thematicManager->getThematicList($course, $session);
$view->assign('data', $list);
$template = $view->get_template('course_progress/pdf_general_thematic.tpl');
$format = 'portrait' !== $pdfOrientation ? 'A4-L' : 'A4-P';
$orientation = 'portrait' !== $pdfOrientation ? 'L' : 'P';
$fileName = get_lang('Thematic').'-'.api_get_local_time();
$title = get_lang('Thematic');
$signatures = ['Drh', 'Teacher', 'Date'];
if ('export_documents' === $action) {
$pdf = new PDF(
$format,
$orientation,
[
'filename' => $fileName,
'pdf_title' => $fileName,
'add_signatures' => $signatures,
]
);
$pdf->exportFromHtmlToDocumentsArea($view->fetch($template), $fileName, $courseId);
header('Location: '.$currentUrl);
exit;
}
Export::export_html_to_pdf(
$view->fetch($template),
[
'filename' => $fileName,
'pdf_title' => $title,
'add_signatures' => $signatures,
'format' => $format,
'orientation' => $orientation,
]
);
break;
case 'export_single_thematic':
case 'export_single_documents':
$view = new Template('', false, false, false, true, false, false);
$view->assign('thematic', $thematicEntity);
$template = $view->get_template('course_progress/pdf_single_thematic.tpl');
$pdfOrientation = api_get_setting('document.thematic_pdf_orientation');
$format = 'portrait' !== $pdfOrientation ? 'A4-L' : 'A4-P';
$orientation = 'portrait' !== $pdfOrientation ? 'L' : 'P';
$title = get_lang('Thematic').'-'.$thematicEntity->getTitle();
$fileName = $title.'-'.api_get_local_time();
$signatures = ['Drh', 'Teacher', 'Date'];
if ('export_single_documents' === $action) {
$pdf = new PDF(
$format,
$orientation,
[
'filename' => $fileName,
'pdf_title' => $fileName,
'add_signatures' => $signatures,
]
);
$pdf->exportFromHtmlToDocumentsArea(
$view->fetch($template),
$fileName,
$courseId
);
header('Location: '.$currentUrl);
exit;
}
Export::export_html_to_pdf(
$view->fetch($template),
[
'filename' => $fileName,
'pdf_title' => $title,
'add_signatures' => $signatures,
'format' => $format,
'orientation' => $orientation,
]
);
break;
case 'thematic_details':
$actionLeft = ''.
Display::getMdiIcon('progress-star', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('New thematic section')).'';
$actionLeft .= ''.
Display::getMdiIcon('file-delimited', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Import course progress')).'';
$actionLeft .= ''.
Display::getMdiIcon(ActionIcon::EXPORT_CSV, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export course progress')).'';
$actionLeft .= ''.
Display::getMdiIcon(ActionIcon::EXPORT_PDF, 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export to PDF')).'';
/*$actionLeft .= Display::url(
Display::getMdiIcon('export_to_documents', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Export latest version of this page to Documents')),
api_get_self().'?'.api_get_cidreq().'&'.http_build_query(['action' => 'export_documents']).$url_token
);*/
$total_average_of_advances = null;
$tpl->assign('token', $url_token);
$tpl->assign('is_allowed_to_edit', $isTeacher);
$toolbar = null;
$last_done_thematic_advance = null;
if ($thematicEntity) {
$thematic_data[$thematicId] = $thematicEntity;
$data['total_average_of_advances'] = $thematicManager->get_average_of_advances_by_thematic($thematicEntity);
} else {
$thematic_data = $thematicManager->getThematicList($course, $session);
//$max_thematic_item = $thematicManager->get_max_thematic_item($course, $session);
$max_thematic_item = 0;
$last_done_thematic_advance = $thematicManager->get_last_done_thematic_advance($course, $session);
$total_average_of_advances = $thematicManager->get_total_average_of_thematic_advances($course, $session);
}
// Second column
//$thematic_plan_data = $thematicManager->get_thematic_plan_data();
// Third column
//$thematic_advance_data = $thematicManager->get_thematic_advance_list(null, true);
if (!empty($message) && !empty($total_average_of_advances)) {
$tpl->assign('message', $message);
}
$tpl->assign('score_progress', $total_average_of_advances);
if (isset($last_id) && $last_id) {
$link_to_thematic_plan = ''.
Display::getMdiIcon('progress-check', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Thematic plan')).'';
$link_to_thematic_advance = ''.
Display::getMdiIcon('progress-clock', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Thematic advance')).'';
Display::addFlash(
Display::return_message(
get_lang('Thematic section has been created successfully').'
'.sprintf(
get_lang('Now you should add thematic plan %s and thematic advance %s'),
$link_to_thematic_plan,
$link_to_thematic_advance
),
'confirmation',
false
)
);
}
if (empty($thematicId)) {
// display information
$text = ''.get_lang('Information').': ';
$text .= get_lang('Thematic view with details');
$message = Display::return_message($text, 'info', false);
}
$list = [];
$listThematic = [];
$extra = [];
$noData = '';
// Display thematic data
if (!empty($thematic_data)) {
/** @var CThematic $thematic */
foreach ($thematic_data as $thematic) {
$id = $thematic->getIid();
$session_star = '';
if (api_is_allowed_to_edit(null, true)) {
/*if (api_get_session_id() == $thematic->getSessionId()) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
}*/
}
//@todo add a validation in order to load or not course thematics in the session thematic
$toolbarThematic = '';
if (api_is_allowed_to_edit(null, true)) {
// Thematic title
$toolbarThematic = Display::url(
Display::getMdiIcon('disc', 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Copy')),
'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$id.$params.$url_token,
['class' => 'btn btn--plain']
);
if (0 == api_get_session_id()) {
if ($thematic->getDisplayOrder() > 1) {
$toolbarThematic .= ' '.
Display::getMdiIcon(ActionIcon::UP, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Up')).'';
} else {
$toolbarThematic .= '