resume_session.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\SequenceResource;
  4. use Chamilo\CoreBundle\Entity\Session;
  5. use Chamilo\CoreBundle\Entity\SessionRelCourse;
  6. use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
  7. use Chamilo\CoreBundle\Repository\SequenceRepository;
  8. use Chamilo\CoreBundle\Repository\SessionRepository;
  9. /**
  10. * @author Bart Mollet, Julio Montoya lot of fixes
  11. *
  12. * @package chamilo.admin
  13. */
  14. $cidReset = true;
  15. require_once __DIR__.'/../inc/global.inc.php';
  16. // setting the section (for the tabs)
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : null;
  19. if (empty($sessionId)) {
  20. api_not_allowed(true);
  21. }
  22. SessionManager::protectSession($sessionId);
  23. $codePath = api_get_path(WEB_CODE_PATH);
  24. $tool_name = get_lang('Session overview');
  25. $interbreadcrumb[] = [
  26. 'url' => 'session_list.php',
  27. 'name' => get_lang('Session list'),
  28. ];
  29. $orig_param = '&origin=resume_session';
  30. // Database Table Definitions
  31. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  32. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  33. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  34. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  35. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  36. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  37. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  38. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  39. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  40. $em = Database::getManager();
  41. $sessionInfo = api_get_session_info($sessionId);
  42. /** @var SessionRepository $sessionRepository */
  43. $sessionRepository = $em->getRepository('ChamiloCoreBundle:Session');
  44. /** @var Session $session */
  45. $session = $sessionRepository->find($sessionId);
  46. $sessionCategory = $session->getCategory();
  47. $action = isset($_GET['action']) ? $_GET['action'] : null;
  48. $url_id = api_get_current_access_url_id();
  49. switch ($action) {
  50. case 'move_up':
  51. SessionManager::moveUp($sessionId, $_GET['course_id']);
  52. header('Location: resume_session.php?id_session='.$sessionId);
  53. exit;
  54. break;
  55. case 'move_down':
  56. SessionManager::moveDown($sessionId, $_GET['course_id']);
  57. header('Location: resume_session.php?id_session='.$sessionId);
  58. exit;
  59. break;
  60. case 'add_user_to_url':
  61. $user_id = $_REQUEST['user_id'];
  62. $result = UrlManager::add_user_to_url($user_id, $url_id);
  63. $user_info = api_get_user_info($user_id);
  64. if ($result) {
  65. Display::addFlash(
  66. Display::return_message(
  67. get_lang('The user has been added').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
  68. 'confirm'
  69. )
  70. );
  71. }
  72. break;
  73. case 'delete':
  74. // Delete course from session.
  75. $idChecked = isset($_GET['idChecked']) ? $_GET['idChecked'] : null;
  76. if (is_array($idChecked)) {
  77. $usersToDelete = [];
  78. foreach ($idChecked as $courseCode) {
  79. // forcing the escape_string
  80. $courseInfo = api_get_course_info($courseCode);
  81. SessionManager::unsubscribe_course_from_session(
  82. $sessionId,
  83. $courseInfo['real_id']
  84. );
  85. }
  86. }
  87. if (!empty($_GET['class'])) {
  88. $class = (int) $_GET['class'];
  89. $result = Database::query(
  90. "DELETE FROM $tbl_session_rel_class
  91. WHERE session_id = $sessionId
  92. AND class_id = $class"
  93. );
  94. $nbr_affected_rows = Database::affected_rows($result);
  95. Database::query(
  96. "UPDATE $tbl_session
  97. SET nbr_classes = nbr_classes - $nbr_affected_rows
  98. WHERE id = $sessionId");
  99. }
  100. if (!empty($_GET['user'])) {
  101. SessionManager::unsubscribe_user_from_session(
  102. $sessionId,
  103. $_GET['user']
  104. );
  105. }
  106. Display::addFlash(Display::return_message(get_lang('Update successful')));
  107. break;
  108. }
  109. $sessionHeader = Display::page_header(
  110. Display::return_icon('session.png', get_lang('Session')).' '.$session->getName(),
  111. null,
  112. 'h3'
  113. );
  114. $url = Display::url(
  115. Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
  116. "session_edit.php?page=resume_session.php&id=$sessionId"
  117. );
  118. $sessionTitle = Display::page_subheader(get_lang('General properties').$url);
  119. $generalCoach = api_get_user_info($sessionInfo['id_coach']);
  120. $sessionField = new ExtraField('session');
  121. $extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
  122. $multiple_url_is_on = api_get_multiple_access_url();
  123. $urlList = [];
  124. if ($multiple_url_is_on) {
  125. $urlList = UrlManager::get_access_url_from_session($sessionId);
  126. }
  127. $url = Display::url(
  128. Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL),
  129. "add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
  130. );
  131. $courseListToShow = Display::page_subheader(get_lang('Course list').$url);
  132. $courseListToShow .= '<table id="session-list-course" class="table table-hover data_table">
  133. <tr>
  134. <th width="35%">'.get_lang('Course title').'</th>
  135. <th width="30%">'.get_lang('Course coach').'</th>
  136. <th width="10%">'.get_lang('Users number').'</th>
  137. <th width="25%">'.get_lang('Detail').'</th>
  138. </tr>';
  139. if ($session->getNbrCourses() === 0) {
  140. $courseListToShow .= '<tr>
  141. <td colspan="4">'.get_lang('No course for this session').'</td>
  142. </tr>';
  143. } else {
  144. $count = 0;
  145. $courseItem = '';
  146. $courses = $session->getCourses();
  147. $allowSkills = api_get_configuration_value('allow_skill_rel_items');
  148. /** @var SessionRelCourse $sessionRelCourse */
  149. foreach ($courses as $sessionRelCourse) {
  150. $course = $sessionRelCourse->getCourse();
  151. // Select the number of users
  152. $numberOfUsers = SessionManager::getCountUsersInCourseSession(
  153. $course,
  154. $session
  155. );
  156. // Get coachs of the courses in session
  157. $namesOfCoaches = [];
  158. $coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH);
  159. if ($coachSubscriptions) {
  160. /** @var SessionRelCourseRelUser $subscription */
  161. foreach ($coachSubscriptions as $subscription) {
  162. $namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName();
  163. }
  164. }
  165. $orderButtons = '';
  166. if (SessionManager::orderCourseIsEnabled()) {
  167. $orderButtons = Display::url(
  168. Display::return_icon(
  169. !$count ? 'up_na.png' : 'up.png',
  170. get_lang('Move up')
  171. ),
  172. !$count
  173. ? '#'
  174. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up'
  175. );
  176. $orderButtons .= Display::url(
  177. Display::return_icon(
  178. $count + 1 == count($courses) ? 'down_na.png' : 'down.png',
  179. get_lang('Move down')
  180. ),
  181. $count + 1 == count($courses)
  182. ? '#'
  183. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down'
  184. );
  185. }
  186. $courseUrl = api_get_course_url($course->getCode(), $sessionId);
  187. // hide_course_breadcrumb the parameter has been added to hide the name
  188. // of the course, that appeared in the default $interbreadcrumb
  189. $courseItem .= '<tr>
  190. <td class="title">'
  191. .Display::url(
  192. $course->getTitle().' ('.$course->getVisualCode().')',
  193. $courseUrl
  194. )
  195. .'</td>';
  196. $courseItem .= '<td>'.($namesOfCoaches ? implode('<br>', $namesOfCoaches) : get_lang('none')).'</td>';
  197. $courseItem .= '<td>'.$numberOfUsers.'</td>';
  198. $courseItem .= '<td>';
  199. $courseItem .= Display::url(Display::return_icon('course_home.png', get_lang('Course')), $courseUrl);
  200. if ($allowSkills) {
  201. $courseItem .= Display::url(
  202. Display::return_icon('skills.png', get_lang('Skills')),
  203. $codePath.'admin/skill_rel_course.php?session_id='.$sessionId.'&course_id='.$course->getId()
  204. );
  205. }
  206. $courseItem .= $orderButtons;
  207. $courseItem .= Display::url(
  208. Display::return_icon('new_user.png', get_lang('Add a user')),
  209. $codePath."session/add_users_to_session_course.php?id_session=$sessionId&course_id=".$course->getId()
  210. );
  211. $courseItem .= Display::url(
  212. Display::return_icon('user.png', get_lang('Users')),
  213. $codePath."session/session_course_user_list.php?id_session=$sessionId&course_code=".$course->getCode()
  214. );
  215. $courseItem .= Display::url(
  216. Display::return_icon('import_csv.png', get_lang('Import users list')),
  217. $codePath."user/user_import.php?action=import&cidReq={$course->getCode()}&id_session=$sessionId"
  218. );
  219. $courseItem .= Display::url(
  220. Display::return_icon('export_csv.png', get_lang('Export users of a course')),
  221. $codePath."user/user_export.php?file_type=csv&course_session={$course->getCode()}:$sessionId&addcsvheader=1"
  222. );
  223. $courseItem .= Display::url(
  224. Display::return_icon('statistics.gif', get_lang('Reporting')),
  225. $codePath."tracking/courseLog.php?id_session=$sessionId&cidReq={$course->getCode()}$orig_param&hide_course_breadcrumb=1"
  226. );
  227. $courseItem .= Display::url(
  228. Display::return_icon('teacher.png', get_lang('Edit coach')),
  229. $codePath."session/session_course_edit.php?id_session=$sessionId&page=resume_session.php&course_code={$course->getCode()}$orig_param"
  230. );
  231. $courseItem .= Display::url(
  232. Display::return_icon('folder_document.png', get_lang('File upload')),
  233. '#',
  234. [
  235. 'class' => 'session-upload-file-btn',
  236. 'data-session' => $sessionId,
  237. 'data-course' => $course->getId(),
  238. ]
  239. );
  240. $courseItem .= Display::url(
  241. Display::return_icon('delete.png', get_lang('Delete')),
  242. api_get_self()."?id_session=$sessionId&action=delete&idChecked[]={$course->getCode()}",
  243. [
  244. 'onclick' => "javascript:if(!confirm('".get_lang('Please confirm your choice')."')) return false;",
  245. ]
  246. );
  247. $courseItem .= '</td></tr>';
  248. $count++;
  249. }
  250. $courseListToShow .= $courseItem;
  251. }
  252. $courseListToShow .= '</table><br />';
  253. $url = '&nbsp;'.Display::url(
  254. Display::return_icon('user_subscribe_session.png', get_lang('Add')),
  255. $codePath."session/add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
  256. );
  257. $url .= Display::url(
  258. Display::return_icon('import_csv.png', get_lang('Import users')),
  259. $codePath."session/session_user_import.php?id_session=$sessionId"
  260. );
  261. $url .= Display::url(
  262. Display::return_icon('export_csv.png', get_lang('Export users list')),
  263. $codePath."user/user_export.php?file_type=csv&session=$sessionId&addcsvheader=1"
  264. );
  265. $userListToShow = Display::page_subheader(get_lang('User list').$url);
  266. $userList = SessionManager::get_users_by_session($sessionId);
  267. if (!empty($userList)) {
  268. $table = new HTML_Table(
  269. ['class' => 'table table-bordered', 'id' => 'session-user-list']
  270. );
  271. $table->setHeaderContents(0, 0, get_lang('User'));
  272. $table->setHeaderContents(0, 1, get_lang('Status'));
  273. $table->setHeaderContents(0, 2, get_lang('Registration date'));
  274. $table->setHeaderContents(0, 3, get_lang('Detail'));
  275. $row = 1;
  276. foreach ($userList as $user) {
  277. $userId = $user['user_id'];
  278. $userInfo = api_get_user_info($userId);
  279. $userLink = '<a href="'.$codePath.'admin/user_information.php?user_id='.$userId.'">'.
  280. api_htmlentities($userInfo['complete_name_with_username']).'</a>';
  281. $reportingLink = Display::url(
  282. Display::return_icon('statistics.gif', get_lang('Reporting')),
  283. $codePath.'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'&id_session='
  284. .$sessionId
  285. );
  286. $courseUserLink = Display::url(
  287. Display::return_icon('course.png', get_lang('Block user from courses in this session')),
  288. $codePath.'session/session_course_user.php?id_user='.$user['user_id'].'&id_session='
  289. .$sessionId
  290. );
  291. $removeLink = Display::url(
  292. Display::return_icon('delete.png', get_lang('Delete')),
  293. api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'],
  294. ['onclick' => "javascript:if(!confirm('".get_lang('Please confirm your choice')."')) return false;"]
  295. );
  296. $addUserToUrlLink = '';
  297. if ($multiple_url_is_on) {
  298. if ($user['access_url_id'] != $url_id) {
  299. $userLink .= ' '.Display::return_icon('warning.png', get_lang('Users not added to the URL'));
  300. $add = Display::return_icon('add.png', get_lang('Add a userToURL'));
  301. $addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId
  302. .'&user_id='.$user['user_id'].'">'.$add.'</a>';
  303. }
  304. }
  305. $editUrl = null;
  306. /*
  307. if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
  308. $editUrl = $codePath . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
  309. $editUrl = Display::url(
  310. Display::return_icon('agenda.png', get_lang('Edit session duration')),
  311. $editUrl
  312. );
  313. }*/
  314. $table->setCellContents($row, 0, $userLink);
  315. $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
  316. switch ($user['relation_type']) {
  317. case 1:
  318. $status = get_lang('Human Resources Manager');
  319. $link = Display::url(
  320. Display::return_icon('edit.png', get_lang('Edit')),
  321. $codePath.'admin/dashboard_add_sessions_to_user.php?user='.$userId
  322. );
  323. break;
  324. default:
  325. $status = get_lang('Learner');
  326. }
  327. $registered = !empty($user['registered_at']) ? Display::dateToStringAgoAndLongDate($user['registered_at']) : '';
  328. $table->setCellContents($row, 1, $status);
  329. $table->setCellContents($row, 2, $registered);
  330. $table->setCellContents($row, 3, $link);
  331. $row++;
  332. }
  333. $userListToShow .= $table->toHtml();
  334. }
  335. /** @var SequenceRepository $repo */
  336. $repo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
  337. $requirementAndDependencies = $repo->getRequirementAndDependencies(
  338. $sessionId,
  339. SequenceResource::SESSION_TYPE
  340. );
  341. $requirements = '';
  342. if (!empty($requirementAndDependencies['requirements'])) {
  343. $requirements = Display::page_subheader(get_lang('Requirements'));
  344. $requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
  345. }
  346. $dependencies = '';
  347. if (!empty($requirementAndDependencies['dependencies'])) {
  348. $dependencies = Display::page_subheader(get_lang('Items that depend on the reference'));
  349. $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
  350. }
  351. $promotion = null;
  352. if (!empty($sessionInfo['promotion_id'])) {
  353. $promotion = $em->getRepository('ChamiloCoreBundle:Promotion');
  354. $promotion = $promotion->find($sessionInfo['promotion_id']);
  355. }
  356. $programmedAnnouncement = new ScheduledAnnouncement();
  357. $programmedAnnouncement = $programmedAnnouncement->allowed();
  358. $tpl = new Template($tool_name);
  359. $tpl->assign('session_header', $sessionHeader);
  360. $tpl->assign('title', $sessionTitle);
  361. $tpl->assign('general_coach', $generalCoach);
  362. $tpl->assign('session_admin', api_get_user_info($session->getSessionAdminId()));
  363. $tpl->assign('session', $sessionInfo);
  364. $tpl->assign('programmed_announcement', $programmedAnnouncement);
  365. $tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName());
  366. $tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true));
  367. $tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo));
  368. $tpl->assign('promotion', $promotion);
  369. $tpl->assign('url_list', $urlList);
  370. $tpl->assign('extra_fields', $extraFieldData);
  371. $tpl->assign('course_list', $courseListToShow);
  372. $tpl->assign('user_list', $userListToShow);
  373. $tpl->assign('dependencies', $dependencies);
  374. $tpl->assign('requirements', $requirements);
  375. $layout = $tpl->get_template('session/resume_session.tpl');
  376. $tpl->display($layout);