question_course_report.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report
  5. * @package chamilo.tracking
  6. */
  7. /**
  8. * Code
  9. */
  10. $language_file = array ('registration', 'index', 'tracking', 'exercice','survey');
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
  14. require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
  15. require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
  16. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  17. $this_section = "session_my_space";
  18. $is_allowedToTrack = api_is_course_admin() || api_is_platform_admin() || api_is_course_coach() || api_is_session_admin();
  19. if(!$is_allowedToTrack) {
  20. Display :: display_header(null);
  21. api_not_allowed();
  22. Display :: display_footer();
  23. }
  24. $export_to_xls = false;
  25. if (isset($_GET['export'])) {
  26. $export_to_xls = true;
  27. }
  28. if (api_is_platform_admin() ) {
  29. $global = true;
  30. } else {
  31. $global = false;
  32. }
  33. $global = true;
  34. $course_list = $course_select_list = array();
  35. $course_select_list[0] = get_lang('None');
  36. $htmlHeadXtra[] = '
  37. <script type="text/javascript">
  38. function load_courses() {
  39. document.search_simple.submit();
  40. }
  41. </script> ';
  42. $session_id = intval($_REQUEST['session_id']);
  43. if (empty($session_id)) {
  44. $temp_course_list = CourseManager :: get_courses_list();
  45. } else {
  46. $temp_course_list = SessionManager::get_course_list_by_session_id($session_id);
  47. }
  48. foreach($temp_course_list as $temp_course_item) {
  49. $course_item = CourseManager ::get_course_information($temp_course_item['code']);
  50. $course_list[]= array('db_name' =>$course_item['db_name'],'code'=>$course_item['code'], 'title'=>$course_item['title'], 'visual_code'=>$course_item['visual_code']);
  51. $course_select_list[$temp_course_item['code']] = $course_item['title'];
  52. }
  53. //Get session list
  54. $session_list = SessionManager::get_sessions_list(array(), array('name'));
  55. $my_session_list = array();
  56. $my_session_list[0] = get_lang('None');
  57. foreach($session_list as $sesion_item) {
  58. $my_session_list[$sesion_item['id']] = $sesion_item['name'];
  59. }
  60. $form = new FormValidator('search_simple','POST','','',null,false);
  61. $form->addElement('select', 'session_id', get_lang('Sessions'), $my_session_list, array('id'=>'session_id', 'onchange'=>'load_courses();'));
  62. $form->addElement('select', 'course_code',get_lang('Courses'), $course_select_list);
  63. $form->addElement('style_submit_button','submit_form', get_lang('Filter'));
  64. if (!empty($_REQUEST['course_code'])) $course_code = $_REQUEST['course_code']; else $course_code = '';
  65. if (empty($course_code)) {
  66. $course_code = 0;
  67. }
  68. $form->setDefaults(array('course_code'=>(string)$course_code));
  69. $course_info = api_get_course_info($course_code);
  70. if (!empty($course_info)) {
  71. $list = new LearnpathList('', $course_code);
  72. $lp_list = $list->get_flat_list();
  73. $_course = $course_info;
  74. $main_question_list = array();
  75. foreach ($lp_list as $lp_id =>$lp) {
  76. $exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
  77. foreach ($exercise_list as $exercise) {
  78. $my_exercise = new Exercise();
  79. $my_exercise->read($exercise['path']);
  80. $question_list = $my_exercise->selectQuestionList();
  81. $exercise_stats = get_all_exercise_event_from_lp($exercise['path'],$course_info['real_id'], $session_id);
  82. foreach ($question_list as $question_id) {
  83. $question_data = Question::read($question_id);
  84. $main_question_list[$question_id] = $question_data;
  85. $quantity_exercises = 0;
  86. $question_result = 0;
  87. foreach($exercise_stats as $stats) {
  88. if (!empty($stats['question_list'])) {
  89. foreach($stats['question_list'] as $my_question_stat) {
  90. if ($question_id == $my_question_stat['question_id']) {
  91. $question_result = $question_result + $my_question_stat['marks'];
  92. $quantity_exercises++;
  93. }
  94. }
  95. }
  96. }
  97. if(!empty($quantity_exercises)) {
  98. $main_question_list[$question_id]->results =(($question_result / ($quantity_exercises)) ) ; // Score % average
  99. } else {
  100. $main_question_list[$question_id]->results = 0;
  101. }
  102. $main_question_list[$question_id]->quantity = $quantity_exercises;
  103. }
  104. }
  105. }
  106. }
  107. if (!$export_to_xls) {
  108. Display :: display_header(get_lang("MySpace"));
  109. echo '<div class="actions" style ="font-size:10pt;" >';
  110. if ($global) {
  111. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  112. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher');
  113. $menu_items[] = Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32);
  114. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  115. $nb_menu_items = count($menu_items);
  116. if($nb_menu_items>1) {
  117. foreach($menu_items as $key=> $item) {
  118. echo $item;
  119. }
  120. }
  121. } else {
  122. echo '<div style="float:left; clear:left">
  123. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  124. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;';
  125. echo '</div>';
  126. }
  127. echo '</div>';
  128. if (api_is_platform_admin()) {
  129. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  130. echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  131. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
  132. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'mySpace/?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
  133. echo ' | '.get_lang('LPQuestionListResults');
  134. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin">'.get_lang('LPExerciseResultsBySession').'</a>';
  135. }
  136. echo '<br />';
  137. echo '<h2>'.get_lang('LPQuestionListResults').'</h2>';
  138. $form->display();
  139. //Display::display_normal_message(get_lang('QuestionsAreTakenFromLPExercises'));
  140. if (empty($course_code)) {
  141. Display::display_warning_message(get_lang('PleaseSelectACourse'));
  142. }
  143. }
  144. $course_average = array();
  145. $counter = 0;
  146. if (!empty($main_question_list) && is_array($main_question_list)) {
  147. $html_result .= '<table class="data_table">';
  148. $html_result .= '<tr><th>'.get_lang('Question').Display :: return_icon('info3.gif', get_lang('QuestionsAreTakenFromLPExercises'), array('align' => 'absmiddle', 'hspace' => '3px')).'</th>';
  149. $html_result .= '<th>'.$course_info['visual_code'].' '.get_lang('AverageScore').Display :: return_icon('info3.gif', get_lang('AllStudentsAttemptsAreConsidered'), array('align' => 'absmiddle', 'hspace' => '3px')).' </th>';
  150. $html_result .= '<th>'.get_lang('Quantity').'</th>';
  151. foreach($main_question_list as $question) {
  152. $total_student = 0;
  153. $counter ++;
  154. $s_css_class = 'row_even';
  155. if ($counter % 2 ==0 ) {
  156. $s_css_class = 'row_odd';
  157. }
  158. $html_result .= "<tr class='$s_css_class'>
  159. <td >";
  160. $question_title = trim($question->question);
  161. if (empty($question_title)) {
  162. $html_result .= get_lang('Untitled').' '.get_lang('Question').' #'.$question->id;
  163. } else {
  164. $html_result .= $question->question;
  165. }
  166. $html_result .= "</td>";
  167. $html_result .= "<td>";
  168. $html_result .= round($question->results, 2).' / '.$question->weighting;
  169. $html_result .= "</td>";
  170. $html_result .= "<td>";
  171. $html_result .= $question->quantity;
  172. $html_result .= "</td>";
  173. }
  174. $html_result .="</tr>";
  175. $html_result .= '</table>';
  176. } else {
  177. if (!empty($course_code)) {
  178. Display::display_warning_message(get_lang('NoResults'));
  179. }
  180. }
  181. if (!$export_to_xls) {
  182. echo $html_result;
  183. }
  184. $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
  185. if ($export_to_xls) {
  186. echo $html_result;
  187. export_complete_report_xls($filename, $export_array);
  188. exit;
  189. }
  190. function sort_user($a, $b) {
  191. if (is_numeric($a['score']) && is_numeric($b['score'])) {
  192. echo $a['score'].' : '.$b['score'];
  193. echo '<br />';
  194. if ($a['score'] < $b['score']) {
  195. return 1;
  196. }
  197. return 0;
  198. }
  199. return 1;
  200. }
  201. function export_complete_report_xls($filename, $array) {
  202. global $charset;
  203. $workbook = new Spreadsheet_Excel_Writer();
  204. $workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
  205. $workbook->send($filename);
  206. $workbook->setVersion(8); // BIFF8
  207. $worksheet =& $workbook->addWorksheet('Report');
  208. //$worksheet->setInputEncoding(api_get_system_encoding());
  209. $worksheet->setInputEncoding($charset);
  210. /*
  211. $line = 0;
  212. $column = 1; // Skip the first column (row titles)
  213. foreach ($array as $elem) {
  214. $worksheet->write($line, $column, $elem);
  215. $column++;
  216. }
  217. $workbook->close();*/
  218. exit;
  219. }
  220. Display :: display_footer();