hotpotatoes_exercise_report.php 12 KB

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