EIOS/inc/rejtkaf.php

196 lines
6.4 KiB
PHP

<?php
session_start();
$maincontent = '';
$smarty->assign('razdel','rejtkaf');
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'].'_rejtkaf_razdels';
$TB['items'] = $ST['dbpf'].'_rejtkaf_items';
$TB['polyas'] = $ST['dbpf'].'_rejtkaf_polyas';
$TB['itemspolyas'] = $ST['dbpf'].'_rejtkaf_itemspolyas';
$TB['saves'] = $ST['dbpf'].'_rejtkaf_saves';
$TB['otchgods'] = $ST['dbpf'].'_rejt_otchgods';
{$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);
}
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;
}
//if($_SESSION['user']['status']==99){
if($page=='admin'){
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejtkaf_main.html');
}
if($page=='admin1'){//УПРАВЛЕНИЕ ОСНОВНЫМИ РАЗДЕЛАМИ
include 'rejtkaf_admin1.php';
}
if($page=='admin2'){//УПРАВЛЕНИЕ ПОДРАЗДЕЛАМИ
include 'rejtkaf_admin2.php';
}
if($page=='admin3'){//УПРАВЛЕНИЕ полями в ПОДРАЗДЕЛАХ
include 'rejtkaf_admin3.php';
}
if($page=='admin4'){//УПРАВЛЕНИЕ значениями в полях
include 'rejtkaf_admin4.php';
}
if($page=='main'){
include 'rejtkaf_anketa.php';
}
if($page=='otchet01'){
$id = (int)$_GET['des'];
$sql = 'SELECT * FROM '.$TB['otchgods'].' WHERE id='.$id.'';
$rez = $DB->QUR_SEL($sql); //echo $sql.'<pre>'.print_r($rez,1).'</pre>';
if($rez){
$tip = $rez[1]['tip'];//1-деканы 2-кафедры 3-НПР
$data_s1 = $rez[1]['data_s1'];//дата начала периода
$data_s2 = $rez[1]['data_s2'];//дата конца периода
$otch=array();
//echo $data_s1.'='.$data_s2.'<pre>'.print_r($rez,1).'</pre>';
if($tip==2){//-кафедры
include_once 'inc/rejt_admin5.php';
$_SESSION['otchgods'][2]['data_s1'] = $data_s1;
$_SESSION['otchgods'][2]['data_s2'] = $data_s2;
//1.Надо выбрать всех зав.кафедрой и потом проходить по всем пунктам, т.к. поля расчетные и не все он заполняет!
$sql = 'SELECT
sb.id_user, us.fio, te.dolgnost,te.stepen,te.fakultet,te.kafedra
FROM
'.$ST['dbpf'].'_rejtkaf_saves as sb,
'.$ST['dbpf'].'_users as us,
'.$ST['dbpf'].'_teachers as te
WHERE
sb.data_c BETWEEN '.$data_s1.' AND '.$data_s2.' AND
us.id = sb.id_user AND
te.id_user = us.id
GROUP BY sb.id_user
';
$rez = $DB->QUR_SEL($sql);
//echo '<pre>'.print_r($rez,1).'</pre>';
if($rez&&$rez[0]){
foreach($rez as $key => $val)if($key){
//расчитываем анкету для каждого пользователя
//выбираем анкету, возможно вывести из цикла-она одинакова будет для всех
$sql1 = 'SELECT rkr.name as rname,rki.name as iname, rki.id as idi FROM '.$ST['dbpf'].'_rejtkaf_items as rki,'.$ST['dbpf'].'_rejtkaf_razdels as rkr WHERE rki.id_razdel=rkr.id';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1&&$rez1[0]){
foreach($rez1 as $key1 => $val1)if($key1){
$balls = rejtkaf_raschet($val1['idi'],$val['id_user']);//возвращает баллы по полю
$val['balls']=$balls['itogo'];
$val['rname']=$val1['rname'];
$val['iname']=$val1['iname'];
$otch[$val['fakultet']][$val['kafedra']][$val['fio']][$val1['rname']][] = $val;
}
}
}
//echo '<pre>'.print_r($otch,1).'</pre>';
otchet01_get2($otch,$data_s1,$data_s2);//отдадим на сохранение данных
}
}
}
//echo '<pre>'.print_r($otch,1).'</pre>';
exit();
}
//}else{$maincontent = 'в разработке';}