session_list.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. $language_file='admin';
  4. $cidReset=true;
  5. include('../inc/global.inc.php');
  6. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  7. require_once (api_get_path(LIBRARY_PATH).'sessionmanager.lib.php');
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script(true);
  10. $htmlHeadXtra[] = '<script language="javascript">
  11. function selectAll(idCheck,numRows,action) {
  12. for(i=0;i<numRows;i++) {
  13. idcheck = document.getElementById(idCheck+"_"+i);
  14. if (action == "true"){
  15. idcheck.checked = true;
  16. } else {
  17. idcheck.checked = false;
  18. }
  19. }
  20. }
  21. </script>
  22. ';
  23. $tbl_session=Database::get_main_table(TABLE_MAIN_SESSION);
  24. $tbl_session_category=Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  25. $tbl_session_rel_course=Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  26. $tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  27. $tbl_session_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_USER);
  28. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  29. $page=intval($_GET['page']);
  30. $action=$_REQUEST['action'];
  31. $sort=in_array($_GET['sort'],array('name', 'nbr_courses', 'name_category', 'date_start', 'date_end','visibility'))?$_GET['sort']:'name';
  32. $idChecked = $_REQUEST['idChecked'];
  33. $id_category = intval($_REQUEST['id_category']);
  34. $cond_url = '';
  35. if ($action == 'delete') {
  36. SessionManager::delete_session($idChecked);
  37. header('Location: '.api_get_self().'?sort='.$sort);
  38. exit();
  39. }
  40. $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  41. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  42. $interbreadcrumb[] = array ("url" => 'session_list.php', "name" => get_lang('SessionList'));
  43. $tool_name = get_lang('SearchASession');
  44. Display :: display_header($tool_name);
  45. $form = new FormValidator('advanced_search','get');
  46. $form->addElement('header', '', $tool_name);
  47. $active_group = array();
  48. $active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
  49. $active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
  50. $form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
  51. $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
  52. $defaults['active'] = 1;
  53. $defaults['inactive'] = 1;
  54. $form->setDefaults($defaults);
  55. $form->display();
  56. } else {
  57. $limit=20;
  58. $from=$page * $limit;
  59. $where = '';
  60. //if user is crfp admin only list its sessions
  61. if(!api_is_platform_admin()) {
  62. $where = 'WHERE session_admin_id='.intval($_user['user_id']);
  63. $where .= (empty($_REQUEST['keyword']) ? "" : " AND s.name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  64. } else {
  65. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE s.name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  66. }
  67. if (isset($_REQUEST['active']) && isset($_REQUEST['inactive'] )) {
  68. // if both are set we search all sessions
  69. $cond_url = '&amp;active='.Security::remove_XSS($_REQUEST['active']);
  70. $cond_url .= '&amp;inactive='.Security::remove_XSS($_REQUEST['inactive']);
  71. } else {
  72. if (isset($_REQUEST['active'])) {
  73. if (empty($where)) {
  74. $where .= ' WHERE ( (s.date_start <= CURDATE() AND s.date_end >= CURDATE()) OR s.date_start="0000-00-00" ) ';
  75. } else {
  76. $where .= ' AND ( (s.date_start <= CURDATE() AND s.date_end >= CURDATE()) OR s.date_start="0000-00-00" ) ';
  77. }
  78. $cond_url = '&amp;active='.Security::remove_XSS($_REQUEST['active']);
  79. }
  80. if (isset($_REQUEST['inactive'])) {
  81. if (empty($where)) {
  82. $where .= ' WHERE ( (s.date_start > CURDATE() OR s.date_end < CURDATE()) AND s.date_start<>"0000-00-00" ) ';
  83. } else {
  84. $where .= ' AND ( (s.date_start > CURDATE() OR s.date_end < CURDATE()) AND s.date_start<>"0000-00-00" ) ';
  85. }
  86. $cond_url = '&amp;inactive='.Security::remove_XSS($_REQUEST['inactive']);
  87. }
  88. }
  89. if(isset($_GET['id_category'])){
  90. $where.= (empty($where))? ' AND ' : ' WHERE ';
  91. $id_category = Security::remove_XSS($id_category);
  92. $where.= ' session_category_id = "'.$id_category.'" ';
  93. $cond_url.= '&amp;id_category='.$id_category;
  94. }
  95. $sort = ($sort != "name_category")? 's.'.$sort : 'category_name';
  96. $query = "SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name, s.visibility
  97. FROM $tbl_session s
  98. LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
  99. INNER JOIN $tbl_user u ON s.id_coach = u.user_id
  100. $where
  101. ORDER BY $sort ";
  102. //query which allows me to get a record without taking into account the page
  103. $query_rows = "SELECT count(*) as total_rows
  104. FROM $tbl_session s
  105. LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
  106. INNER JOIN $tbl_user u ON s.id_coach = u.user_id
  107. $where ";
  108. //filtering the session list by access_url
  109. if ($_configuration['multiple_access_urls'] == true){
  110. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  111. $access_url_id = api_get_current_access_url_id();
  112. if ($access_url_id != -1) {
  113. $where.= " AND ar.access_url_id = $access_url_id ";
  114. $query = "SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name , s.visibility
  115. FROM $tbl_session s
  116. LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
  117. INNER JOIN $tbl_user u ON s.id_coach = u.user_id
  118. INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
  119. $where
  120. ORDER BY $sort LIMIT $from,".($limit+1);
  121. $query_rows = "SELECT count(*) as total_rows
  122. FROM $tbl_session s
  123. LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
  124. INNER JOIN $tbl_user u ON s.id_coach = u.user_id
  125. INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
  126. $where ";
  127. }
  128. }
  129. $result_rows = Database::query($query_rows,__FILE__,__LINE__);
  130. $recorset = Database::fetch_array($result_rows);
  131. $num = $recorset['total_rows'];
  132. $result=Database::query($query,__FILE__,__LINE__);
  133. $Sessions=Database::store_result($result);
  134. $nbr_results=sizeof($Sessions);
  135. $tool_name = get_lang('SessionList');
  136. Display::display_header($tool_name);
  137. //api_display_tool_title($tool_name);
  138. if (!empty($_GET['warn'])) {
  139. Display::display_warning_message(urldecode($_GET['warn']),false);
  140. }
  141. if(isset($_GET['action'])) {
  142. Display::display_normal_message(stripslashes($_GET['message']),false);
  143. }
  144. ?>
  145. <div class="actions">
  146. <?php
  147. echo '<div style="float:right;">
  148. <a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('view_more_stats.gif',get_lang('AddSessionsInCategories')).get_lang('AddSessionsInCategories').'</a>
  149. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::return_icon('view_more_stats.gif',get_lang('AddSession')).get_lang('AddSession').'</a>
  150. </div>';
  151. ?>
  152. <form method="POST" action="session_list.php">
  153. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  154. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  155. <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a>
  156. </form>
  157. <form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  158. </div><br />
  159. <div align="left">
  160. <?php
  161. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  162. echo get_lang('NoSearchResults');
  163. echo ' </div>';
  164. } else {
  165. if($num>$limit){
  166. if($page) {
  167. ?>
  168. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
  169. <?php
  170. } else {
  171. echo get_lang('Previous');
  172. }
  173. ?>
  174. |
  175. <?php
  176. if($nbr_results > $limit) {
  177. ?>
  178. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
  179. <?php
  180. } else {
  181. echo get_lang('Next');
  182. }
  183. }
  184. ?>
  185. </div>
  186. <br />
  187. <table class="data_table" width="100%">
  188. <tr>
  189. <th>&nbsp;</th>
  190. <th><a href="<?php echo api_get_self(); ?>?sort=name"><?php echo get_lang('NameOfTheSession'); ?></a></th>
  191. <th><a href="<?php echo api_get_self(); ?>?sort=nbr_courses"><?php echo get_lang('NumberOfCourses'); ?></a></th>
  192. <th><a href="<?php echo api_get_self(); ?>?sort=name_category<?php echo $cond_url; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  193. <th><a href="<?php echo api_get_self(); ?>?sort=date_start"><?php echo get_lang('StartDate'); ?></a></th>
  194. <th><a href="<?php echo api_get_self(); ?>?sort=date_end"><?php echo get_lang('EndDate'); ?></a></th>
  195. <th><a href="<?php echo api_get_self(); ?>?sort=coach_name"><?php echo get_lang('Coach'); ?></a></th>
  196. <th><a href="<?php echo api_get_self(); ?>?sort=visibility<?php echo $cond_url; ?>"><?php echo get_lang('Visibility'); ?></a></th>
  197. <th><?php echo get_lang('Actions'); ?></th>
  198. </tr>
  199. <?php
  200. $i=0;
  201. $x=0;
  202. foreach ($Sessions as $key=>$enreg) {
  203. if($key == $limit) {
  204. break;
  205. }
  206. $sql = 'SELECT COUNT(course_code) FROM '.$tbl_session_rel_course.' WHERE id_session='.intval($enreg['id']);
  207. $rs = Database::query($sql, __FILE__, __LINE__);
  208. list($nb_courses) = Database::fetch_array($rs);
  209. ?>
  210. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  211. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  212. <td><a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></a></td>
  213. <td><a href="session_course_list.php?id_session=<?php echo $enreg['id']; ?>"><?php echo $nb_courses; ?> cours</a></td>
  214. <td><?php echo api_htmlentities($enreg['category_name'],ENT_QUOTES,$charset); ?></td>
  215. <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  216. <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  217. <td><?php echo api_htmlentities(api_get_person_name($enreg['firstname'], $enreg['lastname']),ENT_QUOTES,$charset); ?></td>
  218. <td><?php
  219. switch (intval($enreg['visibility'])) {
  220. case SESSION_VISIBLE_READ_ONLY: //1
  221. echo get_lang('ReadOnly');
  222. break;
  223. case SESSION_VISIBLE: //2
  224. echo get_lang('Visible');
  225. break;
  226. case SESSION_INVISIBLE: //3
  227. echo api_ucfirst(get_lang('Invisible'));
  228. break;
  229. }
  230. ?></td>
  231. <td>
  232. <a href="add_users_to_session.php?page=session_list.php&id_session=<?php echo $enreg['id']; ?>"><?php Display::display_icon('add_user_big.gif', get_lang('SubscribeUsersToSession')); ?></a>
  233. <a href="add_courses_to_session.php?page=session_list.php&id_session=<?php echo $enreg['id']; ?>"><?php Display::display_icon('synthese_view.gif', get_lang('SubscribeCoursesToSession')); ?></a>
  234. <a href="session_edit.php?page=session_list.php&id=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a>
  235. <a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=delete&idChecked=<?php echo $enreg['id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"><?php Display::display_icon('delete.gif', get_lang('Delete')); ?></a>
  236. </td>
  237. </tr>
  238. <?php
  239. $i=$i ? 0 : 1;
  240. $x++;
  241. }
  242. unset($Sessions);
  243. ?>
  244. </table>
  245. <br />
  246. <div align="left">
  247. <?php
  248. if($num>$limit) {
  249. if($page)
  250. {
  251. ?>
  252. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
  253. <?php
  254. }
  255. else
  256. {
  257. echo get_lang('Previous');
  258. }
  259. ?>
  260. |
  261. <?php
  262. if($nbr_results > $limit)
  263. {
  264. ?>
  265. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
  266. <?php
  267. }
  268. else
  269. {
  270. echo get_lang('Next');
  271. }
  272. }
  273. ?>
  274. </div>
  275. <br />
  276. <a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  277. <a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  278. <select name="action">
  279. <option value="delete"><?php echo get_lang('DeleteSelectedSessions'); ?></option>
  280. </select>
  281. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  282. <?php } ?>
  283. </table>
  284. <?php
  285. }
  286. Display::display_footer();
  287. ?>