gradebook_flatview.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php // $Id: $
  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).'ezpdf/class.ezpdf.php'; // This is the old library for pdf-export (non UTF-8 compatible).
  17. define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
  18. require_once _MPDF_PATH.'mpdf.php';
  19. if (!class_exists('HTML_Table')) { require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.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. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  27. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('Gradebook'));
  28. $showeval = isset($_POST['showeval']) ? '1' : '0';
  29. $showlink = isset($_POST['showlink']) ? '1' : '0';
  30. if (($showlink == '0') && ($showeval == '0')) {
  31. $showlink = '1';
  32. $showeval = '1';
  33. }
  34. $cat = Category::load($_REQUEST['selectcat']);
  35. if (isset($_GET['userid'])) {
  36. $userid = Security::remove_XSS($_GET['userid']);
  37. } else {
  38. $userid = '';
  39. }
  40. if ($showeval) {
  41. $alleval = $cat[0]->get_evaluations($userid, true);
  42. } else {
  43. $alleval = null;
  44. }
  45. if ($showlink) {
  46. $alllinks = $cat[0]->get_links($userid, true);
  47. } else {
  48. $alllinks = null;
  49. }
  50. if (isset($export_flatview_form) && (!$file_type == 'pdf')) {
  51. Display :: display_normal_message($export_flatview_form->toHtml(), false);
  52. }
  53. if (isset($_GET['selectcat'])) {
  54. $category_id = Security::remove_XSS($_GET['selectcat']);
  55. } else {
  56. $category_id = '';
  57. }
  58. $simple_search_form = new UserForm(UserForm :: TYPE_SIMPLE_SEARCH, null, 'simple_search_form', null, api_get_self() . '?selectcat=' . $category_id);
  59. $values = $simple_search_form->exportValues();
  60. $keyword = '';
  61. if (isset($_GET['search']) && !empty($_GET['search'])) {
  62. $keyword = Security::remove_XSS($_GET['search']);
  63. }
  64. if ($simple_search_form->validate() && (empty($keyword))) {
  65. $keyword = $values['keyword'];
  66. }
  67. if (!empty($keyword)) {
  68. $users = find_students($keyword);
  69. } else {
  70. if (isset($alleval) && isset($alllinks)) {
  71. $users = get_all_users($alleval, $alllinks);
  72. } else {
  73. $users = null;
  74. }
  75. }
  76. if (isset ($_GET['exportpdf'])) {
  77. $interbreadcrumb[] = array (
  78. 'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
  79. 'name' => get_lang('FlatView')
  80. );
  81. $export_pdf_form = new DataForm(DataForm :: TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self().'?exportpdf=&offset='.$_GET['offset'].'&selectcat='.$_GET['selectcat'], '_blank');
  82. if ($export_pdf_form->validate()) {
  83. // Beginning of PDF report creation
  84. $printable_data = get_printable_data($users, $alleval, $alllinks);
  85. $export = $export_pdf_form->exportValues();
  86. // Reading report's CSS
  87. //$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  88. $css_file = api_get_path(SYS_CODE_PATH).'gradebook/print.css';
  89. $css = file_exists($css_file) ? @file_get_contents($css_file) : '';
  90. // HTML report creation first
  91. $time = time();
  92. $cat_name = trim($cat[0]->get_name());
  93. $course_code = trim($cat[0]->get_course_code());
  94. $report_name = $course_code;
  95. if (!empty($cat_name) && $report_name != $cat_name) {
  96. $report_name .= ' - '.$cat_name;
  97. }
  98. $organization = api_get_setting('Institution');
  99. $creator = api_get_person_name($GLOBALS['_user']['firstName'], $GLOBALS['_user']['lastName']);
  100. $html = '';
  101. if (!empty($organization)) {
  102. $html .= '<h2 align="center">'.$organization.'</h2>';
  103. }
  104. $html .= '<h1 align="center">'.get_lang('FlatView').'</h1>';
  105. $html .= '<p><strong>'.$report_name.'</strong></p>';
  106. $html .= '<p><strong>'.api_convert_and_format_date().'</strong></p>';
  107. $html .= '<p><strong>'.get_lang('By').': '.$creator.'</strong></p>';
  108. $columns = count($printable_data[0]);
  109. $has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
  110. if (api_is_western_name_order()) {
  111. // Choosing the right person name order according to the current language.
  112. list($printable_data[0][0], $printable_data[0][1]) = array($printable_data[0][1], $printable_data[0][0]);
  113. if ($has_data) {
  114. foreach ($printable_data[1] as &$printable_data_row) {
  115. list($printable_data_row[0], $printable_data_row[1]) = array($printable_data_row[1], $printable_data_row[0]);
  116. }
  117. }
  118. }
  119. $table = new HTML_Table(array('class' => 'data_table'));
  120. $row = 0;
  121. $column = 0;
  122. foreach ($printable_data[0] as $printable_data_cell) {
  123. $table->setHeaderContents($row, $column, $printable_data_cell);
  124. $column++;
  125. }
  126. $row++;
  127. if ($has_data) {
  128. foreach ($printable_data[1] as &$printable_data_row) {
  129. $column = 0;
  130. foreach ($printable_data_row as &$printable_data_cell) {
  131. $table->setCellContents($row, $column, $printable_data_cell);
  132. $table->updateCellAttributes($row, $column, 'align="center"');
  133. $column++;
  134. }
  135. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  136. $row++;
  137. }
  138. } else {
  139. $column = 0;
  140. $table->setCellContents($row, $column, get_lang('NoResults'));
  141. $table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
  142. }
  143. $html .= $table->toHtml();
  144. $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" />';
  145. // Memory release
  146. unset($printable_data);
  147. unset($table);
  148. // Conversion of the created HTML report to a PDF report
  149. $html = api_utf8_encode($html);
  150. $creator_pdf = api_utf8_encode($creator);
  151. $title_pdf = api_utf8_encode($report_name);
  152. $subject_pdf = api_utf8_encode(get_lang('FlatView'));
  153. $keywods_pdf = api_utf8_encode($course_code);
  154. $pdf = new mPDF('UTF-8', 'A4', '', '', 32, 25, 27, 25, 16, 13, $export['orientation']);
  155. $pdf->directionality = api_get_text_direction();
  156. $pdf->useOnlyCoreFonts = true;
  157. $pdf->SetFooter('{PAGENO}');
  158. $pdf->SetAuthor($creator_pdf);
  159. $pdf->SetTitle($title_pdf);
  160. $pdf->SetSubject($subject_pdf);
  161. $pdf->SetKeywords($keywods_pdf);
  162. if (!empty($css)) {
  163. $pdf->WriteHTML($css, 1);
  164. $pdf->WriteHTML($html, 2);
  165. } else {
  166. $pdf->WriteHTML($html);
  167. }
  168. // Sending the created PDF report to the client
  169. $file_name = date('YmdHi_', $time);
  170. if (!empty($course_code)) {
  171. $file_name .= $course_code.'_';
  172. }
  173. $file_name .= get_lang('FlatView').'.pdf';
  174. $file_name = replace_dangerous_char($file_name);
  175. $pdf->Output($file_name, 'D');
  176. /*
  177. // This is the old pdf-exporting routine that uses ezpdf library.
  178. //
  179. $format = $export['orientation']; //format is 'portrait' or 'landscape'
  180. $pdf =& new Cezpdf('a4',$format); //format is 'portrait' or 'landscape'
  181. $clear_printable_data=array();
  182. $clear_send_printable_data=array();
  183. //var_dump(count($printable_data[1]));
  184. for ($i=0;$i<count($printable_data[1]);$i++) {
  185. for ($k=0;$k<count($printable_data[1][$i]);$k++) {
  186. $clear_printable_data[]=strip_tags($printable_data[1][$i][$k]);
  187. }
  188. $clear_send_printable_data[]=$clear_printable_data;
  189. $clear_printable_data=array();
  190. }
  191. export_pdf($pdf,$clear_send_printable_data,$printable_data[0],$format);
  192. */
  193. exit;
  194. } else {
  195. Display :: display_header(get_lang('ExportPDF'));
  196. }
  197. }
  198. if (isset ($_GET['print'])) {
  199. $printable_data = get_printable_data ($users,$alleval, $alllinks);
  200. echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
  201. exit;
  202. }
  203. if (!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
  204. if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
  205. $user_id = null;
  206. if (empty($_SESSION['export_user_fields'])) {
  207. $_SESSION['export_user_fields'] = false;
  208. }
  209. if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
  210. $user_id = api_get_user_id();
  211. }
  212. require_once 'gradebook_result.class.php';
  213. $printable_data = get_printable_data($users, $alleval, $alllinks);
  214. switch($_POST['export_format']) {
  215. case 'xls':
  216. $export = new GradeBookResult();
  217. $export->exportCompleteReportXLS($printable_data);
  218. exit;
  219. break;
  220. case 'csv':
  221. default:
  222. $export = new GradeBookResult();
  223. $export->exportCompleteReportCSV($printable_data);
  224. exit;
  225. break;
  226. }
  227. } else {
  228. api_not_allowed(true);
  229. }
  230. }
  231. $addparams = array ('selectcat' => $cat[0]->get_id());
  232. if (isset($_GET['search'])) {
  233. $addparams['search'] = $keyword;
  234. }
  235. $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
  236. $flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
  237. if (isset($_GET['exportpdf'])) {
  238. echo '<div class="normal-message">';
  239. $export_pdf_form->display();
  240. echo '</div>';
  241. } else {
  242. Display :: display_header(get_lang('FlatView'));
  243. }
  244. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
  245. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  246. $flatviewtable->display();
  247. } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
  248. DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
  249. /*echo '<div id="contentLoading" class="contentLoading">';
  250. echo Display::display_icon('loader.gif');
  251. echo '</div>';*/
  252. // main graph
  253. //@todo load images with jquery
  254. echo '<div id="contentArea" style="text-align:center;" >';
  255. $image_file = $flatviewtable->display_graph();
  256. $my_info_path_img = array();
  257. $my_info_path_img = explode('/', $image_file);
  258. if (strlen($my_info_path_img[5]) == 32) {
  259. echo '<img src="'.$image_file.'">';
  260. }
  261. $flatviewtable->display();
  262. $flatviewtable->display_graph_by_resource();
  263. echo '</div>';
  264. }
  265. Display :: display_footer();