hotpotatoes_exercise_report.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise list: This script shows the list of exercises for administrators and students.
  5. * @package chamilo.exercise
  6. * @author hubert.borderiou
  7. *
  8. */
  9. /**
  10. * Code
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = array('exercice');
  14. // including the global library
  15. require_once '../inc/global.inc.php';
  16. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be.inc.php';
  17. // Setting the tabs
  18. $this_section = SECTION_COURSES;
  19. $htmlHeadXtra[] = api_get_jqgrid_js();
  20. // Access control
  21. api_protect_course_script(true, false, true);
  22. // including additional libraries
  23. require_once 'exercise.class.php';
  24. require_once 'question.class.php';
  25. require_once 'answer.class.php';
  26. require_once 'hotpotatoes.lib.php';
  27. // need functions of statsutils lib to display previous exercices scores
  28. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  29. // document path
  30. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  31. /* Constants and variables */
  32. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh();
  33. $is_tutor = api_is_allowed_to_edit(true);
  34. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  35. $TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  36. $TBL_TRACK_HOTPOTATOES_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  37. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  38. $course_id = api_get_course_int_id();
  39. $hotpotatoes_path = isset($_REQUEST['path']) ? $_REQUEST['path'] : null;
  40. $filter_user = isset($_REQUEST['filter_by_user']) ? intval($_REQUEST['filter_by_user']) : null;
  41. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  42. if (empty($hotpotatoes_path)) {
  43. api_not_allowed();
  44. }
  45. if (!$is_allowedToEdit) {
  46. // api_not_allowed();
  47. }
  48. if (!empty($_REQUEST['path'])) {
  49. $parameters['path'] = Security::remove_XSS($_REQUEST['path']);
  50. }
  51. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  52. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  53. $load_extra_data = false;
  54. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  55. $load_extra_data = true;
  56. }
  57. require_once 'hotpotatoes_exercise_result.class.php';
  58. // @todo make xls export work
  59. // switch ($_GET['export_format']) {
  60. // case 'xls' :
  61. // $export = new ExerciseResult();
  62. // $export->exportCompleteReportXLS($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']);
  63. // exit;
  64. // break;
  65. // case 'csv' :
  66. // default :
  67. $export = new HotpotatoesExerciseResult();
  68. $export->exportCompleteReportCSV($documentPath, $hotpotatoes_path);
  69. exit;
  70. // break;
  71. // }
  72. } else {
  73. api_not_allowed(true);
  74. }
  75. }
  76. //Send student email @todo move this code in a class, library
  77. //if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
  78. // $id = intval($_GET['exeid']); //filtered by post-condition
  79. // $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  80. // if (empty($track_exercise_info)) {
  81. // api_not_allowed();
  82. // }
  83. // $test = $track_exercise_info['title'];
  84. // $student_id = $track_exercise_info['exe_user_id'];
  85. //
  86. // $session_id = $track_exercise_info['session_id'];
  87. // $lp_id = $track_exercise_info['orig_lp_id'];
  88. // //$lp_item_id = $track_exercise_info['orig_lp_item_id'];
  89. // $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  90. //
  91. // // Teacher data
  92. // $teacher_info = api_get_user_info(api_get_user_id());
  93. // $user_info = api_get_user_info($student_id);
  94. // $student_email = $user_info['mail'];
  95. // $from = $teacher_info['mail'];
  96. // $from_name = api_get_person_name($teacher_info['firstname'], $teacher_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
  97. //
  98. // $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&id_session='.$session_id.'&exerciseId='.$exercise_id;
  99. //
  100. // $my_post_info = array();
  101. // $post_content_id = array();
  102. // $comments_exist = false;
  103. //
  104. // foreach ($_POST as $key_index => $key_value) {
  105. // $my_post_info = explode('_',$key_index);
  106. // $post_content_id[]=$my_post_info[1];
  107. // if ($my_post_info[0]=='comments') {
  108. // $comments_exist=true;
  109. // }
  110. // }
  111. //
  112. // $loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST);
  113. //
  114. // $array_content_id_exe=array();
  115. // if ($comments_exist===true) {
  116. // $array_content_id_exe = array_slice($post_content_id,$loop_in_track);
  117. // } else {
  118. // $array_content_id_exe = $post_content_id;
  119. // }
  120. //
  121. // for ($i=0;$i<$loop_in_track;$i++) {
  122. // $my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]);
  123. // $contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  124. // if (isset($contain_comments)) {
  125. // $my_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
  126. // } else {
  127. // $my_comments = '';
  128. // }
  129. // $my_questionid = intval($array_content_id_exe[$i]);
  130. // $sql = "SELECT question from $TBL_QUESTIONS WHERE c_id = $course_id AND id = '$my_questionid'";
  131. // $result =Database::query($sql);
  132. // Database::result($result,0,"question");
  133. //
  134. // $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = ".$my_questionid." AND exe_id=".$id;
  135. // Database::query($query);
  136. //
  137. // //Saving results in the track recording table
  138. // $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment)
  139. // VALUES ('."'$id','".$my_questionid."','$my_marks','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$my_comments.'")';
  140. // Database::query($recording_changes);
  141. // }
  142. //
  143. // $qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = '.$id .' GROUP BY question_id';
  144. // $res = Database::query($qry);
  145. // $tot = 0;
  146. // while ($row = Database :: fetch_array($res, 'ASSOC')) {
  147. // $tot += $row['marks'];
  148. // }
  149. //
  150. // $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id;
  151. // Database::query($totquery);
  152. //
  153. // //@todo move this somewhere else
  154. // $subject = get_lang('ExamSheetVCC');
  155. //
  156. // $message = '<p>'.get_lang('DearStudentEmailIntroduction') . '</p><p>'.get_lang('AttemptVCC');
  157. // $message .= '<h3>'.get_lang('CourseName'). '</h3><p>'.Security::remove_XSS($course_info['name']).'';
  158. // $message .= '<h3>'.get_lang('Exercise') . '</h3><p>'.Security::remove_XSS($test);
  159. //
  160. // //Only for exercises not in a LP
  161. // if ($lp_id == 0) {
  162. // $message .= '<p>'.get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />';
  163. // }
  164. //
  165. // $message .= '<p>'.get_lang('Regards').'</p>';
  166. // $message .= $from_name;
  167. //
  168. // $message = str_replace("#test#", Security::remove_XSS($test), $message);
  169. // $message = str_replace("#url#", $url, $message);
  170. //
  171. // @api_mail_html($student_email, $student_email, $subject, $message, $from_name, $from, array('charset'=>api_get_system_encoding()));
  172. //
  173. // //Updating LP score here
  174. // if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) {
  175. // $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . floatval($tot) . "' WHERE c_id = ".$course_id." AND id = " .$lp_item_view_id;
  176. // Database::query($sql_update_score);
  177. // if ($origin == 'tracking_course') {
  178. // //Redirect to the course detail in lp
  179. // header('location: exercice.php?course=' . Security :: remove_XSS($_GET['course']));
  180. // exit;
  181. // } else {
  182. // //Redirect to the reporting
  183. // header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id);
  184. // exit;
  185. // }
  186. // }
  187. //}
  188. if ($is_allowedToEdit && $origin != 'learnpath') {
  189. // the form
  190. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  191. $actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">'.Display :: return_icon(
  192. 'back.png',
  193. get_lang('GoBackToQuestionList'),
  194. '',
  195. ICON_SIZE_MEDIUM
  196. ).'</a>';
  197. $actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&path='.Security::remove_XSS(
  198. $hotpotatoes_path
  199. ).' ">'.Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
  200. }
  201. } else {
  202. $actions .= '<a href="exercice.php">'.Display :: return_icon(
  203. 'back.png',
  204. get_lang('GoBackToQuestionList'),
  205. '',
  206. ICON_SIZE_MEDIUM
  207. ).'</a>';
  208. }
  209. //Deleting an attempt
  210. //if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false) {
  211. // $exe_id = intval($_GET['did']);
  212. // if (!empty($exe_id)) {
  213. // $sql = 'DELETE FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$exe_id;
  214. // Database::query($sql);
  215. // $sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
  216. // Database::query($sql);
  217. // header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId='.$exercise_id);
  218. // exit;
  219. // }
  220. //}
  221. if ($is_allowedToEdit || $is_tutor) {
  222. $nameTools = get_lang('StudentScore');
  223. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  224. $objExerciseTmp = new Exercise();
  225. if ($objExerciseTmp->read($exercise_id)) {
  226. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name);
  227. }
  228. } else {
  229. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  230. $objExerciseTmp = new Exercise();
  231. if ($objExerciseTmp->read($exercise_id)) {
  232. $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
  233. }
  234. }
  235. Display :: display_header($nameTools);
  236. $actions = Display::div($actions, array('class' => 'actions'));
  237. $extra = '<script type="text/javascript">
  238. $(document).ready(function() {
  239. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  240. $( "#dialog-confirm" ).dialog({
  241. autoOpen: false,
  242. show: "blind",
  243. resizable: false,
  244. height:300,
  245. modal: true
  246. });
  247. $("#export_opener").click(function() {
  248. var targetUrl = $(this).attr("href");
  249. $( "#dialog-confirm" ).dialog({
  250. width:400,
  251. height:300,
  252. buttons: {
  253. "'.addslashes(get_lang('Download')).'": function() {
  254. var export_format = $("input[name=export_format]:checked").val();
  255. var extra_data = $("input[name=load_extra_data]:checked").val();
  256. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
  257. $( this ).dialog( "close" );
  258. },
  259. }
  260. });
  261. $( "#dialog-confirm" ).dialog("open");
  262. return false;
  263. });
  264. });
  265. </script>';
  266. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  267. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  268. $form->addElement(
  269. 'radio',
  270. 'export_format',
  271. null,
  272. get_lang('ExportAsCSV'),
  273. 'csv',
  274. array('id' => 'export_format_csv_label')
  275. );
  276. //$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  277. //$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  278. $form->setDefaults(array('export_format' => 'csv'));
  279. $extra .= $form->return_form();
  280. $extra .= '</div>';
  281. if ($is_allowedToEdit) {
  282. echo $extra;
  283. }
  284. echo $actions;
  285. $url = api_get_path(
  286. WEB_AJAX_PATH
  287. ).'model.ajax.php?a=get_hotpotatoes_exercise_results&path='.$hotpotatoes_path.'&filter_by_user='.$filter_user;
  288. //$activeurl = '?sidx=session_active';
  289. $action_links = '';
  290. //Generating group list
  291. $group_list = GroupManager::get_group_list();
  292. $group_parameters = array('group_all:'.get_lang('All'), 'group_none:'.get_lang('None'));
  293. foreach ($group_list as $group) {
  294. $group_parameters[] = $group['id'].':'.$group['name'];
  295. }
  296. if (!empty($group_parameters)) {
  297. $group_parameters = implode(';', $group_parameters);
  298. }
  299. if ($is_allowedToEdit || $is_tutor) {
  300. //The order is important you need to check the the $column variable in the model.ajax.php file
  301. $columns = array(
  302. get_lang('FirstName'),
  303. get_lang('LastName'),
  304. get_lang('LoginName'),
  305. get_lang('Group'),
  306. get_lang('StartDate'),
  307. get_lang('Score'),
  308. get_lang('Actions')
  309. );
  310. //Column config
  311. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  312. $column_model = array(
  313. array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  314. array(
  315. 'name' => 'lastname',
  316. 'index' => 'lastname',
  317. 'width' => '50',
  318. 'align' => 'left',
  319. 'formatter' => 'action_formatter',
  320. 'search' => 'false'
  321. ),
  322. array(
  323. 'name' => 'login',
  324. 'hidden' => 'true',
  325. 'index' => 'username',
  326. 'width' => '40',
  327. 'align' => 'left',
  328. 'search' => 'false'
  329. ),
  330. array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'),
  331. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  332. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  333. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false')
  334. );
  335. $action_links = '
  336. // add username as title in lastname filed - ref 4226
  337. function action_formatter(cellvalue, options, rowObject) {
  338. // rowObject is firstname,lastname,login,... get the third word
  339. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  340. var tabLoginx = loginx.split(/:::/);
  341. // tabLoginx[0] is before and tabLoginx[1] is after :::
  342. // may be empty string but is defined
  343. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  344. }';
  345. } else {
  346. //The order is important you need to check the the $column variable in the model.ajax.php file
  347. $columns = array(get_lang('StartDate'), get_lang('Score'), get_lang('Actions'));
  348. //Column config
  349. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  350. $column_model = array(
  351. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  352. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  353. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false')
  354. );
  355. }
  356. //Autowidth
  357. $extra_params['autowidth'] = 'true';
  358. //height auto
  359. $extra_params['height'] = 'auto';
  360. //$extra_params['excel'] = 'excel';
  361. //$extra_params['rowList'] = array(20, 50, 100, 500, 1000, 2000, 5000, 10000);
  362. ?>
  363. <script>
  364. function setSearchSelect(columnName) {
  365. $("#results").jqGrid('setColProp', columnName,
  366. {
  367. searchoptions:{
  368. dataInit:function (el) {
  369. $("option[value='1']", el).attr("selected", "selected");
  370. setTimeout(function () {
  371. $(el).trigger('change');
  372. }, 1000);
  373. }
  374. }
  375. });
  376. }
  377. function exportExcel() {
  378. var mya = new Array();
  379. mya = $("#results").getDataIDs(); // Get All IDs
  380. var data = $("#results").getRowData(mya[0]); // Get First row to get the labels
  381. var colNames = new Array();
  382. var ii = 0;
  383. for (var i in data) {
  384. colNames[ii++] = i;
  385. } // capture col names
  386. var html = "";
  387. for (i = 0; i < mya.length; i++) {
  388. data = $("#results").getRowData(mya[i]); // get each row
  389. for (j = 0; j < colNames.length; j++) {
  390. html = html + data[colNames[j]] + ","; // output each column as tab delimited
  391. }
  392. html = html + "\n"; // output each row with end of line
  393. }
  394. html = html + "\n"; // end of line at the end
  395. var form = $("#export_report_form");
  396. $("#csvBuffer").attr('value', html);
  397. form.target = '_blank';
  398. form.submit();
  399. }
  400. $(function () {
  401. <?php
  402. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  403. if ($is_allowedToEdit || $is_tutor) {
  404. ?>
  405. //setSearchSelect("status");
  406. //
  407. //view:true, del:false, add:false, edit:false, excel:true}
  408. $("#results").jqGrid('navGrid', '#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  409. {height:280, reloadAfterSubmit:false}, // view options
  410. {height:280, reloadAfterSubmit:false}, // edit options
  411. {height:280, reloadAfterSubmit:false}, // add options
  412. {reloadAfterSubmit:false}, // del options
  413. {width:500} // search options
  414. );
  415. //Adding search options
  416. var options = {
  417. 'stringResult':true,
  418. 'autosearch':true,
  419. 'searchOnEnter':false
  420. }
  421. jQuery("#results").jqGrid('filterToolbar', options);
  422. var sgrid = $("#results")[0];
  423. sgrid.triggerToolbar();
  424. <?php } ?>
  425. });
  426. </script>
  427. <form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php">
  428. <input type="hidden" name="csvBuffer" id="csvBuffer" value=""/>
  429. <input type="hidden" name="export_report" id="export_report" value="1"/>
  430. <input type="hidden" name="path" id="path" value="<?php echo $hotpotatoes_path ?>"/>
  431. </form>
  432. <?php
  433. echo Display::grid_html('results');
  434. Display :: display_footer();