hotpotatoes_exercise_report.php 19 KB

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