79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?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'])));
|
|
$status = (int)htmlspecialchars(addslashes($_POST['status']));
|
|
$_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.','.$status.')';
|
|
$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.',status='.$status.' 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('UPDATE `'.$TB['itemspolyas'].'` SET status=0 WHERE id='.$id.' LIMIT 1');
|
|
//$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_rejt_main.html'); |