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


function neoblockmenubutton_block_show($options,$thisvar)
{
global $xoopsDB, $xoTheme,$xoopsModule;
  
$block['setting']=neil_modulessetting($modulesid="neothemesadmin");
	
$options[1]=explode(',', $options[1]);
$options[1]=$block['setting']['themefolder']=='computer' ? $options[1][0] : (empty($options[1][1]) ? $options[1][0] : $options[1][1]); //顯示內容數量
	

//分類觀看權限/啟用判斷
if(!empty(grouppermission($dbneme="neoblockmenusort",$where="  where `sortid` = '".$options[0]."' order by  sortid  ASC",$var="browsegroup",$type=true)) && empty(sorttruefunction($dbneme="neoblockmenusort",$of_sortid=$options[0],$sorting="sorting"))  ){
$listvar=moduledb($dbneme="neoblockmenusort",$where=" where `sortid` = '{$options[0]}'  &&  `enable` = '1'");
$group_perm=true;
}  

    
switch ($options[2]){	
case "0":  	  	 //最新
$order="order by  sortid  DESC";	
break; 
case "1":      //排序
$order="order by  sortidsort  ASC";	
break; 
case "2":      //隨機
$order="order by RAND()";
break; 

default:
$order="order by  sortid  DESC";	 	 
}

$order= $order." limit ".$options[1];
	
	
   $block['img_date'] = date("H:i:s");
   $block['listvar']=$listvar;
   $block['category'] = neothemesadmin_leftmenureturn($categoryid=$options[0], $sortid = "0", $dbneme = 'neoblockmenubutton', $sublayer = 0, $order);
   $block['radiogstyle']=$listvar['radiogstyle'];	
   $block['btntextyn']=$options[3];	
   $block['bid']=$thisvar->getVar('bid');
   $block['menuadmin']=_MB_MENUADMINBUTTON;
   $block['menusortid']=$options[0];  



  
   //分類觀看權限/啟用判斷
if(!empty($group_perm)){
  //  return $block;
  //顯示裝置判斷
foreach(explode(',', $options[4]) as  $val){
if($val=='1' && $block['setting']['themefolder']=='computer'){
return $block;
}
if($val=='2' && $block['setting']['themefolder']=='phone'){
return $block;
}
}
if(empty($options[4])){
return $block;
}    
    
    
    
    
    
 }    
 
 
 
  
}

//區塊編輯函式
function neoblockmenubutton_block_edit($options)
{
  global $xoopsDB, $xoTheme;
  
	
neillibrary_bootstrap3blockscss($typevar="3");	

/*  
//取得變數
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$bid=isset($_REQUEST['bid'])?$_REQUEST['bid']:"";
	
$bid=bidnamefunction($op=$op,$bid=$bid);
*/


$sortlist=moduledb($dbneme="neoblockmenusort",$where="  where  `sortid` = '".$options[0]."' ");

//選擇按鈕類型
$btntypeArr = array(); //建構陣列
$i=0;
$btntypeArr[$i]['value']='text';  //文字按鈕
$btntypeArr[$i]['title']=_MASLIDINGMENU05;
$btntypeArr[$i]['id']='text'; 
$i++;
$btntypeArr[$i]['value']='img';  //圖片按鈕
$btntypeArr[$i]['title']=_MASLIDINGMENU06;
$btntypeArr[$i]['id']='img'; 


//下拉選單
foreach($btntypeArr as $key=> $val){
$blockvar['1'].=optionselect($dataid=$btntypeArr[$key]['id'],$optionname=$btntypeArr[$key]['title'],$oid=$sortlist['radiogstyle'],$value=$btntypeArr[$key]['value'],$id="");
} 

$options[1]=explode(',', $options[1]);	
//顯示按鈕數量(電腦)
$blockvar['2']=inputtext($class="",$name="options[1][0]",$value="".$options[1][0]."",$placeholder="",$id="");
//顯示按鈕數量(手機)
$blockvar['5']=inputtext($class="",$name="options[1][1]",$value="".$options[1][1]."",$placeholder="",$id="");


//子選單排列方式 
$blockvar['3']=radioinline($class="",$name="options[2]",$text=array(_MB_SHOWTHENUMBER3,_MB_SHOWTHENUMBER4,_MB_SHOWTHENUMBER5),$checked=$options[2]); 

//按鈕顯示文字說明
$blockvar['4']=radioinline($class="",$name="options[3]",$text=array(_MS_SHARED131,_MS_SHARED130),$checked=$options[3]); 

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


    $form = "{$option['js']}
   <div class='alert alert-info' role='alert'>"._MASLIDINGMENU08."</div> 
  <table  class='table'>
  <tr><th style='width: 30%;'>
  " . _MB_CHOOSECATEGORY. "
  </th><td>
 <div class='row'>
  <div class='col-md-6'>	<select size='1'  name='btntype' id='btntype'  class='form-control' >
    <option value='0'  data-id='0' >"._MASLIDINGMENU07."</option>	  
".$blockvar['1']."											
	</select>
	<div id='sortidboxhidden'></div>  
	  </div>
  <div class='col-md-6'><div name='".$sortlist['radiogstyle'].",".$sortlist['sortid']."' id='sortidselectbox'></div></div>
</div> 	   
  	   


  </td></tr> 	  
  	  
  <tr><th>
  " . _MB_SHOWTHENUMBER.'-'._MS_SHARED257. "
  </th><td>
".$blockvar['2']."
  </td></tr>
 <tr><th>
  " . _MB_SHOWTHENUMBER.'-'._MS_SHARED258. "
  </th><td>
".$blockvar['5']."
  </td></tr>  
   <tr><th>
  " . _MB_SHOWTHENUMBER17. "
  </th><td>
".$blockvar['3']."
  </td></tr>
   <tr id='btntextyn'><th>
  " . _MB_SHOWTHENUMBER24. "
  </th><td>
".$blockvar['4']."
  </td></tr> 
   <tr ><th>
  " . _MS_SHARED248. "
  </th><td>
".$blockvar['6']."
  </td></tr> 
  	  
  </table>

<script>var xoopsjsurl='".XOOPS_URL."';</script> 
<script src='".XOOPS_URL."/modules/neothemesadmin/js/customize.js'></script>      
<script>custombuttonunction();custombuttonunctionAjax();</script>      
      	  
  ";
    return $form;
}
