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