gradebook_flatview.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. require_once 'lib/be.inc.php';
  12. require_once 'lib/fe/dataform.class.php';
  13. require_once 'lib/fe/userform.class.php';
  14. require_once 'lib/flatview_data_generator.class.php';
  15. require_once 'lib/fe/flatviewtable.class.php';
  16. require_once 'lib/fe/displaygradebook.php';
  17. require_once 'lib/fe/exportgradebook.php';
  18. require_once 'lib/scoredisplay.class.php';
  19. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  20. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  21. api_block_anonymous_users();
  22. block_students();
  23. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  24. header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  25. exit;
  26. }
  27. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  28. $showeval = isset($_POST['showeval']) ? '1' : '0';
  29. $showlink = isset($_POST['showlink']) ? '1' : '0';
  30. if (($showlink == '0') && ($showeval == '0')) {
  31. $showlink = '1';
  32. $showeval = '1';
  33. }
  34. $cat = Category::load($_REQUEST['selectcat']);
  35. if (isset($_GET['userid'])) {
  36. $userid = Security::remove_XSS($_GET['userid']);
  37. } else {
  38. $userid = '';
  39. }
  40. if ($showeval) {
  41. $alleval = $cat[0]->get_evaluations($userid, true);
  42. } else {
  43. $alleval = null;
  44. }
  45. if ($showlink) {
  46. $alllinks = $cat[0]->get_links($userid, true);
  47. } else {
  48. $alllinks = null;
  49. }
  50. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  51. Display :: display_normal_message($export_flatview_form->toHtml(), false);
  52. }
  53. if (isset($_GET['selectcat'])) {
  54. $category_id = Security::remove_XSS($_GET['selectcat']);
  55. } else {
  56. $category_id = '';
  57. }
  58. $simple_search_form = new UserForm(
  59. UserForm :: TYPE_SIMPLE_SEARCH,
  60. null,
  61. 'simple_search_form',
  62. null,
  63. api_get_self() . '?selectcat=' . $category_id
  64. );
  65. $values = $simple_search_form->exportValues();
  66. $keyword = '';
  67. if (isset($_GET['search']) && !empty($_GET['search'])) {
  68. $keyword = Security::remove_XSS($_GET['search']);
  69. }
  70. if ($simple_search_form->validate() && (empty($keyword))) {
  71. $keyword = $values['keyword'];
  72. }
  73. if (!empty($keyword)) {
  74. $users = find_students($keyword);
  75. } else {
  76. if (isset($alleval) && isset($alllinks)) {
  77. $users = get_all_users($alleval, $alllinks);
  78. } else {
  79. $users = null;
  80. }
  81. }
  82. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  83. // Main course category
  84. $mainCourseCategory = Category::load(null, null, api_get_course_id(), null, null, api_get_session_id());
  85. $flatviewtable = new FlatViewTable(
  86. $cat[0],
  87. $users,
  88. $alleval,
  89. $alllinks,
  90. true,
  91. $offset,
  92. $addparams,
  93. $mainCourseCategory[0]
  94. );
  95. $parameters = array('selectcat' => intval($_GET['selectcat']));
  96. $flatviewtable->set_additional_parameters($parameters);
  97. $params = array();
  98. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  99. $params['only_total_category'] = true;
  100. $params['join_firstname_lastname'] = true;
  101. $params['show_official_code'] = true;
  102. $params['export_pdf'] = true;
  103. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  104. Display :: set_header(null, false, false);
  105. export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
  106. }
  107. }
  108. if (isset($_GET['exportpdf'])) {
  109. $interbreadcrumb[] = array (
  110. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  111. 'name' => get_lang('FlatView')
  112. );
  113. $export_pdf_form = new DataForm(
  114. DataForm::TYPE_EXPORT_PDF,
  115. 'export_pdf_form',
  116. null,
  117. api_get_self() . '?exportpdf=&offset=' . intval($_GET['offset']) . '&selectcat=' . intval($_GET['selectcat']),
  118. '_blank',
  119. ''
  120. );
  121. if ($export_pdf_form->validate()) {
  122. $params = $export_pdf_form->exportValues();
  123. Display :: set_header(null, false, false);
  124. $params['join_firstname_lastname'] = true;
  125. $params['show_official_code'] = true;
  126. $params['export_pdf'] = true;
  127. $params['only_total_category'] = false;
  128. export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
  129. } else {
  130. Display :: display_header(get_lang('ExportPDF'));
  131. }
  132. }
  133. if (isset($_GET['print'])) {
  134. $printable_data = get_printable_data(
  135. $cat[0],
  136. $users,
  137. $alleval,
  138. $alllinks,
  139. $params,
  140. $mainCourseCategory[0]
  141. );
  142. echo print_table(
  143. $printable_data[1],
  144. $printable_data[0],
  145. get_lang('FlatView'),
  146. $cat[0]->get_name()
  147. );
  148. exit;
  149. }
  150. if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
  151. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  152. $user_id = null;
  153. if (empty($_SESSION['export_user_fields'])) {
  154. $_SESSION['export_user_fields'] = false;
  155. }
  156. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  157. $user_id = api_get_user_id();
  158. }
  159. require_once 'gradebook_result.class.php';
  160. $printable_data = get_printable_data(
  161. $cat[0],
  162. $users,
  163. $alleval,
  164. $alllinks,
  165. $params,
  166. $mainCourseCategory[0]
  167. );
  168. switch ($_GET['export_format']) {
  169. case 'xls':
  170. $export = new GradeBookResult();
  171. $export->exportCompleteReportXLS($printable_data);
  172. break;
  173. case 'doc':
  174. $export = new GradeBookResult();
  175. $export->exportCompleteReportDOC($printable_data);
  176. exit;
  177. break;
  178. case 'csv':
  179. default:
  180. $export = new GradeBookResult();
  181. $export->exportCompleteReportCSV($printable_data);
  182. exit;
  183. break;
  184. }
  185. } else {
  186. api_not_allowed(true);
  187. }
  188. }
  189. $addparams = array ('selectcat' => $cat[0]->get_id());
  190. if (isset($_GET['search'])) {
  191. $addparams['search'] = $keyword;
  192. }
  193. $this_section = SECTION_COURSES;
  194. if (isset($_GET['exportpdf'])) {
  195. $export_pdf_form->display();
  196. } else {
  197. Display :: display_header(get_lang('FlatView'));
  198. }
  199. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  200. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  201. $flatviewtable->display();
  202. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  203. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  204. // main graph
  205. $flatviewtable->display();
  206. // @todo this needs a fix
  207. //$image_file = $flatviewtable->display_graph();
  208. //@todo load images with jquery
  209. echo '<div id="contentArea" style="text-align: center;" >';
  210. if (!empty($image_file)) {
  211. echo '<img src="'.$image_file.'">';
  212. }
  213. $flatviewtable->display_graph_by_resource();
  214. echo '</div>';
  215. }
  216. Display :: display_footer();