session_list.php 14 KB

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