<?
include_once ('i_megamenu_form.php') ;
include_once (_DIR_TO_CLASS.'/c_page_cabinet.php') ;
class c_page_cab_theme extends c_page_cabinet
{

   public $block_main_class='sky-form no_box_shadow' ;

   function __construct($options=array())
   { parent::__construct($options);

     $this->color_set=($GLOBALS['LS_cab_color_set'])? $GLOBALS['LS_cab_color_set']:'bg-cyan' ;

   }

    function set_head_tags()
    {

        // sky-mega-menu + sky-forms-pro
        $this->HEAD['css'][]='/'._CLASS_.'/assets/mForm.css' ; //
        $this->HEAD['css'][]='/'._CLASS_.'/ext/megamenu/style.css' ; //
       $this->HEAD['css'][]=_PATH_TO_ADDONS.'/sky-mega-menu/version_1.2.1/css/demo.css' ;
       $this->HEAD['css'][]='/'._CLASS_.'/assets/sky-mega-menu.css' ;
       $this->HEAD['css'][]='/'._CLASS_.'/assets/sky-forms.css' ;

       $this->HEAD['css'][]='/images/open-sans/opensans_regular_cyrillic/stylesheet.css' ;
       $this->HEAD['css'][]='/images/open-sans/opensans_light_cyrillic/stylesheet.css' ;
       $this->HEAD['css'][]='/images/open-sans/opensans_bold_cyrillic/stylesheet.css' ;

        $this->HEAD['css'][]=_PATH_TO_EXT.'/interface/multiple-select/multiple-select.css' ;

        parent::set_head_tags() ;

        $this->HEAD['js'][]=_PATH_TO_EXT.'/interface/multiple-select/multiple-select.js' ;
     }

  function body_autorize()
  {
    ?><body class="x1 <?echo $this->color_set?> login_panel"><table id=wrapper class="login_panel"><tr><td><? $this->panel_autorize();?></td></tr></body><?
  }

  function body_work()
  { ?><body class="<?echo $this->color_set?> body_work <?echo $this->body_class?> <?echo $this->block_main_class?> <?echo _CUR_ROOT_DIR_NAME?>">
        <div class="body">
        <aside>
          <? $this->panel_WS_status() ;
             $this->panel_main_menu() ;
             if ($GLOBALS['LS_help_enabled']) $this->panel_help_content();
             $this->panel_block_before_menu();
             $this->panel_second_menu();
          ?>
        <table id="block_center">
             <tr><td id="center_left"><? $this->panel_block_main();
                                         $this->panel_block_second();
                                         $this->panel_block_debug();
                                      ?>
                 </td>
                 <td id="center_right"><?$this->panel_block_right(); ?></td>
             </tr>
        </table>
        </aside>
        </div>
        <div id="div_print"></div>
     </body>
    <script type="text/javascript">
      /*$j(document).ready(function(){ $j('body').everyTime(30000,'check_autorize',function(){$j.ajax({url:'/cab/ajax.php',type:'POST',dataType:'xml',success:exec_ajax_cmd_success_JQ,data:{cmd:'aspmo/check_autorize2'}});}) ;});*/
    </script>
    <?
  }
    /*
    function panel_main_menu_ul()
    {   ?><ul id="panel_main_menu" class="sky-mega-menu sky-mega-menu-pos-left  sky-mega-menu-fixed  sky-mega-menu-anim-scale"><?
            // логотип
            $this->panel_logo() ;
            // информация по текущему аккааунту
            $this->panel_main_menu_title() ;
            // текущее меню страницы
            if (_sizeof($this->menu)) foreach($this->menu as $url=>$item)  $this->panel_mega_menu_item($url,$item) ;
            // кнопка "закрыть страницу"
            if ($this->menu_show_close_item) $this->button_close_window() ;
        ?></ul><?
    }

    function panel_logo()
    {
        ?><li class="logo"><img src="<?echo _LOGO_CAB?>" width="150" class="v2" cmd="aspmo/reboot"></li><?
    }
      */
    /*function button_close_window()
    {
        ?><li><a href="" class="close_window"><i class="fa fa-home"></i>Закрыть</a></li><?
    }*/

