EIOS/inc/rejtnpr.php

225 lines
7.6 KiB
PHP
Raw Normal View History

2023-12-28 15:39:22 +03:00
<?php
session_start();
$maincontent = '';
$smarty->assign('razdel','rejtnpr');
if(isset($_GET['page'])){ $page=$_GET['page']; }else{ $page='main'; }
if(isset($_GET['des'])){ $des=$_GET['des']; }else{ $des='show';}
/*
echo '<pre>'.print_r($_POST,1).'</pre>';
echo '<pre>'.print_r($_GET,1).'</pre>';
[rejt] =>
[page] => admin1
[des] => add*/
$TB['razdels'] = $ST['dbpf'].'_rejtnpr_razdels';
$TB['items'] = $ST['dbpf'].'_rejtnpr_items';
$TB['polyas'] = $ST['dbpf'].'_rejtnpr_polyas';
$TB['itemspolyas'] = $ST['dbpf'].'_rejtnpr_itemspolyas';
$TB['saves'] = $ST['dbpf'].'_rejtnpr_saves';
$TB['otchgods'] = $ST['dbpf'].'_rejt_otchgods';
$TB['npr_celpok'] = $ST['dbpf'].'_rejtnpr_celpok';
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['razdels'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`descr` varchar(255) NOT NULL,
`pos` tinyint(4) NOT NULL,
`status` tinyint(4) NOT NULL,
`dostup` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['items'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_razdel` int(11) NOT NULL,
`name` text NOT NULL,
`tip` tinyint(4) NOT NULL,
`pos` tinyint(4) NOT NULL,
`formuls` varchar(255) NOT NULL,
`descr` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['polyas'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_item` int(11) NOT NULL,
`name` text NOT NULL,
`pos` tinyint(4) NOT NULL,
`value` DOUBLE NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['itemspolyas'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_item` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`pos` tinyint(4) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['saves'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data_c` int(11) NOT NULL,
`id_user` int(11) NOT NULL,
`id_razdel` int(11) NOT NULL,
`id_items` int(11) NOT NULL,
`id_itemspolyas` int(11) NOT NULL,
`id_polyas` int(11) NOT NULL,
`value` text NOT NULL,
`pos` tinyint(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
{$sql = 'CREATE TABLE IF NOT EXISTS `'.$TB['npr_celpok'].'` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_razdel` int(11) NOT NULL,
`id_items` int(11) NOT NULL,
`id_itemspolyas` int(11) NOT NULL,
`id_polyas` int(11) NOT NULL,
`celvalue` varchar(255) NOT NULL,
`stimvalue` varchar(255) NOT NULL,
`tipfor` tinyint NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;';
$rez = $DB->QUR($sql);}
function rejt_get_razdels($id=0){
GLOBAL $TB,$DB; $out=array();
if($id){
$sql = 'SELECT * FROM '.$TB['razdels'].' WHERE id='.$id.' LIMIT 1';
}else{
$sql = 'SELECT * FROM '.$TB['razdels'].' ORDER BY pos';
}
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$out[]=$val;
}
}
return $out;
}
function rejt_get_items($id=0){
GLOBAL $TB,$DB; $out=array();
if($id){
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id='.$id.' LIMIT 1';
}else{
$sql = 'SELECT * FROM '.$TB['itemspolyas'].' ORDER BY id_item,pos';
}
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$sql1 = 'SELECT * FROM '.$TB['items'].' WHERE id='.$val['id_item'].'';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1){
$sql2 = 'SELECT * FROM '.$TB['razdels'].' WHERE id='.$rez1[1]['id_razdel'].'';
$rez2 = $DB->QUR_SEL($sql2);
if($rez2){
$rez1[1]['razdel'] = $rez2[1];
}
$val['item'] = $rez1[1];
}
$out[]=$val;
}
}
return $out;
}
function rejt_get_useranketa(){
GLOBAL $ST,$DB,$TB;
$items=array(); $BALLS=0;
$sql = 'SELECT * FROM '.$TB['razdels'].' WHERE status=1 ORDER BY pos';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$val['razdel']=array();
$sql1 = 'SELECT * FROM '.$TB['items'].' WHERE id_razdel='.$val['id'].' ORDER BY pos';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
$val1['itemspolyas']=array();
$sql2 = 'SELECT * FROM '.$TB['itemspolyas'].' WHERE id_item='.$val1['id'].' ORDER BY pos';
$rez2 = $DB->QUR_SEL($sql2);
if($rez2){
$kolsaves=0;
foreach($rez2 as $key2 => $val2)if($key2){
$val2['polyas']=array();
//выбираем выпадающие элементы
$sql3 = 'SELECT * FROM '.$TB['polyas'].' WHERE id_item='.$val2['id'].' ORDER BY pos';
$rez3 = $DB->QUR_SEL($sql3);
if($rez3){
foreach($rez3 as $key3 => $val3)if($key3){
$val2['polyas'][]=$val3;
}
}
$val2['saves']=array();
//$sql4 = 'SELECT * FROM '.$TB['saves'].' WHERE id_user='.$_SESSION['user']['id'].' AND id_razdel='.$val['id'].' AND id_items='.$val1['id'].' AND id_itemspolyas='.$val2['id'].' AND (data_c BETWEEN '.$_SESSION['otchgods'][4]['data_s1'].' AND '.$_SESSION['otchgods'][4]['data_s2'].') ORDER BY pos';
$sql4 = 'SELECT * FROM '.$TB['saves'].' WHERE id_user='.$_SESSION['user']['id'].' AND id_razdel='.$val['id'].' AND id_items='.$val1['id'].' AND id_itemspolyas='.$val2['id'].' AND (data_c BETWEEN '.$_SESSION['otchgods'][3]['data_s1'].' AND '.$_SESSION['otchgods'][3]['data_s2'].') ORDER BY pos';
$rez4 = $DB->QUR_SEL($sql4);
if($rez4){
if($rez4[0]>$kolsaves) $kolsaves=$rez4[0];
foreach($rez4 as $key4 => $val4)if($key4){
$val2['saves'][$val4['pos']+1]=$val4;
}
}
$val1['itemspolyas'][]=$val2;
}
}
$val1['kolsaves']=$kolsaves;
//$val1['formuls'] = rejt_raschet($val1['id'],$_SESSION['user']['id']);
//$BALLS+=$val1['formuls']['itogo'];
$val1['formuls1'] = $val1['formuls'];
$tmp01 = explode('|',$val1['formuls']);//определяем по формуле, пользователь вводит число или оно расчитывается
if(count($tmp01)==2&&$tmp01[0]==0){
$val1['edit'] = false;
//надо расчитать и сохранить в базу
$val1['formuls2'] = rejtnpr_raschet($val1['id'],$_SESSION['user']['id']);
//$BALLS+=$val1['formuls2']['itogo'];
}else{
$val1['edit'] = true;
$val1['formuls'] = rejtnpr_raschet($val1['id'],$_SESSION['user']['id']);
$BALLS+=$val1['formuls']['itogo'];
}
$val['razdel'][]=$val1;
}
}
$items[]=$val;
}
}
return array('items'=>$items,'balls'=>$BALLS);
}
//if($_SESSION['user']['status']==99){
if($page=='admincelpok'){
include 'rejt_admincelpok.php';
}
if($page=='admin'){
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejtnpr_main.html');
}
if($page=='admin1'){//УПРАВЛЕНИЕ ОСНОВНЫМИ РАЗДЕЛАМИ
include 'rejtnpr_admin1.php';
}
if($page=='admin2'){//УПРАВЛЕНИЕ ПОДРАЗДЕЛАМИ
include 'rejtnpr_admin2.php';
}
if($page=='admin3'){//УПРАВЛЕНИЕ полями в ПОДРАЗДЕЛАХ
include 'rejtnpr_admin3.php';
}
if($page=='admin4'){//УПРАВЛЕНИЕ значениями в полях
include 'rejtnpr_admin4.php';
}
if($page=='main'){
include 'rejtnpr_anketa.php';
}
if($page=='maineu'){
//echo '<pre>'.print_r($_GET,1).'</pre>';exit();
$_SESSION['rejteu'] = (int)$_GET['des'];
include 'rejtnpr_anketa.php';
}
//}else{$maincontent = 'в разработке';}