Joywork/admin/ajax/togglePresentationFrame.php

70 lines
2.0 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
$agent_id = null;
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$agent_id = $_GET['id'];
if ($_SESSION['id'] && $agent_id && (int)$agent_id > 0) {
$q = mysql_query("SELECT * FROM presentation_frame WHERE agency_id = $agent_id");
if ($frame = mysql_fetch_assoc($q)) {
// http://localhost:8080
$frame['url'] = "$site_url/new-buildings-frame/#/catalogs/" . $frame['token'];
echo json_encode([
'status' => true,
'data' => $frame,
]);
exit;
}
echo json_encode([
'status' => false,
'message' => 'Frame not found',
]);
exit;
}
break;
case 'POST':
if(!isset($_POST['id'])) {
$agent_id = $_SESSION['agency_id'];
} else {
$agent_id = $_POST['id'];
}
if ($_SESSION['id'] && $agent_id && (int)$agent_id > 0) {
$region_id = isset($_POST['region']) ? (int)$_POST['region'] : null;
$end_date = isset($_POST['endDate']) ? $_POST['endDate'] : null;
$color = isset($_POST['color']) ? $_POST['color'] : null;
$q = mysql_query("SELECT * FROM presentation_frame WHERE agency_id = $agent_id");
$update_fields = [];
if ($region_id !== null) {
$update_fields[] = "rf_region_id = $region_id";
}
if ($end_date !== null) {
$update_fields[] = "end_date = '$end_date'";
}
if ($color !== null) {
$update_fields[] = "color = '$color'";
}
if ($frame = mysql_fetch_assoc($q)) {
if (!empty($update_fields)) {
$update_query = "UPDATE presentation_frame SET " . implode(', ', $update_fields) . " WHERE agency_id = $agent_id";
$query = mysql_query($update_query);
}
} else {
$token = md5($agent_id . time());
$query = mysql_query("INSERT INTO presentation_frame SET token = '$token', agency_id = $agent_id," . implode(', ', $update_fields));
die(mysql_error());
}
echo ($query);
}
break;
default:
break;
}