View file news-ds/edit/index.php

File size: 5.76Kb
<?
	include_once '../../sys/inc/start.php';
	include_once '../../sys/inc/compress.php';
	include_once '../../sys/inc/sess.php';
	include_once '../../sys/inc/home.php';
	include_once '../../sys/inc/settings.php';
	include_once '../../sys/inc/db_connect.php';
	include_once '../../sys/inc/ipua.php';
	include_once '../../sys/inc/fnc.php';
	include_once '../../sys/inc/user.php';

	user_access('adm_news',null,'index.php?'.SID);

	define ('id', isset( $_GET['id'] ) ? abs(intval($_GET['id'])) : 0);	
	
	$act = mysql_fetch_assoc(mysql_query("SELECT * FROM `news` WHERE `id` = '".id."' LIMIT 1"));	
	$lists = mysql_fetch_assoc(mysql_query("SELECT name FROM `news_list` WHERE `id` = '".$act['list']."' LIMIT 1"));	
	
	// проверяем существует новость
	
	if (!empty($act)) {
	
	$title = htmlspecialchars( $act['title'] );
	$msg = htmlspecialchars($act['msg']); 
	$index = abs(intval( $act['index'] ));
	$head = abs(intval( $act['head'] ));
	$list = abs(intval( $act['list'] ));
	$link = htmlspecialchars( $act['link'] );


	if (isset($_POST['save']) && isset($user))
	{
	$title = htmlspecialchars( $_POST['title'] );
	$msg = my_esc($_POST['msg']); 
	$index = abs(intval( $_POST['index'] ));
	$head = abs(intval( $_POST['head'] ));
	$list = abs(intval( $_POST['list'] ));
	$link = htmlspecialchars( $_POST['link'] );
	if (!preg_match('#^https?://#',$link) && !preg_match('#^/#i',$link))$link;
	
	if (strlen2($title) > 33 ){ $err = 'Название слишком длинная'; }
	if (strlen2($title) < 3){ $err = 'Название слишком короткое'; }
	
	if (strlen2($msg) > 10025  ){ $err = 'Запись слишком длинная'; }
	if (strlen2($msg) < 3){ $err = 'Запись слишком короткое'; }

	if ($index > 2){ $err = 'Не верно указан парамент показ на главной страницы'; }
	if ($head > 2){ $err = 'Не верно указан парамент показ на всех страницах'; }
	
	if (empty($lists)) {$err = 'Не верно указана категория'; }

	if (!isset($err)){
	
	mysql_query("UPDATE `news` SET 
	`title` = '$title',
	`id_user` = '$user[id]',
	`msg` = '$msg',
	`list` = '$list',
	`index`  = '$index',
	`head`  = '$head',
	`link`  = '$link'
	WHERE `id` = '$act[id]' LIMIT 1");
	
	$_SESSION['message'] = 'Запись изменена ';
	header ("Location: /news/news/?id=".$act['id']."" . SID);
	exit;
	
	}
	}

// заголовок страницы

	$set['title'] = 'Новости : Запись : Рекактирование'; 
	
// head	

	include_once '../../sys/inc/thead.php';
	
	title();
	aut();
	err();

	echo'
	<link rel="stylesheet" href="/news/style.css" type="text/css">
	<div class="main_bg">
	<div class="lc_br wbg font0 relative oh" id="header_path">  
	<a href="/" style="font-size:0;"> <img src="/news/ico/home.png" alt=""> </a>       
	<span class="lc_brw"> 
	<img src="/news/ico/sep.png" alt="" class="lc_br_sep"> <span class="lc_br_text">
	<a href="/news/">Новости</a></span>
	<span class="lc_brw"> 
	<img src="/news/ico/sep.png" alt="" class="lc_br_sep"> <span class="lc_br_text">
	<a href="/news/news/?id='.$act['id'].'">'.$title.'</a></span>
	<span class="lc_brw"> 
	<img src="/news/ico/sep.png" alt="" class="lc_br_sep"> <span class="lc_br_text">
	Рекактирование</span></span>	
	</div></div>
	<form method="post">
	<div class="wrapper"> 
	<div class="block"> 
	<div class="grey" style ="margin-bottom: 6px;">Название  (32 знака): </div> 
	<div class="input-txt_wrapper"> 
	<input class="input-txt" type="text" name="title" value="'.$title.'" maxlength="32">
	</div></div>
	
	<div class="block  js-toolbar_wrap"> 
	<div class="grey" style ="margin-bottom: 6px;">Запись  (10024 знака): </div> 
	<div class="text-input__wrap">
	<textarea class="input-txt" style = "width: 95%;" tabindex="1" name="msg" rows="5" data-maxlength="10024" cols="17">'.$msg.'</textarea>
	</div></div>
	
	<div class="block break-word transpar"> 
	<div class="input-checkbox"> 
	<input type="hidden" name="head" value="0">
	<input type="checkbox" '.($head == 1 ? 'checked="checked"':'').' value="1" name="head" class="m">
	<span class="m grey chb_lbl">Показ на всех страницах (Будет отображатся только название)
	</span> </div> </div>
	
	<div class="block break-word transpar"> 
	<div class="input-checkbox"> 
	<input type="hidden" name="index" value="0">
	<input type="checkbox" '.($index == 1 ? 'checked="checked"':'').' value="1" name="index" class="m">
	<span class="m grey chb_lbl">Показ на главной страницы
	</span> </div> </div>
	
	<div class="block  js-toolbar_wrap"> 
	<div class="grey" style ="margin-bottom: 6px;">Категория: 
	<select name="list" class="select">
	'.($list > 0 ? '<option value="'.$list.'">'.$lists['name'].'</option>':'').'
	';
	
	$query = mysql_query("SELECT * FROM `news_list` ORDER BY id");
	while ($act = mysql_fetch_assoc($query))
	{
	echo'<option value="'.$act['id'].'">'.$act['name'].'</option>  ';	
	}

	echo'
	</select>
	</div>
	</div>
	<div class="block"> 
	<div class="grey" style ="margin-bottom: 6px;">Ссылка  (64 знака): </div> 
	<div class="input-txt_wrapper"> 
	<input class="input-txt" type="text" name="link" value="'.$link.'" maxlength="64">
	</div></div>
	
	</div>
	<table class="table__wrap">
	<tbody><tr>

	<td> 
	<div class="wrapper mt_0 mr0">
	<button name="save"  class="  link  blue full is_final    " style = "color: grey!important;">
	<img src="/news/ico/profile.png " alt="" class="m"> 
	<span class="m">Изменить запись</span>
	</button>
	</div></td> 
	
	</tr> 
	</tbody></table>
	</form>
	';
	
	}else{$_SESSION['message'] = 'Ошибка запись не найдена'; header("location: /news/");}
	
	include_once '../../sys/inc/tfoot.php';
?>