hotpotatoes_exercise_report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. use ChamiloSession as Session;
  10. // name of the language file that needs to be included
  11. $language_file = array('exercice');
  12. // including the global library
  13. require_once '../inc/global.inc.php';
  14. require_once '../gradebook/lib/be.inc.php';
  15. // Setting the tabs
  16. $this_section = SECTION_COURSES;
  17. $htmlHeadXtra[] = api_get_jqgrid_js();
  18. // Access control
  19. api_protect_course_script(true, false, true);
  20. // including additional libraries
  21. require_once 'exercise.class.php';
  22. require_once 'exercise.lib.php';
  23. require_once 'question.class.php';
  24. require_once 'answer.class.php';
  25. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  26. require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
  27. require_once 'hotpotatoes.lib.php';
  28. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  29. // need functions of statsutils lib to display previous exercices scores
  30. require_once api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php';
  31. // document path
  32. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  33. /* Constants and variables */
  34. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh();
  35. $is_tutor = api_is_allowed_to_edit(true);
  36. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  37. $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  38. $TBL_TRACK_HOTPOTATOES_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  39. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  40. $course_id = api_get_course_int_id();
  41. $hotpotatoes_path = isset($_REQUEST['path']) ? $_REQUEST['path'] : null;
  42. $filter_user = isset($_REQUEST['filter_by_user']) ? intval($_REQUEST['filter_by_user']) : null;
  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. $origin = isset($origin) ? $origin : null;
  53. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  54. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  55. $load_extra_data = false;
  56. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  57. $load_extra_data = true;
  58. }
  59. require_once 'hotpotatoes_exercise_result.class.php';
  60. $export = new HotpotatoesExerciseResult();
  61. $export->exportCompleteReportCSV($documentPath, $hotpotatoes_path);
  62. exit;
  63. } else {
  64. api_not_allowed(true);
  65. }
  66. }
  67. $actions = null;
  68. if ($is_allowedToEdit && $origin != 'learnpath') {
  69. // the form
  70. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
  71. $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>';
  72. }
  73. } else {
  74. $actions .= '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
  75. }
  76. if ($is_allowedToEdit) {
  77. $action = isset($_GET['action']) ? $_GET['action'] : null;
  78. switch ($action) {
  79. case 'delete':
  80. $fileToDelete = isset($_GET['id']) ? $_GET['id'] : null;
  81. deleteAttempt($fileToDelete);
  82. Session::write('message', Display::return_message(get_lang('ItemDeleted')));
  83. $url = api_get_self().'?'.api_get_cidreq().'&path='.$hotpotatoes_path;
  84. header("Location: $url");
  85. exit;
  86. break;
  87. }
  88. }
  89. $nameTools = get_lang('Results');
  90. if ($is_allowedToEdit || $is_tutor) {
  91. $nameTools = get_lang('StudentScore');
  92. $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
  93. $objExerciseTmp = new Exercise();
  94. /*if ($objExerciseTmp->read($exercise_id)) {
  95. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name);
  96. }*/
  97. } else {
  98. $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
  99. $objExerciseTmp = new Exercise();
  100. /*if ($objExerciseTmp->read($exercise_id)) {
  101. $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
  102. }*/
  103. }
  104. Display :: display_header($nameTools);
  105. $actions = Display::div($actions, array('class'=> 'actions'));
  106. $extra = '<script type="text/javascript">
  107. $(document).ready(function() {
  108. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  109. $( "#dialog-confirm" ).dialog({
  110. autoOpen: false,
  111. show: "blind",
  112. resizable: false,
  113. height:300,
  114. modal: true
  115. });
  116. $("#export_opener").click(function() {
  117. var targetUrl = $(this).attr("href");
  118. $( "#dialog-confirm" ).dialog({
  119. width:400,
  120. height:300,
  121. buttons: {
  122. "'.addslashes(get_lang('Download')).'": function() {
  123. var export_format = $("input[name=export_format]:checked").val();
  124. var extra_data = $("input[name=load_extra_data]:checked").val();
  125. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
  126. $( this ).dialog( "close" );
  127. },
  128. }
  129. });
  130. $( "#dialog-confirm" ).dialog("open");
  131. return false;
  132. });
  133. });
  134. </script>';
  135. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  136. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  137. $form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
  138. //$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  139. //$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  140. $form->setDefaults(array('export_format' => 'csv'));
  141. $extra .= $form->return_form();
  142. $extra .= '</div>';
  143. if ($is_allowedToEdit) {
  144. echo $extra;
  145. }
  146. echo $actions;
  147. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_hotpotatoes_exercise_results&path='.$hotpotatoes_path.'&filter_by_user='.$filter_user;
  148. $action_links = '';
  149. // Generating group list
  150. $group_list = GroupManager::get_group_list();
  151. $group_parameters = array('group_all:'.get_lang('All'),'group_none:'.get_lang('None'));
  152. foreach ($group_list as $group) {
  153. $group_parameters[] = $group['id'].':'.$group['name'];
  154. }
  155. if (!empty($group_parameters)) {
  156. $group_parameters = implode(';', $group_parameters);
  157. }
  158. if ($is_allowedToEdit || $is_tutor) {
  159. // The order is important you need to check the the $column variable in the model.ajax.php file
  160. $columns = array(
  161. get_lang('FirstName'),
  162. get_lang('LastName'),
  163. get_lang('LoginName'),
  164. get_lang('Group'),
  165. get_lang('StartDate'),
  166. get_lang('Score'),
  167. get_lang('Actions')
  168. );
  169. // Column config
  170. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  171. $column_model = array(
  172. array('name'=>'firstname', 'index'=>'firstname', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
  173. array('name'=>'lastname', 'index'=>'lastname', 'width'=>'50', 'align'=>'left', 'formatter'=>'action_formatter', 'search' => 'false'),
  174. array('name'=>'login', 'hidden'=>'true', 'index'=>'username', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
  175. array('name'=>'group_name', 'index'=>'group_id', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
  176. array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'false'),
  177. array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
  178. array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false')
  179. );
  180. $action_links = '
  181. // add username as title in lastname filed - ref 4226
  182. function action_formatter(cellvalue, options, rowObject) {
  183. // rowObject is firstname,lastname,login,... get the third word
  184. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  185. var tabLoginx = loginx.split(/:::/);
  186. // tabLoginx[0] is before and tabLoginx[1] is after :::
  187. // may be empty string but is defined
  188. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  189. }';
  190. } else {
  191. //The order is important you need to check the the $column variable in the model.ajax.php file
  192. $columns = array(
  193. get_lang('StartDate'),
  194. get_lang('Score'),
  195. get_lang('Actions')
  196. );
  197. //Column config
  198. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  199. $column_model = array(
  200. array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'false'),
  201. array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
  202. array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false')
  203. );
  204. }
  205. //Autowidth
  206. $extra_params['autowidth'] = 'true';
  207. //height auto
  208. $extra_params['height'] = 'auto';
  209. ?>
  210. <script>
  211. function setSearchSelect(columnName) {
  212. $("#results").jqGrid('setColProp', columnName,
  213. {
  214. searchoptions:{
  215. dataInit:function(el){
  216. $("option[value='1']",el).attr("selected", "selected");
  217. setTimeout(function(){
  218. $(el).trigger('change');
  219. },1000);
  220. }
  221. }
  222. });
  223. }
  224. function exportExcel() {
  225. var mya=new Array();
  226. mya=$("#results").getDataIDs(); // Get All IDs
  227. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  228. var colNames=new Array();
  229. var ii=0;
  230. for (var i in data){colNames[ii++]=i;} // capture col names
  231. var html="";
  232. for(i=0;i<mya.length;i++) {
  233. data=$("#results").getRowData(mya[i]); // get each row
  234. for(j=0;j<colNames.length;j++) {
  235. html=html+data[colNames[j]]+","; // output each column as tab delimited
  236. }
  237. html=html+"\n"; // output each row with end of line
  238. }
  239. html = html+"\n"; // end of line at the end
  240. var form = $("#export_report_form");
  241. $("#csvBuffer").attr('value', html);
  242. form.target='_blank';
  243. form.submit();
  244. }
  245. $(function() {
  246. <?php
  247. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  248. if ($is_allowedToEdit || $is_tutor) { ?>
  249. //setSearchSelect("status");
  250. //
  251. //view:true, del:false, add:false, edit:false, excel:true}
  252. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  253. {height:280, reloadAfterSubmit:false}, // view options
  254. {height:280, reloadAfterSubmit:false}, // edit options
  255. {height:280, reloadAfterSubmit:false}, // add options
  256. {reloadAfterSubmit: false}, // del options
  257. {width:500} // search options
  258. );
  259. //Adding search options
  260. var options = {
  261. 'stringResult': true,
  262. 'autosearch' : true,
  263. 'searchOnEnter':false
  264. }
  265. jQuery("#results").jqGrid('filterToolbar',options);
  266. var sgrid = $("#results")[0];
  267. sgrid.triggerToolbar();
  268. <?php } ?>
  269. });
  270. </script>
  271. <form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php">
  272. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  273. <input type="hidden" name="export_report" id="export_report" value="1" />
  274. <input type="hidden" name="path" id="path" value="<?php echo $hotpotatoes_path ?>" />
  275. </form>
  276. <?php
  277. $showMessage = Session::read('message');
  278. Session::erase('message');
  279. echo isset($showMessage) ? $showMessage : null;
  280. echo Display::grid_html('results');
  281. Display :: display_footer();