gradebook_flatview.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = 'gradebook';
  4. //$cidReset= true;
  5. require_once '../inc/global.inc.php';
  6. require_once 'lib/be.inc.php';
  7. require_once 'lib/gradebook_functions.inc.php';
  8. require_once 'lib/fe/dataform.class.php';
  9. require_once 'lib/fe/userform.class.php';
  10. require_once 'lib/flatview_data_generator.class.php';
  11. require_once 'lib/fe/flatviewtable.class.php';
  12. require_once 'lib/fe/displaygradebook.php';
  13. require_once 'lib/fe/exportgradebook.php';
  14. require_once 'lib/scoredisplay.class.php';
  15. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  16. require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  17. if (!class_exists('HTML_Table')) { require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php'; }
  18. api_block_anonymous_users();
  19. block_students();
  20. if (isset ($_POST['submit']) && isset ($_POST['keyword'])) {
  21. header('Location: '.api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&search='.Security::remove_XSS($_POST['keyword']));
  22. exit;
  23. }
  24. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  25. $showeval = isset($_POST['showeval']) ? '1' : '0';
  26. $showlink = isset($_POST['showlink']) ? '1' : '0';
  27. if (($showlink == '0') && ($showeval == '0')) {
  28. $showlink = '1';
  29. $showeval = '1';
  30. }
  31. $cat = Category::load($_REQUEST['selectcat']);
  32. if (isset($_GET['userid'])) {
  33. $userid = Security::remove_XSS($_GET['userid']);
  34. } else {
  35. $userid = '';
  36. }
  37. if ($showeval) {
  38. $alleval = $cat[0]->get_evaluations($userid, true);
  39. } else {
  40. $alleval = null;
  41. }
  42. if ($showlink) {
  43. $alllinks = $cat[0]->get_links($userid, true);
  44. } else {
  45. $alllinks = null;
  46. }
  47. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  48. Display :: display_normal_message($export_flatview_form->toHtml(), false);
  49. }
  50. if (isset($_GET['selectcat'])) {
  51. $category_id = Security::remove_XSS($_GET['selectcat']);
  52. } else {
  53. $category_id = '';
  54. }
  55. $simple_search_form = new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $category_id);
  56. $values = $simple_search_form->exportValues();
  57. $keyword = '';
  58. if (isset($_GET['search']) && !empty($_GET['search'])) {
  59. $keyword = Security::remove_XSS($_GET['search']);
  60. }
  61. if ($simple_search_form->validate() && (empty($keyword))) {
  62. $keyword = $values['keyword'];
  63. }
  64. if (!empty($keyword)) {
  65. $users = find_students($keyword);
  66. } else {
  67. if (isset($alleval) && isset($alllinks)) {
  68. $users = get_all_users($alleval, $alllinks);
  69. } else {
  70. $users = null;
  71. }
  72. }
  73. if (isset ($_GET['exportpdf'])) {
  74. $interbreadcrumb[] = array (
  75. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  76. 'name' => get_lang('FlatView')
  77. );
  78. $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', '');
  79. if ($export_pdf_form->validate()) {
  80. // Beginning of PDF report creation
  81. $printable_data = get_printable_data($users, $alleval, $alllinks);
  82. $export = $export_pdf_form->exportValues();
  83. // Reading report's CSS
  84. //$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  85. $css_file = api_get_path(SYS_CODE_PATH).'gradebook/print.css';
  86. $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
  87. // HTML report creation first
  88. $time = time();
  89. $cat_name = trim($cat[0]->get_name());
  90. $course_code = trim($cat[0]->get_course_code());
  91. $report_name = $course_code;
  92. if (!empty($cat_name) && $report_name != $cat_name) {
  93. $report_name .= ' - '.$cat_name;
  94. }
  95. $organization = api_get_setting('Institution');
  96. $creator = api_get_person_name($GLOBALS['_user']['firstName'], $GLOBALS['_user']['lastName']);
  97. $html = '';
  98. if (!empty($organization)) {
  99. $html .= '<h2 align="center">'.$organization.'</h2>';
  100. }
  101. $html .= '<h1 align="center">'.get_lang('FlatView').'</h1>';
  102. $html .= '<p><strong>'.$report_name.'</strong></p>';
  103. $html .= '<p><strong>'.api_convert_and_format_date(date('Y-m-d', time()), 2).'</strong></p>';
  104. $html .= '<p><strong>'.get_lang('By').': '.$creator.'</strong></p>';
  105. $columns = count($printable_data[0]);
  106. $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
  107. if (api_is_western_name_order()) {
  108. // Choosing the right person name order according to the current language.
  109. list($printable_data[0][0], $printable_data[0][1]) = array($printable_data[0][1], $printable_data[0][0]);
  110. if ($has_data) {
  111. foreach ($printable_data[1] as &$printable_data_row) {
  112. list($printable_data_row[0], $printable_data_row[1]) = array($printable_data_row[1], $printable_data_row[0]);
  113. }
  114. }
  115. }
  116. $table = new HTML_Table(array('class' => 'data_table'));
  117. $row = 0;
  118. $column = 0;
  119. foreach ($printable_data[0] as $printable_data_cell) {
  120. $table->setHeaderContents($row, $column, $printable_data_cell);
  121. $column++;
  122. }
  123. $row++;
  124. if ($has_data) {
  125. foreach ($printable_data[1] as &$printable_data_row) {
  126. $column = 0;
  127. foreach ($printable_data_row as &$printable_data_cell) {
  128. $table->setCellContents($row, $column, $printable_data_cell);
  129. $table->updateCellAttributes($row, $column, 'align="center"');
  130. $column++;
  131. }
  132. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  133. $row++;
  134. }
  135. } else {
  136. $column = 0;
  137. $table->setCellContents($row, $column, get_lang('NoResults'));
  138. $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
  139. }
  140. $html .= $table->toHtml();
  141. $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" />';
  142. // Memory release
  143. unset($printable_data);
  144. unset($table);
  145. // Conversion of the created HTML report to a PDF report
  146. $html = api_utf8_encode($html);
  147. //@todo this is really a must?
  148. $creator_pdf = api_utf8_encode($creator);
  149. $title_pdf = api_utf8_encode($report_name);
  150. $subject_pdf = api_utf8_encode(get_lang('FlatView'));
  151. $keywods_pdf = api_utf8_encode($course_code);
  152. $page_format = $export['orientation'] == 'landscape' ? 'A4-L' : 'A4';
  153. $pdf = new PDF($page_format, $export['orientation']);
  154. // Sending the created PDF report to the client
  155. $file_name = date('YmdHi_', $time);
  156. if (!empty($course_code)) {
  157. $file_name .= $course_code.'_';
  158. }
  159. $file_name .= get_lang('FlatView').'.pdf';
  160. $pdf->content_to_pdf($html, $css, $file_name);
  161. exit;
  162. /*
  163. $pdf->SetAuthor($creator_pdf);
  164. $pdf->SetTitle($title_pdf);
  165. $pdf->SetSubject($subject_pdf);
  166. $pdf->SetKeywords($keywods_pdf);*/
  167. } else {
  168. Display :: display_header(get_lang('ExportPDF'));
  169. }
  170. }
  171. if (isset ($_GET['print'])) {
  172. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  173. echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
  174. exit;
  175. }
  176. if (!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  177. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  178. $user_id = null;
  179. if (empty($_SESSION['export_user_fields'])) {
  180. $_SESSION['export_user_fields'] = false;
  181. }
  182. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  183. $user_id = api_get_user_id();
  184. }
  185. require_once 'gradebook_result.class.php';
  186. $printable_data = get_printable_data($users, $alleval, $alllinks);
  187. switch($_POST['export_format']) {
  188. case 'xls':
  189. $export = new GradeBookResult();
  190. $export->exportCompleteReportXLS($printable_data);
  191. exit;
  192. break;
  193. case 'csv':
  194. default:
  195. $export = new GradeBookResult();
  196. $export->exportCompleteReportCSV($printable_data);
  197. exit;
  198. break;
  199. }
  200. } else {
  201. api_not_allowed(true);
  202. }
  203. }
  204. $addparams = array ('selectcat' => $cat[0]->get_id());
  205. if (isset($_GET['search'])) {
  206. $addparams['search'] = $keyword;
  207. }
  208. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  209. $flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
  210. $this_section = SECTION_COURSES;
  211. if (isset($_GET['exportpdf'])) {
  212. echo '<div class="normal-message">';
  213. $export_pdf_form->display();
  214. echo '</div>';
  215. } else {
  216. Display :: display_header(get_lang('FlatView'));
  217. }
  218. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  219. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  220. $flatviewtable->display();
  221. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  222. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  223. /*echo '<div id="contentLoading" class="contentLoading">';
  224. echo Display::display_icon('loader.gif');
  225. echo '</div>';*/
  226. // main graph
  227. $flatviewtable->display();
  228. $image_file = $flatviewtable->display_graph();
  229. $my_info_path_img = array();
  230. $my_info_path_img = explode('/', $image_file);
  231. if (strlen($my_info_path_img[5]) == 32) {
  232. echo '<img src="'.$image_file.'">';
  233. }
  234. //@todo load images with jquery
  235. echo '<div id="contentArea" style="text-align:center;" >';
  236. $flatviewtable->display_graph_by_resource();
  237. echo '</div>';
  238. }
  239. Display :: display_footer();