diff --git a/main/course_progress/index.php b/main/course_progress/index.php
index a112431e0e..32bb19f689 100644
--- a/main/course_progress/index.php
+++ b/main/course_progress/index.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;
diff --git a/main/course_progress/thematic.php b/main/course_progress/thematic.php
index b6f5376962..234da14772 100644
--- a/main/course_progress/thematic.php
+++ b/main/course_progress/thematic.php
@@ -29,6 +29,7 @@ if (api_is_allowed_to_edit(null, true)) {
echo ''.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'';
echo ''.Display::return_icon('import_csv.png',get_lang('ImportThematic'),'',ICON_SIZE_MEDIUM).'';
echo ''.Display::return_icon('export_csv.png',get_lang('ExportThematic'),'', ICON_SIZE_MEDIUM).'';
+ echo ''.Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'';
break;
default :
echo ''.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'';
diff --git a/main/course_progress/thematic_controller.php b/main/course_progress/thematic_controller.php
index 5fba41fa45..01210d8ee8 100644
--- a/main/course_progress/thematic_controller.php
+++ b/main/course_progress/thematic_controller.php
@@ -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 .= ''.$plan['title']. '
'.$plan['description'].'
';
+ }
+ }
+ $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'].'
'.$advance['content'].'
';
+ }
+ }
+ $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';
diff --git a/main/gradebook/lib/gradebook_functions.inc.php b/main/gradebook/lib/gradebook_functions.inc.php
index 37a7ff0751..8e3be24d52 100644
--- a/main/gradebook/lib/gradebook_functions.inc.php
+++ b/main/gradebook/lib/gradebook_functions.inc.php
@@ -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 = "
";
- } else {
- if (!empty($organization)) {
- $organization = '
'.$organization.'
';
- }
- }
-
- 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 = ''.api_strtoupper(get_lang('Average')).'
'.get_lang('Detailed').'
';
+ $title = api_strtoupper(get_lang('Average')).'
'.get_lang('Detailed');
} else {
- $title = ' '.api_strtoupper(get_lang('Average')).'
'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')
';
+ $title = api_strtoupper(get_lang('Average')).'
'.$cat[0]->get_description().' - ('.$cat[0]->get_name().')';
}
} else {
if ($parent_id == 0) {
- $title = ''.api_strtoupper(get_lang('Average')).'
'.get_lang('Detailed').'
';
+ $title = api_strtoupper(get_lang('Average')).'
'.get_lang('Detailed');
} else {
- $title = ''.api_strtoupper(get_lang('Average')).'
';
+ $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;
}
diff --git a/main/inc/lib/export.lib.inc.php b/main/inc/lib/export.lib.inc.php
index cb83cefbbc..60c495193f 100644
--- a/main/inc/lib/export.lib.inc.php
+++ b/main/inc/lib/export.lib.inc.php
@@ -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 = '
';
-
- $html = '
';
- $html .= $description.'
';
-
+ 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());
}
-}
\ No newline at end of file
+}
diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php
index 1f29d4fe6f..1ed6d3abf3 100644
--- a/main/inc/lib/pdf.lib.php
+++ b/main/inc/lib/pdf.lib.php
@@ -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 = "
";
+ } else {
+ if (!empty($organization)) {
+ $organization = ''.$organization.'
';
+ }
+ }
+
+ 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 {
'@@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);
diff --git a/main/template/default/export/table_pdf.tpl b/main/template/default/export/table_pdf.tpl
new file mode 100644
index 0000000000..165063d8f7
--- /dev/null
+++ b/main/template/default/export/table_pdf.tpl
@@ -0,0 +1,62 @@
+{{ organization }}
+
+ {{ pdf_title }}
+
+{% if pdf_description != null %}
+ {{ pdf_description }}
+
+{% endif %}
+
+
+
+ |
+ {{ "Teacher" | get_lang }}: {{ pdf_teachers }}
+ |
+
+ {% if pdf_session != null %}
+
+ |
+ {{ "Session" | get_lang }}: {{ pdf_session }}
+ |
+
+ {% endif %}
+
+ |
+ {{ "Course" | get_lang }}: {{ pdf_course }}
+ |
+
+
+ |
+ {{ "Date" | get_lang }}: {{ pdf_date }}
+ |
+
+
+
+
+
+{{ pdf_table }}
+
+{% if add_signatures == true %}
+
+
+
+
+
+
+ _____________________________
+
+ {{ "Drh" | get_lang }}
+ |
+
+ _____________________________
+
+ {{ "Teacher" | get_lang }}
+ |
+
+ _____________________________
+
+ {{ "Date" | get_lang }}
+ |
+
+
+{% endif %}
\ No newline at end of file
diff --git a/main/template/default/gradebook/flatview.pdf.tpl b/main/template/default/gradebook/flatview.pdf.tpl
deleted file mode 100644
index befb076158..0000000000
--- a/main/template/default/gradebook/flatview.pdf.tpl
+++ /dev/null
@@ -1,55 +0,0 @@
-{{ organization }}
-
- {{ pdf_title }}
-
-
-
- |
- {{ "Teacher" | get_lang }}: {{ pdf_teachers }}
- |
-
- {% if pdf_session != null %}
-
- |
- {{ "Session" | get_lang }}: {{ pdf_session }}
- |
-
- {% endif %}
-
- |
- {{ "Course" | get_lang }}: {{ pdf_course }}
- |
-
-
- |
- {{ "Date" | get_lang }}: {{ pdf_date }}
- |
-
-
-
-
-
-{{ pdf_table }}
-
-
-
-
-
-
-
- _____________________________
-
- {{ "Drh" | get_lang }}
- |
-
- _____________________________
-
- {{ "Teacher" | get_lang }}
- |
-
- _____________________________
-
- {{ "Date" | get_lang }}
- |
-
-
\ No newline at end of file
diff --git a/main/user/user.php b/main/user/user.php
index 276457aa83..7576207a61 100644
--- a/main/user/user.php
+++ b/main/user/user.php
@@ -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 = '';
if (api_get_session_id()) {
$description .= '| '.get_lang('Session').': | '.api_get_session_name(api_get_session_id()).' | ';
@@ -285,18 +284,26 @@ if (api_is_allowed_to_edit(null, true)) {
$description .= '
| '.get_lang('Coachs').': | '.$coaches.' | ';
}
}
- }
+ }
$description .= '
| '.get_lang('Date').': | '.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).' | ';
$description .= '
';
- $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;
}
}