|
56 | 56 | $action = isset($_GET['action']) ? $_GET['action'] : null;
|
57 | 57 | $url_id = api_get_current_access_url_id();
|
58 | 58 |
|
| 59 | +// Course DRAG & DROP via AJAX |
| 60 | +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] == 'reorder_courses') { |
| 61 | + api_protect_admin_script(true); |
| 62 | + $order = $_POST['order'] ?? []; |
| 63 | + if (!empty($order) && is_array($order)) { |
| 64 | + foreach ($order as $position => $courseId) { |
| 65 | + $qb = $em->createQueryBuilder(); |
| 66 | + $qb->update('ChamiloCoreBundle:SessionRelCourse', 'src') |
| 67 | + ->set('src.position', ':position') |
| 68 | + ->where('src.session = :session') |
| 69 | + ->andWhere('src.course = :course') |
| 70 | + ->setParameter('position', $position + 1) |
| 71 | + ->setParameter('session', $sessionId) |
| 72 | + ->setParameter('course', $courseId) |
| 73 | + ->getQuery() |
| 74 | + ->execute(); |
| 75 | + } |
| 76 | + echo json_encode(['success' => true]); |
| 77 | + exit; |
| 78 | + } |
| 79 | +} |
| 80 | + |
59 | 81 | switch ($action) {
|
60 | 82 | case 'export_certified_course_users':
|
61 | 83 | $courseCode = $_GET['course_code'] ?? null;
|
62 | 84 | if (!empty($courseCode)) {
|
63 | 85 | SessionManager::exportCourseSessionReport($sessionId, $courseCode);
|
64 | 86 | }
|
65 | 87 | break;
|
66 |
| - case 'move_up': |
67 |
| - SessionManager::moveUp($sessionId, $_GET['course_id']); |
68 |
| - header('Location: resume_session.php?id_session='.$sessionId); |
69 |
| - exit; |
70 |
| - break; |
71 |
| - case 'move_down': |
72 |
| - SessionManager::moveDown($sessionId, $_GET['course_id']); |
73 |
| - header('Location: resume_session.php?id_session='.$sessionId); |
74 |
| - exit; |
75 |
| - break; |
76 | 88 | case 'add_user_to_url':
|
77 | 89 | $user_id = $_REQUEST['user_id'];
|
78 | 90 | $result = UrlManager::add_user_to_url($user_id, $url_id);
|
|
167 | 179 | $courseListToShow = Display::page_subheader(get_lang('CourseList').$url);
|
168 | 180 |
|
169 | 181 | $courseListToShow .= '<table id="session-list-course" class="table table-hover table-striped data_table">
|
| 182 | +<thead> |
170 | 183 | <tr>
|
| 184 | + <th></th> |
171 | 185 | <th width="35%">'.get_lang('CourseTitle').'</th>
|
172 | 186 | <th width="30%">'.get_lang('CourseCoach').'</th>
|
173 | 187 | <th width="10%">'.get_lang('UsersNumber').'</th>
|
174 | 188 | <th width="25%">'.get_lang('Actions').'</th>
|
175 |
| -</tr>'; |
| 189 | +</tr></thead><tbody id="sortable-course-list">'; |
176 | 190 |
|
177 | 191 | if ($session->getNbrCourses() === 0) {
|
178 | 192 | $courseListToShow .= '<tr>
|
|
229 | 243 | }
|
230 | 244 | }
|
231 | 245 |
|
232 |
| - $orderButtons = ''; |
233 |
| - if (SessionManager::orderCourseIsEnabled()) { |
234 |
| - $orderButtons = Display::url( |
235 |
| - Display::return_icon( |
236 |
| - !$count ? 'up_na.png' : 'up.png', |
237 |
| - get_lang('MoveUp') |
238 |
| - ), |
239 |
| - !$count |
240 |
| - ? '#' |
241 |
| - : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up' |
242 |
| - ); |
243 |
| - |
244 |
| - $orderButtons .= Display::url( |
245 |
| - Display::return_icon( |
246 |
| - $count + 1 == count($courses) ? 'down_na.png' : 'down.png', |
247 |
| - get_lang('MoveDown') |
248 |
| - ), |
249 |
| - $count + 1 == count($courses) |
250 |
| - ? '#' |
251 |
| - : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down' |
252 |
| - ); |
253 |
| - } |
254 |
| - |
255 | 246 | $courseUrl = api_get_course_url($course->getCode(), $sessionId);
|
256 | 247 | $courseBaseUrl = api_get_course_url($course->getCode());
|
257 | 248 |
|
258 | 249 | // hide_course_breadcrumb the parameter has been added to hide the name
|
259 | 250 | // of the course, that appeared in the default $interbreadcrumb
|
260 |
| - $courseItem .= '<tr> |
261 |
| - <td class="title">' |
| 251 | + $courseItem .= '<tr data-course-id="'.$course->getId().'">'; |
| 252 | + $courseItem .= '<td class="handle" style="cursor:move;text-align:center;width:30px;"><span style="font-size:1.4em;">☰</span></td>'; |
| 253 | + $courseItem .= '<td class="title">' |
262 | 254 | .Display::url(
|
263 | 255 | $course->getTitle().' ('.$course->getVisualCode().')',
|
264 | 256 | $courseUrl
|
|
281 | 273 | $codePath.'admin/skill_rel_course.php?session_id='.$sessionId.'&course_id='.$course->getId()
|
282 | 274 | );
|
283 | 275 | }
|
284 |
| - $courseItem .= $orderButtons; |
285 | 276 |
|
286 | 277 | $courseItem .= Display::url(
|
287 | 278 | Display::return_icon('new_user.png', get_lang('AddUsers')),
|
|
495 | 486 | $programmedAnnouncement = $programmedAnnouncement->allowed();
|
496 | 487 |
|
497 | 488 | $htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
|
| 489 | +$htmlHeadXtra[] = <<<EOD |
| 490 | +<script> |
| 491 | +$(function() { |
| 492 | + $("#sortable-course-list").sortable({ |
| 493 | + handle: '.handle', |
| 494 | + placeholder: "ui-sortable-placeholder", |
| 495 | + update: function(event, ui) { |
| 496 | + var order = []; |
| 497 | + $("#sortable-course-list tr").each(function() { |
| 498 | + order.push($(this).data('course-id')); |
| 499 | + }); |
| 500 | + $.ajax({ |
| 501 | + url: window.location.pathname + window.location.search, |
| 502 | + method: "POST", |
| 503 | + data: { |
| 504 | + action: "reorder_courses", |
| 505 | + order: order |
| 506 | + }, |
| 507 | + success: function(response) { |
| 508 | + // Optionnel : affiche un message |
| 509 | + } |
| 510 | + }); |
| 511 | + } |
| 512 | + }).disableSelection(); |
| 513 | +}); |
| 514 | +</script> |
| 515 | +<style> |
| 516 | + .ui-sortable-placeholder { background: #fffae6; height:40px; } |
| 517 | + .handle { cursor:move; } |
| 518 | +</style> |
| 519 | +EOD; |
498 | 520 |
|
499 | 521 | $tpl = new Template($tool_name);
|
500 | 522 | $tpl->assign('session_header', $sessionHeader);
|
|
0 commit comments