    function panel_block_debug()
    { if ($GLOBALS['LS_debug_mode'])
      { ?><div id="block_debug">
          <?if (MEMBER()->rol==1){?>
            <div class="small">Адрес страницы: <?echo _CUR_PAGE_DIR?></div>
            <div class="small">Имя скрипта: <?echo hide_server_dir($this->script_file)?></div>
          <?}

          if (MEMBER()->info['debug_sql'])
          {  ?><div class="panel_sql_debug_info"><?
              $time=round($GLOBALS['__debug_sql_time'],4) ;
              echo '<br>Всего запросов:'.$GLOBALS['__debug_sql_cnt'].', время выполения: '.$time.'<br>' ;
              update_rating_sql_stats()  ;
              //print_2x_arr($GLOBALS['sql_stats'],['table_class'=>'full auto']) ;
              ?><table class="basic fz_small full auto">
                    <tr>
                        <th>№</th>
                        <th>Общее время</th>
                        <th>Время запроса</th>
                        <th>Время обработки</th>
                        <th>%</th>
                        <th>Число записей</th>
                        <!--<th>SQL</th>-->
                        <th></th>
                        <th>Параметры запроса</th>
                        <th>Источник</th>
                    </tr>
              <? if (_sizeof($GLOBALS['sql_stats'])) foreach($GLOBALS['sql_stats'] as $i=>$rec)
                  { ?><tr>
                        <td><?echo $i+1?></td>
                        <td class="left"><?echo $rec['time']?></td>
                        <td class="left"><?echo $rec['exec_sql']?></td>
                        <td class="left"><?echo $rec['work_sql']?></td>
                        <td><?echo $rec['%']?></td>
                        <td><?echo $rec['count']?></td>
                        <td class="left"><?echo $rec['sql']?></td>
                        <!--<td class="left"><i class="fas fa-bolt green v2" cmd="debug/exec_sql" sql="<?echo base64_encode($rec['sql'])?>"></i></i></td>-->
                        <td><?if (_sizeof($rec['options'])) damp_array($rec['options'],1,-1)?></td>
                        <td class="left"><?echo $rec['source']?></td>
                     </tr><?
                  }

              ?>

              </table></div><?
          }
        ?></div><?
      }
      ?><div class="clean"></div><?
    }

    function panel_mega_menu_item($url,$item,$options=array())
    {  if (!is_array($item))  $item=array('title'=>$item) ;
       if (is_int($url)) $url='' ;
       $arr_url=parse_url($url) ;
       $_li_class=[] ; $_li_attr=[] ;$_a_class=[] ; $_a_attr=[] ;
       $cur_dir=_CUR_PAGE_DIR._CUR_PAGE_NAME ;
       // сначала проверяем полное соответствие url с фильтром
       if ($arr_url['path']==$cur_dir)  $_li_class[]='current' ;
       // потом проверяем  соответствие url без фильтра
       if (_sizeof($this->filter)) $cur_dir=str_replace(_CUR_FILTER.'/','',$cur_dir) ; // подсвечивать пункт меню даже если установлены фильтры
       if ($arr_url['path']==$cur_dir)  $_li_class[]='current' ;
       if ($arr_url['path']==$this->selected_item_by_url)   $_li_class[]='current' ;
       if ($options['selected'])                            $_li_class[]='current' ;

       if (_sizeof($item['items']))  $_li_attr[]='aria-haspopup="true"' ;
       else                         $_li_attr[]='aria-haspopup="false"' ;
       if (_sizeof($_li_class))      $_li_attr[]='class="'.implode(' ',$_li_class).'"' ;



       $item_url=$url.$this->menu_url_params ;

       $_a_attr[]='href="'.$item_url.'"' ;
       $arr=explode('/',$item_url) ;
       unset($arr[_sizeof($arr)-1]) ;
       unset($arr[0]) ;
       $_a_attr[]='id="a_url_'.str_replace(['.','[',']'],['_','',''],implode('_',$arr)).'"' ;

       if (isset($item['open_in_window']) and $item['open_in_window']==1) $_a_attr[]='open_in_window=1' ;

       if ($item['no_link']) $_a_attr[]='nolink' ;
       if (_sizeof($item)) foreach($item as $name=>$value)
           if ($name!='class' and $name!='title' and $name!='info_id' and $name!='no_link' and $name!='items')
           { if ($name=='cmd')
             {   $_a_class[]='v2' ;
                 $_a_attr[]='cmd="'.$value.'"' ;
                 $_li_attr[]='id="'.str_replace('/','_',$value).'"' ;
             }
             elseif ($name=='new_window')
             {   $_a_class[]='new_window' ;
                 $_a_attr[]='title="'.$value.'"' ;
             }
             else $_a_attr[]=$name.'="'.$value.'"' ;
           }
       //damp_array($_a_attr);
       if (_sizeof($_a_class))      $_a_attr[]='class="'.implode(' ',$_a_class).'"' ;

       $li_attr=implode(' ',$_li_attr) ;
       $a_attr=implode(' ',$_a_attr) ;
       if ($item['class'] and !$options['no_icons']) $item['title']='<i class="'.$item['class'].'"></i>'.$item['title'] ;


       ?><li <?echo $li_attr?>>
         	<a <? echo $a_attr?>><? echo $item['title']?></a>
            <?if ($item['info_id'] or $item['info_value']){?><span class="info" id="<?echo $item['info_id']?>"><?echo $item['info_value']?></span><?}?>
            <?if (_sizeof($item['items'])){?><div class="grid-container4"><ul><?foreach($item['items'] as $url2=>$item2) $this->panel_mega_menu_item($url2,$item2);?></ul></div><?}?>
        </li>
      <?

    }

