exercise_category_report.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. api_protect_admin_script();
  6. $exportCSV = isset($_GET['export']) && $_GET['export'] === 'csv' ? true : false;
  7. // the section (for the tabs)
  8. $this_section = SECTION_TRACKING;
  9. $csv_content = [];
  10. $nameTools = get_lang('MySpace');
  11. $is_platform_admin = api_is_platform_admin();
  12. $is_drh = api_is_drh();
  13. $is_session_admin = api_is_session_admin();
  14. $currentUrl = api_get_self();
  15. $courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
  16. $defaults = [];
  17. $defaults['start_date'] = isset($_GET['start_date']) ? Security::remove_XSS($_GET['start_date']) : '';
  18. $defaults['course_id'] = $courseId;
  19. $htmlHeadXtra[] = api_get_jqgrid_js();
  20. $htmlHeadXtra[] = '<script>
  21. $(function() {
  22. $("#exercise_course_id").on("change", function(e) {
  23. var data = $(this).select2(\'data\');
  24. var option = data[0];
  25. //Then I take the values like if I work with an array
  26. var value = option.id;
  27. var selectedDate = $("#start_date").datepicker({ dateFormat: \'dd,MM,yyyy\' }).val();
  28. window.location.replace("'.$currentUrl.'?start_date="+selectedDate+"&course_id="+value);
  29. });
  30. });
  31. </script>';
  32. $form = new FormValidator('exercise', 'get');
  33. $form->addDatePicker('start_date', get_lang('StartDate'));
  34. if (empty($courseId)) {
  35. $form->addSelectAjax(
  36. 'course_id',
  37. get_lang('Course'),
  38. null,
  39. [
  40. 'url' => api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course',
  41. ]
  42. );
  43. } else {
  44. $courseInfo = api_get_course_info_by_id($courseId);
  45. if (!empty($courseInfo)) {
  46. $form->addHidden('course_id', $courseId);
  47. $courseLabel = Display::url(
  48. $courseInfo['name'].' ('.$courseInfo['code'].')',
  49. $courseInfo['course_public_url'],
  50. ['target' => '_blank']
  51. );
  52. $form->addLabel(get_lang('Course'), $courseLabel);
  53. $exerciseList = ExerciseLib::get_all_exercises_for_course_id(
  54. $courseInfo,
  55. 0,
  56. $courseId,
  57. true
  58. );
  59. if (!empty($exerciseList)) {
  60. $options = [];
  61. foreach ($exerciseList as $exercise) {
  62. $options[$exercise['id']] = $exercise['title'];
  63. }
  64. $form->addSelect('exercise_id', get_lang('Exercises'), $options);
  65. } else {
  66. $form->addLabel(get_lang('Exercises'), Display::return_message(get_lang('NoExercises')));
  67. }
  68. } else {
  69. Display::addFlash(Display::return_message(get_lang('CourseDoesNotExist'), 'warning'));
  70. }
  71. }
  72. $form->setDefaults($defaults);
  73. $form->addButtonSearch(get_lang('Search'));
  74. Display::display_header($nameTools);
  75. $form->display();
  76. $extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
  77. if ($form->validate() && !empty($courseInfo)) {
  78. $values = $form->getSubmitValues();
  79. $exerciseId = isset($values['exercise_id']) ? $values['exercise_id'] : 0;
  80. $startDate = Security::remove_XSS($values['start_date']);
  81. $exportFilename = 'exercise_results_report_'.$exerciseId.'_'.$courseInfo['code'];
  82. $url = api_get_path(WEB_AJAX_PATH).
  83. 'model.ajax.php?a=get_exercise_results_report&exercise_id='.$exerciseId.
  84. '&start_date='.$startDate.'&cidReq='.$courseInfo['code'].
  85. '&course_id='.$courseId.
  86. '&export_filename='.$exportFilename;
  87. $categoryList = TestCategory::getListOfCategoriesIDForTest($exerciseId, $courseId);
  88. $columns = [
  89. get_lang('FirstName'),
  90. get_lang('LastName'),
  91. get_lang('LoginName'),
  92. ];
  93. if (!empty($extraFields) && isset($extraFields['fields'])) {
  94. $extraField = new ExtraField('user');
  95. foreach ($extraFields['fields'] as $variable) {
  96. $info = $extraField->get_handler_field_info_by_field_variable($variable);
  97. if ($info) {
  98. $columns[] = $info['display_text'];
  99. }
  100. }
  101. }
  102. $columns[] = get_lang('Session');
  103. $columns[] = get_lang('SessionStartDate');
  104. $columns[] = get_lang('StartDate');
  105. $columns[] = get_lang('Score');
  106. if (!empty($categoryList)) {
  107. foreach ($categoryList as $categoryInfo) {
  108. $columns[] = $categoryInfo['title'];
  109. }
  110. }
  111. $columns[] = get_lang('Actions');
  112. $columnModel = [
  113. ['name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'],
  114. [
  115. 'name' => 'lastname',
  116. 'index' => 'lastname',
  117. 'width' => '50',
  118. 'align' => 'left',
  119. 'formatter' => 'action_formatter',
  120. 'search' => 'true',
  121. ],
  122. [
  123. 'name' => 'login',
  124. 'index' => 'username',
  125. 'width' => '40',
  126. 'align' => 'left',
  127. 'search' => 'true',
  128. 'hidden' => 'true',
  129. ],
  130. ];
  131. if (!empty($extraFields) && isset($extraFields['fields'])) {
  132. $extraField = new ExtraField('user');
  133. foreach ($extraFields['fields'] as $variable) {
  134. $columnModel[] = [
  135. 'name' => $variable,
  136. 'index' => $variable,
  137. 'width' => '40',
  138. 'align' => 'left',
  139. 'search' => 'false',
  140. ];
  141. }
  142. }
  143. $columnModel[] = [
  144. 'name' => 'session',
  145. 'index' => 'session',
  146. 'width' => '40',
  147. 'align' => 'left',
  148. 'search' => 'false',
  149. ];
  150. $columnModel[] = [
  151. 'name' => 'session_access_start_date',
  152. 'index' => 'session_access_start_date',
  153. 'width' => '50',
  154. 'align' => 'center',
  155. 'search' => 'true',
  156. ];
  157. $columnModel[] = [
  158. 'name' => 'exe_date',
  159. 'index' => 'exe_date',
  160. 'width' => '60',
  161. 'align' => 'left',
  162. 'search' => 'true',
  163. ];
  164. $columnModel[] = [
  165. 'name' => 'score',
  166. 'index' => 'exe_result',
  167. 'width' => '50',
  168. 'align' => 'center',
  169. 'search' => 'true',
  170. ];
  171. if (!empty($categoryList)) {
  172. foreach ($categoryList as $categoryInfo) {
  173. $columnModel[] = [
  174. 'name' => 'category_'.$categoryInfo['id'],
  175. 'index' => 'category_'.$categoryInfo['id'],
  176. 'width' => '50',
  177. 'align' => 'center',
  178. 'search' => 'true',
  179. ];
  180. }
  181. }
  182. $columnModel[] = [
  183. 'name' => 'actions',
  184. 'index' => 'actions',
  185. 'width' => '60',
  186. 'align' => 'left',
  187. 'search' => 'false',
  188. 'sortable' => 'false',
  189. 'hidden' => 'true',
  190. ];
  191. $extra_params['autowidth'] = 'true';
  192. //height auto
  193. $extra_params['height'] = 'auto';
  194. $actionLinks = '
  195. // add username as title in lastname filed - ref 4226
  196. function action_formatter(cellvalue, options, rowObject) {
  197. // rowObject is firstname,lastname,login,... get the third word
  198. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  199. var tabLoginx = loginx.split(/:::/);
  200. // tabLoginx[0] is before and tabLoginx[1] is after :::
  201. // may be empty string but is defined
  202. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  203. }';
  204. $tableId = 'results'; ?>
  205. <script>
  206. $(function() {
  207. <?php
  208. echo Display::grid_js(
  209. 'results',
  210. $url,
  211. $columns,
  212. $columnModel,
  213. $extra_params,
  214. [],
  215. $actionLinks,
  216. true
  217. ); ?>
  218. });
  219. </script>
  220. <?php
  221. echo '<script>
  222. $(function() {
  223. var myUrl = jQuery("#'.$tableId.'").jqGrid(\'getGridParam\', \'url\');
  224. myUrl += "&export_format=xls&oper=excel";
  225. var postData = jQuery("#'.$tableId.'").jqGrid(\'getGridParam\', \'postData\');
  226. $.each(postData, function(key, value) {
  227. myUrl += "&"+key+"="+encodeURIComponent(value);
  228. });
  229. $("#excel_export").attr("href", myUrl);
  230. jQuery("#'.$tableId.'").jqGrid(
  231. "navGrid",
  232. "#'.$tableId.'_pager",
  233. {
  234. view:false, edit:false, add:false, del:false, search:false, excel:true
  235. }
  236. );
  237. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  238. caption: "",
  239. title:"'.get_lang('ExportExcel').'",
  240. onClickButton : function() {
  241. jQuery("#'.$tableId.'").jqGrid(
  242. "excelExport",{
  243. "url":"'.$url.'&export_format=xls"
  244. }
  245. );
  246. }
  247. });
  248. });
  249. </script>';
  250. $items = [
  251. [
  252. 'url' => ' ',
  253. 'url_attributes' => ['id' => 'excel_export'],
  254. 'content' => Display::return_icon('export_excel.png', get_lang('ExportExcel')),
  255. ],
  256. ];
  257. echo Display::actions($items);
  258. echo Display::grid_html('results');
  259. }
  260. Display::display_footer();