<?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 "keyword01":  

if(empty($_POST['keywordcenter']))   redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);   //空值判斷 	 	 
redirect_header(XOOPS_URL. '/modules/neothemesadmin/admin/keywordmeta.php'.keyword_insert()  ,0 , _MA_NEODWADMIN_ADDDATA);    //資料已新增
break; 

 case "keyword02":  
 	 	
if(empty($_POST['keywordcenter']))   redirect_header($_SERVER['PHP_SELF'].'?nsn='.$nsn.'',0 , _MS_SHARED90);   //空值判斷 	 	 
redirect_header(XOOPS_URL. '/modules/neothemesadmin/admin/keywordmeta.php'.keyword_updated($nsn)  ,0 , _MA_NEODWADMIN_INFORMATIONTOMODIFY);     //資料已修改 
break; 
 
 
 default:
 $main = menu_form($nsn);
}

function menu_form($nsn=""){	
 global $xoopsDB,$xoopsModule; 
 
if(empty($nsn)){
$op='keyword01';
if(empty($keywordidname['name'])){
$keywordidname['name']=_MA_NOTSET;
}  
}else{

//引入模組DB函數-初始化設定
$dbneme="neothemeskeyword";
$where=" where `nsn` = '".$nsn."'";
//$neothemeskeyword=moduledb($dbneme,$where);
$neothemeskeyword=htmlspecialcharsbatch($allowvar=array("keywordcenter","wdescription","title"),$eachvar=moduledb($dbneme,$where));




//引入模組DB函數-初始化設定
$dbneme="modules";
$where=" where `dirname` = '".$neothemeskeyword['keywordid']."'";
$keywordidname=moduledb($dbneme,$where);



if($neothemeskeyword['keywordid']=="modules"){
$keywordidname['name']=_MA_NEODWADMIN_DISPLAYALLPAGESKEYWORD;
}	
if($neothemeskeyword['keywordid']=="system"){
$keywordidname['name']=_MA_NEODWADMIN_DISPLAYHOMEKEYWORD;
}



$op='keyword02';
$nsninput="<input type='hidden' name='nsn' value='".$nsn."'>";  
if($neothemeskeyword['keywordid']=="modules"){
$selected="selected='selected'";  
}

} 

 

//引入模組選單
$input1['modules']=modulesnameoption($name=$neothemeskeyword['keywordid']);
//引入input物件
$input1['keywordcenter']=inputtext($class,$name="keywordcenter",$value=$neothemeskeyword['keywordcenter'],$placeholder=_MA_NEODWADMIN_ENTERKEYWORDS);
//引入textarea物件
$input1['wdescription']=inputtextarea($class,$name="wdescription",$id="wdescription",$rows="10",$cols="80",$value=$neothemeskeyword['wdescription']);
//引入input物件
$input1['title']=inputtext($class,$name="title",$value=$neothemeskeyword['title'],$placeholder=_MA_NEODWADMIN_METATITLE);

 
$tablebox.="<div class='container'>
	
	   <div class='page-header'>
  <h2>"._MA_KEYWORDMETAPHP02."<small> &nbsp;Create a keyword setting</small>&nbsp;&nbsp; <a class='btn btn-primary active'  href='".XOOPS_URL."/modules/".$xoopsModule->getVar("dirname")."/admin/keywordmeta.php'' >"._MA_KEYWORDMETAPHP03."</a></h2>
</div>	
	<form method='post'  action='{$_SERVER['PHP_SELF']}' role='form' >
		<div class='form-group'>
 <table class='table'>
    <thead>
      <tr>
        <th colspan='2'>"._MA_NEODWADMIN_CONFIGURATIONSETTINGS."</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>"._MA_NEODWADMIN_ENTERKEYWORDS3."</td>
        <td><div class='col-md-12'>".$keywordidname['name']."</div></td>
    
      </tr> 		
    		
    		   <tr>
        <td>"._MA_NEODWADMIN_CONFIGURATIONKEYWORDS."</td>
        <td> <div class='col-md-8'>  <select name='keywordid'  class='form-control col-md-2' >
		
    	".$input1['modules']."   
  </select>	</div></td>
    
      </tr>
      <tr>
        <td style='width: 20%'>"._MA_NEODWADMIN_ENTERKEYWORDS."</td>
        <td><div class='col-md-12 '>
   ".$input1['keywordcenter']."
     <span id='helpBlock' class='help-block'>"._MA_NEODWADMIN_ENTERKEYWORDS2."</span>
     </div>
     	  
     	  </td>
    
      </tr>
      <tr>
        <td>"._MA_NEODWADMIN_ENTERKEYWORDDESCRIPTION."</td>
        <td><div class='col-md-12 '>
   ".$input1['wdescription']."
        </div></td>
      
      </tr>
      <tr>
        <td>"._MA_NEODWADMIN_METATITLE."</td>
        <td><div class='col-md-12 '>
   ".$input1['title']."
     <span id='helpBlock' class='help-block'>"._MA_NEODWADMIN_METATITLE2."</span>
     </div></td>
     
      </tr>
     </tbody>
  </table></div>
 <input type='hidden' name='op' value='".$op."'>  
 ".$nsninput."
	  <button type='submit'  class='buttond btn btn-primary btn-lg btn-block btn-bottom active'>"._MA_NEODWADMIN_SENT."</button>    	  
  	  </form></div>";

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

//儲存最後一次更新的modulesid
function keyword_updatensn($keywordid=""){
 global $xoopsDB; 
$setvar="set modulesid='".$keywordid."'  ";
update($dbname="neothemesconfig",$set=$setvar);  	
}	


//新增關鍵字
function keyword_insert(){		
  global $xoopsDB; 

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

$valuesvar="(keywordid,keywordcenter,wdescription,title) values('{$_POST['keywordid']}','{$_POST['keywordcenter']}','{$_POST['wdescription']}','{$_POST['title']}')";	  
$nsn=insert($dbname="neothemeskeyword",$values=$valuesvar);

//儲存最後一次新增的nsn	
keyword_updatensn($_POST['keywordid']);

}


//編輯關鍵字
function  keyword_updated($nsn=""){
  global $xoopsDB; 

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

//儲存最後一次新增的nsn	
keyword_updatensn($_POST['keywordid']);	
} 

	

loadModuleAdminMenu(0);



echo $main;
//xoops_cp_footer();
include_once "footer.php"; //XOOPS檔尾	
	?>