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. /**
  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. header('Location: '.api_get_self().'?sort='.$sort.'&action=show_message&message='.urlencode(get_lang('SessionCategoryDelete')));
  38. exit();
  39. }
  40. $interbreadcrumb[] = array("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  41. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  42. $interbreadcrumb[] = array("url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory'));
  43. $tool_name = get_lang('SearchASession');
  44. Display :: display_header($tool_name);
  45. $form = new FormValidator('advanced_search', 'get');
  46. $form->addElement('header', '', $tool_name);
  47. $active_group = array();
  48. $active_group[] = $form->createElement('checkbox', 'active', '', get_lang('Active'));
  49. $active_group[] = $form->createElement('checkbox', 'inactive', '', get_lang('Inactive'));
  50. $form->addGroup($active_group, '', get_lang('ActiveSession'), '<br/>', false);
  51. $form->addButtonSearch(get_lang('SearchUsers'));
  52. $defaults['active'] = 1;
  53. $defaults['inactive'] = 1;
  54. $form->setDefaults($defaults);
  55. $form->display();
  56. } else {
  57. $limit = 20;
  58. $from = $page * $limit;
  59. //if user is crfp admin only list its sessions
  60. $where = null;
  61. if (!api_is_platform_admin()) {
  62. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  63. } else {
  64. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  65. }
  66. if (empty($where)) {
  67. $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
  68. } else {
  69. $where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
  70. }
  71. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  72. $query = "SELECT sc.*, (
  73. SELECT count(id) FROM $tbl_session s INNER JOIN $table_access_url_rel_session us ON (s.id = us.session_id)
  74. WHERE s.session_category_id = sc.id and 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. if (!empty($_GET['warn'])) {
  91. Display::display_warning_message(urldecode($_GET['warn']), false);
  92. }
  93. if (isset($_GET['action'])) {
  94. Display::display_confirmation_message(stripslashes($_GET['message']), false);
  95. }
  96. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  97. ?>
  98. <div class="actions">
  99. <?php
  100. echo '<div style="float:right;">
  101. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>
  102. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>
  103. </div>';
  104. ?>
  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. <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><br />
  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($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['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($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['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. <br />
  142. <table class="data_table" width="100%">
  143. <tr>
  144. <th>&nbsp;</th>
  145. <th><a href="<?php echo api_get_self(); ?>?sort=name&order=<?php echo ($sort == 'name') ? $order : 'ASC'; ?>"><?php echo get_lang('SessionCategoryName'); ?></a></th>
  146. <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>
  147. <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>
  148. <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>
  149. <th><?php echo get_lang('Actions'); ?></th>
  150. </tr>
  151. <?php
  152. $i = 0;
  153. $x = 0;
  154. foreach ($Sessions as $key => $enreg) {
  155. if ($key == $limit) {
  156. break;
  157. }
  158. $sql = 'SELECT COUNT(session_category_id)
  159. FROM '.$tbl_session.' s INNER JOIN '.$table_access_url_rel_session.' us ON (s.id = us.session_id)
  160. WHERE s.session_category_id = '.intval($enreg['id']).' AND us.access_url_id = '.api_get_current_access_url_id();
  161. $rs = Database::query($sql);
  162. list($nb_courses) = Database::fetch_array($rs);
  163. ?>
  164. <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
  165. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  166. <td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
  167. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
  168. <td><?php echo api_htmlentities($enreg['date_start'], ENT_QUOTES, $charset); ?></td>
  169. <td><?php echo api_htmlentities($enreg['date_end'], ENT_QUOTES, $charset); ?></td>
  170. <td>
  171. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  172. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  173. </a>
  174. <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;">
  175. <?php Display::display_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); ?>
  176. </a>
  177. </td>
  178. </tr>
  179. <?php
  180. $i = $i ? 0 : 1;
  181. $x++;
  182. }
  183. unset($Sessions);
  184. ?>
  185. </table>
  186. <br />
  187. <div align="left">
  188. <?php
  189. if ($num > $limit) {
  190. if ($page) {
  191. ?>
  192. <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>
  193. <?php
  194. } else {
  195. echo get_lang('Previous');
  196. }
  197. ?>
  198. |
  199. <?php
  200. if ($nbr_results > $limit) {
  201. ?>
  202. <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>
  203. <?php
  204. } else {
  205. echo get_lang('Next');
  206. }
  207. }
  208. ?>
  209. </div>
  210. <br />
  211. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  212. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  213. <select 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. <button class="btn btn-success" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  218. <?php } ?>
  219. </table>
  220. <?php }
  221. Display::display_footer();