gradebook_flatview.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/fe/exportgradebook.php';
  9. $current_course_tool = TOOL_GRADEBOOK;
  10. api_protect_course_script(true);
  11. api_block_anonymous_users();
  12. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  13. api_get_user_id(),
  14. api_get_course_info()
  15. );
  16. if (!$isDrhOfCourse) {
  17. GradebookUtils::block_students();
  18. }
  19. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  20. header('Location: '.api_get_self().'?selectcat='.intval($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  21. exit;
  22. }
  23. $interbreadcrumb[] = array(
  24. 'url' => $_SESSION['gradebook_dest'].'?selectcat=1',
  25. 'name' => get_lang('ToolGradebook')
  26. );
  27. $showeval = isset($_POST['showeval']) ? '1' : '0';
  28. $showlink = isset($_POST['showlink']) ? '1' : '0';
  29. if (($showlink == '0') && ($showeval == '0')) {
  30. $showlink = '1';
  31. $showeval = '1';
  32. }
  33. $cat = Category::load($_REQUEST['selectcat']);
  34. if (isset($_GET['userid'])) {
  35. $userid = Security::remove_XSS($_GET['userid']);
  36. } else {
  37. $userid = '';
  38. }
  39. if ($showeval) {
  40. $alleval = $cat[0]->get_evaluations($userid, true);
  41. } else {
  42. $alleval = null;
  43. }
  44. if ($showlink) {
  45. $alllinks = $cat[0]->get_links($userid, true);
  46. } else {
  47. $alllinks = null;
  48. }
  49. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  50. Display::addFlash(Display::return_message($export_flatview_form->toHtml(), 'normal', false));
  51. }
  52. if (isset($_GET['selectcat'])) {
  53. $category_id = (int) $_GET['selectcat'];
  54. } else {
  55. $category_id = '';
  56. }
  57. $simple_search_form = new UserForm(
  58. UserForm :: TYPE_SIMPLE_SEARCH,
  59. null,
  60. 'simple_search_form',
  61. null,
  62. api_get_self().'?selectcat='.$category_id
  63. );
  64. $values = $simple_search_form->exportValues();
  65. $keyword = '';
  66. if (isset($_GET['search']) && !empty($_GET['search'])) {
  67. $keyword = Security::remove_XSS($_GET['search']);
  68. }
  69. if ($simple_search_form->validate() && (empty($keyword))) {
  70. $keyword = $values['keyword'];
  71. }
  72. if (!empty($keyword)) {
  73. $users = GradebookUtils::find_students($keyword);
  74. } else {
  75. if (isset($alleval) && isset($alllinks)) {
  76. $users = GradebookUtils::get_all_users($alleval, $alllinks);
  77. } else {
  78. $users = null;
  79. }
  80. }
  81. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  82. $addparams = array('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 = array('selectcat' => intval($_GET['selectcat']));
  107. $flatviewtable->set_additional_parameters($parameters);
  108. $params = array();
  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[] = array(
  129. 'url' => api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq(),
  130. 'name' => get_lang('FlatView')
  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' => intval($_GET['selectcat']),
  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(null, false, false);
  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('ExportPDF'));
  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('FlatView'),
  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_course_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) and !api_is_course_tutor()) {
  195. $user_id = api_get_user_id();
  196. }
  197. $printable_data = GradebookUtils::get_printable_data(
  198. $cat[0],
  199. $users,
  200. $alleval,
  201. $alllinks,
  202. $params,
  203. $mainCourseCategory[0]
  204. );
  205. switch ($_GET['export_format']) {
  206. case 'xls':
  207. ob_start();
  208. $export = new GradeBookResult();
  209. $export->exportCompleteReportXLS($printable_data);
  210. $content = ob_get_contents();
  211. ob_end_clean();
  212. echo $content;
  213. break;
  214. case 'doc':
  215. ob_start();
  216. $export = new GradeBookResult();
  217. $export->exportCompleteReportDOC($printable_data);
  218. $content = ob_get_contents();
  219. ob_end_clean();
  220. echo $content;
  221. break;
  222. case 'csv':
  223. default:
  224. ob_start();
  225. $export = new GradeBookResult();
  226. $export->exportCompleteReportCSV($printable_data);
  227. $content = ob_get_contents();
  228. ob_end_clean();
  229. echo $content;
  230. exit;
  231. break;
  232. }
  233. } else {
  234. api_not_allowed(true);
  235. }
  236. }
  237. $this_section = SECTION_COURSES;
  238. if (isset($_GET['exportpdf'])) {
  239. $export_pdf_form->display();
  240. } else {
  241. Display :: display_header(get_lang('FlatView'));
  242. }
  243. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  244. DisplayGradebook:: display_header_reduce_flatview(
  245. $cat[0],
  246. $showeval,
  247. $showlink,
  248. $simple_search_form
  249. );
  250. $flatviewtable->display();
  251. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  252. DisplayGradebook:: display_header_reduce_flatview(
  253. $cat[0],
  254. $showeval,
  255. $showlink,
  256. $simple_search_form
  257. );
  258. // Table
  259. $flatviewtable->display();
  260. //@todo load images with jquery
  261. echo '<div id="contentArea" style="text-align: center;" >';
  262. $flatviewtable->display_graph_by_resource();
  263. echo '</div>';
  264. }
  265. Display :: display_footer();