resume_session.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Bart Mollet, Julio Montoya lot of fixes
  5. * @package chamilo.admin
  6. */
  7. use Chamilo\CoreBundle\Entity\Repository\SequenceRepository;
  8. use Chamilo\CoreBundle\Entity\SequenceResource;
  9. use Chamilo\CoreBundle\Entity\Promotion;
  10. use Chamilo\CoreBundle\Entity\Session,
  11. Doctrine\Common\Collections\Criteria,
  12. Chamilo\CoreBundle\Entity\SessionRelUser,
  13. Chamilo\CoreBundle\Entity\Repository\SessionRepository,
  14. Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
  15. $cidReset = true;
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. // setting the section (for the tabs)
  18. $this_section = SECTION_PLATFORM_ADMIN;
  19. $sessionId = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  20. if (empty($sessionId)) {
  21. api_not_allowed(true);
  22. }
  23. SessionManager::protectSession($sessionId);
  24. $tool_name = get_lang('SessionOverview');
  25. $interbreadcrumb[] = array(
  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 = array();
  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. $result = Database::query("DELETE FROM $tbl_session_rel_class
  89. WHERE session_id='$sessionId' AND class_id=".intval($_GET['class']));
  90. $nbr_affected_rows = Database::affected_rows($result);
  91. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$sessionId'");
  92. }
  93. if (!empty($_GET['user'])) {
  94. SessionManager::unsubscribe_user_from_session(
  95. $sessionId,
  96. $_GET['user']
  97. );
  98. }
  99. break;
  100. }
  101. $sessionHeader = Display::page_header(
  102. Display::return_icon('session.png', get_lang('Session')).' '.$sessionInfo['name'],
  103. null,
  104. 'h3'
  105. );
  106. $url = Display::url(
  107. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  108. "session_edit.php?page=resume_session.php&id=$sessionId"
  109. );
  110. $sessionTitle = Display::page_subheader(get_lang('GeneralProperties').$url);
  111. $generalCoach = api_get_user_info($sessionInfo['id_coach']);
  112. $sessionField = new ExtraField('session');
  113. $extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
  114. $multiple_url_is_on = api_get_multiple_access_url();
  115. $urlList = [];
  116. if ($multiple_url_is_on) {
  117. $urlList = UrlManager::get_access_url_from_session($sessionId);
  118. }
  119. $url = Display::url(
  120. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  121. "add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
  122. );
  123. $courseListToShow = Display::page_subheader(get_lang('CourseList').$url);
  124. $courseListToShow .= '<table id="session-list-course" class="data_table">
  125. <tr>
  126. <th width="35%">'.get_lang('CourseTitle').'</th>
  127. <th width="30%">'.get_lang('CourseCoach').'</th>
  128. <th width="10%">'.get_lang('UsersNumber').'</th>
  129. <th width="25%">'.get_lang('Actions').'</th>
  130. </tr>';
  131. if ($sessionInfo['nbr_courses'] == 0) {
  132. $courseListToShow .= '<tr>
  133. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  134. </tr>';
  135. } else {
  136. $count = 0;
  137. $courseItem = '';
  138. $courses = $sessionRepository->getCoursesOrderedByPosition($session);
  139. foreach ($courses as $course) {
  140. // Select the number of users
  141. $numberOfUsers = SessionManager::getCountUsersInCourseSession(
  142. $course,
  143. $session
  144. );
  145. // Get coachs of the courses in session
  146. $namesOfCoaches = [];
  147. $coachSubscriptions = $session
  148. ->getUserCourseSubscriptionsByStatus($course, Session::COACH)
  149. ->forAll(function ($index, SessionRelCourseRelUser $subscription) use (&$namesOfCoaches) {
  150. $namesOfCoaches[] = $subscription->getUser()->getCompleteNameWithUserName();
  151. return true;
  152. });
  153. $orderButtons = '';
  154. if (SessionManager::orderCourseIsEnabled()) {
  155. $orderButtons = Display::url(
  156. Display::return_icon(
  157. !$count ? 'up_na.png' : 'up.png',
  158. get_lang('MoveUp')
  159. ),
  160. !$count
  161. ? '#'
  162. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up'
  163. );
  164. $orderButtons .= Display::url(
  165. Display::return_icon(
  166. $count + 1 == count($courses) ? 'down_na.png' : 'down.png',
  167. get_lang('MoveDown')
  168. ),
  169. $count + 1 == count($courses)
  170. ? '#'
  171. : api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down'
  172. );
  173. }
  174. $courseUrl = api_get_course_url($course->getCode(), $sessionId);
  175. // hide_course_breadcrumb the parameter has been added to hide the name
  176. // of the course, that appeared in the default $interbreadcrumb
  177. $courseItem .= '<tr>
  178. <td class="title">'.
  179. Display::url(
  180. $course->getTitle().' ('.$course->getVisualCode().')',
  181. $courseUrl
  182. ).'</td>';
  183. $courseItem .= '<td>'.($namesOfCoaches ? implode('<br>', $namesOfCoaches) : get_lang('None')).'</td>';
  184. $courseItem .= '<td>'.$numberOfUsers.'</td>';
  185. $courseItem .= '
  186. <td>
  187. <a href="'. $courseUrl.'">'.
  188. Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  189. '.$orderButtons.'
  190. <a href="session_course_user_list.php?id_session='.$sessionId.'&course_code='.$course->getCode().'">'.
  191. Display::return_icon('user.png', get_lang('Users'), '', ICON_SIZE_SMALL).'</a>
  192. <a href="'.api_get_path(WEB_CODE_PATH).'user/user_import.php?action=import&cidReq='.$course->getCode().'&id_session='.$sessionId.'">'.
  193. Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL).'</a>
  194. <a href="'.api_get_path(WEB_CODE_PATH).'user/user_export.php?file_type=csv&course_session='.$course->getCode().':'.$sessionId.'&addcsvheader=1">'.
  195. Display::return_icon('export_csv.png', get_lang('ExportUsersOfACourse'), null, ICON_SIZE_SMALL).'</a>
  196. <a href="../tracking/courseLog.php?id_session='.$sessionId.'&cidReq='.$course->getCode().$orig_param.'&hide_course_breadcrumb=1">'.
  197. Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;
  198. <a href="session_course_edit.php?id_session='.$sessionId.'&page=resume_session.php&course_code='.$course->getCode().''.$orig_param.'">'.
  199. Display::return_icon('teacher.png', get_lang('ModifyCoach'), '', ICON_SIZE_SMALL).'</a>
  200. <a href="'.api_get_self().'?id_session='.$sessionId.'&action=delete&idChecked[]='.$course->getCode().'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.
  201. Display::return_icon('delete.png', get_lang('Delete')).'</a>
  202. </td>
  203. </tr>';
  204. $count++;
  205. }
  206. $courseListToShow .= $courseItem;
  207. }
  208. $courseListToShow .= '</table><br />';
  209. $url = Display::url(
  210. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  211. "add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
  212. );
  213. $url .= Display::url(
  214. Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL),
  215. "session_user_import.php?id_session=$sessionId"
  216. );
  217. $url .= Display::url(
  218. Display::return_icon('export_csv.png', get_lang('ExportUsers'), array(), ICON_SIZE_SMALL),
  219. api_get_path(WEB_CODE_PATH)."user/user_export.php?file_type=csv&session=$sessionId&addcsvheader=1"
  220. );
  221. $userListToShow = Display::page_subheader(get_lang('UserList').$url);
  222. $userList = SessionManager::get_users_by_session($sessionId);
  223. if (!empty($userList)) {
  224. $table = new HTML_Table(
  225. array('class' => 'data_table', 'id' => 'session-user-list')
  226. );
  227. $table->setHeaderContents(0, 0, get_lang('User'));
  228. $table->setHeaderContents(0, 1, get_lang('Status'));
  229. $table->setHeaderContents(0, 2, get_lang('Actions'));
  230. $row = 1;
  231. foreach ($userList as $user) {
  232. $userId = $user['user_id'];
  233. $userInfo = api_get_user_info($userId);
  234. $userLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$userId.'">'.
  235. api_htmlentities($userInfo['complete_name_with_username']).'</a>';
  236. $reportingLink = Display::url(
  237. Display::return_icon('statistics.gif', get_lang('Reporting')),
  238. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'&id_session='.$sessionId
  239. );
  240. $courseUserLink = Display::url(
  241. Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')),
  242. api_get_path(WEB_CODE_PATH).'session/session_course_user.php?id_user='.$user['user_id'].'&id_session='.$sessionId
  243. );
  244. $removeLink = Display::url(
  245. Display::return_icon('delete.png', get_lang('Delete')),
  246. api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'],
  247. array('onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;")
  248. );
  249. $addUserToUrlLink = '';
  250. if ($multiple_url_is_on) {
  251. if ($user['access_url_id'] != $url_id) {
  252. $userLink .= ' '.Display::return_icon(
  253. 'warning.png',
  254. get_lang('UserNotAddedInURL'),
  255. array(),
  256. ICON_SIZE_SMALL
  257. );
  258. $add = Display::return_icon(
  259. 'add.png',
  260. get_lang('AddUsersToURL'),
  261. array(),
  262. ICON_SIZE_SMALL
  263. );
  264. $addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  265. }
  266. }
  267. $editUrl = null;
  268. /*
  269. if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
  270. $editUrl = api_get_path(WEB_CODE_PATH) . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
  271. $editUrl = Display::url(
  272. Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
  273. $editUrl
  274. );
  275. }*/
  276. $table->setCellContents($row, 0, $userLink);
  277. $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
  278. switch ($user['relation_type']) {
  279. case 1:
  280. $status = get_lang('Drh');
  281. $link = Display::url(
  282. Display::return_icon('edit.png', get_lang('Edit')),
  283. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_sessions_to_user.php?user='.$userId
  284. );
  285. break;
  286. default:
  287. $status = get_lang('Student');
  288. }
  289. $table->setCellContents($row, 1, $status);
  290. $table->setCellContents($row, 2, $link);
  291. $row++;
  292. }
  293. $userListToShow .= $table->toHtml();
  294. }
  295. /** @var SequenceRepository $repo */
  296. $repo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
  297. $requirementAndDependencies = $repo->getRequirementAndDependencies(
  298. $sessionId,
  299. SequenceResource::SESSION_TYPE
  300. );
  301. $requirements = '';
  302. if (!empty($requirementAndDependencies['requirements'])) {
  303. $requirements = Display::page_subheader(get_lang('Requirements'));
  304. $requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
  305. }
  306. $dependencies = '';
  307. if (!empty($requirementAndDependencies['dependencies'])) {
  308. $dependencies = Display::page_subheader(get_lang('Dependencies'));
  309. $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
  310. }
  311. $promotion = null;
  312. if (!empty($sessionInfo['promotion_id'])) {
  313. $promotion = $em->getRepository('ChamiloCoreBundle:Promotion');
  314. $promotion = $promotion->find($sessionInfo['promotion_id']);
  315. }
  316. $programmedAnnouncement = new ScheduledAnnouncement();
  317. $programmedAnnouncement = $programmedAnnouncement->allowed();
  318. $tpl = new Template($tool_name);
  319. $tpl->assign('session_header', $sessionHeader);
  320. $tpl->assign('title', $sessionTitle);
  321. $tpl->assign('general_coach', $generalCoach);
  322. $tpl->assign('session_admin', api_get_user_info($session->getSessionAdminId()));
  323. $tpl->assign('session', $sessionInfo);
  324. $tpl->assign('programmed_announcement', $programmedAnnouncement);
  325. $tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName());
  326. $tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true));
  327. $tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo));
  328. $tpl->assign('promotion', $promotion);
  329. $tpl->assign('url_list', $urlList);
  330. $tpl->assign('extra_fields', $extraFieldData);
  331. $tpl->assign('course_list', $courseListToShow);
  332. $tpl->assign('user_list', $userListToShow);
  333. $tpl->assign('dependencies', $dependencies);
  334. $tpl->assign('requirements', $requirements);
  335. $layout = $tpl->get_template('session/resume_session.tpl');
  336. $tpl->display($layout);