exercise_report.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 Julio Montoya <gugli100@gmail.com> jqgrid integration
  7. * Modified by hubert.borderiou (question category)
  8. *
  9. * @todo fix excel export
  10. *
  11. */
  12. /**
  13. * Code
  14. */
  15. // name of the language file that needs to be included
  16. $language_file = array('exercice');
  17. api_protect_global_admin_script();
  18. $urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
  19. // Setting the tabs
  20. $this_section = SECTION_COURSES;
  21. $htmlHeadXtra[] = api_get_jqgrid_js();
  22. // including additional libraries
  23. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  24. require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
  25. require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php';
  26. // need functions of statsutils lib to display previous exercices scores
  27. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  28. // document path
  29. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  30. /* Constants and variables */
  31. $is_tutor = api_is_allowed_to_edit(true);
  32. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  33. $TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  34. $TBL_TRACK_ATTEMPT = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  35. $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  36. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  37. $course_id = api_get_course_int_id();
  38. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  39. $load_extra_data = false;
  40. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  41. $load_extra_data = true;
  42. }
  43. require_once 'exercise_result.class.php';
  44. switch ($_GET['export_format']) {
  45. case 'xls':
  46. $export = new ExerciseResult();
  47. $export->exportCompleteReportXLS(
  48. $documentPath,
  49. null,
  50. $load_extra_data,
  51. null,
  52. $_GET['exerciseId'],
  53. $_GET['hotpotato_name']
  54. );
  55. exit;
  56. break;
  57. case 'csv':
  58. default:
  59. $export = new ExerciseResult();
  60. $export->exportCompleteReportCSV(
  61. $documentPath,
  62. null,
  63. $load_extra_data,
  64. null,
  65. $_GET['exerciseId'],
  66. $_GET['hotpotato_name']
  67. );
  68. exit;
  69. break;
  70. }
  71. }
  72. $nameTools = get_lang('StudentScore');
  73. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  74. $interbreadcrumb[] = array("url" => "", "name" => get_lang('ExercicesReport'));
  75. Display :: display_header($nameTools);
  76. $extra = '<script>
  77. $(document).ready(function() {
  78. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  79. $( "#dialog-confirm" ).dialog({
  80. autoOpen: false,
  81. show: "blind",
  82. resizable: false,
  83. height:300,
  84. modal: true
  85. });
  86. $("#export_opener").click(function() {
  87. var targetUrl = $(this).attr("href");
  88. $( "#dialog-confirm" ).dialog({
  89. width:400,
  90. height:300,
  91. buttons: {
  92. "'.addslashes(get_lang('Download')).'": function() {
  93. var export_format = $("input[name=export_format]:checked").val();
  94. var extra_data = $("input[name=load_extra_data]:checked").val();
  95. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
  96. $( this ).dialog( "close" );
  97. },
  98. }
  99. });
  100. $( "#dialog-confirm" ).dialog("open");
  101. return false;
  102. });
  103. });
  104. </script>';
  105. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  106. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  107. $form->addElement(
  108. 'radio',
  109. 'export_format',
  110. null,
  111. get_lang('ExportAsCSV'),
  112. 'csv',
  113. array('id' => 'export_format_csv_label')
  114. );
  115. $form->addElement(
  116. 'radio',
  117. 'export_format',
  118. null,
  119. get_lang('ExportAsXLS'),
  120. 'xls',
  121. array('id' => 'export_format_xls_label')
  122. );
  123. $form->addElement(
  124. 'checkbox',
  125. 'load_extra_data',
  126. null,
  127. get_lang('LoadExtraData'),
  128. '0',
  129. array('id' => 'export_format_xls_label')
  130. );
  131. $form->setDefaults(array('export_format' => 'csv'));
  132. $extra .= $form->return_form();
  133. $extra .= '</div>';
  134. echo $extra;
  135. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_admin_exercise_results';
  136. $action_links = '';
  137. //The order is important you need to check the the $column variable in the model.ajax.php file
  138. $columns = array(
  139. get_lang('LoginName'),
  140. get_lang('FirstName'),
  141. get_lang('LastName'),
  142. get_lang('Score'),
  143. get_lang('Link'),
  144. get_lang('Session')
  145. // get_lang('Actions')
  146. );
  147. //Column config
  148. $column_model = array(
  149. array(
  150. 'name' => 'login',
  151. 'index' => 'username',
  152. 'width' => '40',
  153. 'align' => 'left',
  154. 'search' => 'true'
  155. ),
  156. array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  157. array(
  158. 'name' => 'lastname',
  159. 'index' => 'lastname',
  160. 'width' => '50',
  161. 'align' => 'left',
  162. //'formatter' => 'action_formatter',
  163. 'search' => 'true'
  164. ),
  165. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  166. array('name' => 'link', 'index' => 'link', 'width' => '50', 'align' => 'left', 'search' => 'false'),
  167. array('name' => 'session', 'index' => 'session_id', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  168. );
  169. //Autowidth
  170. $extra_params['autowidth'] = 'true';
  171. //height auto
  172. $extra_params['height'] = 'auto';
  173. ?>
  174. <script>
  175. function setSearchSelect(columnName) {
  176. $("#results").jqGrid('setColProp', columnName, {
  177. searchoptions:{
  178. dataInit:function (el) {
  179. $("option[value='1']", el).attr("selected", "selected");
  180. setTimeout(function () {
  181. $(el).trigger('change');
  182. }, 1000);
  183. }
  184. }
  185. });
  186. }
  187. function exportExcel() {
  188. var mya = new Array();
  189. mya = $("#results").getDataIDs(); // Get All IDs
  190. var data = $("#results").getRowData(mya[0]); // Get First row to get the labels
  191. var colNames = new Array();
  192. var ii = 0;
  193. for (var i in data) {
  194. colNames[ii++] = i;
  195. } // capture col names
  196. var html = "";
  197. for (i = 0; i < mya.length; i++) {
  198. data = $("#results").getRowData(mya[i]); // get each row
  199. for (j = 0; j < colNames.length; j++) {
  200. html = html + data[colNames[j]] + ","; // output each column as tab delimited
  201. }
  202. html = html + "\n"; // output each row with end of line
  203. }
  204. html = html + "\n"; // end of line at the end
  205. var form = $("#export_report_form");
  206. $("#csvBuffer").attr('value', html);
  207. form.target = '_blank';
  208. form.submit();
  209. }
  210. $(function () {
  211. <?php
  212. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  213. ?>
  214. //setSearchSelect("status");
  215. //
  216. //view:true, del:false, add:false, edit:false, excel:true}
  217. $("#results").jqGrid(
  218. 'navGrid',
  219. '#results_pager',
  220. { view:true, edit:false, add:false, del:false, excel:false },
  221. { height:280, reloadAfterSubmit:false }, // view options
  222. { height:280, reloadAfterSubmit:false }, // edit options
  223. { height:280, reloadAfterSubmit:false }, // add options
  224. { reloadAfterSubmit : false }, // del options
  225. { width:500 } // search options
  226. );
  227. //Adding search options
  228. var options = {
  229. 'stringResult': true,
  230. 'autosearch' : true,
  231. 'searchOnEnter':false
  232. }
  233. jQuery("#results").jqGrid('filterToolbar', options);
  234. var sgrid = $("#results")[0];
  235. sgrid.triggerToolbar();
  236. });
  237. </script>
  238. <form id="export_report_form" method="post" action="exercise_report.php">
  239. <input type="hidden" name="csvBuffer" id="csvBuffer" value=""/>
  240. <input type="hidden" name="export_report" id="export_report" value="1"/>
  241. </form>
  242. <?php
  243. echo Display::grid_html('results');
  244. Display :: display_footer();