gradebook_flatview.php 6.3 KB

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