session_category_list.php 11 KB

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