Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 59 additions & 37 deletions main/session/resume_session.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,35 @@
$action = isset($_GET['action']) ? $_GET['action'] : null;
$url_id = api_get_current_access_url_id();

// Course DRAG & DROP via AJAX
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'reorder_courses') {
api_protect_admin_script(true);
$order = $_POST['order'] ?? [];
if (!empty($order) && is_array($order)) {
foreach ($order as $position => $courseId) {
$qb = $em->createQueryBuilder();
$qb->update('ChamiloCoreBundle:SessionRelCourse', 'src')
->set('src.position', ':position')
->where('src.session = :session')
->andWhere('src.course = :course')
->setParameter('position', $position + 1)
->setParameter('session', $sessionId)
->setParameter('course', $courseId)
->getQuery()
->execute();
}
echo json_encode(['success' => true]);
exit;
}
}

switch ($action) {
case 'export_certified_course_users':
$courseCode = $_GET['course_code'] ?? null;
if (!empty($courseCode)) {
SessionManager::exportCourseSessionReport($sessionId, $courseCode);
}
break;
case 'move_up':
SessionManager::moveUp($sessionId, $_GET['course_id']);
header('Location: resume_session.php?id_session='.$sessionId);
exit;
break;
case 'move_down':
SessionManager::moveDown($sessionId, $_GET['course_id']);
header('Location: resume_session.php?id_session='.$sessionId);
exit;
break;
case 'add_user_to_url':
$user_id = $_REQUEST['user_id'];
$result = UrlManager::add_user_to_url($user_id, $url_id);
Expand Down Expand Up @@ -167,12 +179,14 @@
$courseListToShow = Display::page_subheader(get_lang('CourseList').$url);

$courseListToShow .= '<table id="session-list-course" class="table table-hover table-striped data_table">
<thead>
<tr>
<th></th>
<th width="35%">'.get_lang('CourseTitle').'</th>
<th width="30%">'.get_lang('CourseCoach').'</th>
<th width="10%">'.get_lang('UsersNumber').'</th>
<th width="25%">'.get_lang('Actions').'</th>
</tr>';
</tr></thead><tbody id="sortable-course-list">';

if ($session->getNbrCourses() === 0) {
$courseListToShow .= '<tr>
Expand Down Expand Up @@ -229,36 +243,14 @@
}
}

$orderButtons = '';
if (SessionManager::orderCourseIsEnabled()) {
$orderButtons = Display::url(
Display::return_icon(
!$count ? 'up_na.png' : 'up.png',
get_lang('MoveUp')
),
!$count
? '#'
: api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up'
);

$orderButtons .= Display::url(
Display::return_icon(
$count + 1 == count($courses) ? 'down_na.png' : 'down.png',
get_lang('MoveDown')
),
$count + 1 == count($courses)
? '#'
: api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down'
);
}

$courseUrl = api_get_course_url($course->getCode(), $sessionId);
$courseBaseUrl = api_get_course_url($course->getCode());

// hide_course_breadcrumb the parameter has been added to hide the name
// of the course, that appeared in the default $interbreadcrumb
$courseItem .= '<tr>
<td class="title">'
$courseItem .= '<tr data-course-id="'.$course->getId().'">';
$courseItem .= '<td class="handle" style="cursor:move;text-align:center;width:30px;"><span style="font-size:1.4em;">&#9776;</span></td>';
$courseItem .= '<td class="title">'
.Display::url(
$course->getTitle().' ('.$course->getVisualCode().')',
$courseUrl
Expand All @@ -281,7 +273,6 @@
$codePath.'admin/skill_rel_course.php?session_id='.$sessionId.'&course_id='.$course->getId()
);
}
$courseItem .= $orderButtons;

$courseItem .= Display::url(
Display::return_icon('new_user.png', get_lang('AddUsers')),
Expand Down Expand Up @@ -495,6 +486,37 @@
$programmedAnnouncement = $programmedAnnouncement->allowed();

$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
$htmlHeadXtra[] = <<<EOD
<script>
$(function() {
$("#sortable-course-list").sortable({
handle: '.handle',
placeholder: "ui-sortable-placeholder",
update: function(event, ui) {
var order = [];
$("#sortable-course-list tr").each(function() {
order.push($(this).data('course-id'));
});
$.ajax({
url: window.location.pathname + window.location.search,
method: "POST",
data: {
action: "reorder_courses",
order: order
},
success: function(response) {
// Optionnel : affiche un message
}
});
}
}).disableSelection();
});
</script>
<style>
.ui-sortable-placeholder { background: #fffae6; height:40px; }
.handle { cursor:move; }
</style>
EOD;

$tpl = new Template($tool_name);
$tpl->assign('session_header', $sessionHeader);
Expand Down
Loading