session_list.php 10 KB

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