<?php
if(!empty($_FILES['upfile']['name']['0'])) $_FILES['upfile']['name']['0']=strtotime(date("Y-m-d H:i:s")).'.'.substr(strrchr($_FILES['upfile']['name']['0'], '.'), 1);	//重編檔名防止被防護模組阻擋	

include_once 'header.php'; //XOOPS檔頭
include_once "../function.php";	
include_once "../class/themeset.php";

//上傳圖檔
include_once XOOPS_ROOT_PATH."/modules/neillibrary/class/imguploader.php";	


$op=(empty($_REQUEST['op']))?"":$_REQUEST['op'];


if(!empty($_REQUEST['categoryid'])){
$categoryid=(empty($_REQUEST['categoryid']))?"":$_REQUEST['categoryid'];
$sortid=(empty($_REQUEST['sortid']))?"":$_REQUEST['sortid'];
}else{	
$categoryid=(empty($_REQUEST['sortid']))?"":$_REQUEST['sortid'];
}


$status=isset($_REQUEST['status'])?$_REQUEST['status']:"";
$i=isset($_REQUEST['i'])?$_REQUEST['i']:"";
$sortvar=isset($_REQUEST['sortvar'])?$_REQUEST['sortvar']:"";
$url=isset($_REQUEST['url'])?$_REQUEST['url']:"";


//先建構class($themesetclass)
$themesetclass   = new  themesetclass;  
$topvsplit =$themesetclass-> themespublicb($variableok,$setting); 
list($variableok,$setting) = $topvsplit;

//切割$setting陣列內容
$variablesplit=cuttingfunction($cutting=$variableok,$sign=";"); 
$xoops_theme = $GLOBALS['xoopsConfig']['theme_set'];


$radiogstyle=(empty($_REQUEST['radiogstyle']))?"":$_REQUEST['radiogstyle'];
$pagrtype=(empty($_REQUEST['pagrtype']))?"":$_REQUEST['pagrtype'];
$blocktitle=(empty($_REQUEST['blocktitle']))?"":$_REQUEST['blocktitle'];



//取得模組mid值 
$mid=modulesmidvar($modulesid="neothemesadmin");







switch ($op){
 case "jointhelink":   



switch($pagrtype){
  case "1":
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/menutable.php?url=".$url."&blocktitle=".urlencode($blocktitle)."" ,0 , "");  
  break;
  
  case "2":  
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=".$sortvar."&url=".$url."&blocktitle=".urlencode($blocktitle)."" ,0 , "");  
   break; 	 
   
  case "3":  
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/playeradmin.php?url=".$url."&blocktitle=".urlencode($blocktitle)."" ,0 , "");  
  break; 
  	  
  case "4":  
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/advertise.php?op=advertise2&menutype=2&url=".$url."&blocktitle=".urlencode($blocktitle)."" ,0 , "");  
  break; 
}
 
 	 
 	 

break;
	
	
	
 case "save_news":   //新增分類
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);   //空值判斷 	 
	 
redirect_header($_SERVER['PHP_SELF'].save_news(),0 , _MA_BLOCKMENUSORTPHP22);   
break;

   case "changelist":

$urlstring=changelist();   
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=default".$urlstring."" ,0 , _MS_SHARED02);   

  break;   
  
  case "updated":   //編輯分類
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'].'?sortid='.$categoryid.'',0 , _MS_SHARED90);   //空值判斷 	 

 
 redirect_header($_SERVER['PHP_SELF'].updated(),0 , _MS_SHARED02);   
break; 

  case "textfunction": 
$mainvar=blockmenusort();   
$main=textfunction($mainvar=$mainvar['DB']);
break; 

   case "textfunctioninsert": //新增文字按鈕
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'].'?op=textfunction&categoryid='.$categoryid.'',0 , _MS_SHARED90);   //空值判斷 	  	   
$categoryid=textfunctioninsert();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);  
  break;   

   case "textfunctionpdate": //編輯文字按鈕
if(!empty($i)) $ivar='&i='.$i.'';  	   
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'].'?op=textfunction&categoryid='.$categoryid.'&sortid='.$sortid.'&status=edit'.$ivar ,0 , _MS_SHARED90);   //空值判斷 	   	   
$categoryid=textfunctionpdate();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);  
  break;   

  case "sortidsortupdate":  	  
$categoryid=sortidsortupdate(); 
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);    
  break; 
  
  case "imgfunction": 
$mainvar=blockmenusort();   
$main=imgfunction($mainvar=$mainvar['DB']);
break; 
 
   case "imgfunctionsave_news": //新增圖片
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'].'?op=imgfunction&categoryid='.$categoryid.'',0 , _MS_SHARED90);   //空值判斷 	      
	     	   
$categoryid=imgfunctionsave_news();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=imgfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);  
  break;  

   case "imgfunctionchangelist":

$categoryid=sortidsortupdate();   
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=imgfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);     
  break;

   case "imgfunctionupdated":  //編輯圖片
if(empty($_POST['sorttitle']))   redirect_header($_SERVER['PHP_SELF'].'?op=imgfunction&categoryid='.$categoryid.'&sortid='.$sortid.'' ,0 , _MS_SHARED90);   //空值判斷 	   	   
	   
$categoryid=imgfunctionupdated();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=imgfunction&categoryid=".$categoryid."" ,0 , _MS_SHARED02);  
  break;  


 default:
$mainvar=blockmenusort(); 
$main=$mainvar['table']; 
}


//分類選單function
function classificationmenu($categoryid="",$sortid="",$type="",$xoops_theme=""){


$dbneme="neoblockmenusort";

if(empty($type)){
$where="  where  `enable` = '1' order by  sorting  ASC";  //where數值 
}else{
$where="  where  `enable` = '1' &&  `radiogstyle` = '".$type."' order by  sorting  ASC";  //where數值 
}	

$sortoption=databasetablewhile($dbneme,$where);  
//下拉選單(分類)
foreach($sortoption as $key=> $val){
if(empty($type)){	
$url[$key]=$sortoption[$key]['radiogstyle']=='text' ? "?op=textfunction&categoryid=".$sortoption[$key]['sortid']."" : "?op=imgfunction&categoryid=".$sortoption[$key]['sortid'].""; // get TRUE
}else{
$url[$key]=$sortoption[$key]['sortid']; // get TRUE
}	
$menu.=optionselect($dataid=$sortoption[$key]['sortid'],$optionname=$sortoption[$key]['sorttitle'],$oid=$categoryid,$value=$url[$key]);
}
  return $menu;

}


