resume_session.php 15 KB

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