session_category_list.php 12 KB

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