gradebook_flatview.php 6.4 KB

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