Joywork/ajax/engine/pdf_functions.php

348 lines
14 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
/* Перевод в нижний регистр кириллица */
// function c_lcfirst($str, $e='utf-8') {
// $fc = mb_strtolower(mb_substr($str, 0, 1, $e), $e);
// return $fc.mb_substr($str, 1, mb_strlen($str, $e), $e);
// }
/* Сбор информации для шапки PDF */
function getHeaderData($closeHeader){
// Get current user
$user = new User;
$user->get($_SESSION['id']);
// Header data for future set default where empty (default img / text / etc.)
$header = [
'left-img' => '',
'left-title' => '',
'left-phone' => '',
'manager-name' => '',
'manager-is' => false,
'manager-img' => '',
'email' => '',
'sitename' => '',
'site' => '',
'address' => '',
'phone' => '',
'close' => $closeHeader,
];
if($user->photo)
$header['left-img'] = $_SERVER['DOCUMENT_ROOT']."/photos/agency/".$_SESSION['photo'];
else
$header['left-img'] = '';
if ($user->agency) {
$header['left-title'] = htmlspecialchars_decode($user->agency_name);
} else if ($_SESSION['agency'] && $_SESSION['agency_name']) {
$header['left-title'] = htmlspecialchars_decode($_SESSION['agency_name']);
} else if (isset($user->agencyName)) {
$header['left-title'] = htmlspecialchars_decode($user->agencyName);
}
if($user->phoneAgency){
$header['left-phone'] = $user->phoneAgency;
}else{
$header['left-phone'] = $user->phone;
}
/*if(!$_SESSION['agency'])
$header['manager-name'] = htmlspecialchars_decode($user->fio);
else
$header['manager-name'] = $user->director;
*/
$header['manager-name'] = htmlspecialchars_decode(trim($user->last_name . ' ' . $user->first_name . ' ' . $user->middle_name));
if ($_SESSION['individual'] == 1) {
$header['email'] = $_SESSION['email'];
if($user->sitename) {
$header['sitename'] = $user->sitename;
$header['site'] = $user->site;
}
$header['address'] = $user->adres;
}elseif ($_SESSION['individual'] == 0) {
$header['manager-is'] = true;
$header['email']= $_SESSION['email'];
$header['phone'] = $_SESSION['phone'];
if ($user->user_logo) {
$header['manager-img'] = $_SERVER['DOCUMENT_ROOT'] . "/photos/agency/" . $user->user_logo;
}
}
return $header;
}
/* Формирование шаблона шапки PDF */
function pdf_header($header){
if($header['close'] == 1){
$html = '';
} else {
$html = '<table class="headerTable borderHeader">
<tr width="100%">
<td width="37%">
<table>
<tr>';
if($header['left-img'] != '')
$html.= '<td class="p-r-30"><img height="40" src="'.$header['left-img'].'"></td>';
$html .= '<td class="gray">'.$header['left-title'].'</td>
</tr>
</table>
</td>
<td width="24%">
<a class="link black f-16" href="tel:'.$header['left-phone'].'">'.$header['left-phone'].'</a><br>
<a class="link gray f-14" href="mailto:'.$header['email'].'">'.$header['email'].'</a><br>
<a class="link gray f-14" href="'.$header['site'].'">'.$header['sitename'].'</a>';
if($header['address'] != ''){
$html .= '<br><a class="link gray f-14" href="">'.$header['address'].'</a>';
$html .= '</td>';
}else{
$html .= '</td>';
}
if($header['manager-is'])
$html .= '<td width="38%"><table><tr>';
if($header['manager-img']!='')
$html .= '<td><img width="50" height="50" src="'.$header['manager-img'].'"></td>';
if(!empty($header['manager-name']))
$html .= '<td style="padding-left: 20px;">
<div class="f-bold f-14 lh-15">Ваш менеджер '.$header['manager-name'].'</div>
<div><a href="mailto:'.$header['email'].'" class="link f-14 gray">'.$header['email'].'</a></div>
<div><a href="tel:'.$header['phone'].'" class="link black f-14">'.$header['phone'].'</a></div>
</td>
</tr>
</table>
</td>';
$html .= '</tr></table>';
}
return $html;
}
/* Формирование первой страницы */
function pdf_body_first($arrTop, $arrProps, $type = null, $typeCategory = null){
$data = [
'type' => $arrTop['type'],
'commerce_type' => $arrTop['commerce_type'],
'operation_type' => $arrTop['operation_type'],
'sdelka' => $arrTop['sdelka'],
'nazv' => $arrTop['nazv'],
'etazh' => $arrTop['etazh'],
'etazh_iz' => $arrTop['etazh_iz'],
'stoim' => $arrTop['stoim'],
'currency' => get_currency_sign($arrTop['currency']),
'replace_plan' => $arrTop['replace_plan'],
'planirovka' => $arrTop['plan'],
'metro' => [
'name'=> $arrTop['metrostr'],
'way'=>$arrTop['way']
],
'address' => $arrTop['address'],
'rayon' => $arrTop['rayon'],
'square' => [
'all' => $arrTop['ploshad'],
'live' => $arrTop['ploshad_komn'],
'kitchen' => $arrTop['ploshad_k'],
],
'squareLand' => $arrTop['commerc_site'],
'landArea' => $arrTop['land_area']
];
$countProps = count($arrProps);
if($countProps > 30){
$props = array_slice($arrProps,0,30);
}else{
$props = $arrProps;
}
$etazhnost = empty($data['etazh_iz']) ? $data['etazh'] : $data['etazh'].' из '.$data['etazh_iz'];
if(empty($etazhnost)) $etazhnost = '-';
$arrType = ['-', 'Квартира','Комната','Дом','Коммерческая недвижимость','Часть дома','Комплекс','Участок'];
$subtitle = $arrType[$data['type']];
if(!empty($data['commerce_type'])){
$subtitle .= ' - '.$data['commerce_type'];
}
$propsHTML = '';
$html = '
<h1 class="f-regular f-24 m-b-20 lh-10">'.$data['nazv'].'</h1>
<p class="f-16 gray m-b-20">'.$subtitle.'</p>
<p class="f-14 m-b-20"><b class="dark">Тип сделки:</b> <span class="gray">'.$data['sdelka'].'</span></p>
<table class="m-b-20">
<tr>';
if ($data['metro'] && $data['metro']['name']) {
$html .= '<td>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14.8521 1.67725L9.10085 9.84398L3.22609 1.86722L0 15.2233H4.36573L5.16558 10.9517L9.02977 16.3227L12.8738 11.0695L13.6471 15.247H18L14.8521 1.67725Z" fill="#549FC5"/>
</svg>
</td>
<td class="p-r-30 f-14"><b class="dark">'.$data['metro']['name'].'</b></td>
<td class="p-r-30 f-14"><span class="gray">'.$data['metro']['way'].'</span></td>';
}
$html .= '<td class="p-r-30 f-14"><b class="dark">'.$data['address'].'</b></td>
<td class="gray f-14"><span>'.$data['rayon'].'</span></td>
</tr>
</table>';
if ($type && ($type == 7 || ($type == 4 && $typeCategory == 9))) {
$html .= '<p class="m-b-20 gray">Цена: &nbsp; <b style="" class="f-24 black">' . $data['stoim'] . ' ' . $data['currency'] . '</b></p>
<div class="delim p-t-10"></div>';
} else {
$html .= '<p class="m-b-20 f-14"><b class="dark">Этажность:</b> <span class="gray">' . $etazhnost . '</span></p>
<p class="m-b-20 gray">Цена: &nbsp; <b style="" class="f-24 black">' . $data['stoim'] . ' ' . $data['currency'] . '</b></p>
<div class="delim p-t-10"></div>';
}
if($countProps > 15){
$layout = 1;
$propsHTML .= '<tr><td valign="top" width="50%"><table>';
for($i=0; $i < 15; $i++){
$propsHTML .= '<tr class="p-b-10"><td valign="top" class="dark f-14 p-r-30 p-b-10">'.$props[$i]['desc'].'</td><td valign="top" class="gray f-14 p-b-10">'.$props[$i]['val'].'</td></tr>';
}
$propsHTML .= '</table></td><td valign="top" width="50%"><table>';
for($i=15; $i < $countProps; $i++){
$propsHTML .= '<tr class="p-b-10"><td valign="top" class="dark f-14 p-r-30 p-b-10">'.$props[$i]['desc'].'</td><td valign="top" class="gray f-14 p-b-10">'.$props[$i]['val'].'</td></tr>';
}
$propsHTML .= '</table></td></tr>';
}elseif($countProps <= 15 && $countProps > 0){
$layout = 2;
foreach($props as $val){
$propsHTML .= '<tr><td valign="top" class="dark f-14 p-r-30 p-b-10">'.$val['desc'].'</td><td valign="top" class="gray f-14 p-b-10">'.$val['val'].'</td></tr>';
}
}else{
$layout = 3;
}
$html .= '<table class="w-100 p-t-10"><tr class="w-100">';
if ($type && $type == 4 && $typeCategory && $typeCategory == 9) {
$squareHTML = '<p class="m-b-20"><b class="f-18 black">Площадь:</b></p>
<table style="border-spacing: 0px;padding-top:10px;" class="m-b-20">
<tr>
<td align="left" class="p-r-30"><span class="gray">Общая:</span> <b>'.$data['squareLand'].' ГА</b></td>';
$squareHTML .= '</tr></table>';
} else {
if ($type && $type == 7) {
$squareHTML = '<p class="m-b-20"><b class="f-18 black">Площадь:</b></p>
<table style="border-spacing: 0px;padding-top:10px;" class="m-b-20">
<tr>
<td align="left" class="p-r-30"><span class="gray">Общая:</span> <b>'.$data['landArea'].' соток</b></td>';
$squareHTML .= '</tr></table>';
} else {
$squareHTML = '<p class="m-b-20"><b class="f-18 black">Площадь:</b></p>
<table style="border-spacing: 0px;padding-top:10px;" class="m-b-20">
<tr>
<td align="left" class="p-r-30"><span class="gray">Общая:</span> <b>' . $data['square']['all'] . ' м2</b></td>';
if (!empty($data['square']['live']))
$squareHTML .= '<td class="p-r-30"><span class="gray">Жилая:</span> <b>' . $data['square']['live'] . ' м2</b></td>';
if (!empty($data['square']['kitchen']))
$squareHTML .= '<td class="p-r-30"><span class="gray">Кухня:</span> <b>' . $data['square']['kitchen'] . ' м2</b></td>';
$squareHTML .= '</tr></table>';
}
}
$planTitle = $data['replace_plan'] ? ' ' : 'Планировка:';
switch ($layout) {
case 1:
// все свойства и картинка справа
$html .= '<td valign="top" width="61%">';
$html .= $squareHTML;
$html .= '<p class="m-b-20"><b class="f-18 black">Характеристики:</b></p>';
$html .= '<table width="100%" border="0" style="border-spacing: 0; margin-top:10px">'.$propsHTML.'</table>';
$html .= '</td>';
if(!empty($data['planirovka']))
$html .= '<td valign="top" width="39%">
<p class="m-b-20"><b class="f-18 black">'.$planTitle.'</b></p>
<img width="350px" class="p-t-10" src="'.$data['planirovka'].'">
</td>';
break;
case 2:
// половина свойств и картинка справа
$html .= '<td valign="top" width="50%">';
$html .= $squareHTML;
$html .= '<p class="m-b-20"><b class="f-18 black">Характеристики:</b></p>';
$html .= '<table width="100%" border="0" style="border-spacing: 0; margin-top:10px">'.$propsHTML.'</table>';
$html .= '</td>';
if(!empty($data['planirovka']))
$html .= '<td valign="top" width="50%">
<p class="m-b-20"><b class="f-18 black">'.$planTitle.'</b></p>
<div><img width="350px" class="p-t-10" src="'.$data['planirovka'].'"></div>
</td>';
break;
case 3:
// нет свойств и картинка снизу
$html .= '<td valign="top" width="100%">';
$html .= $squareHTML;
if(!empty($data['planirovka']))
$html .= '<p class="m-b-20"><b class="f-18 black">'.$planTitle.'</b></p>
<div><img width="350px" class="p-t-10" src="'.$data['planirovka'].'"></div>';
$html .= '</td>';
break;
}
$html .= '</tr></table>';
return $html;
}
/* Формирование второй страницы с описанием */
function pdf_body_second($opis, $img, $common) {
$html = '<h1 class="f-regular f-24 m-b-20 lh-10">Описание</h1>
<table width="100%">
<tr width="100%">';
/* Формирование доп. инфо */
if (count($common) > 0) {
$propsHTML = '';
foreach($common as $key => $value) {
$propsHTML .= '<tr><td valign="top" class="dark f-14 p-r-30 p-b-10">'.$key.':</td><td valign="top" class="gray f-14 p-b-10">'.$value.'</td></tr>';
}
$opis .= '<br/><br/>';
$opis .= '<p class="m-b-20"><b class="f-18 black">Дополнительная информация:</b></p>';
$opis .= '<table width="100%" border="0" style="border-spacing: 0; margin-top:10px">'.$propsHTML.'</table>';
}
if ($img == '') {
$html .= '<td valign="top" width="100%" class="gray p-r-30 f-12">'.$opis.'</td>';
} else {
$html .= '<td valign="top" width="61%" class="gray p-r-30 f-12">'.$opis.'</td>';
$html .= '<td valign="top" width="39%"><img width="400px" src="'.$img.'"></td>';
}
$html .= '</tr></table>';
return $html;
}
/* Формирование третьей страницы с фотографиями */
function pdf_body_third($photos){
$html = '<h1 class="f-regular f-24 m-b-20 lh-10">Фотографии</h1><div>';
foreach($photos as $photo){
$html .= '<img class="img" src="'.$photo.'">';
}
$html .= '</div>';
return $html;
}
function get_currency_sign($currencyNumber)
{
switch ($currencyNumber) {
case 0:
return 'р.';
case 1:
return '&#36;';
case 2:
return '€';
}
}
?>