//區塊管理子項目-圖片按鈕管理
function imgfunction($mainvar=""){
 global $xoopsDB,$xoopsModule,$sortid,$mid,$categoryid,$variablesplit,$xoops_theme,$url,$blocktitle,$variablesplit;



//開啟neoblockmenusort資料表
$menusortlist=moduledb($dbneme="neoblockmenusort",$where="  where `sortid` = '".$categoryid."'");
//圖檔尺寸
if(empty($menusortlist['boxwidth'])) $menusortlist['boxwidth']=$variablesplit[14]; 
$imgsizetext=sprintf(_MA_BLOCKMENUSORTPHP52,$menusortlist['boxwidth']);


//判斷傳入值
if(!empty($url)) $listvar['url']=base64_decode($url);
if(!empty($blocktitle)) $listvar['sorttitle']=$blocktitle;

$img_date = date("H:i:s");
if(empty($sortid)){  //新增
$imgfunction_table_form['7']="<h3>"._MA_BLOCKMENUSORTPHP44."</h3>";
//POST類型
$imgfunction_table_form['9']="<input type='hidden' name='categoryid' value='".$categoryid."'><input type='hidden' name='op' value='imgfunctionsave_news'>";
$listvar['enable']=1;
$listvar['target']=0;
//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  


}else{  //編輯
$imgfunction_table_form['7']="<h3>"._MA_BLOCKMENUSORTPHP45."</h3>";

//開啟neothemesflash資料表
$dbneme="neoblockmenubutton";
$where="  where `sortid` = '".$sortid."'";  //where數值
//$listvar=moduledb($dbneme,$where);

//批次轉換htmlspecialchars
$listvar=htmlspecialcharsbatch($allowvar=array("sorttitle","url"),$eachvar=moduledb($dbneme,$where));

if(empty($listvar['browsegroup'])){
//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  
}



//檔名
$imgid=$listvar['buttonimg'];

//已上傳圖片
$imgfunction_table_form['8']="<div class='form-group'>
	 <div class='col-sm-12'> 
		 	    <div class='text-center'> <h4><span id='helpBlock' class='help-block'>"._MA_PLAYERADMINPHP12."</span></h4> </div> 	
  <div class='row'>
    <div class='thumbnail'>   
        <img src='".XOOPS_URL."/uploads/".$xoopsModule->getVar("dirname")."/".$imgid.".png?state=".$img_date."' >
     </div></div>
	
   
  
		 <br /></div> 
</div>";

//分類選單
$imgfunction_table_form['11']="
	<div class='form-group' >
<label class='col-sm-3'>"._MA_BLOCKMENUSORTPHP47."</label>	
	 <div class='col-sm-9'><select name='categoryid' id='categoryid' class='form-control' >
    <option value=''  data-id='1' >"._MA_BLOCKMENUSORTPHP48."</option>
    	".classificationmenu($categoryid,$sortid,$type="img",$xoops_theme)."   
  </select>	 
  	<br /></div> 
</div>"; 

//POST類型
$imgfunction_table_form['9']="<input type='hidden' name='op' value='imgfunctionupdated'><input type='hidden' name='sortid' value='".$listvar['sortid']."'>";
}

//類型
$radiogstyletext= $mainvar['radiogstyle']=='text' ? _MA_BLOCKMENUSORTPHP06 : _MA_BLOCKMENUSORTPHP07; // get TRUE
//圖片標題
$imgfunction_table_form['0']=inputtext($class="",$name="sorttitle",$value="".$listvar['sorttitle']."",$placeholder=""._MD_CONTACTENTER.""._MA_PLAYERADMINPHP03."",$id="");	

//圖片連結
$imgfunction_table_form['1']=inputtext($class="",$name="url",$value="".$listvar['url']."",$placeholder=""._MD_CONTACTENTER.""._MA_PLAYERADMINPHP04."",$id="");	

//圖片開啟方式
$imgfunction_table_form['2']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$listvar['target'].""); 

//上傳圖檔
$imgfunction_table_form['3']=typefile($multiple=false,$name="upfile[]",$id="blockimg",$class=""); 

//是否啟用
$imgfunction_table_form['4']=radioinline($class="",$name="enable",$text=array(_MS_SHARED04,_MS_SHARED03),$checked="".$listvar['enable'].""); 
 
//分類選單
$imgfunction_table_form['10']=classificationmenu($categoryid,$sortid,$type="",$xoops_theme); 




//可觀看群組
$groupsArr=neillibrary_permissionmenu($types='2',$admingroup="",$browsegroup=$listvar['browsegroup'],$groupArr);

//可觀看群組
$imgfunction_table_form['12']=$groupsArr[2];



//TABLE區塊
$dbneme="neoblockmenubutton";
$where=" where `categoryid` = '".$categoryid."'  order by  sortidsort  ASC"; 
$buttonArr=databasetablewhile($dbneme,$where);  
foreach($buttonArr as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="sortidsort{$buttonArr[$key]['sortid']}",$value="".$buttonArr[$key]['sortidsort']."",$placeholder="".$buttonArr[$key]['sortidsort']."");


//圖片
$td['img']="<div  class='thumbnail'><img title='".$buttonArr[$key]['sorttitle']."' src='".XOOPS_URL."/uploads/".$xoopsModule->getVar("dirname")."/".$buttonArr[$key]['buttonimg'].".png?state=".$img_date."'></div>";
//狀態

$td['enable']=enable($envar=$buttonArr[$key]['enable']);

//頁面開啟方式
$td['target']=pagemethod($types=$buttonArr[$key]['target']);

if($buttonArr[$key]['sortid']==$sortid){
$colorstyle[$key]="class='color1'";
}
$titlebox[$key]=!empty($buttonArr[$key]['url']) ? "<a class='black' target='_blank' href=".$buttonArr[$key]['url'].">".$buttonArr[$key]['sorttitle']."</a>" : $buttonArr[$key]['sorttitle']; // get TRUE

	
$imgfunction_table_form['6'].="<tr id='deletetr{$key}' ".$colorstyle[$key].">
        <td>".$td['nnumber']."</td>
        <td>".$td['img']."</td>
        <td>".$titlebox[$key]."</td>
        <td>".groupslabel($Arr=phpconversion($conversion=$buttonArr[$key]['browsegroup'],$type="unserialize"),$type="",$style="label-danger")."</td>        	
       <td>".$td['target']['text']."</td>
        <td>".$td['enable']."</td>
        <td>  <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=imgfunction&categoryid=".$buttonArr[$key]['categoryid']."&sortid=".$buttonArr[$key]['sortid']."'  class='btn btn-sm btn-info btn-xs active'>"._MS_SHARED08."</a>   
     <a id='deletebotton{$key}' type='button'  mane='87,".$buttonArr[$key]['sortid'].",".$buttonArr[$key]['sorttitle'].","._MA_PLAYERADMINPHP10."'  class='btn btn-sm btn-danger btn-xs active deleteeach'>"._MS_SHARED09."</a></td>
      </tr>";
}

 
$imgfunction_table_form['5']="
<table class='table basictable'>
    <thead>
      <tr>
      
        <th style='width: 10%'>"._MA_MARQUEETABLEPHP07."</th>
        <th style='width: 24%'>"._MA_PLAYERADMINPHP09."</th>
          <th style='width: 18%'>"._MA_MENUTABLEPHP10."</th> 
          <th style='width: 7%'>"._MS_SHARED94."</th> 
           <th style='width: 14%'>"._MS_SHARED43."</th>
            

               <th style='width: 12%'>"._MS_SHARED10."</th>  
                 <th style='width: 16%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$imgfunction_table_form['6']."
     
    </tbody>
  </table>
";
 
$main.="<div class='container'>
<h4>".sprintf(_MA_BLOCKMENUSORTPHP23,$mainvar['sorttitle'])."&nbsp;<label for='sel2'>project admin</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=imgfunction&categoryid=".$mainvar['sortid']."'>"._MS_SHARED25."</a>&nbsp; <a class='btn btn-primary active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php'>"._MA_BLOCKMENUSORTPHP24."</a>&nbsp; <a class='btn btn-info active'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".$mid."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a>  </h4>	


	
<div class='row'>   
  	   <div class='col-md-2'>
  	   	<select id='FriendLink' class='form-control' >
    <option value=''  data-id='1' >"._MA_BLOCKMENUSORTPHP27."</option>
    	".$imgfunction_table_form['10']."   
  </select>	
  	  </div>
  	   <div class='col-md-10'>
  	<span><span class='red'>".sprintf(_MA_BLOCKMENUSORTPHP26,$radiogstyletext)."</span>"._MA_BLOCKMENUSORTPHP25."</span></div>
  	  	  
  	  	  </div>	
    <div class='row'>
    ";
