resume_session.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\CoreBundle\Entity\Repository\SequenceRepository;
  5. use Chamilo\CoreBundle\Entity\Repository\SessionRepository;
  6. use Chamilo\CoreBundle\Entity\SequenceResource;
  7. use Chamilo\CoreBundle\Entity\Session;
  8. use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
  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('SessionOverview');
  25. $interbreadcrumb[] = [
  26. 'url' => 'session_list.php',
  27. 'name' => get_lang('SessionList'),
  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('UserAdded').' '.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('Updated')));
  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('GeneralProperties').$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('CourseList').$url);
  132. $courseListToShow .= '<table id="session-list-course" class="table table-hover data_table">
  133. <tr>
  134. <th width="35%">'.get_lang('CourseTitle').'</th>
  135. <th width="30%">'.get_lang('CourseCoach').'</th>
  136. <th width="10%">'.get_lang('UsersNumber').'</th>
  137. <th width="25%">'.get_lang('Actions').'</th>
  138. </tr>';
  139. if ($session->getNbrCourses() === 0) {
  140. $courseListToShow .= '<tr>
  141. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  142. </tr>';
  143. } else {
  144. $count = 0;
  145. $courseItem = '';
  146. $courses = $sessionRepository->getCoursesOrderedByPosition($session);
  147. $allowSkills = api_get_configuration_value('allow_skill_rel_items');
  148. /** @var Course $course */
  149. foreach ($courses as $course) {
  150. // Select the number of users
  151. $numberOfUsers = SessionManager::getCountUsersInCourseSession(
  152. $course,
  153. $session
  154. );
  155. // Get coachs of the courses in session
  156. $namesOfCoaches = [];
  157. $coachSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, Session::COACH);
  158. if ($coachSubscriptions) {
  159. /** @var SessionRelCourseRelUser $subscription */
  160. foreach ($coachSubscriptions as $subscription) {
  161. $namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName();
  162. }
  163. }
  164. $orderButtons = '';
  165. if (SessionManager::orderCourseIsEnabled()) {
  166. $orderButtons = Display::url(
  167. Display::return_icon(
  168. !$count ? 'up_na.png' : 'up.png',
  169. get_lang('MoveUp')
  170. ),
  171. !$count
  172. ? '#'
  173. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up'
  174. );
  175. $orderButtons .= Display::url(
  176. Display::return_icon(
  177. $count + 1 == count($courses) ? 'down_na.png' : 'down.png',
  178. get_lang('MoveDown')
  179. ),
  180. $count + 1 == count($courses)
  181. ? '#'
  182. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down'
  183. );
  184. }
  185. $courseUrl = api_get_course_url($course->getCode(), $sessionId);
  186. // hide_course_breadcrumb the parameter has been added to hide the name
  187. // of the course, that appeared in the default $interbreadcrumb
  188. $courseItem .= '<tr>
  189. <td class="title">'
  190. .Display::url(
  191. $course->getTitle().' ('.$course->getVisualCode().')',
  192. $courseUrl
  193. )
  194. .'</td>';
  195. $courseItem .= '<td>'.($namesOfCoaches ? implode('<br>', $namesOfCoaches) : get_lang('None')).'</td>';
  196. $courseItem .= '<td>'.$numberOfUsers.'</td>';
  197. $courseItem .= '<td>';
  198. $courseItem .= Display::url(Display::return_icon('course_home.gif', get_lang('Course')), $courseUrl);
  199. if ($allowSkills) {
  200. $courseItem .= Display::url(
  201. Display::return_icon('skills.png', get_lang('Skills')),
  202. $codePath.'admin/skill_rel_course.php?session_id='.$sessionId.'&course_id='.$course->getId()
  203. );
  204. }
  205. $courseItem .= $orderButtons;
  206. $courseItem .= Display::url(
  207. Display::return_icon('new_user.png', get_lang('AddUsers')),
  208. $codePath."session/add_users_to_session_course.php?id_session=$sessionId&course_id=".$course->getId()
  209. );
  210. $courseItem .= Display::url(
  211. Display::return_icon('user.png', get_lang('Users')),
  212. $codePath."session/session_course_user_list.php?id_session=$sessionId&course_code=".$course->getCode()
  213. );
  214. $courseItem .= Display::url(
  215. Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse')),
  216. $codePath."user/user_import.php?action=import&cidReq={$course->getCode()}&id_session=$sessionId"
  217. );
  218. $courseItem .= Display::url(
  219. Display::return_icon('export_csv.png', get_lang('ExportUsersOfACourse')),
  220. $codePath."user/user_export.php?file_type=csv&course_session={$course->getCode()}:$sessionId&addcsvheader=1"
  221. );
  222. $courseItem .= Display::url(
  223. Display::return_icon('statistics.gif', get_lang('Tracking')),
  224. $codePath."tracking/courseLog.php?id_session=$sessionId&cidReq={$course->getCode()}$orig_param&hide_course_breadcrumb=1"
  225. );
  226. $courseItem .= Display::url(
  227. Display::return_icon('teacher.png', get_lang('ModifyCoach')),
  228. $codePath."session/session_course_edit.php?id_session=$sessionId&page=resume_session.php&course_code={$course->getCode()}$orig_param"
  229. );
  230. $courseItem .= Display::url(
  231. Display::return_icon('folder_document.png', get_lang('UploadFile')),
  232. '#',
  233. [
  234. 'class' => 'session-upload-file-btn',
  235. 'data-session' => $sessionId,
  236. 'data-course' => $course->getId(),
  237. ]
  238. );
  239. $courseItem .= Display::url(
  240. Display::return_icon('delete.png', get_lang('Delete')),
  241. api_get_self()."?id_session=$sessionId&action=delete&idChecked[]={$course->getCode()}",
  242. [
  243. 'onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;",
  244. ]
  245. );
  246. $courseItem .= '</td></tr>';
  247. $count++;
  248. }
  249. $courseListToShow .= $courseItem;
  250. }
  251. $courseListToShow .= '</table><br />';
  252. $url = '&nbsp;'.Display::url(
  253. Display::return_icon('user_subscribe_session.png', get_lang('Add')),
  254. $codePath."session/add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
  255. );
  256. $url .= Display::url(
  257. Display::return_icon('import_csv.png', get_lang('ImportUsers')),
  258. $codePath."session/session_user_import.php?id_session=$sessionId"
  259. );
  260. $url .= Display::url(
  261. Display::return_icon('export_csv.png', get_lang('ExportUsers')),
  262. $codePath."user/user_export.php?file_type=csv&session=$sessionId&addcsvheader=1"
  263. );
  264. $userListToShow = Display::page_subheader(get_lang('UserList').$url);
  265. $userList = SessionManager::get_users_by_session($sessionId);
  266. if (!empty($userList)) {
  267. $table = new HTML_Table(
  268. ['class' => 'table table-hover data_table', 'id' => 'session-user-list']
  269. );
  270. $table->setHeaderContents(0, 0, get_lang('User'));
  271. $table->setHeaderContents(0, 1, get_lang('Status'));
  272. $table->setHeaderContents(0, 2, get_lang('RegistrationDate'));
  273. $table->setHeaderContents(0, 3, get_lang('Actions'));
  274. $row = 1;
  275. foreach ($userList as $user) {
  276. $userId = $user['user_id'];
  277. $userInfo = api_get_user_info($userId);
  278. $userLink = '<a href="'.$codePath.'admin/user_information.php?user_id='.$userId.'">'.
  279. api_htmlentities($userInfo['complete_name_with_username']).'</a>';
  280. $reportingLink = Display::url(
  281. Display::return_icon('statistics.gif', get_lang('Reporting')),
  282. $codePath.'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'&id_session='
  283. .$sessionId
  284. );
  285. $courseUserLink = Display::url(
  286. Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')),
  287. $codePath.'session/session_course_user.php?id_user='.$user['user_id'].'&id_session='
  288. .$sessionId
  289. );
  290. $removeLink = Display::url(
  291. Display::return_icon('delete.png', get_lang('Delete')),
  292. api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'],
  293. ['onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;"]
  294. );
  295. $addUserToUrlLink = '';
  296. if ($multiple_url_is_on) {
  297. if ($user['access_url_id'] != $url_id) {
  298. $userLink .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'));
  299. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'));
  300. $addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId
  301. .'&user_id='.$user['user_id'].'">'.$add.'</a>';
  302. }
  303. }
  304. $editUrl = null;
  305. /*
  306. if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
  307. $editUrl = $codePath . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
  308. $editUrl = Display::url(
  309. Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
  310. $editUrl
  311. );
  312. }*/
  313. $table->setCellContents($row, 0, $userLink);
  314. $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
  315. switch ($user['relation_type']) {
  316. case 1:
  317. $status = get_lang('Drh');
  318. $link = Display::url(
  319. Display::return_icon('edit.png', get_lang('Edit')),
  320. $codePath.'admin/dashboard_add_sessions_to_user.php?user='.$userId
  321. );
  322. break;
  323. default:
  324. $status = get_lang('Student');
  325. }
  326. $registered = !empty($user['registered_at']) ? Display::dateToStringAgoAndLongDate($user['registered_at']) : '';
  327. $table->setCellContents($row, 1, $status);
  328. $table->setCellContents($row, 2, $registered);
  329. $table->setCellContents($row, 3, $link);
  330. $row++;
  331. }
  332. $userListToShow .= $table->toHtml();
  333. }
  334. /** @var SequenceRepository $repo */
  335. $repo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
  336. $requirementAndDependencies = $repo->getRequirementAndDependencies(
  337. $sessionId,
  338. SequenceResource::SESSION_TYPE
  339. );
  340. $requirements = '';
  341. if (!empty($requirementAndDependencies['requirements'])) {
  342. $requirements = Display::page_subheader(get_lang('Requirements'));
  343. $requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
  344. }
  345. $dependencies = '';
  346. if (!empty($requirementAndDependencies['dependencies'])) {
  347. $dependencies = Display::page_subheader(get_lang('Dependencies'));
  348. $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
  349. }
  350. $promotion = null;
  351. if (!empty($sessionInfo['promotion_id'])) {
  352. $promotion = $em->getRepository('ChamiloCoreBundle:Promotion');
  353. $promotion = $promotion->find($sessionInfo['promotion_id']);
  354. }
  355. $programmedAnnouncement = new ScheduledAnnouncement();
  356. $programmedAnnouncement = $programmedAnnouncement->allowed();
  357. $htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
  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);