resume_session.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. // setting breadcrumbs
  13. $interbreadcrumb[] = array(
  14. 'url' => 'session_list.php',
  15. 'name' => get_lang('Sessions'),
  16. );
  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('url' => 'session_list.php', 'name' => get_lang('SessionList'));
  26. $orig_param = '&origin=resume_session';
  27. // Database Table Definitions
  28. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  29. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  30. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  31. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  32. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  33. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  34. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  35. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  36. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  37. $sessionInfo = api_get_session_info($sessionId);
  38. $session = Database::getManager()->find('ChamiloCoreBundle:Session', $sessionId);
  39. $sessionCategory = $session->getCategory();
  40. $action = isset($_GET['action']) ? $_GET['action'] : null;
  41. $url_id = api_get_current_access_url_id();
  42. switch ($action) {
  43. case 'move_up':
  44. SessionManager::moveUp($sessionId, $_GET['course_id']);
  45. header('Location: resume_session.php?id_session='.$sessionId);
  46. exit;
  47. break;
  48. case 'move_down':
  49. SessionManager::moveDown($sessionId, $_GET['course_id']);
  50. header('Location: resume_session.php?id_session='.$sessionId);
  51. exit;
  52. break;
  53. case 'add_user_to_url':
  54. $user_id = $_REQUEST['user_id'];
  55. $result = UrlManager::add_user_to_url($user_id, $url_id);
  56. $user_info = api_get_user_info($user_id);
  57. if ($result) {
  58. Display::addFlash(
  59. Display::return_message(
  60. get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
  61. 'confirm'
  62. )
  63. );
  64. }
  65. break;
  66. case 'delete':
  67. // Delete course from session.
  68. $idChecked = isset($_GET['idChecked']) ? $_GET['idChecked'] : null;
  69. if (is_array($idChecked)) {
  70. $usersToDelete = array();
  71. foreach ($idChecked as $courseCode) {
  72. // forcing the escape_string
  73. $courseInfo = api_get_course_info($courseCode);
  74. SessionManager::unsubscribe_course_from_session(
  75. $sessionId,
  76. $courseInfo['real_id']
  77. );
  78. }
  79. }
  80. if (!empty($_GET['class'])) {
  81. $result = Database::query("DELETE FROM $tbl_session_rel_class
  82. WHERE session_id='$sessionId' AND class_id=".intval($_GET['class']));
  83. $nbr_affected_rows = Database::affected_rows($result);
  84. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$sessionId'");
  85. }
  86. if (!empty($_GET['user'])) {
  87. SessionManager::unsubscribe_user_from_session(
  88. $sessionId,
  89. $_GET['user']
  90. );
  91. }
  92. break;
  93. }
  94. $sessionHeader = Display::page_header(
  95. Display::return_icon('session.png', get_lang('Session')).' '.$sessionInfo['name'],
  96. null,
  97. 'h3'
  98. );
  99. $url = Display::url(
  100. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  101. "session_edit.php?page=resume_session.php&id=$sessionId"
  102. );
  103. $sessionTitle = Display::page_subheader(get_lang('GeneralProperties').$url);
  104. $generalCoach = api_get_user_info($sessionInfo['id_coach']);
  105. $sessionField = new ExtraField('session');
  106. $extraFieldData = $sessionField->getDataAndFormattedValues($sessionId);
  107. $multiple_url_is_on = api_get_multiple_access_url();
  108. $urlList = [];
  109. if ($multiple_url_is_on) {
  110. $urlList = UrlManager::get_access_url_from_session($sessionId);
  111. }
  112. $url = Display::url(
  113. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  114. "add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
  115. );
  116. $courseListToShow = Display::page_subheader(get_lang('CourseList').$url);
  117. $courseListToShow .= '<table id="session-list-course" class="data_table">
  118. <tr>
  119. <th width="35%">'.get_lang('CourseTitle').'</th>
  120. <th width="30%">'.get_lang('CourseCoach').'</th>
  121. <th width="10%">'.get_lang('UsersNumber').'</th>
  122. <th width="25%">'.get_lang('Actions').'</th>
  123. </tr>';
  124. if ($sessionInfo['nbr_courses'] == 0) {
  125. $courseListToShow .= '<tr>
  126. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  127. </tr>';
  128. } else {
  129. $count = 0;
  130. $courseItem = '';
  131. /** @var \Chamilo\CoreBundle\Entity\Repository\SessionRepository $sessionRepository */
  132. $sessionRepository = Database::getManager()->getRepository('ChamiloCoreBundle:Session');
  133. $courses = $sessionRepository->getCoursesOrderedByPosition($session);
  134. foreach ($courses as $course) {
  135. // Select the number of users
  136. $sql = "SELECT count(*)
  137. FROM $tbl_session_rel_user sru,
  138. $tbl_session_rel_course_rel_user srcru
  139. WHERE
  140. srcru.user_id = sru.user_id AND
  141. srcru.session_id = sru.session_id AND
  142. srcru.c_id = '".intval($course->getId())."' AND
  143. sru.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
  144. srcru.session_id = '".intval($sessionId)."'";
  145. $rs = Database::query($sql);
  146. $numberOfUsers = Database::result($rs, 0, 0);
  147. // Get coachs of the courses in session
  148. $sql = "SELECT user.lastname, user.firstname, user.username
  149. FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  150. WHERE
  151. session_rcru.user_id = user.user_id AND
  152. session_rcru.session_id = '".intval($sessionId)."' AND
  153. session_rcru.c_id ='".intval($course->getId())."' AND
  154. session_rcru.status=2";
  155. $rs = Database::query($sql);
  156. $coachs = array();
  157. if (Database::num_rows($rs) > 0) {
  158. while ($info_coach = Database::fetch_array($rs)) {
  159. $coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
  160. }
  161. } else {
  162. $coach = get_lang('None');
  163. }
  164. if (count($coachs) > 0) {
  165. $coach = implode('<br />', $coachs);
  166. } else {
  167. $coach = get_lang('None');
  168. }
  169. $orderButtons = null;
  170. $upIcon = 'up.png';
  171. $urlUp = api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_up';
  172. if ($count == 0) {
  173. $upIcon = 'up_na.png';
  174. $urlUp = '#';
  175. }
  176. $orderButtons = Display::url(
  177. Display::return_icon($upIcon, get_lang('MoveUp')),
  178. $urlUp
  179. );
  180. $downIcon = 'down.png';
  181. $downUrl = api_get_self().'?id_session='.$sessionId.'&course_id='.$course->getId().'&action=move_down';
  182. if ($count + 1 == count($courses)) {
  183. $downIcon = 'down_na.png';
  184. $downUrl = '#';
  185. }
  186. $orderButtons .= Display::url(
  187. Display::return_icon($downIcon, get_lang('MoveDown')),
  188. $downUrl
  189. );
  190. if (!SessionManager::orderCourseIsEnabled()) {
  191. $orderButtons = '';
  192. }
  193. $courseUrl = api_get_course_url($course->getCode(), $sessionId);
  194. // hide_course_breadcrumb the parameter has been added to hide the name
  195. // of the course, that appeared in the default $interbreadcrumb
  196. $courseItem .= '
  197. <tr>
  198. <td class="title">'.Display::url(
  199. $course->getTitle().' ('.$course->getVisualCode().')',
  200. $courseUrl
  201. ).'</td>
  202. <td>'.$coach.'</td>
  203. <td>'.$numberOfUsers.'</td>
  204. <td>
  205. <a href="'. $courseUrl.'">'.
  206. Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  207. '.$orderButtons.'
  208. <a href="session_course_user_list.php?id_session='.$sessionId.'&course_code='.$course->getCode().'">'.
  209. Display::return_icon('user.png', get_lang('Users'), '', ICON_SIZE_SMALL).'</a>
  210. <a href="'.api_get_path(WEB_CODE_PATH).'user/user_import.php?action=import&cidReq='.$course->getCode().'&id_session='.$sessionId.'">'.
  211. Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL).'</a>
  212. <a href="'.api_get_path(WEB_CODE_PATH).'user/user_export.php?file_type=csv&course_session='.$course->getCode().':'.$sessionId.'&addcsvheader=1">'.
  213. Display::return_icon('export_csv.png', get_lang('ExportUsersOfACourse'), null, ICON_SIZE_SMALL).'</a>
  214. <a href="../tracking/courseLog.php?id_session='.$sessionId.'&cidReq='.$course->getCode().$orig_param.'&hide_course_breadcrumb=1">'.
  215. Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;
  216. <a href="session_course_edit.php?id_session='.$sessionId.'&page=resume_session.php&course_code='.$course->getCode().''.$orig_param.'">'.
  217. Display::return_icon('teacher.png', get_lang('ModifyCoach'), '', ICON_SIZE_SMALL).'</a>
  218. <a href="'.api_get_self().'?id_session='.$sessionId.'&action=delete&idChecked[]='.$course->getCode().'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.
  219. Display::return_icon('delete.png', get_lang('Delete')).'</a>
  220. </td>
  221. </tr>';
  222. $count++;
  223. }
  224. $courseListToShow .= $courseItem;
  225. }
  226. $courseListToShow .= '</table><br />';
  227. $url = Display::url(
  228. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  229. "add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
  230. );
  231. $url .= Display::url(
  232. Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL),
  233. "session_user_import.php?id_session=$sessionId"
  234. );
  235. $url .= Display::url(
  236. Display::return_icon('export_csv.png', get_lang('ExportUsers'), array(), ICON_SIZE_SMALL),
  237. "/main/user/user_export.php?file_type=csv&session=$sessionId&addcsvheader=1"
  238. );
  239. $userListToShow = Display::page_subheader(get_lang('UserList').$url);
  240. $userList = SessionManager::get_users_by_session($sessionId);
  241. if (!empty($userList)) {
  242. $table = new HTML_Table(array('class' => 'data_table', 'id'=>'session-user-list'));
  243. $table->setHeaderContents(0, 0, get_lang('User'));
  244. $table->setHeaderContents(0, 1, get_lang('Status'));
  245. $table->setHeaderContents(0, 2, get_lang('Actions'));
  246. $row = 1;
  247. foreach ($userList as $user) {
  248. $userId = $user['user_id'];
  249. $userInfo = api_get_user_info($userId);
  250. $userLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$userId.'">'.
  251. api_htmlentities($userInfo['complete_name_with_username']).'</a>';
  252. $reportingLink = Display::url(
  253. Display::return_icon('statistics.gif', get_lang('Reporting')),
  254. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'&id_session='.$sessionId
  255. );
  256. $courseUserLink = Display::url(
  257. Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')),
  258. api_get_path(WEB_CODE_PATH).'session/session_course_user.php?id_user='.$user['user_id'].'&id_session='.$sessionId
  259. );
  260. $removeLink = Display::url(
  261. Display::return_icon('delete.png', get_lang('Delete')),
  262. api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'],
  263. array('onclick' => "javascript:if(!confirm('".get_lang('ConfirmYourChoice')."')) return false;")
  264. );
  265. $addUserToUrlLink = '';
  266. if ($multiple_url_is_on) {
  267. if ($user['access_url_id'] != $url_id) {
  268. $userLink .= ' '.Display::return_icon(
  269. 'warning.png',
  270. get_lang('UserNotAddedInURL'),
  271. array(),
  272. ICON_SIZE_SMALL
  273. );
  274. $add = Display::return_icon(
  275. 'add.png',
  276. get_lang('AddUsersToURL'),
  277. array(),
  278. ICON_SIZE_SMALL
  279. );
  280. $addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  281. }
  282. }
  283. $editUrl = null;
  284. /*
  285. if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
  286. $editUrl = api_get_path(WEB_CODE_PATH) . 'session/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
  287. $editUrl = Display::url(
  288. Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
  289. $editUrl
  290. );
  291. }*/
  292. $table->setCellContents($row, 0, $userLink);
  293. $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
  294. switch ($user['relation_type']) {
  295. case 1:
  296. $status = get_lang('Drh');
  297. $link = Display::url(
  298. Display::return_icon('edit.png', get_lang('Edit')),
  299. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_sessions_to_user.php?user='.$userId
  300. );
  301. break;
  302. default:
  303. $status = get_lang('Student');
  304. }
  305. $table->setCellContents($row, 1, $status);
  306. $table->setCellContents($row, 2, $link);
  307. $row++;
  308. }
  309. $userListToShow .= $table->toHtml();
  310. }
  311. /** @var SequenceRepository $repo */
  312. $repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
  313. $requirementAndDependencies = $repo->getRequirementAndDependencies(
  314. $sessionId,
  315. SequenceResource::SESSION_TYPE
  316. );
  317. $requirements = '';
  318. if (!empty($requirementAndDependencies['requirements'])) {
  319. $requirements = Display::page_subheader(get_lang('Requirements'));
  320. $requirements .= implode(' + ', array_column($requirementAndDependencies['requirements'], 'admin_link'));
  321. }
  322. $dependencies = '';
  323. if (!empty($requirementAndDependencies['dependencies'])) {
  324. $dependencies = Display::page_subheader(get_lang('Dependencies'));
  325. $dependencies .= implode(', ', array_column($requirementAndDependencies['dependencies'], 'admin_link'));
  326. }
  327. $promotion = null;
  328. if (!empty($sessionInfo['promotion_id'])) {
  329. $promotion = Database::getManager()->getRepository('ChamiloCoreBundle:Promotion');
  330. $promotion = $promotion->find($sessionInfo['promotion_id']);
  331. }
  332. $tpl = new Template(get_lang('Session'));
  333. $tpl->assign('session_header', $sessionHeader);
  334. $tpl->assign('title', $sessionTitle);
  335. $tpl->assign('general_coach', $generalCoach);
  336. $tpl->assign('session_admin', api_get_user_info($session->getSessionAdminId()));
  337. $tpl->assign('session', $sessionInfo);
  338. $tpl->assign('session_category', is_null($sessionCategory) ? null : $sessionCategory->getName());
  339. $tpl->assign('session_dates', SessionManager::parseSessionDates($sessionInfo, true));
  340. $tpl->assign('session_visibility', SessionManager::getSessionVisibility($sessionInfo));
  341. $tpl->assign('promotion', $promotion);
  342. $tpl->assign('url_list', $urlList);
  343. $tpl->assign('extra_fields', $extraFieldData);
  344. $tpl->assign('course_list', $courseListToShow);
  345. $tpl->assign('user_list', $userListToShow);
  346. $tpl->assign('dependencies', $dependencies);
  347. $tpl->assign('requirements', $requirements);
  348. $layout = $tpl->get_template('session/resume_session.tpl');
  349. $tpl->display($layout);