session_list.php 13 KB

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