<?php
class report_put_list extends c_report
{
 var $title='Лог пакетов ПЛ' ;
 var $view_by_space_filter=1 ;
 var $type='' ;

 function setting($options=array())
 {   $arr_import_types=execSQL('select distinct(obj_name) from obj_site_post_log') ;
      ?><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">
                          <?
                          if (!$this->type) $this->filter_section_select('type','Тип импорта:',2,$arr_import_types) ;
                          $this->filter_section_input_text('uid','UID:',2) ;
                          $this->filter_section_input_text('number','Номер:',2) ;
                          $this->filter_section_input_text('data_from','От:',2,array('class'=>'datetimepicker')) ;
                          $this->filter_section_input_text('data_to','До:',2,array('class'=>'datetimepicker')) ;
                          ?>
                        </div>
                  </fieldset>
                  <?$this->panel_button_apply();?>
              </form>
       </div><br>
     <?
  }

  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter) ;
     $usl=array() ;
     $usl[]='true';
     if ($this->filter['number'])              $usl[]='pl.number like "%'.$this->filter['number'].'"' ;
     if ($this->filter['uid'])              $usl[]='pl.uid like "%'.$this->filter['uid'].'%"' ;
     if ($this->filter['type'])              $usl[]='pl.obj_name like "'.$this->filter['type'].'"' ;
     if ($this->type)                        $usl[]='pl.obj_name like "'.$this->type.'"' ;
     if ($this->filter['data_from'])        $usl[]='pl.c_data>='.strtotime($this->filter['data_from']) ;
     if ($this->filter['data_to'])          $usl[]='pl.c_data<='.strtotime($this->filter['data_to']) ;
     $usl_res=implode(' and ',$usl) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['type'])                            $info['Тип импорта']='"'.$this->filter['type'].'"' ;
   if ($this->type)                                      $info['Тип импорта']='"'.$this->type.'"' ;
   if ($this->filter['data_from'])                       $info['дата от']='"'.$this->filter['data_from'].'"' ;
   if ($this->filter['data_to'])                         $info['дата до']='"'.$this->filter['data_to'].'"' ;
   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(pl.pkey)
                        from  pl_put_list pl
                        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 pkey desc' ;
     // $options['debug']=2 ;
    //echo $usl ;
 	$list_rec=execSQL('select pl.*,
 	                   t1.c_data as titul1_c_data,t1.status as  titul1_status,t1.titul_date_from,t1.titul_date_to,t1.car_number,
 	                   t2.c_data as titul2_c_data,t2.status as  titul2_status,
 	                   t3.c_data as titul3_c_data,t3.status as  titul3_status,
 	                   t4.c_data as titul4_c_data,t4.status as  titul4_status,
 	                   t5.c_data as titul5_c_data,t5.status as  titul5_status,
 	                   t6.c_data as titul6_c_data,t6.status as  titul6_status,
 	                   pers.obj_name as driver_name
                       from  pl_put_list pl
                       left join pl_packets t1 on t1.pkey=pl.packet_titul1_id
                       left join pl_packets t2 on t2.pkey=pl.packet_titul2_id
                       left join pl_packets t3 on t3.pkey=pl.packet_titul3_id
                       left join pl_packets t4 on t4.pkey=pl.packet_titul4_id
                       left join pl_packets t5 on t5.pkey=pl.packet_titul5_id
                       left join pl_packets t6 on t6.pkey=pl.packet_titul6_id
                       left join obj_site_personals pers on pers.pkey=pl.driver_id
                       where '.$usl.$order.$limit,$options) ;
    //if (_sizeof($list_rec)) foreach($list_rec as $id=>$rec) ESMO()->prepare_public_info_to_mo($list_rec[$id],$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    ?>
      <table class="table_pl_lists basic fz_small full auto" <?echo $id?>>
        <tr>
            <th>ID</th>
            <th>Дата ПЛ</th>
            <th>№ ПЛ</th>
            <th>UID ПЛ</th>
            <th>Водитель</th>
            <th>Авто</th>
            <th>Титул 1</th>
            <th>Титул 2</th>
            <th>Титул 3</th>
            <th>Титул 4</th>
            <th>Титул 5</th>
            <th>Титул 6</th>
        </tr><? ;
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {

            ?><tr>
              <td><? echo $rec['pkey'] ?></td>
              <td class=data><?
                    $day_from=date('d.m.Y',$rec['titul_date_from']) ;
                    $day_to=date('d.m.Y',$rec['titul_date_to']) ;
                    if ($day_from!=$day_to) echo $day_from.' - '.$day_to ;
                    else echo $day_from ;
              ?></td>
              <td><? echo $rec['number'] ?></td>
              <td><? echo $rec['uid'] ?></td>
              <td class="left"><?
                     $recs_drivers=execSQL('select * from pl_packet_driver where packet_id='.$rec['packet_titul1_id']);
                     if (sizeof($recs_drivers))
                     { ?><ul><?
                       foreach($recs_drivers as $rec_driver) echo '<li>'.$rec_driver['driver_fio'].'</li>';
                       ?></ul><?

                     }
                  ?>
              </td>
              <td><? echo $rec['car_number'] ;?></td>
              <td><? if ($rec['packet_titul1_id']) echo '<div class=comment>'.date('d.m.Y H:i:s',$rec['titul1_c_data']).'</div>ID '.$rec['packet_titul1_id']?><div class="info"><?echo PL()->arr_packet_titul_status[1][$rec['titul1_status']]?></div></td>
              <td class="left"><?
                        $recs_titul2=execSQL('select * from pl_packets where pl_id='.$rec['pkey']);
                        if (sizeof($recs_titul2))
                       { ?><ul><?
                         foreach($recs_titul2 as $rec_t2) echo '<li>ID '.$rec_t2['pkey'].' - <span class="green">'.PL()->arr_packet_titul_status[2][$rec_t2['status']].'</span></li>';
                         ?></ul><?
                       }
                   ?>
              </td>
              <td><? if ($rec['packet_titul3_id']) echo '<div class=comment>'.date('d.m.Y H:i:s',$rec['titul3_c_data']).'</div>ID '.$rec['packet_titul3_id']?><div class="info"><?echo PL()->arr_packet_titul_status[3][$rec['titul3_status']]?></div></td>
              <td><? if ($rec['packet_titul4_id']) echo '<div class=comment>'.date('d.m.Y H:i:s',$rec['titul4_c_data']).'</div>ID '.$rec['packet_titul4_id']?><div class="info"><?echo PL()->arr_packet_titul_status[4][$rec['titul4_status']]?></div></td>
              <td><? if ($rec['packet_titul5_id']) echo '<div class=comment>'.date('d.m.Y H:i:s',$rec['titul5_c_data']).'</div>ID '.$rec['packet_titul5_id']?><div class="info"><?echo PL()->arr_packet_titul_status[5][$rec['titul5_status']]?></div></td>
              <td><? if ($rec['packet_titul6_id']) echo '<div class=comment>'.date('d.m.Y H:i:s',$rec['titul6_c_data']).'</div>ID '.$rec['packet_titul6_id']?><div class="info"><?echo PL()->arr_packet_titul_status[6][$rec['titul6_status']]?></div></td>
           </tr><?
        }
    ?></table>

      <?
  }

}

?>
