Adding thematic to PDF export see BT#4940

skala
Julio Montoya 13 years ago
parent 99d829df64
commit e83510cd81
  1. 3
      main/course_progress/index.php
  2. 1
      main/course_progress/thematic.php
  3. 28
      main/course_progress/thematic_controller.php
  4. 80
      main/gradebook/lib/gradebook_functions.inc.php
  5. 39
      main/inc/lib/export.lib.inc.php
  6. 69
      main/inc/lib/pdf.lib.php
  7. 62
      main/template/default/export/table_pdf.tpl
  8. 55
      main/template/default/gradebook/flatview.pdf.tpl
  9. 17
      main/user/user.php

@ -35,7 +35,7 @@ define('ADD_THEMATIC_PLAN', 6);
// get actions
$actions = array('thematic_details', 'thematic_list', 'thematic_add', 'thematic_edit', 'thematic_copy', 'thematic_delete', 'moveup', 'movedown',
'thematic_import_select', 'thematic_import', 'thematic_export',
'thematic_import_select', 'thematic_import', 'thematic_export', 'thematic_export_pdf',
'thematic_plan_list', 'thematic_plan_add', 'thematic_plan_edit', 'thematic_plan_delete',
'thematic_advance_list', 'thematic_advance_add', 'thematic_advance_edit', 'thematic_advance_delete');
@ -311,6 +311,7 @@ switch ($action) {
}
case 'thematic_list' :
case 'thematic_export' :
case 'thematic_export_pdf' :
case 'thematic_details' :
$thematic_controller->thematic($action);
break;

