gradebook_flatview.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. $language_file = 'gradebook';
  8. require_once '../inc/global.inc.php';
  9. $current_course_tool = TOOL_GRADEBOOK;
  10. api_protect_course_script();
  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='.Security::remove_XSS($_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 :: display_normal_message($export_flatview_form->toHtml(), false);
  51. }
  52. if (isset($_GET['selectcat'])) {
  53. $category_id = Security::remove_XSS($_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. $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']),
  129. 'name' => get_lang('FlatView')
  130. );
  131. $export_pdf_form = new DataForm(
  132. DataForm::TYPE_EXPORT_PDF,
  133. 'export_pdf_form',
  134. null,
  135. api_get_self() . '?exportpdf=&offset=' . intval($_GET['offset']) . '&selectcat=' . intval($_GET['selectcat']).'&'.api_get_cidreq(),
  136. '_blank',
  137. ''
  138. );
  139. if ($export_pdf_form->validate()) {
  140. $params = $export_pdf_form->exportValues();
  141. Display :: set_header(null, false, false);
  142. $params['join_firstname_lastname'] = true;
  143. $params['show_official_code'] = true;
  144. $params['export_pdf'] = true;
  145. $params['only_total_category'] = false;
  146. GradebookUtils::export_pdf_flatview(
  147. $flatviewtable,
  148. $cat,
  149. $users,
  150. $alleval,
  151. $alllinks,
  152. $params,
  153. $mainCourseCategory[0]
  154. );
  155. } else {
  156. Display :: display_header(get_lang('ExportPDF'));
  157. }
  158. }
  159. if (isset($_GET['print'])) {
  160. $printable_data = GradebookUtils::get_printable_data(
  161. $cat[0],
  162. $users,
  163. $alleval,
  164. $alllinks,
  165. $params,
  166. $mainCourseCategory[0]
  167. );
  168. echo print_table(
  169. $printable_data[1],
  170. $printable_data[0],
  171. get_lang('FlatView'),
  172. $cat[0]->get_name()
  173. );
  174. exit;
  175. }
  176. if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
  177. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
  178. $user_id = null;
  179. if (empty($_SESSION['export_user_fields'])) {
  180. $_SESSION['export_user_fields'] = false;
  181. }
  182. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  183. $user_id = api_get_user_id();
  184. }
  185. $printable_data = GradebookUtils::get_printable_data(
  186. $cat[0],
  187. $users,
  188. $alleval,
  189. $alllinks,
  190. $params,
  191. $mainCourseCategory[0]
  192. );
  193. switch ($_GET['export_format']) {
  194. case 'xls':
  195. $export = new GradeBookResult();
  196. $export->exportCompleteReportXLS($printable_data);
  197. break;
  198. case 'doc':
  199. $export = new GradeBookResult();
  200. $export->exportCompleteReportDOC($printable_data);
  201. exit;
  202. break;
  203. case 'csv':
  204. default:
  205. $export = new GradeBookResult();
  206. $export->exportCompleteReportCSV($printable_data);
  207. exit;
  208. break;
  209. }
  210. } else {
  211. api_not_allowed(true);
  212. }
  213. }
  214. $this_section = SECTION_COURSES;
  215. if (isset($_GET['exportpdf'])) {
  216. $export_pdf_form->display();
  217. } else {
  218. Display :: display_header(get_lang('FlatView'));
  219. }
  220. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  221. DisplayGradebook:: display_header_reduce_flatview(
  222. $cat[0],
  223. $showeval,
  224. $showlink,
  225. $simple_search_form
  226. );
  227. $flatviewtable->display();
  228. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  229. DisplayGradebook:: display_header_reduce_flatview(
  230. $cat[0],
  231. $showeval,
  232. $showlink,
  233. $simple_search_form
  234. );
  235. // main graph
  236. $flatviewtable->display();
  237. //@todo load images with jquery
  238. echo '<div id="contentArea" style="text-align: center;" >';
  239. if (!empty($image_file)) {
  240. echo '<img src="'.$image_file.'">';
  241. }
  242. $flatviewtable->display_graph_by_resource();
  243. echo '</div>';
  244. }
  245. Display :: display_footer();