<?php
class report_log_sql_long_stats extends c_report
{
 var $title='Журнал долгих SQL-запросов (статистика)' ;
 var $allow_to_rol=array() ;
 var $filter=array() ;
 var $view_by_space_filter=1 ;
 var $use_jwplayer=1 ;
 var $view_graf=1 ;

 function setting($options=array())
 {
     //$members=ACCOUNTS()->get_list_members() ;
     //damp_array($this->filter) ;
     $ts=getdate()  ;
     $from=mktime($ts['hours'],$ts['minutes'],0,$ts['mon'],$ts['mday']-1,$ts['year']);
     $arr_server_ip=execSQL_row('select distinct(server_ip),server_ip from '.TM_LOG_SQL_LONG.' where server_ip!=""') ;
     $arr_sources=[1=>'Все запросы',2=>'Терминалы',3=>'ЛК'] ;



     if (!$this->filter['data_to']) $this->filter['data_to']=date('d.m.Y H:i',time()) ;
     if (!$this->filter['data_from']) $this->filter['data_from']=date('d.m.Y H:i',$from) ;
     ?><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">Дата от</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>
                          <?FORM()->section_select(['title'=>'Адрес сервера','name'=>'filter[server_ip]','recs'=>$arr_server_ip,'col_count'=>2,'value'=>$this->filter['server_ip']]);?>
                          <?FORM()->section_select(['title'=>'Источник запросов','name'=>'filter[source]','recs'=>$arr_sources,'col_count'=>2,'value'=>$this->filter['source']]);?>
                          <section class="col col-2">
                               <label class="label">Группировка данных:</label>
                               <label class="select">
                                  <select name="filter[grp]" id="grp">
                                      <option value="1" <?if ($this->filter['grp']==1) echo 'selected'?>>1 час</option>
                                      <option value="2" <?if ($this->filter['grp']==2) echo 'selected'?>>1 сутки</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 HTML_report_body($options=array())
    {   $stats=$this->prepare_result_data() ;
        //damp_array($recs,1,-1) ;
        ?><div id="reports_itog1"><?
           if ($this->view_graf) $this->report_graf($stats) ;
           //if ($this->view_table) $this->report_table($recs) ;
        ?></div><?
    }


    function prepare_result_data()
    {



        $to=($this->filter['data_to'])? strtotime($this->filter['data_to']):time()  ;
        $ts=getdate($to) ;
        $from=($this->filter['data_from'])? strtotime($this->filter['data_from']):mktime($ts['hours'],0,0,$ts['mon'],$ts['mday']-1,$ts['year']);
        //echo 'from='.date('d.m.Y H:i',$from).'<br>' ; echo 'to='.date('d.m.Y H:i',$to).'<br>' ;

        $group_template_mysql=($this->filter['grp']==2)? '%Y.%m.%d':'%Y.%m.%d %H' ;
        $group_template_php=($this->filter['grp']==2)? 'd.m.Y':'d.m.Y H:00' ;

        $t=$from ;
        $stats=array() ;
        while($t<=$to)
        {   $stats[date($group_template_php,$t)]=array('time'=>$t,'cnt_long'=>0,'sum_t_long'=>0,'cnt_mo_all'=>0,'cnt_mo'=>0) ;
            $ts=getdate($t) ;
            // grp=2 - группировка по суткам, иначе - по часовая
            if ($this->filter['grp']==2) $t=mktime($ts['hours'],$ts['minutes'],$ts['seconds'],$ts['mon'],$ts['mday']+1,$ts['year']);
            else  $t=mktime($ts['hours']+1,$ts['minutes'],$ts['seconds'],$ts['mon'],$ts['mday'],$ts['year']);
        }



        // получаем статистику по журналу долгих запросов
        // time_from используется далее как ключ, так как FROM_UNIXTIME возвращает данные по гринцичу (см. настройки mtsql)
        //damp_array($this->filter);
        $_arr_usl=[] ;
        $_arr_usl[]='c_data>='.$from ;
        $_arr_usl[]='c_data<='.$to ;
        if ($this->filter['source']==2) $_arr_usl[]='(url like "%check_access%" or url like "%examination_result%")' ;
        if ($this->filter['source']==3) $_arr_usl[]='not (url like "%check_access%" or url like "%examination_result%")' ;
        if ($this->filter['server_ip'])  $_arr_usl[]='server_ip="'.$this->filter['server_ip'].'"' ;
        //damp_array($_arr_usl);
        $usl_select=implode(' and ',$_arr_usl) ;

        $recs=execSQL('select (FROM_UNIXTIME(c_data,"'.$group_template_mysql.'")) as H,
                 count(pkey) as cnt,
                 min(c_data) as time_from,max(c_data) as time_to, 
                 sum(t_send)+sum(t_exec) as sum_t
                 from '.TM_LOG_SQL_LONG.'
                 where '.$usl_select.' 
                 group by H
                 order by H ',0,1) ;

        if (_sizeof($recs)) foreach($recs as $rec)
        {
            $stats[date($group_template_php,$rec['time_from'])]['cnt_long']=$rec['cnt'] ;
            $stats[date($group_template_php,$rec['time_from'])]['sum_t_long']=$rec['sum_t'] ;
        }


        $recs=execSQL('select FROM_UNIXTIME(c_data,"'.$group_template_mysql.'") as H,
                       min(c_data) as time_from,max(c_data) as time_to, 
                       min(pkey) as pkey_from,max(pkey) as pkey_to, 
                       count(pkey) as cnt
                       from obj_site_mo_session 
                       where c_data>='.$from.' and c_data<='.$to.'
                       group by H
                       order by H',0,1) ;

        if (_sizeof($recs)) foreach($recs as $id=>$rec)
        {
            //$stats[$rec['H']]['cnt_mo_all']=execSQL_value('select count(pkey) from obj_site_mo_session where pkey<='.$rec['pkey_to']) ; ;

            $stats[date($group_template_php,$rec['time_from'])]['cnt_mo']=$rec['cnt'] ;

        }
        $last_mo_cnt_value=0 ;
        if (_sizeof($stats)) foreach($stats as $id=>$rec_stat)
        {
            $stats[$id]['cnt_mo_all']=execSQL_value('select count(pkey) from obj_site_mo_session where c_data<='.$rec_stat['time']) ; ;
        }
        //print_2x_arr($recs);
        //print_2x_arr($stats) ;

        /*$recs=execSQL('select * from car_smena where task_id='.$this->task_id.' order by t_start') ;
        $last_data=0 ;
        foreach($recs as $rec)
        {   $ts=getdate($rec['t_start']) ;
            $day=mktime(0,0,0,$ts['mon'],$ts['mday'],$ts['year']);
            $stats[date('d.m',$day)]['cnt_smena']++ ;
            $stats[date('d.m',$day)]['cnt_trip']+=$rec['trip_count'] ;
            $stats[date('d.m',$day)]['wn']+=round(($rec['wn']/1000)) ;
            if ($rec['wn']>0) $last_data=$rec['t_start'] ;
        }
        $value=0 ;
        foreach($stats as $id=>$stat)
        {  $value=$value+$stat['wn'] ;
           $max_value=$rec_task['value'] ;
           $proc=$value/$max_value*100 ;
           if ($stat['time']<=$last_data) $stats[$id]['proc']=round($proc) ;
        }
        //print_2x_arr($stats) ;
        */
        return($stats) ;
    }


    function report_graf($stats)
       {   $caption='График статистики долгих SQL-запросов ' ;
           $arr_month=array_keys($stats) ;
            ?><div id="chart-container">Подождите, идет построение графика</div>
             <script type="text/javascript">
            $j(document).ready(function(){
              FusionCharts.ready(function(){
             var revenueChart2 = new FusionCharts({
                   type: 'mscombidy2d',
                   renderAt: 'chart-container',
                   width: '1800',
                   height: '600',
                   dataFormat: 'json',
                   dataSource: {
                       "chart": {
                           "caption": "<?echo $caption?>",
                           "xAxisname": "Дни/часы",
                           "pYAxisName": "Число долгих запросов.",
                           "sYAxisName": "Общее число МО",
                           "numberPrefix": "",
                           "sNumberSuffix" : "",
                           //"sYAxisMaxValue" : "50",
                           //Cosmetics
                           //"paletteColors" : "#f2c500,#FF0000,#1aaf5d",
                           "baseFontColor" : "#333333",
                           "baseFont" : "Helvetica Neue,Arial",
                           "captionFontSize" : "14",
                           "subcaptionFontSize" : "14",
                           "subcaptionFontBold" : "0",
                           "showBorder" : "0",
                           "bgColor" : "#ffffff",
                           "showShadow" : "0",
                           "canvasBgColor" : "#ffffff",
                           "canvasBorderAlpha" : "0",
                           "divlineAlpha" : "100",
                           "divlineColor" : "#999999",
                           "divlineThickness" : "1",
                           "divLineIsDashed" : "1",
                           "divLineDashLen" : "1",
                           "divLineGapLen" : "1",
                           "usePlotGradientColor" : "0",
                           "showplotborder" : "0",
                           "showXAxisLine" : "1",
                           "xAxisLineThickness" : "1",
                           "xAxisLineColor" : "#999999",
                           "showAlternateHGridColor" : "0",
                           "showAlternateVGridColor" : "0",
                           "legendBgAlpha" : "0",
                           "legendBorderAlpha" : "0",
                           "legendShadow" : "0",
                           "legendItemFontSize" : "10",
                           "legendItemFontColor" : "#666666"
                       },
                       "categories":
                       [{"showValues": "0",
                           "category": [ <?foreach($stats as $t=>$res)
                           {  echo '{ "label": "'.$t.'" },' ;
                           }

                           ?>]
                       }],
                       "dataset":
                       [
                           {
                               "seriesName": "Число долгих запросов",
                               "data": [ <?foreach($stats as $t=>$res) echo '{ "value" : "'.(($res['cnt_long'])? $res['cnt_long']:'null').'" },'?>],
                               "showValues": "0",
                           },
                          <? /*{
                               "seriesName": "Число рейсов",
                               "parentYAxis": "S",
                               "renderAs": "line",
                               "showValues": "1",
                               "divlineThickness" : "1",
                               "data": [ <?foreach($stats as $t=>$res) echo '{ "value" : "'.(($res['cnt_trip'])? $res['cnt_trip']:'null').'" },'?>]
                           },
                           {
                               "seriesName": "Суммарное время долгих запросов, сек",
                               //"parentYAxis": "S",
                               "renderAs": "line",
                               "showValues": "0",
                               "divlineThickness" : "1",
                               "data": [ <?foreach($stats as $t=>$res) echo '{ "value" : "'.(($res['sum_t_long'])? $res['sum_t_long']:'null').'" },'?>]
                           },*/?>
                           {
                               "seriesName": "Число МО",
                               "parentYAxis": "S",
                               "renderas": "line",
                               "showValues": "0",
                               "divlineThickness" : "1",
                               "showanchors": "0",
                               "plottooltext": "Число МО за час: $dataValue",
                               "data": [ <?foreach($stats as $t=>$res) echo '{ "value" : "'.(($res['cnt_mo'])? $res['cnt_mo']:'null').'" },'?>]
                           },
                           {
                               "seriesName": "Общее число МО, тыс.",
                               "parentYAxis": "S",
                               "renderas": "line",
                               "showValues": "0",
                               "divlineThickness" : "1",
                               "showanchors": "0",
                               "plottooltext": "Всего МО: $dataValue тыс.",
                               "data": [ <?foreach($stats as $t=>$res) echo '{ "value" : "'.(($res['cnt_mo_all'])? round($res['cnt_mo_all']/1000,1):'null').'" },'?>]
                           }

                       ]
                   }
               });

               revenueChart2.render();
           });
            }) ;
                </script>
                <style type="text/css">#chart-container{}</style>
              <?



       }

    function report_table($result)
       {   ?><table class="basic fz_small" style="table-layout:fixed;">
                   <colgroup>
                       <col id="c1">
                       <col id="c2">
                       <col id="c3">
                       <col id="c4">
                       <col id="c5">
                       <col id="c6">
                       <col id="c7">
                       <col id="c8">
                   </colgroup>
                   <tr><th rowspan="3">Дата</th>
                       <th rowspan="3"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/cntmo.png'?>"><!--Кол-во МО--></th>
                       <th colspan="2">Терминалы</th>
                       <th colspan="9">РМВ</th>
                       <th rowspan="3"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/dlit.png'?>"><!--Среднее время МО<br>сек--></th>
                       <th rowspan="3">КРТ</th>
                       <th rowspan="3">КОC</th>
                   </tr>
                   <tr><th rowspan="2"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/mo_success.png'?>"><!--МО пройден--></th>
                       <th rowspan="2"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/ukl.png'?>"><!--МО не пройден, уклонились от РМВ--></th>
                       <th colspan="7">Причины направления на РМВ</th>
                       <th rowspan="2"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/mo_success.png'?>"><!--МО пройден--></th>
                       <th rowspan="2"><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/mo_failed.png'?>"><!--Допуск запрещен--></th>
                   </tr>
                   <tr><th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/sd.png'?>"><!--Давление--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/p.png'?>"><!--Пульс--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/t.png'?>"><!--Температура--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/a.png'?>"><!--Алкоголь--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/pp.png'?>"><!--Пупиллометрия--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/question.png'?>"><!--Жалобы--></th>
                       <th><img src="<?echo _PATH_TO_SITE._PATH_TO_EXT.'/aspmo_reports/images/no_result.png'?>"><!--Не удалось провести измерение--></th>
                   </tr>
               <? $itog=array() ;
                  if (_sizeof($result)) foreach($result as $data=>$rec)
                   {   $time_s=strtotime($data) ;
                       $ts=getdate($time_s) ;
                       //$time_e=mktime(0,0,0,$ts['mon']+1,1,$ts['year'])-1 ;  // исправлено
                       $a_href='' ; $row_title='' ;
                       switch($this->step)
                       { case '1h': $row_title=date('H:i:s',$time_s) ;
                                    $time_e=mktime($ts['hours']+1,0,0,$ts['mon'],$ts['mday'],$ts['year'])-1 ;
                                    $a_href='' ;
                                    break  ;
                         case '1d': $row_title=date('d.m.Y',$time_s) ;
                                    $time_e=mktime(0,0,0,$ts['mon'],$ts['mday']+1,$ts['year'])-1 ;
                                    $a_href='' ;
                                    break  ;
                         case '1m': $row_title=get_month_year($time_s,'month year');
                                    $time_e=mktime(0,0,0,$ts['mon']+1,1,$ts['year'])-1 ;
                                    $a_href=$this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e),array('url_report'=>'/cab/reports/itog6/')) ;
                                    break ;

                       }

                       ?><tr>
                         <td><?echo ($a_href)? '<a href="'.$a_href.'" target=_BLANK>'.$row_title.'</a>':$row_title?></td>
                         <td><?echo $rec['count_mo'] ;            $itog['all']+=$rec['count_mo'] ; ?></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'model'=>'(1;3)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><? $a1=$rec['mo_stats'][1]+$rec['mo_stats'][3] ; if ($a1) echo $a1 ; $itog['a1']+=$a1 ; ?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'model'=>'(2;4)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><? $a2=$rec['mo_stats'][2]+$rec['mo_stats'][4] ; if ($a2) echo $a2 ; $itog['a2']+=$a2 ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'d'=>1,'model'=>'(0;1;3;5;6;7;8;9;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?echo $d=$rec['d'][0] ;  $itog['d']+=$d ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'p'=>1,'model'=>'(0;1;3;5;6;7;8;9;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?echo $p=$rec['p'][0] ;  $itog['p']+=$p ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'t'=>1,'model'=>'(0;1;3;5;6;7;8;9;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?echo $t=$rec['t'][0] ;  $itog['t']+=$t ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'a'=>1,'model'=>'(0;1;3;5;6;7;8;9;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?echo $a=$rec['a'][0] ;  $itog['a']+=$a ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'n'=>1,'model'=>'(0;1;3;5;6;7;8;9;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?echo $n=$rec['n'][0] ;  $itog['n']+=$n ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'q'=>1,'model'=>'(0;1;3)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><?$q=$rec['q'][0] ; if ($q) echo $q ; $itog['q']+=$q ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'equipmentErrorOrCancelTimeout'=>1,'model'=>'(0;1;3)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><? $e=$rec['error'][0] ; if ($e) echo $e ; ?></a><? $itog['e']+=$e ;?></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'model'=>'(5;7;9)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><? $a3=$rec['mo_stats'][5]+$rec['mo_stats'][7]+$rec['mo_stats'][9]  ; if ($a3) echo $a3 ; $itog['a3']+=$a3 ;?></a></td>
                         <td><a href="<?echo $this->get_filter_to_params(array('time_from'=>$time_s,'time_to'=>$time_e,'model'=>'(6;8;10)'),array('url_report'=>'/cab/reports/report_mo_sess/'))?>" target=_BLANK><? $a4=$rec['mo_stats'][6]+$rec['mo_stats'][8]+$rec['mo_stats'][10]  ; if ($a4) echo $a4 ;$itog['a4']+=$a4 ;?></a></td>
                         <td><? $t=round($rec['avg_time']) ;  if ($t) echo $t ; $itog['avg_time']+=$rec['avg_time']  ;  ?></td>
                         <td><?$k1=($rec['count_mo'])? round(($a3+$a4)/$rec['count_mo']*100,2):0 ;
                             $result[$data]['k1']=$k1 ; if ($k1) echo $k1 ;  $itog['k1']+=$k1  ;  ?></td>
                         <td><?$k2=($rec['count_mo'])? round($e/$rec['count_mo']*100,2):0 ;
                              $result[$data]['k2']=$k2 ; if ($k2) echo $k2 ;  $itog['k2']+=$k2  ;  ?></td>
                        </tr>
                       <?
                   }
                   ?><tr class="itog">
                       <td class="left">ИТОГО</td>
                       <td><?echo $itog['all']?></td>
                       <td><?echo $itog['a1']?></td>
                       <td><?echo $itog['a2']?></td>
                       <td><?echo $itog['d']?></td>
                       <td><?echo $itog['p']?></td>
                       <td><?echo $itog['t']?></td>
                       <td><?echo $itog['a']?></td>
                       <td><?echo $itog['n']?></td>
                       <td><?echo $itog['q']?></td>
                       <td><?echo $itog['e']?></td>
                       <td><?echo $itog['a3']?></td>
                       <td><?echo $itog['a4']?></td>
                       <td><? echo round($itog['avg_time']/_sizeof($result))?></td>
                       <td><?echo round($itog['k1']/_sizeof($result),2)?></td>
                       <td><?echo round($itog['k2']/_sizeof($result),2)?></td>
                   </tr>
                 </table>
           <br>
           <br>
                 <style type="text/css">
                     div#reports_itog1{}
                     div#reports_itog1 table{width:100%;table-layout:fixed;border-collapse:collapse;}
                     div#reports_itog1 table colgroup col#c1{width:100px;}
                     div#reports_itog1 table colgroup col#c2{width:100px;}
                     div#reports_itog1 table colgroup col#c3{width:100px;}
                     div#reports_itog1 table colgroup col#c4{width:100px;}
                     div#reports_itog1 table colgroup col#c6{width:100px;}
                     div#reports_itog1 table colgroup col#c7{width:100px;}
                     div#reports_itog1 table colgroup col#c8{width:100px;}
                     div#reports_itog1 th{background:#dddddd;color:black;font-weight:bold;border:1px solid #aaaaaa;}
                     div#reports_itog1 td{padding:5px;border:1px solid #aaaaaa;text-align:center;}
                     div#reports_itog1 td.left{text-align:left;}
                     div#reports_itog1 tr.subitog1 td{font-weight:bold;background:#f1f1f1;text-align:center;}
                     div#reports_itog1 tr.subitog1 td.left{text-align:left;}
                     div#reports_itog1 tr.subitog2 td{font-weight:bold;background:#fafafa;text-align:center;}
                     div#reports_itog1 tr.subitog2 td.left{text-align:left;}
                     div#reports_itog1 tr.itog td{font-weight:bold;background:#dddddd;}
                     div#reports_itog1 table.debug td:first-child{width:250px;text-align:left;}
                     div#reports_itog1 table.debug td:last-child{width:70px;}
                  </style>
         <?
       }






  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
     $recs_account=execSQL('select pkey,obj_name,rol from obj_site_account') ;
     ?><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>Дата, время</th><th>Время</th><th>Время SQL</th><th>Время передачи</th><th>Число строк</th><th>SQL</th><th>URL страницы</th><th>trace</th><th>Аккаунт</th><th>IP</th></tr>
        </thead>
        <tbody>

        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   if (isset($rec['user_id']) and isset($recs_account[$rec['user_id']]) and !$rec['member_id']){ $rec['member_id']=$rec['user_id'] ; $rec['user_id']='' ;}
            ?><tr>
              <td class=id><? echo $rec['pkey'] ;?></td>
              <td class=data><? echo date('d.m.Y H:i:s',$rec['c_data']) ;?></td>
              <td class="left"><? echo $rec['t_exec']+$rec['t_send'] ;?></td>
              <td class="left"><? echo $rec['t_exec'] ;?></td>
              <td class="left"><? echo $rec['t_send'] ;?></td>
              <td class="left"><? echo $rec['cnt'] ;?></td>
              <td class="left"><div style="width:700px;"><? echo nl2br(str_replace(',',', ',base64_decode($rec['obj_name']))) ;?></div></td>
              <td class="left"><? echo $rec['url'] ;?></td>
              <td class="comment left"><? if ($rec['trace'] and file_exists(_DIR_TO_ROOT.$rec['trace'])) echo '<a target=_blank href="'.$rec['trace'].'">'.$rec['trace'].'</a>'?></td>
              <td class=name><? echo $recs_account[$rec['account_id']]['obj_name'].'<br>'.$_SESSION['ARR_roll'][$rec['rol']]['obj_name'] ?></td>
              <td class=id><? echo $rec['IP'] ;?></td>
           </tr><?
        }
    ?></tbody></table>

    <? $this->panel_info_select($options) ;

  }

  function print_template_HTML_small($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
     $recs_account=execSQL('select pkey,obj_name,rol from obj_site_account') ;
     ?><table class="basic fz_small full auto" <?echo $id?>>
        <thead>
            <tr><th>ID</th><th>IP</th><th>Дата, время</th><th>Оператор</th><th>Действие</th><th>Объекты события</th><th>Результат</th></tr>
        </thead>
        <tbody>

        <?
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        {   if (isset($rec['user_id']) and isset($recs_account[$rec['user_id']]) and !$rec['member_id'])
                { $rec['member_id']=$rec['user_id'] ; $rec['user_id']='' ;

                }
            $recs_reffers=array() ; $str=array() ;
            if (isset($rec['reffer1'])) $recs_reffers[]=get_obj_info($rec['reffer1']) ;
            if (isset($rec['reffer2'])) $recs_reffers[]=get_obj_info($rec['reffer2']) ;
            if (isset($rec['reffer3'])) $recs_reffers[]=get_obj_info($rec['reffer3']) ;
            if (isset($rec['reffer4'])) $recs_reffers[]=get_obj_info($rec['reffer4']) ;
            if (isset($rec['reffer5'])) $recs_reffers[]=get_obj_info($rec['reffer5']) ;
            if (_sizeof($recs_reffers)) foreach($recs_reffers as $rec_reffer)
              {  $class_name=$_SESSION['descr_clss'][$rec_reffer['clss']]['name'] ;
                 $obj_name=$rec_reffer['obj_name'] ;
                 $obj_ID=$rec_reffer['pkey'] ;
                 $str[]=$class_name.' '.$obj_name.', ID '.$obj_ID.'' ;
              }
            ?><tr>
              <td class=id><? echo $rec['pkey'] ;?></td>
              <td class=id><? echo $rec['IP'] ;?></td>
              <td class=data><? echo date('d.m.Y H:i:s',$rec['c_data']) ;?></td>
              <td class=name><? echo $recs_account[$rec['account_id']]['obj_name'].'<br>'.$_SESSION['ARR_roll'][$rec['rol']]['obj_name'] ?></td>
              <td class=name><? echo $rec['obj_name'] ?></td>
              <td class="left"><? if (_sizeof($str)) echo implode('<br>',$str) ;?></td>
              <td class="comment left"><? echo $rec['comment'] ?></td>
           </tr><?
        }
    ?></tbody></table>

    <? $this->panel_info_select($options) ;

  }





}

?>
