gradebook_flatview.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. require_once 'lib/be.inc.php';
  13. require_once 'lib/gradebook_functions.inc.php';
  14. require_once 'lib/fe/dataform.class.php';
  15. require_once 'lib/fe/userform.class.php';
  16. require_once 'lib/flatview_data_generator.class.php';
  17. require_once 'lib/fe/flatviewtable.class.php';
  18. require_once 'lib/fe/displaygradebook.php';
  19. require_once 'lib/fe/exportgradebook.php';
  20. require_once 'lib/scoredisplay.class.php';
  21. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  22. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  23. if (!class_exists('HTML_Table')) { require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.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. if (isset ($_GET['exportpdf'])) {
  80. $interbreadcrumb[] = array (
  81. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  82. 'name' => get_lang('FlatView')
  83. );
  84. $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', '');
  85. if ($export_pdf_form->validate()) {
  86. // Beginning of PDF report creation
  87. $printable_data = get_printable_data($users, $alleval, $alllinks);
  88. $export = $export_pdf_form->exportValues();
  89. // Reading report's CSS
  90. //$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  91. $css_file = api_get_path(SYS_CODE_PATH).'gradebook/print.css';
  92. $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
  93. // HTML report creation first
  94. $time = time();
  95. $cat_name = trim($cat[0]->get_name());
  96. $course_code = trim($cat[0]->get_course_code());
  97. $report_name = $course_code;
  98. if (!empty($cat_name) && $report_name != $cat_name) {
  99. $report_name .= ' - '.$cat_name;
  100. }
  101. $organization = api_get_setting('Institution');
  102. $creator = api_get_person_name($GLOBALS['_user']['firstName'], $GLOBALS['_user']['lastName']);
  103. $html = '';
  104. if (!empty($organization)) {
  105. $html .= '<h2 align="center">'.$organization.'</h2>';
  106. }
  107. $html .= '<h1 align="center">'.get_lang('FlatView').'</h1>';
  108. $html .= '<p><strong>'.$report_name.'</strong></p>';
  109. $html .= '<p><strong>'.api_convert_and_format_date(date('Y-m-d', time()), 2).'</strong></p>';
  110. $html .= '<p><strong>'.get_lang('By').': '.$creator.'</strong></p>';
  111. $columns = count($printable_data[0]);
  112. $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
  113. if (api_is_western_name_order()) {
  114. // Choosing the right person name order according to the current language.
  115. list($printable_data[0][0], $printable_data[0][1]) = array($printable_data[0][1], $printable_data[0][0]);
  116. if ($has_data) {
  117. foreach ($printable_data[1] as &$printable_data_row) {
  118. list($printable_data_row[0], $printable_data_row[1]) = array($printable_data_row[1], $printable_data_row[0]);
  119. }
  120. }
  121. }
  122. $table = new HTML_Table(array('class' => 'data_table'));
  123. $row = 0;
  124. $column = 0;
  125. foreach ($printable_data[0] as $printable_data_cell) {
  126. $table->setHeaderContents($row, $column, $printable_data_cell);
  127. $column++;
  128. }
  129. $row++;
  130. if ($has_data) {
  131. foreach ($printable_data[1] as &$printable_data_row) {
  132. $column = 0;
  133. foreach ($printable_data_row as &$printable_data_cell) {
  134. $table->setCellContents($row, $column, $printable_data_cell);
  135. $table->updateCellAttributes($row, $column, 'align="center"');
  136. $column++;
  137. }
  138. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  139. $row++;
  140. }
  141. } else {
  142. $column = 0;
  143. $table->setCellContents($row, $column, get_lang('NoResults'));
  144. $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
  145. }
  146. $html .= $table->toHtml();
  147. $html .= '<pagefooter name="myFooter1" content-left="My Book Title" content-center="myFooter1" content-right="{PAGENO}" footer-style="font-family:sans-serif; font-size:8pt; font-weight:bold; color:#008800;" footer-style-left="" line="on" />';
  148. // Memory release
  149. unset($printable_data);
  150. unset($table);
  151. // Conversion of the created HTML report to a PDF report
  152. $html = api_utf8_encode($html);
  153. //@todo this is really a must?
  154. $creator_pdf = api_utf8_encode($creator);
  155. $title_pdf = api_utf8_encode($report_name);
  156. $subject_pdf = api_utf8_encode(get_lang('FlatView'));
  157. $keywods_pdf = api_utf8_encode($course_code);
  158. $page_format = $export['orientation'] == 'landscape' ? 'A4-L' : 'A4';
  159. $pdf = new PDF($page_format, $export['orientation']);
  160. // Sending the created PDF report to the client
  161. $file_name = date('YmdHi_', $time);
  162. if (!empty($course_code)) {
  163. $file_name .= $course_code.'_';
  164. }
  165. $file_name .= get_lang('FlatView').'.pdf';
  166. $pdf->content_to_pdf($html, $css, $file_name);
  167. exit;
  168. /*
  169. $pdf->SetAuthor($creator_pdf);
  170. $pdf->SetTitle($title_pdf);
  171. $pdf->SetSubject($subject_pdf);
  172. $pdf->SetKeywords($keywods_pdf);*/
  173. } else {
  174. Display :: display_header(get_lang('ExportPDF'));
  175. }
  176. }
  177. if (isset ($_GET['print'])) {
  178. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  179. echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
  180. exit;
  181. }
  182. if (!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  183. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  184. $user_id = null;
  185. if (empty($_SESSION['export_user_fields'])) {
  186. $_SESSION['export_user_fields'] = false;
  187. }
  188. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  189. $user_id = api_get_user_id();
  190. }
  191. require_once 'gradebook_result.class.php';
  192. $printable_data = get_printable_data($users, $alleval, $alllinks);
  193. switch($_POST['export_format']) {
  194. case 'xls':
  195. $export = new GradeBookResult();
  196. $export->exportCompleteReportXLS($printable_data);
  197. exit;
  198. break;
  199. case 'doc':
  200. $export = new GradeBookResult();
  201. $export->exportCompleteReportDOC($printable_data);
  202. exit;
  203. break;
  204. case 'csv':
  205. default:
  206. $export = new GradeBookResult();
  207. $export->exportCompleteReportCSV($printable_data);
  208. exit;
  209. break;
  210. }
  211. } else {
  212. api_not_allowed(true);
  213. }
  214. }
  215. $addparams = array ('selectcat' => $cat[0]->get_id());
  216. if (isset($_GET['search'])) {
  217. $addparams['search'] = $keyword;
  218. }
  219. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  220. $flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
  221. $this_section = SECTION_COURSES;
  222. if (isset($_GET['exportpdf'])) {
  223. echo '<div class="normal-message">';
  224. $export_pdf_form->display();
  225. echo '</div>';
  226. } else {
  227. Display :: display_header(get_lang('FlatView'));
  228. }
  229. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  230. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  231. $flatviewtable->display();
  232. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  233. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  234. // main graph
  235. $flatviewtable->display();
  236. // @todo this needs a fix
  237. //$image_file = $flatviewtable->display_graph();
  238. //@todo load images with jquery
  239. echo '<div id="contentArea" style="text-align: center;" >';
  240. if (!empty($image_file)) {
  241. echo '<img src="'.$image_file.'">';
  242. }
  243. $flatviewtable->display_graph_by_resource();
  244. echo '</div>';
  245. }
  246. Display :: display_footer();