103 lines
3.6 KiB
PHP
103 lines
3.6 KiB
PHP
<?php
|
|
//error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
|
//ini_set('display_errors', 'On');
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
if ($_SESSION['id']) {
|
|
$user_id = $_SESSION['id'];
|
|
$post = clearInputData($_POST);
|
|
$doc_id = (!empty($post['doc_id'])) ? $post['doc_id'] : ((!empty($post['doc_id_save'])) ? $post['doc_id_save'] : null);
|
|
$client_id = (!empty($post['client_id'])) ? $post['client_id'] : null;
|
|
$email = (!empty($post['email'])) ? $post['email'] : null;
|
|
$theme = (!empty($post['theme'])) ? $post['theme'] : "";
|
|
$text = (!empty($post['text'])) ? $post['text'] : "";
|
|
|
|
if (!is_null($client_id)) {
|
|
$email = mysql_result(mysql_query("SELECT email FROM clients WHERE deleted <> 1 AND id = $client_id"),0);
|
|
} else if (!is_null($email)) {
|
|
$email = explode(',', $email);
|
|
}
|
|
|
|
if (!is_null($doc_id) && $email) {
|
|
$doc = Docs::getInnerDoc(null, $doc_id);
|
|
if ($doc['id'] && $doc['content']) {
|
|
|
|
error_reporting(E_ALL | E_STRICT);
|
|
ini_set('display_errors', 1);
|
|
|
|
require_once(__DIR__ . '/vendor/autoload.php');
|
|
|
|
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
|
|
$fontDirs = $defaultConfig['fontDir'];
|
|
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
|
|
$fontData = $defaultFontConfig['fontdata'];
|
|
|
|
$settings = [
|
|
'mode' => 'utf-8',
|
|
'format' => 'A4',
|
|
'orientation' => 'P',
|
|
'margin_left'=> 25,
|
|
'margin_right'=> 15,
|
|
'margin_top'=> 15,
|
|
'margin_bottom'=> 15,
|
|
'margin_header'=> 10,
|
|
'margin_footer'=> 10,
|
|
'fontDir' => array_merge($fontDirs, [__DIR__ . '/engine/fonts']),
|
|
'fontdata' => $fontData + [
|
|
'lato' => [
|
|
'R' => 'Lato-Regular.ttf',
|
|
'B' => 'Lato-Bold.ttf',
|
|
]
|
|
],
|
|
'default_font' => 'lato'
|
|
];
|
|
|
|
try {
|
|
|
|
$mpdf = new \Mpdf\Mpdf($settings);
|
|
$mpdf->SetTitle($doc['name']);
|
|
$stylesheet = file_get_contents(__DIR__.'/engine/style.css');
|
|
$mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
|
|
$mpdf->WriteHTML($doc['content']);
|
|
$file_name = Docs::stringToTranslit($doc['name']) . ".pdf";
|
|
$full_path = $_SERVER['DOCUMENT_ROOT'] . "/pdf/" . $doc['agency_id'] . '-' . $doc['id'] . '-' . $file_name;
|
|
|
|
$mpdf->Output($full_path, \Mpdf\Output\Destination::FILE);
|
|
sleep(1);
|
|
|
|
if (!$theme)
|
|
$theme = 'Документ';
|
|
|
|
if (!$text)
|
|
$text = "\r\n";
|
|
|
|
$result = true;
|
|
if (is_array($email)) {
|
|
foreach ($email as $addr) {
|
|
$result = mailClient(trim($addr), $theme, $text, [$full_path], [$doc['name']]);
|
|
}
|
|
} else {
|
|
$result = mailClient(trim($email), $theme, $text, [$full_path], [$doc['name']]);
|
|
}
|
|
|
|
// Cleanup PDF
|
|
unlink($full_path);
|
|
|
|
echo json_encode([
|
|
'result' => $result,
|
|
'user_id' => $user_id,
|
|
'email' => $email,
|
|
'theme' => $theme,
|
|
'text' => $text,
|
|
'doc' => $doc,
|
|
'full_path' => $full_path,
|
|
]);
|
|
exit();
|
|
|
|
} catch(\Mpdf\MpdfException $e) {
|
|
echo $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
} |