|
|
|
@ -2207,159 +2207,6 @@ class DocumentManager |
|
|
|
|
return $content_html; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Export document to PDF. |
|
|
|
|
* |
|
|
|
|
* @param int $documentId |
|
|
|
|
* @param string $courseCode |
|
|
|
|
* @param string $orientation |
|
|
|
|
* @param bool $showHeaderAndFooter |
|
|
|
|
*/ |
|
|
|
|
public static function export_to_pdf( |
|
|
|
|
$documentId, |
|
|
|
|
$courseCode, |
|
|
|
|
$orientation = 'landscape', |
|
|
|
|
$showHeaderAndFooter = true |
|
|
|
|
) { |
|
|
|
|
$repo = Container::getDocumentRepository(); |
|
|
|
|
$document = $repo->find($documentId); |
|
|
|
|
|
|
|
|
|
if (empty($document)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$filePath = $repo->getDocumentPath($documentId); |
|
|
|
|
|
|
|
|
|
if (empty($filePath)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$title = $document->getTitle(); |
|
|
|
|
//$filePath = api_get_path(SYS_COURSE_PATH).$course_data['path'].'/document'.$document_data['path']; |
|
|
|
|
$pageFormat = 'A4'; |
|
|
|
|
$pdfOrientation = 'P'; |
|
|
|
|
if ('landscape' === $orientation) { |
|
|
|
|
$pageFormat = 'A4-L'; |
|
|
|
|
$pdfOrientation = 'L'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$pdf = new PDF( |
|
|
|
|
$pageFormat, |
|
|
|
|
$pdfOrientation, |
|
|
|
|
$showHeaderAndFooter ? [] : ['top' => 0, 'left' => 0, 'bottom' => 0, 'right' => 0] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (api_get_configuration_value('use_alternative_document_pdf_footer')) { |
|
|
|
|
$view = new Template('', false, false, false, true, false, false); |
|
|
|
|
$template = $view->get_template('export/alt_pdf_footer.tpl'); |
|
|
|
|
|
|
|
|
|
$pdf->set_custom_footer([ |
|
|
|
|
'html' => $view->fetch($template), |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$pdf->html_to_pdf( |
|
|
|
|
$filePath, |
|
|
|
|
$title, |
|
|
|
|
$courseCode, |
|
|
|
|
false, |
|
|
|
|
$showHeaderAndFooter |
|
|
|
|
); |
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Uploads a document. |
|
|
|
|
* |
|
|
|
|
* @param array $files the $_FILES variable |
|
|
|
|
* @param string $path |
|
|
|
|
* @param string $title |
|
|
|
|
* @param string $comment |
|
|
|
|
* @param int $unzip unzip or not the file |
|
|
|
|
* @param string $ifExists overwrite, rename or warn (default) |
|
|
|
|
* @param bool $index_document index document (search xapian module) |
|
|
|
|
* @param bool $show_output print html messages |
|
|
|
|
* @param string $fileKey |
|
|
|
|
* @param bool $treat_spaces_as_hyphens |
|
|
|
|
* @param int $parentId |
|
|
|
|
* @param string $content |
|
|
|
|
* |
|
|
|
|
* @return CDocument|false |
|
|
|
|
*/ |
|
|
|
|
public static function upload_document( |
|
|
|
|
$files, |
|
|
|
|
$path, |
|
|
|
|
$title = '', |
|
|
|
|
$comment = '', |
|
|
|
|
$unzip = 0, |
|
|
|
|
$ifExists = '', |
|
|
|
|
$index_document = false, |
|
|
|
|
$show_output = false, |
|
|
|
|
$fileKey = 'file', |
|
|
|
|
$treat_spaces_as_hyphens = true, |
|
|
|
|
$parentId = 0, |
|
|
|
|
$content = null |
|
|
|
|
) { |
|
|
|
|
$course_info = api_get_course_info(); |
|
|
|
|
$sessionId = api_get_session_id(); |
|
|
|
|
|
|
|
|
|
if (isset($files[$fileKey])) { |
|
|
|
|
$uploadOk = process_uploaded_file($files[$fileKey], $show_output); |
|
|
|
|
|
|
|
|
|
if ($uploadOk) { |
|
|
|
|
$document = handle_uploaded_document( |
|
|
|
|
$course_info, |
|
|
|
|
$files[$fileKey], |
|
|
|
|
null, |
|
|
|
|
$path, |
|
|
|
|
api_get_user_id(), |
|
|
|
|
api_get_group_id(), |
|
|
|
|
null, |
|
|
|
|
$unzip, |
|
|
|
|
$ifExists, |
|
|
|
|
$show_output, |
|
|
|
|
false, |
|
|
|
|
null, |
|
|
|
|
$sessionId, |
|
|
|
|
$treat_spaces_as_hyphens, |
|
|
|
|
$fileKey, |
|
|
|
|
$parentId, |
|
|
|
|
$content |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Showing message when sending zip files |
|
|
|
|
if ($document && 1 == $unzip) { |
|
|
|
|
if ($show_output) { |
|
|
|
|
echo Display::return_message( |
|
|
|
|
get_lang('File upload succeeded!').'<br />', |
|
|
|
|
'confirm', |
|
|
|
|
false |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $document; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($document) { |
|
|
|
|
if ($index_document) { |
|
|
|
|
self::index_document( |
|
|
|
|
$document->getIid(), |
|
|
|
|
$course_info['code'], |
|
|
|
|
null, |
|
|
|
|
$_POST['language'] ?? '', |
|
|
|
|
$_REQUEST, |
|
|
|
|
$ifExists |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $document; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Obtains the text inside the file with the right parser. |
|
|
|
|
*/ |
|
|
|
|