<?php
class report_log_faceid extends c_report
{
 var $title='Журнал обработки faceid' ;
 var $allow_to_rol=array() ;
 var $filter=array() ;
 var $view_by_space_filter=1 ;
 var $use_jwplayer=1 ;

 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">

                          <section class="col col-2">
                              <label class="label">IP:</label>
                              <label class="input">
                                  <input type="text" name="filter[ip]"  value="<? echo $this->filter['ip']?>">
                              </label>
                           </section>


                          <section class="col col-2">
                              <label class="label">Дата от</label>
                              <label class="input">
                                  <i class="icon-append fa fa-calendar"></i>
                                  <input type="text" name="filter[data_from]" class="datetimepicker" value="<?if ($this->filter['data_from']) echo $this->filter['data_from']?>">
                              </label>
                            </section>
                            <section class="col col-2">
                              <label class="label">Дата до</label>
                              <label class="input">
                                  <i class="icon-append fa fa-calendar"></i>
                                  <input type="text" name="filter[data_to]" class="datetimepicker" value="<?if ($this->filter['data_to']) echo $this->filter['data_to']?>">
                              </label>
                          </section>
                          <section class="col col-2">
                               <label class="label">Сортировка:</label>
                               <label class="select">
                                  <select name="filter[order]" id="order">
                                      <option value="0" <?if (!$this->filter['order']) echo 'selected'?>>Обратная</option>
                                      <option value="1" <?if ($this->filter['order']==1) echo 'selected'?>>Прямая</option>
                                  </select>
                               </label>
                            </section>
                        </div>
                  </fieldset>
                 <div id="panel_buttons"><input type="submit" class="button v2" cmd="set_filter" value="OK"></div>
              </form>
       </div>
     <?
  }


  function create_usl_select_obj($_params,&$options)
  {  $usl=array() ;
     if ($this->filter['personal_id'])          $usl[]='personal_id="'.$this->filter['personal_id'].'"' ;
     if ($this->filter['image_id'])          $usl[]='image_id="'.$this->filter['image_id'].'"' ;
     if ($this->filter['data_from'])           $usl[]='c_data>='.strtotime($this->filter['data_from']) ;
     if ($this->filter['data_to'])             $usl[]='c_data<='.strtotime($this->filter['data_to']) ;
     if ($this->filter['text'])              $usl[]='comment like "%'.$this->filter['text'].'%"' ;

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

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['data_from'])                         $info['c']=$this->filter['data_from'] ;
   if ($this->filter['data_to'])                           $info['по']=$this->filter['data_to'] ;
   if ($this->filter['text'])                              $info['текст']=$this->filter['text'] ;
   if ($this->filter['ip'])                                $info['IP']=$this->filter['ip'] ;
   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  log_faceid_upload_photo 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']=0 ;
    $list_rec=execSQL('select * from  log_faceid_upload_photo where '.$usl.$order.$limit,$options) ;
    return($list_rec) ;
  }


  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;

     ?><table class="basic fz_small <?if (!$this->filter['no_full_width']) echo 'full'?> auto list_logs_events" <?echo $id?>>
        <thead>
            <tr><th>ID</th><th>ID сотрудника</th><th>ID фото</th><th>Время запроса</th><th>Время ответа</th><th>Продолжительность обработки фото</th><th>Результат</th><th>Комментарий</th></tr>
        </thead>
        <tbody>

        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   ?><tr>
              <td class=id><? echo $rec['pkey'] ;?></td>
              <td class=id><? echo $rec['personal_id'] ;?></td>
              <td class=id><? echo $rec['image_id'] ;?></td>
              <td class=data><? echo date('d.m.Y H:i:s',$rec['time_send']) ;?></td>
              <td class=data><? echo date('d.m.Y H:i:s',$rec['time_response']) ;?></td>
              <td class=name><? echo ($rec['time_response'])? ($rec['time_response']-$rec['time_send']).' сек':'-' ?></td>
              <td class=name><? if ($rec['result']==1) echo '<span class="green">ok</span>' ;
                                if ($rec['result']==2) echo '<span class="red">failed</span>' ;
              ?></td>
              <td class="left"><? echo $rec['comment'] ;?></td>
           </tr><?
        }
    ?></tbody></table><?
  }


}

?>
