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


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

//分類觀看權限/啟用判斷
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;
  }   
    
}

//區塊編輯函式
function neoblockmenubutton_block_edit($options)
{
  global $xoopsDB, $xoTheme;
  
//模組區塊載入bootstrap3	
neillibrary_bootstrap3blockscss();	

/*  
//取得變數
$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){
$options_table_form['1'].=optionselect($dataid=$btntypeArr[$key]['id'],$optionname=$btntypeArr[$key]['title'],$oid=$sortlist['radiogstyle'],$value=$btntypeArr[$key]['value'],$id="");
} 
  	
//顯示按鈕數量(電腦)
$options_table_form['2']=inputtext($class="",$name="options[1]",$value="".$options[1]."",$placeholder="",$id="");

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

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

//顯示按鈕數量(手機)
$options_table_form['5']=inputtext($class="",$name="options[4]",$value="".$options[4]."",$placeholder="",$id="");


    $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>	  
".$options_table_form['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>
".$options_table_form['2']."
  </td></tr>
 
   <tr><th>
  " . _MB_SHOWTHENUMBER17. "
  </th><td>
".$options_table_form['3']."
  </td></tr>
   <tr id='btntextyn'><th>
  " . _MB_SHOWTHENUMBER24. "
  </th><td>
".$options_table_form['4']."
  </td></tr> 
 <tr><th>
  " . _MB_SHOWTHENUMBER.'-'._MS_SHARED258. "
  </th><td>
".$options_table_form['5']."
  </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;
}
