<?php
include_once XOOPS_ROOT_PATH . "/modules/neothemesadmin/function.php";
include_once XOOPS_ROOT_PATH . "/modules/neothemesadmin/block_function.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');  




    return $block;
}


function neoblockmenulayers_block_edit($options){
	
//模組區塊載入bootstrap3	
neillibrary_bootstrap3blockscss();	
/*
//取得變數
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$bid=isset($_REQUEST['bid'])?$_REQUEST['bid']:"";
	
$bid=bidnamefunction($op=$op,$bid=$bid);
*/
	
 
	  	  
  	    
//顯示每個分類中子按鈕數量 
$options_table_form['0']=inputtext($class="",$name="options[0]",$value="".$options[0]."",$placeholder="",$id="");	
//顯示按鈕群組總數量
$options_table_form['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'];
}

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

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

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


  
  
    return $form;
}
