session_list.php 15 KB

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