259 lines
8.5 KiB
PHP
259 lines
8.5 KiB
PHP
|
<?php
|
||
|
if(isset($_POST['admin2f_save'])){
|
||
|
$id = (int)$_POST['id'];
|
||
|
$formuls = htmlspecialchars(addslashes($_POST['formula']));
|
||
|
$sql = 'UPDATE `'.$TB['items'].'` SET formuls="'.$formuls.'" WHERE id='.$id.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
if(!$rez['err']){
|
||
|
$msg['msg'][]='Запись отредактирована!';
|
||
|
$last_id=$id;
|
||
|
}else{
|
||
|
$msg['err'][]='Запись не отредактирована! Ошибка БД!!!';
|
||
|
}
|
||
|
//$des = 'show';
|
||
|
}
|
||
|
if(isset($_POST['admin2_save'])||isset($_POST['admin2_edit'])){
|
||
|
$id_razdel = (int)htmlspecialchars(addslashes($_POST['id_razdel']));
|
||
|
$name = htmlspecialchars(addslashes($_POST['name']));
|
||
|
$tip = (int)htmlspecialchars(addslashes($_POST['tip']));
|
||
|
$pos = (int)htmlspecialchars(addslashes($_POST['pos']));
|
||
|
$formuls = htmlspecialchars(addslashes($_POST['formuls']));
|
||
|
$descr = htmlspecialchars(addslashes($_POST['descr']));
|
||
|
$_SESSION['rejt']['id_razdel'] = $id_razdel;
|
||
|
$_SESSION['rejt']['pos'] = $pos;
|
||
|
$last_id=0;
|
||
|
}
|
||
|
if(isset($_POST['admin2_save'])){
|
||
|
$sql = 'INSERT INTO `'.$TB['items'].'` VALUES (0,'.$id_razdel.',"'.$name.'",'.$tip.','.$pos.',"'.$formuls.'","'.$descr.'")';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
if(!$rez['err']){
|
||
|
$msg['msg'][]='Запись создана!';
|
||
|
$last_id=mysql_insert_id();
|
||
|
}else{
|
||
|
$msg['err'][]='Запись не создана! Ошибка БД!!!';
|
||
|
}
|
||
|
$des = 'show';
|
||
|
}
|
||
|
if(isset($_POST['admin2_edit'])){
|
||
|
$id = (int)$_POST['id'];//,formuls="'.$formuls.'"
|
||
|
$sql = 'UPDATE `'.$TB['items'].'` SET id_razdel='.$id_razdel.',name="'.$name.'",tip='.$tip.',pos='.$pos.',descr="'.$descr.'" WHERE id='.$id.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
if(!$rez['err']){
|
||
|
$msg['msg'][]='Запись отредактирована!';
|
||
|
$last_id=$id;
|
||
|
}else{
|
||
|
$msg['err'][]='Запись не отредактирована! Ошибка БД!!!';
|
||
|
}
|
||
|
$des = 'show';
|
||
|
}
|
||
|
if(isset($_POST['admin2_save'])||isset($_POST['admin2_edit'])){
|
||
|
if(isset($_POST['polyas'])&&$last_id!=0){
|
||
|
foreach($_POST['polyas'] as $key => $val){
|
||
|
$name = htmlspecialchars(addslashes($val['name']));
|
||
|
$pos = htmlspecialchars(addslashes($val['pos']));
|
||
|
$value = (float)str_replace(',','.',htmlspecialchars(addslashes($val['value'])));
|
||
|
//$id_item=$last_id;
|
||
|
$id_item=(int)htmlspecialchars(addslashes($val['id_item']));
|
||
|
|
||
|
if($key>0){//обновление
|
||
|
if(!isset($val['del'])){
|
||
|
$sql = 'UPDATE `'.$TB['polyas'].'` SET id_item='.$id_item.',name="'.$name.'",pos='.$pos.',value='.$value.' WHERE id='.$key.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}else{
|
||
|
$sql = 'DELETE FROM `'.$TB['polyas'].'` WHERE id='.$key.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}
|
||
|
}else{//добавление
|
||
|
if($name!=''&&$value!=0){
|
||
|
$sql = 'INSERT INTO `'.$TB['polyas'].'` VALUES (0,'.$id_item.',"'.$name.'",'.$pos.','.$value.')';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(isset($_POST['itemspolya'])&&$last_id!=0){
|
||
|
foreach($_POST['itemspolya'] as $key => $val){
|
||
|
$name = htmlspecialchars(addslashes($val['name']));
|
||
|
$pos = htmlspecialchars(addslashes($val['pos']));
|
||
|
$value = htmlspecialchars(addslashes($val['value']));
|
||
|
$id_item=$last_id;
|
||
|
if($key>0){//обновление
|
||
|
if(!isset($val['del'])){
|
||
|
$sql = 'UPDATE `'.$TB['itemspolyas'].'` SET id_item='.$id_item.',name="'.$name.'",pos='.$pos.',value="'.$value.'" WHERE id='.$key.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}else{
|
||
|
$sql = 'DELETE FROM `'.$TB['itemspolyas'].'` WHERE id='.$key.' LIMIT 1';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}
|
||
|
}else{//добавление
|
||
|
if($name!=''){
|
||
|
$sql = 'INSERT INTO `'.$TB['itemspolyas'].'` VALUES (0,'.$id_item.',"'.$name.'",'.$pos.',"'.$value.'")';
|
||
|
$rez = $DB->QUR($sql);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//
|
||
|
if($des == 'del'){
|
||
|
$id = (int)$_GET['id'];
|
||
|
$rez = $DB->QUR_SEL('DELETE FROM '.$TB['items'].' WHERE id='.$id.' LIMIT 1');
|
||
|
$des = 'show';
|
||
|
}
|
||
|
if($des == 'add'){
|
||
|
$razdels = rejt_get_razdels();
|
||
|
$item=array();
|
||
|
$item['tip']=1;
|
||
|
if(isset($_SESSION['rejt'])) {
|
||
|
$item['id_razdel']=$_SESSION['rejt']['id_razdel'];
|
||
|
$item['pos']=$_SESSION['rejt']['pos']+1;
|
||
|
}
|
||
|
$polyas=array();
|
||
|
for($i=1;$i<=5;$i++){
|
||
|
$polyas[$i*(-1)]['id']=$i*(-1);
|
||
|
$polyas[$i*(-1)]['name']='';
|
||
|
$polyas[$i*(-1)]['pos']=$i;
|
||
|
$polyas[$i*(-1)]['value']='';
|
||
|
}
|
||
|
$itemspolyas=array();
|
||
|
for($i=1;$i<=5;$i++){
|
||
|
$itemspolyas[$i*(-1)]['id']=$i*(-1);
|
||
|
$itemspolyas[$i*(-1)]['name']='';
|
||
|
$itemspolyas[$i*(-1)]['pos']=$i;
|
||
|
$itemspolyas[$i*(-1)]['value']='';
|
||
|
}
|
||
|
$smarty->assign('item',$item);
|
||
|
$smarty->assign('polyas',$polyas);
|
||
|
$smarty->assign('itemspolyas',$itemspolyas);
|
||
|
$smarty->assign('razdels',$razdels);
|
||
|
}
|
||
|
if($des == 'edit'){
|
||
|
$id = (int)$_GET['id'];
|
||
|
$sql = 'SELECT * FROM '.$TB['items'].' WHERE id='.$id.'';
|
||
|
$rez = $DB->QUR_SEL($sql);
|
||
|
if($rez){
|
||
|
$razdels = rejt_get_razdels();
|
||
|
$itemspolyas=array(); $ilpos=0; $ipis=0; $idsp=array();
|
||
|
$sql1 = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id_item='.$id.' ORDER BY pos';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
$ipis=$rez1[0];
|
||
|
foreach($rez1 as $key1 => $val1)if($key1){
|
||
|
$idsp[]=$val1['id'];
|
||
|
$itemspolyas[$val1['id']]=$val1;
|
||
|
$ilpos=$val1['pos'];
|
||
|
}
|
||
|
}
|
||
|
for($i=1;$i<=5;$i++){
|
||
|
$itemspolyas[$i*(-1)]['id']=$i*(-1);
|
||
|
$itemspolyas[$i*(-1)]['name']='';
|
||
|
$itemspolyas[$i*(-1)]['pos']=$ilpos+$i;
|
||
|
$itemspolyas[$i*(-1)]['value']='';
|
||
|
}
|
||
|
|
||
|
$polyas=array(); $lpos=0;
|
||
|
if(count($idsp)){
|
||
|
$sql1 = 'SELECT * FROM '.$TB['polyas'].' WHERE id_item='.implode(' OR id_item=',$idsp).' ORDER BY pos';
|
||
|
//$sql1 = 'SELECT * FROM '.$TB['polyas'].' WHERE id_item='.$id.' ORDER BY pos';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
foreach($rez1 as $key1 => $val1)if($key1){
|
||
|
$polyas[$val1['id']]=$val1;
|
||
|
$lpos=$val1['pos'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for($i=1;$i<=5;$i++){
|
||
|
$polyas[$i*(-1)]['id']=$i*(-1);
|
||
|
$polyas[$i*(-1)]['name']='';
|
||
|
$polyas[$i*(-1)]['pos']=$lpos+$i;
|
||
|
$polyas[$i*(-1)]['value']='';
|
||
|
}
|
||
|
|
||
|
$smarty->assign('razdels',$razdels);
|
||
|
$smarty->assign('item',$rez[1]);
|
||
|
$smarty->assign('polyas',$polyas);
|
||
|
$smarty->assign('itemspolyas',$itemspolyas);
|
||
|
$smarty->assign('ipis',$ipis);
|
||
|
|
||
|
}else{
|
||
|
$des = 'show';
|
||
|
}
|
||
|
//echo '<pre>'.print_r($rez[1],1).'</pre>';
|
||
|
}
|
||
|
if($des == 'formula'){
|
||
|
$id = (int)$_GET['id'];
|
||
|
$sql = 'SELECT * FROM '.$TB['items'].' WHERE id='.$id.'';
|
||
|
$rez = $DB->QUR_SEL($sql);
|
||
|
if($rez){
|
||
|
$polyas=array();
|
||
|
$sql1 = 'SELECT * FROM '.$TB['polyas'].' WHERE id_item='.$id.' ORDER BY pos';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
foreach($rez1 as $key1 => $val1)if($key1){
|
||
|
$polyas[$val1['id']]=$val1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$itemspolyas=array(); $ilpos=0;
|
||
|
$sql1 = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id_item='.$id.' ORDER BY pos';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
foreach($rez1 as $key1 => $val1)if($key1){
|
||
|
$sql2 = 'SELECT count(id) as kol FROM '.$TB['polyas'].' WHERE id_item='.$val1['id'].'';
|
||
|
$rez2 = $DB->QUR_SEL($sql2);
|
||
|
if($rez2){
|
||
|
$val1['polyas']=$rez2[1]['kol'];
|
||
|
}else $val1['polyas']=0;
|
||
|
$itemspolyas[$val1['id']]=$val1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//надо выбрать все поля РЕЙТИНГА из нужного блока(не понятно как определить?)
|
||
|
$smarty->assign('useranketa_polya',rejt_get_useranketa_polya());
|
||
|
|
||
|
/*if($rez[1]['formuls']!=''){
|
||
|
$dan['ip'][0]['id']=6;
|
||
|
$dan['ip'][0]['value']=20000;
|
||
|
$fff = parse_formula($rez[1]['formuls'],$dan);
|
||
|
}*/
|
||
|
|
||
|
$smarty->assign('razdels',$razdels);
|
||
|
$smarty->assign('item',$rez[1]);
|
||
|
$smarty->assign('polyas',$polyas);
|
||
|
$smarty->assign('itemspolyas',$itemspolyas);
|
||
|
|
||
|
}else{
|
||
|
$des = 'show';
|
||
|
}
|
||
|
}
|
||
|
if($des == 'show'){
|
||
|
$items=array();
|
||
|
$sql = 'SELECT * FROM '.$TB['items'].' ORDER BY id_razdel,pos';
|
||
|
$rez = $DB->QUR_SEL($sql);
|
||
|
if($rez){
|
||
|
foreach($rez as $key => $val)if($key){
|
||
|
$val['razdel'] = rejt_get_razdels($val['id_razdel']);
|
||
|
/*
|
||
|
$sql1 = 'SELECT COUNT(id) as kol FROM '.$TB['polyas'].' WHERE id_item='.$val['id'].'';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
$val['polej'] = $rez1[1]['kol'];
|
||
|
}else $val['polej'] = 0;
|
||
|
*/
|
||
|
$sql1 = 'SELECT COUNT(id) as kol FROM '.$TB['itemspolyas'].' WHERE id_item='.$val['id'].'';
|
||
|
$rez1 = $DB->QUR_SEL($sql1);
|
||
|
if($rez1){
|
||
|
$val['ipolej'] = $rez1[1]['kol'];
|
||
|
}else $val['ipolej'] = 0;
|
||
|
|
||
|
$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');
|