<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_esmo_master_stats extends c_page
{
  public $h1='Статистика - Эффективность системы' ;
  public $use_fusioncharts=1 ;

  function second_menu_config()
  { $this->second_menu['/cab/esmo_master/stats/']=array('title'=>'Эффективность системы') ;
    $this->second_menu['/cab/esmo_master/stats/health/']=array('title'=>'Состояние здоровья') ;
    //$this->second_menu[$this->rec_member['__href'].'sert/']=array('title'=>'Сертификат','class'=>'fa fa-user-md') ;
  }

 function block_main()
 { $this->page_title() ;
   $this->panel_graf_itog6() ;
   ?><br><h2>Статистика работы ЭСМО за текущие сутки</h2><?
   include_once('panel_stats.php');
   $this->panel_stats() ;
   //$this->panel_stats_graf() ;
   /*?><br><h2>График работы ЭСМО</h2><?
   include_once('panel_stats.php');
   $this->panel_stats_graf() ;

   ?><br><h2>Интенсивность проведения МО на объектах</h2><?
   */


 }

 function panel_graf_itog6()
 {
     include_once(_DIR_EXT.'/aspmo_reports/report_itog6.php') ;
     $report_obj=new report_itog6() ;
     //$report_obj->filter['org_id']=7106 ;
     $now=getdate() ;
     $report_obj->filter['month_from']=mktime(0,0,0,$now['mon'],1,$now['year']) ;
     $report_obj->filter['month_to']=mktime(0,0,0,$now['mon']+1,1,$now['year'])-1 ;
     $report_obj->filter['time_int']=3;
     $report_obj->view_table=0 ;
     $report_obj->setting_small() ;
     $report_obj->view_as_HTML() ;

 }


function panel_stats()
 { $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']);

   //select                  * from view_mo_session where group_id in (331) and c_data>=1473109200 and c_data<=1473195600 and dopusk in (1) and status in (2,3) and model>0 order by pkey desc limit 0,50
   //select dopusk,count(pkey) from view_mo_session where group_id=331      and c_data>=1473109200  and _org_id=7106 and member_id>0 and model>0 group by dopusk order by dopusk
   ?><div id="panel_rmv_stats"><table class="basic full">
     <tr><th>Группа терминалов</th><th>Допущено</th><th>Не допущено</th></tr>
     <?
     if (_sizeof($list_group)) foreach($list_group as $rec)
     {  $usl_based='c_data>='.$start_day.' and group_id='.$rec['pkey'].'  ' ;
        ?><tr></tr>
               <tr><td><?echo $rec['obj_name'] ;
                       $stats=execSQL_row('select dopusk,count(pkey) from view_mo_session where '.$usl_based.' and member_id>0 and model>0  group by dopusk order by dopusk') ;
                               $s2=$stats[1] ; if (!$s2) $s2=0 ;
                               $s3=$stats[2] ; if (!$s3) $s3=0 ;

                       ?></td>
                   <td><?echo ($stats[1])? $stats[1]:'-'?></td>
                   <td><?echo ($stats[2])? $stats[2]:'-'?></td>
               </tr>
        <?
     }
   ?></table><?
   ?></div><?
 }


}



?>
