session_list.php 11 KB

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