Joywork/ajax/toggle_objects_iframe.php

42 lines
1.5 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
$agency_id = isset($_POST['agency_id']) ? intval($_POST['agency_id']) : 0;
$enable = isset($_POST['enable']) ? intval($_POST['enable']) : 0;
if ($enable == 1) {
$sql = "SELECT iframe_token,primary_color FROM object_iframe WHERE agency_id = " . $agency_id . " LIMIT 1";
$res = mysql_query($sql);
if ($res && mysql_num_rows($res) > 0) {
$row = mysql_fetch_assoc($res);
$color= $row['primary_color'];
$token = $row['iframe_token'];
mysql_query("UPDATE object_iframe
SET iframe_enabled = 1
WHERE agency_id = " . $agency_id);
} else {
$token = md5(uniqid(mt_rand(), true));
$color = '#328436';
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO object_iframe
(agency_id, iframe_token, iframe_created_at, primary_color, iframe_enabled)
VALUES ($agency_id, '$token', '$date', '$color', 1)";
$result = mysql_query($sql);
$data = mysql_fetch_assoc($result);
}
echo json_encode(['status' => 'success', 'iframe_token' => $token, 'connected' => 1,'primary_color'=> $color ]);
} else {
mysql_query("UPDATE object_iframe
SET iframe_enabled = 0
WHERE agency_id = " . $agency_id);
echo json_encode(['status' => 'success', 'connected' => 0]);
}
?>