gradebook_flatview.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. if (isset($_POST['submit']) && isset($_POST['keyword'])) {
  21. header('Location: '.api_get_self().'?selectcat='.intval($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  22. exit;
  23. }
  24. $interbreadcrumb[] = [
  25. 'url' => Category::getUrl().'selectcat=1',
  26. 'name' => get_lang('ToolGradebook'),
  27. ];
  28. $showeval = isset($_POST['showeval']) ? '1' : '0';
  29. $showlink = isset($_POST['showlink']) ? '1' : '0';
  30. if (($showlink == '0') && ($showeval == '0')) {
  31. $showlink = '1';
  32. $showeval = '1';
  33. }
  34. $cat = Category::load($_REQUEST['selectcat']);
  35. $userId = isset($_GET['userid']) ? (int) $_GET['userid'] : 0;
  36. if ($showeval) {
  37. $alleval = $cat[0]->get_evaluations($userId, true);
  38. } else {
  39. $alleval = null;
  40. }
  41. if ($showlink) {
  42. $alllinks = $cat[0]->get_links($userId, true);
  43. } else {
  44. $alllinks = null;
  45. }
  46. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  47. Display::addFlash(
  48. Display::return_message(
  49. $export_flatview_form->toHtml(),
  50. 'normal',
  51. false
  52. )
  53. );
  54. }
  55. if (isset($_GET['selectcat'])) {
  56. $category_id = (int) $_GET['selectcat'];
  57. } else {
  58. $category_id = '';
  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' => intval($_GET['selectcat'])];
  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='.Security::remove_XSS($_GET['selectcat']).'&'.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' => intval($_GET['selectcat']),
  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) and !api_is_course_tutor()) {
  198. $user_id = api_get_user_id();
  199. }
  200. $printable_data = GradebookUtils::get_printable_data(
  201. $cat[0],
  202. $users,
  203. $alleval,
  204. $alllinks,
  205. $params,
  206. $mainCourseCategory[0]
  207. );
  208. switch ($_GET['export_format']) {
  209. case 'xls':
  210. ob_start();
  211. $export = new GradeBookResult();
  212. $export->exportCompleteReportXLS($printable_data);
  213. $content = ob_get_contents();
  214. ob_end_clean();
  215. echo $content;
  216. break;
  217. case 'doc':
  218. ob_start();
  219. $export = new GradeBookResult();
  220. $export->exportCompleteReportDOC($printable_data);
  221. $content = ob_get_contents();
  222. ob_end_clean();
  223. echo $content;
  224. break;
  225. case 'csv':
  226. default:
  227. ob_start();
  228. $export = new GradeBookResult();
  229. $export->exportCompleteReportCSV($printable_data);
  230. $content = ob_get_contents();
  231. ob_end_clean();
  232. echo $content;
  233. exit;
  234. break;
  235. }
  236. } else {
  237. api_not_allowed(true);
  238. }
  239. }
  240. $this_section = SECTION_COURSES;
  241. if (isset($_GET['exportpdf'])) {
  242. $export_pdf_form->display();
  243. } else {
  244. Display::display_header(get_lang('FlatView'));
  245. }
  246. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  247. DisplayGradebook::display_header_reduce_flatview(
  248. $cat[0],
  249. $showeval,
  250. $showlink,
  251. $simple_search_form
  252. );
  253. $flatViewTable->display();
  254. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  255. DisplayGradebook::display_header_reduce_flatview(
  256. $cat[0],
  257. $showeval,
  258. $showlink,
  259. $simple_search_form
  260. );
  261. // Table
  262. $flatViewTable->display();
  263. //@todo load images with jquery
  264. echo '<div id="contentArea" style="text-align: center;" >';
  265. $flatViewTable->display_graph_by_resource();
  266. echo '</div>';
  267. }
  268. Display :: display_footer();