session_list.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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_rel_course=Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  25. $tbl_session_rel_course_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  26. $tbl_session_rel_user=Database::get_main_table(TABLE_MAIN_SESSION_USER);
  27. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  28. $page=intval($_GET['page']);
  29. $action=$_REQUEST['action'];
  30. $sort=in_array($_GET['sort'],array('name','nbr_courses','date_start','date_end'))?$_GET['sort']:'name';
  31. $idChecked = $_REQUEST['idChecked'];
  32. if ($action == 'delete') {
  33. SessionManager::delete_session($idChecked);
  34. header('Location: '.api_get_self().'?sort='.$sort);
  35. exit();
  36. }
  37. $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  38. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  39. $interbreadcrumb[] = array ("url" => 'session_list.php', "name" => get_lang('SessionList'));
  40. $tool_name = get_lang('SearchASession');
  41. Display :: display_header($tool_name);
  42. $form = new FormValidator('advanced_search','get');
  43. $form->addElement('header', '', $tool_name);
  44. $active_group = array();
  45. $active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
  46. $active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
  47. $form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
  48. $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
  49. $defaults['active'] = 1;
  50. $defaults['inactive'] = 1;
  51. $form->setDefaults($defaults);
  52. $form->display();
  53. } else {
  54. $limit=20;
  55. $from=$page * $limit;
  56. //if user is crfp admin only list its sessions
  57. if(!api_is_platform_admin()) {
  58. $where = 'WHERE session_admin_id='.intval($_user['user_id']);
  59. $where .= (empty($_REQUEST['keyword']) ? " " : " AND name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  60. }
  61. else {
  62. $where .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  63. }
  64. if(trim($where) == ''){
  65. $and=" WHERE id_coach=user_id";
  66. } else {
  67. $and=" AND id_coach=user_id";
  68. }
  69. if(isset($_REQUEST['active']) && !isset($_REQUEST['inactive']) ){
  70. $and .= ' AND ( (session.date_start <= CURDATE() AND session.date_end >= CURDATE()) OR session.date_start="0000-00-00" ) ';
  71. $cond_url = '&amp;active='.Security::remove_XSS($_REQUEST['active']);
  72. }
  73. if(!isset($_REQUEST['active']) && isset($_REQUEST['inactive']) ){
  74. $and .= ' AND ( (session.date_start > CURDATE() OR session.date_end < CURDATE()) AND session.date_start<>"0000-00-00" ) ';
  75. $cond_url = '&amp;inactive='.Security::remove_XSS($_REQUEST['inactive']);
  76. }
  77. $query= "SELECT id,name,nbr_courses,date_start,date_end, firstname, lastname
  78. FROM $tbl_session, $tbl_user
  79. $where
  80. $and
  81. ORDER BY $sort
  82. LIMIT $from,".($limit+1);
  83. //query which allows me to get a record without taking into account the page
  84. $query_rows= "SELECT count(*) as total_rows
  85. FROM $tbl_session, $tbl_user
  86. $where
  87. $and
  88. ORDER BY $sort";
  89. //filtering the session list by access_url
  90. if ($_configuration['multiple_access_urls']==true){
  91. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  92. $access_url_id = api_get_current_access_url_id();
  93. if ($access_url_id != -1) {
  94. $and.= " AND access_url_id = $access_url_id AND $table_access_url_rel_session.session_id = $tbl_session.id";
  95. $query= "SELECT id,name,nbr_courses,date_start,date_end, firstname, lastname
  96. FROM $tbl_session, $tbl_user, $table_access_url_rel_session
  97. $where
  98. $and
  99. ORDER BY $sort
  100. LIMIT $from,".($limit+1);
  101. $query_rows= "SELECT count(*) as total_rows
  102. FROM $tbl_session, $tbl_user,$table_access_url_rel_session
  103. $where
  104. $and
  105. ORDER BY $sort";
  106. }
  107. }
  108. $result_rows = api_sql_query($query_rows,__FILE__,__LINE__);
  109. $recorset = Database::fetch_array($result_rows);
  110. $num = $recorset['total_rows'];
  111. $result=api_sql_query($query,__FILE__,__LINE__);
  112. $Sessions=api_store_result($result);
  113. $nbr_results=sizeof($Sessions);
  114. $tool_name = get_lang('SessionList');
  115. Display::display_header($tool_name);
  116. //api_display_tool_title($tool_name);
  117. if (!empty($_GET['warn'])) {
  118. Display::display_warning_message(urldecode($_GET['warn']),false);
  119. }
  120. if(isset($_GET['action'])) {
  121. Display::display_normal_message(stripslashes($_GET['message']),false);
  122. }
  123. ?>
  124. <div class="actions">
  125. <?php
  126. echo '<div style="float:right;">
  127. <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>
  128. </div>';
  129. ?>
  130. <form method="POST" action="session_list.php">
  131. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  132. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  133. <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a>
  134. </form>
  135. <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;">
  136. </div><br />
  137. <div align="left">
  138. <?php
  139. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  140. echo get_lang('NoSearchResults');
  141. echo ' </div>';
  142. } else {
  143. if($num>$limit){
  144. if($page) {
  145. ?>
  146. <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>
  147. <?php
  148. } else {
  149. echo get_lang('Previous');
  150. }
  151. ?>
  152. |
  153. <?php
  154. if($nbr_results > $limit) {
  155. ?>
  156. <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>
  157. <?php
  158. } else {
  159. echo get_lang('Next');
  160. }
  161. }
  162. ?>
  163. </div>
  164. <br />
  165. <table class="data_table" width="100%">
  166. <tr>
  167. <th>&nbsp;</th>
  168. <th><a href="<?php echo api_get_self(); ?>?sort=name"><?php echo get_lang('NameOfTheSession'); ?></a></th>
  169. <th><a href="<?php echo api_get_self(); ?>?sort=nbr_courses"><?php echo get_lang('NumberOfCourses'); ?></a></th>
  170. <th><a href="<?php echo api_get_self(); ?>?sort=date_start"><?php echo get_lang('StartDate'); ?></a></th>
  171. <th><a href="<?php echo api_get_self(); ?>?sort=date_end"><?php echo get_lang('EndDate'); ?></a></th>
  172. <th><a href="<?php echo api_get_self(); ?>?sort=coach_name"><?php echo get_lang('Coach'); ?></a></th>
  173. <th><?php echo get_lang('Actions'); ?></th>
  174. </tr>
  175. <?php
  176. $i=0;
  177. $x=0;
  178. foreach ($Sessions as $key=>$enreg) {
  179. if($key == $limit) {
  180. break;
  181. }
  182. $sql = 'SELECT COUNT(course_code) FROM '.$tbl_session_rel_course.' WHERE id_session='.intval($enreg['id']);
  183. $rs = api_sql_query($sql, __FILE__, __LINE__);
  184. list($nb_courses) = Database::fetch_array($rs);
  185. ?>
  186. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  187. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  188. <td><a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></a></td>
  189. <td><a href="session_course_list.php?id_session=<?php echo $enreg['id']; ?>"><?php echo $nb_courses; ?> cours</a></td>
  190. <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  191. <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  192. <td><?php echo api_htmlentities(api_get_person_name($enreg['firstname'], $enreg['lastname']),ENT_QUOTES,$charset); ?></td>
  193. <td>
  194. <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>
  195. <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>
  196. <a href="session_edit.php?page=session_list.php&id=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a>
  197. <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>
  198. </td>
  199. </tr>
  200. <?php
  201. $i=$i ? 0 : 1;
  202. $x++;
  203. }
  204. unset($Sessions);
  205. ?>
  206. </table>
  207. <br />
  208. <div align="left">
  209. <?php
  210. if($num>$limit) {
  211. if($page)
  212. {
  213. ?>
  214. <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>
  215. <?php
  216. }
  217. else
  218. {
  219. echo get_lang('Previous');
  220. }
  221. ?>
  222. |
  223. <?php
  224. if($nbr_results > $limit)
  225. {
  226. ?>
  227. <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>
  228. <?php
  229. }
  230. else
  231. {
  232. echo get_lang('Next');
  233. }
  234. }
  235. ?>
  236. </div>
  237. <br />
  238. <a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  239. <a href="javascript: void(0);" onclick="javascript: selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  240. <select name="action">
  241. <option value="delete"><?php echo get_lang('DeleteSelectedSessions'); ?></option>
  242. </select>
  243. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  244. <?php } ?>
  245. </table>
  246. <?php
  247. }
  248. Display::display_footer();
  249. ?>