session_list.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. $language_file='admin';
  17. $cidReset=true;
  18. include('../inc/global.inc.php');
  19. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  20. require_once (api_get_path(LIBRARY_PATH).'sessionmanager.lib.php');
  21. api_protect_admin_script(true);
  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::DeleteSession($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. $active_group = array();
  43. $active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
  44. $active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
  45. $form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
  46. $form->addElement('submit','submit',get_lang('Ok'));
  47. $defaults['active'] = 1;
  48. $defaults['inactive'] = 1;
  49. $form->setDefaults($defaults);
  50. $form->display();
  51. } else {
  52. $limit=20;
  53. $from=$page * $limit;
  54. //if user is crfp admin only list its sessions
  55. if(!api_is_platform_admin()) {
  56. $where = 'WHERE session_admin_id='.intval($_user['user_id']);
  57. $where .= (empty($_REQUEST['keyword']) ? " " : " AND name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  58. }
  59. else {
  60. $where .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
  61. }
  62. if(trim($where) == ''){
  63. $and=" WHERE id_coach=user_id";
  64. } else {
  65. $and=" AND id_coach=user_id";
  66. }
  67. if (isset($_REQUEST['active']) && !isset($_REQUEST['inactive']) ){
  68. $and .= ' AND ( (session.date_start <= CURDATE() AND session.date_end >= CURDATE()) OR session.date_start="0000-00-00" ) ';
  69. }
  70. if (!isset($_REQUEST['active']) && isset($_REQUEST['inactive']) ){
  71. $and .= ' AND ( (session.date_start > CURDATE() OR session.date_end < CURDATE()) AND session.date_start<>"0000-00-00" ) ';
  72. }
  73. $query= "SELECT id,name,nbr_courses,date_start,date_end, firstname, lastname
  74. FROM $tbl_session, $tbl_user
  75. $where
  76. $and
  77. ORDER BY $sort
  78. LIMIT $from,".($limit+1);
  79. //filtering the session list by access_url
  80. if ($_configuration['multiple_access_urls']==true){
  81. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  82. $access_url_id = api_get_current_access_url_id();
  83. if ($access_url_id != -1) {
  84. $and.= " AND access_url_id = $access_url_id AND $table_access_url_rel_session.session_id = $tbl_session.id";
  85. $query= "SELECT id,name,nbr_courses,date_start,date_end, firstname, lastname
  86. FROM $tbl_session, $tbl_user, $table_access_url_rel_session
  87. $where
  88. $and
  89. ORDER BY $sort
  90. LIMIT $from,".($limit+1);
  91. }
  92. }
  93. $result=api_sql_query($query,__FILE__,__LINE__);
  94. $Sessions=api_store_result($result);
  95. $nbr_results=sizeof($Sessions);
  96. $tool_name = get_lang('SessionList');
  97. Display::display_header($tool_name);
  98. api_display_tool_title($tool_name);
  99. if (!empty($_GET['warn'])) {
  100. Display::display_warning_message(urldecode($_GET['warn']));
  101. }
  102. if(isset($_GET['action'])) {
  103. Display::display_normal_message($_GET['message']);
  104. }
  105. ?>
  106. <div id="main">
  107. <div class="actions">
  108. <?php
  109. echo '<div style="float:right;">
  110. <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>
  111. </div>';
  112. ?>
  113. <form method="POST" action="session_list.php">
  114. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  115. <input type="submit" value="<?php echo get_lang('Search'); ?>"/>
  116. <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a>
  117. </form>
  118. <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;">
  119. <div align="left">
  120. <?php
  121. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  122. echo get_lang('NoSearchResults');
  123. } else {
  124. if($page) {
  125. ?>
  126. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?>"><?php echo get_lang('Previous'); ?></a>
  127. <?php
  128. } else {
  129. echo get_lang('Previous');
  130. }
  131. ?>
  132. |
  133. <?php
  134. if($nbr_results > $limit) {
  135. ?>
  136. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?>"><?php echo get_lang('Next'); ?></a>
  137. <?php
  138. } else {
  139. echo get_lang('Next');
  140. }
  141. ?>
  142. </div>
  143. </div>
  144. <br>
  145. <table class="data_table" width="100%">
  146. <tr>
  147. <th>&nbsp;</th>
  148. <th><a href="<?php echo api_get_self(); ?>?sort=name"><?php echo get_lang('NameOfTheSession'); ?></a></th>
  149. <th><a href="<?php echo api_get_self(); ?>?sort=nbr_courses"><?php echo get_lang('NumberOfCourses'); ?></a></th>
  150. <th><a href="<?php echo api_get_self(); ?>?sort=date_start"><?php echo get_lang('StartDate'); ?></a></th>
  151. <th><a href="<?php echo api_get_self(); ?>?sort=date_end"><?php echo get_lang('EndDate'); ?></a></th>
  152. <th><a href="<?php echo api_get_self(); ?>?sort=coach_name"><?php echo get_lang('Coach'); ?></a></th>
  153. <th><?php echo get_lang('Actions'); ?></th>
  154. </tr>
  155. <?php
  156. $i=0;
  157. foreach ($Sessions as $key=>$enreg) {
  158. if($key == $limit) {
  159. break;
  160. }
  161. $sql = 'SELECT COUNT(course_code) FROM '.$tbl_session_rel_course.' WHERE id_session='.intval($enreg['id']);
  162. $rs = api_sql_query($sql, __FILE__, __LINE__);
  163. list($nb_courses) = Database::fetch_array($rs);
  164. ?>
  165. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  166. <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  167. <td><a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php echo htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></a></td>
  168. <td><a href="session_course_list.php?id_session=<?php echo $enreg['id']; ?>"><?php echo $nb_courses; ?> cours</a></td>
  169. <td><?php echo htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  170. <td><?php echo htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  171. <td><?php echo htmlentities($enreg['firstname'],ENT_QUOTES,$charset).' '.htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
  172. <td>
  173. <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>
  174. <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>
  175. <a href="session_edit.php?page=session_list.php&id=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a>
  176. <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>
  177. </td>
  178. </tr>
  179. <?php
  180. $i=$i ? 0 : 1;
  181. }
  182. unset($Sessions);
  183. ?>
  184. </table>
  185. <br>
  186. <div align="left">
  187. <?php
  188. if($page)
  189. {
  190. ?>
  191. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?>"><?php echo get_lang('Previous'); ?></a>
  192. <?php
  193. }
  194. else
  195. {
  196. echo get_lang('Previous');
  197. }
  198. ?>
  199. |
  200. <?php
  201. if($nbr_results > $limit)
  202. {
  203. ?>
  204. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&keyword=<?php echo $_REQUEST['keyword']; ?>"><?php echo get_lang('Next'); ?></a>
  205. <?php
  206. }
  207. else
  208. {
  209. echo get_lang('Next');
  210. }
  211. ?>
  212. </div>
  213. <br>
  214. <select name="action">
  215. <option value="delete"><?php echo get_lang('DeleteSelectedSessions'); ?></option>
  216. </select>
  217. <input type="submit" value="<?php echo get_lang('Ok'); ?>">
  218. <?php } ?>
  219. </table>
  220. </div>
  221. <?php
  222. }
  223. Display::display_footer();
  224. ?>