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

24 lines
825 B
PHP
Raw 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");
$id = (int)$_POST['id'];
$sql = "SELECT site_published FROM objects_site_published WHERE object_id = $id";
$result = mysql_query($sql);
$data = mysql_fetch_assoc($result);
if ($data) {
$newValue = $data['site_published'] == 1 ? 0 : 1;
$sql_update = "UPDATE objects_site_published SET site_published = $newValue WHERE object_id = $id";
mysql_query($sql_update);
} else {
$newValue = 1;
$sql_insert = "INSERT INTO objects_site_published (object_id, site_published) VALUES ($id, $newValue)";
mysql_query($sql_insert);
}
echo json_encode([
'status' => 'success',
'newValue' => $newValue,
'newTitle' => $newValue == 1 ? 'Снять с сайта компании' : 'Опубликовать на сайте компании'
]);