resume_session.php 15 KB

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