//左邊區塊
$main.="
<form method='post'  action='{$_SERVER['PHP_SELF']}' enctype='multipart/form-data'>	
  <div class='col-md-5'>".$imgfunction_table_form['7']."<hr />
 
 ".$imgfunction_table_form['11']."
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP03."</label>
 		 <div class='col-sm-9'> ".$imgfunction_table_form['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP04."</label>
 		 <div class='col-sm-9'> ".$imgfunction_table_form['1']." 
  	   <br /></div> 
 	 <hr />	</div> 	

<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP05."</label>
 		 <div class='col-sm-9'> ".$imgfunction_table_form['2']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	

 
  <div class='form-group'>
    <label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP02."</label>   
     <div class='col-sm-9'>
    ".$imgfunction_table_form['3']." <span id='helpBlock' class='help-block'>".$imgsizetext."</span>
     <div class='preview'></div>  
  
           </div> </div>
  <hr /> 
  			   
 ".$imgfunction_table_form['8']." 			   	  
  
  
<div class='form-group'>
<label class='col-sm-3 control-label'>"._MS_SHARED91."</label>	
	 <div class='col-sm-9'>
	<select  class='form-control' id='sel1'  name='browsegroup[]' multiple  >
    	".$imgfunction_table_form['12']."   
  </select>		  
  	<br />
  <span id='helpBlock' class='help-block'>"._MS_SHARED92."</span>
  	</div> 
</div> 
	  
  	  
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP06."</label>
 		 <div class='col-sm-9'> ".$imgfunction_table_form['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
  	  
 
  ".$imgfunction_table_form['9']."	

 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
  	  
  	  </div>
   </form> <br />	  
  	  
    ";
//右邊區塊
$main.="
  <form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-7'><h3>"._MA_BLOCKMENUSORTPHP46."</h3><hr />
  	  ".$imgfunction_table_form['5']."
  	  

  	   <input type='hidden' name='categoryid' value='".$categoryid."'>	
  	    <button  type='submit' name='op' value='imgfunctionchangelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
    
  
    	  </div>
  	  	  
  	     </form> 
  	     	 
    ";
$main.="
</div>
<script src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></script>	 	
  <script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 	
<script>previewfunction();</script>		
	";
 
 
	
	


 
  return $main;
}


