gradebook_flatview.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once '../inc/global.inc.php';
  8. $current_course_tool = TOOL_GRADEBOOK;
  9. api_protect_course_script(true);
  10. api_block_anonymous_users();
  11. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  12. api_get_user_id(),
  13. api_get_course_info()
  14. );
  15. if (!$isDrhOfCourse) {
  16. GradebookUtils::block_students();
  17. }
  18. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  19. header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  20. exit;
  21. }
  22. $interbreadcrumb[] = array(
  23. 'url' => $_SESSION['gradebook_dest'].'?selectcat=1',
  24. 'name' => get_lang('ToolGradebook')
  25. );
  26. $showeval = isset($_POST['showeval']) ? '1' : '0';
  27. $showlink = isset($_POST['showlink']) ? '1' : '0';
  28. if (($showlink == '0') && ($showeval == '0')) {
  29. $showlink = '1';
  30. $showeval = '1';
  31. }
  32. $cat = Category::load($_REQUEST['selectcat']);
  33. if (isset($_GET['userid'])) {
  34. $userid = Security::remove_XSS($_GET['userid']);
  35. } else {
  36. $userid = '';
  37. }
  38. if ($showeval) {
  39. $alleval = $cat[0]->get_evaluations($userid, true);
  40. } else {
  41. $alleval = null;
  42. }
  43. if ($showlink) {
  44. $alllinks = $cat[0]->get_links($userid, true);
  45. } else {
  46. $alllinks = null;
  47. }
  48. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  49. Display :: display_normal_message($export_flatview_form->toHtml(), false);
  50. }
  51. if (isset($_GET['selectcat'])) {
  52. $category_id = Security::remove_XSS($_GET['selectcat']);
  53. } else {
  54. $category_id = '';
  55. }
  56. $simple_search_form = new UserForm(
  57. UserForm :: TYPE_SIMPLE_SEARCH,
  58. null,
  59. 'simple_search_form',
  60. null,
  61. api_get_self() . '?selectcat=' . $category_id
  62. );
  63. $values = $simple_search_form->exportValues();
  64. $keyword = '';
  65. if (isset($_GET['search']) && !empty($_GET['search'])) {
  66. $keyword = Security::remove_XSS($_GET['search']);
  67. }
  68. if ($simple_search_form->validate() && (empty($keyword))) {
  69. $keyword = $values['keyword'];
  70. }
  71. if (!empty($keyword)) {
  72. $users = GradebookUtils::find_students($keyword);
  73. } else {
  74. if (isset($alleval) && isset($alllinks)) {
  75. $users = GradebookUtils::get_all_users($alleval, $alllinks);
  76. } else {
  77. $users = null;
  78. }
  79. }
  80. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  81. $addparams = array('selectcat' => $cat[0]->get_id());
  82. if (isset($_GET['search'])) {
  83. $addparams['search'] = $keyword;
  84. }
  85. // Main course category
  86. $mainCourseCategory = Category::load(
  87. null,
  88. null,
  89. api_get_course_id(),
  90. null,
  91. null,
  92. api_get_session_id()
  93. );
  94. $flatviewtable = new FlatViewTable(
  95. $cat[0],
  96. $users,
  97. $alleval,
  98. $alllinks,
  99. true,
  100. $offset,
  101. $addparams,
  102. $mainCourseCategory[0]
  103. );
  104. $flatviewtable->setAutoFill(false);
  105. $parameters = array('selectcat' => intval($_GET['selectcat']));
  106. $flatviewtable->set_additional_parameters($parameters);
  107. $params = array();
  108. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  109. $params['only_total_category'] = true;
  110. $params['join_firstname_lastname'] = true;
  111. $params['show_official_code'] = true;
  112. $params['export_pdf'] = true;
  113. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  114. Display :: set_header(null, false, false);
  115. GradebookUtils::export_pdf_flatview(
  116. $flatviewtable,
  117. $cat,
  118. $users,
  119. $alleval,
  120. $alllinks,
  121. $params,
  122. $mainCourseCategory[0]
  123. );
  124. }
  125. }
  126. if (isset($_GET['exportpdf'])) {
  127. $interbreadcrumb[] = array (
  128. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']).'&'.api_get_cidreq(),
  129. 'name' => get_lang('FlatView')
  130. );
  131. $pageNum = isset($_GET['flatviewlist_page_nr']) ? intval($_GET['flatviewlist_page_nr']) : '';
  132. $perPage = isset($_GET['flatviewlist_per_page']) ? intval($_GET['flatviewlist_per_page']) : '';
  133. $url = api_get_self().'?exportpdf=&offset='.$offset.'&selectcat='.intval($_GET['selectcat']).'&'.api_get_cidreq().'&flatviewlist_page_nr='.$pageNum.'&flatviewlist_per_page='.$perPage;
  134. $export_pdf_form = new DataForm(
  135. DataForm::TYPE_EXPORT_PDF,
  136. 'export_pdf_form',
  137. null,
  138. $url,
  139. '_blank',
  140. ''
  141. );
  142. if ($export_pdf_form->validate()) {
  143. $params = $export_pdf_form->exportValues();
  144. Display :: set_header(null, false, false);
  145. $params['join_firstname_lastname'] = true;
  146. $params['show_official_code'] = true;
  147. $params['export_pdf'] = true;
  148. $params['only_total_category'] = false;
  149. GradebookUtils::export_pdf_flatview(
  150. $flatviewtable,
  151. $cat,
  152. $users,
  153. $alleval,
  154. $alllinks,
  155. $params,
  156. $mainCourseCategory[0]
  157. );
  158. } else {
  159. Display :: display_header(get_lang('ExportPDF'));
  160. }
  161. }
  162. if (isset($_GET['print'])) {
  163. $printable_data = GradebookUtils::get_printable_data(
  164. $cat[0],
  165. $users,
  166. $alleval,
  167. $alllinks,
  168. $params,
  169. $mainCourseCategory[0]
  170. );
  171. echo print_table(
  172. $printable_data[1],
  173. $printable_data[0],
  174. get_lang('FlatView'),
  175. $cat[0]->get_name()
  176. );
  177. exit;
  178. }
  179. if (!empty($_GET['export_report']) &&
  180. $_GET['export_report'] == 'export_report'
  181. ) {
  182. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
  183. $user_id = null;
  184. if (empty($_SESSION['export_user_fields'])) {
  185. $_SESSION['export_user_fields'] = false;
  186. }
  187. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  188. $user_id = api_get_user_id();
  189. }
  190. $printable_data = GradebookUtils::get_printable_data(
  191. $cat[0],
  192. $users,
  193. $alleval,
  194. $alllinks,
  195. $params,
  196. $mainCourseCategory[0]
  197. );
  198. switch ($_GET['export_format']) {
  199. case 'xls':
  200. $export = new GradeBookResult();
  201. $export->exportCompleteReportXLS($printable_data);
  202. break;
  203. case 'doc':
  204. $export = new GradeBookResult();
  205. $export->exportCompleteReportDOC($printable_data);
  206. exit;
  207. break;
  208. case 'csv':
  209. default:
  210. $export = new GradeBookResult();
  211. $export->exportCompleteReportCSV($printable_data);
  212. exit;
  213. break;
  214. }
  215. } else {
  216. api_not_allowed(true);
  217. }
  218. }
  219. $this_section = SECTION_COURSES;
  220. if (isset($_GET['exportpdf'])) {
  221. $export_pdf_form->display();
  222. } else {
  223. Display :: display_header(get_lang('FlatView'));
  224. }
  225. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  226. DisplayGradebook:: display_header_reduce_flatview(
  227. $cat[0],
  228. $showeval,
  229. $showlink,
  230. $simple_search_form
  231. );
  232. $flatviewtable->display();
  233. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  234. DisplayGradebook:: display_header_reduce_flatview(
  235. $cat[0],
  236. $showeval,
  237. $showlink,
  238. $simple_search_form
  239. );
  240. // Table
  241. $flatviewtable->display();
  242. //@todo load images with jquery
  243. echo '<div id="contentArea" style="text-align: center;" >';
  244. $flatviewtable->display_graph_by_resource();
  245. echo '</div>';
  246. }
  247. Display :: display_footer();