EIOS/inc/rejtdek_anketa.php

109 lines
4.2 KiB
PHP

<?php
$otchgods=array();//выберем активный отчетный период
unset($_SESSION['otchgods'][1]);
$sql = 'SELECT * FROM '.$TB['otchgods'].' WHERE status=1';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$otchgods = $val;
$_SESSION['otchgods'][$otchgods['tip']] = $otchgods;//для подсчета баллов
}
}
$smarty->assign('otchgods',$otchgods);
//надо определить группы для баллов
$idsid=array();
$sql1 = 'SELECT id,pos FROM '.$ST['dbpf'].'_rejt_razdels ORDER BY pos';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
if($val1['pos']!=1) $idsid[$val1['pos']]=$val1['id'];
}
}
//надо выбрать всех преподов для этой кафедры
$teachers=array();
$sql1 = 'SELECT u.*,t.zvanie,t.dolgnost,t.stepen,t.kafedra FROM '.$ST['dbpf'].'_teachers as t,'.$ST['dbpf'].'_users as u WHERE t.fakultet="'.$_SESSION['user']['teacher']['fakultet'].'" AND u.id=t.id_user ORDER BY t.kafedra,u.fio';
$rez1 = $DB->QUR_SEL($sql1);
if($rez1){
foreach($rez1 as $key1 => $val1)if($key1){
$val1['ball'] = 0; $val1['ball1'] = 0; $val1['ball2'] = 0; $val1['ball3'] = 0;
foreach($idsid as $k => $v){
//учесть выбранный период
$sql2 = 'SELECT SUM(balls) as ball FROM '.$ST['dbpf'].'_rejt_savesballs WHERE id_user='.$val1['id'].' AND id_razdel='.$v.' AND (data_c BETWEEN '.$_SESSION['otchgods'][1]['data_s1'].' AND '.$_SESSION['otchgods'][1]['data_s2'].')';
$rez2 = $DB->QUR_SEL($sql2);
if($rez2) {
$val1['ball'.($k-1)] = $rez2[1]['ball'];
$val1['ball'] += $val1['ball'.($k-1)];
}else $val1['ball'.($k-1)] = 0;
}
$teachers[]=$val1;
}
}
$smarty->assign('teachers',$teachers);
$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'][1]['data_s1'].' AND '.$_SESSION['otchgods'][1]['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['formuls1'] = $val1['formuls'];
$tmp01 = explode('|',$val1['formuls']);//определяем по формуле, пользователь вводит число или оно расчитывается
if(count($tmp01)==2&&$tmp01[0]==0){
$val1['edit'] = false;
//надо расчитать и сохранить в базу
$val1['formuls2'] = rejtdek_raschet($val1['id'],$_SESSION['user']['id']);
//$BALLS+=$val1['formuls2']['itogo'];
}else{
$val1['edit'] = true;
$val1['formuls'] = rejtdek_raschet($val1['id'],$_SESSION['user']['id']);
$BALLS+=$val1['formuls']['itogo'];
}
$val['razdel'][]=$val1;
}
}
$items[]=$val;
}
}
$smarty->assign('BALLS',$BALLS);
$smarty->assign('items',$items);
$smarty->assign('page',$page);
$smarty->assign('des',$des);
$maincontent = $smarty->fetch('tpl_rejtdek_anketa.html');