//區塊管理子項目-文字按鈕管理
function textfunction($mainvar=""){
 global $xoopsDB,$xoopsModule,$sortid,$status,$i,$mid,$categoryid,$url,$blocktitle;



//判斷傳入值
if(!empty($url)) $sortlimit['url']=base64_decode($url);
if(!empty($blocktitle)) $sortlimit['sorttitle']=$blocktitle;

if(!empty($sortid)){ //編輯設定
//讀取neoblockmenubutton資料表
//引入模組DB函數-初始化設定
$dbneme="neoblockmenubutton";
$where=" where `sortid` = '".$sortid."'";
//$sortlimit=moduledb($dbneme,$where);
//批次轉換htmlspecialchars
$sortlimit=htmlspecialcharsbatch($allowvar=array("sorttitle","url","variableid"),$eachvar=moduledb($dbneme,$where));


$buttonvar="textfunctionpdate";
$hidden="<input type='hidden' name='sortid' value='".$sortid."'><input type='hidden' name='i' value='".$i."'>"; 
$sorttitletext=_MA_BLOCKMENUSORTPHP29;
//取得上層捲單數值
//$sortidnamedefault=$sortid;
$sortmemu['1']="<h3>"._MA_MENUTABLEPHP05."</h3>";
$sortidboxvar=$sortid;

if(empty($sortlimit['typesof'])){
$radiogstylenontop="style='display: none;'";
$radiogstylenone="style='display: none;'";
}


if(empty($sortlimit['browsegroup'])){
//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  
}



//分類選單
$textfunction['5']="
	<div class='form-group' >
<label class='col-sm-4'>"._MA_BLOCKMENUSORTPHP27."</label>	
	 <div class='col-sm-8'><select name='categoryid' id='categoryid' class='form-control' >
    <option value='1'  data-id='1' >"._MA_BLOCKMENUSORTPHP27."</option>
    	".classificationmenu($categoryid,$sortid,$type="text",$xoops_theme)."   
  </select>	 
  	<br /></div> 
</div>"; 

}else{ //新增設定
$buttonvar="textfunctioninsert";	
$sortlimit['enable']=1;
$sortlimit['target']=0;
$sorttitletext=_MA_BLOCKMENUSORTPHP28;
$sortmemu['1']="<h3>"._MA_MENUTABLEPHP04."</h3>";
$radiogstylenone="style='display: none;'";
$radiogstylenontop="style='display: none;'";
$hidden="<input type='hidden' name='categoryid' value='".$categoryid."'>"; 

//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  
}  


//分類選單
$textfunction['0']=classificationmenu($categoryid,$sortid,$type="",$xoops_theme);


//可觀看群組
$groupsArr=neillibrary_permissionmenu($types='2',$admingroup="",$browsegroup=$sortlimit['browsegroup'],$groupArr);

//可觀看群組
$textfunction['6']=$groupsArr[2];






//讀取neoblockmenubutton資料表 
//取出sortid值按照排列
$dbneme="neoblockmenubutton";  //資料表名稱
$where="  where `of_sortid` = '0' && `categoryid` = '".$categoryid."'  order by  sortidsort  ASC";  //where數值
$sort=databasetablewhile($dbneme,$where); 


//編輯下拉選單取值
//第一層
$where="  where `sortid` = '".$sortid."'  order by  of_sortid  DESC";  //where數值
$sortselect=moduledb($dbneme,$where);
$sortselectbox.=$sortselect['sortid'].",";


//讀取function.php中sortselect(函數)
if(!empty($sortselect['of_sortid'])){
$sortselectbox.=tplsortselect($dbneme,$sortid="".$sortselect['of_sortid']."");
}

//去除最後一個字元
$sortselectbox=substr($sortselectbox,0,-1);
//切割陣列
//$ofsortid=preg_split('/,/',$sortselectbox);

$ofsortid=cuttingfunction($cutting=$sortselectbox,$sign=",");



//反轉陣列順序
$ofsortid=array_reverse($ofsortid);
	
	

//第一層
//$selectmenu1=$ofsortid[0];
//第二層
//$selectmenu2=$ofsortid[1];
//第三層
//$selectmenu3=$ofsortid[2];
//第四層
//$selectmenu4=$ofsortid[3];


 
//下拉選單設定
$where="  where `of_sortid` = '0' && `categoryid` = '".$categoryid."'  order by  sortidsort  ASC";  //where數值 
$sortoption=databasetablewhile($dbneme,$where);  

//遞回開始
function sortidretorted($dbneme="",$sortid="",$i=""){ 
$where=" where `of_sortid` = '".$sortid."' order by sortidsort ASC";   //where數值
$sortArr=databasetablewhile($dbneme,$where);
empty($i) ? $i=1 : '';  
foreach($sortArr as $key=> $val){
$sortidvar.=$sortArr[$key]['sortid'].",";
if($i<1){ //限制迴圈階層數3層	 
$sortidvar.=sortidretorted($dbneme,$sortid="".$sortArr[$key]['sortid']."",$i+1);
}
}
return $sortidvar;
}

foreach($sort as $key=> $val){
$sortidvar.=$sort[$key]['sortid'].","; 
$sortidvar.=sortidretorted($dbneme,$sortid="".$sort[$key]['sortid']."");

} 
 
$sortidvar=substr($sortidvar,0,-1);
 
 


//遞回開始
function retorted($dbneme="",$sortid="",$i="",$sortidboxvar="",$boxtopid=""){
 global $xoopsModule;	
$where="  where `of_sortid` = '".$sortid."' order by  sortidsort  ASC";	
$sortArr=databasetablewhile($dbneme,$where);




empty($i) ? $i=1 : '';  
$arrowspan="<span class='glyphicon glyphicon-arrow-right' aria-hidden=".true."></span> ";
switch($i){
  case "1":
$arrow=$arrowspan;
$stylebox='color2';    
  break;	
  case "2":
$arrow=$arrowspan.$arrowspan;
$stylebox='color3';     
  break;
  case "3":
$arrow=$arrowspan.$arrowspan.$arrowspan;
$stylebox='color4';   
  break;  
  default:
}




foreach($sortArr as $key=> $val){
	
//頁面開啟方式
$td['target']=pagemethod($types=$sortArr[$key]['target']);	
//排序
$sortidsort=inputtext($class="",$name="sortidsort{$sortArr[$key]['sortid']}",$value="".$sortArr[$key]['sortidsort']."",$placeholder="".$sortArr[$key]['sortidsort']."");
  	
$enableforeach=enable($envar=$sortArr[$key]['enable']);


if($sortArr[$key]['sortid']==$sortidboxvar){
$colorstyle2[$key]="class='color1'";
}else{
$colorstyle2[$key]="class='".$stylebox." ".$boxtopid."'";
}

$typesof[$key]=empty($sortArr[$key]['typesof']) ? _MA_BLOCKMENUSORTPHP32 : _MA_BLOCKMENUSORTPHP31; // get TRUE

$titlebox[$key]=!empty($sortArr[$key]['url']) ? "<a class='black' target='_blank' href=".$sortArr[$key]['url'].">".$sortArr[$key]['sorttitle']."</a>" : $sortArr[$key]['sorttitle']; // get TRUE


$sortvar.="<tr id='deletetr{$sortArr[$key]['sortid']}' ".$colorstyle2[$key].">
<td class='".$boxtopid."'>".$sortidsort."</td>
<td class='".$boxtopid."'>".$arrow."".$titlebox[$key]."</td>
<td class='".$boxtopid."'>".groupslabel($Arr=phpconversion($conversion=$sortArr[$key]['browsegroup'],$type="unserialize"),$type="",$style="label-danger")."</td>
<td class='".$boxtopid."'>".$typesof[$key]."</td>		
<td class='".$boxtopid."'>".$enableforeach."</td>	
<td class='".$boxtopid."'>".$td['target']['text']."</td>		
  <td class='".$boxtopid."'>
       <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$sortArr[$key]['categoryid']."&sortid=".$sortArr[$key]['sortid']."&status=edit&i=".$i."' class='btn  btn-warning btn-xs active'>"._MS_SHARED08."</a>  
       <a id='deletebotton{$sortArr[$key]['sortid']}'  type='button'   mane='86,".$sortArr[$key]['sortid'].",".$sortArr[$key]['sorttitle'].","._MA_MENUTABLEPHP12."' class='btn  btn-danger btn-xs active deleteeachArr'>"._MS_SHARED09."</a>  
    </td>	
</tr>
	
	";
if($i<1){ //限制迴圈階層數1層	 
$sortvar.=retorted($dbneme,$sortid="".$sortArr[$key]['sortid']."",$i+1,$sortidboxvar=$sortidboxvar,$boxtopid=$boxtopid);
}

}

return $sortvar;
}

//第一層迴圈
foreach($sort as $key=> $val){



//頁面開啟方式
$td['target']=pagemethod($types=$sort[$key]['target']);		
//排序
$sortidsort=inputtext($class="",$name="sortidsort{$sort[$key]['sortid']}",$value="".$sort[$key]['sortidsort']."",$placeholder="".$sort[$key]['sortidsort']."");

if($sort[$key]['sortid']==$sortidboxvar){
$colorstyle[$key]="color1";
}else{
$colorstyle[$key]="levelone";
}

$boxtopid="box".$key."";	
$boxtopid2="boxbutton".$key."";	


	








//判斷子層
$dbneme="neoblockmenubutton";  //資料表名稱
$where="  where `of_sortid` = '".$sort[$key]['sortid']."'  order by  of_sortid  DESC";  //where數值
$listvar=moduledb($dbneme,$where);

if(!empty($listvar)){
$blockbtn="&nbsp;<a type='button' class='".$boxtopid2." btn btn-info btn-xs boxbuteach'>"._MS_SHARED46."</a>";
}else{
$blockbtn="&nbsp;<p class='boxbuteach'>";
}
	
$enableforeach=enable($envar=$sort[$key]['enable']);	

$typesof[$key]=empty($sort[$key]['typesof']) ? _MA_BLOCKMENUSORTPHP32 : _MA_BLOCKMENUSORTPHP31; // get TRUE

$titlebox[$key]=!empty($sort[$key]['url']) ? "<a class='black' target='_blank' href=".$sort[$key]['url'].">".$sort[$key]['sorttitle']."</a>" : $sort[$key]['sorttitle']; // get TRUE


$sortvar.="<tr id='deletetr{$sort[$key]['sortid']}' class=".$colorstyle[$key].">
<td>".$sortidsort."</td>	
<td><span class='glyphicon glyphicon-option-horizontal' aria-hidden='true'></span>&nbsp;".$titlebox[$key]."".$blockbtn."</td>
<td>".groupslabel($Arr=phpconversion($conversion=$sort[$key]['browsegroup'],$type="unserialize"),$type="",$style="label-danger")."</td>		
<td>".$typesof[$key]."</td>		
<td>".$enableforeach."</td>	
<td>".$td['target']['text']."</td>		
  <td>
       <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$sort[$key]['categoryid']."&sortid=".$sort[$key]['sortid']."&status=edit' class='btn  btn-warning btn-xs active'>"._MS_SHARED08."</a>  
       <a id='deletebotton{$sort[$key]['sortid']}'  type='button' mane='86,".$sort[$key]['sortid'].",".$sort[$key]['sorttitle'].","._MA_MENUTABLEPHP12."' class='btn  btn-danger btn-xs active deleteeachArr'>"._MS_SHARED09."</a>  
    </td>	
</tr>";	

$sortvar.=retorted($dbneme,$sortid="".$sort[$key]['sortid']."",$i="",$sortidboxvar=$sortidboxvar,$boxtopid=$boxtopid);

}




 
//下拉選單
foreach($sortoption as $key=> $val){
$optionone.=optionselect($dataid=$sortoption[$key]['sortid'],$optionname=$sortoption[$key]['sorttitle'],$oid="".$sortlimit['of_sortid']."",$value=$sortoption[$key]['sortid']);
}
//分類名稱
$sorttitle=inputtext($class="",$name="sorttitle",$value="".$sortlimit['sorttitle']."",$placeholder="".$sortlimit['sorttitle'].""); 

//狀態
$enable=radioinline($class="",$name="enable",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$sortlimit['enable']); 
//按鈕連結
$url=inputtext($class="",$name="url",$value="".$sortlimit['url']."",$placeholder="".$sortlimit['url'].""); 
//按鈕連結開啟方式
$target=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$sortlimit['target'].""); 

//類型
$radiogstyletext= $mainvar['radiogstyle']=='text' ? _MA_BLOCKMENUSORTPHP06 : _MA_BLOCKMENUSORTPHP07; // get TRUE




