session_category_list.php 12 KB

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