File size: 5.94Kb
<?php
/**
* Created by PhpStorm.
* User: Valeriy Shikuta aka Str@nnik
* Date: 14.02.2016
* Time: 19:59
* File: add_ad.php
* ICQ: 609-745-227
* E-mail: [email protected]
*/
if ($id && $user_id)
{
require_once ('../incfiles/lib/class.upload.php');
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `board_categories` WHERE `id` = $id"));
$father_cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `board_categories` WHERE `id` = " . $cat['cat_id'] . ""));
echo '<div class="phdr"><a href="./">Доска объявлений</a> | <a href="./?id=' . $father_cat['id'] . '">' . $father_cat['name'] . '</a> | ' . $cat['name'] . '</div>';
if (isset($_POST['submit']))
{
$name = isset($_POST['name']) ? mb_substr(functions::checkin(trim($_POST['name'])), 0, 50) : null;
$desc = isset($_POST['desc']) ? mb_substr(functions::checkin(trim($_POST['desc'])), 0, 1000) : null;
$days = isset($_POST['days']) ? abs(intval($_POST['days'])) : 0;
$end = time() + (3600 * 24 * $days);
$status = ($set_board['moderation'] == 1) ? 0 : 1;
$error = array();
if (empty($name))
$error[] = 'Введите название объявления!';
if (empty($desc))
$error[] = 'Введите описание объявления!';
if ($days == 0 || $days < 0)
$error[] = 'Количество дней должно быть больше нуля!';
if ($set_board['pay'] == 1 && (($days - $set_board['free_days']) * $set_board['price']) > $datauser['balans'])
$error[] = 'У вас недостаточно средств на балансе!';
if (!$error)
{
$handle = new upload($_FILES['img']);
if ($handle->uploaded)
{
$fname = time();
$handle->file_new_name_body = $fname;
$handle->allowed = array (
'image/jpeg',
'image/jpg',
'image/gif',
'image/png'
);
$handle->file_max_size = 1024 * $set['flsz'];
$handle->file_overwrite = true;
$handle->image_convert = 'png';
$handle->process('../images/board/');
$handle->file_new_name_body = $fname;
$handle->file_overwrite = true;
$handle->image_resize = true;
$handle->image_x = 25;
$handle->image_y = 25;
$handle->image_convert = 'png';
$handle->process('../images/board/small/');
if ($handle->processed)
{
mysql_query("INSERT INTO `board_ads` SET
`cat_id` = $id,
`user_id` = $user_id,
`img` = '" . $fname . "',
`name` = '" . mysql_real_escape_string($name) . "',
`desc` = '" . mysql_real_escape_string($desc) . "',
`end` = $end,
`time` = " . time() . ",
`status` = $status");
}
else
{
echo functions::display_error($handle->error);
}
$handle->clean();
}
else
{
mysql_query("INSERT INTO `board_ads` SET
`cat_id` = $id,
`user_id` = $user_id,
`name` = '" . mysql_real_escape_string($name) . "',
`desc` = '" . mysql_real_escape_string($desc) . "',
`end` = $end,
`time` = " . time() . ",
`status` = $status");
}
if ($set_board['pay'] == 1)
{
$price = ($days - $set_board['free_days']) * $set_board['price'];
mysql_query("UPDATE `users` SET `balans` = `balans` - $price WHERE `id` = $user_id");
}
header('location: ./?act=list&id=' . $id);
}
else
{
echo functions::display_error($error, '<a href="' . $_SERVER['HTTP_REFERER'] . '">Повторить</a>');
}
}
else
{
echo '<div class="gmenu"><form action="./?act=add_ad&id=' . $id . '" method="post" name="form" enctype="multipart/form-data">'
. '<p>Название объявления (max 50):</p>'
. '<input type="text" name="name">'
. '<p>Описание (max 1000):<br>';
echo bbcode::auto_bb('form', 'desc');
echo '<textarea rows="' . $set_user['field_h'] . '" name="desc"></textarea></p>'
. '<p>Изображение:</p>'
. '<input type="file" name="img">';
if ($set_board['pay'] == 1)
{
echo '<p>Сколько дней показывать? <li>Включен лимит бесплатных дней. Стоимость ' . $set_board['price'] . ' баллов/день, ' . $set_board['free_days'] . ' дня(й) показ бесплатный</li></p>'
. '<input type="text" size="2" name="days" value="' . $set_board['free_days'] . '">';
}
else
{
echo '<p>Сколько дней показывать? <li>Лимит бесплатных дней отключен</li></p>'
. '<input type="text" size="2" name="days">';
}
echo '<p>Модерация: ' . ($set_board['moderation'] == 0 ? '<span class="red">Откл.</span>' : '<span class="green">Вкл.</span>') . '</p>'
. '<p><input type="submit" name="submit" value="Добавить"></p>'
. '</form></div>';
}
echo '<div class="menu"><a href="./?act=list&id=' . $id . '">В категорию</a></div>';
}
else
{
header('location: ./');
}