<?php
include_once("c_debug.php");
class c_page_cab_debug_info extends c_page_cab_debug
{
  public $h1='Информация по работе системы' ;

    function second_menu_config()
    {
       $this->second_menu['/cab/debug/info/']='Информация' ;
       $this->second_menu['/cab/debug/info/db/']='Информация БД' ;
       $this->second_menu['/cab/debug/info/clss/']='Классы' ;
     $this->second_menu['/cab/debug/info/log_mo/']='Журнал событий' ;
       //$this->second_menu['/cab/debug/info/sql/']='SQL-запрос' ;
       //$this->second_menu['/cab/debug/info/shell/']='Shell-команда' ;
       $this->second_menu['/cab/debug/personal_filters/']='Фильтры по сотрудникам' ;
       $this->second_menu['/cab/debug/server_info/']='Сервер' ;
       $this->second_menu['/cab/debug/phpinfo/']='phpinfo' ;
     $this->second_menu['/cab/debug/dir_info/']='Диск' ;
     $this->second_menu['/cab/debug/session/']='Сессия' ;
     //$this->second_menu['/cab/debug/info/cleaning/']='Чистка базы' ;
     $this->second_menu['/cab/debug/upload_XLS/']='Загрузка XLS' ;
     $this->second_menu['/cab/debug/info/mail/']='Проверка почты' ;
     $this->second_menu['/cab/debug/info/mo/']='Проверка МО' ;
     $this->second_menu['/cab/debug/monitor/']='Мониторинг' ;
     $this->second_menu['/cab/debug/info/state/']='Состояние сервера' ;
     $this->second_menu['/cab/mBox/']='mBox' ;
     $this->second_menu['/cab/megamenu/']='megamenu' ;
     $this->second_menu['/cab/debug/info/general/']='general' ;
     $this->second_menu['/cab/debug/engine_load/']='engine_load' ;
       //$this->second_menu['/cab/debug/info/ag/']='Импорт направлений по АГ' ;
    }


  function block_main()
  { $this->page_title() ;
    $this->panel_info() ;
  }

