<?php
class report_pl_log 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('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['type'])              $usl[]='obj_name like "'.$this->filter['type'].'"' ;
     if ($this->type)                        $usl[]='obj_name like "'.$this->type.'"' ;
     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']) ;
     $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(pkey)
                        from  obj_site_post_log
                        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' ;
    //echo $usl ;
 	$list_rec=execSQL('select *
                       from  obj_site_post_log
                       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="log_upload_persons basic fz_small full auto" <?echo $id?>>
        <tr>
            <th>Дата, время</th>
            <th>IP</th>
            <th>Источник</th>
            <th>Обработано записей</th>
            <th>Обновлено<br>записей</th>
            <th>Добавлено<br>записей</th>
            <th>Деактивировано<br>записей</th>
            <th>Лог</th>
        </tr><? ;
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   $result=unserialize($rec['result'])  ;
            ?><tr>
              <td class=data><? echo date('d.m.Y H:i:s',$rec['c_data']) ;?></td>
              <td class=name><? echo $rec['ip'] ?></td>
                <td class=name><? echo $rec['obj_name'] ?></td>
              <td>
                      <?
                      switch ($rec['obj_name']) {
                          case 'upload_persons':      echo $result['person_count'] ;      break;
                          case 'upload_cars':         echo $result['car_count'] ;         break;
                          case 'upload_relationcar':  echo $result['relation_count'] ;    break;
                          default:                    echo $result['person_count'] ;

                      }
                      ?>
                </td>
                <td>
                      <?
                      switch ($rec['obj_name']) {
                          case 'upload_persons':      echo $result['person_update'] ;     break;
                          case 'upload_cars':         echo $result['car_update'] ;        break;
                          case 'upload_relationcar':  echo $result['relation_update'] ;       break;
                          default:                    echo $result['person_update'] ;
                      }
                      ?>
                </td>
                <td>
                      <?
                      switch ($rec['obj_name']) {
                          case 'upload_persons':      echo $result['person_adding'] ;     break;
                          case 'upload_cars':         echo $result['car_adding'] ;        break;
                          case 'upload_relationcar':  echo $result['relation_adding'] ;       break;
                          default:                    echo $result['person_adding'] ;
                      }
                      ?>
                </td>
                <td>
                      <?
                      switch ($rec['obj_name']) {
                          case 'upload_relationcar':  echo $result['relation_deactivate'] ;       break;
                          default:                    echo $result['person_fired'] ;
                      }
                      ?>
                </td>
              <td><? if ($rec['session_uid'] and file_exists(_DIR_TO_ROOT.'/logs/import_trace_'.$rec['session_uid'].'.html')) echo '<a target="blank" href="/logs/import_trace_'.$rec['session_uid'].'.html">'.$rec['session_uid'].'</a>' ?></td>
           </tr><?
        }
    ?></table><?
  }

}

?>
