Joywork/ajax/getInnerFields.php
2026-05-22 21:21:54 +03:00

209 lines
9.3 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 (isset($_SESSION['id'])) {
$get = clearInputData($_GET);
$user = new User;
$user->get($_SESSION['id']);
$user->checkPermissions();
$agenciesHaveAccessToNewComplexes = [4, 12028, 12061, 17328, 11325, 13735, 19093, 16378, 19467, 20197, 19909, 19646];
$menuPermissions = $user->checkMenuPermissions();
if((!empty($menuPermissions) && $menuPermissions['menu_complexes'] == 1 )||
(($_SESSION['agency'] || $_SESSION['users_admin'] || (!empty($menuPermissions) && $menuPermissions['menu_complexes'] == 1))
&& (in_array($_SESSION['agency_id'] , $agenciesHaveAccessToNewComplexes)))) {
$haveComplexes = true;
}
else {
$haveComplexes = false;
}
if ($get['view'] == "list") {
$show_system_vars = false;
if (isset($get['system']))
$show_system_vars = boolval($get['system']);
?>
<table<?= $haveComplexes ? ' data-have-complexes="true"' : '' ?>>
<thead>
<tr>
<th width="20"></th>
<th width="220">Переменная</th>
<th width="280">Название</th>
<th>Автор</th>
<th>Дата/время</th>
<th width="20"></th>
</tr>
</thead>
<tbody>
<?php if ($varsList = Docs::getVariablesList(null, null, $show_system_vars)) {
$num = 1;
foreach ($varsList as $section => $variables) {
if ($section == "objects") {
//$section_id = 1;
echo '<tr class="header"><td colspan="6">Объекты</td></tr>';
} else if ($section == "clients") {
//$section_id = 2;
echo '<tr class="header"><td colspan="6">Клиенты</td></tr>';
} else if ($section == "premise" && $haveComplexes) {
//$section_id = 3;
echo '<tr class="header"><td colspan="6">ЖК.Помещение</td></tr>';
} else {
//$section_id = 0;
echo '<tr class="header"><td colspan="6">Общие</td></tr>';
}
foreach ($variables as $variable => $data) {
echo '<tr ';
if ($num % 2 > 0)
echo 'style="background-color: #f9f9f9;"';
echo '>';
if ($data['created_by'] == $_SESSION['id'] || $data['updated_by'] == $_SESSION['id'] || ($user->agency || $user->users_admin)) {
echo '<td width="20"><a href="javascript:{};" onclick="editBlankVariable(\''. $data['id'] .'\', \''. $section .'\', false);" title="Редактировать"><i class="ti-pencil"></i></a></td>';
} else {
echo '<td width="20">&nbsp;</td>';
}
echo '<td width="220" class="mask"><a href="javascript:{};" class="variable" onclick="copyVariable(this);" title="Копировать">' . $data['name'] . '</a></td>';
echo '<td width="280">' . $data['title'] . '</td>';
if (isset($data['author']) && isset($data['datetime'])) {
echo '<td>' . $data['author'] . '</td>';
echo '<td>' . $data['datetime'] . '</td>';
} else {
echo '<td colspan="3" class="text-small text-center text-muted"><i class="ti-info-alt"></i> Системная переменная с автозаполнением</td>';
}
if ($data['created_by'] == $_SESSION['id'] || $data['updated_by'] == $_SESSION['id'] || ($user->agency || $user->users_admin)) {
echo '<td width="20"><a href="javascript:{};" onclick="confirmDeleteBlankVariable(\''. $data['id'] .'\', \''. $section .'\');" title="Удалить"><i class="ti-trash"></i></a></td>';
} else {
echo '<td width="20">&nbsp;</td>';
}
echo '</tr>';
$num++;
}
}
} else {
echo '<tr>';
echo '<td colspan="6" style="text-align: center;">Нет доступных переменных</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php } else if ($get['view'] == "form" && !empty($get['section'])) {
$source_id = (isset($get['source_id'])) ? $get['source_id'] : null;
$varsList = Docs::getVariablesList(null, $get['section'], false, $source_id);
//if($)
foreach ($varsList as $section => $variables) {
foreach ($variables as $variable => $data) {
if (isset($data['id']) && isset($data['title'])) { ?>
<div class="line rooms">
<div class="title-line">
<div class="label"><span><?= $data['title']; ?></span></div>
<div class="inputs">
<div class="inputs-group">
<input type="text"
class="text small-input"
name="variables['<?= $data['id']; ?>']"
placeholder=""
value="<?= (isset($data['value']) ? $data['value'] : (isset($data['default']) ? $data['default'] : "")) ?>" />
<?php if ($user->agency || $user->users_admin) { ?>
<a href="javascript:{};" onclick="editBlankVariable('<?= $data['id']; ?>', '<?= $get['section']; ?>', true);" title="Редактировать"><i class="ti-pencil"></i></a>
<a href="javascript:{};" onclick="confirmDeleteBlankVariable('<?= $data['id']; ?>', '<?= $get['section']; ?>', '<?= $get['source_id']; ?>');" title="Удалить"><i class="ti-trash"></i></a>
<?php } ?>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<?php
}
}
}
} else if ($get['view'] == "json") {
$output = [];
$show_system_vars = false;
if (isset($get['system']))
$show_system_vars = boolval($get['system']);
$section = null;
if (isset($get['section']))
$section = $get['section'];
$varsList = Docs::getVariablesList(null, $section, $show_system_vars, null);
foreach ($varsList as $section => $variables) {
if ($section == "objects") {
$section_name = "Объект";
} elseif ($section == "premise" && $haveComplexes) {
$section_name = "ЖК.Помещение";
} elseif ($section == "clients") {
$section_name = "Клиент";
} else if($section == 'sobstv'){
$section_name = 'Собственник';
} else if($section == 'clients_more'){
$section_name = 'Клиент';
} else {
$section_name = 'Общие';
}
foreach ($variables as $variable => $data) {
if($section_get == 'infosob'){
if($section == 'sobstv' || $section == 'clients_more'){
if (isset($data['title'])) {
$output[] = [
((!empty($section_name)) ? $section_name . ": " : "") .$data['title'],
$data['name']
];
}
}
} else if($section != 'sobstv' && $section != 'clients_more') {
if (isset($data['title'])) {
$output[] = [
((!empty($section_name)) ? $section_name . ": " : "") .$data['title'],
$data['name']
];
}
}
}
}
echo json_encode($output, JSON_UNESCAPED_UNICODE);
} else if ($get['view'] == "info") {
$output = [];
$show_system_vars = false;
if (isset($get['system']))
$show_system_vars = boolval($get['system']);
$section = null;
if (isset($get['section']))
$section = $get['section'];
$source_id = (isset($get['source_id'])) ? $get['source_id'] : null;
$varsList = Docs::getVariablesList(null, $section, $show_system_vars, $source_id);
foreach ($varsList as $section => $variables) {
foreach ($variables as $variable => $data) {
if (isset($data['title'])) {
$output[$data['title']] = $data['value'];
}
}
}
echo json_encode($output);
}
}
?>