session_category_list.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. } else {
  59. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  60. }
  61. if (empty($where)) {
  62. $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
  63. } else {
  64. $where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
  65. }
  66. $query = "SELECT sc.*, (select count(id) FROM $tbl_session WHERE session_category_id = sc.id) as nbr_session
  67. FROM $tbl_session_category sc
  68. $where
  69. ORDER BY $sort $order
  70. LIMIT $from,".($limit+1);
  71. $query_rows = "SELECT count(*) as total_rows FROM $tbl_session_category sc $where ";
  72. $order = ($order == 'ASC')? 'DESC': 'ASC';
  73. $result_rows = Database::query($query_rows);
  74. $recorset = Database::fetch_array($result_rows);
  75. $num = $recorset['total_rows'];
  76. $result = Database::query($query);
  77. $Sessions = Database::store_result($result);
  78. $nbr_results = sizeof($Sessions);
  79. $tool_name = get_lang('ListSessionCategory');
  80. Display::display_header($tool_name);
  81. //api_display_tool_title($tool_name);
  82. if (!empty($_GET['warn'])) {
  83. Display::display_warning_message(urldecode($_GET['warn']),false);
  84. }
  85. if(isset($_GET['action'])) {
  86. Display::display_confirmation_message(stripslashes($_GET['message']),false);
  87. }
  88. ?>
  89. <div class="actions">
  90. <?php
  91. echo '<div style="float:right;">
  92. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('new_folder.png',get_lang('AddSessionCategory'),'','32').'</a>
  93. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('session.png',get_lang('ListSession'),'','32').'</a>
  94. </div>';
  95. ?>
  96. <form method="POST" action="session_category_list.php">
  97. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  98. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  99. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  100. </form>
  101. <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;">
  102. </div><br />
  103. <div align="left">
  104. <?php
  105. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  106. echo get_lang('NoSearchResults');
  107. echo '</div>';
  108. } else {
  109. if ($num > $limit) {
  110. if ($page) {
  111. ?>
  112. <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>
  113. <?php
  114. } else {
  115. echo get_lang('Previous');
  116. }
  117. ?>
  118. |
  119. <?php
  120. if($nbr_results > $limit) {
  121. ?>
  122. <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>
  123. <?php
  124. } else {
  125. echo get_lang('Next');
  126. }
  127. }
  128. ?>
  129. </div>
  130. <br />
  131. <table class="data_table" width="100%">
  132. <tr>
  133. <th>&nbsp;</th>
  134. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort=='name')? $order: 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  135. <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>
  136. <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>
  137. <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>
  138. <th><?php echo get_lang('Actions'); ?></th>
  139. </tr>
  140. <?php
  141. $i=0;
  142. $x=0;
  143. foreach ($Sessions as $key=>$enreg) {
  144. if($key == $limit) {
  145. break;
  146. }
  147. $sql = 'SELECT COUNT(session_category_id) FROM '.$tbl_session.' WHERE session_category_id = '.intval($enreg['id']);
  148. $rs = Database::query($sql);
  149. list($nb_courses) = Database::fetch_array($rs);
  150. ?>
  151. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  152. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  153. <td><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></td>
  154. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
  155. <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  156. <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  157. <td>
  158. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  159. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), 22); ?>
  160. </a>
  161. <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;">
  162. <?php Display::display_icon('delete.png', get_lang('Delete'), array(), 22); ?>
  163. </a>
  164. </td>
  165. </tr>
  166. <?php
  167. $i=$i ? 0 : 1;
  168. $x++;
  169. }
  170. unset($Sessions);
  171. ?>
  172. </table>
  173. <br />
  174. <div align="left">
  175. <?php
  176. if ($num > $limit) {
  177. if ($page)
  178. {
  179. ?>
  180. <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>
  181. <?php
  182. }
  183. else
  184. {
  185. echo get_lang('Previous');
  186. }
  187. ?>
  188. |
  189. <?php
  190. if($nbr_results > $limit)
  191. {
  192. ?>
  193. <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>
  194. <?php
  195. }
  196. else
  197. {
  198. echo get_lang('Next');
  199. }
  200. } ?>
  201. </div>
  202. <br />
  203. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  204. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  205. <select name="action">
  206. <option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option>
  207. <option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option>
  208. </select>
  209. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  210. <?php } ?>
  211. </table>
  212. <?php } Display::display_footer(); ?>