@ -29,6 +29,7 @@ if (api_is_allowed_to_edit(null, true)) {
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.Display::return_icon('import_csv.png',get_lang('ImportThematic'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.Display::return_icon('export_csv.png',get_lang('ExportThematic'),'', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
break;
default :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';

@ -165,6 +165,34 @@ class ThematicController
exit;
// Don't continue building a normal page.
return;
case 'thematic_export_pdf':
$list = $thematic->get_thematic_list();
$table = array();
$table[] = array (get_lang('Thematic'), get_lang('ThematicPlan'), get_lang('ThematicAdvance'));
foreach ($list as $theme) {
$data = $thematic->get_thematic_plan_data($theme['id']);
$plan_html = null;
if (!empty($data)) {
foreach ($data as $plan) {
$plan_html .= '<strong>'.$plan['title']. '</strong><br /> '.$plan['description'].'<br />';
}
}
$data = $thematic->get_thematic_advance_by_thematic_id ($theme['id']);
$advance_html = null;
if (!empty($data)) {
foreach ($data as $advance) {
$advance_html .= api_convert_and_format_date($advance['start_date'], DATE_TIME_FORMAT_LONG).' '.$advance['duration'].'<br />'.$advance['content'].'<br />';
}
}
$table[] = array($theme['title'], $plan_html, $advance_html);
}
$params = array(
'filename' => get_lang('Thematic'),
'pdf_title' => get_lang('Thematic'),
'add_signatures' => true
);
Export::export_table_pdf($table, $params);
break;
case 'moveup':
$thematic->move_thematic('up', $thematic_id);
$action = 'thematic_details';

@ -706,14 +706,9 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
//Getting data
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params);
// Reading report's CSS
$css_file = api_get_path(SYS_CODE_PATH).'gradebook/print.css';
$css = file_exists($css_file) ? @file_get_contents($css_file) : '';
// HTML report creation first
$course_code = trim($cat[0]->get_course_code());
$organization = api_get_setting('Institution');
$displayscore = ScoreDisplay :: instance();
$customdisplays = $displayscore->get_custom_score_display_settings();
@ -727,20 +722,6 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$total[$user_result[count($user_result)-1][1]]++;
}
}
$html = '';
$img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
if (file_exists($img)) {
$img = api_get_path(WEB_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
$organization = "<img src='$img'>";
} else {
if (!empty($organization)) {
$organization = '<h2 align="left">'.$organization.'</h2>';
}
}
Display::$global_template->assign('organization', $organization);
$parent_id = $cat[0]->get_parent_id();
if (isset($cat[0]) && isset($parent_id)) {
@ -759,31 +740,17 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
if ($use_grade_model) {
if ($parent_id == 0) {
$title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed').'</h2>';
$title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed');
} else {
$title = '<h2 align="center"> '.api_strtoupper(get_lang('Average')).'<br />'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')</h2>';
$title = api_strtoupper(get_lang('Average')).'<br />'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')';
}
} else {
if ($parent_id == 0) {
$title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed').'</h2>';
$title = api_strtoupper(get_lang('Average')).'<br />'.get_lang('Detailed');
} else {
$title = '<h2 align="center">'.api_strtoupper(get_lang('Average')).'</h2>';
$title = api_strtoupper(get_lang('Average'));
}
}
Display::$global_template->assign('pdf_title', $title);
//Showing only the current teacher/admin instead the all teacherlist name see BT#4080
//$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
$user_info = api_get_user_info();
$teacher_list = $user_info['complete_name'];
$session_name = api_get_session_name(api_get_session_id());
if (!empty($session_name)) {
Display::$global_template->assign('pdf_session', $session_name);
}
Display::$global_template->assign('pdf_course', $course_code);
Display::$global_template->assign('pdf_date', api_format_date(api_get_utc_datetime(), DATE_TIME_FORMAT_LONG));
Display::$global_template->assign('pdf_teachers', $teacher_list);
$columns = count($printable_data[0]);
$has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
@ -829,38 +796,23 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
}
//exit;
}
} else {
$column = 0;
$table->setCellContents($row, $column, get_lang('NoResults'));
$table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
}
Display::$global_template->assign('pdf_table', $table->toHtml());
unset($printable_data);
unset($table);
}
// Conversion of the created HTML report to a PDF report
$gradebook_tpl = Display::$global_template->get_template('gradebook/flatview.pdf.tpl');
$gradebook_flatview = Display::$global_template->fetch($gradebook_tpl);
$params = array(
'filename' => get_lang('FlatView').'_'.api_get_utc_datetime(),
'pdf_title' => $title,
'course_code' => $course_code,
'add_signatures' => true
);
//Header
$html = $gradebook_flatview;
$html = api_utf8_encode($html);
$page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pdf = new PDF($page_format, $params['orientation']);
// Sending the created PDF report to the client
$file_name = null;
if (!empty($course_code)) {
$file_name .= $course_code;
}
$file_name = api_get_utc_datetime();
$file_name = get_lang('FlatView').'_'.$file_name;
$pdf->content_to_pdf($html, $css, $file_name, api_get_course_id());
$page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pdf = new PDF($page_format, $params['orientation'], $params);
$pdf->table_to_pdf($table->toHtml());
exit;
}

@ -168,18 +168,17 @@ class Export {
}
return $string;
}
public static function export_table_pdf($data, $file_name = 'export', $header = null, $description = null, $params = array(), $header_attributes = array()) {
/**
*
* @param array table in array format to be read with the HTML_table class
*/
public static function export_table_pdf($data, $params = array()) {
$headers = $data[0];
unset($data[0]);
$html = '';
$headers_in_pdf = '<img width="150px" src="'.api_get_path(WEB_CSS_PATH).api_get_setting('stylesheets').'/images/header-logo.png">';
$html = '<br/><table width="100%" cellspacing="1" cellpadding="5" border="0">
<tr><td width="100%" style="text-align: center;" class="title" colspan="4"><h1>'.$header.'</h1></td></tr></table><br />';
$html .= $description.'<br />';
unset($data[0]);
$header_attributes = isset($params['header_attributes']) ? $params['header_attributes'] : array();
$table = new HTML_Table(array('class' => 'data_table', 'repeat_header' => '1'));
$row = 0;
$column = 0;
@ -194,8 +193,7 @@ class Export {
}
$column++;
}
$row++;
$row++;
foreach ($data as &$printable_data_row) {
$column = 0;
foreach ($printable_data_row as &$printable_data_cell) {
@ -205,17 +203,8 @@ class Export {
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
}
$html .= $table->toHtml();
$html = api_utf8_encode($html);
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css';
$css = file_exists($css_file) ? @file_get_contents($css_file) : '';
}
$pdf = new PDF('A4', 'P', $params);
$pdf->set_custom_header($headers_in_pdf);
$pdf->content_to_pdf($html, $css, $file_name, api_get_course_id());
exit;
$pdf->table_to_pdf($table->toHtml());
}
}
}

