<?
 function panel_stats_admin()
 { $list_group=execSQL('select t1.pkey,t1.obj_name,t2.obj_name as doctor_name,t2.smena_in 
                            from obj_site_account t1 
                            left join obj_site_account t2 on t2.group_id=t1.pkey and t2.smena=1 
                            where t1.clss=206 and t1.enabled=1 and t1.pkey!=1 
                            order by t1.obj_name') ;

   $now=getdate() ;
   $start_day=mktime(0,0,0,$now['mon'],$now['mday'],$now['year']);

   ?><div id="panel_rmv_stats"><table class="basic full auto" id="mo_stats_admin">
     <tr><th>Группа терминалов</th><th>Дежурный фельдшер</th><th>Время начала смены</th><th>Длительность смены</th><th>Проверено сотрудников</th><th>Ожидается на проверку</th><th>Пройдено МО</th><th>Допущено</th><th>Не допущено</th></tr>
     <?
     if (_sizeof($list_group)) foreach($list_group as $rec)
     {
         

     $usl_based='c_data>='.$rec['smena_in'].' and group_id='.$rec['pkey'].' ' ;

     if ($rec['smena_in'])
     { $stats=execSQL_row('select dopusk,count(DISTINCT(member_id)) from obj_site_mo_session where '.$usl_based.' and member_id>0  group by dopusk order by dopusk desc') ;
       $count_personal=execSQL_value('select count(DISTINCT(member_id)) from obj_site_mo_session where '.$usl_based.' and status in (1,2,3)') ;
       $now=getdate() ;
       $start_check=mktime($now['hours']-2,$now['minutes'],$now['seconds'],$now['mon'],$now['mday'],$now['year']);
       $count_to_check=execSQL_value('select count(DISTINCT(member_id)) from obj_site_mo_session where c_data>='.$start_check.' and group_id='.$rec['pkey'].' and (status=3 or (status=4 and (reason="nonRule" or reason="failedMO"))) and (dopusk is null or dopusk=0) and tk in (0,2) and not member_id in (select distinct(member_id) from obj_site_mo_session where c_data>='.$start_check.' and dopusk in (1,2))') ;
     }
     else
     { $stats=array() ;
       $count_personal=0 ;
       $count_to_check=0 ;
     }
     //execSQL('select DISTINCT(member_id) as member_id,(select obj_name from obj_site_personals where pkey=member_id) as member_name from obj_site_mo_session where c_data>='.MEMBER()->info['smena_in'].' and status=3  and (dopusk is null or dopusk=0) and  tk=0',2,-1) ;
     $s2=$stats[1] ; if (!$s2) $s2=0 ;
     $s3=$stats[2] ; if (!$s3) $s3=0 ;
     $s1=$s2+$s3 ;
     $d=time()-$rec['smena_in'] ;
     ?><tr></tr>
       
       <tr><td><?echo $rec['obj_name']?></td>
           <td class="left"><?echo $rec['doctor_name']?></td>
           <td><?echo ($rec['smena_in'])? date('d.m.Y H:i',$rec['smena_in']):'-'?></td>
           <td><?echo ($rec['smena_in'])? gmstrftime('%H:%M',$d):'-'?></td>
           <td><?echo ($count_personal)? $count_personal:'-'?></td>
           <td><?echo ($count_to_check)? $count_to_check:'-'?></td>
           <td><?echo ($s1)? $s1:'-'?></td>
           <td><?echo ($s2)? $s2:'-'?></td>
           <td><?echo ($s3)? $s3:'-'?></td>
       </tr>
    <?}?>
     </table>
     <?
   ?></div><?
 }
?>