    function panel_main_menu_view()
    {    /*?><ul  id="panel_main_menu" class="sky-mega-menu sky-mega-menu-pos-left sky-mega-menu-response-to-icons sky-mega-menu-anim-scale"><?*/
         ?><ul id="panel_main_menu" class="sky-mega-menu sky-mega-menu-pos-left  sky-mega-menu-fixed  sky-mega-menu-anim-scale"><?
         if ($this->menu_show_logo_item)
         {?><li class="logo"><img src="<?echo _LOGO_CAB?>" width="130" class="v2" cmd="aspmo/reboot">
                <strong>Техподдержка</strong><a href="tel:88003509134">8 800 350-91-34</a>
            </li>
           <?
         }
         else $this->panel_page_left_title() ;
         // информация по текущему аккааунту
         $this->panel_main_menu_title() ;

         // текущее меню страницы
         if (_sizeof($this->menu)) foreach($this->menu as $url=>$item)  $this->panel_mega_menu_item($url,$item) ;

         // кнопка "закрыть страницу"
         if ($this->menu_show_close_item){?><li><a href="" class="close_window"><i class="fa fa-home"></i>Закрыть</a></li><?}
         ?></ul><?

     }

     function panel_page_left_title()
     {

     }

    // -----------------------------------------------------------------------------------
    // ДОПОЛНИТЕЛЬНОЕ МЕНЮ
    // -----------------------------------------------------------------------------------

    // формирование меню
    function panel_second_menu_view($menu_items=array())
    {   ?><ul id=panel_second_menu class="sky-mega-menu sky-mega-menu-response-to-icons sky-mega-menu-anim-scale"><?
        // текущее дополнительное меню страницы
        if (_sizeof($menu_items)) foreach($menu_items as $url=>$item)  $this->panel_mega_menu_item($url,$item,['no_icons'=>1]) ;
        ?></ul><div class=clear></div><?
    }

    function get_panel_second_menu_view($menu_items=array())
    { ob_start() ;
      $this->panel_second_menu_view($menu_items) ;
      $text=ob_get_clean() ;
      return($text) ;
    }




    function panel_autorize()
    { /*if ($GLOBALS['LS_auth_by_token'])
      { ?><SCRIPT type="text/javascript" src="/<?echo _CLASS_?>/ext/rutoken/script.js"></SCRIPT>
          <object type="application/x-rutoken-pki" id="plugin-object" width="0" height="0"><param name="onload" value="onPluginLoaded"/></object>
        <?
      } */
      if ($GLOBALS['LS_auth_by_pass'])
      {  include_once(_DIR_EXT.'/megamenu/panel_form_autorize.php') ;
         panel_form_autorize() ;
      }
    }





}

?>
