<?
define("ADMIN_AUTHORIZATION",1);
include("../../../includes/common.php");
$table = "banners";
$id = trim($_GET['id']=="")?trim($_POST['id']):trim($_GET['id']);
$CheckObj=new TCheckForm;
//$res=pg_query($DB_LINK, );
/*getting row*/
if($id>0){
$row = mysql_fetch_object(mysql_query("select * from $table where id=$id"));
$name = $row->name;
$html_code = $row->html_code;
$stat=$row->status;
}
else{
$id=-1;
}
/* generating fields */
$fields=Array();
if ($id>0) {
$fields[id]=Array($id,'ID:');
}
$fields = Array_Merge($fields,Array(
"name" => Array('<input type="text" size=20 class="text_input" maxlength=255>','Название:',"Введите название."),
"html_code" => Array('<textarea cols="75" rows="15">','HTML код:'),
"stat" => Array('<select><option value="1">Активный<option value="0">Не активный</select>','Статус:','Укажите статус, пожалуйста.',"^0|1$")
));
if(isset($_POST['subm'])){
reset ($_POST);
while (list($key, $value) = each ($_POST)) {
$$key = $value;
}
if($error==""){
$arr = Array(
"name" => addslashes($name),
"html_code" => addslashes($html_code),
"status" => $stat,
// "js_code" => "<script src="/banners.php?id=1&pid=24" language="javascript" type="text/javascript"></script>"
);
if(($id<0?AddRecord($table,$arr,1):UpdateRecord($table,$arr,$id)) ){
$arr = Array(
"js_code" => "<script src=\"/banners.php?id=".$id."&pid=24\" language=\"javascript\" type=\"text/javascript\"></script>"
);
UpdateRecord($table,$arr,$id);
$_SESSION['STATUS_MSG'] = "Информация успешно сохранена!";
header("Location: ./banners.php");
exit;
}
else{
$_SESSION['ERROR_MSG'] = "Ошибка при работе с базой данных.";
header("Location: ./banners.php");
exit;
}
}
}
$pass="";
$c_pass="";
foreach($fields as $key=>$value){
$$key=htmlspecialchars(stripslashes($$key));
$smarty->assign($key,$$key);
}
/* smarty */
$smarty->assign('id',$id);
$page_title = $id>0?"Изменение выносного кода":"Добавление нового выносного кода";
$smarty->assign('index_page','./index.php?l_pager');
$smarty->assign('page_title',$page_title);
$smarty->assign('top_menu_tpl',"admin_ads_menu.tpl");
$smarty->assign('error',$error);
$smarty->assign('status',$status);
/* table template */
$smarty->assign('fields',$fields);
$smarty->assign('table_width',"95%");
$smarty->assign('main_tpl',"admin_add_form.tpl");
/* display content */
$smarty->display('admin_index.tpl');
?>