$main="<div class='container'>
  <h4>".sprintf(_MA_BLOCKMENUSORTPHP23,$mainvar['sorttitle'])."&nbsp;<label for='sel2'>project admin</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php?op=textfunction&categoryid=".$mainvar['sortid']."'>"._MS_SHARED25."</a>&nbsp; <a class='btn btn-primary active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php'>"._MA_BLOCKMENUSORTPHP24."</a>&nbsp; <a class='btn btn-info active'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".$mid."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a>  </h4>	


	
<div class='row'>   
  	   <div class='col-md-2'>
  	   	<select id='FriendLink' class='form-control' >
    <option value=''  data-id='1' >"._MA_BLOCKMENUSORTPHP27."</option>
    	".$textfunction['0']."   
  </select>	
  	  </div>
  	   <div class='col-md-10'>
  	<span><span class='red'>".sprintf(_MA_BLOCKMENUSORTPHP26,$radiogstyletext)."</span>"._MA_BLOCKMENUSORTPHP25."</span></div>
  	  	  
  	  	  </div>	
	
          <hr />
    <div class='form-group col-md-12'>
<div class='row'>

<div class='col-md-5'>	

	<form method='post'  action='{$_SERVER['PHP_SELF']}'> 
		".$sortmemu['1']."<hr />
".$textfunction['5']."	
<div class='form-group'>
<label class='col-sm-4'>"._MA_BLOCKMENUSORTPHP39."</label>	
	 <div class='col-sm-8'>
	 <select id=blockdefault class='form-control' name='of_sortid' >
    <option   data-id='0' value='0'>"._MA_BLOCKMENUSORTPHP39."</option>
    	".$optionone."   
  </select>	 <br />

   	

  	

  	</div> 

</div> 


	
	
<div class='form-group'>
<label class='col-sm-4'>".$sorttitletext."</label>	
	 <div class='col-sm-8'> ".$sorttitle."    
  	<br /></div> 
</div> 	

<div class='form-group'>
<label class='col-sm-4'>"._MA_MENUTABLEPHP08."</label>	
	 <div class='col-sm-8'> ".$url."    
  	<br /></div> 
</div> 
	
<div class='form-group'>
<label class='col-sm-4'>"._MA_MENUTABLEPHP09."</label>	
	 <div class='col-sm-8'> ".$target."    
  	<br /><br /><br /></div> 
</div> 			
	

	
<div class='form-group'>
<label class='col-sm-4 control-label'>"._MS_SHARED91."</label>	
	 <div class='col-sm-8'>
	<select  class='form-control' id='sel1'  name='browsegroup[]' multiple  >
    	".$textfunction['6']."   
  </select>		  
  	<br />
  <span id='helpBlock' class='help-block'>"._MS_SHARED92."</span>
  	</div> 
</div> 		
	
	
<div class='form-group'>
<label class='col-sm-4'>"._MS_SHARED05."</label>	
	 <div class='col-sm-8'> ".$enable."    
  	<br /><br /><br /></div> 
</div> 	
	
".$hidden."	 
<input type='hidden' name='op' value='".$buttonvar."'>  	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
	
		
		
		  </form> <br />

   </div> 
 <div class='col-md-7'>
 	   	<form method='post'  action='{$_SERVER['PHP_SELF']}'> 
 	   <div id='deletename' mane='".$sortidvar."'></div>
  <table class='table basictable'>
    <thead>
      <tr>
        <th style='width: 10%;'>"._MS_SHARED11."</th>
        <th style='width: 26%;'>"._MS_SHARED93."</th>
        <th style='width: 7%;'>"._MS_SHARED94."</th> 	
            <th style='width: 13%;'>"._MA_BLOCKMENUSORTPHP43."</th>       
         <th  style='width: 11%;'>"._MS_SHARED10."</th>
                 <th style='width: 13%;'>"._MS_SHARED43."</th>   
        <th style='width: 17%;'>"._MS_SHARED07."</th>
      </tr>
    </thead>
    <tbody>
   ".$sortvar." 
 
    </tbody>
  </table> 	   
 <input type='hidden' name='categoryid' value='".$categoryid."'>	   
 <input type='hidden' name='op' value='sortidsortupdate'>  	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button>
	
		
		
		  </form> 	   
 	   
 	   	  </div>    
      
       </div> </div>  
  	  
  	  </div>   
  	<script src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></script>	   	 
  <script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 			   
  "; 
  
 return $main;




}



//區塊按鈕分類管理
function blockmenusort(){
 global $xoopsDB,$xoopsModule,$categoryid,$radiogstyle,$mid,$variablesplit;	


 




if(empty($categoryid)){  //新增
$blockmenusort_table_form['7']="<h3>"._MA_BLOCKMENUSORTPHP03."</h3>";
//POST類型
$blockmenusort_table_form['9']="<input type='hidden' name='op' value='save_news'>";
$neoblockmenusortlist['enable']=1;
$neoblockmenusortlist['radiogstyle']="text";

//取得圖標 
$glyphiconicon=glyphiconicon($sortimg=0);
$stylebox="style='display: none;'";
//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  

$stylebox3="style='display: none;'";

$neoblockmenusortlist['boxwidth']=$variablesplit[14];
$neoblockmenusortlist['target']=0;
}else{  //編輯
$blockmenusort_table_form['7']="<h3>"._MA_BLOCKMENUSORTPHP04."</h3>";

//開啟neoblockmenusort資料表
$dbneme="neoblockmenusort";
$where="  where `sortid` = '".$categoryid."'";  //where數值
//$neoblockmenusortlist=moduledb($dbneme,$where);
//批次轉換htmlspecialchars
$neoblockmenusortlist=htmlspecialcharsbatch($allowvar=array("sorttitle","sorttitleurl","icon"),$eachvar=moduledb($dbneme,$where));

$main['DB']=$neoblockmenusortlist;

if(empty($neoblockmenusortlist['browsegroup'])){
//預設群組
$groupArr = array(); //建構陣列
$groupArr[0]='2'; 
$groupArr[1]='3';  
}

if(empty($neoblockmenusortlist['boxwidth'])) $neoblockmenusortlist['boxwidth']=$variablesplit[14];


//取得圖標 
$glyphiconicon=glyphiconicon($sortimg=$neoblockmenusortlist['sortimg']);

//判斷分類按鈕連結是否啟用

if(empty($neoblockmenusortlist['urlenable'])){
$stylebox="style='display: none;'";
}

//判斷按鈕類型
if($neoblockmenusortlist['radiogstyle']=="img"){
$stylebox2="style='display: none;'";
$stylebox3="style='display: block;'";
}

if($neoblockmenusortlist['radiogstyle']=="text"){
$stylebox3="style='display: none;'";
}


//POST類型
$blockmenusort_table_form['9']="<input type='hidden' name='op' value='updated'><input type='hidden' name='sortid' value='".$neoblockmenusortlist['sortid']."'>";
}


//分類標題
$blockmenusort_table_form['0']=inputtext($class="",$name="sorttitle",$value="".$neoblockmenusortlist['sorttitle']."",$placeholder=""._MD_CONTACTENTER.""._MA_BLOCKMENUSORTPHP05."",$id="");	

//是否使用分類按鈕用連結 
$blockmenusort_table_form['1']=radioinline($class="",$name="urlenable",$text=array(_MS_SHARED41,_MS_SHARED40),$checked=$neoblockmenusortlist['urlenable'],$id="enablebtn");  





//選擇按鈕樣式
$radiogstyleArr = array(); //建構陣列
//顯示全部
$i=0;
$radiogstyleArr[$i]['value']="text";
$radiogstyleArr[$i]['title']=_MA_BLOCKMENUSORTPHP06;
$radiogstyleArr[$i]['url']="blockmenusort.php?radiogstyle=text";

$i++;
$radiogstyleArr[$i]['value']="img";
$radiogstyleArr[$i]['title']=_MA_BLOCKMENUSORTPHP07;
$radiogstyleArr[$i]['url']="blockmenusort.php?radiogstyle=img";
$i++;

foreach($radiogstyleArr as $key=> $val){
$blockmenusort_table_form['2'].=radioinlinelist($dataid=$radiogstyleArr[$key]['value'],$class="",$name='radiogstyle',$text=$radiogstyleArr[$key]['title'],$value=$radiogstyleArr[$key]['value'],$oid=$neoblockmenusortlist['radiogstyle'],$id="inlineRadio"); 
}


foreach($radiogstyleArr as $key=> $val){
$blockmenusort_table_form['7'].=optionselect($dataid=$radiogstyleArr[$key]['value'],$optionname=$radiogstyleArr[$key]['title'],$oid="".$radiogstyle."",$value=$radiogstyleArr[$key]['url']);
}

//分類按鈕連結
$blockmenusort_table_form['3']=inputtext($class="",$name="sorttitleurl",$value="".$neoblockmenusortlist['sorttitleurl']."",$placeholder=""._MD_CONTACTENTER.""._MA_BLOCKMENUSORTPHP09."",$id="");	

//按鈕連結開啟方式
$blockmenusort_table_form['4']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$neoblockmenusortlist['target'].""); 




