Joywork/templates/system__object_table.php
2026-05-22 21:21:54 +03:00

570 lines
19 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$type = 'Объект';
switch ($obj['type']) {
case 1:
if ($obj['komnat'] == 1 && $obj['studio_flag']) {
$type = "Квартира-студия";
} else {
$type = "$obj[komnat]-комнатная квартира";
}
break;
case 2:
$type = "Комната в $obj[komnat]-комнатной квартире";
break;
case 3:
$type = "$obj[komnat]-комнатный дом";
break;
case 4:
switch ($obj['type_category']){
case 1:
$type = "Офис";
break;
case 2:
$type = "Склад";
break;
case 3:
$type = "Торговая площадь";
break;
case 4:
$type = "Производство";
break;
case 5:
$type = "Помещение свободного назначения";
break;
case 6:
$type = "Здание";
break;
case 7:
$type = "Гараж";
break;
case 8:
$type = "Готовый бизнес";
break;
case 9:
$type = "Коммерческая земля";
break;
default: $type = "Помещение";
}
break;
case 5:
$type = "Часть дома";
break;
case 6:
$type = "Комплекс";
break;
case 7:
$type = "Участок";
break;
default:
$type = "$obj[komnat]-комнатная квартира";
}
$mtr = array();
if(isset($objMetroArrayTable)){
if(isset($objMetroArrayTable[$obj['id']])){
foreach($objMetroArrayTable[$obj['id']] as $m){
$mtr[] = $m['metro'];
}
}
} else {
$sql = "SELECT metro.metro FROM metro, sp_metro WHERE sp_metro.id_metro = metro.id AND sp_metro.id_obj = $obj[id]";
$result = mysql_query($sql);
while ($m = mysql_fetch_row($result)) {
$mtr[] = $m[0];
}
}
//if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:46 '.microtime(true).'`)</script>'; }
//if($post['is_custom'] == 0){
//$r_check_permissions = $user->checkMenuPermissions();
//$sql_check_manager = "SELECT `id_manager` FROM `users` WHERE `id` = ".$obj['id_add_user'];
//$result_check_manager = mysql_query($sql_check_manager);
$obj_id_manager = 0;
if(isset($menegersCheck[$obj['id_add_user']])){
$obj_id_manager = $menegersCheck[$obj['id_add_user']];
}
$user_allow_edit = 0;
if (($user->agency == 1 || $dep_user['role'] == 'admin_department' || $user->users_admin == 1 || $r_check_permissions['menu_all_objects_edit'] == 1) || ($user->manager == 1 && $user->id == $obj_id_manager['id_manager']) || ($user->id == $obj['id_add_user'])) {
$user_allow_edit = 1;
}
//}
$metroRayon = '';
if ($obj['rayon']) {
$metroRayon .= $obj['rayon'] . ' район';
}
if (count($mtr) > 0) {
$metroRayon .= ' / ' . implode(", ", $mtr);
}
$objCoordinates = [];
//if($post['is_custom'] == 0){
if (isset($objCoordinatesArrayTable)) {
if(isset($objCoordinatesArrayTable[$obj['id']])){
$objCoordinates = $$objCoordinatesArrayTable[$obj['id']];
$obj['latitude'] = $objCoordinates['latitude'];
$obj['longitude'] = $objCoordinates['longitude'];
}
} else {
$sql_coordinates = "SELECT address, latitude, longitude FROM object_location WHERE object_id=".$obj['id'];
$rezCoordinates = mysql_query($sql_coordinates);
if (mysql_num_rows($rezCoordinates) > 0) {
$objCoordinates = mysql_fetch_assoc($rezCoordinates);
$obj['latitude'] = $objCoordinates['latitude'];
$obj['longitude'] = $objCoordinates['longitude'];
}
}
//}
if ($objCoordinates && isset($objCoordinates['address'])) {
$address = $objCoordinates['address'];
} else {
$address = $obj['adres'];
if ($obj['dom']) {
$address = $address . ", " . $obj['dom'];
}
if ($obj['korpus']) {
$address = $address . ", корпус " . $obj['korpus'];
}
if ($obj['litera']) {
$address = $address . ", литера " . $obj['litera'];
}
}
$etazh = '';
if ($obj['type'] == 3) {
if ($obj['etazh_iz'] * 1 != 0) {
$etazh = $obj['etazh_iz'] . " этажей";
}
}
if ($obj['etazh'] * 1 != 0) {
$etazh = $obj['etazh'] . ' этаж';
if ((int)$obj['etazh'] == 1 && !empty($obj['etaz_first_type'])) {
$etazh = $etaz_first_types[$obj['etaz_first_type']];
}
if ($obj['etazh_iz'] * 1 != 0) {
$etazh .= "&nbsp;из&nbsp;" . $obj['etazh_iz'];
}
}
if($obj['date_really_add'] == 0 || empty($obj['date_really_add'])){
$obj['date_really_add'] = $obj['date_add'];
}
//var_dump($obj['date_add']);
//list($dateAdd, $timeAdd) = explode(" ", $obj['date_add']);
//list($d, $m, $y) = explode(".", $dateAdd);
//$date_add = $d . " " . getRusMonth($m) . " " . $y;
$updateDate = date('d.m.Y H:i:s', $obj['date_add']);
//list($dateAdd, $timeAdd) = explode(" ", $obj['date_really_add']);
//list($d, $m, $y) = explode(".", $dateAdd);
//$date_add = $d . " " . getRusMonth($m) . " " . $y;
$createDate = date('d.m.Y H:i:s', $obj['date_really_add']);
/*} else {
list($dateAdd, $timeAdd) = explode(" ", $obj['date_add']);
list($d, $m, $y) = explode(".", $dateAdd);
$date_add = $d . " " . getRusMonth($m) . " " . $y;
$updateDate = $date_add . "&nbsp;" . $timeAdd;
list($dateAdd, $timeAdd) = explode(" ", $obj['date_really_add']);
list($d, $m, $y) = explode(".", $dateAdd);
$date_add = $d . " " . getRusMonth($m) . " " . $y;
$createDate = $date_add . "&nbsp;" . $timeAdd;
}*/
if(isset($menegersCheck[$obj['id_add_user']])){
$agentData = $menegersCheck[$obj['id_add_user']];
$agentData['fio'] = trim($agentData['last_name'] . ' ' . $agentData['first_name'] . ' ' . $agentData['middle_name']);
$managerData = [];
// if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:128 '.microtime(true).'`)</script>'; }
if (isset($agentData['id_manager']) && $agentData['id_manager']) {
$managerData = $menegersCheck[$agentData['id_manager']];
$managerData['fio'] = trim($managerData['last_name'] . ' ' . $managerData['first_name'] . ' ' . $managerData['middle_name']);
} else {
$managerData['fio'] = trim($agentData['last_name'] . ' ' . $agentData['first_name'] . ' ' . $agentData['middle_name']);
}
}
/** @var array $clientData
* передается из родительского скрипта
*/
$clients = '[';
//$clientsPhone = '[';
if (isset($clientData[$obj['id']])) {
$clCount = count($clientData[$obj['id']]);
foreach ($clientData[$obj['id']] as $idx => $client) {
$clients = $clients . ($idx == 0 ? '' : ',') . json_encode($client);
}
}
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:154 '.microtime(true).'`)</script>'; }
$clients .= ']';
//$clientsPhone = ']';
$requestsCount = 0;
if (isset($objRequisitionsArrayTable) && isset($objRequisitionsArrayTable[$obj['id']])) {
$requestsCount = (int)$objRequisitionsArrayTable[$obj['id']];
} /*else {
$sqlRequest = "SELECT id FROM requisitions WHERE type_id = 4 AND cancel = 0 AND object_id = $obj[id]";
$qRequest = mysql_query($sqlRequest);
$requestsCount = mysql_num_rows($qRequest);
}*/
$presentationsCount = 0;
if(isset($presentationsCounts[$obj['id']])){
$presentationsCount = (int)$presentationsCounts[$obj['id']];
}
$meetCount = 0;
if(isset($meetCounts[$obj['id']])){
$meetCount = (int)$meetCounts[$obj['id']];
}
/*if($post['is_custom'] == 0){
/*$sqlPresentation = "SELECT id FROM sended_pdf WHERE id_object = $obj[id]";
$rezPresentation = mysql_query($sqlPresentation);
$presentationsCount = mysql_num_rows($rezPresentation);*/
/*$sqlMeet = "SELECT id FROM user_object_events WHERE object_id = $obj[id] and `type` = 'show' and calendar_view = 1
and schedule_date is not null DATE_FORMAT(schedule_date, '%Y-%m-%d %H:%i:%s') <= '".date("Y-m-d H:i:s")."'";
$rezMeet = mysql_query($sqlMeet);
$meetCount = mysql_num_rows($rezMeet);
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:173 '.microtime(true).'`)</script>'; }
*/
/*$packs = '';
$sqlAdvInPeriod = "SELECT id, name FROM `advertising_package` where id in (SELECT advertising_package_id from advertising_package_object_publish where id in (SELECT DISTINCT advertising_package_object_publish_id FROM object_publish_statistic WHERE on_moderation = 0 AND object_id=$obj[id]))";
$rezAdvInPeriod = mysql_query($sqlAdvInPeriod);
if (mysql_num_rows($rezAdvInPeriod) > 0) {
while ($pack = mysql_fetch_assoc($rezAdvInPeriod)) {
$packs = $packs . $pack['name'] . "; ";
}
}
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:185 '.microtime(true).'`)</script>'; }
}*/
$packs = '';
$promo = [];
if(isset($objPromoAdsArray[$obj['id']])){
$promo = $objPromoAdsArray[$obj['id']];
}
if($obj['add_to_avito_feed'] > 0){
$packs .= 'Авито';
if(intval($promo['avito_highlight'])){
$packs .= " (Выделение объявления)";
} else if (intval($promo['avito_xl'])){
$packs .= " (XL-объявление)";
} else if (intval($promo['avito_x2_1'])){
$packs .= " (x2 просмотров на 1 день)";
} else if ((intval($promo['avito_x2_7']))){
$packs .= " (x2 просмотров на 7 дней)";
} else if ((intval($promo['avito_x5_1']))){
$packs .= " (x5 просмотров на 1 день)";
} else if ((intval($promo['avito_x5_7']))){
$packs .= " (x5 просмотров на 7 дней)";
} else if ((intval($promo['avito_x10_1']))){
$packs .= " (x10 просмотров на 1 день)";
} else if ((intval($promo['avito_x10_7']))){
$packs .= " (x10 просмотров на 7 дней)";
}
}
if($obj['add_to_cian_feed'] > 0){
if($packs != '') $packs .= ', ';
$packs .= 'Циан';
$pr = '';
if(intval($promo['cian_standard'])) {
if($pr == '') $pr .= "(";
$pr .= "Стандарт";
} else if(intval($promo['cian_premium'])) {
if($pr == '') $pr .= "(";
$pr .= "Премиум-объявление";
} else if(intval($promo['cian_top3'])) {
if($pr == '') $pr .= "(";
$pr .= "Топ";
} else if(intval($promo['cian_ignore_pkg'])) {
if($pr == '') $pr .= "(";
$pr .= "Не использовать пакет размещений";
}
if($promo['cian_bet'] > 0){
if($pr == '') $pr .= "(";
$pr .= " Ставка аукциона ".$promo['cian_bet'];
}
if($pr != ''){
$pr .= ")";
$packs .= " ".$pr;
}
}
if($obj['add_to_bn_feed'] > 0){
if($packs != '') $packs .= ', ';
$packs .= 'Яндекс';
if(intval($promo['yandex_premium'])){
$packs .= " (Премиум)";
} else if (intval($promo['yandex_raise'])){
$packs .= " (Поднятие)";
} else if (intval($promo['yandex_promotion'])){
$packs .= " (Продвижение)";
}
}
if($obj['add_to_domclick_feed'] > 0){
if($packs != '') $packs .= ', ';
$packs .= 'Домклик';
if(intval($promo['domclick_express'])){
$packs .= " (Экспресс)";
} else if (intval($promo['domclick_premium'])){
$packs .= " (Премиум)";
} else if (intval($promo['domclick_top'])){
$packs .= " (Топ)";
}
}
if($obj['add_to_yandex_feed'] > 0){
if($packs != '') $packs .= ', ';
$packs .= 'Бесплатные';
}
if($obj['add_to_emls_feed'] > 0){
if($packs != '') $packs .= ', ';
$packs .= 'Jcat';
}
$minDate = '';
$maxDate = '';
$sumPrice = 0;
$periods = [];
$periodsCount = 0;
$days = 0;
$datetime1 = null;
$datetime2 = null;
$objFind = json_encode(array('id'=>$obj['id'], 'who_work'=>$obj['id_add_user']));
if(isset($objDatesAndPriceInPeriod) && isset($objDatesAndPriceInPeriod[$obj['id']])) {
$minDate = $objDatesAndPriceInPeriod[$obj['id']]['minDate'];
$maxDate = $objDatesAndPriceInPeriod[$obj['id']]['maxDate'];
if($objDatesAndPriceInPeriod[$obj['id']]['sumPrice'] > 0){
$sumPrice = $objDatesAndPriceInPeriod[$obj['id']]['sumPrice'];
}
if($objDatesAndPriceInPeriod[$obj['id']]['periodsCount'] > 0){
$periodsCount = $objDatesAndPriceInPeriod[$obj['id']]['periodsCount'];
}
$datetime1 = new DateTime($minDate);
$datetime2 = new DateTime($maxDate);
$difference = $datetime1->diff($datetime2);
$days = $difference->days;
}
$photo = [];
for ($num = 1; $num <= 20; $num++) {
if ($obj['photo' . $num]) {
if(stripos($obj['photo'.$num],"http://") === false && stripos($obj['photo'.$num], "https://") === false) {
$photo[] = "/photos/".$obj['photo'.$num];
}
if($obj['photo'.$num]) {
$photo[] = $obj['photo'.$num];
}
}
}
if (!count($photo)) {
$photo[] = '/images/no_photo.png';
}
//if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:303 '.microtime(true).'`)</script>'; }
$canEdit = false;
$links = '';
$edit = '';
$archive = '';
if (($obj['archive'] ||
(stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false && $obj['id_add_user'] > 0))) {
// $sqlStat = "SELECT id from object_feed_stat where object_id = $obj[id] and deleted = 0";
// $rezStat = mysql_query($sqlStat);
// $kolStat = mysql_num_rows($rezStat);
$links .= 'ad-report;';
// if ($kolStat) {
// }
}
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:321 '.microtime(true).'`)</script>'; }
if ((stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false || stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) && $obj['id_add_user'] > 0 && $obj['add_to_zipal'] == 1) {
/*if($post['is_custom'] == 0){
$sqlStat = "SELECT id from zipal_objects_posting where object_id = $obj[id] and deleted = 0";
$rezStat = mysql_query($sqlStat);
$kolStat = mysql_num_rows($rezStat);
if($kolStat) {
$links .= 'publish-report;';
}
}*/
}
if(stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false || stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) {
// $sqlAdvCostStat = "SELECT id from object_publish_statistic where on_moderation = 0 AND object_id = $obj[id]";
// $rezAdvCostStat = mysql_query($sqlAdvCostStat);
// $advCostStatCount = mysql_num_rows($rezAdvCostStat);
$links .= 'advertisingCosts;';
// if($advCostStatCount > 0) {
// }
}
if(stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false || stripos($_SERVER['SCRIPT_NAME'],"sale.php") !== false || stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) {
$links .= 'add-note;';
}
if(stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false && $obj['id_add_user'] == $_SESSION['id']) {
$edit = 'editMyObject';
if(!$obj['archive'] || $_SESSION['id'] == 93) {
$links .= 'add_client_new;';
}
}
if ((stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false && $obj['id_add_user'] != $_SESSION['id'] && $user_allow_edit == 1) || $obj['id_add_user'] == $_SESSION['id']) {
if ($obj['id_add_user'] > 0) {
$canEdit = true;
}
if ($canEdit) {
$edit = 'editObjectCan';
}
}
if (stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) {
$canEdit = true;
$edit = 'editObjectCan';
}
$canDelete = false;
if($currentUser->users_admin == 1 || $currentUser->agency == 1) {
$canDelete = true;
}
if ($isArchive && $canDelete) {
$links .= 'deleteMyObject;';
}
if($canEdit) {
$links .= 'cabinet;';
}
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:386 '.microtime(true).'`)</script>'; }
if((stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false && ($obj['id_add_user'] == $_SESSION['id'] || $canEdit)) ||
stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) {
if (!$obj['archive']) {
if (stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") != true) {
$archive = 'archiveMyObject';
}
} else {
$archive = 'unArchiveMyObject';
}
if ($_SESSION['individual'] == 0) {
/* if($post['is_custom'] == 0){
$sql_obj_send = "SELECT id FROM `objects_to_send` WHERE object_id = $obj[id] and accept_state = 'NEW'";
$q_obj_send = mysql_query($sql_obj_send);
if(mysql_num_rows($q_obj_send) == 0){
$links .= 'sendToNewUser;';
}
}*/
}
}
if ($_COOKIE['debug_spd']) { echo '<script>console.log(`templates/system__object_table.php:406 '.microtime(true).'`)</script>'; }
if ($obj['archive'] ||
(stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php") !== false && $obj['id_add_user'] > 0) ||
stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php") !== false) {
$links .= 'add-event;';
}
$obj['tags'] = '';
if(!empty($obj['activities'])){
$obj['tags'] = implode(', ', $obj['activities']);
}
$export = [
'id' => $obj['id'],
'preview' => json_encode($photo),
'type' => $obj['operation_type'] == 1 ? "Продажа" : "Аренда",
'objType' => $type,
'metro' => $metroRayon,
'address' => $address,
'allArea' => $obj['type'] == 7 ? $obj['land_area'] * 1 : $obj['ploshad'] * 1,
'liveArea' => $obj['ploshad_komn'],
'kitchenArea' => $obj['ploshad_k'] * 1,
'floor' => $etazh,
'price' => number_format($obj['stoim'], 0, ',', ' '),
'prep_price' => number_format($obj['prep_price'], 0, ',', ' '),
'start_price' => number_format($obj['start_price'], 0, ',', ' '),
'fact_price' => number_format($obj['fact_price'], 0, ',', ' '),
'manager' => $managerData['fio'],
'agent' => $agentData['fio'],
'client' => $clients,
'createDate' => $createDate,
'updateDate' => $updateDate,
'requests' => $requestsCount,
'presentations' => $presentationsCount,
'meets' => $meetCount,
'advPacks' => $packs,
'advStart' => $minDate ? date("d.m.Y", strtotime($minDate)) : '',
'advEnd' => $maxDate ? date("d.m.Y", strtotime($maxDate)) : '',
'daysCount' => $days,
'adv_price' => number_format($sumPrice, 2, '.', ' '),
'contract_type' => isset($contracts[$obj['id']]['types']) ? $contracts[$obj['id']]['types'] : '',
'contract_number' => isset($contracts[$obj['id']]['types']) ? $contracts[$obj['id']]['numbers'] : '',
'contract_date' => isset($contracts[$obj['id']]['dates']) ? $contracts[$obj['id']]['dates'] : '',
'cadastral_number' => $obj['cadastral_number'],
'tags' => $obj['tags']
];
?>
<tr>
<?php if(!isset($_POST['find_object'])){ ?>
<td></td>
<td><?= $edit ?></td>
<td><?= $archive ?></td>
<td><?= $links ?></td>
<?php } else { ?>
<td><?= $objFind ?></td>
<?php } ?>
<?php foreach ($orderMap as $column) {
echo "<td>" . $export[$column] . "</td>";
}?>
</tr>
<?php
if (stripos($_SERVER['SCRIPT_NAME'],"getObjectsView.php")) {
//$_SESSION['my_objects_export'][] = $export;
} else if (stripos($_SERVER['SCRIPT_NAME'],"getAgencyObjects.php")) {
//$_SESSION['agency_objects_export'][] = $export;
}
?>