Gradebook tool: Replacing mpdf calls with the pdf.lib.php see BT#1617

skala
Julio Montoya 14 years ago
parent f5a9f061f3
commit be9da0afed
  1. 73
      main/gradebook/gradebook_flatview.php
  2. 14
      main/gradebook/gradebook_scoring_system.php
  3. 26
      main/gradebook/gradebook_view_result.php
  4. 34
      main/gradebook/lib/fe/exportgradebook.php
  5. 2
      main/gradebook/lib/fe/scoredisplayform.class.php
  6. 90
      main/inc/lib/pdf.lib.php

@ -1,4 +1,4 @@
<?php // $Id: $
<?php
/* For licensing terms, see /license.txt */
$language_file = 'gradebook';
@ -15,10 +15,8 @@ require_once 'lib/fe/displaygradebook.php';
require_once 'lib/fe/exportgradebook.php';
require_once 'lib/scoredisplay.class.php';
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
//require_once api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php'; // This is the old library for pdf-export (non UTF-8 compatible).
define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
require_once _MPDF_PATH.'mpdf.php';
if (!class_exists('HTML_Table')) { require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php'; }
api_block_anonymous_users();
@ -185,60 +183,31 @@ if (isset ($_GET['exportpdf'])) {
// Conversion of the created HTML report to a PDF report
$html = api_utf8_encode($html);
$creator_pdf = api_utf8_encode($creator);
$title_pdf = api_utf8_encode($report_name);
$subject_pdf = api_utf8_encode(get_lang('FlatView'));
$keywods_pdf = api_utf8_encode($course_code);
$html = api_utf8_encode($html);
//@todo this is really a must?
$creator_pdf = api_utf8_encode($creator);
$title_pdf = api_utf8_encode($report_name);
$subject_pdf = api_utf8_encode(get_lang('FlatView'));
$keywods_pdf = api_utf8_encode($course_code);
$page_format = $export['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pdf = new mPDF('UTF-8', $page_format, '', '', 32, 25, 27, 25, 16, 13, $export['orientation']);
$pdf->directionality = api_get_text_direction();
$pdf->useOnlyCoreFonts = true;
$pdf->SetFooter('{PAGENO}');
$pdf = new PDF($page_format, $export['orientation']);
// Sending the created PDF report to the client
$file_name = date('YmdHi_', $time);
if (!empty($course_code)) {
$file_name .= $course_code.'_';
}
$file_name .= get_lang('FlatView').'.pdf';
$pdf->content_to_pdf($html, $css, $file_name);
exit;
/*
$pdf->SetAuthor($creator_pdf);
$pdf->SetTitle($title_pdf);
$pdf->SetSubject($subject_pdf);
$pdf->SetKeywords($keywods_pdf);
if (!empty($css)) {
$pdf->WriteHTML($css, 1);
$pdf->WriteHTML($html, 2);
} else {
$pdf->WriteHTML($html);
}
// Sending the created PDF report to the client
$file_name = date('YmdHi_', $time);
if (!empty($course_code)) {
$file_name .= $course_code.'_';
}
$file_name .= get_lang('FlatView').'.pdf';
$file_name = replace_dangerous_char($file_name);
$pdf->Output($file_name, 'D');
/*
// This is the old pdf-exporting routine that uses ezpdf library.
//
$format = $export['orientation']; //format is 'portrait' or 'landscape'
$pdf =& new Cezpdf('a4',$format); //format is 'portrait' or 'landscape'
$clear_printable_data=array();
$clear_send_printable_data=array();
for ($i=0;$i<count($printable_data[1]);$i++) {
for ($k=0;$k<count($printable_data[1][$i]);$k++) {
$clear_printable_data[]=strip_tags($printable_data[1][$i][$k]);
}
$clear_send_printable_data[]=$clear_printable_data;
$clear_printable_data=array();
}
export_pdf($pdf,$clear_send_printable_data,$printable_data[0],$format);
*/
$pdf->SetKeywords($keywods_pdf);*/
exit;
} else {
Display :: display_header(get_lang('ExportPDF'));
}

@ -112,12 +112,10 @@ if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') || (isse
Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
}
if (isset ($_GET['nouniqueranges'])) {
Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
if (isset ($_GET['nouniqueranges'])) {
Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
}
$scoreform->display();
}
echo '<div class="maincontent">';
$scoreform->display();
echo '</div>';
}
Display :: display_footer();
Display :: display_footer();