//選擇子選單圖示
$sortimgArr = array(); //建構陣列
//顯示全部




for ($i = 0; $i < 21; $i++) {
$sortimgArr[$i]['id']=$i;
$sortimgArr[$i]['title']=sprintf(_MA_BLOCKMENUSORTPHP14,$i+1);
}


foreach($sortimgArr as $key=> $val){
$blockmenusort_table_form['5'].=optionselect($dataid=$sortimgArr[$key]['id'],$optionname=$sortimgArr[$key]['title'],$oid="".$neoblockmenusortlist['sortimg']."",$value=$sortimgArr[$key]['id']);
}

//分類型態文字
if(!empty($radiogstyle)){
$radiogstyletext= $radiogstyle=='text' ? "-"._MA_BLOCKMENUSORTPHP06."" : "-"._MA_BLOCKMENUSORTPHP07.""; // get TRUE
}

//是否啟用
$blockmenusort_table_form['10']=radioinline($class="",$name="enable",$text=array(_MS_SHARED04,_MS_SHARED03),$checked="".$neoblockmenusortlist['enable']."");

//ICON
$blockmenusort_table_form['12']=inputtext($class="",$name="icon",$value="".$neoblockmenusortlist['icon']."",$placeholder=""._MA_NEILRANDOMIDIOM13."");



//圖片寬度
$blockmenusort_table_form['14']=inputtext($class="",$name="boxwidth",$value="".$neoblockmenusortlist['boxwidth']."",$placeholder=""._MD_CONTACTENTER.""._MA_BLOCKMENUSORTPHP50."",$id="");	




 	
//可觀看群組
$groupsArr=neillibrary_permissionmenu($types='2',$admingroup="",$browsegroup=$neoblockmenusortlist['browsegroup'],$groupArr);

//可觀看群組
$blockmenusort_table_form['13']=$groupsArr[2];








//TABLE區塊
if(!empty($radiogstyle)){
$wherevar=" where `radiogstyle` = '".$radiogstyle."'";
}

$dbneme="neoblockmenusort";
$where=" ".$wherevar." order by  sorting  ASC"; 
$neoblockmenusortArr=databasetablewhile($dbneme,$where);  
foreach($neoblockmenusortArr as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="sorting".$neoblockmenusortArr[$key]['sortid']."",$value="".$neoblockmenusortArr[$key]['sorting']."",$placeholder="");	

//狀態
$td['enable']=enable($envar=$neoblockmenusortArr[$key]['enable']);

//按鈕類型
$td['radiogstyle']=$neoblockmenusortArr[$key]['radiogstyle']=='text' ? _MA_BLOCKMENUSORTPHP06."&nbsp;<span class='".glyphiconicon($sortimg=$neoblockmenusortArr[$key]['sortimg'])."' aria-hidden='true'>" : _MA_BLOCKMENUSORTPHP07."&nbsp;<span class='glyphicon glyphicon-picture' aria-hidden='true'></span>"; // get TRUE

//子項目OP變數
$td['opvar']=$neoblockmenusortArr[$key]['radiogstyle']=='text' ? "?op=textfunction" : "?op=imgfunction"; // get TRUE


//按鈕連結
$td['urlenable']=empty($neoblockmenusortArr[$key]['urlenable']) ? _MS_SHARED41 : _MS_SHARED40; // get TRUE


if($neoblockmenusortArr[$key]['sortid']==$categoryid){
$colorstyle[$key]="class='color1'";
}

$disabledbox= empty($neoblockmenusortArr[$key]['enable']) ? 'disabled' : 'active'; // get TRUE	

	
$blockmenusort_table_form['11'].="<tr id='deletetr{$key}' ".$colorstyle[$key].">
        <td>".$td['nnumber']."</td>
        <td>".$neoblockmenusortArr[$key]['sorttitle']."</td>
        <td>".groupslabel($Arr=phpconversion($conversion=$neoblockmenusortArr[$key]['browsegroup'],$type="unserialize"),$type="",$style="label-danger")."</td>        	
        <td>".$td['urlenable']."</td>
         <td>".$td['radiogstyle']."</td>
        <td>".$td['enable']."</td>
        <td>  <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/blockmenusort.php?sortid=".$neoblockmenusortArr[$key]['sortid']."'  class='btn btn-xs btn-info  active'>"._MS_SHARED08."</a>   
     <a id='deletebotton{$key}' type='button' mane='88,".$neoblockmenusortArr[$key]['sortid'].",".$neoblockmenusortArr[$key]['sorttitle'].","._MA_BLOCKMENUSORTPHP49."'  class='btn btn-xs btn-danger  active deleteeach'>"._MS_SHARED09."</a>
     	 <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/blockmenusort.php".$td['opvar']."&categoryid=".$neoblockmenusortArr[$key]['sortid']."'  class='btn btn-xs btn-success  ".$disabledbox."'>"._MA_BLOCKMENUSORTPHP21."</a>  	
     		</td>
      </tr>";
}


$blockmenusort_table_form['6']="
<table class='table basictable'>
    <thead>
      <tr>
      
        <th style='width: 6%'>"._MA_MARQUEETABLEPHP07."</th>
        <th style='width: 14%'>"._MA_BLOCKMENUSORTPHP18."</th>
          <th style='width: 8%'>"._MS_SHARED94."</th>      	
           <th style='width: 9%'>"._MA_BLOCKMENUSORTPHP19."</th>
            <th style='width: 10%'>"._MA_BLOCKMENUSORTPHP20."</th> 
               <th style='width: 8%'>"._MS_SHARED10."</th>  
                 <th style='width: 19%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$blockmenusort_table_form['11']."
     
    </tbody>
  </table>
";
 
$main['table'].="<div class='container'>
  <h4>"._MA_BLOCKMENUSORTPHP01."&nbsp;<label for='sel2'>themes Block classification admin</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/blockmenusort.php'>"._MS_SHARED25."</a> &nbsp; <a class='btn btn-info active'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".$mid."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a></h4>	
    <div class='row'>
    ";
//左邊區塊
$main['table'].="
<form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-4'>".$blockmenusort_table_form['8']."<hr />
 
 
 
