gradebook_flatview.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. $category_id = 0;
  57. if (isset($_GET['selectcat'])) {
  58. $category_id = (int) $_GET['selectcat'];
  59. }
  60. $simple_search_form = new UserForm(
  61. UserForm::TYPE_SIMPLE_SEARCH,
  62. null,
  63. 'simple_search_form',
  64. null,
  65. api_get_self().'?selectcat='.$category_id
  66. );
  67. $values = $simple_search_form->exportValues();
  68. $keyword = '';
  69. if (isset($_GET['search']) && !empty($_GET['search'])) {
  70. $keyword = Security::remove_XSS($_GET['search']);
  71. }
  72. if ($simple_search_form->validate() && empty($keyword)) {
  73. $keyword = $values['keyword'];
  74. }
  75. if (!empty($keyword)) {
  76. $users = GradebookUtils::find_students($keyword);
  77. } else {
  78. if (isset($alleval) && isset($alllinks)) {
  79. $users = GradebookUtils::get_all_users($alleval, $alllinks);
  80. } else {
  81. $users = null;
  82. }
  83. }
  84. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  85. $addparams = ['selectcat' => $cat[0]->get_id()];
  86. if (isset($_GET['search'])) {
  87. $addparams['search'] = $keyword;
  88. }
  89. // Main course category
  90. $mainCourseCategory = Category::load(
  91. null,
  92. null,
  93. api_get_course_id(),
  94. null,
  95. null,
  96. api_get_session_id()
  97. );
  98. $flatViewTable = new FlatViewTable(
  99. $cat[0],
  100. $users,
  101. $alleval,
  102. $alllinks,
  103. true,
  104. $offset,
  105. $addparams,
  106. $mainCourseCategory[0]
  107. );
  108. $flatViewTable->setAutoFill(false);
  109. $parameters = ['selectcat' => $categoryId];
  110. $flatViewTable->set_additional_parameters($parameters);
  111. $params = [];
  112. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  113. $params['only_total_category'] = true;
  114. $params['join_firstname_lastname'] = true;
  115. $params['show_official_code'] = true;
  116. $params['export_pdf'] = true;
  117. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  118. Display::set_header(null, false, false);
  119. GradebookUtils::export_pdf_flatview(
  120. $flatViewTable,
  121. $cat,
  122. $users,
  123. $alleval,
  124. $alllinks,
  125. $params,
  126. $mainCourseCategory[0]
  127. );
  128. }
  129. }
  130. if (isset($_GET['exportpdf'])) {
  131. $interbreadcrumb[] = [
  132. 'url' => api_get_self().'?selectcat='.$categoryId.'&'.api_get_cidreq(),
  133. 'name' => get_lang('FlatView'),
  134. ];
  135. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : null;
  136. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : null;
  137. $url = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  138. 'exportpdf' => '',
  139. 'offset' => $offset,
  140. 'selectcat' => $categoryId,
  141. 'flatviewlist_page_nr' => $pageNum,
  142. 'flatviewlist_per_page' => $perPage,
  143. ]);
  144. $export_pdf_form = new DataForm(
  145. DataForm::TYPE_EXPORT_PDF,
  146. 'export_pdf_form',
  147. null,
  148. $url,
  149. '_blank',
  150. ''
  151. );
  152. if ($export_pdf_form->validate()) {
  153. $params = $export_pdf_form->exportValues();
  154. Display::set_header(null, false, false);
  155. $params['join_firstname_lastname'] = true;
  156. $params['show_official_code'] = true;
  157. $params['export_pdf'] = true;
  158. $params['only_total_category'] = false;
  159. GradebookUtils::export_pdf_flatview(
  160. $flatViewTable,
  161. $cat,
  162. $users,
  163. $alleval,
  164. $alllinks,
  165. $params,
  166. $mainCourseCategory[0]
  167. );
  168. } else {
  169. Display::display_header(get_lang('ExportPDF'));
  170. }
  171. }
  172. if (isset($_GET['print'])) {
  173. $printable_data = GradebookUtils::get_printable_data(
  174. $cat[0],
  175. $users,
  176. $alleval,
  177. $alllinks,
  178. $params,
  179. $mainCourseCategory[0]
  180. );
  181. echo print_table(
  182. $printable_data[1],
  183. $printable_data[0],
  184. get_lang('FlatView'),
  185. $cat[0]->get_name()
  186. );
  187. exit;
  188. }
  189. if (!empty($_GET['export_report']) &&
  190. $_GET['export_report'] == 'export_report'
  191. ) {
  192. if (api_is_platform_admin() || api_is_course_admin() || api_is_session_general_coach() || $isDrhOfCourse) {
  193. $user_id = null;
  194. if (empty($_SESSION['export_user_fields'])) {
  195. $_SESSION['export_user_fields'] = false;
  196. }
  197. if (!api_is_allowed_to_edit(false, false) && !api_is_course_tutor()) {
  198. $user_id = api_get_user_id();
  199. }
  200. $params['show_official_code'] = true;
  201. $printable_data = GradebookUtils::get_printable_data(
  202. $cat[0],
  203. $users,
  204. $alleval,
  205. $alllinks,
  206. $params,
  207. $mainCourseCategory[0]
  208. );
  209. switch ($_GET['export_format']) {
  210. case 'xls':
  211. ob_start();
  212. $export = new GradeBookResult();
  213. $export->exportCompleteReportXLS($printable_data);
  214. $content = ob_get_contents();
  215. ob_end_clean();
  216. echo $content;
  217. break;
  218. case 'doc':
  219. ob_start();
  220. $export = new GradeBookResult();
  221. $export->exportCompleteReportDOC($printable_data);
  222. $content = ob_get_contents();
  223. ob_end_clean();
  224. echo $content;
  225. break;
  226. case 'csv':
  227. default:
  228. ob_start();
  229. $export = new GradeBookResult();
  230. $export->exportCompleteReportCSV($printable_data);
  231. $content = ob_get_contents();
  232. ob_end_clean();
  233. echo $content;
  234. exit;
  235. break;
  236. }
  237. } else {
  238. api_not_allowed(true);
  239. }
  240. }
  241. $this_section = SECTION_COURSES;
  242. if (isset($_GET['exportpdf'])) {
  243. $export_pdf_form->display();
  244. } else {
  245. Display::display_header(get_lang('FlatView'));
  246. }
  247. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  248. DisplayGradebook::display_header_reduce_flatview(
  249. $cat[0],
  250. $showeval,
  251. $showlink,
  252. $simple_search_form
  253. );
  254. $flatViewTable->display();
  255. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  256. DisplayGradebook::display_header_reduce_flatview(
  257. $cat[0],
  258. $showeval,
  259. $showlink,
  260. $simple_search_form
  261. );
  262. // Table
  263. $flatViewTable->display();
  264. //@todo load images with jquery
  265. echo '<div id="contentArea" style="text-align: center;" >';
  266. $flatViewTable->display_graph_by_resource();
  267. echo '</div>';
  268. }
  269. Display :: display_footer();