resume_session.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. // name of the language file that needs to be included
  8. $language_file = 'admin';
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. // setting the section (for the tabs)
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. $sessionId = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  14. if (empty($sessionId)) {
  15. api_not_allowed(true);
  16. }
  17. SessionManager::protect_session_edit($sessionId);
  18. $tool_name = get_lang('SessionOverview');
  19. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  20. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  21. // Database Table Definitions
  22. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  23. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  24. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  25. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  26. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  27. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  28. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  29. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  30. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  31. $sql = 'SELECT
  32. name,
  33. nbr_courses,
  34. nbr_users,
  35. nbr_classes,
  36. DATE_FORMAT(date_start,"%d-%m-%Y") as date_start,
  37. DATE_FORMAT(date_end,"%d-%m-%Y") as date_end,
  38. lastname,
  39. firstname,
  40. username,
  41. session_admin_id,
  42. nb_days_access_before_beginning,
  43. nb_days_access_after_end,
  44. session_category_id,
  45. visibility
  46. FROM '.$tbl_session.'
  47. LEFT JOIN '.$tbl_user.'
  48. ON id_coach = user_id
  49. WHERE '.$tbl_session.'.id='.$sessionId;
  50. $rs = Database::query($sql);
  51. $session = Database::store_result($rs);
  52. $session = $session[0];
  53. $sql = 'SELECT name FROM '.$tbl_session_category.'
  54. WHERE id = "'.intval($session['session_category_id']).'"';
  55. $rs = Database::query($sql);
  56. $session_category = '';
  57. if (Database::num_rows($rs)>0) {
  58. $rows_session_category = Database::store_result($rs);
  59. $rows_session_category = $rows_session_category[0];
  60. $session_category = $rows_session_category['name'];
  61. }
  62. $action = isset($_GET['action']) ? $_GET['action'] : null;
  63. $url_id = api_get_current_access_url_id();
  64. switch ($action) {
  65. case 'move_up':
  66. SessionManager::moveUp($sessionId, $_GET['course_code']);
  67. header('Location: resume_session.php?id_session='.$sessionId);
  68. exit;
  69. break;
  70. case 'move_down':
  71. SessionManager::moveDown($sessionId, $_GET['course_code']);
  72. header('Location: resume_session.php?id_session='.$sessionId);
  73. exit;
  74. break;
  75. case 'add_user_to_url':
  76. $user_id = $_REQUEST['user_id'];
  77. $result = UrlManager::add_user_to_url($user_id, $url_id);
  78. $user_info = api_get_user_info($user_id);
  79. if ($result) {
  80. $message = Display::return_message(
  81. get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
  82. 'confirm'
  83. );
  84. }
  85. break;
  86. case 'delete':
  87. // Delete course from session.
  88. $idChecked = isset($_GET['idChecked']) ? $_GET['idChecked'] : null;
  89. if (is_array($idChecked)) {
  90. $usersToDelete = array();
  91. foreach ($idChecked as $courseCode) {
  92. // forcing the escape_string
  93. $courseInfo = api_get_course_info($courseCode);
  94. SessionManager::unsubscribe_course_from_session(
  95. $sessionId,
  96. $courseInfo['real_id']
  97. );
  98. }
  99. }
  100. if (!empty($_GET['class'])) {
  101. Database::query("DELETE FROM $tbl_session_rel_class
  102. WHERE session_id='$sessionId' AND class_id=".intval($_GET['class']));
  103. $nbr_affected_rows=Database::affected_rows();
  104. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$sessionId'");
  105. }
  106. if (!empty($_GET['user'])) {
  107. SessionManager::unsubscribe_user_from_session(
  108. $sessionId,
  109. $_GET['user']
  110. );
  111. }
  112. break;
  113. }
  114. Display::display_header($tool_name);
  115. if (!empty($_GET['warn'])) {
  116. Display::display_warning_message(urldecode($_GET['warn']));
  117. }
  118. if (!empty($message)) {
  119. echo $message;
  120. }
  121. echo Display::page_header(
  122. Display::return_icon('session.png', get_lang('Session')).' '.$session['name']
  123. );
  124. $url = Display::url(
  125. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  126. "session_edit.php?page=resume_session.php&id=$sessionId"
  127. );
  128. echo Display::page_subheader(get_lang('GeneralProperties').$url);
  129. ?>
  130. <!-- General properties -->
  131. <table class="data_table">
  132. <tr>
  133. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  134. <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
  135. </tr>
  136. <?php if(!empty($session_category)) { ?>
  137. <tr>
  138. <td><?php echo get_lang('SessionCategory') ?></td>
  139. <td><?php echo $session_category; ?></td>
  140. </tr>
  141. <?php } ?>
  142. <tr>
  143. <td><?php echo get_lang('Date'); ?> :</td>
  144. <td>
  145. <?php
  146. if ($session['date_start'] == '00-00-0000' && $session['date_end']== '00-00-0000' )
  147. echo get_lang('NoTimeLimits');
  148. else {
  149. if ($session['date_start'] != '00-00-0000') {
  150. $session['date_start'] = get_lang('From').' '.$session['date_start'];
  151. } else {
  152. $session['date_start'] = '';
  153. }
  154. if ($session['date_end'] == '00-00-0000') {
  155. $session['date_end'] ='';
  156. } else {
  157. $session['date_end'] = get_lang('Until').' '.$session['date_end'];
  158. }
  159. echo $session['date_start'].' '.$session['date_end'];
  160. }
  161. ?>
  162. </td>
  163. </tr>
  164. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  165. <tr>
  166. <td>
  167. <?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
  168. </td>
  169. <td>
  170. <?php echo intval($session['nb_days_access_before_beginning']) ?>
  171. </td>
  172. </tr>
  173. <tr>
  174. <td>
  175. <?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
  176. </td>
  177. <td>
  178. <?php echo intval($session['nb_days_access_after_end']) ?>
  179. </td>
  180. </tr>
  181. <tr>
  182. <td>
  183. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  184. </td>
  185. <td>
  186. <?php
  187. if ($session['visibility']==1)
  188. echo get_lang('ReadOnly');
  189. elseif($session['visibility']==2)
  190. echo get_lang('Visible');
  191. elseif($session['visibility']==3)
  192. echo api_ucfirst(get_lang('Invisible'));
  193. ?>
  194. </td>
  195. </tr>
  196. <?php
  197. $multiple_url_is_on = api_get_multiple_access_url();
  198. if ($multiple_url_is_on) {
  199. echo '<tr><td>';
  200. echo 'URL';
  201. echo '</td>';
  202. echo '<td>';
  203. $url_list = UrlManager::get_access_url_from_session($sessionId);
  204. foreach ($url_list as $url_data) {
  205. echo $url_data['url'].'<br />';
  206. }
  207. echo '</td></tr>';
  208. }
  209. if (SessionManager::durationPerUserIsEnabled()) {
  210. $sessionInfo = api_get_session_info($sessionId);
  211. echo '<tr><td>';
  212. echo get_lang('Duration');
  213. echo '</td>';
  214. echo '<td>';
  215. echo $sessionInfo['duration'].' ';
  216. echo get_lang('Days');
  217. echo '</td></tr>';
  218. }
  219. ?>
  220. <?php
  221. if (class_exists('AdvancedSessionsPlugin') && AdvancedSessionsPlugin::hasDescriptionField()) {
  222. $sessionDescription = AdvancedSessionsPlugin::getSessionDescription($sessionId);
  223. if (!empty($sessionDescription)) {
  224. ?>
  225. <tr>
  226. <td><?php echo get_lang('Description'); ?></td>
  227. <td><?php echo AdvancedSessionsPlugin::getSessionDescription($sessionId) ?></td>
  228. </tr>
  229. <?php
  230. }
  231. }
  232. ?>
  233. </table>
  234. <br />
  235. <?php
  236. $url = Display::url(
  237. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  238. "add_courses_to_session.php?page=resume_session.php&id_session=$sessionId"
  239. );
  240. echo Display::page_subheader(get_lang('CourseList').$url);
  241. ?>
  242. <!--List of courses -->
  243. <table class="data_table">
  244. <tr>
  245. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  246. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  247. <th width="10%"><?php echo get_lang('UsersNumber'); ?></th>
  248. <th width="25%"><?php echo get_lang('Actions'); ?></th>
  249. </tr>
  250. <?php
  251. if ($session['nbr_courses'] == 0) {
  252. echo '<tr>
  253. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  254. </tr>';
  255. } else {
  256. // select the courses
  257. $orderBy = "ORDER BY title";
  258. if (SessionManager::orderCourseIsEnabled()) {
  259. $orderBy = "ORDER BY position";
  260. }
  261. $sql = "SELECT code,title,visual_code, nbr_users
  262. FROM $tbl_course, $tbl_session_rel_course
  263. WHERE
  264. course_code = code AND
  265. id_session='$sessionId'
  266. $orderBy";
  267. $result = Database::query($sql);
  268. $courses = Database::store_result($result);
  269. $count = 0;
  270. foreach ($courses as $course) {
  271. //select the number of users
  272. $sql = "SELECT count(*)
  273. FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  274. WHERE
  275. srcru.id_user = sru.id_user AND
  276. srcru.id_session = sru.id_session AND
  277. srcru.course_code = '".Database::escape_string($course['code'])."' AND
  278. sru.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
  279. srcru.id_session = '".intval($sessionId)."'";
  280. $rs = Database::query($sql);
  281. $course['nbr_users'] = Database::result($rs, 0, 0);
  282. // Get coachs of the courses in session
  283. $sql = "SELECT user.lastname,user.firstname,user.username
  284. FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  285. WHERE
  286. session_rcru.id_user = user.user_id AND
  287. session_rcru.id_session = '".intval($sessionId)."' AND
  288. session_rcru.course_code ='".Database::escape_string($course['code'])."' AND
  289. session_rcru.status=2";
  290. $rs = Database::query($sql);
  291. $coachs = array();
  292. if (Database::num_rows($rs) > 0) {
  293. while($info_coach = Database::fetch_array($rs)) {
  294. $coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
  295. }
  296. } else {
  297. $coach = get_lang('None');
  298. }
  299. if (count($coachs) > 0) {
  300. $coach = implode('<br />',$coachs);
  301. } else {
  302. $coach = get_lang('None');
  303. }
  304. $orderButtons = null;
  305. if (SessionManager::orderCourseIsEnabled()) {
  306. $upIcon = 'up.png';
  307. $urlUp = api_get_self().'?id_session='.$sessionId.'&course_code='.$course['code'].'&action=move_up';
  308. if ($count == 0) {
  309. $upIcon = 'up_na.png';
  310. $urlUp = '#';
  311. }
  312. $orderButtons = Display::url(
  313. Display::return_icon($upIcon, get_lang('MoveUp')),
  314. $urlUp
  315. );
  316. $downIcon = 'down.png';
  317. $downUrl = api_get_self().'?id_session='.$sessionId.'&course_code='.$course['code'].'&action=move_down';
  318. if ($count +1 == count($courses)) {
  319. $downIcon = 'down_na.png';
  320. $downUrl = '#';
  321. }
  322. $orderButtons .= Display::url(
  323. Display::return_icon($downIcon, get_lang('MoveDown')),
  324. $downUrl
  325. );
  326. }
  327. $orig_param = '&origin=resume_session';
  328. //hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  329. echo '
  330. <tr>
  331. <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$sessionId),'</td>
  332. <td>'.$coach.'</td>
  333. <td>'.$course['nbr_users'].'</td>
  334. <td>
  335. <a href="'.api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$sessionId.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  336. '.$orderButtons.'
  337. <a href="session_course_user_list.php?id_session='.$sessionId.'&course_code='.$course['code'].'">'.Display::return_icon('user.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  338. <a href="'.api_get_path(WEB_CODE_PATH).'/user/user_import.php?action=import&cidReq='.$course['code'].'&id_session='.$sessionId.'">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL).'</a>
  339. <a href="../tracking/courseLog.php?id_session='.$sessionId.'&cidReq='.$course['code'].$orig_param.'&hide_course_breadcrumb=1">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;
  340. <a href="session_course_edit.php?id_session='.$sessionId.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  341. <a href="'.api_get_self().'?id_session='.$sessionId.'&action=delete&idChecked[]='.$course['code'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
  342. </td>
  343. </tr>';
  344. $count++;
  345. }
  346. }
  347. ?>
  348. </table>
  349. <br />
  350. <?php
  351. $url = Display::url(
  352. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  353. "add_users_to_session.php?page=resume_session.php&id_session=$sessionId"
  354. );
  355. $url .= Display::url(
  356. Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL),
  357. "session_user_import.php?id_session=$sessionId"
  358. );
  359. echo Display::page_subheader(get_lang('UserList').$url);
  360. $userList = SessionManager::get_users_by_session($sessionId);
  361. if (!empty($userList)) {
  362. $table = new HTML_Table(array('class' => 'data_table'));
  363. $table->setHeaderContents(0, 0, get_lang('User'));
  364. $table->setHeaderContents(0, 1, get_lang('Status'));
  365. $table->setHeaderContents(0, 2, get_lang('Actions'));
  366. $row = 1;
  367. foreach ($userList as $user) {
  368. $userId = $user['user_id'];
  369. $userInfo = api_get_user_info($userId);
  370. $userLink = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$userId.'">'.
  371. api_htmlentities($userInfo['complete_name_with_username']).'</a>';
  372. $reportingLink = Display::url(
  373. Display::return_icon('statistics.gif', get_lang('Reporting')),
  374. api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param
  375. );
  376. $courseUserLink = Display::url(
  377. Display::return_icon('course.gif', get_lang('BlockCoursesForThisUser')),
  378. api_get_path(WEB_CODE_PATH).'admin/session_course_user.php?id_user='.$user['user_id'].'&id_session='.$sessionId
  379. );
  380. $removeLink = Display::url(
  381. Display::return_icon('delete.png', get_lang('Delete')),
  382. api_get_self().'?id_session='.$sessionId.'&action=delete&user='.$user['user_id'],
  383. array('onclick' => "javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;")
  384. );
  385. $addUserToUrlLink= '';
  386. if ($multiple_url_is_on) {
  387. if ($user['access_url_id'] != $url_id) {
  388. $userLink .= ' '.Display::return_icon(
  389. 'warning.png',
  390. get_lang('UserNotAddedInURL'),
  391. array(),
  392. ICON_SIZE_SMALL
  393. );
  394. $add = Display::return_icon(
  395. 'add.png',
  396. get_lang('AddUsersToURL'),
  397. array(),
  398. ICON_SIZE_SMALL
  399. );
  400. $addUserToUrlLink = '<a href="resume_session.php?action=add_user_to_url&id_session='.$sessionId.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  401. }
  402. }
  403. $editUrl = null;
  404. if (SessionManager::durationPerUserIsEnabled()) {
  405. if (isset($sessionInfo['duration']) && !empty($sessionInfo['duration'])) {
  406. $editUrl = api_get_path(WEB_CODE_PATH) . 'admin/session_user_edit.php?session_id=' . $sessionId . '&user_id=' . $userId;
  407. $editUrl = Display::url(
  408. Display::return_icon('agenda.png', get_lang('SessionDurationEdit')),
  409. $editUrl
  410. );
  411. }
  412. }
  413. $table->setCellContents($row, 0, $userLink);
  414. $link = $reportingLink.$courseUserLink.$removeLink.$addUserToUrlLink.$editUrl;
  415. switch ($user['relation_type']) {
  416. case 1:
  417. $status = get_lang('Drh');
  418. $link = Display::url(
  419. Display::return_icon('edit.png', get_lang('Edit')),
  420. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_sessions_to_user.php?user='.$userId
  421. );
  422. break;
  423. default:
  424. $status = get_lang('Student');
  425. }
  426. $table->setCellContents($row, 1, $status);
  427. $table->setCellContents($row, 2, $link);
  428. $row++;
  429. }
  430. $table->display();
  431. }
  432. Display :: display_footer();
  433. /*
  434. ALTER TABLE session_rel_course ADD COLUMN position int;
  435. ALTER TABLE session_rel_course ADD COLUMN category varchar(255);
  436. https://task.beeznest.com/issues/8317:
  437. ALTER TABLE session ADD COLUMN duration int;
  438. ALTER TABLE session_rel_user ADD COLUMN duration int;
  439. *
  440. */