hotpotatoes_exercise_report.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. *
  6. * @package chamilo.exercise
  7. *
  8. * @author hubert.borderiou
  9. */
  10. require_once __DIR__.'/../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_session_general_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_session_general_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. Display::addFlash(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[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')];
  83. $objExerciseTmp = new Exercise();
  84. } else {
  85. $interbreadcrumb[] = ["url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises')];
  86. $objExerciseTmp = new Exercise();
  87. }
  88. Display :: display_header($nameTools);
  89. $actions = Display::div($actions, ['class' => 'actions']);
  90. $extra = '<script>
  91. $(function() {
  92. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  93. $( "#dialog-confirm" ).dialog({
  94. autoOpen: false,
  95. show: "blind",
  96. resizable: false,
  97. height:300,
  98. modal: true
  99. });
  100. $("#export_opener").click(function() {
  101. var targetUrl = $(this).attr("href");
  102. $( "#dialog-confirm" ).dialog({
  103. width:400,
  104. height:300,
  105. buttons: {
  106. "'.addslashes(get_lang('Download')).'": function() {
  107. var export_format = $("input[name=export_format]:checked").val();
  108. var extra_data = $("input[name=load_extra_data]:checked").val();
  109. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
  110. $( this ).dialog( "close" );
  111. }
  112. }
  113. });
  114. $( "#dialog-confirm" ).dialog("open");
  115. return false;
  116. });
  117. });
  118. </script>';
  119. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  120. $form = new FormValidator('report', 'post', null, null, ['class' => 'form-vertical']);
  121. $form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', ['id' => 'export_format_csv_label']);
  122. //$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  123. //$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  124. $form->setDefaults(['export_format' => 'csv']);
  125. $extra .= $form->returnForm();
  126. $extra .= '</div>';
  127. if ($is_allowedToEdit) {
  128. echo $extra;
  129. }
  130. echo $actions;
  131. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_hotpotatoes_exercise_results&path='.$hotpotatoes_path.'&filter_by_user='.$filter_user;
  132. $action_links = '';
  133. // Generating group list
  134. $group_list = GroupManager::get_group_list();
  135. $group_parameters = ['group_all:'.get_lang('All'), 'group_none:'.get_lang('None')];
  136. foreach ($group_list as $group) {
  137. $group_parameters[] = $group['id'].':'.$group['name'];
  138. }
  139. if (!empty($group_parameters)) {
  140. $group_parameters = implode(';', $group_parameters);
  141. }
  142. if ($is_allowedToEdit || $is_tutor) {
  143. // The order is important you need to check the the $column variable in the model.ajax.php file
  144. $columns = [
  145. get_lang('FirstName'),
  146. get_lang('LastName'),
  147. get_lang('LoginName'),
  148. get_lang('Group'),
  149. get_lang('StartDate'),
  150. get_lang('Score'),
  151. get_lang('Actions'),
  152. ];
  153. // Column config
  154. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  155. $column_model = [
  156. ['name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'false'],
  157. [
  158. 'name' => 'lastname',
  159. 'index' => 'lastname',
  160. 'width' => '50',
  161. 'align' => 'left',
  162. 'formatter' => 'action_formatter',
  163. 'search' => 'false',
  164. ],
  165. [
  166. 'name' => 'login',
  167. 'hidden' => 'true',
  168. 'index' => 'username',
  169. 'width' => '40',
  170. 'align' => 'left',
  171. 'search' => 'false',
  172. ],
  173. ['name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'],
  174. ['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'],
  175. ['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'],
  176. ['name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'],
  177. ];
  178. $action_links = '
  179. // add username as title in lastname filed - ref 4226
  180. function action_formatter(cellvalue, options, rowObject) {
  181. // rowObject is firstname,lastname,login,... get the third word
  182. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  183. var tabLoginx = loginx.split(/:::/);
  184. // tabLoginx[0] is before and tabLoginx[1] is after :::
  185. // may be empty string but is defined
  186. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  187. }';
  188. } else {
  189. //The order is important you need to check the the $column variable in the model.ajax.php file
  190. $columns = [
  191. get_lang('StartDate'),
  192. get_lang('Score'),
  193. get_lang('Actions'),
  194. ];
  195. //Column config
  196. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  197. $column_model = [
  198. ['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'],
  199. ['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'],
  200. ['name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'],
  201. ];
  202. }
  203. //Autowidth
  204. $extra_params['autowidth'] = 'true';
  205. //height auto
  206. $extra_params['height'] = 'auto';
  207. ?>
  208. <script>
  209. function setSearchSelect(columnName) {
  210. $("#results").jqGrid('setColProp', columnName,
  211. {
  212. searchoptions:{
  213. dataInit:function(el){
  214. $("option[value='1']",el).attr("selected", "selected");
  215. setTimeout(function(){
  216. $(el).trigger('change');
  217. },1000);
  218. }
  219. }
  220. });
  221. }
  222. function exportExcel() {
  223. var mya=new Array();
  224. mya=$("#results").getDataIDs(); // Get All IDs
  225. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  226. var colNames=new Array();
  227. var ii=0;
  228. for (var i in data){colNames[ii++]=i;} // capture col names
  229. var html="";
  230. for(i=0;i<mya.length;i++) {
  231. data=$("#results").getRowData(mya[i]); // get each row
  232. for(j=0;j<colNames.length;j++) {
  233. html=html+data[colNames[j]]+","; // output each column as tab delimited
  234. }
  235. html=html+"\n"; // output each row with end of line
  236. }
  237. html = html+"\n"; // end of line at the end
  238. var form = $("#export_report_form");
  239. $("#csvBuffer").attr('value', html);
  240. form.target='_blank';
  241. form.submit();
  242. }
  243. $(function() {
  244. <?php
  245. echo Display::grid_js(
  246. 'results',
  247. $url,
  248. $columns,
  249. $column_model,
  250. $extra_params,
  251. [],
  252. $action_links,
  253. true
  254. );
  255. if ($is_allowedToEdit || $is_tutor) {
  256. ?>
  257. //setSearchSelect("status");
  258. //
  259. //view:true, del:false, add:false, edit:false, excel:true}
  260. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  261. {height:280, reloadAfterSubmit:false}, // view options
  262. {height:280, reloadAfterSubmit:false}, // edit options
  263. {height:280, reloadAfterSubmit:false}, // add options
  264. {reloadAfterSubmit: false}, // del options
  265. {width:500} // search options
  266. );
  267. //Adding search options
  268. var options = {
  269. 'stringResult': true,
  270. 'autosearch' : true,
  271. 'searchOnEnter':false
  272. }
  273. jQuery("#results").jqGrid('filterToolbar',options);
  274. var sgrid = $("#results")[0];
  275. sgrid.triggerToolbar();
  276. <?php
  277. } ?>
  278. });
  279. </script>
  280. <form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php?<?php echo api_get_cidreq(); ?>">
  281. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  282. <input type="hidden" name="export_report" id="export_report" value="1" />
  283. <input type="hidden" name="path" id="path" value="<?php echo $hotpotatoes_path; ?>" />
  284. </form>
  285. <?php
  286. echo Display::grid_html('results');
  287. Display :: display_footer();