Joywork/ajax/getLogForNotes.php

139 lines
5.4 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
if ($_SESSION['id'] && $_GET['object_id'] && is_numeric($_GET['object_id'])) {
$gmtmsk = get_time_zone_user();
$time_zone = '';
if($gmtmsk >= 0){
$time_zone = '+'.$gmtmsk.' hour';
} else {
$time_zone = '-'.$gmtmsk.' hour';
}
$get = clearInputData($_GET);
$agencyId = User::getAgencyIdForUser($_SESSION['id']);
if (!empty($agencyId)) {
$usersIds = User::getAllAgencyUsers($agencyId);
$usersIds[] = $agencyId;
}
$usersIds[] = $_SESSION['id'];
$usersIds = array_unique($usersIds);
//echo "<!-- \$usersIds: " . var_export($usersIds, true) . " -->";
$sql = "SELECT *,
If(
notes.created_by <> 0,
(
SELECT users.user_logo FROM users AS users
WHERE users.id = notes.created_by
),
If(notes.updated_by <> 0, (
SELECT users.user_logo FROM users AS users
WHERE users.id = notes.updated_by
), null)
) AS user_logo,
If(
notes.created_by <> 0,
(
SELECT IF(users.last_name != '' AND users.first_name != '', CONCAT(users.last_name, ' ', users.first_name, ' ', users.middle_name), users.fio) FROM users AS users
WHERE users.id = notes.created_by
),
If(notes.updated_by <> 0, (
SELECT IF(users.last_name != '' AND users.first_name != '', CONCAT(users.last_name, ' ', users.first_name, ' ', users.middle_name), users.fio) FROM users AS users
WHERE users.id = notes.updated_by
), null)
) AS user_fio
FROM object_notes AS notes
WHERE notes.created_by IN (" . implode(",", $usersIds) . ") AND notes.object_id = $get[object_id]
ORDER BY notes.created_at ASC";
$res = mysql_query($sql);
//echo "<!-- \$sql: " . var_export($sql, true) . " -->";
$date = null;
$createDate = null;
$sqlObj = "SELECT objects.*, DATE_FORMAT(objects.date_add,'%d.%m.%Y %H:%i') as date_add
FROM objects
WHERE objects.id=$_GET[object_id]";
$rezObj = mysql_query($sqlObj);
$obj = mysql_fetch_assoc($rezObj);
if ($obj['archive']) {
echo '<div class="chat-status archive"><span>Объект в архиве</span></div>';
}
while ($event = mysql_fetch_assoc($res)) {
//echo "<!-- \$event: " . var_export($event, true) . " -->";
if ($createDate == null || $createDate != date("d.m.Y", strtotime($event['created_at']))) {
$createDate = date("d.m.Y", strtotime($event['created_at']));
list($d, $m, $y) = explode(".", $createDate);
if ($y == date("Y"))
$y = "";
echo '<div class="chat-date"><span>' . $d . " " . getRusMonth($m) . " " . $y . '</span></div>';
}
$class_ev = " is__right";
$from_id = $event['created_by'];
if (!empty($event['updated_by']))
$from_id = $event['updated_by'];
if ($_SESSION['id'] == $from_id) {
$class_ev = " is__left";
}
if (!empty($event['message'])) { ?>
<div class="chat-block<?=$class_ev?>">
<div class="chat-author">
<div class="pic">
<?php
if (empty($event['user_logo'])) {
?>
<img src="/images/user-pic.svg"/>
<?php
} else {
?>
<img src="/photos/agency/<?=$event['user_logo']?>">
<?php } ?>
<div class="fio_user" title="<?=$event['user_fio']?>">
<?=$event['user_fio']?>
</div>
</div>
</div>
<div class="chat-message">
<div class="chat-content" id="chat_content_<?=$event['id']?>">
<div class="message"><?=$event['message']?></div>
<span class="time"><?=date("H:i", strtotime($time_zone, strtotime($event['created_at'])))?></span>
<!-- DELETING HERE -->
<?php if($event['created_by'] == $_SESSION['id'] || $_SESSION['id'] == $agencyId || $_SESSION['superadmin'] == '1'){ ?>
<div class="message" style="margin-top: 10px;">
<a href="javascript:{}" class="no-border" onclick="editNoteObj('<?=$event['id']?>')" title="Редактировать">
<span class="simple-button settings"><i class="jw-action-icon-settings"></i></span>
</a>
<a href="javascript:{}" class="no-border" onclick="deleteNoteObj('<?=$event['id']?>')" title="Удалить">
<span class="simple-button delete"><i class="jw-action-icon-delete"></i></span>
</a>
</div>
<?php } ?>
</div>
</div>
<div class="clear"></div>
</div>
<?php
}
}
}
?>