<?php
// специальный отчет для добавления сотрудников в группы
include_once(_DIR_EXT.'/esmo_magnit_pmo/i_event_pmo.php') ;
include_once(_DIR_EXT.'/events/report_personals_in_event.php');
class report_personals_in_event_pmo extends report_personals_in_event
{
 var $title='Зарегистрированные участники мероприятия' ;
 var $report_script=__FILE__ ;
// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    $arr_status_personal=$this->get_status_to_personals($list_recs) ;

    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <tr><th rowspan="2">ID</th>
            <th rowspan="2">ФИО, дата рождения, Возраст</th>
            <th rowspan="2">Организация, подразделение, должность</th>
            <th rowspan="2">Медицинская группа сотрудника</th>
            <th rowspan="2">Статус</th>
            <th colspan="6">Даты</th>
            <?if (!$options['denited_action']){?><th rowspan="2">Операции</th><?}?>
        </tr>
        <tr><th>Направлен на ПМО</th>
            <th>готовность документов</th>
            <th>оповещение</th>
            <th>блокировка МО</th>
            <th>получение документов</th>
            <th>сдача заключения</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   $arr_status=$arr_status_personal[$rec['personal_id']]  ;
            ?><tr class=item>
                <td><a href="/window/events/event_pass/<?echo $rec['event_pass_id']?>/" class="new_window"><?echo $rec['event_pass_id']?></a></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 '<br>'.$rec['age'].' '.get_case_by_count_1_2_5($rec['age'],'год,года,лет');
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec['_org_name'].'</strong><br><div class="small">'.$rec['_otdel_path'].'</div>'._IL('IL_works')->recs[$rec['working']]['obj_name']?></td>
                <td ><?echo $rec['_groups_names']?></td>
                <td><?echo EVENT_PMO()->arr_status[$rec['event_status']]?></td>
            <td><?if ($arr_status[2]) echo $arr_status[2]?></td>
            <td><?if ($arr_status[3]) echo $arr_status[3]?></td>
            <td><?if ($arr_status[4]) echo $arr_status[4]?></td>
            <td><?if ($arr_status[7]) echo $arr_status[7] ; else if ($arr_status[5]) echo $arr_status[5]?></td>
            <td><?if ($arr_status[6]) echo $arr_status[6]?></td>
            <td><?if ($arr_status[8]) echo $arr_status[8] ;
                  if ($arr_status[9]) echo $arr_status[9] ;
                ?></td>
            <?if (!$options['denited_action']){?>
            <td>
                <?if ($rec['event_status']!=1){?><button class="v2" cmd="esmo_magnit_pmo/prepare_put_packet_docs" show_saved_doc=1 event_id="<?echo $rec['event_id']?>" personal_id="<?echo $rec['pkey']?>">Открыть пакет документов</button>
                            <div id="time_print_<?echo $rec['event_person_id']?>"><?  if ($rec['time_print']) echo '<br>Напечатано: '.date('d.m.Y H:i',$rec['time_print'])?><?}?></div>
                <?if (MEMBER()->rol==1 and $rec['event_status']>=3 and $rec['event_status']<=7){?><br><button class="v2" cmd="aspmo_personal/personal_message_add_day" mess_id="<?echo $rec['mess_id']?>">Добавить дней</button><?}?>
                </td>
           <?}?>
            </tr><?
        }
      ?></table><?
      echo '</form>' ;
      //damp_array($rec) ;
  }


    function print_template_CSV($list_recs,$options=array())
    { $i=$options['from'] ;
       $arr_status_personal=$this->get_status_to_personals($list_recs) ;
       if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {  $arr_status=$arr_status_personal[$rec['personal_id']]  ;
           $data=array() ;
      	   $data['№']=$i+1 ;
           $data['UID']=$rec['uid']  ;
      	   $data['ФИО']=$rec['obj_name']  ;
           $data['UID']=$rec['uid']  ;
           $data['Дата рождения']=$rec['dr']  ;
           $data['Возраст']=$rec['age']  ;
      	   $data['Организация']=$rec['_org_name'] ;
      	   $data['Подразделение']=$rec['_otdel_name'] ;
           $data['Должность']=$rec['_work_name'] ;
           $data['Группа сотрудника']=$rec['_groups_names'] ;
           $data['Статус ПМО']= EVENT_PMO()->arr_status[$rec['event_status']] ;
           $data['Добавлен в мероприятие']=date('d.m.Y',$rec['event_c_data']); ;
            $data['Срок действия ПМО, от']=(($rec['event_status']==8 or $rec['event_status']==9) and $rec['data_from'])? date('d.m.Y',$rec['data_from']):'-';
            $data['Срок действия ПМО, по']=(($rec['event_status']==8 or $rec['event_status']==9) and $rec['data_from'])? date('d.m.Y',$rec['data_to']):'-';
           $data['Направлен на ПМО']=$arr_status[2] ;
           $data['готовность документов']=$arr_status[3] ;
           $data['оповещение']=$arr_status[4] ;
           $data['блокировка МО']=($arr_status[7])? $arr_status[7]:$arr_status[5] ;
           $data['получение документов']=$arr_status[6] ;
           $data['сдача заключения']=($arr_status[8])? $arr_status[8]:$arr_status[9] ;
            $data['дата заключения']=($rec['data_from'])? date('d.m.Y',$rec['data_from']):'' ;
           // вносим данные в csv
           $this->put_data_to_CSV($data,$i) ;
      	   $i++ ;
  	}
   }

    function get_status_to_personals($recs)
    {
        $personal_ids=array();
        $event_id=0;
        $arr_status_pers=array();
        $arr_status_personal=array();
        if(_sizeof($recs)) foreach($recs as $rec)
        {
            $personal_ids[]=$rec['personal_id'];
            $event_id=$rec['event_id'];
        }
        $_usl=[] ;
        $_usl[]='personal_id in ('.implode(',',$personal_ids).')' ;
        $_usl[]='event_id='.$event_id ;
        $_usl[]='not obj_name like "%Разблокировка%"' ;
        $_usl[]='status_new!=status_old' ;
        if(_sizeof($personal_ids) and $event_id) $arr_status_pers=execSQL('select personal_id,status_new,c_data from obj_site_events_pass_status where '.implode(' and ',$_usl).'',0,1);
        if (_sizeof($arr_status_pers)) foreach($arr_status_pers as $rec_status) $arr_status_personal[$rec_status['personal_id']][$rec_status['status_new']]=date('d.m.Y',$rec_status['c_data']) ;
        return($arr_status_personal) ;
    }

    function get_messages_to_personals($recs)
    {
        $personal_ids=array();
        $event_id=0;
        $arr_status_pers=array();
        $arr_status_personal=array();
        if(_sizeof($recs)) foreach($recs as $rec)
        {
            $personal_ids[]=$rec['personal_id'];
            $event_id=$rec['event_id'];
        }
        $_usl=[] ;
        $_usl[]='personal_id in ('.implode(',',$personal_ids).')' ;
        //$_usl[]='event_id='.$event_id ;
        $_usl[]='source_obj="esmo_magnit_pmo/i_event_pmo"' ;
        $_usl[]='status!=4' ;
        if(_sizeof($personal_ids) and $event_id) $arr_status_pers=execSQL('select personal_id,pkey,c_data from obj_site_personal_mess where '.implode(' and ',$_usl).'',0,1);
        if (_sizeof($arr_status_pers)) foreach($arr_status_pers as $rec_status) $arr_status_personal[$rec_status['personal_id']][$rec_status['pkey']]=date('d.m.Y',$rec_status['c_data']) ;
        return($arr_status_personal) ;
    }

}

?>
