resume_session.php 15 KB

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