gradebook_flatview.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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']),
  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']) &&
  177. $_GET['export_report'] == 'export_report'
  178. ) {
  179. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach() || $isDrhOfCourse) {
  180. $user_id = null;
  181. if (empty($_SESSION['export_user_fields'])) {
  182. $_SESSION['export_user_fields'] = false;
  183. }
  184. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  185. $user_id = api_get_user_id();
  186. }
  187. $printable_data = GradebookUtils::get_printable_data(
  188. $cat[0],
  189. $users,
  190. $alleval,
  191. $alllinks,
  192. $params,
  193. $mainCourseCategory[0]
  194. );
  195. switch ($_GET['export_format']) {
  196. case 'xls':
  197. $export = new GradeBookResult();
  198. $export->exportCompleteReportXLS($printable_data);
  199. break;
  200. case 'doc':
  201. $export = new GradeBookResult();
  202. $export->exportCompleteReportDOC($printable_data);
  203. exit;
  204. break;
  205. case 'csv':
  206. default:
  207. $export = new GradeBookResult();
  208. $export->exportCompleteReportCSV($printable_data);
  209. exit;
  210. break;
  211. }
  212. } else {
  213. api_not_allowed(true);
  214. }
  215. }
  216. $this_section = SECTION_COURSES;
  217. if (isset($_GET['exportpdf'])) {
  218. $export_pdf_form->display();
  219. } else {
  220. Display :: display_header(get_lang('FlatView'));
  221. }
  222. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  223. DisplayGradebook:: display_header_reduce_flatview(
  224. $cat[0],
  225. $showeval,
  226. $showlink,
  227. $simple_search_form
  228. );
  229. $flatviewtable->display();
  230. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  231. DisplayGradebook:: display_header_reduce_flatview(
  232. $cat[0],
  233. $showeval,
  234. $showlink,
  235. $simple_search_form
  236. );
  237. // Table
  238. $flatviewtable->display();
  239. //@todo load images with jquery
  240. echo '<div id="contentArea" style="text-align: center;" >';
  241. $flatviewtable->display_graph_by_resource();
  242. echo '</div>';
  243. }
  244. Display :: display_footer();