session_category_list.php 11 KB

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