session_list.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * List sessions in an efficient and usable way.
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. SessionManager::protectSession(null, false);
  12. //Add the JS needed to use the jqgrid
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  15. $idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
  16. $list_type = isset($_REQUEST['list_type']) ? $_REQUEST['list_type'] : 'simple';
  17. if ($action == 'delete') {
  18. $sessionInfo = api_get_session_info($idChecked);
  19. if ($sessionInfo) {
  20. $response = SessionManager::delete($idChecked);
  21. if ($response) {
  22. Display::addFlash(
  23. Display::return_message(get_lang('Deleted').': '.Security::remove_XSS($sessionInfo['name']))
  24. );
  25. }
  26. }
  27. header('Location: session_list.php');
  28. exit();
  29. } elseif ($action == 'copy') {
  30. $result = SessionManager::copy($idChecked);
  31. if ($result) {
  32. Display::addFlash(Display::return_message(get_lang('ItemCopied')));
  33. } else {
  34. Display::addFlash(Display::return_message(get_lang('ThereWasAnError'), 'error'));
  35. }
  36. header('Location: session_list.php');
  37. exit();
  38. }
  39. $tool_name = get_lang('SessionList');
  40. Display::display_header($tool_name);
  41. $courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
  42. $sessionFilter = new FormValidator(
  43. 'course_filter',
  44. 'get',
  45. '',
  46. '',
  47. [],
  48. FormValidator::LAYOUT_INLINE
  49. );
  50. $courseSelect = $sessionFilter->addElement(
  51. 'select_ajax',
  52. 'course_name',
  53. get_lang('SearchCourse'),
  54. null,
  55. ['url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course']
  56. );
  57. if (!empty($courseId)) {
  58. $courseInfo = api_get_course_info_by_id($courseId);
  59. $parents = CourseCategory::getParentsToString($courseInfo['categoryCode']);
  60. $courseSelect->addOption($parents.$courseInfo['title'], $courseInfo['code'], ['selected' => 'selected']);
  61. }
  62. $url = api_get_self();
  63. $actions = '
  64. <script>
  65. $(function() {
  66. $("#course_name").on("change", function() {
  67. var courseId = $(this).val();
  68. if (!courseId) {
  69. return;
  70. }
  71. window.location = "'.$url.'?course_id="+courseId;
  72. });
  73. });
  74. </script>';
  75. // jqgrid will use this URL to do the selects
  76. if (!empty($courseId)) {
  77. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
  78. } else {
  79. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
  80. }
  81. if (isset($_REQUEST['keyword'])) {
  82. //Begin with see the searchOper param
  83. $filter = new stdClass();
  84. $filter->groupOp = 'OR';
  85. $rule = new stdClass();
  86. $rule->field = 'category_name';
  87. $rule->op = 'in';
  88. $rule->data = Security::remove_XSS($_REQUEST['keyword']);
  89. $filter->rules[] = $rule;
  90. $filter->groupOp = 'OR';
  91. $filter = json_encode($filter);
  92. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters='.$filter.'&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=in';
  93. }
  94. if (isset($_REQUEST['id_category'])) {
  95. $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
  96. if (!empty($sessionCategory)) {
  97. //Begin with see the searchOper param
  98. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=in';
  99. }
  100. }
  101. $url .= '&list_type='.$list_type;
  102. $result = SessionManager::getGridColumns($list_type);
  103. $columns = $result['columns'];
  104. $column_model = $result['column_model'];
  105. // Autowidth
  106. $extra_params['autowidth'] = 'true';
  107. // height auto
  108. $extra_params['height'] = 'auto';
  109. if (!isset($_GET['keyword'])) {
  110. $extra_params['postData'] = [
  111. 'filters' => [
  112. 'groupOp' => 'AND',
  113. 'rules' => $result['rules'],
  114. ],
  115. ];
  116. }
  117. $hideSearch = api_get_configuration_value('hide_search_form_in_session_list');
  118. //With this function we can add actions to the jgrid (edit, delete, etc)
  119. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  120. return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  121. '&nbsp;<a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('user_subscribe_session.png', get_lang('SubscribeUsersToSession'), '', ICON_SIZE_SMALL).'</a>'.
  122. '&nbsp;<a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('courses_to_session.png', get_lang('SubscribeCoursesToSession'), '', ICON_SIZE_SMALL).'</a>'.
  123. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=copy&idChecked=\'+options.rowId+\'">'.Display::return_icon('copy.png', get_lang('Copy'), '', ICON_SIZE_SMALL).'</a>'.
  124. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=delete&idChecked=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
  125. '\';
  126. }';
  127. $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
  128. $allowOrder = api_get_configuration_value('session_list_order');
  129. $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
  130. ?>
  131. <script>
  132. function setSearchSelect(columnName) {
  133. $("#sessions").jqGrid('setColProp', columnName, {
  134. });
  135. }
  136. var added_cols = [];
  137. var original_cols = [];
  138. function clean_cols(grid, added_cols) {
  139. // Cleaning
  140. for (key in added_cols) {
  141. grid.hideCol(key);
  142. };
  143. grid.showCol('name');
  144. grid.showCol('display_start_date');
  145. grid.showCol('display_end_date');
  146. grid.showCol('course_title');
  147. }
  148. function show_cols(grid, added_cols) {
  149. grid.showCol('name').trigger('reloadGrid');
  150. for (key in added_cols) {
  151. grid.showCol(key);
  152. };
  153. }
  154. var second_filters = [];
  155. $(function() {
  156. date_pick_today = function(elem) {
  157. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  158. $(elem).datetimepicker('setDate', (new Date()));
  159. }
  160. date_pick_one_month = function(elem) {
  161. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  162. next_month = Date.today().next().month();
  163. $(elem).datetimepicker('setDate', next_month);
  164. }
  165. //Great hack
  166. register_second_select = function(elem) {
  167. second_filters[$(elem).val()] = $(elem);
  168. }
  169. fill_second_select = function(elem) {
  170. $(elem).on("change", function() {
  171. composed_id = $(this).val();
  172. field_id = composed_id.split("#")[0];
  173. id = composed_id.split("#")[1];
  174. $.ajax({
  175. url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
  176. dataType: "json",
  177. data: "type=session&field_id="+field_id+"&option_value_id="+id,
  178. success: function(data) {
  179. my_select = second_filters[field_id];
  180. my_select.empty();
  181. $.each(data, function(index, value) {
  182. my_select.append($("<option/>", {
  183. value: index,
  184. text: value
  185. }));
  186. });
  187. }
  188. });
  189. });
  190. }
  191. <?php
  192. echo Display::grid_js(
  193. 'sessions',
  194. $url,
  195. $columns,
  196. $column_model,
  197. $extra_params,
  198. [],
  199. $action_links,
  200. true
  201. );
  202. ?>
  203. setSearchSelect("status");
  204. var grid = $("#sessions"),
  205. prmSearch = {
  206. multipleSearch : true,
  207. overlay : false,
  208. width: 'auto',
  209. caption: '<?php echo addslashes(get_lang('Search')); ?>',
  210. formclass:'data_table',
  211. onSearch : function() {
  212. var postdata = grid.jqGrid('getGridParam', 'postData');
  213. if (postdata && postdata.filters) {
  214. filters = jQuery.parseJSON(postdata.filters);
  215. clean_cols(grid, added_cols);
  216. added_cols = [];
  217. $.each(filters, function(key, value) {
  218. if (key == 'rules') {
  219. $.each(value, function(subkey, subvalue) {
  220. if (subvalue.data == undefined) {
  221. }
  222. added_cols[subvalue.field] = subvalue.field;
  223. });
  224. }
  225. });
  226. show_cols(grid, added_cols);
  227. }
  228. },
  229. onReset: function() {
  230. clean_cols(grid, added_cols);
  231. }
  232. };
  233. original_cols = grid.jqGrid('getGridParam', 'colModel');
  234. <?php if ($allowOrder) {
  235. ?>
  236. options = {
  237. update: function (e, ui) {
  238. var rowNum = jQuery("#sessions").getGridParam('rowNum');
  239. var page = jQuery("#sessions").getGridParam('page');
  240. page = page - 1;
  241. var start = rowNum * page;
  242. var list = jQuery('#sessions').jqGrid('getRowData');
  243. var orderList = [];
  244. $(list).each(function(index, e) {
  245. index = index + start;
  246. orderList.push({'order':index, 'id': e.id});
  247. });
  248. orderList = JSON.stringify(orderList);
  249. $.get("<?php echo $orderUrl; ?>", "order="+orderList, function (result) {
  250. });
  251. }
  252. };
  253. // Sortable rows
  254. grid.jqGrid('sortableRows', options);
  255. <?php
  256. } ?>
  257. grid.jqGrid('navGrid','#sessions_pager',
  258. {edit:false,add:false,del:false},
  259. {height:280,reloadAfterSubmit:false}, // edit options
  260. {height:280,reloadAfterSubmit:false}, // add options
  261. {reloadAfterSubmit:false},// del options
  262. prmSearch
  263. );
  264. <?php
  265. // Create the searching dialog.
  266. if ($hideSearch !== true) {
  267. echo 'grid.searchGrid(prmSearch);';
  268. }
  269. ?>
  270. // Fixes search table.
  271. var searchDialogAll = $("#fbox_"+grid[0].id);
  272. searchDialogAll.addClass("table");
  273. var searchDialog = $("#searchmodfbox_"+grid[0].id);
  274. searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
  275. searchDialog.css({position:"adsolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
  276. var gbox = $("#gbox_"+grid[0].id);
  277. gbox.before(searchDialog);
  278. gbox.css({clear:"left"});
  279. // Select first elements by default
  280. $('.input-elm').each(function(){
  281. $(this).find('option:first').attr('selected', 'selected');
  282. });
  283. $('.delete-rule').each(function(){
  284. $(this).click(function(){
  285. $('.input-elm').each(function(){
  286. $(this).find('option:first').attr('selected', 'selected');
  287. });
  288. });
  289. });
  290. });
  291. </script>
  292. <div class="actions">
  293. <?php
  294. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
  295. Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM).'</a>';
  296. if (api_is_platform_admin()) {
  297. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
  298. Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
  299. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
  300. Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  301. }
  302. if ($list_type == 'complete') {
  303. echo '<a href="'.api_get_self().'?list_type=simple">'.
  304. Display::return_icon('view_remove.png', get_lang('Simple'), '', ICON_SIZE_MEDIUM).'</a>';
  305. } else {
  306. echo '<a href="'.api_get_self().'?list_type=complete">'.
  307. Display::return_icon('view_text.png', get_lang('Complete'), '', ICON_SIZE_MEDIUM).'</a>';
  308. }
  309. echo $actions;
  310. if (api_is_platform_admin()) {
  311. echo '<div class="pull-right">';
  312. // Create a search-box
  313. $form = new FormValidator(
  314. 'search_simple',
  315. 'get',
  316. '',
  317. '',
  318. [],
  319. FormValidator::LAYOUT_INLINE
  320. );
  321. $form->addElement('text', 'keyword', null, [
  322. 'aria-label' => get_lang('Search'),
  323. ]);
  324. $form->addButtonSearch(get_lang('Search'));
  325. $form->display();
  326. echo '</div>';
  327. echo '<div class="pull-right">';
  328. echo $sessionFilter->returnForm();
  329. echo '</div>';
  330. }
  331. echo '</div>';
  332. echo '<div id="session-table" class="table-responsive">';
  333. echo Display::grid_html('sessions');
  334. echo '</div>';
  335. Display::display_footer();