<?php
// специальный отчет для добавления сотрудников в группы
class report_to 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 $account_id=0 ;


 function init($options=array())
 {
    //if ($this->event_id) $this->rec_event=EVENTS()->get_event_by_id($this->event_id) ;

 }

 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?>">
                 <input type="hidden" name="filter[event_id]" value="<?echo $this->filter['event_id']?>">
                 <fieldset>
                                      <div class="row">
                                          <section class="col col-3">
                                              <label class="label">ФИО:</label>
                                              <label class="input"><input type="text" name="filter[name]" value="<?echo htmlspecialchars($this->filter['name'])?>"></label>
                                          </section>
                                          <section class="col col-3">
                                              <label class="label">Номер машины:</label>
                                              <label class="input"><input type="text" name="filter[car_number]" value="<?echo htmlspecialchars($this->filter['car_number'])?>"></label>
                                          </section>
                                      </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=360' ;
     $usl[]='enabled=1' ;
     if ($this->event_id)            $usl[]='event_id='.$this->event_id ;
     if ($this->group_id)
     {   $chids_group=ACCOUNTS()->tree[$this->group_id]->get_list_child() ;
         $usl[]='org_group_id in ('.$chids_group.')' ;
     }
     if ($this->filter['name'])                $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;
     if ($this->filter['car_number'])                $usl[]='car_number like "%'.$this->filter['car_number'].'%"' ;
     if ($this->filter['status'])                $usl[]='event_status='.$this->filter['status'].'' ;
     if ($this->filter['dep_ids'])         $usl[]='parent2 in ('.implode(',',array_keys($this->filter['dep_ids'])).')' ;
     if ($this->filter['age_from'])        $usl[]='age>='.$this->filter['age_from'];
     if ($this->filter['age_to'])          $usl[]='age<='.$this->filter['age_to'];
     if (sizeof($this->filter['working_ids'])) $usl[]='working in ('.implode(',',array_keys($this->filter['working_ids'])).')' ;

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

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['car_number'])                            $info['Номер авто']='"'.$this->filter['car_number'].'"' ;
   if ($this->filter['status'])                            $info['Статус']=$_SESSION['ARR_event_pass_status'][$this->filter['status']] ;
   
     if ($this->filter['dep_ids'])                         $info['Организация']=PERSONAL()->get_org_names_by_ids(array_keys($this->filter['dep_ids']))  ;
     //if ($this->filter['working'])                         $info['должность']=_IL('IL_works')->recs[$this->filter['working']]['obj_name'];
     //if ($this->filter['working_id'])                      $info['должность']=_IL('IL_works')->recs[$this->filter['working_id']]['obj_name'];
     if (sizeof($this->filter['working_ids']))
     {   $arr=array() ;
         foreach($this->filter['working_ids'] as $work_id=>$flag)  $arr[]=_IL('IL_works')->recs[$work_id]['obj_name'] ;
         $info['должность']=implode(',',$arr) ;
     }
     //if ($this->filter['propusk'])                         $info['номер пропуска']='"'.$this->filter['propusk'].'"' ;

     if ($this->filter['age_from'])                        $info['возраст, от']=$this->filter['age_from'];
     if ($this->filter['age_to'])                          $info['возраст, до']=$this->filter['age_to'];

     if (sizeof($this->filter['group_medic']))
     { $arr_group_name=array() ;
       foreach($this->filter['group_medic'] as $group_id=>$flag) $arr_group_name[]=_IL('IL_group_medic')->recs[$group_id]['obj_name'] ;
       if (sizeof($arr_group_name)) $info['группа по болезни']=implode(',',$arr_group_name);
     }

     if (sizeof($this->filter['group_pers']))
     { $arr_group_name=array() ;
       foreach($this->filter['group_pers'] as $group_id=>$flag) $arr_group_name[]=_IL('IL_groups')->recs[$group_id]['obj_name'] ;
       if (sizeof($arr_group_name)) $info['группа сотрудников']=implode(',',$arr_group_name);
     }


   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())
  { $cnt=execSQL_value('select count(pkey)
                        from  obj_site_cars_to
                        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' ;
    //echo $usl ;
//    $options['debug']=2 ;
 	$list_rec=execSQL('select *
                       from obj_site_cars_to
                       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() ;
    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <tr><th>№</th>
            <th>Гос.номер</th>
            <th>ФИО водителя</th>
            <th>Марка ТС</th>
            <th>Дата время/выезда</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)
        {
            if($rec['status']==1) $status = 'Исправно';
            elseif($rec['status']==2) $status = 'Неисправно';
            else $status = 'Не окончен';
            ?><tr class=item>
                <td><?echo $rec['pkey']?></td>
                <td><?echo $rec['car_number']?></td>
                <td><?echo $rec['obj_name']?></td>
                <td><?echo $rec['car_model']?></td>
                <td><?if ($rec['access_type']) echo date('d.m.Y H:i',$rec['c_data'])?></td>
                <td><?if ($rec['access_type']) echo $rec['probeg']?></td>
                <td><?if ($rec['access_type']) echo $status?></td>
                <td><?if ($rec['access_type']) if ($rec['sign_driver']){?><img class=sign src="/public/to_sign/<?echo $rec['sign_driver']?>" width="100px"><?}?></td>
                <td><?if ($rec['access_type']) if ($rec['sign_tech']){?><img class=sign src="/public/to_sign/<?echo $rec['sign_tech']?>" width="100px"><?}?></td>
                <td><?if (!$rec['access_type']) echo date('d.m.Y H:i',$rec['c_data'])?></td>
                <td><?if (!$rec['access_type']) echo $rec['probeg']?></td>
                <td><?if (!$rec['access_type']) echo $status?></td>
                <td><?if (!$rec['access_type']) if ($rec['sign_driver']){?><img class=sign src="/public/to_sign/<?echo $rec['sign_driver']?>" width="100px"><?}?></td>
                <td><?if (!$rec['access_type']) if ($rec['sign_tech']){?><img class=sign src="/public/to_sign/<?echo $rec['sign_tech']?>" width="100px"><?}?></td>
            </tr><?
        }
      ?></table><?
      echo '</form>' ;
      //damp_array($rec) ;
  }
    

}

?>