session_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. /*array(
  115. array( "field" => "display_start_date", "op" => "gt", "data" => ""),
  116. array( "field" => "display_end_date", "op" => "gt", "data" => "")
  117. ),*/
  118. //'groups' => $groups
  119. ],
  120. ];
  121. }
  122. $hideSearch = api_get_configuration_value('hide_search_form_in_session_list');
  123. //With this function we can add actions to the jgrid (edit, delete, etc)
  124. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  125. 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>'.
  126. '&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>'.
  127. '&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>'.
  128. '&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>'.
  129. '&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>'.
  130. '\';
  131. }';
  132. $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
  133. $allowOrder = api_get_configuration_value('session_list_order');
  134. $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
  135. ?>
  136. <script>
  137. function setSearchSelect(columnName) {
  138. $("#sessions").jqGrid('setColProp', columnName, {
  139. /*searchoptions:{
  140. dataInit:function(el){
  141. $("option[value='1']",el).attr("selected", "selected");
  142. setTimeout(function(){
  143. $(el).trigger('change');
  144. }, 1000);
  145. }
  146. }*/
  147. });
  148. }
  149. var added_cols = [];
  150. var original_cols = [];
  151. function clean_cols(grid, added_cols) {
  152. //Cleaning
  153. for (key in added_cols) {
  154. //console.log('hide: ' + key);
  155. grid.hideCol(key);
  156. };
  157. grid.showCol('name');
  158. grid.showCol('display_start_date');
  159. grid.showCol('display_end_date');
  160. grid.showCol('course_title');
  161. }
  162. function show_cols(grid, added_cols) {
  163. grid.showCol('name').trigger('reloadGrid');
  164. for (key in added_cols) {
  165. //console.log('show: ' + key);
  166. grid.showCol(key);
  167. };
  168. }
  169. var second_filters = [];
  170. $(function() {
  171. date_pick_today = function(elem) {
  172. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  173. $(elem).datetimepicker('setDate', (new Date()));
  174. }
  175. date_pick_one_month = function(elem) {
  176. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  177. next_month = Date.today().next().month();
  178. $(elem).datetimepicker('setDate', next_month);
  179. }
  180. //Great hack
  181. register_second_select = function(elem) {
  182. second_filters[$(elem).val()] = $(elem);
  183. }
  184. fill_second_select = function(elem) {
  185. $(elem).on("change", function() {
  186. composed_id = $(this).val();
  187. field_id = composed_id.split("#")[0];
  188. id = composed_id.split("#")[1];
  189. $.ajax({
  190. url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
  191. dataType: "json",
  192. data: "type=session&field_id="+field_id+"&option_value_id="+id,
  193. success: function(data) {
  194. my_select = second_filters[field_id];
  195. my_select.empty();
  196. $.each(data, function(index, value) {
  197. my_select.append($("<option/>", {
  198. value: index,
  199. text: value
  200. }));
  201. });
  202. }
  203. });
  204. });
  205. }
  206. <?php
  207. echo Display::grid_js(
  208. 'sessions',
  209. $url,
  210. $columns,
  211. $column_model,
  212. $extra_params,
  213. [],
  214. $action_links,
  215. true
  216. );
  217. ?>
  218. setSearchSelect("status");
  219. var grid = $("#sessions"),
  220. prmSearch = {
  221. multipleSearch : true,
  222. overlay : false,
  223. width: 'auto',
  224. caption: '<?php echo addslashes(get_lang('Search')); ?>',
  225. formclass:'data_table',
  226. onSearch : function() {
  227. var postdata = grid.jqGrid('getGridParam', 'postData');
  228. if (postdata && postdata.filters) {
  229. filters = jQuery.parseJSON(postdata.filters);
  230. clean_cols(grid, added_cols);
  231. added_cols = [];
  232. $.each(filters, function(key, value){
  233. //console.log('key: ' + key );
  234. if (key == 'rules') {
  235. $.each(value, function(subkey, subvalue) {
  236. if (subvalue.data == undefined) {
  237. }
  238. //if (added_cols[value.field] == undefined) {
  239. added_cols[subvalue.field] = subvalue.field;
  240. //}
  241. //grid.showCol(value.field);
  242. });
  243. }
  244. });
  245. show_cols(grid, added_cols);
  246. }
  247. },
  248. onReset: function() {
  249. clean_cols(grid, added_cols);
  250. }
  251. };
  252. original_cols = grid.jqGrid('getGridParam', 'colModel');
  253. <?php if ($allowOrder) {
  254. ?>
  255. options = {
  256. update: function (e, ui) {
  257. var rowNum = jQuery("#sessions").getGridParam('rowNum');
  258. var page = jQuery("#sessions").getGridParam('page');
  259. page = page - 1;
  260. var start = rowNum * page;
  261. var list = jQuery('#sessions').jqGrid('getRowData');
  262. var orderList = [];
  263. $(list).each(function(index, e) {
  264. index = index + start;
  265. orderList.push({'order':index, 'id': e.id});
  266. });
  267. orderList = JSON.stringify(orderList);
  268. $.get("<?php echo $orderUrl; ?>", "order="+orderList, function (result) {
  269. //console.log(result);
  270. });
  271. }
  272. };
  273. // Sortable rows
  274. grid.jqGrid('sortableRows', options);
  275. <?php
  276. } ?>
  277. grid.jqGrid('navGrid','#sessions_pager',
  278. {edit:false,add:false,del:false},
  279. {height:280,reloadAfterSubmit:false}, // edit options
  280. {height:280,reloadAfterSubmit:false}, // add options
  281. {reloadAfterSubmit:false},// del options
  282. prmSearch
  283. );
  284. <?php
  285. // Create the searching dialog.
  286. if ($hideSearch !== true) {
  287. echo 'grid.searchGrid(prmSearch);';
  288. }
  289. ?>
  290. // Fixes search table.
  291. var searchDialogAll = $("#fbox_"+grid[0].id);
  292. searchDialogAll.addClass("table");
  293. var searchDialog = $("#searchmodfbox_"+grid[0].id);
  294. searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
  295. searchDialog.css({position:"adsolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
  296. var gbox = $("#gbox_"+grid[0].id);
  297. gbox.before(searchDialog);
  298. gbox.css({clear:"left"});
  299. //Select first elements by default
  300. $('.input-elm').each(function(){
  301. $(this).find('option:first').attr('selected', 'selected');
  302. });
  303. $('.delete-rule').each(function(){
  304. $(this).click(function(){
  305. $('.input-elm').each(function(){
  306. $(this).find('option:first').attr('selected', 'selected');
  307. });
  308. });
  309. });
  310. });
  311. </script>
  312. <div class="actions">
  313. <?php
  314. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
  315. Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM).'</a>';
  316. if (api_is_platform_admin()) {
  317. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
  318. Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
  319. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
  320. Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  321. }
  322. if ($list_type == 'complete') {
  323. echo '<a href="'.api_get_self().'?list_type=simple">'.
  324. Display::return_icon('view_remove.png', get_lang('Simple'), '', ICON_SIZE_MEDIUM).'</a>';
  325. } else {
  326. echo '<a href="'.api_get_self().'?list_type=complete">'.
  327. Display::return_icon('view_text.png', get_lang('Complete'), '', ICON_SIZE_MEDIUM).'</a>';
  328. }
  329. echo $actions;
  330. if (api_is_platform_admin()) {
  331. echo '<div class="pull-right">';
  332. // Create a search-box
  333. $form = new FormValidator(
  334. 'search_simple',
  335. 'get',
  336. '',
  337. '',
  338. [],
  339. FormValidator::LAYOUT_INLINE
  340. );
  341. $form->addElement('text', 'keyword', null, [
  342. 'aria-label' => get_lang('Search'),
  343. ]);
  344. $form->addButtonSearch(get_lang('Search'));
  345. $form->display();
  346. echo '</div>';
  347. echo '<div class="pull-right">';
  348. echo $sessionFilter->returnForm();
  349. echo '</div>';
  350. }
  351. echo '</div>';
  352. echo '<div id="session-table" class="table-responsive">';
  353. echo Display::grid_html('sessions');
  354. echo '</div>';
  355. Display::display_footer();