<?php
include_once 'header.php'; //XOOPS檔頭
include_once "../function.php";	




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




switch ($op){
   case "changelist":
changelist();
redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED02);     
  break;   

 case "save_news":   
 save_news();
 redirect_header($_SERVER['PHP_SELF'],0 , _MA_PLAYERADMINPHP07);   
break;

 case "updated":   
 updated();
 redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED02);   
break;
 
 default:

$main=custommenu_table();
}


function custommenu_table(){	
 global $xoopsDB,$xoopsModule,$nsn,$url;	
 


$img_date = date("H:i:s");
if(empty($nsn)){  //新增
$custommenu_table_form['7']="<h3>"._MA_RIGHTMENUPHP02."</h3>";
//POST類型
$custommenu_table_form['9']="<input type='hidden' name='op' value='save_news'>";
$neorightmenulist['enable']=1;
$neorightmenulist['target']=0;
}else{  //編輯
$custommenu_table_form['7']="<h3>"._MA_RIGHTMENUPHP03."</h3>";

//開啟neothemesflash資料表
$dbneme="neorightmenu";
$where="  where `nsn` = '".$nsn."'";  //where數值
//$neorightmenulist=moduledb($dbneme,$where);

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



//POST類型
$custommenu_table_form['9']="<input type='hidden' name='op' value='updated'><input type='hidden' name='nsn' value='".$neorightmenulist['nsn']."'>";
}


//按鈕名稱
$custommenu_table_form['0']=inputtext($class="",$name="title",$value="".$neorightmenulist['title']."",$placeholder=""._MD_CONTACTENTER.""._MA_RIGHTMENUPHP04."",$id="");	


//按鈕連結
$custommenu_table_form['1']=inputtext($class="",$name="url",$value="".$neorightmenulist['url']."",$placeholder=""._MD_CONTACTENTER.""._MA_RIGHTMENUPHP05."",$id="");	

//按鈕開啟方式
$custommenu_table_form['2']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$neorightmenulist['target'].""); 



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

//TABLE區塊
foreach($neorightmenuArr=databasetablewhile($dbneme="neorightmenu",$where="  order by  snid  ASC") as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="snid".$neorightmenuArr[$key]['nsn']."",$value="".$neorightmenuArr[$key]['snid']."",$placeholder="");	


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

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

if($neorightmenuArr[$key]['nsn']==$nsn){
$colorstyle[$key]="class='color1'";
}

	
$custommenu_table_form['6'].="<tr id='deletetr{$key}' ".$colorstyle[$key].">
        <td>".$td['nnumber']."</td>
        <td><a  target='_blank' href='".$neorightmenuArr[$key]['url']."'>".$neorightmenuArr[$key]['title']."</a></td>
        <td>".$td['target']['text']."</td>
        <td>".$td['enable']."</td>
        <td>  <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/rightmenu.php?nsn=".$neorightmenuArr[$key]['nsn']."'  class='btn btn-sm btn-info  active'>"._MS_SHARED08."</a>   
     <a id='deletebotton{$key}' type='button' mane='122,".$neorightmenuArr[$key]['nsn'].",".$neorightmenuArr[$key]['title'].","._MA_RIGHTMENUPHP11."'  class='btn btn-sm btn-danger  active deleteeach'>"._MS_SHARED09."</a></td>
      </tr>";
}

 
$custommenu_table_form['5']="
<table class='table basictable'>
    <thead>
      <tr>
      
        <th style='width: 6%'>"._MA_MARQUEETABLEPHP07."</th>
        <th style='width: 30%'>"._MA_RIGHTMENUPHP10."</th>
           <th style='width: 12%'>"._MA_MARQUEETABLEPHP09."</th>

               <th style='width: 8%'>"._MS_SHARED10."</th>  
                 <th style='width: 15%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$custommenu_table_form['6']."
     
    </tbody>
  </table>
";
 
$main.="<div class='container'>
  <h2>"._MA_RIGHTMENUPHP01."&nbsp;<label for='sel2'>Custom website menu management</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/rightmenu.php'>"._MS_SHARED25."</a> </h2>	
    <div class='row'>
    ";
//左邊區塊
$main.="
<form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-4'>".$custommenu_table_form['7']."<hr />
 
 
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_RIGHTMENUPHP04."</label>
 		 <div class='col-sm-9'> ".$custommenu_table_form['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_RIGHTMENUPHP05."</label>
 		 <div class='col-sm-9'> ".$custommenu_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'> ".$custommenu_table_form['2']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	

			   	  
  	  
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_RIGHTMENUPHP06."</label>
 		 <div class='col-sm-9'> ".$custommenu_table_form['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
  	  
 
  ".$custommenu_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-8'><h3>"._MA_RIGHTMENUPHP09."</h3><hr />
  	  ".$custommenu_table_form['5']."
  	  
  
  	  
  	    <button  type='submit' name='op' value='changelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
  
  
    	  </div>
  	  	  
  	     </form> 
  	     	 
    ";
$main.="
</div>
<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 		
	";
 
 
	
	


  return $main;
}

//編輯按鈕
function updated(){
 global $xoopsDB,$nsn;	

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("title"));   
 
$setvar="set title='{$_POST['title']}',url='{$_POST['url']}',target='{$_POST['target']}',enable='{$_POST['enable']}'  where nsn='".$nsn."'";
update($dbname="neorightmenu",$set=$setvar);  
 

}


//新增按鈕
function save_news(){
 global $xoopsDB;	

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("title")); 
 
$valuesvar="(title,url,target,snid,enable) values('{$_POST['title']}','{$_POST['url']}','{$_POST['target']}','0','{$_POST['enable']}')";	  
$nsn=insert($dbname="neorightmenu",$values=$valuesvar);


//存入排序
$setvar="set snid='".$nsn."'  where nsn='".$nsn."'";
update($dbname="neorightmenu",$set=$setvar);


}






//變更排序
function changelist(){
$dbneme="neorightmenu";
$where=" order by  snid  DESC";
$sort=databasetablewhile($dbneme,$where);

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

//判斷排序是否有值傳入
$_POST[$digital]=!empty($_POST[$digital]) ? $_POST[$digital] : $sort[$key]['snid']; // get TRUE
	
$setvar="set snid='{$_POST[$digital]}'   where nsn='".$sort[$key]['nsn']."'";
update($dbname="neorightmenu",$set=$setvar); 

}


}




loadModuleAdminMenu(7);
echo $main;

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

	
	?>