<?php
include_once('c_personal_person_db.php') ;
class c_page_cab_personal_person_db_stats extends c_page_cab_personal_person_db
{
 public $h1='Карточка сотрудника - статистика' ;

 function get_cur_page_meta_tags()
 {
   if ($this->rec_personal['pkey']) $this->h1='Статистика по сотруднику '.$this->rec_personal['obj_name'] ;
 }

 function block_main()
 { $this->page_title() ;

     $rec_personal=execSQL_van('select t1.*,
                              (select count(pkey) from obj_site_mo_session where member_id=t1.pkey) as cnt_mo,
                              (select count(pkey) from obj_site_personal_mess where personal_id=t1.pkey) as cnt_mess,
                              (select count(pkey) from obj_site_events_pass where personal_id=t1.pkey) as cnt_event_pass,
                              (select count(pkey) from obj_site_docs where personal_id=t1.pkey) as cnt_docs,
                              (select count(pkey) from obj_site_personals_image where parent=t1.pkey) as cnt_img,
                              (select count(pkey) from obj_site_mo_log where personal_id=t1.pkey) as cnt_log,
                              (select count(pkey) from obj_site_scan where personal_id=t1.pkey) as cnt_scan,
                              (select count(pkey) from obj_site_lession_persons where personal_id=t1.pkey) as cnt_lession
                              from view_personals t1 
                              where pkey='.$this->rec_personal['pkey'].'
                            ') ;

     ?><table class="basic fz_small">
          <tr><th>ID</th><th>Статус</th><th>Пропуск</th><th>UID</th><th>Фото</th><th>Организация</th><th>Отдел</th><th>Должность</th>
              <th>Группы сотрудника</th><th>Фото</th><th>МО</th><th>Cообщений</th><th>Мероприятий</th><th>Занятий</th><th>Документов</th><th>Сканов</th><th>Журнал событий</th>
          </tr>
           <tr><td><?echo $rec_personal['pkey']?></td>
                 <td><?echo ($rec_personal['enabled'])? 'Действующий':'Уволен '.(($rec_personal['fired_data'])? '<br>'.date('d.m.Y',$rec_personal['fired_data']):'')?></td>
                 <td><?echo $rec_personal['propusk']?></td>
                 <td><?echo $rec_personal['uid']?></td>
                 <td><?if ($rec_personal['_image_name']) echo '<img src="'.img_clone($rec_personal,'small').'">'?></td>
                 <td class="left"><?echo $rec_personal['_org_name']?></td>
                 <td class="left"><?echo $rec_personal['_otdel_name']?></td>
                 <td class="left"><?echo $rec_personal['_work_name']?></td>
                 <td><?echo $rec_personal['_groups_names']?></td>
                 <td><?echo $rec_personal['cnt_img']?></td>
                 <td><?echo $rec_personal['cnt_mo']?></td>
                 <td><?echo $rec_personal['cnt_mess']?></td>
                 <td><?echo $rec_personal['cnt_event_pass']?></td>
                 <td><?echo $rec_personal['cnt_lession']?></td>
                 <td><?echo $rec_personal['cnt_docs']?></td>
                 <td><?echo $rec_personal['cnt_scan']?></td>
                 <td><?echo $rec_personal['cnt_log']?></td>
              </tr>
           </table><br>
     <?
     //$rec_personal['cnt_mo']=0 ;
     //$rec_personal['cnt_mess']=0 ;
     //$rec_personal['cnt_event_pass']=0 ;
     //$rec_personal['cnt_lession']=0 ;
     //$rec_personal['cnt_docs']=0 ;
     //$rec_personal['cnt_scan']=0 ;
     if (!$rec_personal['cnt_mo'] and !$rec_personal['cnt_mess'] and !$rec_personal['cnt_event_pass'] and !$rec_personal['cnt_lession'] and !$rec_personal['cnt_docs'] and !$rec_personal['cnt_scan'])
     {  ?><div class="alert">Сотрудник не имеет признаков активности в ЭСМО и может быть удален</div><br>
          <button class="v2" cmd="aspmo_personal/personal_delete" personal_id="<?echo $rec_personal['pkey']?>">Удалить сотрудника</button>
         <?
 }
     else {?><div class="alert">Сотрудник имеет признаки активности в ЭСМО и не может быть удален</div><?}



}
}

?>