gradebook_flatview.php 7.9 KB

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