session_category_list.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file='admin';
  4. $cidReset=true;
  5. require_once '../inc/global.inc.php';
  6. api_protect_admin_script(true);
  7. // setting the section (for the tabs)
  8. $this_section = SECTION_PLATFORM_ADMIN;
  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. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  22. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  23. $page=intval($_GET['page']);
  24. $action= Security::remove_XSS($_REQUEST['action']);
  25. $sort=in_array($_GET['sort'],array('name','nbr_session','date_start','date_end'))? Security::remove_XSS($_GET['sort']) : 'name';
  26. $idChecked = Security::remove_XSS($_REQUEST['idChecked']);
  27. $order = (isset($_REQUEST['order']))? Security::remove_XSS($_REQUEST['order']): 'ASC';
  28. if ($action == 'delete_on_session' || $action == 'delete_off_session') {
  29. $delete_session = ($action == 'delete_on_session')? true: false;
  30. SessionManager::delete_session_category($idChecked, $delete_session);
  31. header('Location: '.api_get_self().'?sort='.$sort.'&action=show_message&message='.urlencode(get_lang('SessionCategoryDelete')));
  32. exit();
  33. }
  34. $interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin'));
  35. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  36. $interbreadcrumb[] = array ("url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory'));
  37. $tool_name = get_lang('SearchASession');
  38. Display :: display_header($tool_name);
  39. $form = new FormValidator('advanced_search','get');
  40. $form->addElement('header', '', $tool_name);
  41. $active_group = array();
  42. $active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
  43. $active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
  44. $form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
  45. $form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
  46. $defaults['active'] = 1;
  47. $defaults['inactive'] = 1;
  48. $form->setDefaults($defaults);
  49. $form->display();
  50. } else {
  51. $limit = 20;
  52. $from = $page * $limit;
  53. //if user is crfp admin only list its sessions
  54. if(!api_is_platform_admin()) {
  55. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  56. } else {
  57. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  58. }
  59. if (empty($where)) {
  60. $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
  61. } else {
  62. $where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
  63. }
  64. $query = "SELECT sc.*, (select count(id) FROM $tbl_session WHERE session_category_id = sc.id) as nbr_session
  65. FROM $tbl_session_category sc
  66. $where
  67. ORDER BY $sort $order
  68. LIMIT $from,".($limit+1);
  69. $query_rows = "SELECT count(*) as total_rows FROM $tbl_session_category sc $where ";
  70. $order = ($order == 'ASC')? 'DESC': 'ASC';
  71. $result_rows = Database::query($query_rows);
  72. $recorset = Database::fetch_array($result_rows);
  73. $num = $recorset['total_rows'];
  74. $result = Database::query($query);
  75. $Sessions = Database::store_result($result);
  76. $nbr_results = sizeof($Sessions);
  77. $tool_name = get_lang('ListSessionCategory');
  78. Display::display_header($tool_name);
  79. //api_display_tool_title($tool_name);
  80. if (!empty($_GET['warn'])) {
  81. Display::display_warning_message(urldecode($_GET['warn']),false);
  82. }
  83. if(isset($_GET['action'])) {
  84. Display::display_confirmation_message(stripslashes($_GET['message']),false);
  85. }
  86. ?>
  87. <div class="actions">
  88. <?php
  89. echo '<div style="float:right;">
  90. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('new_folder.png',get_lang('AddSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>
  91. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('session.png',get_lang('ListSession'),'',ICON_SIZE_MEDIUM).'</a>
  92. </div>';
  93. ?>
  94. <form method="POST" action="session_category_list.php">
  95. <input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
  96. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  97. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  98. </form>
  99. <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;">
  100. </div><br />
  101. <div align="left">
  102. <?php
  103. if(count($Sessions)==0 && isset($_POST['keyword'])) {
  104. echo get_lang('NoSearchResults');
  105. echo '</div>';
  106. } else {
  107. if ($num > $limit) {
  108. if ($page) {
  109. ?>
  110. <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>
  111. <?php
  112. } else {
  113. echo get_lang('Previous');
  114. }
  115. ?>
  116. |
  117. <?php
  118. if($nbr_results > $limit) {
  119. ?>
  120. <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>
  121. <?php
  122. } else {
  123. echo get_lang('Next');
  124. }
  125. }
  126. ?>
  127. </div>
  128. <br />
  129. <table class="data_table" width="100%">
  130. <tr>
  131. <th>&nbsp;</th>
  132. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort=='name')? $order: 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  133. <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>
  134. <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>
  135. <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>
  136. <th><?php echo get_lang('Actions'); ?></th>
  137. </tr>
  138. <?php
  139. $i=0;
  140. $x=0;
  141. foreach ($Sessions as $key=>$enreg) {
  142. if($key == $limit) {
  143. break;
  144. }
  145. $sql = 'SELECT COUNT(session_category_id) FROM '.$tbl_session.' WHERE session_category_id = '.intval($enreg['id']);
  146. $rs = Database::query($sql);
  147. list($nb_courses) = Database::fetch_array($rs);
  148. ?>
  149. <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
  150. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  151. <td><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></td>
  152. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
  153. <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
  154. <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
  155. <td>
  156. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  157. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  158. </a>
  159. <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;">
  160. <?php Display::display_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); ?>
  161. </a>
  162. </td>
  163. </tr>
  164. <?php
  165. $i=$i ? 0 : 1;
  166. $x++;
  167. }
  168. unset($Sessions);
  169. ?>
  170. </table>
  171. <br />
  172. <div align="left">
  173. <?php
  174. if ($num > $limit) {
  175. if ($page)
  176. {
  177. ?>
  178. <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>
  179. <?php
  180. }
  181. else
  182. {
  183. echo get_lang('Previous');
  184. }
  185. ?>
  186. |
  187. <?php
  188. if($nbr_results > $limit)
  189. {
  190. ?>
  191. <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>
  192. <?php
  193. }
  194. else
  195. {
  196. echo get_lang('Next');
  197. }
  198. } ?>
  199. </div>
  200. <br />
  201. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  202. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  203. <select name="action">
  204. <option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option>
  205. <option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option>
  206. </select>
  207. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  208. <?php } ?>
  209. </table>
  210. <?php } Display::display_footer(); ?>