session_category_list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * List sessions categories
  5. * @package chamilo.admin
  6. */
  7. /**
  8. * Code
  9. */
  10. $language_file = 'admin';
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. api_protect_admin_script(true);
  14. api_protect_limit_for_session_admin();
  15. // setting the section (for the tabs)
  16. $this_section = SECTION_PLATFORM_ADMIN;
  17. $htmlHeadXtra[] = '<script>
  18. function selectAll(idCheck,numRows,action) {
  19. for(i=0;i<numRows;i++) {
  20. idcheck = document.getElementById(idCheck+"_"+i);
  21. if (action == "true"){
  22. idcheck.checked = true;
  23. } else {
  24. idcheck.checked = false;
  25. }
  26. }
  27. </script>';
  28. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  29. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  30. $page = isset($_GET['page']) ? intval($_GET['page']) : null;
  31. $action = isset($_REQUEST['action']) ? Security::remove_XSS($_REQUEST['action']) : null;
  32. $sort = isset($_GET['sort']) && in_array($_GET['sort'], array('name', 'nbr_session', 'date_start', 'date_end')) ? Security::remove_XSS($_GET['sort']) : 'name';
  33. $idChecked = isset($_REQUEST['idChecked']) ? Security::remove_XSS($_REQUEST['idChecked']) : null;
  34. $order = isset($_REQUEST['order']) ? Security::remove_XSS($_REQUEST['order']) : 'ASC';
  35. if ($action == 'delete_on_session' || $action == 'delete_off_session') {
  36. $delete_session = ($action == 'delete_on_session') ? true : false;
  37. SessionManager::delete_session_category($idChecked, $delete_session);
  38. header('Location: '.api_get_self().'?sort='.$sort.'&action=show_message&message='.urlencode(get_lang('SessionCategoryDelete')));
  39. exit();
  40. }
  41. $interbreadcrumb[] = array("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  42. if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
  43. $interbreadcrumb[] = array("url" => 'session_category_list.php', "name" => get_lang('ListSessionCategory'));
  44. $tool_name = get_lang('SearchASession');
  45. Display :: display_header($tool_name);
  46. $form = new FormValidator('advanced_search', 'get');
  47. $form->addElement('header', '', $tool_name);
  48. $active_group = array();
  49. $active_group[] = $form->createElement('checkbox', 'active', '', get_lang('Active'));
  50. $active_group[] = $form->createElement('checkbox', 'inactive', '', get_lang('Inactive'));
  51. $form->addGroup($active_group, '', get_lang('ActiveSession'), '<br/>', false);
  52. $form->addElement('style_submit_button', 'submit', get_lang('SearchUsers'), 'class="search"');
  53. $defaults['active'] = 1;
  54. $defaults['inactive'] = 1;
  55. $form->setDefaults($defaults);
  56. $form->display();
  57. } else {
  58. $limit = 20;
  59. $from = $page * $limit;
  60. //if user is crfp admin only list its sessions
  61. $where = null;
  62. if (!api_is_platform_admin()) {
  63. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  64. } else {
  65. $where .= (empty($_REQUEST['keyword']) ? "" : " WHERE name LIKE '%".Database::escape_string(trim($_REQUEST['keyword']))."%'");
  66. }
  67. if (empty($where)) {
  68. $where = " WHERE access_url_id = ".api_get_current_access_url_id()." ";
  69. } else {
  70. $where .= " AND access_url_id = ".api_get_current_access_url_id()." ";
  71. }
  72. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  73. $query = "SELECT sc.*, (
  74. SELECT count(id) FROM $tbl_session s INNER JOIN $table_access_url_rel_session us ON (s.id = us.session_id)
  75. WHERE s.session_category_id = sc.id and access_url_id = ".api_get_current_access_url_id()."
  76. ) as nbr_session
  77. FROM $tbl_session_category sc
  78. $where
  79. ORDER BY $sort $order
  80. LIMIT $from,".($limit + 1);
  81. $query_rows = "SELECT count(*) as total_rows FROM $tbl_session_category sc $where ";
  82. $order = ($order == 'ASC') ? 'DESC' : 'ASC';
  83. $result_rows = Database::query($query_rows);
  84. $recorset = Database::fetch_array($result_rows);
  85. $num = $recorset['total_rows'];
  86. $result = Database::query($query);
  87. $Sessions = Database::store_result($result);
  88. $nbr_results = sizeof($Sessions);
  89. $tool_name = get_lang('ListSessionCategory');
  90. Display::display_header($tool_name);
  91. if (!empty($_GET['warn'])) {
  92. Display::display_warning_message(urldecode($_GET['warn']), false);
  93. }
  94. if (isset($_GET['action'])) {
  95. Display::display_confirmation_message(stripslashes($_GET['message']), false);
  96. }
  97. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  98. ?>
  99. <div class="actions">
  100. <?php
  101. echo '<div style="float:right;">
  102. <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>
  103. <a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>
  104. </div>';
  105. ?>
  106. <form method="POST" action="session_category_list.php">
  107. <input type="text" name="keyword" value="<?php echo $keyword; ?>"/>
  108. <button class="search" type="submit" name="name" value="<?php echo get_lang('Search') ?>"><?php echo get_lang('Search') ?></button>
  109. <!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
  110. </form>
  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><br />
  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. <br />
  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 INNER JOIN '.$table_access_url_rel_session.' us ON (s.id = us.session_id)
  159. WHERE s.session_category_id = '.intval($enreg['id']).' AND us.access_url_id = '.api_get_current_access_url_id();
  160. $rs = Database::query($sql);
  161. list($nb_courses) = Database::fetch_array($rs);
  162. ?>
  163. <tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
  164. <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
  165. <td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
  166. <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
  167. <td><?php echo api_htmlentities($enreg['date_start'], ENT_QUOTES, $charset); ?></td>
  168. <td><?php echo api_htmlentities($enreg['date_end'], ENT_QUOTES, $charset); ?></td>
  169. <td>
  170. <a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>">
  171. <?php Display::display_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL); ?>
  172. </a>
  173. <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;">
  174. <?php Display::display_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL); ?>
  175. </a>
  176. </td>
  177. </tr>
  178. <?php
  179. $i = $i ? 0 : 1;
  180. $x++;
  181. }
  182. unset($Sessions);
  183. ?>
  184. </table>
  185. <br />
  186. <div align="left">
  187. <?php
  188. if ($num > $limit) {
  189. if ($page) {
  190. ?>
  191. <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>
  192. <?php
  193. } else {
  194. echo get_lang('Previous');
  195. }
  196. ?>
  197. |
  198. <?php
  199. if ($nbr_results > $limit) {
  200. ?>
  201. <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>
  202. <?php
  203. } else {
  204. echo get_lang('Next');
  205. }
  206. }
  207. ?>
  208. </div>
  209. <br />
  210. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'true');return false;"><?php echo get_lang('SelectAll') ?></a>&nbsp;-&nbsp;
  211. <a href="#" onclick="selectAll('idChecked',<?php echo $x; ?>,'false');return false;"><?php echo get_lang('UnSelectAll') ?></a>
  212. <select name="action">
  213. <option value="delete_off_session" selected="selected"><?php echo get_lang('DeleteSelectedSessionCategory'); ?></option>
  214. <option value="delete_on_session"><?php echo get_lang('DeleteSelectedFullSessionCategory'); ?></option>
  215. </select>
  216. <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Ok') ?></button>
  217. <?php } ?>
  218. </table>
  219. <?php }
  220. Display::display_footer();