Smarty new Smarty db_connect st do_style if isset _SESSION admin admin

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
$Smarty = new Smarty();
db_connect();
$st = do_style();
if(isset($_SESSION['admin'])) $admin = $_SESSION['admin']; else $admin = null;
$q = "SELECT `value` FROM `site_options` WHERE `name` = 'news_on_page'";
$res = db_query($q) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$num_res = mysql_num_rows($res);
if($num_res)
$zap_on_str = (int)$row['value'];
else $zap_on_str = 9;
//=========================================================================
// E N G I N I N G
//=========================================================================
if(isset($_SESSION['admin']))
{
$do=-1;
$act = 'add_news';
$table_title = 'Добавление новости';
$title = 'Заголовок новости';
$content = 'Текст новости';
$but_cap = 'button_add';
$on_fns = 'onFocus="return FocusText(this);" onBlur="return BlurText(this);"';
if(isset($_REQUEST['ident']))
{
$ident = $_REQUEST['ident'];
if(isset($_REQUEST['id']))$id = (int)$_REQUEST['id'];
switch($ident)
{
case $ident=='add_news':
{
$title = clean_value($_POST['title']);
$news = clean_value($_POST['news']);
$user = $_SESSION['admin'];
$date = date('c');
$query = "INSERT INTO news (`id`,`title`,`content`,`user`,`date` )
VALUES ('','$title','$news','$user','$date' )";
$result = db_query($query) or die(mysql_error());
};break;
case $ident=='del_news':
{
$query = "DELETE FROM news WHERE id = '$id'";
$result = db_query($query) or die(mysql_error());
};break;
case $ident=='edit_news':
{
$do = "edit";
$_GET['do'] = 0;
$act = 'edit_news_go';
$query = "SELECT *FROM news WHERE id = '$id'";
$result = db_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$title = $row['title'];
$content = $row['content'];
$but_cap = 'button_edit';
$table_title = 'Редактирование новости';
$on_fns = '';
};break;
case $ident=='edit_news_go':
{
$title = clean_value($_POST['title']);
$news = clean_value($_POST['news']);
$user = $_SESSION['admin'];
$date = date('c');
$query = "UPDATE `news` SET `title` = '$title',`content` = '$news',`date` = '$date' WHERE `id` = $id";
$result = db_query($query) or die(mysql_error());
};break;
}
}
}
//======= Output list======================================================
$query = "SELECT * FROM `news`";
$result = db_query($query) or die(mysql_error());
$num_results = mysql_num_rows($result);
mysql_free_result($result);
$str_col = ($num_results/$zap_on_str)+1;
settype($str_col,"integer");
//Проверка количества записей и вывод нужных
if((!isset($_GET['str_id'])) || ($_GET['str_id'] == '0')) $str_id = 0;
else $str_id = (int)$_GET['str_id'];
$n_start = $str_id * $zap_on_str;
$n_end = $n_start + $zap_on_str;
$news = array();
$query = "SELECT * FROM `news` ORDER BY `id` DESC LIMIT $n_start,$n_end";
$result = db_query($query) or die(mysql_error());
While ($row = mysql_fetch_assoc($result))
{
$row['content'] = substr($row['content'],0,450);
$row['content'] .= '...';
$row['date'] = our_data($row['date']);
$news[] = $row;
}
if(isset($_REQUEST['id']))
$Smarty->assign("id",$_REQUEST['id']);
$Smarty->assign("st",$st);
$Smarty->assign("admin",$admin);
$Smarty->assign("zap_on_str",$zap_on_str);
$Smarty->assign("ident",$ident);
$Smarty->assign("table_title",$table_title);
$Smarty->assign("act",$act);
$Smarty->assign("title",$title);
$Smarty->assign("content",$content);
$Smarty->assign("but_cap",$but_cap);
$Smarty->assign("on_fns",$on_fns);
$Smarty->assign("str_col",$str_col);
$Smarty->assign("news",$news);
$Smarty->display("index.tpl");