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