EIOS/inc/rejtkaf_anketa.php

165 lines
6.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$otchgods=array();//выберем активный отчетный период
unset($_SESSION['otchgods'][2]);
$sql = 'SELECT * FROM '.$TB['otchgods'].' WHERE tip=2 AND status=1';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$otchgods = $val;
$_SESSION['otchgods'][$otchgods['tip']] = $otchgods;//для подсчета баллов
}
}
$sql = 'SELECT * FROM '.$TB['otchgods'].' WHERE tip=3 AND status=1';
$rez = $DB->QUR_SEL($sql);
if($rez){
foreach($rez as $key => $val)if($key){
$otchgods = $val;
$_SESSION['otchgods'][$otchgods['tip']] = $otchgods;//для подсчета баллов
}
}
//echo '<pre>'.print_r($_SESSION['otchgods'],1).'</pre>';
$smarty->assign('otchgods',$otchgods);
//надо определить группы для баллов
$idsid=array();
//$sql1 = 'SELECT r.pos,i.id FROM '.$ST['dbpf'].'_rejt_razdels as r,'.$ST['dbpf'].'_rejt_items as i WHERE r.id=i.id_razdel ORDER BY r.pos';
$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'];
}
}
//echo '<pre>'.print_r($idsid,1).'</pre>';
//надо выбрать всех преподов для этой кафедры
$teachers=array();
$sql1 = 'SELECT u.id,u.data_u,u.fio,t.zvanie,t.dolgnost,t.stepen,t.fakultet FROM '.$ST['dbpf'].'_teachers as t,'.$ST['dbpf'].'_users as u WHERE t.kafedra="'.$_SESSION['user']['teacher']['kafedra'].'" AND u.id=t.id_user AND NOT (u.status = "-1")'; //добавил ограничение - если пользователь забанен, то он не выводиться
$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; $val1['ps']=array();
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'][3]['data_s1'].' AND '.$_SESSION['otchgods'][3]['data_s2'].')';
//echo $sql2;
$rez2 = $DB->QUR_SEL($sql2);
//if($val1['id']==541) echo $sql2.'<pre>'.print_r($rez2,1).'</pre>';
if($rez2) {
$val1['ball'.($k-1)] = $rez2[1]['ball'];
$val1['ball'] += $val1['ball'.($k-1)];
}else $val1['ball'.($k-1)] = 0;
}
//пересчет баллов - не из сохранений, а все заново по формулам!
$ps=array();
$sql3 = 'SELECT * FROM acs_rejt_saves WHERE id_user='.$val1['id'].' AND (data_c BETWEEN '.$_SESSION['otchgods'][3]['data_s1'].' AND '.$_SESSION['otchgods'][3]['data_s2'].') ORDER BY pos';
//echo $sql3.'<br>';
$rez3 = $DB->QUR_SEL($sql3);
if($rez3){
foreach($rez3 as $key3 => $val3)if($key3){
//if ($val3['id_razdel']==2) echo 'val3<pre>'.print_r($val3,1).'</pre>';
$ff = rejt_raschet($val3['id_items'],$val1['id']);
//if ($val3['id_razdel']==2) echo 'ff<pre>'.print_r($ff,1).'</pre>';
if($ff['itogo']==INF||$ff['itogo']==NAN) {
$ff['itogo']=0;
}
if(isset($ff['itogo'])) {
$ps[$val1['id']][$val3['id_razdel']][$val3['id_items']] = $ff;
//if ($val3['id_razdel']==2) { echo $val1['id'].'-'.$val3['id_razdel'].'-'.$val3['id_items'].'<pre>'.print_r($val3,1).print_r($ff,1).'</pre>'; }
}
}
}
//echo '<pre>'.print_r($ps,1).'</pre>';
foreach($ps[$val1['id']] as $razd => $iii){
foreach($iii as $kk => $vv){
//echo $razd.'='.$kk.'<pre>'.print_r($vv,1).'</pre>';
if(isset($val1['ps'][$razd])) {
//echo 'isset<br>';
$val1['ps'][$razd] += $vv['itogo'];
}
else {
$val1['ps'][$razd]=$vv['itogo'];
//echo 'Noisset<br>';
}
}
}
//echo '<pre>'.print_r($ps,1).'</pre>';
/*
$sql2 = 'SELECT SUM(balls) as ball FROM '.$ST['dbpf'].'_rejt_savesballs WHERE id_user='.$val1['id'].'';
$rez2 = $DB->QUR_SEL($sql2);
if($rez2) $val1['ball'] = $rez2[1]['ball']; else $val1['ball'] = 0;
*/
$teachers[]=$val1;
}
//echo '<pre>'.print_r($teachers,1).'</pre>';exit();
//echo '<pre>'.print_r($ps,1).'</pre>';exit();
}
$smarty->assign('teachers',$teachers);
//echo '<pre>'.print_r($teachers,1).'</pre>';
$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'][2]['data_s1'].' AND '.$_SESSION['otchgods'][2]['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'] = rejtkaf_raschet($val1['id'],$_SESSION['user']['id']);
//$BALLS+=$val1['formuls2']['itogo'];
}else{
$val1['edit'] = true;
$val1['formuls'] = rejtkaf_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_rejtkaf_anketa.html');