Joywork/cabinet-edit.php
2026-05-22 21:21:54 +03:00

322 lines
20 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
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
if(!$_SESSION['id']) {
header("location:index.php");
die("Доступ запрещён!");
}
//ini_set('display_errors', 1);
//error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
if(isset($_POST) && isset($_POST['cabinet_id'])) {
$comment = mysql_real_escape_string($_POST['comment']);
$cabinetId = mysql_real_escape_string($_POST['cabinet_id']);
$showSame = mysql_real_escape_string($_POST['showSame']);
$showSame = mysql_real_escape_string($_POST['showSame']);
$showEmptyLinks = mysql_real_escape_string($_POST['showEmptyLinks']);
$sql = "UPDATE object_cabinet SET comment = '$comment', show_same = '$showSame', show_empty_links = '$showEmptyLinks' WHERE id=$cabinetId";
mysql_query($sql);
$sqlCabinetInfo = "SELECT * FROM object_cabinet WHERE id=$cabinetId";
$rezCabinetRez = mysql_query($sqlCabinetInfo);
$cabinetObj = mysql_fetch_assoc($rezCabinetRez);
header("location:/cabinet-edit.php?id=" . $cabinetObj['object_id']);
exit();
}
require($_SERVER['DOCUMENT_ROOT']."/templates/new-header.php");
$get=clearInputData($_GET);
if(!isset($post) && isset($get) && isset($get['id']) && $get['id'] != 0) {
$sql="SELECT objects.*, sale_objects.house_material,
sale_objects.house_type , sale_objects.deal_type , sale_objects.build_year,
DATE_FORMAT(objects.date_add, '%d.%m.%Y') AS date_add
FROM objects objects
LEFT JOIN sale_objects sale_objects on objects.id = sale_objects.object_id
WHERE objects.id=$get[id]";
$rez=mysql_query($sql);
$obj=mysql_fetch_assoc($rez);
$cabinetObjCompetitors = [];
$sqlCabinetInfo = "SELECT * FROM object_cabinet WHERE object_id=$get[id]";
$rezCabinetRez = mysql_query($sqlCabinetInfo);
if (mysql_num_rows($rezCabinetRez) == 0) {
$sql = "INSERT INTO object_cabinet(object_id, comment, show_same, show_empty_links) VALUES('$obj[id]', NULL, 0, 0)";
mysql_query($sql);
$sqlCabinetInfo = "SELECT * FROM object_cabinet WHERE object_id=$get[id]";
$rezCabinetRez = mysql_query($sqlCabinetInfo);
$cabinetObj = mysql_fetch_assoc($rezCabinetRez);
} else {
$cabinetObj = mysql_fetch_assoc($rezCabinetRez);
}
if (isset($cabinetObj) && isset($cabinetObj['id'])) {
$cabinetObjCompetitors = ObjectCabinet::getCabinetObjCompetitorsAsObjectIds($mdb, $get['id']);
}
} else {
header("location:index.php");
die("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Не найден ИД объкта!");
}
?>
<script src="/js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
setTimeout(function(){
var elem = document.createElement('script');
elem.type = 'text/javascript';
elem.src = 'https://api-maps.yandex.ru/2.1/?load=package.standard&apikey=692f0a05-cb88-4158-88b9-06bc0dc93004&lang=ru_RU';
document.getElementsByTagName('body')[0].appendChild(elem);
}, 1000);
</script>
<link rel="stylesheet" href="cabinet/css/styles.min.css">
<div class="content-right">
<div class="inner">
<div class="main-title">
<h1>
Кабинет клиента
</h1>
</div>
<div class="new-object">
<div class="new-object__form">
<form method="post">
<div class="block">
<h2>Настройки кабинета клиента для объекта <a target="_blank" href="/object.php?id=<?php echo $obj['id']; ?>"><?php echo $obj['id']; ?></a> (<?php echo $obj['nazv']; ?>)</h2>
<div class="jw__NB" style="padding-bottom: 10px;">
<a target="_blank" href="/cabinet.php?token=<?php echo md5($cabinetObj['id']);?>" class="fr-btn edit-btn steel i-btn very-small" style="-webkit-box-sizing:initial;">Предварительный просмотр</a>
<a class="fr-btn edit-btn steel i-btn very-small" style="-webkit-box-sizing:initial;" onclick="copyUrl();">Отправить клиенту</a>
</div>
<div class="line rooms">
<div class="title-line">
<div class="label" style="width: 200px;"><span>Показывать конкурентов:</span></div>
<div class="inputs" style="margin-left: 210px;">
<div class="inputs-group jw__NB" style="padding-bottom: 5px; padding-top: 0;">
<table>
<tr>
<td width="100px;">
<div class="checkbox">
<input name="showSame" id="showSame" type="checkbox" value="1" <?php if($cabinetObj['show_same'] == 1) echo "checked"; ?>>
<label for="showSame">&nbsp;</label>
</div>
</td>
<td style="vertical-align: top;">
<div id="showSameButton" <?php if($cabinetObj['show_same'] == 1) { echo "style='padding-top: 5px;'"; } else { echo "style='display:none; padding-top: 5px'"; } ?>>
<button type="button" data-id="<?php echo $cabinetObj['object_id'];?>" class="action-button actionJW showCabinetAnalyticsWindow">Работа с конкурентами</button>
</div>
<script type="text/javascript">
$('#showSame').click(function() {
if (this.checked) {
$("#showSameButton").show();
$("#competitors").show();
$("#averagePriceButtonCabinetContainer").show();
} else {
$("#showSameButton").hide();
$("#competitors").hide();
$("#averagePriceButtonCabinetContainer").hide();
}
});
</script>
</td>
<td style="padding-left: 20px;vertical-align: top;">
<div class="tab__controls-bottom" id="averagePriceButtonCabinetContainer" <?php if($cabinetObj['show_same'] == 1 && count($cabinetObjCompetitors) > 0) { echo ""; } else { echo "style='display:none;'"; } ?>>
<button class="tab__controls-average-btn btn-default inner-modal-opener" type="button" onclick="showAveragePrices();">
<svg width="18" height="18">
<use xlink:href="#icon-chart"></use>
</svg><span>Показать средние цены</span>&nbsp;<span style="font-size: 12px; border-bottom: none;" id="averageCountNumberCabinet">Объектов в сравнении: <?php echo count($cabinetObjCompetitors);?></span>
</button>
</div>
</td>
</tr>
</table>
<div id="competitors" <?php if($cabinetObj['show_same'] == 1) { echo ""; } else { echo "style='display:none;'"; } ?>>
<?php if (count($cabinetObjCompetitors) > 0) {?>
<div id="competitorsMessage" style="font-weight: bold;">Будут показаны следующие объекты конкуренов:</div>
<?php } else { ?>
<div id="competitorsMessage" style="font-weight: bold;">Будут показаны все объекты конкуренов по указанному адресу</div>
<?php } ?>
<div class="cabinet__section cabinet__section--info" style="margin-top: 15px;">
<div class="info">
<ul class="info__objects-list">
<?php
if (count($cabinetObjCompetitors) > 0) {
include($_SERVER['DOCUMENT_ROOT'] . "/templates/object_cabinet_objects_list.php");
}
?>
</ul>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="line rooms">
<div class="title-line">
<div class="label" style="width: 200px;"><span>Выводить список бесплатных сайтов:</span></div>
<div class="inputs" style="margin-left: 210px;">
<div class="inputs-group">
<div class="checkbox">
<input name="showEmptyLinks" id="showEmptyLinks" type="checkbox" value="1" <?php if($cabinetObj['show_empty_links'] == 1) echo "checked"; ?>>
<label for="showEmptyLinks">&nbsp;</label>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="line rooms">
<div class="title-line">
<div class="label" style="width: 200px;"><span>Дополнительные данные:</span></div>
<div class="inputs" style="margin-left: 210px;">
<div class="inputs-group">
<textarea style="height: 400px;" id="comment" name="comment" rows="10"><? echo $cabinetObj['comment'];?></textarea>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<div class="line rooms">
<div class="title-line">
<div class="label" style="width: 200px;"><span>Дополнительные ссылки:</span></div>
<div class="inputs" style="margin-left: 210px;">
<div class="inputs-group">
<div class="jw__NB">
<div>
<button type="button" data-id="<?php echo $cabinetObj['id'];?>" class="action-button actionJW addCabinetLink">Добавить</button>
</div>
<div class="jw__NB__flat-list">
<table>
<thead>
<tr>
<th></th>
<th>Наименование</th>
<th>Ссылка</th>
<th>Просмотры</th>
<th></th>
</tr>
</thead>
<tbody id="cabinetData">
<?php
$sqlCabinetFeeds = "SELECT * FROM object_cabinet_feeds WHERE object_cabinet_id=$cabinetObj[id]";
$rezCabinetFeeds = mysql_query($sqlCabinetFeeds);
include($_SERVER['DOCUMENT_ROOT']."/templates/cabinet_links_body.php");
?>
</tbody>
</table>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function () {
tinymce.init(
{
"language": "ru",
"selector":"#comment",
"style_formats_merge":true,
"theme":"modern",
"plugins":["advlist autolink lists link image charmap print preview hr anchor pagebreak","searchreplace wordcount visualblocks visualchars code fullscreen","insertdatetime media nonbreaking save table contextmenu directionality","emoticons template paste textcolor"],
"templates":[],
"height":300,
"fontsize_formats":"6pt 7pt 8pt 9pt 10pt 11pt 12pt 13pt 14pt 15pt 16pt 18pt 20pt 24pt 28pt 36pt 40pt 48pt","toolbar":"undo redo | fontsizeselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | forecolor backcolor | print preview media",
"image_advtab":"true",
setup: function( editor ){
editor.on('init', function( e ){
$('#' + e.target.id + '_ifr').removeAttr('title');
});
}
}
);
});
function copyUrl() {
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute("id", "dummy_id");
document.getElementById("dummy_id").value = document.getElementById("cabinet_url").value;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
alert("Ссылка скопирована")
}
function deleteConcurrentObject(that) {
$.ajax({
url: '/ajax/deleteCabinetCompetitorObject.php?competitorObjectId=' + $(that).attr('data-id') + '&cabinetId=<?php echo $cabinetObj['id'];?>',
success: function(data) {
$(".info__objects-list").html(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("eRROR: " + errorThrown);
}
});
}
function showAveragePrices() {
$.ajax({
url: '/ajax/modals/cabinetAvaragePricesContent.php?cabinetId=' + $("#cabinet_id").val(),
success: function(data) {
$("#average_prices_window_bg").html(data).fadeIn(500);
$("#average_prices_window").toggle(10);
$("body").addClass("lock");
$("#average_prices_window_bg .load-bar").addClass("hidden");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("eRROR: " + errorThrown + "; status:" + textStatus);
}
});
}
function selectAllOnPageForCabinet() {
$.each($(".object__list .object-card"), function (i, el) {
let id = el.id.replace("item_map", "");
id = id.replace("item", "");
if (!$("#addToSelectedCabinet__" + id).is(":checked")) {
$("#addToSelectedCabinet__" + id).click();
}
if (!$("#addToSelectedCabinetMap__" + id).is(":checked")) {
$("#addToSelectedCabinetMap__" + id).click();
}
});
}
</script>
</div>
<div class="" style="position: relative;">
<input type="hidden" name="cabinet_id" id="cabinet_id" value="<?php echo $cabinetObj['id']; ?>">
<input type="hidden" name="cabinet_url" id="cabinet_url" value="https://joywork.ru/cabinet.php?token=<?php echo md5($cabinetObj['id']);?>">
<button class="button-fl-left big-button" onclick="" type="submit">Сохранить</button>
<div class="load-bar hidden">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="load-bar__center">
<span class="load-bar__loading">Сохраняем...</span>
</div>
</div>
<div class="clear"></div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require($_SERVER['DOCUMENT_ROOT']."/templates/footer.php"); ?>