gradebook_flatview.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script.
  5. *
  6. * @package chamilo.gradebook
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';
  10. $current_course_tool = TOOL_GRADEBOOK;
  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. $categoryId = isset($_REQUEST['selectcat']) ? (int) $_REQUEST['selectcat'] : 0;
  21. if (isset($_POST['submit']) && isset($_POST['keyword'])) {
  22. header('Location: '.api_get_self().'?selectcat='.$categoryId.'&search='.Security::remove_XSS($_POST['keyword']));
  23. exit;
  24. }
  25. $interbreadcrumb[] = [
  26. 'url' => Category::getUrl().'selectcat=1',
  27. 'name' => get_lang('ToolGradebook'),
  28. ];
  29. $showeval = isset($_POST['showeval']) ? '1' : '0';
  30. $showlink = isset($_POST['showlink']) ? '1' : '0';
  31. if ($showlink == '0' && $showeval == '0') {
  32. $showlink = '1';
  33. $showeval = '1';
  34. }
  35. $cat = Category::load($categoryId);
  36. $userId = isset($_GET['userid']) ? (int) $_GET['userid'] : 0;
  37. if ($showeval) {
  38. $alleval = $cat[0]->get_evaluations($userId, true);
  39. } else {
  40. $alleval = null;
  41. }
  42. if ($showlink) {
  43. $alllinks = $cat[0]->get_links($userId, true);
  44. } else {
  45. $alllinks = null;
  46. }
  47. if (isset($export_flatview_form) && !$file_type == 'pdf') {
  48. Display::addFlash(
  49. Display::return_message(
  50. $export_flatview_form->toHtml(),
  51. 'normal',
  52. false
  53. )
  54. );
  55. }
  56. if (isset($_GET['selectcat'])) {
  57. $category_id = (int) $_GET['selectcat'];
  58. } else {
  59. $category_id = '';
  60. }
  61. $simple_search_form = new UserForm(
  62. UserForm::TYPE_SIMPLE_SEARCH,
  63. null,
  64. 'simple_search_form',
  65. null,
  66. api_get_self().'?selectcat='.$category_id
  67. );
  68. $values = $simple_search_form->exportValues();
  69. $keyword = '';
  70. if (isset($_GET['search']) && !empty($_GET['search'])) {
  71. $keyword = Security::remove_XSS($_GET['search']);
  72. }
  73. if ($simple_search_form->validate() && empty($keyword)) {
  74. $keyword = $values['keyword'];
  75. }
  76. if (!empty($keyword)) {
  77. $users = GradebookUtils::find_students($keyword);
  78. } else {
  79. if (isset($alleval) && isset($alllinks)) {
  80. $users = GradebookUtils::get_all_users($alleval, $alllinks);
  81. } else {
  82. $users = null;
  83. }
  84. }
  85. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  86. $addparams = ['selectcat' => $cat[0]->get_id()];
  87. if (isset($_GET['search'])) {
  88. $addparams['search'] = $keyword;
  89. }
  90. // Main course category
  91. $mainCourseCategory = Category::load(
  92. null,
  93. null,
  94. api_get_course_id(),
  95. null,
  96. null,
  97. api_get_session_id()
  98. );
  99. $flatViewTable = new FlatViewTable(
  100. $cat[0],
  101. $users,
  102. $alleval,
  103. $alllinks,
  104. true,
  105. $offset,
  106. $addparams,
  107. $mainCourseCategory[0]
  108. );
  109. $flatViewTable->setAutoFill(false);
  110. $parameters = ['selectcat' => $categoryId];
  111. $flatViewTable->set_additional_parameters($parameters);
  112. $params = [];
  113. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  114. $params['only_total_category'] = true;
  115. $params['join_firstname_lastname'] = true;
  116. $params['show_official_code'] = true;
  117. $params['export_pdf'] = true;
  118. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  119. Display::set_header(null, false, false);
  120. GradebookUtils::export_pdf_flatview(
  121. $flatViewTable,
  122. $cat,
  123. $users,
  124. $alleval,
  125. $alllinks,
  126. $params,
  127. $mainCourseCategory[0]
  128. );
  129. }
  130. }
  131. if (isset($_GET['exportpdf'])) {
  132. $interbreadcrumb[] = [
  133. 'url' => api_get_self().'?selectcat='.$categoryId.'&'.api_get_cidreq(),
  134. 'name' => get_lang('FlatView'),
  135. ];
  136. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  137. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  138. $url = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  139. 'exportpdf' => '',
  140. 'offset' => $offset,
  141. 'selectcat' => $categoryId,
  142. 'flatviewlist_page_nr' => $pageNum,
  143. 'flatviewlist_per_page' => $perPage,
  144. ]);
  145. $export_pdf_form = new DataForm(
  146. DataForm::TYPE_EXPORT_PDF,
  147. 'export_pdf_form',
  148. null,
  149. $url,
  150. '_blank',
  151. ''
  152. );
  153. if ($export_pdf_form->validate()) {
  154. $params = $export_pdf_form->exportValues();
  155. Display::set_header(null, false, false);
  156. $params['join_firstname_lastname'] = true;
  157. $params['show_official_code'] = true;
  158. $params['export_pdf'] = true;
  159. $params['only_total_category'] = false;
  160. GradebookUtils::export_pdf_flatview(
  161. $flatViewTable,
  162. $cat,
  163. $users,
  164. $alleval,
  165. $alllinks,
  166. $params,
  167. $mainCourseCategory[0]
  168. );
  169. } else {
  170. Display::display_header(get_lang('ExportPDF'));
  171. }
  172. }
  173. if (isset($_GET['print'])) {
  174. $printable_data = GradebookUtils::get_printable_data(
  175. $cat[0],
  176. $users,
  177. $alleval,
  178. $alllinks,
  179. $params,
  180. $mainCourseCategory[0]
  181. );
  182. echo print_table(
  183. $printable_data[1],
  184. $printable_data[0],
  185. get_lang('FlatView'),
  186. $cat[0]->get_name()
  187. );
  188. exit;
  189. }
  190. if (!empty($_GET['export_report']) &&
  191. $_GET['export_report'] == 'export_report'
  192. ) {
  193. if (api_is_platform_admin() || api_is_course_admin() || api_is_session_general_coach() || $isDrhOfCourse) {
  194. $user_id = null;
  195. if (empty($_SESSION['export_user_fields'])) {
  196. $_SESSION['export_user_fields'] = false;
  197. }
  198. if (!api_is_allowed_to_edit(false, false) && !api_is_course_tutor()) {
  199. $user_id = api_get_user_id();
  200. }
  201. $params['show_official_code'] = true;
  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']) && ($_SESSION['studentview'] == 'teacherview')) {
  257. DisplayGradebook::display_header_reduce_flatview(
  258. $cat[0],
  259. $showeval,
  260. $showlink,
  261. $simple_search_form
  262. );
  263. // Table
  264. $flatViewTable->display();
  265. //@todo load images with jquery
  266. echo '<div id="contentArea" style="text-align: center;" >';
  267. $flatViewTable->display_graph_by_resource();
  268. echo '</div>';
  269. }
  270. Display :: display_footer();