<?php
// специальный отчет для добавления сотрудников в группы
include_once('i_event_opo.php') ;
include_once(_DIR_EXT.'/events/report_personals_in_event.php');
class report_personals_in_event_opo 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) ;
    $arr_message_personal=$this->get_messages_to_personals($list_recs) ;
    //damp_array($arr_message_personal);
    $arr_personal_ids=array();
        $arr_obj_events=array();

    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <tr>
            <!--<th rowspan="2">Выбор</th>-->
            <th rowspan="2">ID</th>
            <th rowspan="2">ФИО, дата рождения, Возраст</th>
            <th rowspan="2">Организация, подразделение, должность</th>
            <th rowspan="2">МедГруппа</th>
            <th rowspan="2">Статус</th>
            <th colspan="3">Даты</th>
            <?if (!$options['denited_action']){?><th rowspan="2"></th><?}?>
        </tr>
        <tr>
            <th>Направлен на ОПО</th>
            <th>сдача заключения</th>
            <th>дата заключения</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   $arr_status=$arr_status_personal[$rec['personal_id']]  ;

            if(isset($arr_obj_events[$rec['event_id']])) $this->obj_event=$arr_obj_events[$rec['event_id']];
            else    $this->obj_event=$arr_obj_events[$rec['event_id']]=EVENTS()->get_event_obj_by_id($rec['event_id']);
            ?>
            <tr class=item>
                <!--<td><?
                        if(!in_array($rec['pkey'],$arr_personal_ids) and $rec['event_status']==1) {?><input type="<? echo ($options['check_type'])? $options['check_type']:'checkbox' ?>" name="_check[]" value="<? echo $rec['_reffer'] ?>"><? }
                        else echo '<span class="red"></span>' ;
                    ?>
                </td>-->
                <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><?  if($rec['event_status']==8) echo '<span class="green bold">Годен</span>';
                        else if($rec['event_status']==9) echo '<span class="red bold">Не годен</span>';
                        else if (isset($this->obj_event->arr_status[$rec['event_status']])) echo $this->obj_event->arr_status[$rec['event_status']];
                        else echo $this->obj_event->arr_status[2].' ['.$rec['event_status'].']' ;
                        echo '<div class="comment">';
                        if($rec['event_status']==8 or $rec['event_status']==9) echo ' c '.date('d.m.Y',$rec['data_from']).' по '.date('d.m.Y',$rec['data_to']);
                        else echo ' с '.$arr_status[$rec['event_status']] ;
                        echo '</div>'
                        ?>
                </td>
                <td><?if ($arr_status[2]) echo $arr_status[2]?></td>
                <td><?if ($arr_status[8]) echo $arr_status[8] ;
                      if ($arr_status[9]) echo $arr_status[9] ;
                    ?>
                </td>
                <td><? if($rec['data_from']) echo date('d.m.Y',$rec['data_from']); ?></td>
            <?if (!$options['denited_action']){?>
            <td>
                <?if ($rec['event_status']!=1){?><button class="v2" cmd="events_opo/prepare_put_packet_docs" show_saved_doc=0 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>
                </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_OPO()->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="events_opo/i_event_opo"' ;
        $_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) ;
    }

}

?>
