gradebook_flatview.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Script
  6. * @package chamilo.gradebook
  7. */
  8. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';
  9. $current_course_tool = TOOL_GRADEBOOK;
  10. $studentView = Session::read('studentview');
  11. api_protect_course_script(true);
  12. api_block_anonymous_users();
  13. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  14. api_get_user_id(),
  15. api_get_course_info()
  16. );
  17. if (!$isDrhOfCourse) {
  18. GradebookUtils::block_students();
  19. }
  20. if (isset($_POST['submit']) && isset($_POST['keyword'])) {
  21. header(
  22. 'Location: '.api_get_self().'?selectcat='.intval(
  23. $_GET['selectcat']
  24. ).'&search='.Security::remove_XSS($_POST['keyword'])
  25. );
  26. exit;
  27. }
  28. $interbreadcrumb[] = array(
  29. 'url' => $_SESSION['gradebook_dest'].'?selectcat=1',
  30. 'name' => get_lang('ToolGradebook')
  31. );
  32. $showeval = isset($_POST['showeval']) ? '1' : '0';
  33. $showlink = isset($_POST['showlink']) ? '1' : '0';
  34. if (($showlink == '0') && ($showeval == '0')) {
  35. $showlink = '1';
  36. $showeval = '1';
  37. }
  38. $cat = Category::load($_REQUEST['selectcat']);
  39. if (isset($_GET['userid'])) {
  40. $userid = Security::remove_XSS($_GET['userid']);
  41. } else {
  42. $userid = '';
  43. }
  44. if ($showeval) {
  45. $alleval = $cat[0]->get_evaluations($userid, true);
  46. } else {
  47. $alleval = null;
  48. }
  49. if ($showlink) {
  50. $alllinks = $cat[0]->get_links($userid, true);
  51. } else {
  52. $alllinks = null;
  53. }
  54. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  55. Display :: display_normal_message($export_flatview_form->toHtml(), false);
  56. }
  57. if (isset($_GET['selectcat'])) {
  58. $category_id = (int) $_GET['selectcat'];
  59. } else {
  60. $category_id = '';
  61. }
  62. $simple_search_form = new UserForm(
  63. UserForm :: TYPE_SIMPLE_SEARCH,
  64. null,
  65. 'simple_search_form',
  66. null,
  67. api_get_self() . '?selectcat=' . $category_id
  68. );
  69. $values = $simple_search_form->exportValues();
  70. $keyword = '';
  71. if (isset($_GET['search']) && !empty($_GET['search'])) {
  72. $keyword = Security::remove_XSS($_GET['search']);
  73. }
  74. if ($simple_search_form->validate() && (empty($keyword))) {
  75. $keyword = $values['keyword'];
  76. }
  77. if (!empty($keyword)) {
  78. $users = GradebookUtils::find_students($keyword);
  79. } else {
  80. if (isset($alleval) && isset($alllinks)) {
  81. $users = GradebookUtils::get_all_users($alleval, $alllinks);
  82. } else {
  83. $users = null;
  84. }
  85. }
  86. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  87. $addparams = array('selectcat' => $cat[0]->get_id());
  88. if (isset($_GET['search'])) {
  89. $addparams['search'] = $keyword;
  90. }
  91. // Main course category
  92. $mainCourseCategory = Category::load(
  93. null,
  94. null,
  95. api_get_course_id(),
  96. null,
  97. null,
  98. api_get_session_id()
  99. );
  100. $flatviewtable = new FlatViewTable(
  101. $cat[0],
  102. $users,
  103. $alleval,
  104. $alllinks,
  105. true,
  106. $offset,
  107. $addparams,
  108. $mainCourseCategory[0]
  109. );
  110. $flatviewtable->setAutoFill(false);
  111. $parameters = array('selectcat' => intval($_GET['selectcat']));
  112. $flatviewtable->set_additional_parameters($parameters);
  113. $params = array();
  114. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  115. $params['only_total_category'] = true;
  116. $params['join_firstname_lastname'] = true;
  117. $params['show_official_code'] = true;
  118. $params['export_pdf'] = true;
  119. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  120. Display :: set_header(null, false, false);
  121. GradebookUtils::export_pdf_flatview(
  122. $flatviewtable,
  123. $cat,
  124. $users,
  125. $alleval,
  126. $alllinks,
  127. $params,
  128. $mainCourseCategory[0]
  129. );
  130. }
  131. }
  132. if (isset($_GET['exportpdf'])) {
  133. $interbreadcrumb[] = array (
  134. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq(),
  135. 'name' => get_lang('FlatView')
  136. );
  137. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  138. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  139. $url = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([
  140. 'exportpdf' => '',
  141. 'offset' => $offset,
  142. 'selectcat' => intval($_GET['selectcat']),
  143. 'flatviewlist_page_nr' => $pageNum,
  144. 'flatviewlist_per_page' => $perPage
  145. ]);
  146. $export_pdf_form = new DataForm(
  147. DataForm::TYPE_EXPORT_PDF,
  148. 'export_pdf_form',
  149. null,
  150. $url,
  151. '_blank',
  152. ''
  153. );
  154. if ($export_pdf_form->validate()) {
  155. $params = $export_pdf_form->exportValues();
  156. Display :: set_header(null, false, false);
  157. $params['join_firstname_lastname'] = true;
  158. $params['show_official_code'] = true;
  159. $params['export_pdf'] = true;
  160. $params['only_total_category'] = false;
  161. GradebookUtils::export_pdf_flatview(
  162. $flatviewtable,
  163. $cat,
  164. $users,
  165. $alleval,
  166. $alllinks,
  167. $params,
  168. $mainCourseCategory[0]
  169. );
  170. } else {
  171. Display :: display_header(get_lang('ExportPDF'));
  172. }
  173. }
  174. if (isset($_GET['print'])) {
  175. $printable_data = GradebookUtils::get_printable_data(
  176. $cat[0],
  177. $users,
  178. $alleval,
  179. $alllinks,
  180. $params,
  181. $mainCourseCategory[0]
  182. );
  183. echo print_table(
  184. $printable_data[1],
  185. $printable_data[0],
  186. get_lang('FlatView'),
  187. $cat[0]->get_name()
  188. );
  189. exit;
  190. }
  191. if (!empty($_GET['export_report']) &&
  192. $_GET['export_report'] == 'export_report'
  193. ) {
  194. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
  195. $user_id = null;
  196. if (empty($_SESSION['export_user_fields'])) {
  197. $_SESSION['export_user_fields'] = false;
  198. }
  199. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  200. $user_id = api_get_user_id();
  201. }
  202. $printable_data = GradebookUtils::get_printable_data(
  203. $cat[0],
  204. $users,
  205. $alleval,
  206. $alllinks,
  207. $params,
  208. $mainCourseCategory[0]
  209. );
  210. switch ($_GET['export_format']) {
  211. case 'xls':
  212. ob_start();
  213. $export = new GradeBookResult();
  214. $export->exportCompleteReportXLS($printable_data);
  215. $content = ob_get_contents();
  216. ob_end_clean();
  217. echo $content;
  218. break;
  219. case 'doc':
  220. ob_start();
  221. $export = new GradeBookResult();
  222. $export->exportCompleteReportDOC($printable_data);
  223. $content = ob_get_contents();
  224. ob_end_clean();
  225. echo $content;
  226. break;
  227. case 'csv':
  228. default:
  229. ob_start();
  230. $export = new GradeBookResult();
  231. $export->exportCompleteReportCSV($printable_data);
  232. $content = ob_get_contents();
  233. ob_end_clean();
  234. echo $content;
  235. exit;
  236. break;
  237. }
  238. } else {
  239. api_not_allowed(true);
  240. }
  241. }
  242. $this_section = SECTION_COURSES;
  243. if (isset($_GET['exportpdf'])) {
  244. $export_pdf_form->display();
  245. } else {
  246. Display :: display_header(get_lang('FlatView'));
  247. }
  248. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  249. DisplayGradebook:: display_header_reduce_flatview(
  250. $cat[0],
  251. $showeval,
  252. $showlink,
  253. $simple_search_form
  254. );
  255. $flatviewtable->display();
  256. //} elseif (isset($_GET['selectcat']) && ($studentView == 'teacherview')) {
  257. } elseif (isset($_GET['selectcat'])) {
  258. DisplayGradebook:: display_header_reduce_flatview(
  259. $cat[0],
  260. $showeval,
  261. $showlink,
  262. $simple_search_form
  263. );
  264. // Table
  265. $flatviewtable->display();
  266. //@todo load images with jquery
  267. echo '<div id="contentArea" style="text-align: center;" >';
  268. $flatviewtable->display_graph_by_resource();
  269. echo '</div>';
  270. }