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

54 lines
2.2 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");
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
if ($_SESSION['id'] && $_POST['objectId'] && is_numeric($_POST['objectId'])) {
$post = clearInputData($_POST);
$objectId = $post['objectId'];
$days = $post['days'];
$price = $post['price'];
$destinations = json_encode($post['destinations']);
//ищем только по объекту, пользователя ставим всегда текущего
$sql = "SELECT count(id) FROM zipal_objects WHERE object_id = $objectId";
$rez = mysql_query($sql);
$count = mysql_result($rez,0);
//если объект уже был, то обновляем, иначе создаем
if ($count > 0) {
$sql = "UPDATE zipal_objects SET unpublish_user_id = NULL, user_id = '$_SESSION[id]', sended = 0, published = 0, unpublish = 0, error_text = NULL, price = '$price', destinations = '$destinations', days = '$days', add_to_zipal_at = NOW() WHERE object_id = $objectId";
mysql_query($sql);
} else {
$sql = "INSERT into zipal_objects (object_id, user_id, destinations, days, price, add_to_zipal_at) VALUES ('$objectId', '$_SESSION[id]', '$destinations', '$days', '$price', NOW())";
mysql_query($sql);
}
$sql = "UPDATE objects SET use_in_advert=1, add_to_zipal=1, is_main = 0 WHERE id=$objectId";
mysql_query($sql);
$logText = "Отправлен на публикацию через кнопку С отчетами на $days дней";
$sqlLog = "INSERT INTO object_publish_log(object_id, created_at, user_id, log_text) VALUES ('$objectId', NOW(), '$_SESSION[id]', '$logText')";
mysql_query($sqlLog);
$user = new User;
$user->get($_SESSION['id']);
if (empty($user->zipal_balance)) {
$newBalance = $user->agencyZipalBalance - $price;
$sql = "UPDATE users SET zipal_balance='$newBalance' WHERE id=" . $user->agencyId;
mysql_query($sql);
} else {
$newBalance = $user->zipal_balance - $price;
$sql = "UPDATE users SET zipal_balance='$newBalance' WHERE id=$_SESSION[id]";
mysql_query($sql);
}
$array = ZipalCountText($objectId);
print json_encode($array);
}