session_category_list.php 12 KB

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