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

skala
Julio Montoya 15 years ago
parent f5a9f061f3
commit be9da0afed
  1. 51
      main/gradebook/gradebook_flatview.php
  2. 8
      main/gradebook/gradebook_scoring_system.php
  3. 22
      main/gradebook/gradebook_view_result.php
  4. 28
      main/gradebook/lib/fe/exportgradebook.php
  5. 2
      main/gradebook/lib/fe/scoredisplayform.class.php
  6. 46
      main/inc/lib/pdf.lib.php

@ -1,4 +1,4 @@
<?php // $Id: $ <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
$language_file = 'gradebook'; $language_file = 'gradebook';
@ -15,10 +15,8 @@ require_once 'lib/fe/displaygradebook.php';
require_once 'lib/fe/exportgradebook.php'; require_once 'lib/fe/exportgradebook.php';
require_once 'lib/scoredisplay.class.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(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'; } if (!class_exists('HTML_Table')) { require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php'; }
api_block_anonymous_users(); api_block_anonymous_users();
@ -186,59 +184,30 @@ if (isset ($_GET['exportpdf'])) {
// Conversion of the created HTML report to a PDF report // Conversion of the created HTML report to a PDF report
$html = api_utf8_encode($html); $html = api_utf8_encode($html);
//@todo this is really a must?
$creator_pdf = api_utf8_encode($creator); $creator_pdf = api_utf8_encode($creator);
$title_pdf = api_utf8_encode($report_name); $title_pdf = api_utf8_encode($report_name);
$subject_pdf = api_utf8_encode(get_lang('FlatView')); $subject_pdf = api_utf8_encode(get_lang('FlatView'));
$keywods_pdf = api_utf8_encode($course_code); $keywods_pdf = api_utf8_encode($course_code);
$page_format = $export['orientation'] == 'landscape' ? 'A4-L' : 'A4'; $page_format = $export['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pdf = new mPDF('UTF-8', $page_format, '', '', 32, 25, 27, 25, 16, 13, $export['orientation']); $pdf = new PDF($page_format, $export['orientation']);
$pdf->directionality = api_get_text_direction();
$pdf->useOnlyCoreFonts = true;
$pdf->SetFooter('{PAGENO}');
$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 // Sending the created PDF report to the client
$file_name = date('YmdHi_', $time); $file_name = date('YmdHi_', $time);
if (!empty($course_code)) { if (!empty($course_code)) {
$file_name .= $course_code.'_'; $file_name .= $course_code.'_';
} }
$file_name .= get_lang('FlatView').'.pdf'; $file_name .= get_lang('FlatView').'.pdf';
$file_name = replace_dangerous_char($file_name); $pdf->content_to_pdf($html, $css, $file_name);
$pdf->Output($file_name, 'D'); exit;
/* /*
// This is the old pdf-exporting routine that uses ezpdf library. $pdf->SetAuthor($creator_pdf);
// $pdf->SetTitle($title_pdf);
$format = $export['orientation']; //format is 'portrait' or 'landscape' $pdf->SetSubject($subject_pdf);
$pdf =& new Cezpdf('a4',$format); //format is 'portrait' or 'landscape' $pdf->SetKeywords($keywods_pdf);*/
$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);
*/
exit;
} else { } else {
Display :: display_header(get_lang('ExportPDF')); 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); Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
} }
if (isset ($_GET['nouniqueranges'])) { if (isset ($_GET['nouniqueranges'])) {
Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false); 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 // set headers data table
$head_ape_name = ''; $head_ape_name = '';
if (api_is_western_name_order()) { 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 { } else {
$head_ape_name = get_lang('LastName').' '.get_lang('FirstName'); $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');
} }
if ($number_decimals == null) { if ($number_decimals == null) {
$head_letter = get_lang('Letters'); $head_letter = get_lang('Letters');
} }
@ -237,10 +233,16 @@ if ($export_result_form->validate()) {
array(get_lang('Code'),12), array(get_lang('Code'),12),
array($head_ape_name, 40), array($head_ape_name, 40),
array(get_lang('Score'),12), array(get_lang('Score'),12),
array($head_letter,15), array($head_letter,15)
array($head_display_score,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 // get data table
if (api_sort_by_first_name()) { if (api_sort_by_first_name()) {
$data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_FIRSTNAME, 0, null, true, true); $data_array = $datagen->get_data(ResultsDataGenerator :: RDG_SORT_FIRSTNAME, 0, null, true, true);
@ -274,8 +276,6 @@ if ($export_result_form->validate()) {
} }
if ($scoredisplay->is_custom()) { if ($scoredisplay->is_custom()) {
$result[] = $data['display']; $result[] = $data['display'];
} else {
$result[] = '';
} }
$data_table[] = $result; $data_table[] = $result;
} }

@ -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) { 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'; 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">';
$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
if (is_array($headers_pdf)) { if (is_array($headers_pdf)) {
// preparing headers pdf // preparing headers pdf
$header = '<table width="100%" cellspacing="1" cellpadding="5" border="0" class="strong"> $header = '<br/><br/><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>
<tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$title_pdf.'</h1></td></tr> <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> <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> <td><strong>'.$headers_pdf[1][0].'</strong> </td><td> <strong>'.$headers_pdf[1][1].'</strong></td>
@ -123,7 +119,6 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
$footer .= '</tr>'; $footer .= '</tr>';
} }
$footer .= '</table>'; $footer .= '</table>';
$footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>'; $footer .= '<div align="right" style="font-weight: bold;">{PAGENO}/{nb}</div>';
// preparing content pdf // preparing content pdf
@ -133,7 +128,6 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
} else { } else {
$css = ''; $css = '';
} }
$items_per_page = 30; $items_per_page = 30;
$count_pages = ceil(count($data_table) / $items_per_page); $count_pages = ceil(count($data_table) / $items_per_page);
for ($x = 0; $x<$count_pages; $x++) { 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 />'; } if ($x < ($count_pages - 1)) { $content_table .= '<pagebreak />'; }
} }
$html = $content_table; $pdf = new PDF();
$pdf->set_custom_footer($footer);
// set attributes for pdf $pdf->set_custom_header($headers_in_pdf);
$mpdf->SetHTMLHeader($header); $pdf->content_to_pdf($header.$content_table, $css, $title_pdf );
$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');
exit; exit;
} }

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

