Add LP title in export + fix php warning + fix access to teacher to the export

BT#15682
pull/2913/head
Julio Montoya 7 years ago
parent 52fb31926b
commit c6a4858de5
  1. 24
      main/inc/lib/pdf.lib.php
  2. 11
      main/lp/learnpath.class.php
  3. 10
      main/lp/lp_controller.php

@ -187,6 +187,7 @@ class PDF
* @param bool $print_title add title
* @param bool $complete_style show header and footer if true
* @param bool $addStyle
* @param string $mainTitle
*
* @return false|null
*/
@ -196,7 +197,8 @@ class PDF
$course_code = null,
$print_title = false,
$complete_style = true,
$addStyle = true
$addStyle = true,
$mainTitle = ''
) {
if (empty($html_file_array)) {
return false;
@ -231,14 +233,13 @@ class PDF
$counter = 1;
foreach ($html_file_array as $file) {
//Add a page break per file
// Add a page break per file
$page_break = '<pagebreak>';
if ($counter == count($html_file_array)) {
$page_break = '';
}
$counter++;
//if the array provided contained subarrays with 'title' entry,
// if the array provided contained subarrays with 'title' entry,
// then print the title in the PDF
if (is_array($file) && isset($file['title'])) {
$html_title = $file['title'];
@ -248,14 +249,27 @@ class PDF
$html_title = basename($file);
}
$counter++;
if (empty($file) && !empty($html_title)) {
//this is a chapter, print title & skip the rest
// this is a chapter, print title & skip the rest
if ($counter === 2 && !empty($mainTitle)) {
$this->pdf->WriteHTML(
'<html><body><h2 style="text-align: center">'.$mainTitle.'</h2></body></html>'
);
}
if ($print_title) {
$this->pdf->WriteHTML(
'<html><body><h3>'.$html_title.'</h3></body></html>'.$page_break
);
}
continue;
} else {
if ($counter === 2 && !empty($mainTitle)) {
$this->pdf->WriteHTML(
'<html><body><h2 style="text-align: center">'.$mainTitle.'</h2></body></html>'
);
}
}
if (!file_exists($file)) {

@ -12126,7 +12126,10 @@ EOD;
{
$lp_id = (int) $lp_id;
$files_to_export = [];
$sessionId = api_get_session_id();
$course_data = api_get_course_info($this->cc);
if (!empty($course_data)) {
$scorm_path = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/scorm/'.$this->path;
$list = self::get_flat_ordered_items_list($lp_id);
@ -12135,7 +12138,7 @@ EOD;
$item = $this->items[$item_id];
switch ($item->type) {
case 'document':
//Getting documents from a LP with chamilo documents
// Getting documents from a LP with chamilo documents
$file_data = DocumentManager::get_document_data_by_id($item->path, $this->cc);
// Try loading document from the base course.
if (empty($file_data) && !empty($sessionId)) {
@ -12173,12 +12176,16 @@ EOD;
}
}
}
$pdf = new PDF();
$result = $pdf->html_to_pdf(
$files_to_export,
$this->name,
$this->cc,
true
true,
true,
true,
$this->get_name()
);
return $result;

@ -888,14 +888,18 @@ switch ($action) {
}
break;
case 'export_to_pdf':
if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
api_not_allowed();
}
$hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
if ($hideScormPdfLink === 'true') {
api_not_allowed(true);
}
// Teachers can export to PDF
if (!$is_allowed_to_edit) {
if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
api_not_allowed();
}
}
if (!$lp_found) {
require 'lp_list.php';
} else {

Loading…
Cancel
Save