resume_session.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. /* INIT SECTION */
  8. // name of the language file that needs to be included
  9. $language_file = 'admin';
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. // setting the section (for the tabs)
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. $id_session = (int)$_GET['id_session'];
  15. SessionManager::protect_session_edit($id_session);
  16. $tool_name = get_lang('SessionOverview');
  17. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('Sessions'));
  18. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  19. $session = api_get_session_info($id_session);
  20. $session_cat_info = SessionManager::get_session_category($session['session_category_id']);
  21. $session_category = null;
  22. if (!empty($session_cat_info)) {
  23. $session_category = $session_cat_info['name'];
  24. }
  25. $action = isset($_GET['action']) ? $_GET['action'] : null;
  26. $url_id = api_get_current_access_url_id();
  27. switch ($action) {
  28. case 'add_user_to_url':
  29. $user_id = $_REQUEST['user_id'];
  30. $result = UrlManager::add_user_to_url($user_id, $url_id);
  31. $user_info = api_get_user_info($user_id);
  32. if ($result) {
  33. $message = Display::return_message(get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
  34. }
  35. break;
  36. case 'delete':
  37. if (isset($_GET['course_code_to_delete'])) {
  38. SessionManager::delete_course_in_session($id_session, $_GET['course_code_to_delete']);
  39. }
  40. if (!empty($_GET['user'])) {
  41. SessionManager::unsubscribe_user_from_session($id_session, $_GET['user']);
  42. }
  43. break;
  44. }
  45. Display::display_header($tool_name);
  46. if (!empty($_GET['warn'])) {
  47. Display::display_warning_message(urldecode($_GET['warn']));
  48. }
  49. if (!empty($message)) {
  50. echo $message;
  51. }
  52. $dates = SessionManager::parse_session_dates($session);
  53. echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']." <small>$dates</small>");
  54. $url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_add.php?page=resume_session.php&id=$id_session");
  55. echo Display::page_subheader(get_lang('GeneralProperties').$url);
  56. $coach_info = api_get_user_info($session['id_coach']);
  57. ?>
  58. <!-- General properties -->
  59. <table class="data_table">
  60. <tr>
  61. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  62. <td><?php echo $coach_info['complete_name'].' ('.$coach_info['username'].')' ?></td>
  63. </tr>
  64. <?php if(!empty($session_category)) { ?>
  65. <tr>
  66. <td><?php echo get_lang('SessionCategory') ?></td>
  67. <td><?php echo $session_category; ?></td>
  68. </tr>
  69. <?php } ?>
  70. <tr>
  71. <td><?php echo get_lang('SessionDisplayStartDate'); ?> :</td>
  72. <td><?php echo api_get_local_time($session['display_start_date'], null, null, true); ?></td>
  73. </tr>
  74. <tr>
  75. <td><?php echo get_lang('SessionDisplayEndDate'); ?> :</td>
  76. <td><?php echo api_get_local_time($session['display_end_date'], null, null, true); ?></td>
  77. </tr>
  78. <tr>
  79. <td><?php echo get_lang('SessionStartDate'); ?> :</td>
  80. <td><?php echo api_get_local_time($session['access_start_date'], null, null, true); ?></td>
  81. </tr>
  82. <tr>
  83. <td><?php echo get_lang('SessionEndDate'); ?> :</td>
  84. <td><?php echo api_get_local_time($session['access_end_date'], null, null, true); ?></td>
  85. </tr>
  86. <tr>
  87. <td><?php echo get_lang('SessionCoachStartDate'); ?> :</td>
  88. <td><?php echo api_get_local_time($session['coach_access_start_date'], null, null, true); ?></td>
  89. </tr>
  90. <tr>
  91. <td><?php echo get_lang('SessionCoachEndDate'); ?> :</td>
  92. <td><?php echo api_get_local_time($session['coach_access_end_date'], null, null, true); ?></td>
  93. </tr>
  94. <tr>
  95. <td>
  96. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  97. </td>
  98. <td>
  99. <?php
  100. if (isset($session['access_end_date']) && $session['access_end_date'] != '0000-00-00 00:00:00') {
  101. if ($session['visibility'] == 1)
  102. echo get_lang('ReadOnly');
  103. elseif($session['visibility'] == 2)
  104. echo get_lang('Visible');
  105. elseif($session['visibility'] == 3)
  106. echo api_ucfirst(get_lang('Invisible'));
  107. } else {
  108. //By default course sessions can be access normally see function api_get_session_visibility() when no date_end is proposed
  109. echo get_lang('Visible');
  110. }
  111. ?>
  112. </td>
  113. </tr>
  114. <?php
  115. $session_field = new SessionField();
  116. $session_fields = $session_field->get_all();
  117. foreach ($session_fields as $session_field) {
  118. if ($session_field['field_visible'] != '1') {
  119. continue;
  120. }
  121. $obj = new SessionFieldValue();
  122. $result = $obj->get_values_by_handler_and_field_id($id_session, $session_field['id'], true);
  123. $session_value = null;
  124. if ($result) {
  125. $session_value = $result['field_value'];
  126. }
  127. echo "<tr>";
  128. echo "<td> {$session_field['field_display_text']} </td>";
  129. echo "<td> $session_value </td>";
  130. echo "</tr>";
  131. }
  132. $multiple_url_is_on = api_is_multiple_url_enabled();
  133. if ($multiple_url_is_on) {
  134. echo '<tr><td>';
  135. echo 'URL';
  136. echo '</td>';
  137. echo '<td>';
  138. $url_list = UrlManager::get_access_url_from_session($id_session);
  139. foreach ($url_list as $url_data) {
  140. echo $url_data['url'].'<br />';
  141. }
  142. echo '</td></tr>';
  143. }
  144. ?>
  145. </table>
  146. <br />
  147. <?php
  148. $url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "add_courses_to_session.php?page=resume_session.php&id_session=$id_session");
  149. echo Display::page_subheader(get_lang('CourseList').$url);
  150. ?>
  151. <!--List of courses -->
  152. <table class="data_table">
  153. <tr>
  154. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  155. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  156. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  157. <th width="15%"><?php echo get_lang('Actions'); ?></th>
  158. </tr>
  159. <?php
  160. if ($session['nbr_courses'] == 0){
  161. echo '<tr>
  162. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  163. </tr>';
  164. } else {
  165. $courses = SessionManager::get_course_list_by_session_id($id_session);
  166. foreach ($courses as $course) {
  167. $count_users = SessionManager::get_count_users_in_course_session($course['id'], $id_session);
  168. $coaches = SessionManager::get_session_course_coaches_to_string($course['id'], $id_session);
  169. $orig_param = '&origin=resume_session';
  170. //hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  171. echo '
  172. <tr>
  173. <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/index.php?id_session='.$id_session),'</td>
  174. <td>'.$coaches.'</td>
  175. <td>'.$count_users.'</td>
  176. <td>
  177. <a href="'.api_get_path(WEB_COURSE_PATH).$course['code'].'/index.php?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>
  178. <a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$course['code'].'">'.Display::return_icon('user.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  179. <a href="'.api_get_path(WEB_CODE_PATH).'/user/user_import.php?action=import&cidReq='.$course['code'].'&id_session='.$id_session.'">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL).'</a>
  180. <a href="../tracking/courseLog.php?id_session='.$id_session.'&cidReq='.$course['code'].$orig_param.'&hide_course_breadcrumb=1">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;
  181. <a href="session_course_edit.php?id_session='.$id_session.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
  182. <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&course_code_to_delete='.$course['id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
  183. </td>
  184. </tr>';
  185. }
  186. }
  187. ?>
  188. </table>
  189. <br />
  190. <?php
  191. $url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "add_users_to_session.php?page=resume_session.php&id_session=$id_session");
  192. $url .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL), "session_user_import.php?id_session=$id_session");
  193. echo Display::page_subheader(get_lang('StudentList').$url);
  194. ?>
  195. <!--List of users -->
  196. <table class="data_table">
  197. <tr>
  198. <th>
  199. <?php echo get_lang('User'); ?>
  200. </th>
  201. <th>
  202. <?php echo get_lang('Status'); ?>
  203. </th>
  204. <th>
  205. <?php echo get_lang('Information'); ?>
  206. </th>
  207. <th>
  208. <?php echo get_lang('Destination'); ?>
  209. </th>
  210. <th>
  211. <?php echo get_lang('MovedAt'); ?>
  212. </th>
  213. <th>
  214. <?php echo get_lang('Actions'); ?>
  215. </th>
  216. </tr>
  217. <?php
  218. /*
  219. if ($session['nbr_users'] == 0) {
  220. } else {
  221. */
  222. $orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
  223. $users = SessionManager::get_users_by_session($id_session, 0);
  224. //$reasons = SessionManager::get_session_change_user_reasons();
  225. if (!empty($users)) {
  226. foreach ($users as $user) {
  227. $user_info = api_get_user_info($user['user_id']);
  228. //$link_class = 'class="item_disabled"';
  229. $link_class = null;
  230. $user_status_in_platform = Display::return_icon('error.png', get_lang('Inactive'));
  231. $information = '';
  232. $moved_date = '-';
  233. if ($user_info['active'] == 1 ) {
  234. $user_status_in_platform = Display::return_icon('accept.png', get_lang('Active'));
  235. //$link_class = null;
  236. } else {
  237. $status_info = get_latest_event_by_user_and_type($user['user_id'], LOG_USER_DEACTIVATED);
  238. //var_dump($status_info);
  239. if (!empty($status_info)) {
  240. $information .= sprintf(get_lang('UserInactivedSinceX'), api_convert_and_format_date($status_info['default_date'], DATE_TIME_FORMAT_LONG));
  241. $moved_date = api_get_local_time($status_info['default_date']);
  242. }
  243. $user_info['complete_name_with_username'] = Display::tag('del', $user_info['complete_name_with_username']);
  244. }
  245. $user_link = '';
  246. if (!empty($user['user_id'])) {
  247. $user_link = '<a '.$link_class.' href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.$user_info['complete_name_with_username'].'</a>';
  248. }
  249. $origin = null;
  250. $destination = null;
  251. $row_style = null;
  252. $course_link = '<a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('course.gif', get_lang('BlockCoursesForThisUser')).'&nbsp;</a>';
  253. $moved_link = '<a href="change_user_session.php?user_id='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('move.png', get_lang('ChangeUserSession')).'</a>&nbsp;';
  254. //User in this session is subscribed but was moved to another session
  255. if (isset($user['moved_to']) && !empty($user['moved_to']) || $user['moved_status'] == SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
  256. $variation = SessionManager::get_session_change_user_reasons_variations_by_id($user['moved_status'], 'to');
  257. //$information = $reasons[$user['moved_status']].$variation;
  258. $information .= $variation;
  259. $moved_date = isset($user['moved_at']) && $user['moved_at'] != '0000-00-00 00:00:00' ? api_get_local_time($user['moved_at']) : '-';
  260. $session_info = SessionManager::fetch($user['moved_to']);
  261. if ($user['moved_status'] != SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
  262. $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session;
  263. //$origin = Display::url($session['name'], $url);
  264. if ($session_info) {
  265. $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_info['id'];
  266. $destination = Display::url($session_info['name'], $url);
  267. //$destination = $destination;
  268. }
  269. }
  270. $row_style = 'style = " background-color: #ddd;"';
  271. $course_link= Display::return_icon('course_na.gif', get_lang('BlockCoursesForThisUser')).'&nbsp;';
  272. $moved_link = Display::return_icon('move_na.png', get_lang('ChangeUserSession')).'&nbsp;';
  273. $delete_link = Display::return_icon('delete_na.png', get_lang('Delete')).'&nbsp;';
  274. } else {
  275. $session_origin_info = SessionManager::get_session_rel_user_by_moved_to($id_session, $user['user_id']);
  276. if (!empty($session_origin_info)) {
  277. $moved_date = api_get_local_time($session_origin_info['moved_at']);
  278. }
  279. $session_info = SessionManager::fetch($session_origin_info['id_session']);
  280. $variation = SessionManager::get_session_change_user_reasons_variations_by_id($session_origin_info['moved_status'], 'from');
  281. //$information = $reasons[$session_origin_info['moved_status']].$variation;
  282. $information .= $variation;
  283. if ($session_info) {
  284. $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_info['id'];
  285. $origin = Display::url($session_info['name'], $url);
  286. $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session;
  287. //$destination = Display::url($session['name'], $url);
  288. //$destination = ' / '.$destination;
  289. }
  290. $delete_link = '<a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
  291. }
  292. $link_to_add_user_in_url = '';
  293. if ($multiple_url_is_on) {
  294. if (isset($user['access_url_id']) && $user['access_url_id'] != $url_id) {
  295. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_SMALL);
  296. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_SMALL);
  297. $link_to_add_user_in_url = '<a href="resume_session.php?action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
  298. }
  299. }
  300. echo '<tr '.$row_style.'>
  301. <td width="30%">
  302. '.$user_link.'
  303. </td>
  304. <td>'.$user_status_in_platform.'</td>
  305. <td>'.$information.'</td>
  306. <td>'.$origin.' '.$destination.'</td>
  307. <td>'.$moved_date.'</td>
  308. <td>
  309. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  310. '.$course_link.'
  311. '.$moved_link.'
  312. '.$delete_link.'
  313. '.$link_to_add_user_in_url.'
  314. </td>
  315. </tr>';
  316. }
  317. } else {
  318. echo '<tr>
  319. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  320. </tr>';
  321. }
  322. ?>
  323. </table>
  324. <?php
  325. Display :: display_footer();