session_list.php 14 KB

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