<?php
class report_pass_of_skud extends c_report
{
 var $title='Импорт пропусков из СКУД' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $allow_export_to_csv=0 ;

 function setting($options=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','ФИО',2,array('auto_complete'=>"autocomplette_personal_name")) ;
                          $this->filter_section_input_text('propusk','пропуск',2) ;
                          $this->filter_section_input_text('UID','UID:',2) ;
                       ?></div>
                  </fieldset>
                  <?$this->panel_buttons();?>
              </form>
       </div><br>
     <?
  }


  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter) ;
     $usl=array() ;
     $usl[]=1 ;
     if ($this->filter['name'])              $usl[]='obj_name like "'.$this->filter['name'].'%"' ;
     if ($this->filter['propusk'])           $usl[]='(t1.propusk="'.$this->filter['propusk'].'" or t2.propusk="'.$this->filter['propusk'].'")' ;
     if ($this->filter['UID'])              $usl[]='t2.uid="'.$this->filter['UID'].'"' ;

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

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['name'])                  $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['propusk'])                  $info['Пропуск']='"'.$this->filter['propusk'].'"' ;
   if ($this->filter['UID'])                  $info['UID ФЛ']='"'.$this->filter['UID'].'"' ;

   if (sizeof($info)) foreach($info as $title=>$value) $_str[]=$title.': <strong>'.$value.'</strong>' ;
   if (sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
   return $title ;
 }


  function get_cnt_items($usl,$options=array())
  { //$options['debug']=1 ;
    $cnt=execSQL_value('select count(t1.uid)
                        from SKUD_pass t1
                        left join obj_site_personals t2 on t2.uid=t1.uid  
                        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']:' or' ; //' order by mess_c_data' ;
    // запрос по сотрудникам, состоящим в группе на выданные направления по АГ
    $list_recs=execSQL('select t1.UID as SKUD_uid,t1.propusk as SKUD_propusk,t2.*
                       from  SKUD_pass t1
                       left join view_personals t2 on t2.uid=t1.uid
                       where '.$usl.$limit,array('debug'=>0,'no_indx'=>1)) ;

    return($list_recs) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    ?><table class="basic fz_small full auto"<?echo $id?>>
        <colgroup><col id="c1"><col id="c2"><col id="c3"><col id="c4"></colgroup>
        <tr><th>UID ФЛ</th><th>Пропуск СКУД</th><th>Пропуск ЭСМО</th><th>ID ЭСМО</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 class="id"><?echo $rec['SKUD_uid']?></td>
                <td class="id"><?echo $rec['SKUD_propusk']?></td>
                <td class="id"><?echo $rec['propusk']?></td>
                <td class="id"><?echo $rec['pkey']?></td>
                <td class="id"><?echo $rec['obj_name']?></td>
                <td class="id"><?echo $rec['dr']?></td>
                <td class="left"><?echo $rec['_org_name']?></td>
                <td class="left"><?echo $rec['_otdel_name']?></td>
                <td class="left"><?echo _IL('IL_works')->recs[$rec['working']]['obj_name']?></td>
            </tr><?
        }
      ?></table><?


  }

    function print_template_CSV($list_recs,$options=array())
    { $i=$options['from'] ;
       $arr_atp_names=execSQL_row('select pkey,obj_name from obj_site_account where clss=206') ;
       if (sizeof($list_recs)) foreach($list_recs as $rec)
       { 
           //$block_data=($rec['mess_block_from'])? $rec['mess_block_from']:$rec['mess_max_data'] ;
           $block_data=$rec['mess_block_from'] ;
           $group_id=($rec['event_group_id'])? $rec['event_group_id']:$rec['mess_group_id'] ;
           
           $data=array() ;
      	   $data['№']=$i+1 ;
           $data['Пропуск']=$rec['propusk']  ;
           //$data['Табельный номер']=$rec['tabnumber']  ;
      	   $data['ФИО']=$rec['obj_name']  ;
           $data['UID']=$rec['uid']  ;
           $data['Дата рождения']=$rec['dr']  ;
           $data['Возраст']=$rec['age']  ;
      	   $data['Организация']=$rec['_org_name'] ;
      	   $data['Подразделение']=$rec['_otdel_name'] ;
           $data['Должность']=_IL('IL_works')->recs[$rec['working']]['obj_name'] ;
           $data['Группа']=(sizeof($rec['_groups']))? implode(', ',$rec['_groups']):'-' ;
           $data['Статус направления']=EVENT_DOCS()->arr_status[$rec['event_status']] ;
           $data['Место выдачи']=$arr_atp_names[$rec['mess_atp_id']] ;
           $data['Дата выдачи']=($rec['event_pass_c_data'])? date('d.m.Y H:i',$rec['event_pass_c_data']):'' ;
           $data['Дата блокировки']=($block_data)? date('d.m.Y H:i',$block_data):'' ;
           $data['Дней до блокировки']=($rec['event_status']!=5 and $block_data)? (($block_data>time())? floor(($block_data-time())/(60*60*24)):''):'';
           $data['Дата сдачи']=($rec['event_status']==5 and $rec['mess_close_data'])? date('d.m.Y',$rec['mess_close_data']):'' ;
           $data['Блокировка МО']=($rec['event_status']!=5 and $rec['mess_close_data'] and $block_data<time()/* and $rec['mess_block_mo']==1*/)? 'Да':'' ;
           // вносим данные в csv
           $this->put_data_to_CSV($data,$i) ;
      	   $i++ ;
  	   }


   }



}

?>