<select name="category" id="KatalogSelectCategory" onkeyup="CategorySelect();" onkeydown="CategorySelect();" onchange="CategorySelect();" multiple>{$SelectCategory}</select>
<?php
if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );
$id = intval( $_REQUEST['id'] );
if( $id )
{
$result = $db->query( "SELECT * FROM ".PREFIX."_offers_post WHERE id='{$id}'" );
if( $db->num_rows( $result ) > 0 )
{
$row = $db->get_row( $result );
$date = $row['date'];
$end_date = $row['end_date'];
$title = htmlspecialchars( stripslashes( $row['title'] ), ENT_QUOTES, $config['charset'] );
$alt_name = htmlspecialchars( stripslashes( $row['alt_name'] ), ENT_QUOTES, $config['charset'] );
$price = intval( $row['price'] );
$currency = intval( $row['currency'] );
$offers_type = intval( $row['offers_type'] );
$country = intval( $row['country'] );
$city = intval( $row['city'] );
$category = intval( $row['category'] );
$approve = intval( $row['approve'] );
$fio = htmlspecialchars( stripslashes( $row['fio'] ), ENT_QUOTES, $config['charset'] );
$phone = htmlspecialchars( stripslashes( $row['phone'] ), ENT_QUOTES, $config['charset'] );
$email = htmlspecialchars( stripslashes( $row['email'] ), ENT_QUOTES, $config['charset'] );
$http = htmlspecialchars( stripslashes( $row['http'] ), ENT_QUOTES, $config['charset'] );
$allow_comm = intval( $row['allow_comm'] );
$comm_num = intval( $row['comm_num'] );
$noDel = intval( $row['no_del'] );
$vip_date = intval( $row['vip_date'] );
$super_vip_date = intval( $row['super_vip_date'] );
$color = htmlspecialchars( stripslashes( $row['color'] ), ENT_QUOTES, $config['charset'] );
$color_date = intval( $row['color_date'] );
require_once( ENGINE_DIR."/classes/parse.class.php" );
$parse = new ParseFilter( array(), array(), 1, 1 );
$text = $parse->decodeBBCodes( $row['text'], false );
$vip_date = $vip_date > 0 ? date( "Y-m-d H:i:s", ( $vip_date + ( $config['date_adjust'] * 60 ) ) ) : "";
$super_vip_date = $super_vip_date > 0 ? date( "Y-m-d H:i:s", ( $super_vip_date + ( $config['date_adjust'] * 60 ) ) ) : "";
$color_date = $color_date > 0 ? date( "Y-m-d H:i:s", ( $color_date + ( $config['date_adjust'] * 60 ) ) ) : "";
$Offers->LoadListCity( $country );
$SelectCurrency = $Offers->ReturnSelectCurrency( $currency );
$SelectCountry = $Offers->ReturnSelectCountry( $country );
$SelectCity = $Offers->ReturnSelectCity( $country, $city );
$SelectCategory = $Offers->SelectCategory( $category );
$SelectApprove = SelectList( array( 0 => "Не промодерирован", 1 => "Промодерирован" ), $approve );
$JSOffersType = $Offers->JSType();
if( isset( $_POST['submit'] ) )
{
$EditError = "";
$LastCategory = $category;
$title = $db->safesql( htmlspecialchars( stripslashes( $_POST['title'] ), ENT_QUOTES, $config['charset'] ) );
$alt_name = $_POST['alt_name'] != "" ? totranslit( $_POST['alt_name'] ) : totranslit( $title );
$text = $db->safesql( $parse->BB_Parse( $parse->process( strip_tags( $_POST['text'] ) ), false ) );
$fio = $db->safesql( htmlspecialchars( stripslashes( $_POST['fio'] ), ENT_QUOTES, $config['charset'] ) );
$email = $db->safesql( htmlspecialchars( stripslashes( $_POST['email'] ), ENT_QUOTES, $config['charset'] ) );
$http = $db->safesql( htmlspecialchars( stripslashes( $_POST['http'] ), ENT_QUOTES, $config['charset'] ) );
$date = $db->safesql( htmlspecialchars( stripslashes( $_POST['date'] ), ENT_QUOTES, $config['charset'] ) );
$end_date = $db->safesql( htmlspecialchars( stripslashes( $_POST['end_date'] ), ENT_QUOTES, $config['charset'] ) );
$category = intval( $_POST['category'] );
$offers_type = intval( $_POST['offers_type'] );
$currency = intval( $_POST['currency'] );
$price = intval( $_POST['price'] );
$country = intval( $_POST['country'] );
$city = intval( $_POST['city'] );
$approve = intval( $_POST['approve'] );
$noDel = $_POST['no_del'] == 1 ? 1 : 0;
$vip_date = $_POST['vip_date'] != "" ? $db->safesql( strtotime( $_POST['vip_date'] ) ) : "";
$super_vip_date = $_POST['super_vip_date'] != "" ? $db->safesql( strtotime( $_POST['super_vip_date'] ) ) : "";
$color = $db->safesql( stripslashes( $_POST['color'] ) );
$color_date = $_POST['color_date'] != "" ? $db->safesql( strtotime( $_POST['color_date'] ) ) : "";
$phone = preg_replace( "/[^(0-9))(-\s]/i", "", $_REQUEST['phone'] );
if( !$title ) $EditError .= "<li>Введите название объявления.</li>";
if( !$fio && $Offers->Config['add_post_fio'] == "yes" ) $EditError .= "<li>Введите ваше имя.</li>";
if( $Offers->Config['add_post_email'] == "yes" && empty( $email ) ) $AddError .= "<li>Email адрес введён не верно.</li>";
if( !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])'.'(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', $email ) && !empty( $email ) ) $EditError .= "<li>Email адрес введён не верно.</li>";
if( !preg_match( "/^http:\/\/([-.a-z0-9]*)\.([a-z]{2,4})(\/?)*$/", $http ) ) $http = "";
if( !$text ) $EditError .= "<li>Введите текст объявления.</li>";
if( !$offers_type && $Offers->notTypeForCat( $category ) !== true ) $EditError .= "<li>Выберите тип объявления.</li>";
if( $offers_type && $Offers->AllowTypeInCats( $offers_type, $category ) !== true ) $EditError .= "<li>Выберите тип объявления.</li>";
if( !$currency && $Offers->Config['add_post_price'] == "yes" ) $EditError .= "<li>Выберите валюту стоимости.</li>";
if( !$price && $Offers->Config['add_post_price'] == "yes" ) $EditError .= "<li>Введите стоимость.</li>";
if( !$country && $Offers->Config['region_on'] == "on" ) $EditError .= "<li>Выберите вашу страну.</li>";
if( !$category ) $EditError .= "<li>Выберите категорию для объявления.</li>";
if( count( $phone ) < 1 && $Offers->Config['add_post_phone'] == "yes" ) $AddError .= "<li>Укажите телефон.</li>";
if( $Offers->Field !== false && empty( $EditError ) )
{
$xfields = $db->safesql( $Offers->Field->SaveField( "edit", $row['xfields'], $category ) );
if( $Offers->Field->ErrorSave ) $EditError .= $Offers->Field->ErrorSave;
}
if( empty( $EditError ) )
{
if( $LastCategory != $category )
{
$Offers->AddPostCategory( $category );
$Offers->DelPostCategory( $LastCategory );
}
$LinkPost = $Offers->ReturnLinkPost( $id, $alt_name, $category );
$db->query( "UPDATE ".PREFIX."_offers_post SET `title`='{$title}', `alt_name`='{$alt_name}', `category`='{$category}', `offers_type`='{$offers_type}', `price`='{$price}', `currency`='{$currency}', `country`='{$country}', `city`='{$city}', `text`='{$text}', `fio`='{$fio}', `phone`='{$phone}', `email`='{$email}', `http`='{$http}', `date`='{$date}', `end_date`='{$end_date}', `approve`='{$approve}', `xfields`='{$xfields}', `no_del`='{$noDel}', `vip_date`='{$vip_date}', `super_vip_date`='{$super_vip_date}', `color`='{$color}', `color_date`='{$color_date}' WHERE id='{$id}'" );
miniloader( "Редактирование объявления" );
opentable();
tableheader( "Редактирование объявления" );
echo "<div style=\"padding: 10px;\">Объявление успешно отредактировано</div><div class=\"hr_line\"></div><div style=\"padding: 10px;\"><a href=\"$PHP_SELF?mod=offers&action=post_edit&id={$id}\">[Вернуться назад]</a> <a href=\"{$LinkPost}\" target=\"_blank\">[Посмотреть на сайте]<a/> <a href=\"javascript:void(0);\" onclick=\"window.close(); return false;\">[Закрыть окно]</a></div>";
closetable();
minifooter();
}
else
{
miniloader( "Редактирование объявления" );
opentable();
tableheader( "Редактирование объявления" );
echo "<div style=\"padding: 10px;\"><ol style=\"color: #F00; padding: 0px 0px 0px 20px; margin: 0px;\">{$EditError}</ol></div><div class=\"hr_line\"></div><div style=\"padding: 10px;\"><a href=\"$PHP_SELF?mod=offers&action=post_edit&id={$id}\">Вернуться назад</a></div>";
closetable();
minifooter();
}
}
else
{
miniloader( "Редактирование объявления" );
opentable();
tableheader( "Редактирование объявления" );
include_once( ENGINE_DIR."/modules/offers/editor/bb_news.php" );
$bb_code = str_replace( "{THEME}", "templates/{$config['skin']}", $bb_code );
$order = array();
if( $Offers->Config['echo_post_supervip'] != "no" ) $order[] = "`super_vip_date` DESC";
if( $Offers->Config['echo_post_vip'] != "no" ) $order[] = "`vip_date` DESC";
$order[] = "`date` DESC";
$order = implode( ", ", $order );
$ThreadCatForSql = implode( ",", $ThreadCatForSql );
$NewsList = array(
"template" => "offers/{$Folder}/offers.short.tpl",
"template_nav" => "offers/{$Folder}/navigation.tpl",
"template_info" => "offers/{$Folder}/info.tpl",
"tpl_compile" => "offers_content",
"cashe_folder" => "category/",
"cashe_file" => "cashe_{$Offers->RequestCat}.tmp",
"cache" => $Offers->Config['region_on'] == "on" ? false : true,
"sql_count" => "SELECT COUNT(*) as count FROM ".PREFIX."_offers_post WHERE category IN ({$ThreadCatForSql}) AND approve='1' {$SqlRegion} {$SqlSearch}",
"sql_query" => "SELECT * FROM ".PREFIX."_offers_post WHERE category IN ({$ThreadCatForSql}) AND approve='1' {$SqlRegion} {$SqlSearch} ORDER BY {$order} {limit}",
"num" => $OnPage,
"nav" => $PageLink,
"search_info" => $SearchInfo,
"search_text" => $SearchText,
"no_news_error" => $NoNewsError,
);