resume_session.php 15 KB

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