resume_session.php 17 KB

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