session_list.php 12 KB

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