   function panel_info()
   {  ?><div class="float_left">
         <h2>Настройки сервера ЭСМО</h2><?
       ?><table class="basic left fz_small">
            <tr><td><strong>SERVER IP</strong></td><td><?echo $_SERVER['SERVER_ADDR']?></td></tr>
            <tr><td><strong>_PATH_TO_SITE</strong></td><td><?echo _PATH_TO_SITE?></td></tr>
            <tr><td><strong>_MAIN_PROTOCOL</strong></td><td><?echo _MAIN_PROTOCOL?></td></tr>
            <tr><td><strong>_CUR_SHEME</strong></td><td><?echo _CUR_SHEME?></td></tr>
            <tr><td><strong>_MAIN_DOMAIN</strong></td><td><?echo _MAIN_DOMAIN?></td></tr>
            <tr><td><strong>DB NAME</strong></td><td><?echo $GLOBALS['_SETTING']['main_db']['db_name']?></td></tr>
            <tr><td><strong>NODE_ID</strong></td><td><?echo _CLUSTER_NODE_ID?></td></tr>
        </table></div>
        <div class="float_left">
        <h2>Подключенные модули</h2>
        <?  ?><table class="basic fz_small float_left"><tr><th>Наименование модуля</th><th>Тип модуля</th></tr><?
            foreach($GLOBALS['_SETTING']['modules'] as $name=>$use) if ($use and !$GLOBALS['_SETTING']['modules_local'][$name])
            {  ?><tr><?
               ?><td class="left"><?echo $name?></td><?
               ?><td>Основной</td><?
               ?></tr><?
            }
            if (_sizeof($GLOBALS['_SETTING']['modules_local'])) foreach($GLOBALS['_SETTING']['modules_local'] as $name=>$use) if ($use)
            {  ?><tr><?
               ?><td class="left"><?echo $name?></td><?
               ?><td><span class=green>Локальный</span></td><?
               ?></tr><?
            }
       ?></table></div>
       <div class="float_left"><h2>Подключенные плагины</h2>
        <?  ?><table class="basic fz_small float_left"><tr><th>Наименование плагина</th><th>Тип плагина</th></tr><?
            foreach($GLOBALS['_SETTING']['plugins'] as $name=>$use) if ($use and !$GLOBALS['_SETTING']['plugins_local'][$name])
            {  ?><tr><?
               ?><td class="left"><?echo $name?></td><?
               ?><td>Основной</td><?
               ?></tr><?
            }
            if (_sizeof($GLOBALS['_SETTING']['plugins_local'])) foreach($GLOBALS['_SETTING']['plugins_local'] as $name=>$use) if ($use)
            {  ?><tr><?
               ?><td class="left"><?echo $name?></td><?
               ?><td><span class=green>Локальный</span></td><?
               ?></tr><?
            }
         ?></table></div><div class="clear"></div><br><?


      ?><h2>Роли системы</h2><?
      //$recs=execSQL('select * from roles order by id') ; print_2x_arr($recs) ;
      print_2x_arr($_SESSION['ARR_roll']) ;



      ?><h2>Отчеты</h2><? $this->panel_info_reports(REPORTS()->reports_list) ?><br><br><?
      ?><h2>Документы</h2><?$this->panel_info_reports(REPORTS()->docs_list) ;?><br><br><?

      ?><h2>Списки</h2><?
       $res=array() ;
       if (_sizeof($_SESSION['index_list_names'])) foreach($_SESSION['index_list_names'] as $list_name)
       {
          $rec=_IL($list_name) ; foreach($rec as $fname=>$fvalue) if ($fname!='recs' and $fname!='recs_names') $res[$list_name][$fname]=$fvalue ;
          $res[$list_name]['count']=_sizeof(_IL($list_name)->recs) ;
       }

       print_2x_arr($res) ;?><br><br><?

      ?><h2>Сессия</h2><?
       ?>Размер сессии: <strong><?echo show_size(strlen(serialize($_SESSION)))?></strong><br><?
       $res=array() ;
       if (_sizeof($_SESSION)) foreach($_SESSION as $id=>$value)
       {
          $res[$id]=strlen(serialize($value)) ;
       }
       arsort($res) ;
       if (_sizeof($res)) foreach($res as $id=>$value) $res[$id]=show_size($value) ;
       print_1x_arr($res) ;?><br><br><?

      ?><h2>Обрабочики событий</h2><?
      $event_listers=execSQL('select * from event_lister') ;
      if (_sizeof($event_listers))
           { ?><table class="basic fz_small auto left"><tr><th>event</th><th>system</th><th>method</th><th>checked</th></tr><?
             foreach($event_listers as $rec)
               {?><tr><td><?echo $rec['obj_name']?></td>
                     <td><?echo $rec['system_name']?></td>
                     <td><?echo $rec['method_name']?></td>
                     <td><? $result=ENGINE()->on_event($rec['obj_name'],array(),array('check'=>1,'only_system_name'=>$rec['system_name'],'debug'=>0)) ;
                            if ($result['error']) echo '<span class="red">'.$result['error'].'</span>' ; else echo '<span class="green">OK</span>' ;
                         ?></td>
                 </tr>
               <?}?>
               </table>
               <?

           } else echo 'Обработчики событий не определены' ;

      /*
      ?><h2>Файловая система</h2>
       <table class="basic left fz_small">
                   <tr><td><strong>Директория документов</strong></td><td>8.0G</td><td>7304 файлов</td></tr>
                   <tr><td><strong>Директория фото</strong></td><td>6.2G</td><td>66110 изображений</td></tr>
               </table><br><br>
       <?
        */

      //$recs=execSQL('select count(pkey) from obj_site_personals where clss=211 and enabled=1 and _enabled=1 ',2) ;
      //$recs=execSQL('select count(pkey) from obj_site_personals where clss=211 and enabled=1 and _enabled=1 and s_medspravka=0',2) ;
      //$recs=execSQL('select count(pkey) from obj_site_personals where clss=211 and enabled=1 and _enabled=1 and s_medspravka=0 and s_medspravka<'.time(),2) ;

   }

