session_list.php 11 KB

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