<?php
// отчет по участию мероприятии контроля сдачи документа
// вызываетс с
// - карточка сотрудника/мероприятия/контроль сдачи
// - карточка документа/контроль сдачи
include_once(_DIR_EXT.'/events_docs/i_event_docs.php');
class report_events_in_event_docs_put extends c_report
{
 var $title='Сотрудники, получившие документ' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $rec_event=array() ;
 var $event_group_id=0 ;
 var $event_id=0 ;
 var $group_id=0 ;
 var $personal_id=0 ;
 var $event_pass_id=0 ;
 var $ids=0 ;
 var $status=array() ;

 function setting($options=array())
 {   if (!is_array($options['disabled_filter'])) $options['disabled_filter']=array() ;

     ?><div id="panel_filter">
             <form id="sky-form" class="sky-form">
                 <input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                 <fieldset>
                     <div class="row">
                       <? $this->filter_section_input_text('name','ФИО:',3,array('auto_complete'=>"autocomplette_personal_name")) ;
                       ?>
                     </div>
                     <div class="row">
                       <?
                       ?>
                     </div>
                 </fieldset>
                 <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="Поиск"></div>
              </form>
       </div><br>
     <?
  }


  function create_usl_select_obj($_params=array(),&$options=array())
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='clss=223' ;
     // выборку по pass можно делать только с мероприятий контроля сдачи документов
     if (!$this->event_id)
     { $event_ids=execSQL_row('select pkey,obj_name from obj_site_events_schedule where ext like "events_docs/%"') ;
       if (_sizeof($event_ids)) $usl[]='event_id in ('.implode(',',array_keys($event_ids)).')' ;
       else $usl='0' ;
     }
     if ($this->ids)                     $usl[]='pkey in ('.$this->ids.')' ;
     if ($this->doc_id)                     $usl[]='doc_id='.$this->doc_id ;
     if ($this->event_pass_id)           $usl[]='pkey='.$this->event_pass_id ;
     if ($this->personal_id)                     $usl[]='personal_id='.$this->personal_id ;
     if (_sizeof($this->status))            $usl[]='event_status in ('.implode(',',$this->status).')' ;

     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl) ;
     return($usl_res) ;
  }

  function get_arr_info_filters()
  { $info=parent::get_arr_info_filters() ;
    //if ($this->filter['status'])  $info['Статус']=EVENT_PMO()->arr_status[$this->filter['status']] ;
    return $info ;
  }


 function get_cnt_items($usl,$options=array())
  { //$options['debug']=2 ;
    $cnt=execSQL_value('select count(pkey)
                        from  obj_site_events_pass
                        where '.$usl,$options) ;
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by obj_name' ;
      $order=' order by pkey desc' ;
    //echo $usl ;
    //$options['debug']=2 ;
    $options['no_indx']=1 ;
 	$list_rec=execSQL('select *
                       from obj_site_events_pass
                       where '.$usl.$order.$limit,$options) ;
    //if (_sizeof($list_rec)) foreach($list_rec as $id=>$rec) PERSONAL()->prepare_public_info_to_personal($list_rec[$id],$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    $arr_personal_ids=array() ;
      //print_2x_arr($list_recs,1,-1) ;
    ?><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>
            <th>Дата сдачи</th>
            <th>Скан</th>
        </tr>
        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec_event_pass)
        {   if ($rec_event_pass['event_id']) $rec_event=EVENTS()->get_event_by_id($rec_event_pass['event_id']) ;  else $rec_event=array() ;
            if ($rec_event_pass['scan_id']) $rec_scan=DOCS()->get_scan_by_id($rec_event_pass['scan_id']) ;        else $rec_scan=array() ;
            if ($rec_event_pass['doc_id']) $rec_doc=DOCS()->get_doc_by_id($rec_event_pass['doc_id']) ;            else $rec_doc=array() ;
            if ($rec_event_pass['personal_id']) $rec_personal=PERSONAL()->get_personal_by_id($rec_event_pass['personal_id']) ;            else $rec_personal=array() ;

            ?><tr class=item>
                <td><a href="/window/events/event_pass/<?echo $rec_event_pass['pkey']?>/" class="new_window"><?echo $rec_event_pass['pkey']?></a></td>
                <td class="left"><a href="<?echo $rec_personal['__href_window']?>" class="new_window" target="_blank" title="win_second"><?echo $rec_personal['obj_name']?></a>
                    <?  /*if ($rec['uid']) echo '<br><span class="nowrap small">'.$rec['uid'].'</span>' ;*/
                        if (!$rec_personal['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec_personal['fired_data']).')' ;
                        if ($rec_personal['dr'])echo '<br>'.$rec_personal['dr'] ;
                    ?>
                </td>
                <td class="left"><?echo '<strong>'.$rec_personal['_org_name'].'</strong><br><div class="small">'.$rec_personal['_otdel_name'].'</div>'._IL('IL_works')->recs[$rec_personal['working']]['obj_name']?></td>
                <td><?echo (_sizeof($rec_personal['_groups_medic']))? implode(', ',$rec_personal['_groups_medic']):''?></td>
                <td><?if ($rec_event['pkey']) echo $rec_event['__type_name'].'"'.$rec_event['obj_name'].'"<br>['.$rec_event_pass['pkey'].']'?></td>
                <td><?if ($rec_doc['pkey']) {?><a href="<?echo $rec_doc['__href_window']?>" class="new_window"><?echo $rec_doc['obj_name']?></a><?}?></td>
                <td><?if ($rec_doc['pkey']) echo date('d.m.Y H:i:s',$rec_doc['c_data']) ; ?></td>

                <td><?echo EVENT_DOCS()->arr_status[$rec_event_pass['status']] ?></td>
                <td><?echo ($rec_event_pass['close_data'])? date('d.m.Y H:i:s',$rec_event_pass['close_data']):''?></td>
                <td><?if ($rec_scan['pkey']) {?><span class="nowrap"><a href="<?echo $rec_scan['__href']?>" class="new_window" target="_blank" title="window_scan">Открыть скан</a></span><?}?></td>
            </tr><?
        }
      ?></table>
      <style type="text/css">
                      table.list_personal_table_img{}
                      table.list_personal_table_img td.cnt_mess{font-size:22px;color:green;}
                      table.list_personal_table_img td.cnt_mess a{text-decoration:none;}
                      table.list_personal_table_img td.cnt_mess a:hover{text-decoration:underline;}
                      table.list_personal_table_img div.view_cnt{font-size:24px;margin:5px 0;}
                      table.list_personal_table_img div.view_data{font-size:14px;margin:5px 0;}
                      table.list_personal_table_img div.mess_status{font-size:14px;margin:5px 0;font-weight:bold;}
                      table.list_personal_table_img div.mo_alert{color:white;font-size:15px;margin-top:10px;background:darkred;padding:10px;}
                  </style>
      <?
  }


}

?>