<div  class='form-group'>	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP05."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 

 	
 
<div  class='form-group' >	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP08."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['2']." 
  	   <br /> <br /></div> 
 	 <hr />	</div> 	

<div id='topboxny' ".$stylebox2.">
<div  id='enablebox'  class='form-group' >	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP10."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['1']."
  	   <br /> <br /> <span id='helpBlock' class='help-block'>"._MA_BLOCKMENUSORTPHP11."</span>    </div> 
 	 <hr />	</div> 	 
 
 
<div  id='enablebox1' class='form-group'  ".$stylebox.">	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP12."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['3']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 	
<div  id='enablebox2' class='form-group' ".$stylebox.">	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP13."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
 	
 	
 <div  class='form-group' >	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP15."<br /><br /><span id='sortimgicon' ><span class='".$glyphiconicon."' aria-hidden='true'></span></span></label>
 		 <div class='col-sm-8'>	<select size='3'  name='sortimg' id='sortimg' class='form-control' >
    	".$blockmenusort_table_form['5']."   
  </select>	
  	   <br /> <br /></div> 
 	 <hr />	</div> 	
 	 
 	 
 <div    class='form-group' >	
<label class='col-sm-4 control-label'>"._MA_NEILRANDOMIDIOM13."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['12']." 
 	<span id='helpBlock' class='help-block'>"._MA_NEILRANDOMIDIOM14."</span>
  	   <br /></div> 
 	 <hr />	</div> 	 	 
 	 

</div>
	
	
<div id='boxwidth'  class='form-group'  ".$stylebox3.">	
<label class='col-sm-4 control-label'>"._MA_BLOCKMENUSORTPHP50."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['14']." 
 	<span id='helpBlock' class='help-block'>"._MA_BLOCKMENUSORTPHP51."</span>
  	   <br /></div> 
 	 <hr />	</div> 	  	
	
<div class='form-group'>
<label class='col-sm-4 control-label'>"._MS_SHARED91."</label>	
	 <div class='col-sm-8'>
	<select  class='form-control' id='sel1'  name='browsegroup[]' multiple  >
    	".$blockmenusort_table_form['13']."   
  </select>		  
  	<br />
  <span id='helpBlock' class='help-block'>"._MS_SHARED92."</span>
  	</div> 
</div> 	
	
  			   
<div   class='form-group' >	
<label class='col-sm-4 control-label'>"._MS_SHARED44."</label>
 		 <div class='col-sm-8'> ".$blockmenusort_table_form['10']."
  	   <br /> <br />   </div> 
 	 <hr />	</div> 	

  	  
 
  ".$blockmenusort_table_form['9']."	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
  	  
  	  </div>
   </form> 	  
  	  
    ";
 
//右邊區塊
$main['table'].="
  <form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-8'>  
  	  <br /><div class='row'>   
  	   <div class='col-md-4'>
  	   	<select id='FriendLink' class='form-control' >
    <option value='blockmenusort.php'  data-id='1' >"._MA_BLOCKMENUSORTPHP16."</option>
    	".$blockmenusort_table_form['7']."   
  </select>	
  	  </div>
  	   <div class='col-md-8'>
  	  <h3 style='margin-top: 0px;'>"._MA_BLOCKMENUSORTPHP17."".$radiogstyletext."</h3></div>
  	  	  
  	  	  </div>
  	  	  <hr />
  	  ".$blockmenusort_table_form['6']."
  	  
  	  
  	 
  
  	  <input type='hidden' name='radiogstyle' value='".$radiogstyle."'>
    

      	  
  	    <button  type='submit' name='op' value='changelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
  
  
    	  </div>
  	  	  
  	     </form> 
  	     	 
    ";
$main['table'].="
</div>
<script src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></script>	 
<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 			
	";
 
 
	
	


  return $main;


}
//編輯分類子項目-圖片類型
function imgfunctionupdated(){
global $xoopsDB,$variablesplit,$xoops_theme,$categoryid,$sortid,$xoopsModule;	
 
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("sorttitle"));  

/*======資料處理區===========*/
$_POST['browsegroup']=phpconversion($conversion=$_POST['browsegroup'],$type="serialize");

//0->無單引號 1->有單引號
$variable=array(
"categoryid"=>1,	
"sorttitle"=>1,		
"url"=>1,		
"target"=>1,		
"enable"=>1,	
"browsegroup"=>1					
);


foreach($variable as $key=> $val){
$dbpost[$key]=!empty($val) ? "".$key."='".$_POST[$key]."'" : "".$key."=".$_POST[$key].""; // get TRUE
}

//儲存neilhonorcontent
update($dbname="neoblockmenubutton",$set="set ".implode(',', $dbpost)."  where sortid='".$sortid."'");  



//開啟neoblockmenubutton資料夾
$dbneme="neoblockmenubutton";
$where=" where sortid='".$sortid."' order by  sortid  DESC";
$listvar=moduledb($dbneme,$where);


//開啟neoblockmenusort資料表
$menusortlist=moduledb($dbneme="neoblockmenusort",$where="  where `sortid` = '".$categoryid."'");
//圖檔尺寸
if(empty($menusortlist['boxwidth'])) $menusortlist['boxwidth']=$variablesplit[14]; 
 
//製作圖片
//檔名
$imgid=$listvar['buttonimg'];
save_pic($up_id=$imgid,$width=$menusortlist['boxwidth'],$height="0",$modules="".$xoopsModule->getVar("dirname")."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false);

return $categoryid; 
}



//新增分類子項目-圖片類型
function imgfunctionsave_news(){
global $xoopsDB,$variablesplit,$xoops_theme,$categoryid,$xoopsModule;	

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("sorttitle"));  

/*======資料處理區===========*/

$_POST['of_sortid']=0;
$_POST['typesof']=0;
$_POST['modulesid']="NULL";
$_POST['sortidsort']=0;
$_POST['buttonimg']="NULL";
$_POST['browsegroup']=phpconversion($conversion=$_POST['browsegroup'],$type="serialize");



//0->無單引號 1->有單引號
$variable=array(
"of_sortid"=>1,
"categoryid"=>1,	
"sorttitle"=>1,		
"url"=>1,		
"target"=>1,			
"typesof"=>1,		
"modulesid"=>1,				
"sortidsort"=>1,		
"buttonimg"=>1,			
"enable"=>1,	
"browsegroup"=>1					
);

foreach($variable as $key=> $val){
$dbpost[$key]=!empty($val) ? "'".$_POST[$key]."'" : $_POST[$key]; // get TRUE
}

//儲存neilhonorcontent
$sortid=insert($dbname="neoblockmenubutton",$values="(".implode(',', array_keys($variable)).")values(".implode(',', $dbpost).")"); 



//製作圖片
//檔名
$imgid=$categoryid.$sortid."";
//開啟neoblockmenusort資料表
$menusortlist=moduledb($dbneme="neoblockmenusort",$where="  where `sortid` = '".$categoryid."'");
//圖檔尺寸
if(empty($menusortlist['boxwidth'])) $menusortlist['boxwidth']=$variablesplit[14]; 
save_pic($up_id=$imgid,$width=$menusortlist['boxwidth'],$height="",$modules="".$xoopsModule->getVar("dirname")."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false);
//存入排序
$setvar="set sortidsort='".$sortid."' , buttonimg='".$imgid."'  where sortid='".$sortid."'";
update($dbname="neoblockmenubutton",$set=$setvar);



return $categoryid; 
}






