<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_esmo_magnit_check_personals extends c_page
{
  public $h1='Рабочее место сотрудника БДД - Проверка сотрудников' ;
  public $rec_mo=array() ;
  public $rec_personal=array() ;
  public $rec_mess=array() ;

 function second_menu_config()
 { $this->second_menu['/cab/esmo_magnit/check_personals/']=array('title'=>'Проверка сотрудников') ;
 }

 function get_cur_page_meta_tags()
 {
   //if ($this->rec_personal['pkey']) $this->h1='Карточка сообщения ' ;
 }

    function block_main()
     { //$this->page_title() ;
       $this->panel_check_dubl() ;
       ?><br><br><?
     }

     function panel_check_dubl()
     {   ?><h1>Дубликаты пропусков</h1><?
         execSQL_update('drop table if EXISTS temp11') ;
         execSQL_update('create table temp11 select propusk,count(pkey) as cnt
                         from obj_site_personals
                         where clss=211
                         group by propusk
                         having count(pkey)>1
                         ') ;

         $recs=execSQL('select t1.pkey as ud,t1.propusk,t1.uid,t1.enabled,t1.obj_name,t1.dr,t1._org_name,t1._otdel_name,t1.uid
                  from view_personals t1,temp11 tmp
                  where t1.clss=211 and tmp.propusk=t1.propusk and tmp.propusk>""
                  order by propusk,obj_name,dr
         ') ;
         echo '<strong>Найдено '._sizeof($recs).' записей </strong><br>'  ;
         print_2x_arr($recs) ;

         ?><h1>Дубликаты UID</h1><?
         $recs=execSQL('select t1.pkey as ud,t1.propusk,t1.uid,t1.enabled,t1.obj_name,t1.dr,t1._org_name,t1._otdel_name,t1.uid
                  from view_personals t1
                  where t1.clss=211 and uid in (select distinct(uid) from obj_site_personals group by uid having count(pkey)>1)
                  order by uid,obj_name,dr
         ') ;
         echo '<strong>Найдено '._sizeof($recs).' записей </strong><br>'  ;
         print_2x_arr($recs) ;


         ?><h1>Сотрудники без UID</h1><?
         $recs=execSQL('select * from obj_site_personals where clss=211 and  (uid is null or uid="")') ;
         echo '<strong>Найдено '._sizeof($recs).' записей </strong><br>'  ;
         print_2x_arr($recs) ;

         $now=getdate(time()) ;
         //$from=mktime($now['hours'],$now['minutes'],$now['seconds'],$now['mon']-2,$now['mday'],$now['year']);
         $from=mktime(0,0,0,$now['mon']-2,$now['mday'],$now['year']);
         ?><h1>Сотрудники c пропусками, не проходившие МО последние два месяца (<?echo 'c '.date('d.m.Y',$from)?>)</h1><?
         execSQL_update('drop table IF EXISTS temp12') ;
         execSQL_update('create table temp12 select member_id,max(c_data) as last_mo_data
                         from obj_site_mo_session
                         group by member_id
                         ') ;

         //execSQL('select * from temp12',2) ;


         $recs=execSQL('select t1.pkey as ud,t1.propusk,t1.uid,t1.enabled,t1.obj_name,t1.dr,t1._org_name,t1._otdel_name,t1.uid,t2.last_mo_data as c_data
                  from view_personals t1,temp12 t2
                  where t1.clss=211 and t1.propusk!="" and not t1.propusk like "id%" and t2.member_id=t1.pkey and t2.last_mo_data<'.$from.'
                  order by t2.last_mo_data desc
         ') ;
         echo '<strong>Найдено '._sizeof($recs).' записей </strong><br>'  ;
         print_2x_arr($recs) ;


     }

}



?>
