90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
|
|
<?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 complexes_frame WHERE agency_id = $agent_id");
|
||
|
|
if ($frame = mysql_fetch_assoc($q)) {
|
||
|
|
// http://localhost:8080
|
||
|
|
$frame['url'] = "$site_url/complexes-frame/#/" . $frame['token'] . "/view";
|
||
|
|
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) {
|
||
|
|
$end_date = isset($_POST['endDate']) ? $_POST['endDate'] : null;
|
||
|
|
$frame_color = isset($_POST['main_color']) ? $_POST['main_color'] : null;
|
||
|
|
$client_funnel_id = isset($_POST['client_funnel_id']) ? $_POST['client_funnel_id'] : null;
|
||
|
|
$req_funnel_id = isset($_POST['req_funnel_id']) ? $_POST['req_funnel_id'] : null;
|
||
|
|
$color_reserved = isset($_POST['color_reserved']) ? $_POST['color_reserved'] : null;
|
||
|
|
$color_free = isset($_POST['color_free']) ? $_POST['color_free'] : null;
|
||
|
|
|
||
|
|
$q = mysql_query("SELECT * FROM complexes_frame WHERE agency_id = $agent_id");
|
||
|
|
|
||
|
|
$update_fields = [];
|
||
|
|
if ($end_date !== null) {
|
||
|
|
$update_fields[] = "end_date = '$end_date'";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($frame_color !== null) {
|
||
|
|
$update_fields[] = "frame_color = '$frame_color'";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($client_funnel_id !== null) {
|
||
|
|
$update_fields[] = "client_funnel_id = '$client_funnel_id'";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($req_funnel_id !== null) {
|
||
|
|
$update_fields[] = "req_funnel_id = '$req_funnel_id'";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($color_reserved !== null) {
|
||
|
|
$update_fields[] = "color_reserved = '$color_reserved'";
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($color_free !== null) {
|
||
|
|
$update_fields[] = "color_free = '$color_free'";
|
||
|
|
}
|
||
|
|
if ($frame = mysql_fetch_assoc($q)) {
|
||
|
|
|
||
|
|
if (!empty($update_fields)) {
|
||
|
|
$update_query = "UPDATE complexes_frame SET " . implode(', ', $update_fields) . " WHERE agency_id = $agent_id";
|
||
|
|
// var_dump($update_query);die;
|
||
|
|
$query = mysql_query($update_query);
|
||
|
|
// var_dump($query);die;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$token = md5($agent_id . time());
|
||
|
|
$query = mysql_query("INSERT INTO complexes_frame SET token = '$token', agency_id = $agent_id," . implode(', ', $update_fields));
|
||
|
|
|
||
|
|
die(mysql_error());
|
||
|
|
}
|
||
|
|
echo ($query);
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
|
||
|
|
default:
|
||
|
|
break;
|
||
|
|
}
|