session_list.php 14 KB

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