<?php
// специальный отчет для добавления сотрудников в группы
include_once(_DIR_EXT.'/events/report_personals_in_event.php') ;
class report_personals_in_event_instruction extends report_personals_in_event
{
 var $title='Участники мероприятия - направлены на инструктаж' ;
 var $arr_temp_fired=array(0=>'Без сотрудников в отложенном увольнении',1=>'Все сотрудники') ;
 var $filter_set=['name','org_ids','otdel_ids','working_ids','group_pers',/*'group_medic',*/'age_from','age_to','age_to','temp_fired','pass_status'];
 var $report_script=__FILE__ ;

 function prepare_data(&$list_recs)
 {
     $arr_PID=array() ;  $arr_SP=array() ;  $cnt_mess=array() ; $tkey=0 ;
     if (_sizeof($list_recs)) foreach($list_recs as $rec) {$arr_PID[]=$rec['pkey'] ; $arr_SP[]=$rec['event_pass_id'] ; $tkey=$rec['event_pass_tkey'] ; }
     if (_sizeof($list_recs)) $cnt_mess=execSQL('select personal_id,status,count(pkey) as cnt,
                                                 min(block_from) as block_from from obj_site_personal_mess 
                                                 where source_pkey in ('.implode(',',$arr_SP).') and source_tkey='.$tkey.' and personal_id in ('.implode(',',$arr_PID).') 
                                                 group by personal_id,status',0,1) ;
     if (_sizeof($cnt_mess)) foreach($cnt_mess as $rec)
     { $personal_id=$rec['personal_id'] ;
       $list_recs[$personal_id]['_cnt_mess'][$rec['status']]=$rec['cnt'] ;
       if (!isset($list_recs[$personal_id]['_date_block'])) $list_recs[$personal_id]['_date_block']=0 ;
       if ($rec['status']!=4 and $rec['block_from']>0 and ($rec['block_from']<$list_recs[$personal_id]['_date_block'] or $list_recs[$personal_id]['_date_block']==0)) $list_recs[$personal_id]['_date_block']=$rec['block_from'] ;
     }

 }

// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    //print_2x_arr($list_recs);
    //damp_array($arr_persons_time_block);
    $this->prepare_data($list_recs);
    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <tr><th>ID</th>
            <th>Дата добавления</th>
            <th>ФИО, дата рождения, Возраст</th>
            <th>Организация, подразделение</th>
            <th>Должность</th>
            <th>Статус</th>
            <th>Сообщения</th>
            <th>Дата блокировки</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   ?><tr class=item>
                <td><a href="/cab/events/pass/<?echo $rec['event_pass_id']?>/" class="new_window" target="_blank" title="win_pass_info"><?echo $rec['event_pass_id']?></a></td>
                <td><?echo date('d.m.Y H:i',$rec['event_c_data'])?></td>
                <td class="left"><a href="<?echo $rec['__href_window']?>" class="new_window" target="_blank" title="win_second"><?echo $rec['obj_name']?></a>
                    <?  if ($rec['uid']) echo '<br><span class="nowrap small">'.$rec['uid'].'</span>' ;
                        if (!$rec['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec['fired_data']).')' ;
                        if ($rec['dr'])echo '<br>'.$rec['dr'] ;
                        if ($rec['age'])echo ', '.$rec['age'].' '.get_case_by_count_1_2_5($rec['age'],'год,года,лет');
                        if ($rec['fired_data'])echo '<div style="color:burlywood;">Отложенное увольнение до <strong>'.date('d.m.Y',$rec['fired_data']).'</strong></div>' ;
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec['_org_name'].'</strong><br><div class="small">'.$rec['_otdel_name'].'</div>'?></td>
                <td class="left"><?echo _IL('IL_works')->recs[$rec['working']]['obj_name'] ;
                                  if ($rec['working2']) echo '<br><strong>Совмещение: </strong>'._IL('IL_works')->recs[$rec['working2']]['obj_name'] ;
                    ?></td>
                <td><?echo EVENT_INSTR()->arr_status[$rec['event_status']]?></td>
                <td><?  $arr=array() ;
                        if (_sizeof($rec['_cnt_mess'])) foreach($rec['_cnt_mess'] as $status=>$cnt) $arr[]=$_SESSION['ARR_mess_status'][$status].(($cnt)? ' '.$cnt.' шт.':'');
                        if (_sizeof($arr)) echo implode('<br>',$arr) ;
                        //print_r($cnt_mess_pers[$rec['pkey']]) ;
                    ?></td>
                <td><?if ($rec['_date_block']) echo 'с '.date('d.m.Y',$rec['_date_block'])?></td>
            </tr><?
        }
      ?></table><?
      //damp_array($rec) ;

      //echo 'Фильтр аккаунта по сотрудникам: ' ; damp_array(MEMBER());
  }

    function print_template_CSV($list_recs,$options=array())
       {  $i=$options['from'] ;
          include_once(_DIR_EXT.'/esmo_magnit_instruction/i_event_instruction.php') ;

          $this->prepare_data($list_recs);

         if (_sizeof($list_recs)) foreach($list_recs as $rec)
           { $data=array() ;
             $data['ID']=$rec['pkey'] ;
             $data['Дата добавления в инструктаж']= date('d.m.Y H:i',$rec['event_c_data']) ;
             $data['ФИО сотрудника']=$rec['obj_name'] ;
             $data['ДатаРожд']=$rec['dr'] ;
             $data['Возраст']=$rec['age'] ;
             $data['Организация']=$rec['_org_name'] ;
             $data['Подразделение']=strip_tags($rec['_otdel_name']) ;
             $data['Основная должность']=_IL('IL_works')->recs[$rec['working']]['obj_name'];
             $data['Совмещение']=($rec['working2'])? _IL('IL_works')->recs[$rec['working2']]['obj_name']:'' ;
             $data['GUID']=$rec['uid'] ;
             $data['Пропуск']=$rec['propusk'] ;
             $data['Статус']= EVENT_INSTR()->arr_status[$rec['event_status']] ;
             $arr=array() ;
             if (_sizeof($rec['_cnt_mess'])) foreach($rec['_cnt_mess'] as $status=>$cnt) $arr[]=$_SESSION['ARR_mess_status'][$status].(($cnt>1)? ' '.$cnt.' шт.':'');
             $data['Сообщения']=(_sizeof($arr))? implode(', ',$arr):'' ;
             $data['Блокировка МО']=($rec['_date_block'])? date('d.m.Y',$rec['_date_block']):'' ;

             $this->put_data_to_CSV($data,$i) ;
             $i++ ;
           }

       }



}

?>
