<?php
class report_pl_packet_log extends c_report
{
 var $title='Лог обращений к серверу ПЛ' ;
 var $view_by_space_filter=1 ;
 var $packet_id=0 ;



  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter) ;
     $usl=array() ;
     $usl[]='packet_id='.$this->packet_id.'' ;
     $usl_res=implode(' and ',$usl) ;
     return($usl_res) ;
  }

  function get_cnt_items($usl,$options=array())
  { $cnt=execSQL_value('select count(pkey)
                        from  pl_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  pl_log
                       where '.$usl.$order.$limit,$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    print_2x_arr($list_recs);
    ?>
      <table class="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><?
  }

}

?>
