resume_session.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Bart Mollet, Julio Montoya lot of fixes
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. $id_session = (int) $_GET['id_session'];
  13. SessionManager::protect_teacher_session_edit($id_session);
  14. $tool_name = get_lang('SessionOverview');
  15. $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
  16. if ($allowTutors === 'true') {
  17. // Database Table Definitions
  18. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  19. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  20. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  21. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  22. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  23. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  24. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  25. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  26. $table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  27. $sql = 'SELECT
  28. name,
  29. nbr_courses,
  30. nbr_users,
  31. nbr_classes,
  32. DATE_FORMAT(access_start_date,"%d-%m-%Y") as access_start_date,
  33. DATE_FORMAT(access_end_date,"%d-%m-%Y") as access_end_date,
  34. lastname,
  35. firstname,
  36. username,
  37. session_admin_id,
  38. coach_access_start_date,
  39. coach_access_end_date,
  40. session_category_id,
  41. visibility
  42. FROM '.$tbl_session.'
  43. LEFT JOIN '.$tbl_user.'
  44. ON id_coach = user_id
  45. WHERE '.$tbl_session.'.id='.$id_session;
  46. $rs = Database::query($sql);
  47. $session = Database::store_result($rs);
  48. $session = $session[0];
  49. $sql = 'SELECT name
  50. FROM '.$tbl_session_category.'
  51. WHERE id = '.intval($session['session_category_id']);
  52. $rs = Database::query($sql);
  53. $session_category = '';
  54. if (Database::num_rows($rs) > 0) {
  55. $rows_session_category = Database::store_result($rs);
  56. $rows_session_category = $rows_session_category[0];
  57. $session_category = $rows_session_category['name'];
  58. }
  59. $action = isset($_GET['action']) ? $_GET['action'] : null;
  60. $url_id = api_get_current_access_url_id();
  61. switch ($action) {
  62. case 'add_user_to_url':
  63. $user_id = $_REQUEST['user_id'];
  64. $result = UrlManager::add_user_to_url($user_id, $url_id);
  65. $user_info = api_get_user_info($user_id);
  66. if ($result) {
  67. Display::addFlash(
  68. Display::return_message(
  69. get_lang('UserAdded').' '.api_get_person_name(
  70. $user_info['firstname'],
  71. $user_info['lastname']
  72. ),
  73. 'confirm'
  74. )
  75. );
  76. }
  77. break;
  78. case 'delete':
  79. $idChecked = $_GET['idChecked'];
  80. if (is_array($idChecked)) {
  81. $my_temp = [];
  82. foreach ($idChecked as $id) {
  83. $courseInfo = api_get_course_info($id);
  84. $my_temp[] = $courseInfo['real_id']; // forcing the escape_string
  85. }
  86. $idChecked = $my_temp;
  87. $idChecked = "'".implode("','", $idChecked)."'";
  88. $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
  89. $nbr_affected_rows = Database::affected_rows($result);
  90. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
  91. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  92. }
  93. if (!empty($_GET['class'])) {
  94. $result = Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".intval($_GET['class']));
  95. $nbr_affected_rows = Database::affected_rows($result);
  96. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
  97. }
  98. if (!empty($_GET['user'])) {
  99. $result = Database::query("DELETE FROM $tbl_session_rel_user WHERE relation_type<>".SESSION_RELATION_TYPE_RRHH." AND session_id ='$id_session' AND user_id=".intval($_GET['user']));
  100. $nbr_affected_rows = Database::affected_rows($result);
  101. Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
  102. $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id ='$id_session' AND user_id=".intval($_GET['user']));
  103. $nbr_affected_rows = Database::affected_rows($result);
  104. Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE session_id ='$id_session'");
  105. }
  106. break;
  107. }
  108. Display::display_header($tool_name);
  109. echo Display::page_header(
  110. Display::return_icon(
  111. 'session.png',
  112. get_lang('Session')
  113. ).' '.$session['name']
  114. );
  115. echo Display::page_subheader(get_lang('GeneralProperties').$url); ?>
  116. <!-- General properties -->
  117. <table class="data_table">
  118. <tr>
  119. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  120. <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')'; ?></td>
  121. </tr>
  122. <?php if (!empty($session_category)) {
  123. ?>
  124. <tr>
  125. <td><?php echo get_lang('SessionCategory'); ?></td>
  126. <td><?php echo $session_category; ?></td>
  127. </tr>
  128. <?php
  129. } ?>
  130. <tr>
  131. <td><?php echo get_lang('Date'); ?> :</td>
  132. <td>
  133. <?php
  134. if ($session['access_start_date'] == '00-00-0000' && $session['access_end_date'] == '00-00-0000') {
  135. echo get_lang('NoTimeLimits');
  136. } else {
  137. if ($session['access_start_date'] != '00-00-0000') {
  138. //$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
  139. $session['access_start_date'] = get_lang('From').' '.$session['access_start_date'];
  140. } else {
  141. $session['access_start_date'] = '';
  142. }
  143. if ($session['access_end_date'] == '00-00-0000') {
  144. $session['access_end_date'] = '';
  145. } else {
  146. $session['access_end_date'] = get_lang('Until').' '.$session['access_end_date'];
  147. }
  148. echo $session['access_start_date'].' '.$session['access_end_date'];
  149. } ?>
  150. </td>
  151. </tr>
  152. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  153. <tr>
  154. <td>
  155. <?php echo api_ucfirst(get_lang('SessionCoachStartDate')); ?> :
  156. </td>
  157. <td>
  158. <?php echo intval($session['coach_access_start_date']); ?>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td>
  163. <?php echo api_ucfirst(get_lang('SessionCoachEndDate')); ?> :
  164. </td>
  165. <td>
  166. <?php echo intval($session['coach_session_access_end_date']); ?>
  167. </td>
  168. </tr>
  169. <tr>
  170. <td>
  171. <?php echo api_ucfirst(get_lang('SessionVisibility')); ?> :
  172. </td>
  173. <td>
  174. <?php if ($session['visibility'] == 1) {
  175. echo get_lang('ReadOnly');
  176. } elseif ($session['visibility'] == 2) {
  177. echo get_lang('Visible');
  178. } elseif ($session['visibility'] == 3) {
  179. echo api_ucfirst(get_lang('Invisible'));
  180. } ?>
  181. </td>
  182. </tr>
  183. <?php
  184. $multiple_url_is_on = api_get_multiple_access_url();
  185. if ($multiple_url_is_on) {
  186. echo '<tr><td>';
  187. echo 'URL';
  188. echo '</td>';
  189. echo '<td>';
  190. $url_list = UrlManager::get_access_url_from_session($id_session);
  191. foreach ($url_list as $url_data) {
  192. echo $url_data['url'].'<br />';
  193. }
  194. echo '</td></tr>';
  195. } ?>
  196. </table>
  197. <br />
  198. <?php
  199. echo Display::page_subheader(get_lang('CourseList').$url); ?>
  200. <!--List of courses -->
  201. <table class="data_table">
  202. <tr>
  203. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  204. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  205. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  206. </tr>
  207. <?php
  208. if ($session['nbr_courses'] == 0) {
  209. echo '<tr>
  210. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  211. </tr>';
  212. } else {
  213. // select the courses
  214. $sql = "SELECT c.id, code,title,visual_code, nbr_users
  215. FROM $tbl_course c,$tbl_session_rel_course sc
  216. WHERE c.id = sc.c_id
  217. AND session_id='$id_session'
  218. ORDER BY title";
  219. $result = Database::query($sql);
  220. $courses = Database::store_result($result);
  221. foreach ($courses as $course) {
  222. // Select the number of users
  223. $sql = "SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  224. WHERE
  225. srcru.user_id = sru.user_id AND
  226. srcru.session_id = sru.session_id AND
  227. srcru.c_id = '".Database::escape_string($course['id'])."'AND
  228. sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  229. srcru.session_id = '".intval($id_session)."'";
  230. $rs = Database::query($sql);
  231. $course['nbr_users'] = Database::result($rs, 0, 0);
  232. // Get coachs of the courses in session
  233. $sql = "SELECT user.lastname,user.firstname,user.username
  234. FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  235. WHERE
  236. session_rcru.user_id = user.user_id AND
  237. session_rcru.session_id = '".intval($id_session)."' AND
  238. session_rcru.c_id ='".Database::escape_string($course['id'])."' AND
  239. session_rcru.status=2";
  240. $rs = Database::query($sql);
  241. $coachs = [];
  242. if (Database::num_rows($rs) > 0) {
  243. while ($info_coach = Database::fetch_array($rs)) {
  244. $coachs[] = api_get_person_name(
  245. $info_coach['firstname'],
  246. $info_coach['lastname']
  247. ).' ('.$info_coach['username'].')';
  248. }
  249. } else {
  250. $coach = get_lang('None');
  251. }
  252. if (count($coachs) > 0) {
  253. $coach = implode('<br />', $coachs);
  254. } else {
  255. $coach = get_lang('None');
  256. }
  257. $orig_param = '&origin=resume_session';
  258. //hide_course_breadcrumb the parameter has been added to hide the
  259. // name of the course, that appeared in the default $interbreadcrumb
  260. echo '
  261. <tr>
  262. <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session), '</td>
  263. <td>'.$coach.'</td>
  264. <td>'.$course['nbr_users'].'</td>
  265. </tr>';
  266. }
  267. } ?>
  268. </table>
  269. <br />
  270. <?php
  271. echo Display::page_subheader(get_lang('UserList').$url); ?>
  272. <!--List of users -->
  273. <table class="data_table">
  274. <tr>
  275. <th>
  276. <?php echo get_lang('User'); ?>
  277. </th>
  278. <th>
  279. <?php echo get_lang('Actions'); ?>
  280. </th>
  281. </tr>
  282. <?php
  283. if ($session['nbr_users'] == 0) {
  284. echo '<tr>
  285. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  286. </tr>';
  287. } else {
  288. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  289. if ($multiple_url_is_on) {
  290. $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
  291. FROM $tbl_user u
  292. INNER JOIN $tbl_session_rel_user su
  293. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  294. LEFT OUTER JOIN $table_access_url_user uu ON (uu.user_id = u.user_id)
  295. WHERE su.session_id = $id_session AND (access_url_id = $url_id OR access_url_id is null )
  296. $order_clause";
  297. } else {
  298. $sql = "SELECT u.user_id, lastname, firstname, username
  299. FROM $tbl_user u
  300. INNER JOIN $tbl_session_rel_user su
  301. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  302. AND su.session_id = ".$id_session.$order_clause;
  303. }
  304. $result = Database::query($sql);
  305. $users = Database::store_result($result);
  306. // change breadcrumb in destination page
  307. $orig_param = '&origin=resume_session&id_session='.$id_session;
  308. foreach ($users as $user) {
  309. $user_link = '';
  310. if (!empty($user['user_id'])) {
  311. $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.
  312. api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']), ENT_QUOTES, $charset).' ('.$user['username'].')</a>';
  313. }
  314. $link_to_add_user_in_url = '';
  315. if ($multiple_url_is_on) {
  316. if ($user['access_url_id'] != $url_id) {
  317. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), [], ICON_SIZE_SMALL);
  318. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), [], ICON_SIZE_SMALL);
  319. $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>';
  320. }
  321. }
  322. echo '<tr>
  323. <td width="90%">
  324. '.$user_link.'
  325. </td>
  326. <td>
  327. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.
  328. Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  329. <a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.
  330. Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')).'</a>&nbsp;
  331. <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.
  332. Display::return_icon('delete.png', get_lang('Delete')).'</a>
  333. '.$link_to_add_user_in_url.'
  334. </td>
  335. </tr>';
  336. }
  337. } ?>
  338. </table>
  339. <?php
  340. } else {
  341. api_not_allowed();
  342. }
  343. // footer
  344. Display::display_footer();