<?php
include_once XOOPS_ROOT_PATH . "/modules/neothemesadmin/function.php";
include_once XOOPS_ROOT_PATH . "/modules/neothemesadmin/block_function.php";
include_once XOOPS_ROOT_PATH . "/modules/neillibrary/function/blocksfunction.php";	


function neoblockmenulayers_block_show($options,$thisvar){
global $xoopsDB, $xoTheme,$xoopsModule;


switch ($options[3]){	
case "0":  	  	 //最新
$order="order by  sortid  DESC";	
break; 
case "1":      //排序
$order="order by  sorting  ASC";	
break; 
 default:
$order="order by  sortid  DESC";	
}

switch ($options[4]){	
case "0":  	  	 //最新
$order2="order by  sortid  DESC";	
break; 
case "1":      //排序
$order2="order by  sortidsort  ASC";	
break; 
default:
$order2="order by  sortid  DESC";		
}

$order2= $order2." limit ".$options[0];


//空值顯示全部	
$category = array(); //建構第一層陣列
$sortidValues = explode(',', $options[2]);
$DBdata = !empty($options[2]) ? "where sortid IN (" . implode(',', $sortidValues) . ") &&" : 'where ';


// 取出sortid值按照排列
$dbneme = "neoblockmenusort";  // 主表名稱
$where = "  " . $DBdata . "  `radiogstyle` = 'text'  &&  `enable` = '1' " . $order . " limit " . $options[1] . "";  // where 條件
$category = array(); // 建立一個空的主選單數組

foreach ($topMenu = databasetablewhile($dbneme, $where) as $key => $val) {
    $topMenu[$key]['subMenu'] = neothemesadmin_leftmenureturn($topMenu[$key]['sortid'], $sortid = "0", $dbneme = 'neoblockmenubutton', $sublayer = 0, $order2);
    $category[] = $topMenu[$key]; // 將主選單加入數組
}


	

$block['category']=$category;
$block['menuadmin']=_MB_MENUADMINBUTTON;
$block['setting']=neil_modulessetting($modulesid="neothemesadmin");
//bid
$block['cat_id']=$thisvar->getVar('bid');  


  //顯示裝置判斷
foreach(explode(',', $options[5]) as  $val){
if($val=='1' && $block['setting']['themefolder']=='computer'){
return $block;
}
if($val=='2' && $block['setting']['themefolder']=='phone'){
return $block;
}
}
if(empty($options[5])){
return $block;
}

  //  return $block;
}


function neoblockmenulayers_block_edit($options){
	
	
neillibrary_bootstrap3blockscss($typevar="3");	
/*
//取得變數
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$bid=isset($_REQUEST['bid'])?$_REQUEST['bid']:"";
	
$bid=bidnamefunction($op=$op,$bid=$bid);
*/
	
 
	  	  
  	    
//顯示每個分類中子按鈕數量 
$blockvar['0']=inputtext($class="",$name="options[0]",$value="".$options[0]."",$placeholder="",$id="");	
//顯示按鈕群組總數量
$blockvar['1']=inputtext($class="",$name="options[1]",$value="".$options[1]."",$placeholder="",$id="");

$optionsval=cuttingfunction($cutting=$options[2],$sign=",");

$dbneme="neoblockmenusort";
$where="  where  `enable` = '1' &&  `radiogstyle` = 'text' order by  sorting  ASC";  //where數值 	
$sortoption=databasetablewhile($dbneme,$where);  
//下拉選單(分類)
foreach($sortoption as $key=> $val){


if(!empty($optionsval) && in_array($sortoption[$key]['sortid'], $optionsval)){  //單值-> 陣列
$oidvar[$key]=$sortoption[$key]['sortid'];
}

$blockvar['2'].=optionselect($dataid=$sortoption[$key]['sortid'],$optionname=$sortoption[$key]['sorttitle'],$oid=$oidvar[$key],$value=$sortoption[$key]['sortid'],$id="");
}  	  
//區塊選單排列方式
$blockvar['3']=radioinline($class="",$name="options[3]",$text=array(_MB_SHOWTHENUMBER3,_MB_SHOWTHENUMBER4),$checked=$options[3]); 
//子選單排列方式 
$blockvar['4']=radioinline($class="",$name="options[4]",$text=array(_MB_SHOWTHENUMBER3,_MB_SHOWTHENUMBER4),$checked=$options[4]); 

//顯示裝置
$blockvar['5']=neillibrary_displaydevice($oval=$options[5],$nameval="options[5][]");


	  	
$form = "{$option['js']}

  <table class='table'>
 <tr><th>
  " . _MB_SHOWTHENUMBER1. "
  </th><td>
".$blockvar['0']."
  </td></tr>  	  
  <tr><th>
  " . _MB_SHOWTHENUMBER2. "
  </th><td>
".$blockvar['1']."
  </td></tr>
  <tr><th>
  " . _MB_CHOOSECATEGORY2. "
  </th><td>
<select id='selectbox' name='options[2][]' multiple  >
    	".$blockvar['2']."   
  </select>	 
<div id='sortidboxhidden'></div>     	  
  </td></tr> 	
  <tr><th>
  " . _MB_SHOWTHENUMBER16. "
  </th><td>
".$blockvar['3']."
  </td></tr>  	  
   <tr><th>
  " . _MB_SHOWTHENUMBER17. "
  </th><td>
".$blockvar['4']."
  </td></tr> 
   <tr ><th>
  " . _MS_SHARED248. "
  </th><td>
".$blockvar['5']."
  </td></tr> 
  	  
  	    	  
  </table>
<script src='" . XOOPS_URL . "/modules/neothemesadmin/js/customize.js'></script>
<script>menulayers_emptyfield();</script>	 	   	      	  
";


  
  
    return $form;
}