//新增按鈕分類
function save_news(){
 global $xoopsDB;	
 
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("sorttitleurl","boxwidth"),$postvar=$_POST,$sqltags=array("sorttitle"));  
  
$valuesvar="(sorttitle,sortimg,sorting,radiogstyle,sorttitleurl,target,urlenable,enable,icon,browsegroup,boxwidth) values('{$_POST['sorttitle']}','{$_POST['sortimg']}','0','{$_POST['radiogstyle']}','{$_POST['sorttitleurl']}','{$_POST['target']}','{$_POST['urlenable']}','{$_POST['enable']}','{$_POST['icon']}','".phpconversion($conversion=$_POST['browsegroup'],$type="serialize")."','{$_POST['boxwidth']}')";	  
$sortid=insert($dbname="neoblockmenusort",$values=$valuesvar);


//存入排序
$setvar="set sorting='".$sortid."'   where sortid='".$sortid."'";
update($dbname="neoblockmenusort",$set=$setvar);
}


//編輯按鈕分類
function updated(){
 global $xoopsDB,$categoryid;	
 
 
 
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("sorttitleurl","boxwidth"),$postvar=$_POST,$sqltags=array("sorttitle"));  

$setvar="set sorttitle='{$_POST['sorttitle']}',sortimg='{$_POST['sortimg']}',radiogstyle='{$_POST['radiogstyle']}',sorttitleurl='{$_POST['sorttitleurl']}',target='{$_POST['target']}',urlenable='{$_POST['urlenable']}',enable='{$_POST['enable']}',icon='{$_POST['icon']}'  , browsegroup='".phpconversion($conversion=$_POST['browsegroup'],$type="serialize")."' ,boxwidth='{$_POST['boxwidth']}'  where sortid='".$categoryid."'";
update($dbname="neoblockmenusort",$set=$setvar);  
 

}



//變更排序
function changelist(){
 global $radiogstyle;	
 
 if(!empty($radiogstyle)){
$wherevar=" where `radiogstyle` = '".$radiogstyle."'";
}
	

$dbneme="neoblockmenusort";
$where=" ".$wherevar." order by  sorting  DESC";
$sort=databasetablewhile($dbneme,$where);

foreach($sort as $key=> $val){
$digital= 'sorting'.$sort[$key]['sortid'];   

$setvar="set sorting='{$_POST[$digital]}'   where sortid='".$sort[$key]['sortid']."'";
update($dbname="neoblockmenusort",$set=$setvar); 

}



}



//新增分類子項目-文字類型
function  textfunctioninsert(){
global $categoryid;   
  
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("sorttitle"));  

/*======資料處理區===========*/
//判斷網址狀態
$output = $_POST['url'];
if (strpos($output, XOOPS_URL) !== false) {
//站內連結
$_POST['typesof']=1;
preg_match("/modules\/(.*?)(?:\/|$)/", $output, $match);
$_POST['modulesid']=$match[1];
} else {
//站外連結
$_POST['typesof']=0;
$_POST['modulesid']="";
}


$_POST['sortidsort']=0;
$_POST['buttonimg']="NULL";
$_POST['browsegroup']=phpconversion($conversion=$_POST['browsegroup'],$type="serialize");



//0->無單引號 1->有單引號
$variable=array(
"of_sortid"=>1,
"categoryid"=>1,	
"sorttitle"=>1,		
"url"=>1,		
"target"=>1,			
"typesof"=>1,		
"modulesid"=>1,				
"sortidsort"=>1,		
"buttonimg"=>1,			
"enable"=>1,	
"browsegroup"=>1					
);

foreach($variable as $key=> $val){
$dbpost[$key]=!empty($val) ? "'".$_POST[$key]."'" : $_POST[$key]; // get TRUE
}

//儲存neilhonorcontent
$sortid=insert($dbname="neoblockmenubutton",$values="(".implode(',', array_keys($variable)).")values(".implode(',', $dbpost).")"); 


//儲存排序
$setvar="set  sortidsort='".$sortid."'  where sortid='".$sortid."'";   	  
update($dbname="neoblockmenubutton",$set=$setvar); 


return $categoryid; 
}

//編輯分類子項目-文字類型
function textfunctionpdate(){
global $categoryid,$sortid;  
 
 
 
//讀取父分類
$dbneme="neoblockmenubutton";
$where="  where `sortid` = '".$sortid."'  order by  of_sortid  DESC";  //where數值
$sortselect=moduledb($dbneme,$where);

if($sortselect['categoryid']!=$categoryid){

if(empty($_POST['of_sortid'])){
//第一層
$where="  where `sortid` = '".$sortselect['of_sortid']."'   order by  sortidsort  DESC";  //where數值
$Arr=databasetablewhile($dbneme,$where);

//遞回開始
foreach($Arr as $key=> $val){
$sortvar.=$Arr[$key]['sortid'].","; 
$sortvar.=sortretorted($dbneme,$sortid="".$Arr[$key]['sortid']."");
}


foreach(explode(',', $sortvar) as $key=> $val){
$setvar="set categoryid='{$_POST['categoryid']}'   where sortid='".$sortid."'";
update($dbname="neoblockmenubutton",$set=$setvar);

}  	  
	

}else{
$_POST['of_sortid']="0";
}

}else{
$_POST['of_sortid']=$sortid!=$_POST['of_sortid'] ? $_POST['of_sortid']: $sortselect['of_sortid']; 

} 

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("sorttitle"));  


/*======資料處理區===========*/
//判斷網址狀態
$output = $_POST['url'];
if (strpos($output, XOOPS_URL) !== false) {
//站內連結
$_POST['typesof']=1;
preg_match("/modules\/(.*?)(?:\/|$)/", $output, $match);
$_POST['modulesid']=$match[1];
} else {
//站外連結
$_POST['typesof']=0;
$_POST['modulesid']="";
}

$_POST['browsegroup']=phpconversion($conversion=$_POST['browsegroup'],$type="serialize");



//0->無單引號 1->有單引號
$variable=array(
"of_sortid"=>1,
"categoryid"=>1,	
"sorttitle"=>1,		
"url"=>1,		
"target"=>1,			
"typesof"=>1,		
"modulesid"=>1,			
"enable"=>1,	
"browsegroup"=>1					
);


foreach($variable as $key=> $val){
$dbpost[$key]=!empty($val) ? "".$key."='".$_POST[$key]."'" : "".$key."=".$_POST[$key].""; // get TRUE
}

//儲存neilhonorcontent
update($dbname="neoblockmenubutton",$set="set ".implode(',', $dbpost)."  where sortid='".$sortid."'");  

return $categoryid;  
}


//更新排序
function  sortidsortupdate(){
  global $categoryid;   
  
  
//取得sortid值
$dbneme="neoblockmenubutton";
$where="  where `categoryid` = '".$categoryid."'";
$sort=databasetablewhile($dbneme,$where);
foreach($sort as $key=> $val){
$digital= 'sortidsort'.$sort[$key]['sortid'];   


//判斷排序是否有值傳入
$_POST[$digital]=!empty($_POST[$digital]) ? $_POST[$digital] : $sort[$key]['sortidsort']; // get TRUE

$setvar="set sortidsort='{$_POST[$digital]}'   where sortid='".$sort[$key]['sortid']."'";
update($dbname="neoblockmenubutton",$set=$setvar); 
 

}
return $categoryid; 
}



	
loadModuleAdminMenu(8);
if(!empty(modulesmidvar($modulesid="xLanguage",$var="isactive"))){
$main.="<script>neillibrary_llanguagetext(afterid='#buttonbar');</script>";
}
echo $main;

include_once "footer.php"; //XOOPS檔尾	
	
?>