   function panel_info_reports($recs)
   {
       ?> <table class="basic fz_small full auto">
              <tr><th>Код документа</th><th>doc_code</th><th>db_report_code</th><th>Локальный<br>класс</th><th>Директрия скрипта</th><th>Класс</th><th>section_title</th><th>name</th></tr>
              <?  if (_sizeof($recs)) foreach($recs as $code=>$rec)
                   {   $obj=REPORTS()->get_report_obj_by_code($code) ;
                       if (!isset($rec['overload'])) $rec['overload']=array() ;
                       ?><tr>
                           <td class="left"><?echo $code?></td>
                           <td class="left"><?echo $obj->doc_code?></td>
                           <td class="left"><?echo $obj->db_report_code?></td>
                           <td class="center"><?echo ($obj->is_local_verson)? 'Да':'-'?></td>
                           <td class="left"><?echo $this->show_overload_info($rec,'script_dir')?></td>
                           <td class="left"><?echo $this->show_overload_info($rec,'class_name')?></td>
                           <td class="left"><?echo $this->show_overload_info($rec,'section_title')?></td>
                           <td class="left"><?echo $this->show_overload_info($rec,'name')?></td>
                       </tr>
                     <?
                   }
              ?>
          </table>
       <?
   }

   function show_overload_info($rec,$fname)
   { $cur_value=$rec[$fname] ;
     $old_value=$rec['overload'][$fname] ;
     echo $cur_value ;
     if ($cur_value!=$old_value)
     {
         echo '<div style="color:gray">'.$old_value.'</div>' ;
     }

   }

   public function panel_info_db_small($arr_tables)
       {  if (_sizeof($arr_tables))
          {   $arr_names=array() ;
              foreach($arr_tables as $table_name=>$table_title) $arr_names[]='"'.$table_name.'"' ;
              $usl_tables=' and TABLE_NAME in ('.implode(',',$arr_names).')' ;
          }
          else $usl_tables='' ;
          $recs_table=execSQL('
          SELECT TABLE_NAME,TABLE_TYPE,ENGINE,TABLE_COLLATION, AUTO_INCREMENT, data_length, index_length, (data_length + index_length) "size",table_rows 
          FROM information_schema.TABLES 
          WHERE table_schema = "'.$GLOBALS['_SETTING']['main_db']['db_name'].'"
          '.$usl_tables);

          ?><table class="basic fz_small  auto full"><th>Назначение таблицы</th><th>Название таблицы</th><th>Тип</th><th>engine</th><th>Сопоставление</th><th>Счетчик</th><th>Размер данных</th><th>Размер индекса</th><th>Размер таблицы</th><th>Число строк</th><th>Дата первой записи</th><th>Дата последней записи</th><th>Средний размер одной записи	</th><?
          foreach($arr_tables as $table_name=>$table_title)
          {   $rec=$recs_table[$table_name] ;
              $data_stats=execSQL_van('select min(c_data) as t_from,max(c_data) as t_to from '.$rec['TABLE_NAME']) ;
              $dl=$rec['data_length'] ;
              $il=$rec['index_length'] ;
              $cnt=$rec['table_rows'] ;
              $row_size=($cnt)? show_size(round(($dl+$il)/$cnt)):''
              ?><tr>
                <td class="left"><?echo $table_title?></td>
                <td class="left"><a href="/window/db/table/[table_name=<?echo $rec['TABLE_NAME']?>]/" class="new_window" target="_blank"><?echo $rec['TABLE_NAME']?></a></td>
                <td class="left"><?echo $rec['TABLE_TYPE']?></td>
                <td class="left"><?echo $rec['ENGINE']?></td>
                <td class="left"><?echo $rec['TABLE_COLLATION']?></td>
                <td class="right"><?echo number_format($rec['AUTO_INCREMENT'],0,"."," ") ?></td>
                <td class="right"><?if ($rec['data_length']) echo show_size($rec['data_length'])?></td>
                <td class="right"><?if ($rec['index_length']) echo show_size($rec['index_length'])?></td>
                <td class="right"><?if ($rec['size']) echo show_size($rec['size'])?></td>
                <td class="right"><?if ($rec['table_rows']) echo number_format($rec['table_rows'],0,"."," "); else echo '0';?></td>
                <td class="right"><?if ($data_stats['t_from']) echo date('d.m.Y H:i:s',$data_stats['t_from'])?></td>
                <td class="right"><?if ($data_stats['t_to']) echo date('d.m.Y H:i:s',$data_stats['t_to'])?></td>
                <td class="right"><?echo  $row_size?></td>
             </tr><?
          }
           ?></table><?
   }
}



?>