@ -14,9 +14,11 @@ require_once _MPDF_PATH.'mpdf.php';
*/
class PDF {
var $pdf;
var $custom_header = '';
var $custom_footer = '';
public $pdf;
public $custom_header = '';
public $custom_footer = '';
public $params = array();
/**
* Creates the mPDF object
@ -36,11 +38,63 @@ class PDF {
$params['left'] = isset($params['left']) ? $params['left'] : 15;
$params['right'] = isset($params['right']) ? $params['right'] : 15;
$params['top'] = isset($params['top']) ? $params['top'] : 20;
$params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15;
$params['bottom'] = isset($params['bottom']) ? $params['bottom'] : 15;
$this->params['filename'] = isset($params['filename']) ? $params['filename'] : api_get_utc_datetime();
$this->params['pdf_title'] = isset($params['pdf_title']) ? $params['pdf_title'] : get_lang('Untitled');
$this->params['course_code'] = isset($params['course_code']) ? $params['course_code'] : api_get_course_id();
$this->params['add_signatures'] = isset($params['add_signatures']) ? $params['add_signatures'] : false;
$this->pdf = $pdf = new mPDF('UTF-8', $page_format, '', '', $params['left'], $params['right'], $params['top'], $params['bottom'], 8, 8, $orientation);
}
function table_to_pdf($table) {
Display :: display_no_header();
//Assignments
Display::$global_template->assign('pdf_table', $table);
$organization = api_get_setting('Institution');
$img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
if (file_exists($img)) {
$img = api_get_path(WEB_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
$organization = "<img src='$img'>";
} else {
if (!empty($organization)) {
$organization = '<h2 align="left">'.$organization.'</h2>';
}
}
Display::$global_template->assign('organization', $organization);
//Showing only the current teacher/admin instead the all teacherlist name see BT#4080
//$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
$user_info = api_get_user_info();
$teacher_list = $user_info['complete_name'];
$session_name = api_get_session_name(api_get_session_id());
if (!empty($session_name)) {
Display::$global_template->assign('pdf_session', $session_name);
}
Display::$global_template->assign('pdf_course', $this->params['course_code']);
Display::$global_template->assign('pdf_date', api_format_date(api_get_utc_datetime(), DATE_TIME_FORMAT_LONG));
Display::$global_template->assign('pdf_teachers', $teacher_list);
Display::$global_template->assign('pdf_title', $this->params['pdf_title']);
Display::$global_template->assign('add_signatures', $this->params['add_signatures']);
//Getting template
$tpl = Display::$global_template->get_template('export/table_pdf.tpl');
$html = Display::$global_template->fetch($tpl);
$html = api_utf8_encode($html);
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css';
$css = file_exists($css_file) ? @file_get_contents($css_file) : '';
self::content_to_pdf($html, $css, $this->params['filename'], $this->params['course_code']);
}
/**
* Converts HTML files to PDF
* @param mixed could be an html file path or an array with paths example: /var/www/myfile.html or array('/myfile.html','myotherfile.html') or even an indexed array with both 'title' and 'path' indexes for each element like array(0=>array('title'=>'Hello','path'=>'file.html'),1=>array('title'=>'Bye','path'=>'file2.html'));
@ -68,7 +122,7 @@ class PDF {
$course_data = array();
if (!empty($course_code)) {
$course_data = api_get_course_info($course_code);
}
}
//clean styles and javascript document
$clean_search = array (
@ -217,10 +271,9 @@ class PDF {
'@<style[^>]*?>.*?</style>@siU'
);
//Formatting the pdf
//Formatting the pdf
$course_data = api_get_course_info($course_code);
self::format_pdf($course_data);
$document_html = preg_replace($clean_search, '', $document_html);

@ -0,0 +1,62 @@
{{ organization }}
<h2 align="center"> {{ pdf_title }} </h2>
{% if pdf_description != null %}
{{ pdf_description }}
<br /><br />
{% endif %}
<table align="center" width="100%">
<tr>
<td>
<strong>{{ "Teacher" | get_lang }}:</strong> {{ pdf_teachers }}
</td>
</tr>
{% if pdf_session != null %}
<tr>
<td>
<strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session }}
</td>
</tr>
{% endif %}
<tr>
<td>
<strong>{{ "Course" | get_lang }}:</strong> {{ pdf_course }}
</td>
</tr>
<tr>
<td>
<strong>{{ "Date" | get_lang }}:</strong> {{ pdf_date }}
</td>
</tr>
</table>
<br />
{{ pdf_table }}
{% if add_signatures == true %}
<br />
<br />
<table style="text-align:center" width="100%">
<tr>
<td>
_____________________________
<br />
{{ "Drh" | get_lang }}
</td>
<td>
_____________________________
<br />
{{ "Teacher" | get_lang }}
</td>
<td>
_____________________________
<br />
{{ "Date" | get_lang }}
</td>
</tr>
</table>
{% endif %}

@ -1,55 +0,0 @@
{{ organization }}
<h2> {{ pdf_title }} </h2>
<table align="center" width="100%">
<tr>
<td>
<strong>{{ "Teacher" | get_lang }}:</strong> {{ pdf_teachers }}
</td>
</tr>
{% if pdf_session != null %}
<tr>
<td>
<strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session }}
</td>
</tr>
{% endif %}
<tr>
<td>
<strong>{{ "Course" | get_lang }}:</strong> {{ pdf_course }}
</td>
</tr>
<tr>
<td>
<strong>{{ "Date" | get_lang }}:</strong> {{ pdf_date }}
</td>
</tr>
</table>
<br />
{{ pdf_table }}
<br />
<br />
<table style="text-align:center" width="100%">
<tr>
<td>
_____________________________
<br />
{{ "Drh" | get_lang }}
</td>
<td>
_____________________________
<br />
{{ "Teacher" | get_lang }}
</td>
<td>
_____________________________
<br />
{{ "Date" | get_lang }}
</td>
</tr>
</table>

@ -247,8 +247,7 @@ if (api_is_allowed_to_edit(null, true)) {
case 'xls' :
Export::export_table_xls($a_users);
exit;
case 'pdf' :
$header = get_lang('StudentList');
case 'pdf' :
$description = '<table class="data_table_no_border">';
if (api_get_session_id()) {
$description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
@ -285,18 +284,26 @@ if (api_is_allowed_to_edit(null, true)) {
$description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.'</td>';
}
}
}
}
$description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
$description .= '</table>';
$params = array();
$header_attributes = array(
array('style' => 'width:10px'),
array('style' => 'width:30px'),
array('style' => 'width:50px'),
array('style' => 'width:500px'),
);
Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params, $header_attributes);
$params = array(
'add_signatures' => false,
'filename' => get_lang('UserList'),
'pdf_title' => get_lang('StudentList'),
'pdf_description' => $description,
'header_attributes' => $header_attributes
);
Export::export_table_pdf($a_users, $params);
exit;
}
}

Loading…
Cancel
Save