@ -220,15 +220,11 @@ if ($export_result_form->validate()) {
// set headers data table
$head_ape_name = '';
if (api_is_western_name_order()) {
$head_ape_name = get_lang('FirstName').' '.get_lang('LastName');
$head_ape_name = get_lang('FirstName').', '.get_lang('LastName');
} else {
$head_ape_name = get_lang('LastName').' '.get_lang('FirstName');
}
$head_display_score = '';
$scoredisplay = ScoreDisplay :: instance();
if ($scoredisplay->is_custom()) {
$head_display_score = get_lang('Display');
$head_ape_name = get_lang('LastName').', '.get_lang('FirstName');
}
if ($number_decimals == null) {
$head_letter = get_lang('Letters');
}
@ -237,10 +233,16 @@ if ($export_result_form->validate()) {
array(get_lang('Code'),12),
array($head_ape_name, 40),
array(get_lang('Score'),12),
array($head_letter,15),
array($head_display_score,15)
array($head_letter,15)
);
$head_display_score = '';
$scoredisplay = ScoreDisplay :: instance();
if ($scoredisplay->is_custom()) {
$head_display_score = get_lang('Display');
$head_table[] = array($head_display_score,15);
}
// get data table
if (api_sort_by_first_name()) {
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_FIRSTNAME, 0, null, true, true);
@ -274,11 +276,9 @@ if ($export_result_form->validate()) {
}
if ($scoredisplay->is_custom()) {
$result[] = $data['display'];
} else {
$result[] = '';
}
$data_table[] = $result;
}
}
export_pdf_with_html($head_table, $data_table, $header_pdf, $footer_pdf, $title_pdf);
}

@ -90,16 +90,12 @@ a:active {text-decoration: none; font-weight : bold; color : black;}
*/
function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footers_pdf, $title_pdf) {
require_once api_get_path(LIBRARY_PATH).'mpdf/mpdf.php';
$mpdf = new mPDF('UTF-8', 'A4', '', '', 18, 15, 65, 35, 5, 13, 'P');
$mpdf->useOnlyCoreFonts = true;
$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
$headers_in_pdf = '<img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png">';
if (is_array($headers_pdf)) {
// preparing headers pdf
$header = '<table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">
<tr><td width="100%" style="text-align: left;" class="title" colspan="4"><img src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png"></td></tr>
$header = '<br/><br/><table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong">
<tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr>
<tr><td><strong>'.$headers_pdf[0][0].'</strong> </td><td> <strong>'.$headers_pdf[0][1].'</strong></td>
<td><strong>'.$headers_pdf[1][0].'</strong> </td><td> <strong>'.$headers_pdf[1][1].'</strong></td>
@ -122,8 +118,7 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
}
$footer .= '</tr>';
}
$footer .= '</table>';
$footer .= '</table>';
$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
// preparing content pdf
@ -132,8 +127,7 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
$css = @file_get_contents($css_file);
} else {
$css = '';
}
}
$items_per_page = 30;
$count_pages = ceil(count($data_table) / $items_per_page);
for ($x = 0; $x<$count_pages; $x++) {
@ -178,18 +172,10 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
}
$html = $content_table;
// set attributes for pdf
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
if (!empty($css)) {
$mpdf->WriteHTML($css, 1);
$mpdf->WriteHTML($html, 2);
} else {
$mpdf->WriteHTML($html);
}
$mpdf->Output(replace_dangerous_char($title_pdf.'.pdf'), 'D');
$pdf = new PDF();
$pdf->set_custom_footer($footer);
$pdf->set_custom_header($headers_in_pdf);
$pdf->content_to_pdf($header.$content_table, $css, $title_pdf );
exit;
}

@ -88,7 +88,7 @@ class ScoreDisplayForm extends FormValidator
$elementTemplateTwoLabel =
'<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';" class="row">
<p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
<div class="formw"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <b>'.get_lang('And').'</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{element} % =';
<div class="formw"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <br /><b>'.get_lang('And').'</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp{element} % =';
$elementTemplateTwoLabel2 =
'<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}

