gradebook_flatview.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. api_block_anonymous_users();
  21. block_students();
  22. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  23. header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  24. exit;
  25. }
  26. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  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 = find_students($keyword);
  74. } else {
  75. if (isset($alleval) && isset($alllinks)) {
  76. $users = get_all_users($alleval, $alllinks);
  77. } else {
  78. $users = null;
  79. }
  80. }
  81. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  82. //$flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
  83. $mainCourseCategory = Category::load(null, null, api_get_course_id(), null, null, api_get_session_id());
  84. $flatviewtable = new FlatViewTable(
  85. $cat[0],
  86. $users,
  87. $alleval,
  88. $alllinks,
  89. true,
  90. $offset,
  91. $addparams,
  92. $mainCourseCategory[0]
  93. );
  94. $parameters=array('selectcat'=>intval($_GET['selectcat']));
  95. $flatviewtable->set_additional_parameters($parameters);
  96. $params = array();
  97. if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
  98. $params['only_total_category'] = true;
  99. $params['join_firstname_lastname'] = true;
  100. $params['show_official_code'] = true;
  101. $params['export_pdf'] = true;
  102. if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
  103. Display :: set_header(null, false, false);
  104. export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
  105. }
  106. }
  107. if (isset($_GET['exportpdf'])) {
  108. $interbreadcrumb[] = array (
  109. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  110. 'name' => get_lang('FlatView')
  111. );
  112. $export_pdf_form = new DataForm(
  113. DataForm::TYPE_EXPORT_PDF,
  114. 'export_pdf_form',
  115. null,
  116. api_get_self() . '?exportpdf=&offset=' . intval($_GET['offset']) . '&selectcat=' . intval($_GET['selectcat']),
  117. '_blank',
  118. ''
  119. );
  120. if ($export_pdf_form->validate()) {
  121. $params = $export_pdf_form->exportValues();
  122. Display :: set_header(null, false, false);
  123. $params['join_firstname_lastname'] = true;
  124. $params['show_official_code'] = true;
  125. $params['export_pdf'] = true;
  126. $params['only_total_category'] = false;
  127. export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params, $mainCourseCategory[0]);
  128. } else {
  129. Display :: display_header(get_lang('ExportPDF'));
  130. }
  131. }
  132. if (isset ($_GET['print'])) {
  133. $printable_data = get_printable_data(
  134. $cat[0],
  135. $users,
  136. $alleval,
  137. $alllinks,
  138. $params,
  139. $mainCourseCategory[0]
  140. );
  141. echo print_table(
  142. $printable_data[1],
  143. $printable_data[0],
  144. get_lang('FlatView'),
  145. $cat[0]->get_name()
  146. );
  147. exit;
  148. }
  149. if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
  150. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  151. $user_id = null;
  152. if (empty($_SESSION['export_user_fields'])) {
  153. $_SESSION['export_user_fields'] = false;
  154. }
  155. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  156. $user_id = api_get_user_id();
  157. }
  158. require_once 'gradebook_result.class.php';
  159. $printable_data = get_printable_data(
  160. $cat[0],
  161. $users,
  162. $alleval,
  163. $alllinks,
  164. $params,
  165. $mainCourseCategory[0]
  166. );
  167. switch($_GET['export_format']) {
  168. case 'xls':
  169. $export = new GradeBookResult();
  170. $export->exportCompleteReportXLS($printable_data);
  171. break;
  172. case 'doc':
  173. $export = new GradeBookResult();
  174. $export->exportCompleteReportDOC($printable_data);
  175. exit;
  176. break;
  177. case 'csv':
  178. default:
  179. $export = new GradeBookResult();
  180. $export->exportCompleteReportCSV($printable_data);
  181. exit;
  182. break;
  183. }
  184. } else {
  185. api_not_allowed(true);
  186. }
  187. }
  188. $addparams = array ('selectcat' => $cat[0]->get_id());
  189. if (isset($_GET['search'])) {
  190. $addparams['search'] = $keyword;
  191. }
  192. $this_section = SECTION_COURSES;
  193. if (isset($_GET['exportpdf'])) {
  194. $export_pdf_form->display();
  195. } else {
  196. Display :: display_header(get_lang('FlatView'));
  197. }
  198. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  199. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  200. $flatviewtable->display();
  201. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  202. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  203. // main graph
  204. $flatviewtable->display();
  205. // @todo this needs a fix
  206. //$image_file = $flatviewtable->display_graph();
  207. //@todo load images with jquery
  208. echo '<div id="contentArea" style="text-align: center;" >';
  209. if (!empty($image_file)) {
  210. echo '<img src="'.$image_file.'">';
  211. }
  212. $flatviewtable->display_graph_by_resource();
  213. echo '</div>';
  214. }
  215. Display :: display_footer();