session_category_list.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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']) ? (int) $_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'])
  27. ? Security::remove_XSS($_GET['sort'])
  28. : 'name';
  29. $idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null;
  30. $order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) : 'ASC';
  31. $keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : null;
  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. Display::addFlash(Display::return_message(get_lang('SessionCategoryDelete')));
  36. header('Location: '.api_get_self().'?sort='.$sort);
  37. exit();
  38. }
  39. $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
  40. if (isset($_GET['search']) && $_GET['search'] === 'advanced') {
  41. $interbreadcrumb[] = ['url' => 'session_category_list.php', 'name' => get_lang('ListSessionCategory')];
  42. $tool_name = get_lang('SearchASession');
  43. Display::display_header($tool_name);
  44. $form = new FormValidator('advanced_search', 'get');
  45. $form->addElement('header', '', $tool_name);
  46. $active_group = [];
  47. $active_group[] = $form->createElement('checkbox', 'active', '', get_lang('Active'));
  48. $active_group[] = $form->createElement('checkbox', 'inactive', '', get_lang('Inactive'));
  49. $form->addGroup($active_group, '', get_lang('ActiveSession'), null, false);
  50. $form->addButtonSearch(get_lang('SearchUsers'));
  51. $defaults['active'] = 1;
  52. $defaults['inactive'] = 1;
  53. $form->setDefaults($defaults);
  54. $form->display();
  55. } else {
  56. $limit = 20;
  57. $from = $page * $limit;
  58. //if user is crfp admin only list its sessions
  59. $where = null;
  60. if (!api_is_platform_admin()) {
  61. $where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($keyword))."%'";
  62. } else {
  63. $where .= empty($keyword) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($keyword))."%'";
  64. }
  65. if (empty($where)) {
  66. $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
  67. } else {
  68. $where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
  69. }
  70. $table_access_url_rel_session = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  71. $query = "SELECT sc.*, (
  72. SELECT count(s.id) FROM $tbl_session s
  73. INNER JOIN $table_access_url_rel_session us
  74. ON (s.id = us.session_id)
  75. WHERE
  76. s.session_category_id = sc.id AND
  77. access_url_id = ".api_get_current_access_url_id()."
  78. ) as nbr_session
  79. FROM $tbl_session_category sc
  80. $where
  81. ORDER BY $sort $order
  82. LIMIT $from,".($limit + 1);
  83. $query_rows = "SELECT count(*) as total_rows
  84. FROM $tbl_session_category sc $where ";
  85. $order = ($order == 'ASC') ? 'DESC' : 'ASC';
  86. $result_rows = Database::query($query_rows);
  87. $recorset = Database::fetch_array($result_rows);
  88. $num = $recorset['total_rows'];
  89. $result = Database::query($query);
  90. $Sessions = Database::store_result($result);
  91. $nbr_results = sizeof($Sessions);
  92. $tool_name = get_lang('ListSessionCategory');
  93. Display::display_header($tool_name); ?>
  94. <div class="actions">
  95. <div class="row">
  96. <div class="col-md-6">
  97. <?php
  98. echo Display::url(
  99. Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), [], ICON_SIZE_MEDIUM),
  100. api_get_path(WEB_CODE_PATH).'session/session_category_add.php'
  101. );
  102. echo Display::url(
  103. Display::return_icon('session.png', get_lang('ListSession'), [], ICON_SIZE_MEDIUM),
  104. api_get_path(WEB_CODE_PATH).'session/session_list.php'
  105. ); ?>
  106. </div>
  107. <div class="col-md-6">
  108. <div class="pull-right">
  109. <form method="POST" action="session_category_list.php" class="form-inline">
  110. <div class="form-group">
  111. <input class="form-control" type="text" name="keyword" value="<?php echo $keyword; ?>"
  112. aria-label="<?php echo get_lang('Search'); ?>"/>
  113. <button class="btn btn-default" type="submit" name="name"
  114. value="<?php echo get_lang('Search'); ?>"><em
  115. class="fa fa-search"></em> <?php echo get_lang('Search'); ?></button>
  116. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  117. </div>
  118. </form>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>"
  124. onsubmit="if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
  125. <?php
  126. if (count($Sessions) == 0 && isset($_POST['keyword'])) {
  127. echo Display::return_message(get_lang('NoSearchResults'), 'warning');
  128. } else {
  129. if ($num > $limit) {
  130. ?>
  131. <div>
  132. <?php
  133. if ($page) {
  134. ?>
  135. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
  136. - 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
  137. $order
  138. ); ?>&keyword=<?php echo $keyword; ?><?php echo @$cond_url; ?>"><?php echo get_lang(
  139. 'Previous'
  140. ); ?></a>
  141. <?php
  142. } else {
  143. echo get_lang('Previous');
  144. } ?>
  145. |
  146. <?php
  147. if ($nbr_results > $limit) {
  148. ?>
  149. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
  150. + 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
  151. $order
  152. ); ?>&keyword=<?php echo $keyword; ?><?php echo @$cond_url; ?>"><?php echo get_lang(
  153. 'Next'
  154. ); ?></a>
  155. <?php
  156. } else {
  157. echo get_lang('Next');
  158. } ?>
  159. </div>
  160. <?php
  161. } ?>
  162. <table class="data_table" width="100%">
  163. <tr>
  164. <th>&nbsp;</th>
  165. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order
  166. : 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  167. <th><a href="<?php echo api_get_self(); ?>?sort=nbr_session&order=<?php echo ($sort
  168. == 'nbr_session') ? $order : 'ASC'; ?>"><?php echo get_lang('NumberOfSession'); ?></a></th>
  169. <th><a href="<?php echo api_get_self(); ?>?sort=date_start&order=<?php echo ($sort == 'date_start')
  170. ? $order : 'ASC'; ?>"><?php echo get_lang('StartDate'); ?></a></th>
  171. <th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort == 'date_end')
  172. ? $order : 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th>
  173. <th><?php echo get_lang('Actions'); ?></th>
  174. </tr>
  175. <?php
  176. $i = 0;
  177. $x = 0;
  178. foreach ($Sessions as $key => $enreg) {
  179. if ($key == $limit) {
  180. break;
  181. }
  182. $sql = 'SELECT COUNT(session_category_id)
  183. FROM '.$tbl_session.' s
  184. INNER JOIN '.$table_access_url_rel_session.' us
  185. ON (s.id = us.session_id)
  186. WHERE
  187. s.session_category_id = '.intval($enreg['id']).' AND
  188. us.access_url_id = '.api_get_current_access_url_id();
  189. $rs = Database::query($sql);
  190. list($nb_courses) = Database::fetch_array($rs); ?>
  191. <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
  192. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]"
  193. value="<?php echo $enreg['id']; ?>"></td>
  194. <td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
  195. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses
  196. ." Session(s) </a>"; ?></td>
  197. <td><?php echo api_format_date($enreg['date_start'], DATE_FORMAT_SHORT); ?></td>
  198. <td>
  199. <?php
  200. if (!empty($enreg['date_end']) && $enreg['date_end'] != '0000-00-00') {
  201. echo api_format_date($enreg['date_end'], DATE_FORMAT_SHORT);
  202. } else {
  203. echo '-';
  204. } ?>
  205. </td>
  206. <td>
  207. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  208. <?php Display::display_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL); ?>
  209. </a>
  210. <a href="<?php echo api_get_self(
  211. ); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&idChecked=<?php echo $enreg['id']; ?>"
  212. onclick="if(!confirm('<?php echo get_lang(
  213. 'ConfirmYourChoice'
  214. ); ?>')) return false;">
  215. <?php Display::display_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL); ?>
  216. </a>
  217. </td>
  218. </tr>
  219. <?php
  220. $i = $i ? 0 : 1;
  221. $x++;
  222. }
  223. unset($Sessions); ?>
  224. </table>
  225. <br/>
  226. <div>
  227. <?php
  228. if ($num > $limit) {
  229. if ($page) {
  230. ?>
  231. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
  232. - 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
  233. $_REQUEST['order']
  234. ); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
  235. <?php echo get_lang('Previous'); ?></a>
  236. <?php
  237. } else {
  238. echo get_lang('Previous');
  239. } ?>
  240. |
  241. <?php
  242. if ($nbr_results > $limit) {
  243. ?>
  244. <a href="<?php echo api_get_self(); ?>?page=<?php echo $page
  245. + 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS(
  246. $_REQUEST['order']
  247. ); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>">
  248. <?php echo get_lang('Next'); ?></a>
  249. <?php
  250. } else {
  251. echo get_lang('Next');
  252. }
  253. } ?>
  254. </div>
  255. <div class="row">
  256. <div class="col-sm-4">
  257. <div class="btn-group">
  258. <button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');">
  259. <?php echo get_lang('SelectAll'); ?>
  260. </button>
  261. <button type="button" class="btn btn-default" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');">
  262. <?php echo get_lang('UnSelectAll'); ?>
  263. </button>
  264. </div>
  265. </div>
  266. <div class="col-sm-6">
  267. <select class="selectpicker form-control" name="action">
  268. <option value="delete_off_session" selected="selected">
  269. <?php echo get_lang('DeleteSelectedSessionCategory'); ?>
  270. </option>
  271. <option value="delete_on_session">
  272. <?php echo get_lang('DeleteSelectedFullSessionCategory'); ?>
  273. </option>
  274. </select>
  275. </div>
  276. <div class="col-sm-2">
  277. <button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok'); ?>">
  278. <?php echo get_lang('Ok'); ?>
  279. </button>
  280. </div>
  281. </div>
  282. <?php
  283. } ?>
  284. </table>
  285. </form>
  286. <?php
  287. }
  288. Display::display_footer();