80 lines
3.7 KiB
PHP
80 lines
3.7 KiB
PHP
|
|
<?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']) {
|
||
|
|
|
||
|
|
$userId = $_SESSION['id'];
|
||
|
|
|
||
|
|
$user = new User;
|
||
|
|
$user->get($userId);
|
||
|
|
|
||
|
|
$post = clearInputData($_POST);
|
||
|
|
|
||
|
|
$packageId = $post['packageId'];
|
||
|
|
$name = $post['name'];
|
||
|
|
$days = $post['days'];
|
||
|
|
$dealTypeId = $post['dealType'];
|
||
|
|
$objectTypeId = $post['objectType'];
|
||
|
|
$priceTypeId = $post['priceType'];
|
||
|
|
$hasPhoto = $post['hasPhoto'] === 'true' ? 1 : 0;
|
||
|
|
$price = $post['price'];
|
||
|
|
$basePrice = $post['basePrice'];
|
||
|
|
$destinations = $post['destinations'];
|
||
|
|
|
||
|
|
$priceType = null;
|
||
|
|
$region = $post['region_code'];
|
||
|
|
|
||
|
|
$sqlDealType = "SELECT * FROM advertising_package_deal_type WHERE id=$dealTypeId";
|
||
|
|
$rezDealType = mysql_query($sqlDealType);
|
||
|
|
$dealType = mysql_fetch_assoc($rezDealType);
|
||
|
|
|
||
|
|
$sqlObjectType = "SELECT * FROM advertising_package_object_type WHERE id=$objectTypeId";
|
||
|
|
$rezObjectType = mysql_query($sqlObjectType);
|
||
|
|
$objectType = mysql_fetch_assoc($rezObjectType);
|
||
|
|
|
||
|
|
if ($dealType['code'] == 'RENT') {
|
||
|
|
if (!$priceTypeId || $priceTypeId == -1) {
|
||
|
|
echo "<p style='color: red;'>Необходимо указать Тип цены для типа сделки Аренда</p>";
|
||
|
|
exit();
|
||
|
|
} else {
|
||
|
|
$sqlPriceType = "SELECT * FROM advertising_package_price_type WHERE id=$priceTypeId";
|
||
|
|
$rezPriceType = mysql_query($sqlPriceType);
|
||
|
|
$priceType = mysql_fetch_assoc($rezPriceType);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$priceTypeId = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($packageId) {
|
||
|
|
$sql = "UPDATE advertising_package SET region_rf_id = '$region', name = '$name', updated_at = NOW(), days_count = '$days', advertising_package_deal_type_id = '$dealTypeId', advertising_package_object_type_id = '$objectTypeId', is_room = '$objectType[is_room]', has_photo = '$hasPhoto', advertising_package_price_type_id = '$priceTypeId', price = '$price', base_price = '$basePrice' WHERE id=$packageId";
|
||
|
|
mysql_query($sql);
|
||
|
|
|
||
|
|
$sql = "UPDATE advertising_package_destinations SET deleted = 1 where advertising_package_id = $packageId";
|
||
|
|
mysql_query($sql);
|
||
|
|
|
||
|
|
foreach ($destinations as $key => $dest) {
|
||
|
|
$feed = $dest['feed'] === 'true' ? 1 : 0;
|
||
|
|
$sql = "INSERT into advertising_package_destinations(created_at, advertising_package_id, destination, feed, placement_type, manual_price, price) VALUES" .
|
||
|
|
" (NOW(), '$packageId', '$dest[destination]', '$feed', '$dest[placementType]', '$dest[manualPrice]', '$dest[price]')";
|
||
|
|
mysql_query($sql);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$sql = "INSERT into advertising_package(name, created_at, create_user_id, days_count, advertising_package_deal_type_id, advertising_package_object_type_id, is_room, has_photo, advertising_package_price_type_id, price, base_price, agency_id, region_rf_id) VALUES" .
|
||
|
|
" ('$name', NOW(), '$userId', '$days', '$dealTypeId', '$objectTypeId', '$objectType[is_room]', '$hasPhoto', '$priceTypeId', '$price', '$basePrice', $user->agencyId, '$region')";
|
||
|
|
$res = mysql_query($sql);
|
||
|
|
|
||
|
|
if ($res) {
|
||
|
|
$packId = mysql_insert_id();
|
||
|
|
foreach ($destinations as $key => $dest) {
|
||
|
|
$feed = $dest['feed'] === 'true' ? 1 : 0;
|
||
|
|
$sql = "INSERT into advertising_package_destinations(created_at, advertising_package_id, destination, feed, placement_type, manual_price, price) VALUES" .
|
||
|
|
" (NOW(), '$packId', '$dest[destination]', '$feed', '$dest[placementType]', '$dest[manualPrice]', '$dest[price]')";
|
||
|
|
mysql_query($sql);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|