session_category_list.php 12 KB

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