@ -9,8 +9,25 @@ require_once _MPDF_PATH.'mpdf.php';
class PDF { class PDF {
var $pdf; var $pdf;
public function __construct() { var $custom_header = '';
$this->pdf = $pdf = new mPDF('UTF-8', 'A4', '', '', 30, 20, 27, 25, 16, 13, 'P'); 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
} }
/** /**
@ -77,6 +94,7 @@ class PDF {
//$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('<link rel="stylesheet" http://my.chamilo.net/main/css/chamilo/frames.css type="text/css" />','', $document_html);
if (!empty($course_data['path'])) {
$document_html= str_replace('../','',$document_html); $document_html= str_replace('../','',$document_html);
$document_path = api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/'; $document_path = api_get_path(WEB_COURSE_PATH).$course_data['path'].'/document/';
@ -97,7 +115,7 @@ class PDF {
} }
} }
} }
}
//replace relative path by absolute path for resources //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="/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 //$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)) { if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf'; $output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
} else { } else {
$pdf_name = replace_dangerous_char($pdf_name);
$output_file = $pdf_name.'.pdf'; $output_file = $pdf_name.'.pdf';
} }
$result = $this->pdf->Output($output_file, 'D'); /// F to save the pdf in a file $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)) { if (empty($pdf_name)) {
$output_file = 'pdf_'.date('Y-m-d-his').'.pdf'; $output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
} else { } else {
$pdf_name = replace_dangerous_char($pdf_name);
$output_file = $pdf_name.'.pdf'; $output_file = $pdf_name.'.pdf';
} }
$result = $this->pdf->Output($output_file, 'D'); /// F to save the pdf in a file $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); $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) { public function format_pdf($course_code) {
/*$pdf->SetAuthor('Documents Chamilo'); /*$pdf->SetAuthor('Documents Chamilo');
@ -403,7 +431,6 @@ class PDF {
$this->pdf->useOnlyCoreFonts = true; $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 //Adding watermark
if (api_get_setting('pdf_export_watermark_enable') == 'true') { if (api_get_setting('pdf_export_watermark_enable') == 'true') {
$watermark_file = self::get_watermark($course_code); $watermark_file = self::get_watermark($course_code);
@ -413,10 +440,17 @@ class PDF {
$this->pdf->showWatermarkImage = true; $this->pdf->showWatermarkImage = true;
} }
} }
if (empty($this->custom_header)) {
self::set_header($course_code); self::set_header($course_code);
} else {
$this->pdf->SetHTMLHeader($this->custom_header);
}
if (empty($this->custom_footer)) {
self::set_footer(); self::set_footer();
} else {
$this->pdf->SetHTMLFooter($this->custom_footer);
}
} }
} }

Loading…
Cancel
Save