hotpotatoes_exercise_report.php 19 KB

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