session.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Course sessions reporting.
  5. *
  6. * @package chamilo.reporting
  7. */
  8. ob_start();
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_block_anonymous_users();
  12. $this_section = SECTION_TRACKING;
  13. $export_csv = false;
  14. if (isset($_REQUEST['export']) && $_REQUEST['export'] == 'csv') {
  15. $export_csv = true;
  16. }
  17. $id_coach = api_get_user_id();
  18. if (isset($_REQUEST['id_coach']) && $_REQUEST['id_coach'] != '') {
  19. $id_coach = (int) $_REQUEST['id_coach'];
  20. }
  21. $allowToTrack = api_is_platform_admin(true, true) || api_is_teacher();
  22. if (!$allowToTrack) {
  23. api_not_allowed(true);
  24. }
  25. $htmlHeadXtra[] = api_get_jqgrid_js();
  26. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Reporting')];
  27. Display::display_header(get_lang('Course sessions'));
  28. if (api_is_platform_admin(true, true)) {
  29. $a_sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  30. if (!api_is_session_admin()) {
  31. $menu_items[] = Display::url(
  32. Display::return_icon('statistics.png', get_lang('View my progress'), '', ICON_SIZE_MEDIUM),
  33. api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
  34. );
  35. $menu_items[] = Display::url(
  36. Display::return_icon('user.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM),
  37. 'index.php?view=drh_students&amp;display=yourstudents'
  38. );
  39. $menu_items[] = Display::url(
  40. Display::return_icon('teacher.png', get_lang('Teachers'), [], ICON_SIZE_MEDIUM),
  41. 'teachers.php'
  42. );
  43. $menu_items[] = Display::url(
  44. Display::return_icon('course.png', get_lang('Courses'), [], ICON_SIZE_MEDIUM),
  45. 'course.php'
  46. );
  47. $menu_items[] = Display::url(
  48. Display::return_icon('session_na.png', get_lang('Course sessions'), [], ICON_SIZE_MEDIUM),
  49. '#'
  50. );
  51. }
  52. $menu_items[] = Display::url(
  53. Display::return_icon('works.png', get_lang('Assignments report'), [], ICON_SIZE_MEDIUM),
  54. api_get_path(WEB_CODE_PATH).'mySpace/works_in_session_report.php'
  55. );
  56. $menu_items[] = Display::url(
  57. Display::return_icon('clock.png', get_lang('Teachers time report by session'), [], ICON_SIZE_MEDIUM),
  58. api_get_path(WEB_CODE_PATH).'admin/teachers_time_by_session_report.php'
  59. );
  60. if (!api_is_session_admin()) {
  61. $menu_items[] = Display::url(
  62. Display::return_icon('1day.png', get_lang('Course sessionsPlanCalendar'), [], ICON_SIZE_MEDIUM),
  63. api_get_path(WEB_CODE_PATH)."calendar/planification.php"
  64. );
  65. }
  66. $actionsLeft = '';
  67. $nb_menu_items = count($menu_items);
  68. if ($nb_menu_items > 1) {
  69. foreach ($menu_items as $key => $item) {
  70. $actionsLeft .= $item;
  71. }
  72. }
  73. $actionsRight = '';
  74. if (count($a_sessions) > 0) {
  75. $actionsRight = Display::url(
  76. Display::return_icon('printer.png', get_lang('Print'), [], 32),
  77. 'javascript: void(0);',
  78. ['onclick' => 'javascript: window.print();']
  79. );
  80. $actionsRight .= Display::url(
  81. Display::return_icon('export_csv.png', get_lang('CSV export'), [], 32),
  82. api_get_self().'?export=csv'
  83. );
  84. }
  85. $toolbar = Display::toolbarAction(
  86. 'toolbar-session',
  87. [$actionsLeft, $actionsRight]
  88. );
  89. echo $toolbar;
  90. echo Display::page_header(get_lang('YourCourse sessionsList'));
  91. } elseif (api_is_teacher()) {
  92. $actionsRight = Display::url(
  93. Display::return_icon('clock.png', get_lang('Teachers time report by session'), [], ICON_SIZE_MEDIUM),
  94. api_get_path(WEB_CODE_PATH).'admin/teachers_time_by_session_report.php'
  95. );
  96. $toolbar = Display::toolbarAction(
  97. 'toolbar-session',
  98. ['', $actionsRight]
  99. );
  100. echo $toolbar;
  101. echo Display::page_header(get_lang('YourCourse sessionsList'));
  102. } else {
  103. $a_sessions = Tracking::get_sessions_coached_by_user($id_coach);
  104. }
  105. $form = new FormValidator(
  106. 'search_course',
  107. 'post',
  108. api_get_path(WEB_CODE_PATH).'mySpace/session.php'
  109. );
  110. $form->addElement('text', 'keyword', get_lang('Keyword'));
  111. $extraFieldSession = new ExtraField('session');
  112. $extraFieldSession->addElements(
  113. $form,
  114. null,
  115. [], //exclude
  116. true
  117. );
  118. $form->addButtonSearch(get_lang('Search'));
  119. $keyword = '';
  120. $result = SessionManager::getGridColumns('my_space');
  121. $columns = $result['columns'];
  122. $columnModel = $result['column_model'];
  123. $filterToString = '';
  124. if ($form->validate()) {
  125. $values = $form->getSubmitValues();
  126. $keyword = Security::remove_XSS($form->getSubmitValue('keyword'));
  127. $extraField = new ExtraField('session');
  128. $extraFields = $extraField->get_all(null, 'option_order');
  129. $extraFields = array_column($extraFields, 'variable');
  130. $filter = new stdClass();
  131. $filter->groupOp = 'AND';
  132. foreach ($columnModel as $col) {
  133. if (isset($values[$col['index']]) && !empty($values[$col['index']]) &&
  134. in_array(str_replace('extra_', '', $col['index']), $extraFields)
  135. ) {
  136. $rule = new stdClass();
  137. $rule->field = $col['index'];
  138. $rule->op = 'in';
  139. $rule->data = Security::remove_XSS($values[$col['index']]);
  140. $filter->rules[] = $rule;
  141. $filter->groupOp = 'AND';
  142. }
  143. }
  144. $filterToString = json_encode($filter);
  145. }
  146. $form->setDefaults(['keyword' => $keyword]);
  147. $url = api_get_path(WEB_AJAX_PATH).
  148. 'model.ajax.php?a=get_sessions_tracking&_search=true&_force_search=true&filters='.$filterToString.'&keyword='.$keyword;
  149. // Column config
  150. $extraParams = [
  151. 'autowidth' => 'true',
  152. 'height' => 'auto',
  153. ];
  154. /*$extraParams['postData'] = [
  155. 'filters' => [
  156. 'groupOp' => 'AND',
  157. 'rules' => $result['rules'],
  158. ],
  159. ];*/
  160. $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
  161. $allowOrder = api_get_configuration_value('session_list_order');
  162. $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
  163. ?>
  164. <script>
  165. function setSearchSelect(columnName) {
  166. $("#sessions").jqGrid('setColProp', columnName, {
  167. });
  168. }
  169. var added_cols = [];
  170. var original_cols = [];
  171. function clean_cols(grid, added_cols) {
  172. // Cleaning
  173. for (key in added_cols) {
  174. grid.hideCol(key);
  175. };
  176. grid.showCol('name');
  177. grid.showCol('display_start_date');
  178. grid.showCol('display_end_date');
  179. grid.showCol('course_title');
  180. }
  181. function show_cols(grid, added_cols) {
  182. grid.showCol('name').trigger('reloadGrid');
  183. for (key in added_cols) {
  184. grid.showCol(key);
  185. };
  186. }
  187. var second_filters = [];
  188. $(function() {
  189. date_pick_today = function(elem) {
  190. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  191. $(elem).datetimepicker('setDate', (new Date()));
  192. }
  193. date_pick_one_month = function(elem) {
  194. $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
  195. next_month = Date.today().next().month();
  196. $(elem).datetimepicker('setDate', next_month);
  197. }
  198. // Great hack
  199. register_second_select = function(elem) {
  200. second_filters[$(elem).val()] = $(elem);
  201. }
  202. fill_second_select = function(elem) {
  203. $(elem).on("change", function() {
  204. composed_id = $(this).val();
  205. field_id = composed_id.split("#")[0];
  206. id = composed_id.split("#")[1];
  207. $.ajax({
  208. url: "<?php echo $urlAjaxExtraField; ?>&a=get_second_select_options",
  209. dataType: "json",
  210. data: "type=session&field_id="+field_id+"&option_value_id="+id,
  211. success: function(data) {
  212. my_select = second_filters[field_id];
  213. my_select.empty();
  214. $.each(data, function(index, value) {
  215. my_select.append($("<option/>", {
  216. value: index,
  217. text: value
  218. }));
  219. });
  220. }
  221. });
  222. });
  223. }
  224. <?php
  225. echo Display::grid_js(
  226. 'sessions',
  227. $url,
  228. $columns,
  229. $columnModel,
  230. $extraParams,
  231. [],
  232. null,
  233. true
  234. );
  235. ?>
  236. setSearchSelect("status");
  237. var grid = $("#sessions"),
  238. prmSearch = {
  239. multipleSearch : true,
  240. overlay : false,
  241. width: 'auto',
  242. caption: '<?php echo addslashes(get_lang('Search')); ?>',
  243. formclass:'data_table',
  244. onSearch : function() {
  245. var postdata = grid.jqGrid('getGridParam', 'postData');
  246. if (postdata && postdata.filters) {
  247. filters = jQuery.parseJSON(postdata.filters);
  248. clean_cols(grid, added_cols);
  249. added_cols = [];
  250. $.each(filters, function(key, value) {
  251. if (key == 'rules') {
  252. $.each(value, function(subkey, subvalue) {
  253. added_cols[subvalue.field] = subvalue.field;
  254. });
  255. }
  256. });
  257. show_cols(grid, added_cols);
  258. }
  259. },
  260. onReset: function() {
  261. clean_cols(grid, added_cols);
  262. }
  263. };
  264. original_cols = grid.jqGrid('getGridParam', 'colModel');
  265. grid.jqGrid('navGrid','#sessions_pager',
  266. {edit:false,add:false,del:false},
  267. {height:280,reloadAfterSubmit:false}, // edit options
  268. {height:280,reloadAfterSubmit:false}, // add options
  269. {reloadAfterSubmit:false},// del options
  270. prmSearch
  271. );
  272. <?php
  273. // Create the searching dialog.
  274. //echo 'grid.searchGrid(prmSearch);';
  275. ?>
  276. // Fixes search table.
  277. var searchDialogAll = $("#fbox_"+grid[0].id);
  278. searchDialogAll.addClass("table");
  279. var searchDialog = $("#searchmodfbox_"+grid[0].id);
  280. searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
  281. searchDialog.css({position:"adsolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
  282. var gbox = $("#gbox_"+grid[0].id);
  283. gbox.before(searchDialog);
  284. gbox.css({clear:"left"});
  285. // Select first elements by default
  286. $('.input-elm').each(function() {
  287. $(this).find('option:first').attr('selected', 'selected');
  288. });
  289. $('.delete-rule').each(function(){
  290. $(this).click(function(){
  291. $('.input-elm').each(function(){
  292. $(this).find('option:first').attr('selected', 'selected');
  293. });
  294. });
  295. });
  296. });
  297. </script>
  298. <?php
  299. $form->display();
  300. echo Display::grid_html('sessions');
  301. Display::display_footer();