@ -8,9 +8,26 @@ require_once _MPDF_PATH.'mpdf.php';
class PDF {
var $pdf;
public function __construct() {
$this->pdf = $pdf = new mPDF('UTF-8', 'A4', '', '', 30, 20, 27, 25, 16, 13, 'P');
var $pdf;
var $custom_header = '';
var $custom_footer = '';
/**
* Creates the mPDF object
* @params string orientation "P" = Portrait "L" = Landscape
*/
public function __construct($page_format ='A4', $orientation = 'P') {
/* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF
* mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
*/
if(!in_array($orientation,array('P','L'))) {
$orientation = 'P';
}
$this->pdf = $pdf = new mPDF('UTF-8', $page_format, '', '', 30, 20, 27, 25, 16, 13, $orientation);
//$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
}
/**
@ -76,28 +93,29 @@ class PDF {
$document_html=str_replace('href="./css/frames.css"',$absolute_css_path, $document_html);
//$document_html=str_replace('<link rel="stylesheet" http://my.chamilo.net/main/css/chamilo/frames.css type="text/css" />','', $document_html);
$document_html= str_replace('../','',$document_html);
$document_path = api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/';
$doc = new DOMDocument();
$result = @$doc->loadHTML($document_html);
//Fixing only images @todo do the same thing with other elements
$elements = $doc->getElementsByTagName('img');
$replace_img_elements = array();
if (!empty($elements)) {
foreach($elements as $item) {
$old_src = $item->getAttribute('src');
//$old_src= str_replace('../','',$old_src);
if (strpos($old_src, 'http') === false) {
if (strpos($old_src, '/main/default_course_document') === false) {
$document_html= str_replace($old_src, $document_path.$old_src, $document_html);
}
}
if (!empty($course_data['path'])) {
$document_html= str_replace('../','',$document_html);
$document_path = api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/';
$doc = new DOMDocument();
$result = @$doc->loadHTML($document_html);
//Fixing only images @todo do the same thing with other elements
$elements = $doc->getElementsByTagName('img');
$replace_img_elements = array();
if (!empty($elements)) {
foreach($elements as $item) {
$old_src = $item->getAttribute('src');
//$old_src= str_replace('../','',$old_src);
if (strpos($old_src, 'http') === false) {
if (strpos($old_src, '/main/default_course_document') === false) {
$document_html= str_replace($old_src, $document_path.$old_src, $document_html);
}
}
}
}
}
//replace relative path by absolute path for resources
//$document_html= str_replace('src="/chamilo/main/default_course_document/', 'temp_template_path', $document_html);// before save src templates not apply
//$document_html= str_replace('src="/', 'temp_template_path', $document_html);// before save src templates not apply
@ -121,6 +139,7 @@ class PDF {
if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
} else {
$pdf_name = replace_dangerous_char($pdf_name);
$output_file = $pdf_name.'.pdf';
}
$result = $this->pdf->Output($output_file, 'D'); /// F to save the pdf in a file
@ -217,6 +236,7 @@ class PDF {
if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
} else {
$pdf_name = replace_dangerous_char($pdf_name);
$output_file = $pdf_name.'.pdf';
}
$result = $this->pdf->Output($output_file, 'D'); /// F to save the pdf in a file
@ -391,6 +411,14 @@ class PDF {
$this->pdf->SetHeader($my_header);// ('{DATE j-m-Y}|{PAGENO}/{nb}|'.$title);
}
public function set_custom_header($header) {
$this->custom_header = $header;
}
public function set_custom_footer($footer) {
$this->custom_footer = $footer;
}
public function format_pdf($course_code) {
/*$pdf->SetAuthor('Documents Chamilo');
@ -401,8 +429,7 @@ class PDF {
$this->pdf->directionality = api_get_text_direction(); // TODO: To be read from the html document.
$this->pdf->useOnlyCoreFonts = true;
$this->pdf->mirrorMargins = 1; // Use different Odd/Even headers and footers and mirror margins
$this->pdf->mirrorMargins = 1; // Use different Odd/Even headers and footers and mirror margins
//Adding watermark
if (api_get_setting('pdf_export_watermark_enable') == 'true') {
@ -412,11 +439,18 @@ class PDF {
$this->pdf->SetWatermarkImage($watermark_file);
$this->pdf->showWatermarkImage = true;
}
}
if (empty($this->custom_header)) {
self::set_header($course_code);
} else {
$this->pdf->SetHTMLHeader($this->custom_header);
}
self::set_header($course_code);
self::set_footer();
if (empty($this->custom_footer)) {
self::set_footer();
} else {
$this->pdf->SetHTMLFooter($this->custom_footer);
}
}
}

Loading…
Cancel
Save