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 '
'.print_r($_SESSION['otchgods'],1).''; $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 '
'.print_r($idsid,1).''; //надо выбрать всех преподов для этой кафедры $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.'
'.print_r($rez2,1).''; 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.'
'.print_r($val3,1).''; $ff = rejt_raschet($val3['id_items'],$val1['id']); //if ($val3['id_razdel']==2) echo 'ff
'.print_r($ff,1).''; 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'].'
'.print_r($val3,1).print_r($ff,1).''; } } } } //echo '
'.print_r($ps,1).''; foreach($ps[$val1['id']] as $razd => $iii){ foreach($iii as $kk => $vv){ //echo $razd.'='.$kk.'
'.print_r($vv,1).''; if(isset($val1['ps'][$razd])) { //echo 'isset
'.print_r($ps,1).''; /* $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 '
'.print_r($teachers,1).'';exit(); //echo '
'.print_r($ps,1).'';exit(); } $smarty->assign('teachers',$teachers); //echo '
'.print_r($teachers,1).''; $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');