hotpotatoes_exercise_report.php 12 KB

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