hotpotatoes_exercise_report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 __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_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. 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[] = 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>
  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(
  164. 'name' => 'lastname',
  165. 'index' => 'lastname',
  166. 'width' => '50',
  167. 'align' => 'left',
  168. 'formatter' => 'action_formatter',
  169. 'search' => 'false',
  170. ),
  171. array(
  172. 'name' => 'login',
  173. 'hidden' => 'true',
  174. 'index' => 'username',
  175. 'width' => '40',
  176. 'align' => 'left',
  177. 'search' => 'false',
  178. ),
  179. array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'false'),
  180. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  181. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  182. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  183. );
  184. $action_links = '
  185. // add username as title in lastname filed - ref 4226
  186. function action_formatter(cellvalue, options, rowObject) {
  187. // rowObject is firstname,lastname,login,... get the third word
  188. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  189. var tabLoginx = loginx.split(/:::/);
  190. // tabLoginx[0] is before and tabLoginx[1] is after :::
  191. // may be empty string but is defined
  192. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  193. }';
  194. } else {
  195. //The order is important you need to check the the $column variable in the model.ajax.php file
  196. $columns = array(
  197. get_lang('StartDate'),
  198. get_lang('Score'),
  199. get_lang('Actions')
  200. );
  201. //Column config
  202. // @todo fix search firstname/lastname that doesn't work. rmove search for the moment
  203. $column_model = array(
  204. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  205. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  206. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  207. );
  208. }
  209. //Autowidth
  210. $extra_params['autowidth'] = 'true';
  211. //height auto
  212. $extra_params['height'] = 'auto';
  213. ?>
  214. <script>
  215. function setSearchSelect(columnName) {
  216. $("#results").jqGrid('setColProp', columnName,
  217. {
  218. searchoptions:{
  219. dataInit:function(el){
  220. $("option[value='1']",el).attr("selected", "selected");
  221. setTimeout(function(){
  222. $(el).trigger('change');
  223. },1000);
  224. }
  225. }
  226. });
  227. }
  228. function exportExcel() {
  229. var mya=new Array();
  230. mya=$("#results").getDataIDs(); // Get All IDs
  231. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  232. var colNames=new Array();
  233. var ii=0;
  234. for (var i in data){colNames[ii++]=i;} // capture col names
  235. var html="";
  236. for(i=0;i<mya.length;i++) {
  237. data=$("#results").getRowData(mya[i]); // get each row
  238. for(j=0;j<colNames.length;j++) {
  239. html=html+data[colNames[j]]+","; // output each column as tab delimited
  240. }
  241. html=html+"\n"; // output each row with end of line
  242. }
  243. html = html+"\n"; // end of line at the end
  244. var form = $("#export_report_form");
  245. $("#csvBuffer").attr('value', html);
  246. form.target='_blank';
  247. form.submit();
  248. }
  249. $(function() {
  250. <?php
  251. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  252. if ($is_allowedToEdit || $is_tutor) { ?>
  253. //setSearchSelect("status");
  254. //
  255. //view:true, del:false, add:false, edit:false, excel:true}
  256. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  257. {height:280, reloadAfterSubmit:false}, // view options
  258. {height:280, reloadAfterSubmit:false}, // edit options
  259. {height:280, reloadAfterSubmit:false}, // add options
  260. {reloadAfterSubmit: false}, // del options
  261. {width:500} // search options
  262. );
  263. //Adding search options
  264. var options = {
  265. 'stringResult': true,
  266. 'autosearch' : true,
  267. 'searchOnEnter':false
  268. }
  269. jQuery("#results").jqGrid('filterToolbar',options);
  270. var sgrid = $("#results")[0];
  271. sgrid.triggerToolbar();
  272. <?php } ?>
  273. });
  274. </script>
  275. <form id="export_report_form" method="post" action="hotpotatoes_exercise_report.php?<?php echo api_get_cidreq(); ?>">
  276. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  277. <input type="hidden" name="export_report" id="export_report" value="1" />
  278. <input type="hidden" name="path" id="path" value="<?php echo $hotpotatoes_path ?>" />
  279. </form>
  280. <?php
  281. echo Display::grid_html('results');
  282. Display :: display_footer();