gradebook_flatview.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php // $Id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. $language_file= 'gradebook';
  21. //$cidReset= true;
  22. require_once ('../inc/global.inc.php');
  23. require_once ('lib/be.inc.php');
  24. require_once ('lib/gradebook_functions.inc.php');
  25. require_once ('lib/fe/dataform.class.php');
  26. require_once ('lib/fe/userform.class.php');
  27. require_once ('lib/flatview_data_generator.class.php');
  28. require_once ('lib/fe/flatviewtable.class.php');
  29. require_once ('lib/fe/displaygradebook.php');
  30. require_once ('lib/fe/exportgradebook.php');
  31. require_once (api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php');
  32. require_once ('lib/scoredisplay.class.php');
  33. api_block_anonymous_users();
  34. block_students();
  35. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  36. header('Location: ' . api_get_self() . '?selectcat=' . Security::remove_XSS($_GET['selectcat'])
  37. . '&search='.Security::remove_XSS($_POST['keyword']));
  38. exit;
  39. }
  40. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  41. $interbreadcrumb[]= array (
  42. 'url' => $_SESSION['gradebook_dest'],
  43. 'name' => get_lang('Gradebook'
  44. ));
  45. $showeval= (isset ($_POST['showeval']) ? '1' : '0');
  46. $showlink= (isset ($_POST['showlink']) ? '1' : '0');
  47. if (($showlink == '0') && ($showeval == '0')) {
  48. $showlink= '1';
  49. $showeval= '1';
  50. }
  51. $cat= Category :: load($_REQUEST['selectcat']);
  52. if (isset($_GET['userid'])) {
  53. $userid=Security::remove_XSS($_GET['userid']);
  54. } else {
  55. $userid='';
  56. }
  57. if ($showeval) {
  58. $alleval= $cat[0]->get_evaluations($userid, true);
  59. } else {
  60. $alleval=null;
  61. }
  62. if ($showlink) {
  63. $alllinks= $cat[0]->get_links($userid, true);
  64. } else {
  65. $alllinks=null;
  66. }
  67. if (isset ($export_flatview_form) && (!$file_type == 'pdf')) {
  68. Display :: display_normal_message($export_flatview_form->toHtml(),false);
  69. }
  70. if (isset($_GET['selectcat'])) {
  71. $category_id=Security::remove_XSS($_GET['selectcat']);
  72. } else {
  73. $category_id='';
  74. }
  75. $simple_search_form= new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' .$category_id);
  76. $values= $simple_search_form->exportValues();
  77. $keyword = '';
  78. if (isset($_GET['search']) && !empty($_GET['search'])) {
  79. $keyword = Security::remove_XSS($_GET['search']);
  80. }
  81. if ($simple_search_form->validate() && (empty($keyword))) {
  82. $keyword = $values['keyword'];
  83. }
  84. if (!empty($keyword)) {
  85. $users= find_students($keyword);
  86. } else {
  87. if (isset($alleval) && isset($alllinks)) {
  88. $users= get_all_users($alleval, $alllinks);
  89. }else {
  90. $users=null;
  91. }
  92. }
  93. if (isset ($_GET['exportpdf'])) {
  94. $interbreadcrumb[]= array (
  95. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  96. 'name' => get_lang('FlatView')
  97. );
  98. $export_pdf_form= new DataForm(DataForm :: TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self() . '?exportpdf=&offset='.$_GET['offset'].'&selectcat=' . $_GET['selectcat'],'_blank');
  99. if (!$export_pdf_form->validate()) {
  100. Display :: display_header(get_lang('ExportPDF'));
  101. }
  102. if ($export_pdf_form->validate()) {
  103. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  104. $export= $export_pdf_form->exportValues();
  105. $format = $export['orientation'];
  106. $pdf =& new Cezpdf('a4',$format); //format is 'portrait' or 'landscape'
  107. $clear_printable_data=array();
  108. $clear_send_printable_data=array();
  109. //var_dump(count($printable_data[1]));
  110. for ($i=0;$i<count($printable_data[1]);$i++) {
  111. for ($k=0;$k<count($printable_data[1][$i]);$k++) {
  112. $clear_printable_data[]=strip_tags($printable_data[1][$i][$k]);
  113. }
  114. $clear_send_printable_data[]=$clear_printable_data;
  115. $clear_printable_data=array();
  116. }
  117. /*var_dump($printable_data[1]);
  118. var_dump('--------------');
  119. var_dump($clear_send_printable_data);*/
  120. export_pdf($pdf,$clear_send_printable_data,$printable_data[0],$format);
  121. exit;
  122. }
  123. }
  124. if (isset ($_GET['print'])) {
  125. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  126. echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
  127. exit;
  128. }
  129. if(!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report'){
  130. if(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  131. $user_id = null;
  132. if(empty($_SESSION['export_user_fields'])) {
  133. $_SESSION['export_user_fields'] = false;
  134. }
  135. if(!api_is_allowed_to_edit(false,false) and !api_is_course_tutor()) {
  136. $user_id = api_get_user_id();
  137. }
  138. require_once('gradebook_result.class.php');
  139. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  140. switch($_POST['export_format']) {
  141. case 'xls':
  142. $export = new GradeBookResult();
  143. $export->exportCompleteReportXLS($printable_data );
  144. exit;
  145. break;
  146. case 'csv':
  147. default:
  148. $export = new GradeBookResult();
  149. $export->exportCompleteReportCSV($printable_data);
  150. exit;
  151. break;
  152. }
  153. } else {
  154. api_not_allowed(true);
  155. }
  156. }
  157. $addparams= array ('selectcat' => $cat[0]->get_id());
  158. if (isset($_GET['search'])) {
  159. $addparams['search'] = $keyword;
  160. }
  161. $offset = (isset($_GET['offset'])?$_GET['offset']:'0');
  162. $flatviewtable= new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
  163. if (isset($_GET['exportpdf'])) {
  164. echo '<div class="normal-message">';
  165. $export_pdf_form->display();
  166. echo '</div>';
  167. } else {
  168. Display :: display_header(get_lang('FlatView'));
  169. }
  170. if (isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
  171. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  172. $flatviewtable->display();
  173. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')) {
  174. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  175. /*echo '<div id="contentLoading" class="contentLoading">';
  176. echo Display::display_icon('loader.gif');
  177. echo '</div>';*/
  178. // main graph
  179. //@todo load images with jquery
  180. echo '<div id="contentArea" style="text-align:center;" >';
  181. $image_file = $flatviewtable->display_graph();
  182. $my_info_path_img=array();
  183. $my_info_path_img=explode('/',$image_file);
  184. if (strlen($my_info_path_img[5])==32) {
  185. echo '<img src="'.$image_file.'">';
  186. }
  187. $flatviewtable->display();
  188. $flatviewtable->display_graph_by_resource();
  189. echo '</div>';
  190. }
  191. Display :: display_footer();
  192. function get_printable_data($users,$alleval, $alllinks) {
  193. $datagen = new FlatViewDataGenerator ($users,$alleval, $alllinks);
  194. $offset = (isset($_GET['offset'])?$_GET['offset']:'0');
  195. $count = (($offset+10) > $datagen->get_total_items_count()) ?
  196. ($datagen->get_total_items_count()-$offset) : 10;
  197. $header_names = $datagen->get_header_names($offset,$count);
  198. $data_array = $datagen->get_data(FlatViewDataGenerator :: FVDG_SORT_LASTNAME,0,null,$offset,$count,true);
  199. $newarray = array();
  200. foreach ($data_array as $data) {
  201. $newarray[] = array_slice($data, 1);
  202. }
  203. return array ($header_names, $newarray);
  204. }