resume_session.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <?php // $Id: resume_session.php 20709 2009-05-15 19:12:37Z ivantcholakov $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * @author Bart Mollet
  6. * @package dokeos.admin
  7. ==============================================================================
  8. */
  9. /*
  10. ==============================================================================
  11. INIT SECTION
  12. ==============================================================================
  13. */
  14. // name of the language file that needs to be included
  15. $language_file = 'admin';
  16. $cidReset = true;
  17. require '../inc/global.inc.php';
  18. // setting the section (for the tabs)
  19. $this_section=SECTION_PLATFORM_ADMIN;
  20. api_protect_admin_script(true);
  21. $tool_name = get_lang('SessionOverview');
  22. $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  23. $interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList'));
  24. // Database Table Definitions
  25. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  26. $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
  27. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  28. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  29. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  30. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  31. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  32. $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS);
  33. $tbl_class_rel_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
  34. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  35. $id_session = (int)$_GET['id_session'];
  36. $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
  37. FROM '.$tbl_session.'
  38. LEFT JOIN '.$tbl_user.'
  39. ON id_coach = user_id
  40. WHERE '.$tbl_session.'.id='.$id_session;
  41. $rs = Database::query($sql, __FILE__, __LINE__);
  42. $session = Database::store_result($rs);
  43. $session = $session[0];
  44. if(!api_is_platform_admin() && $session['session_admin_id']!=$_user['user_id'])
  45. {
  46. api_not_allowed(true);
  47. }
  48. $sql = 'SELECT name FROM '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
  49. $rs = Database::query($sql, __FILE__, __LINE__);
  50. $session_category = '';
  51. if(Database::num_rows($rs)>0) {
  52. $rows_session_category = Database::store_result($rs);
  53. $rows_session_category = $rows_session_category[0];
  54. $session_category = $rows_session_category['name'];
  55. }
  56. if($_GET['action'] == 'delete')
  57. {
  58. $idChecked = $_GET['idChecked'];
  59. if(is_array($idChecked)) {
  60. $my_temp = array();
  61. foreach ($idChecked as $id){
  62. $my_temp[]= Database::escape_string($id);// forcing the escape_string
  63. }
  64. $idChecked = $my_temp;
  65. $idChecked="'".implode("','",$idChecked)."'";
  66. Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)",__FILE__,__LINE__);
  67. $nbr_affected_rows=Database::affected_rows();
  68. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code IN($idChecked)",__FILE__,__LINE__);
  69. Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'",__FILE__,__LINE__);
  70. }
  71. if(!empty($_GET['class'])){
  72. Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".Database::escape_string($_GET['class']),__FILE__,__LINE__);
  73. $nbr_affected_rows=Database::affected_rows();
  74. Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'",__FILE__,__LINE__);
  75. }
  76. if(!empty($_GET['user'])){
  77. Database::query("DELETE FROM $tbl_session_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']),__FILE__,__LINE__);
  78. $nbr_affected_rows=Database::affected_rows();
  79. Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'",__FILE__,__LINE__);
  80. Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']),__FILE__,__LINE__);
  81. $nbr_affected_rows=Database::affected_rows();
  82. Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session'",__FILE__,__LINE__);
  83. }
  84. }
  85. Display::display_header($tool_name);
  86. if (!empty($_GET['warn'])) {
  87. Display::display_warning_message(urldecode($_GET['warn']));
  88. }
  89. api_display_tool_title($tool_name);
  90. ?>
  91. <!-- General properties -->
  92. <table class="data_table" width="100%">
  93. <tr>
  94. <th colspan="2"><?php echo get_lang('GeneralProperties'); ?>
  95. <a href="session_edit.php?page=resume_session.php&id=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  96. </th>
  97. </tr>
  98. <tr>
  99. <td><?php echo get_lang('SessionName');?> :</td>
  100. <td><?php echo $session['name'] ?></td>
  101. </tr>
  102. <tr>
  103. <td><?php echo get_lang('GeneralCoach'); ?> :</td>
  104. <td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
  105. </tr>
  106. <?php if(!empty($session_category)): ?>
  107. <tr>
  108. <td><?php echo get_lang('SessionCategory') ?></td>
  109. <td><?php echo $session_category; ?></td>
  110. </tr>
  111. <?php endif; ?>
  112. <tr>
  113. <td><?php echo get_lang('Date'); ?> :</td>
  114. <td>
  115. <?php
  116. if($session['date_start']=='00-00-0000')
  117. echo get_lang('NoTimeLimits');
  118. else
  119. echo get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
  120. ?>
  121. </td>
  122. </tr>
  123. <!-- show nb_days_before and nb_days_after only if they are different from 0 -->
  124. <tr>
  125. <td>
  126. <?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
  127. </td>
  128. <td>
  129. <?php echo intval($session['nb_days_access_before_beginning']) ?>
  130. </td>
  131. </tr>
  132. <tr>
  133. <td>
  134. <?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
  135. </td>
  136. <td>
  137. <?php echo intval($session['nb_days_access_after_end']) ?>
  138. </td>
  139. </tr>
  140. <tr>
  141. <td>
  142. <?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
  143. </td>
  144. <td>
  145. <?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')) ?>
  146. </td>
  147. </tr>
  148. </table>
  149. <br />
  150. <!--List of courses -->
  151. <table class="data_table" width="100%">
  152. <tr>
  153. <th colspan="4"><?php echo get_lang('CourseList'); ?>
  154. <a href="add_courses_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  155. </th>
  156. </tr>
  157. <tr>
  158. <tr>
  159. <th width="35%"><?php echo get_lang('CourseTitle'); ?></th>
  160. <th width="30%"><?php echo get_lang('CourseCoach'); ?></th>
  161. <th width="20%"><?php echo get_lang('UsersNumber'); ?></th>
  162. <th width="15%"><?php echo get_lang('Actions'); ?></th>
  163. </tr>
  164. </tr>
  165. <?php
  166. if($session['nbr_courses']==0){
  167. echo '
  168. <tr>
  169. <td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
  170. </tr>';
  171. }
  172. else {
  173. // select the courses
  174. $sql = "SELECT code,title,visual_code, nbr_users, lastname, firstname, username
  175. FROM $tbl_course,$tbl_session_rel_course
  176. LEFT JOIN $tbl_user
  177. ON $tbl_session_rel_course.id_coach = $tbl_user.user_id
  178. WHERE course_code=code
  179. AND id_session='$id_session'
  180. ORDER BY title";
  181. $result=Database::query($sql,__FILE__,__LINE__);
  182. $courses=Database::store_result($result);
  183. foreach($courses as $course){
  184. //select the number of users
  185. $sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
  186. WHERE srcru.id_user = sru.id_user AND srcru.course_code = '".Database::escape_string($course['code'])."'
  187. AND srcru.id_session = '".intval($id_session)."'";
  188. $rs = Database::query($sql, __FILE__, __LINE__);
  189. $course['nbr_users'] = Database::result($rs,0,0);
  190. // Get coachs of the courses in session
  191. $sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
  192. 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";
  193. $rs = Database::query($sql,__FILE__,__LINE__);
  194. $coachs = array();
  195. if (Database::num_rows($rs) > 0) {
  196. while($info_coach = Database::fetch_array($rs)) {
  197. $coachs[] = $info_coach['lastname'].' '.$info_coach['firstname'].' ('.$info_coach['username'].')';
  198. }
  199. } else {
  200. $coach = get_lang('None');
  201. }
  202. if (count($coachs) > 0) {
  203. $coach = implode('<br />',$coachs);
  204. } else {
  205. $coach = get_lang('None');
  206. }
  207. $orig_param = '&origin=resume_session';
  208. //hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
  209. echo '
  210. <tr>
  211. <td>'.$course['title'].' ('.$course['visual_code'].')</td>
  212. <td>'.$coach.'</td>
  213. <td>'.$course['nbr_users'].'</td>
  214. <td>
  215. <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;
  216. <a href="session_course_edit.php?id_session='.$id_session.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>
  217. <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.gif', get_lang('Delete')).'</a>
  218. </td>
  219. </tr>';
  220. }
  221. }
  222. ?>
  223. </table>
  224. <br />
  225. <!--List of courses -->
  226. <table class="data_table" width="100%">
  227. <tr>
  228. <th colspan="4"><?php echo get_lang('UserList'); ?>
  229. <a href="add_users_to_session.php?page=resume_session.php&id_session=<?php echo $id_session; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a></th>
  230. </th>
  231. </tr>
  232. </tr>
  233. <?php
  234. if($session['nbr_users']==0){
  235. echo '
  236. <tr>
  237. <td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
  238. </tr>';
  239. }
  240. else {
  241. // classe development, obsolete for the moment
  242. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  243. $sql = 'SELECT '.$tbl_user.'.user_id, lastname, firstname, username
  244. FROM '.$tbl_user.'
  245. INNER JOIN '.$tbl_session_rel_user.'
  246. ON '.$tbl_user.'.user_id = '.$tbl_session_rel_user.'.id_user
  247. AND '.$tbl_session_rel_user.'.id_session = '.$id_session.$order_clause;
  248. $result=Database::query($sql,__FILE__,__LINE__);
  249. $users=Database::store_result($result);
  250. $orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
  251. foreach($users as $user){
  252. echo '<tr>
  253. <td width="90%">
  254. <b>'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</b>
  255. </td>
  256. <td>
  257. <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
  258. <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;
  259. <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.gif', get_lang('Delete')).'</a>
  260. </td>
  261. </tr>';
  262. }
  263. }
  264. ?>
  265. </table>
  266. <?php
  267. // footer
  268. Display :: display_footer();
  269. ?>