EIOS/inc/rejtnr_admin4.php

76 lines
2.4 KiB
PHP
Raw Normal View History

2023-12-28 15:39:22 +03:00
<?php
if(isset($_POST['admin4_save'])||isset($_POST['admin4_edit'])){
$id_item = (int)htmlspecialchars(addslashes($_POST['id_item']));
$name = htmlspecialchars(addslashes($_POST['name']));
$pos = (int)htmlspecialchars(addslashes($_POST['pos']));
$value = (float)str_replace(',','.',htmlspecialchars(addslashes($_POST['value'])));
$_SESSION['rejt']['id_item4'] = $id_item;
$_SESSION['rejt']['pos4'] = $pos;
}
if(isset($_POST['admin4_save'])){
$sql = 'INSERT INTO `'.$TB['itemspolyas'].'` VALUES (0,'.$id_item.',"'.$name.'",'.$pos.','.$value.')';
$rez = $DB->QUR($sql);
if(!$rez['err']){
$msg['msg'][]='Запись создана!';
}else{
$msg['err'][]='Запись не создана! Ошибка БД!!!';
}
$des = 'show';
}
if(isset($_POST['admin4_edit'])){
$id = (int)$_POST['id'];
$sql = 'UPDATE `'.$TB['itemspolyas'].'` SET id_item='.$id_item.',name="'.$name.'",pos='.$pos.',value='.$value.' WHERE id='.$id.' LIMIT 1';
$rez = $DB->QUR($sql);
if(!$rez['err']){
$msg['msg'][]='Запись отредактирована!';
}else{
$msg['err'][]='Запись не отредактирована! Ошибка БД!!!';
}
$des = 'show';
}
if($des == 'del'){
$id = (int)$_GET['id'];
$rez = $DB->QUR_SEL('DELETE FROM '.$TB['itemspolyas'].' WHERE id='.$id.' LIMIT 1');
$des = 'show';
}
if($des == 'add'){
$razdels = rejt_get_items();
$item=array();
if(isset($_SESSION['rejt'])) {
$item['id_item']=$_SESSION['rejt']['id_item4'];
$item['pos']=$_SESSION['rejt']['pos4']+1;
}
$smarty->assign('item',$item);
$smarty->assign('razdels',$razdels);
}
if($des == 'edit'){
$id = (int)$_GET['id'];
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id='.$id.'';
$rez = $DB->QUR_SEL($sql);
if($rez){
$razdels = rejt_get_items();
$smarty->assign('razdels',$razdels);
$smarty->assign('item',$rez[1]);
}else{
$des = 'show';
}
//echo '<pre>'.print_r($rez[1],1).'</pre>';
}
if($des == 'show'){
$items=array();
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' ORDER BY id_item,pos';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$val['razdel'] = rejt_get_items($val['id_item']);
$items[] = $val;
}
}
$smarty->assign('items',$items);
//echo '<pre>'.print_r($items,1).'</pre>';
}
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejtnr_main.html');