session_list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. $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=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';
  78. }
  79. if (isset($_REQUEST['id_category'])) {
  80. $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
  81. if (!empty($sessionCategory)) {
  82. //Begin with see the searchOper param
  83. $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=bw';
  84. }
  85. }
  86. $url .= '&list_type='.$list_type;
  87. $result = SessionManager::getGridColumns($list_type);
  88. $columns = $result['columns'];
  89. $column_model = $result['column_model'];
  90. // Autowidth
  91. $extra_params['autowidth'] = 'true';
  92. // height auto
  93. $extra_params['height'] = 'auto';
  94. $extra_params['postData'] = array(
  95. 'filters' => array(
  96. "groupOp" => "AND",
  97. "rules" => $result['rules'],
  98. /*array(
  99. array( "field" => "display_start_date", "op" => "gt", "data" => ""),
  100. array( "field" => "display_end_date", "op" => "gt", "data" => "")
  101. ),*/
  102. //'groups' => $groups
  103. )
  104. );
  105. $defaultValues = [];
  106. $filters = isset($_GET['filters']) ? $_GET['filters'] : '';
  107. $filterToSend = [];
  108. if (!empty($filters)) {
  109. $filterToSend = ['groupOp' => 'AND'];
  110. $filters = unserialize(urldecode($filters));
  111. if ($filters) {
  112. $count = 1;
  113. $countExtraField = 1;
  114. foreach ($result['column_model'] as $column) {
  115. if ($count > 5) {
  116. if (isset($filters[$column['name']])) {
  117. $defaultValues['jqg'.$countExtraField] = $filters[$column['name']];
  118. $filterToSend['rules'][] = ['field' => $column['name'], 'op' => 'cn', 'data' => $filters[$column['name']]];
  119. }
  120. $countExtraField++;
  121. }
  122. $count++;
  123. }
  124. }
  125. }
  126. $defaultValues = json_encode($defaultValues);
  127. // jqgrid will use this URL to do the selects
  128. if (!empty($courseId)) {
  129. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
  130. } else {
  131. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
  132. }
  133. if (isset($_REQUEST['keyword'])) {
  134. //Begin with see the searchOper param
  135. $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=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';
  136. }
  137. if (isset($_REQUEST['id_category'])) {
  138. $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']);
  139. if (!empty($sessionCategory)) {
  140. //Begin with see the searchOper param
  141. $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=bw';
  142. }
  143. }
  144. $url .= '&list_type='.$list_type;
  145. //With this function we can add actions to the jgrid (edit, delete, etc)
  146. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  147. 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>'.
  148. '&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>'.
  149. '&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>'.
  150. '&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>'.
  151. '&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>'.
  152. '\';
  153. }';
  154. $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
  155. ?>
  156. <script>
  157. function setSearchSelect(columnName) {
  158. $("#sessions").jqGrid('setColProp', columnName, {
  159. /*searchoptions:{
  160. dataInit:function(el){
  161. $("option[value='1']",el).attr("selected", "selected");
  162. setTimeout(function(){
  163. $(el).trigger('change');
  164. }, 1000);
  165. }
  166. }*/
  167. });
  168. }
  169. var added_cols = [];
  170. var original_cols = [];
  171. function clean_cols(grid, added_cols) {
  172. //Cleaning
  173. for (key in added_cols) {
  174. //console.log('hide: ' + key);
  175. grid.hideCol(key);
  176. };
  177. grid.showCol('name');
  178. grid.showCol('display_start_date');
  179. grid.showCol('display_end_date');
  180. grid.showCol('course_title');
  181. }
  182. function show_cols(grid, added_cols) {
  183. grid.showCol('name').trigger('reloadGrid');
  184. for (key in added_cols) {
  185. grid.showCol(key);
  186. };
  187. }
  188. var second_filters = [];
  189. $(function() {
  190. date_pick_today = function(elem) {
  191. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  192. $(elem).datetimepicker('setDate', (new Date()));
  193. }
  194. date_pick_one_month = function(elem) {
  195. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  196. next_month = Date.today().next().month();
  197. $(elem).datetimepicker('setDate', next_month);
  198. }
  199. //Great hack
  200. register_second_select = function(elem) {
  201. second_filters[$(elem).val()] = $(elem);
  202. }
  203. fill_second_select = function(elem) {
  204. $(elem).on("change", function() {
  205. composed_id = $(this).val();
  206. field_id = composed_id.split("#")[0];
  207. id = composed_id.split("#")[1];
  208. $.ajax({
  209. url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
  210. dataType: "json",
  211. data: "type=session&field_id="+field_id+"&option_value_id="+id,
  212. success: function(data) {
  213. my_select = second_filters[field_id];
  214. my_select.empty();
  215. $.each(data, function(index, value) {
  216. my_select.append($("<option/>", {
  217. value: index,
  218. text: value
  219. }));
  220. });
  221. }
  222. });
  223. });
  224. }
  225. <?php
  226. echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  227. ?>
  228. setSearchSelect("status");
  229. var grid = $("#sessions"),
  230. prmSearch = {
  231. multipleSearch : true,
  232. overlay : false,
  233. width: 'auto',
  234. caption: '<?php echo addslashes(get_lang('Search')); ?>',
  235. formclass:'data_table',
  236. onSearch : function() {
  237. var postdata = grid.jqGrid('getGridParam', 'postData');
  238. if (postdata && postdata.filters) {
  239. filters = jQuery.parseJSON(postdata.filters);
  240. clean_cols(grid, added_cols);
  241. added_cols = [];
  242. $.each(filters, function(key, value){
  243. //console.log('key: ' + key );
  244. if (key == 'rules') {
  245. $.each(value, function(subkey, subvalue) {
  246. if (subvalue.data == undefined) {
  247. }
  248. added_cols[subvalue.field] = subvalue.field;
  249. });
  250. }
  251. });
  252. show_cols(grid, added_cols);
  253. }
  254. },
  255. onReset: function() {
  256. clean_cols(grid, added_cols);
  257. }
  258. };
  259. original_cols = grid.jqGrid('getGridParam', 'colModel');
  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. // Create the searching dialog.
  268. grid.searchGrid(prmSearch);
  269. // Fixes search table.
  270. var searchDialogAll = $("#fbox_"+grid[0].id);
  271. searchDialogAll.addClass("table");
  272. var searchDialog = $("#searchmodfbox_"+grid[0].id);
  273. searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
  274. searchDialog.css({position:"adsolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
  275. var gbox = $("#gbox_"+grid[0].id);
  276. gbox.before(searchDialog);
  277. gbox.css({clear:"left"});
  278. //Select first elements by default
  279. $('.input-elm').each(function(){
  280. $(this).find('option:first').attr('selected', 'selected');
  281. });
  282. var defaultValues = jQuery.parseJSON('<?php echo $defaultValues; ?>');
  283. if (defaultValues) {
  284. $('.input-elm').each(function() {
  285. if (defaultValues.hasOwnProperty($(this).attr('id'))) {
  286. $(this).val(defaultValues[$(this).attr('id')]);
  287. }
  288. });
  289. }
  290. $('.delete-rule').each(function(){
  291. $(this).click(function(){
  292. $('.input-elm').each(function(){
  293. $(this).find('option:first').attr('selected', 'selected');
  294. });
  295. });
  296. });
  297. });
  298. </script>
  299. <div class="actions">
  300. <?php
  301. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_add.php">'.
  302. Display::return_icon('new_session.png', get_lang('AddSession'), '', ICON_SIZE_MEDIUM).'</a>';
  303. if (api_is_platform_admin()) {
  304. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/add_many_session_to_category.php">'.
  305. Display::return_icon('session_to_category.png', get_lang('AddSessionsInCategories'), '', ICON_SIZE_MEDIUM).'</a>';
  306. echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_category_list.php">'.
  307. Display::return_icon('folder.png', get_lang('ListSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  308. }
  309. if ($list_type == 'complete') {
  310. echo '<a href="'.api_get_self().'?list_type=simple">'.Display::return_icon('view_remove.png', get_lang('Simple'), '', ICON_SIZE_MEDIUM).'</a>';
  311. } else {
  312. echo '<a href="'.api_get_self().'?list_type=complete">'.Display::return_icon('view_text.png', get_lang('Complete'), '', ICON_SIZE_MEDIUM).'</a>';
  313. }
  314. echo $actions;
  315. if (api_is_platform_admin()) {
  316. echo '<div class="pull-right">';
  317. // Create a search-box
  318. $form = new FormValidator(
  319. 'search_simple',
  320. 'get',
  321. '',
  322. '',
  323. [],
  324. FormValidator::LAYOUT_INLINE
  325. );
  326. $form->addElement('text', 'keyword', null, array(
  327. 'aria-label' => get_lang('Search')
  328. ));
  329. $form->addButtonSearch(get_lang('Search'));
  330. $form->display();
  331. echo '</div>';
  332. echo '<div class="pull-right">';
  333. echo $sessionFilter->returnForm();
  334. echo '</div>';
  335. }
  336. echo '</div>';
  337. echo '<div id="session-table" class="table-responsive">';
  338. echo Display::grid_html('sessions');
  339. echo '</div>';
  340. Display::display_footer();