session_category_list.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file='admin';
  4. $cidReset=true;
  5. require_once '../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. // setting the section (for the tabs)
  10. $this_section=SECTION_PLATFORM_ADMIN;
  11. $htmlHeadXtra[] = '<script language="javascript">
  12. function selectAll(idCheck,numRows,action) {
  13. for(i=0;i<numRows;i++) {
  14. idcheck = document.getElementById(idCheck+"_"+i);
  15. if (action == "true"){
  16. idcheck.checked = true;
  17. } else {
  18. idcheck.checked = false;
  19. }
  20. }
  21. }
  22. </script>';
  23. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  24. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  25. $page=intval($_GET['page']);
  26. $action= Security::remove_XSS($_REQUEST['action']);
  27. $sort=in_array($_GET['sort'],array('name','nbr_session','date_start','date_end'))? Security::remove_XSS($_GET['sort']) : 'name';
  28. $idChecked = Security::remove_XSS($_REQUEST['idChecked']);
  29. $order = (isset($_REQUEST['order']))? Security::remove_XSS($_REQUEST['order']): 'ASC';
  30. if ($action == 'delete_on_session' || $action == 'delete_off_session') {
  31. $delete_session = ($action == 'delete_on_session')? true: false;
  32. SessionManager::delete_session_category($idChecked, $delete_session);
  33. header('Location: '.api_get_self().'?sort='.$sort.'&action=show_message&message='.urlencode(get_lang('SessionCategoryDelete')));
  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_category_list.php', "name" => get_lang('ListSessionCategory'));
  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('SearchUsers'),'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 .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  58. }
  59. else {
  60. $where .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  61. }
  62. $query = "SELECT sc.*, (select count(id) FROM $tbl_session WHERE session_category_id = sc.id) as nbr_session
  63. FROM $tbl_session_category sc
  64. $where
  65. ORDER BY $sort $order
  66. LIMIT $from,".($limit+1);
  67. $query_rows = "SELECT count(*) as total_rows
  68. FROM $tbl_session_category sc $where ";
  69. $order = ($order == 'ASC')? 'DESC': 'ASC';
  70. $result_rows = Database::query($query_rows);
  71. $recorset = Database::fetch_array($result_rows);
  72. $num = $recorset['total_rows'];
  73. $result = Database::query($query);
  74. $Sessions = Database::store_result($result);
  75. $nbr_results = sizeof($Sessions);
  76. $tool_name = get_lang('ListSessionCategory');
  77. Display::display_header($tool_name);
  78. api_display_tool_title($tool_name);
  79. if (!empty($_GET['warn'])) {
  80. Display::display_warning_message(urldecode($_GET['warn']),false);
  81. }
  82. if(isset($_GET['action'])) {
  83. Display::display_confirmation_message(stripslashes($_GET['message']),false);
  84. }
  85. ?>
  86. <div class="actions">
  87. <?php
  88. echo '<div style="float:right;">
  89. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('folder_new.gif',get_lang('AddSessionCategory')).get_lang('AddSessionCategory').'</a>
  90. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('blackboard_blue.png',get_lang('ListSession'),array('width'=>'24px')).get_lang('ListSession').'</a>
  91. </div>';
  92. ?>
  93. <form method="POST" action="session_category_list.php">
  94. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  95. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  96. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  97. </form>
  98. <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;">
  99. </div><br />
  100. <div align="left">
  101. <?php
  102. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  103. echo get_lang('NoSearchResults');
  104. echo '</div>';
  105. } else {
  106. if ($num > $limit) {
  107. if ($page) {
  108. ?>
  109. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
  110. <?php
  111. } else {
  112. echo get_lang('Previous');
  113. }
  114. ?>
  115. |
  116. <?php
  117. if($nbr_results > $limit) {
  118. ?>
  119. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
  120. <?php
  121. } else {
  122. echo get_lang('Next');
  123. }
  124. }
  125. ?>
  126. </div>
  127. <br />
  128. <table class="data_table" width="100%">
  129. <tr>
  130. <th>&nbsp;</th>
  131. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort=='name')? $order: 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  132. <th><a href="<?php echo api_get_self(); ?>?sort=nbr_session&order=<?php echo ($sort=='nbr_session')? $order: 'ASC'; ?>"><?php echo get_lang('NumberOfSession'); ?></a></th>
  133. <th><a href="<?php echo api_get_self(); ?>?sort=date_start&order=<?php echo ($sort=='date_start')? $order: 'ASC'; ?>"><?php echo get_lang('StartDate'); ?></a></th>
  134. <th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort=='date_end')? $order: 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th>
  135. <th><?php echo get_lang('Actions'); ?></th>
  136. </tr>
  137. <?php
  138. $i=0;
  139. $x=0;
  140. foreach ($Sessions as $key=>$enreg) {
  141. if($key == $limit) {
  142. break;
  143. }
  144. $sql = 'SELECT COUNT(session_category_id) FROM '.$tbl_session.' WHERE session_category_id = '.intval($enreg['id']);
  145. $rs = Database::query($sql);
  146. list($nb_courses) = Database::fetch_array($rs);
  147. ?>
  148. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  149. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  150. <td><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></td>
  151. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
  152. <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  153. <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  154. <td>
  155. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a>
  156. <a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&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>
  157. </td>
  158. </tr>
  159. <?php
  160. $i=$i ? 0 : 1;
  161. $x++;
  162. }
  163. unset($Sessions);
  164. ?>
  165. </table>
  166. <br />
  167. <div align="left">
  168. <?php
  169. if ($num > $limit) {
  170. if ($page)
  171. {
  172. ?>
  173. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
  174. <?php
  175. }
  176. else
  177. {
  178. echo get_lang('Previous');
  179. }
  180. ?>
  181. |
  182. <?php
  183. if($nbr_results > $limit)
  184. {
  185. ?>
  186. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
  187. <?php
  188. }
  189. else
  190. {
  191. echo get_lang('Next');
  192. }
  193. } ?>
  194. </div>
  195. <br />
  196. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  197. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  198. <select name="action">
  199. <option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option>
  200. <option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option>
  201. </select>
  202. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  203. <?php } ?>
  204. </table>
  205. <?php } Display::display_footer(); ?>