session_list.php 12 KB

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