<?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 randomidiom_block_show($options,$thisvar){
global $xoopsDB, $xoTheme,$xoopsModule;	

$xoTheme->addStylesheet(XOOPS_URL.'/modules/neillibrary/js/relatedjs/css/style.css');	
	
$setting=neil_modulessetting($modulesid="neothemesadmin");	

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



}



//$img_date = date("H:i:s");
//$xoops_theme = $GLOBALS['xoopsConfig']['theme_set'];
$dbneme="neilrandomidiom";  //資料表名稱
$where="  where  `enable` = '1'  ".$order."   limit ".$options[1]."";		

foreach($Arr=databasetablewhile($dbneme,$where) as $key=> $val){
$Arr[$key]['content']=preg_replace( "#<li[^>]*>#i", "" , $Arr[$key]['content']);
}

$block['randomidiom']=$Arr;


if(check_mobile()){
$block['randomidiomwidth']=$options[5]; 
$block['randomidiomheight']=$options[6]; 
}else{
$block['randomidiomwidth']=$options[3];
$block['randomidiomheight']=$options[4]; 
}



   
   
   
    $block['timgplay']=$options[0];

    $block['bid']=$thisvar->getVar('bid');
    $block['menuadmin']=_MB_MENUADMINBUTTON;

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

   // return $block;
}

//區塊編輯函式
function randomidiom_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);
*/

//小語切換秒數
$blockvar['0']=inputtext($class="",$name="options[0]",$value="".$options[0]."",$placeholder="",$id="");	

//顯示顯示按鈕數量
$blockvar['1']=inputtext($class="",$name="options[1]",$value="".$options[1]."",$placeholder="",$id="");	
 
  	    
//排列方式
$blockvar['2']=radioinline($class="",$name="options[2]",$text=array(_MB_SHOWTHENUMBER3,_MB_SHOWTHENUMBER4,_MB_SHOWTHENUMBER5),$checked=$options[2]); 

  
//電腦版區塊寬度
$blockvar['3']=inputtext($class="",$name="options[3]",$value="".$options[3]."",$placeholder="",$id="");	 	

//電腦版區塊高度
$blockvar['4']=inputtext($class="",$name="options[4]",$value="".$options[4]."",$placeholder="",$id="");	 

//手機版區塊寬度
$blockvar['5']=inputtext($class="",$name="options[5]",$value="".$options[5]."",$placeholder="",$id="");	 	

//手機版區塊高度
$blockvar['6']=inputtext($class="",$name="options[6]",$value="".$options[6]."",$placeholder="",$id="");	 

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


    $form = "{$option['js']}
  <table  class='table'>
  <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS01. "
  </th><td>
".$blockvar['0']."
  </td></tr> 	  
  	  
  <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS02. "
  </th><td>
".$blockvar['1']."
  </td></tr>
   <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS03. "
  </th><td>
".$blockvar['2']."
  </td></tr>
  	  
   <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS04. "
  </th><td>
".$blockvar['3']."
  </td></tr>	  
  	 
  	 
  <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS05. "
  </th><td>
".$blockvar['4']."
  </td></tr>	  	 
 
   <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS08. "
  </th><td>
".$blockvar['5']."
  </td></tr>
 
   <tr><th>
  " . _MA_NEILRANDOMIDIOM_BLOCLS09. "
  </th><td>
".$blockvar['6']."
  </td></tr> 
  	   
  <tr>
  <th >"._MS_SHARED248."</th>
  <td> <div class='col-sm-12'>
  ".$blockvar['7']."	
   <br />
  </div></td>   
  </tr> 
  
  </table> 	  
  ";
    return $form;
}
