session_category_list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * List sessions categories
  5. * @package chamilo.admin
  6. */
  7. /**
  8. * Code
  9. */
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. api_protect_admin_script(true);
  13. api_protect_limit_for_session_admin();
  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. idcheck.checked = action == "true";
  21. }
  22. }
  23. </script>';
  24. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  25. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  26. $page = isset($_GET['page']) ? intval($_GET['page']) : null;
  27. $action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : null;
  28. $sort = isset($_GET['sort']) && in_array($_GET['sort'], array('name', 'nbr_session', 'date_start', 'date_end')) ? Security::remove_XSS($_GET['sort']) : 'name';
  29. $idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null;
  30. $order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) : 'ASC';
  31. if ($action == 'delete_on_session' || $action == 'delete_off_session') {
  32. $delete_session = ($action == 'delete_on_session') ? true : false;
  33. SessionManager::delete_session_category($idChecked, $delete_session);
  34. Display::addFlash(Display::return_message(get_lang('SessionCategoryDelete')));
  35. header('Location: '.api_get_self().'?sort='.$sort);
  36. exit();
  37. }
  38. //$interbreadcrumb[] = array("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  39. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  40. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  41. $interbreadcrumb[] = array("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 = array();
  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'), '<br/>', 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($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  62. } else {
  63. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['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(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 FROM $tbl_session_category sc $where ";
  84. $order = ($order == 'ASC') ? 'DESC' : 'ASC';
  85. $result_rows = Database::query($query_rows);
  86. $recorset = Database::fetch_array($result_rows);
  87. $num = $recorset['total_rows'];
  88. $result = Database::query($query);
  89. $Sessions = Database::store_result($result);
  90. $nbr_results = sizeof($Sessions);
  91. $tool_name = get_lang('ListSessionCategory');
  92. Display::display_header($tool_name);
  93. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  94. ?>
  95. <div class="actions">
  96. <div class="row">
  97. <div class="col-md-6">
  98. <?php
  99. 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>
  100. <a href="'.api_get_path(WEB_CODE_PATH).'session/session_list.php">'.Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>';
  101. ?>
  102. </div>
  103. <div class="col-md-6">
  104. <div class="pull-right">
  105. <form method="POST" action="session_category_list.php" class="form-inline">
  106. <div class="form-group">
  107. <input class="form-control" type="text" name="keyword" value="<?php echo $keyword; ?>"/>
  108. <button class="btn btn-default" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><i class="fa fa-search"></i> <?php echo get_lang('Search') ?></button>
  109. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  110. </div>
  111. </form>
  112. </div>
  113. </div>
  114. </div>
  115. <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;">
  116. </div>
  117. <div align="left">
  118. <?php
  119. if (count($Sessions) == 0 && isset($_POST['keyword'])) {
  120. echo get_lang('NoSearchResults');
  121. echo '</div>';
  122. } else {
  123. if ($num > $limit) {
  124. if ($page) {
  125. ?>
  126. <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>
  127. <?php
  128. } else {
  129. echo get_lang('Previous');
  130. }
  131. ?>
  132. |
  133. <?php
  134. if ($nbr_results > $limit) {
  135. ?>
  136. <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>
  137. <?php
  138. } else {
  139. echo get_lang('Next');
  140. }
  141. }
  142. ?>
  143. </div>
  144. <table class="data_table" width="100%">
  145. <tr>
  146. <th>&nbsp;</th>
  147. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order : 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  148. <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>
  149. <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>
  150. <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>
  151. <th><?php echo get_lang('Actions'); ?></th>
  152. </tr>
  153. <?php
  154. $i = 0;
  155. $x = 0;
  156. foreach ($Sessions as $key => $enreg) {
  157. if ($key == $limit) {
  158. break;
  159. }
  160. $sql = 'SELECT COUNT(session_category_id)
  161. FROM '.$tbl_session.' s INNER JOIN '.$table_access_url_rel_session.' us ON (s.id = us.session_id)
  162. WHERE s.session_category_id = '.intval($enreg['id']).' AND us.access_url_id = '.api_get_current_access_url_id();
  163. $rs = Database::query($sql);
  164. list($nb_courses) = Database::fetch_array($rs);
  165. ?>
  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><?php echo api_format_date($enreg['date_end'], DATE_FORMAT_SHORT); ?></td>
  172. <td>
  173. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  174. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  175. </a>
  176. <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;">
  177. <?php Display::display_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); ?>
  178. </a>
  179. </td>
  180. </tr>
  181. <?php
  182. $i = $i ? 0 : 1;
  183. $x++;
  184. }
  185. unset($Sessions);
  186. ?>
  187. </table>
  188. <br />
  189. <div align="left">
  190. <?php
  191. if ($num > $limit) {
  192. if ($page) {
  193. ?>
  194. <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>
  195. <?php
  196. } else {
  197. echo get_lang('Previous');
  198. }
  199. ?>
  200. |
  201. <?php
  202. if ($nbr_results > $limit) {
  203. ?>
  204. <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>
  205. <?php
  206. } else {
  207. echo get_lang('Next');
  208. }
  209. }
  210. ?>
  211. </div>
  212. <div class="btn-group">
  213. <a class="btn btn-default" href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>
  214. <a class="btn btn-default" href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  215. </div>
  216. <div class="list-category">
  217. <select class="chzn-select" name="action">
  218. <option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option>
  219. <option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option>
  220. </select>
  221. </div>
  222. <button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  223. <?php } ?>
  224. </table>
  225. <?php }
  226. Display::display_footer();