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. * @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(
  69. $user_info['firstname'],
  70. $user_info['lastname']
  71. ),
  72. 'confirm'
  73. )
  74. );
  75. }
  76. break;
  77. case 'delete':
  78. $idChecked = $_GET['idChecked'];
  79. if (is_array($idChecked)) {
  80. $my_temp = array();
  81. foreach ($idChecked as $id) {
  82. $courseInfo = api_get_course_info($id);
  83. $my_temp[] = $courseInfo['real_id']; // forcing the escape_string
  84. }
  85. $idChecked = $my_temp;
  86. $idChecked = "'".implode("','", $idChecked)."'";
  87. $result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
  88. $nbr_affected_rows = Database::affected_rows($result);
  89. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
  90. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
  91. }
  92. if (!empty($_GET['class'])) {
  93. $result = Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".intval($_GET['class']));
  94. $nbr_affected_rows = Database::affected_rows($result);
  95. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
  96. }
  97. if (!empty($_GET['user'])) {
  98. $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']));
  99. $nbr_affected_rows = Database::affected_rows($result);
  100. Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
  101. $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id ='$id_session' AND user_id=".intval($_GET['user']));
  102. $nbr_affected_rows = Database::affected_rows($result);
  103. Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE session_id ='$id_session'");
  104. }
  105. break;
  106. }
  107. Display::display_header($tool_name);
  108. echo Display::page_header(
  109. Display::return_icon(
  110. 'session.png',
  111. get_lang('Session')
  112. ).' '.$session['name']
  113. );
  114. echo Display::page_subheader(get_lang('GeneralProperties').$url);
  115. ?>
  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. <tr>
  124. <td><?php echo get_lang('SessionCategory') ?></td>
  125. <td><?php echo $session_category; ?></td>
  126. </tr>
  127. <?php } ?>
  128. <tr>
  129. <td><?php echo get_lang('Date'); ?> :</td>
  130. <td>
  131. <?php
  132. if ($session['access_start_date'] == '00-00-0000' && $session['access_end_date'] == '00-00-0000') {
  133. echo get_lang('NoTimeLimits');
  134. } else {
  135. if ($session['access_start_date'] != '00-00-0000') {
  136. //$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
  137. $session['access_start_date'] = get_lang('From').' '.$session['access_start_date'];
  138. } else {
  139. $session['access_start_date'] = '';
  140. }
  141. if ($session['access_end_date'] == '00-00-0000') {
  142. $session['access_end_date'] = '';
  143. } else {
  144. $session['access_end_date'] = get_lang('Until').' '.$session['access_end_date'];
  145. }
  146. echo $session['access_start_date'].' '.$session['access_end_date'];
  147. } ?>
  148. </td>
  149. </tr>
  150. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  151. <tr>
  152. <td>
  153. <?php echo api_ucfirst(get_lang('SessionCoachStartDate')) ?> :
  154. </td>
  155. <td>
  156. <?php echo intval($session['coach_access_start_date']) ?>
  157. </td>
  158. </tr>
  159. <tr>
  160. <td>
  161. <?php echo api_ucfirst(get_lang('SessionCoachEndDate')) ?> :
  162. </td>
  163. <td>
  164. <?php echo intval($session['coach_session_access_end_date']) ?>
  165. </td>
  166. </tr>
  167. <tr>
  168. <td>
  169. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  170. </td>
  171. <td>
  172. <?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')) ?>
  173. </td>
  174. </tr>
  175. <?php
  176. $multiple_url_is_on = api_get_multiple_access_url();
  177. if ($multiple_url_is_on) {
  178. echo '<tr><td>';
  179. echo 'URL';
  180. echo '</td>';
  181. echo '<td>';
  182. $url_list = UrlManager::get_access_url_from_session($id_session);
  183. foreach ($url_list as $url_data) {
  184. echo $url_data['url'].'<br />';
  185. }
  186. echo '</td></tr>';
  187. }
  188. ?>
  189. </table>
  190. <br />
  191. <?php
  192. echo Display::page_subheader(get_lang('CourseList').$url);
  193. ?>
  194. <!--List of courses -->
  195. <table class="data_table">
  196. <tr>
  197. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  198. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  199. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  200. </tr>
  201. <?php
  202. if ($session['nbr_courses'] == 0) {
  203. echo '<tr>
  204. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  205. </tr>';
  206. } else {
  207. // select the courses
  208. $sql = "SELECT c.id, code,title,visual_code, nbr_users
  209. FROM $tbl_course c,$tbl_session_rel_course sc
  210. WHERE c.id = sc.c_id
  211. AND session_id='$id_session'
  212. ORDER BY title";
  213. $result = Database::query($sql);
  214. $courses = Database::store_result($result);
  215. foreach ($courses as $course) {
  216. //select the number of users
  217. $sql = "SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  218. WHERE
  219. srcru.user_id = sru.user_id AND
  220. srcru.session_id = sru.session_id AND
  221. srcru.c_id = '".Database::escape_string($course['id'])."'AND
  222. sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  223. srcru.session_id = '".intval($id_session)."'";
  224. $rs = Database::query($sql);
  225. $course['nbr_users'] = Database::result($rs, 0, 0);
  226. // Get coachs of the courses in session
  227. $sql = "SELECT user.lastname,user.firstname,user.username
  228. FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  229. WHERE
  230. session_rcru.user_id = user.user_id AND
  231. session_rcru.session_id = '".intval($id_session)."' AND
  232. session_rcru.c_id ='".Database::escape_string($course['id'])."' AND
  233. session_rcru.status=2";
  234. $rs = Database::query($sql);
  235. $coachs = array();
  236. if (Database::num_rows($rs) > 0) {
  237. while ($info_coach = Database::fetch_array($rs)) {
  238. $coachs[] = api_get_person_name(
  239. $info_coach['firstname'],
  240. $info_coach['lastname']
  241. ).' ('.$info_coach['username'].')';
  242. }
  243. } else {
  244. $coach = get_lang('None');
  245. }
  246. if (count($coachs) > 0) {
  247. $coach = implode('<br />', $coachs);
  248. } else {
  249. $coach = get_lang('None');
  250. }
  251. $orig_param = '&origin=resume_session';
  252. //hide_course_breadcrumb the parameter has been added to hide the
  253. // name of the course, that appeared in the default $interbreadcrumb
  254. echo '
  255. <tr>
  256. <td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session), '</td>
  257. <td>'.$coach.'</td>
  258. <td>'.$course['nbr_users'].'</td>
  259. </tr>';
  260. }
  261. }
  262. ?>
  263. </table>
  264. <br />
  265. <?php
  266. echo Display::page_subheader(get_lang('UserList').$url);
  267. ?>
  268. <!--List of users -->
  269. <table class="data_table">
  270. <tr>
  271. <th>
  272. <?php echo get_lang('User'); ?>
  273. </th>
  274. <th>
  275. <?php echo get_lang('Actions'); ?>
  276. </th>
  277. </tr>
  278. <?php
  279. if ($session['nbr_users'] == 0) {
  280. echo '<tr>
  281. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  282. </tr>';
  283. } else {
  284. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  285. if ($multiple_url_is_on) {
  286. $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
  287. FROM $tbl_user u
  288. INNER JOIN $tbl_session_rel_user su
  289. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  290. LEFT OUTER JOIN $table_access_url_user uu ON (uu.user_id = u.user_id)
  291. WHERE su.session_id = $id_session AND (access_url_id = $url_id OR access_url_id is null )
  292. $order_clause";
  293. } else {
  294. $sql = "SELECT u.user_id, lastname, firstname, username
  295. FROM $tbl_user u
  296. INNER JOIN $tbl_session_rel_user su
  297. ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  298. AND su.session_id = ".$id_session.$order_clause;
  299. }
  300. $result = Database::query($sql);
  301. $users = Database::store_result($result);
  302. // change breadcrumb in destination page
  303. $orig_param = '&origin=resume_session&id_session='.$id_session;
  304. foreach ($users as $user) {
  305. $user_link = '';
  306. if (!empty($user['user_id'])) {
  307. $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.
  308. api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']), ENT_QUOTES, $charset).' ('.$user['username'].')</a>';
  309. }
  310. $link_to_add_user_in_url = '';
  311. if ($multiple_url_is_on) {
  312. if ($user['access_url_id'] != $url_id) {
  313. $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_SMALL);
  314. $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_SMALL);
  315. $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>';
  316. }
  317. }
  318. echo '<tr>
  319. <td width="90%">
  320. '.$user_link.'
  321. </td>
  322. <td>
  323. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.
  324. Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  325. <a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.
  326. Display::return_icon('course.png', get_lang('BlockCoursesForThisUser')).'</a>&nbsp;
  327. <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.
  328. Display::return_icon('delete.png', get_lang('Delete')).'</a>
  329. '.$link_to_add_user_in_url.'
  330. </td>
  331. </tr>';
  332. }
  333. }
  334. ?>
  335. </table>
  336. <?php
  337. } else {
  338. api_not_allowed();
  339. }
  340. // footer
  341. Display::display_footer();