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

include_once XOOPS_ROOT_PATH."/modules/neillibrary/function/cityadminfunction.php"; //引入城市鄉鎮管理function

//允許傳送變數
$allowvar =array("op","menuid");
//接收變數區
foreach($_REQUEST as $var=> $value){	
if(in_array($var,$allowvar)){
 $$var=sqlinjectionfound($val=trim(isset($value)?$value:""));
} 
}





switch ($op){
 case "save_news":  
//if(empty($_POST['unit']))   redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);   //空值判斷 	  	 
redirect_header($_SERVER['PHP_SELF'].save_news(),0 ,_MS_SHARED02);   
break;

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

$main=address_table();
}


function address_table(){	
 global $xoopsDB,$xoopsModule,$menuid;	
 

if(empty($menuid)){  //新增
$address_table_form['7']="<h4>"._MA_ADDRESS02."</h4>";
//POST類型
$address_table_form['9']="<input type='hidden' name='op' value='save_news'>";
$neil_address['enable']=1;
$neil_address['target']=0;
}else{  //編輯
$address_table_form['7']="<h4>"._MA_ADDRESS03."</h4>";

//開啟neil_address資料表
//批次轉換htmlspecialchars
$neil_address=htmlspecialcharsbatch($allowvar=array("unit","phone","fax","remark","url","fb","line","youtube","maps"),$eachvar=moduledb($dbneme="neil_address",$where="  where `menuid` = '".$menuid."'"));

//地址陣列
$addressArr=phpconversion($conversion=$neil_address['address'],$type="unserialize"); 


//POST類型
$address_table_form['9']="<input type='hidden' name='op' value='updated'><input type='hidden' name='menuid' value='".$neil_address['menuid']."'>";
}



//單位
$address_table_form['0']=inputtext($class="",$name="unit",$value="".$neil_address['unit']."",$placeholder=""._MS_SHARED21._MA_ADDRESS04."");

//電話
$address_table_form['1']=inputtext($class="",$name="phone",$value="".$neil_address['phone']."",$placeholder=""._MS_SHARED21._MA_ADDRESS05."");


//鄉鎮城市
$citydate=neillibrary_countiesajaxmenu($cityid=$addressArr['of_cityid1'],$status="",$signedupshow=$neil_address);

//地址
$address_table_form['2']=inputtext($class="",$name="of_cityid2",$value=htmlspecialchars($addressArr['of_cityid2']),$placeholder=""._MS_SHARED21._MA_ADDRESS06."");

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

//傳真
$address_table_form['10']=inputtext($class="",$name="fax",$value="".$neil_address['fax']."",$placeholder=""._MS_SHARED21._MA_ADDRESS11."");


//備註說明
$address_table_form['11']=inputtextarea($class="",$name="remark",$id="",$rows="4",$cols="80",$value="".$neil_address['remark']."");

//單位連結
$address_table_form['12']=inputtext($class="",$name="url",$value="".$neil_address['url']."",$placeholder=""._MS_SHARED21._MA_ADDRESS13."");

//fb連結
$address_table_form['13']=inputtext($class="",$name="fb",$value="".$neil_address['fb']."",$placeholder=""._MS_SHARED21._MA_ADDRESS14."");

//line-id
$address_table_form['14']=inputtext($class="",$name="line",$value="".$neil_address['line']."",$placeholder=""._MS_SHARED21._MA_ADDRESS15."");

//youtube
$address_table_form['15']=inputtext($class="",$name="youtube",$value="".$neil_address['youtube']."",$placeholder=""._MS_SHARED21._MA_ADDRESS16."");

//Googlemap
$address_table_form['16']=inputtext($class="",$name="maps",$value="".$neil_address['maps']."",$placeholder=""._MS_SHARED21._MA_ADDRESS17."");

//連結開啟方式
$address_table_form['17']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$neil_address['target'].""); 


//TABLE區塊


$neil_addressArr=databasetablewhile($dbneme="neil_address",$where="  order by  btnsort  ASC");  

	
foreach($neil_addressArr as $key=> $val){
	

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


if($neil_addressArr[$key]['menuid']==$menuid){
$colorstyle[$key]="color1";
}

$addressbox[$key]=neillibrary_addresscombination($address=$neil_addressArr[$key]['address']);
	
$address_table_form['6'].="<tr class='deletetr{$key} tr ".$colorstyle[$key]."' id='".$neil_addressArr[$key]['menuid']."'  >
        <td>".$neil_addressArr[$key]['menuid']."</td>
        <td>".$neil_addressArr[$key]['unit']."</td>
        <td>".$addressbox[$key].'<br />'.$neil_addressArr[$key]['phone']."</td>        	
        <td>".$td['enable']."</td>
        <td><a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/address.php?menuid=".$neil_addressArr[$key]['menuid']."'  class='btn btn-sm btn-info  '>"._MS_SHARED08."</a>   
     <a id='deletebotton{$key}' type='button' mane='156,".$neil_addressArr[$key]['menuid'].",".$neil_addressArr[$key]['unit'].","._MA_ADDRESS08.",,neil_address,".$xoopsModule->getVar("dirname").",,menuid'  class='btn btn-sm btn-danger   deleteeach'>"._MS_SHARED09."</a>     
     </tr>";
}

 
$address_table_form['5']="
<table class='table sortable basictable' name='164,".$xoopsModule->getVar("dirname").",".$menutype.",".$pageid.",".$typesid.",".$sortid.",".$suid.",neil_address'>
    <thead>
      <tr>
      
        <th style='width: 6%'>"._MS_SHARED06."</th>
        <th style='width: 15%'>"._MA_ADDRESS04."</th>
        <th style='width: 30%'>"._MA_ADDRESS09."</th>
              <th style='width: 6%'>"._MS_SHARED10."</th>  
                 <th style='width: 12%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$address_table_form['6']."
     
    </tbody>
  </table>
  		<p class='text-center'>"._MS_SHARED143."</p>
	
";
 
$main.="

	<div class='container'>
  <h4>"._MA_ADDRESS01."&nbsp;<label for='sel2'>National base management</label>&nbsp; <a class='btn btn-warning '  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/address.php'>"._MS_SHARED25."</a> <a class='btn btn-info'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".modulesmidvar($modulesid="neothemesadmin")."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a></h4>	
    <div class='row'>
    ";
//左邊區塊
$main.="

  <div id='nationalbasebox' class='col-md-4'>
<form method='post'  action='{$_SERVER['PHP_SELF']}' >	  	  
  	  ".$address_table_form['7']."<hr />
 
 

 

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS04."</label>
 		 <div class='col-md-9'> ".$address_table_form['0']." 
 	<span id='helpBlockunit' class='red blockeach3'>"._MS_SHARED22."</span>
  	   <br /><br /></div> 
 	 	</div> 	

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS13."</label>
 		 <div class='col-md-9'> ".$address_table_form['12']." 
  	   <br /></div> 
 	 	</div> 	

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP05."</label>
 		 <div class='col-md-9'> ".$address_table_form['17']." 
  	   <br /><br /></div> 
<div style='clear: both;'></div>  	
 	 	</div> 	


<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS05."</label>
 		 <div class='col-md-9'> ".$address_table_form['1']." 
  	<span id='helpBlockphone' class='red blockeach3'>"._MS_SHARED22."</span>	
  	   <br /><br /></div> 
 		</div> 	

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS11."</label>
 		 <div class='col-md-9'> ".$address_table_form['10']." 
  	   <br /></div> 
 		</div> 	

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS06."</label>
 		 <div class='col-md-9'>

<div> <select id=citydefault class='form-control' name='of_cityid' >
    <option   data-id='0'  value='0'>"._MS_CITY_MENU04."</option>
    ".$citydate['countiesoptionone']."
  </select><br />	 </div> 
     <span id='cityselectboxname' name='".$citydate['countiesselectmenu1'].",".$citydate['countiesstatus'].",".$citydate['countiesselectmenu2'].",of_cityid1'></span>
   	<div id='cityselectbox'></div>	
    <div>".$address_table_form['2']."</div>
 	  	<span id='helpBlockaddress' class='red blockeach3'>"._MS_SHARED22."</span>	
  	   <br /><br /></div> 
 	 </div> 	
 	 	   
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS12."</label>
 		 <div class='col-md-9'> ".$address_table_form['11']." 
 	  	 <span id='helpBlock' class='help-block'>"._MA_ADDRESS18."</span>
  	  	<span id='helpBlockremark' class='red blockeach3'>"._MS_SHARED22."</span>		
  	   <br /><br /></div> 
 	 	</div> 		 	   
 	
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS14."</label>
 		 <div class='col-md-9'> ".$address_table_form['13']." 
  	   <br /></div> 
 		</div> 
 
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS15."</label>
 		 <div class='col-md-9'> ".$address_table_form['14']." 
  	   <br /></div> 
 		</div> 		 
 	
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS16."</label>
 		 <div class='col-md-9'> ".$address_table_form['15']." 
  	   <br /></div> 
 		</div> 		 

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_ADDRESS17."</label>
 		 <div class='col-md-9'> ".$address_table_form['16']." 
  	   <br /></div> 
 		</div> 	
 		
 	
<div  class='row'>	
<label class='col-md-3 control-label'>"._MS_SHARED44."</label>
 		 <div class='col-md-9'> ".$address_table_form['4']." 
  	   <br /><br /><br /></div> 
 	 	</div> 				   	  
   

  	  
 
  ".$address_table_form['9']."	
 <button  type='submit' disabled='disabled' class='btn btn-primary btn-lg btn-block contentbtn'>"._MS_SHARED01."</button>
<div id='help-blocktext' class='text-center'><span id='helpBlock' class='help-block'><span  class='red'>"._MS_SHARED30."</span></span></div>    
     </form> 		  
  	  </div>
  
  	  
    ";
//右邊區塊
$main.="

  <div class='col-md-8'><h4>"._MA_ADDRESS07."</h4><hr />
  	  ".$address_table_form['5']."
    	  </div>
  	  	  

  	     	 
    ";
$main.="
</div>


<script>citymenufunction();neothemesadmin_nationalbaseform();</script>
<script src='".XOOPS_URL."/modules/neillibrary/js/tpl-jquery/jquery-ui/jquery-ui.js'></script>
<script>var itemsvar='.tr'; dragmenufunction();</script>  	  
<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script>   

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


  return $main;
}

//編輯全國單位
function updated(){
 global $xoopsDB,$menuid;	 

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar="",$postvar=$_POST,$sqltags=array("unit","phone","fax","remark","url","of_cityid2","fb","line","youtube","maps"));  
 
//必填欄位驗證
$arr =array("unit","phone","of_cityid2","remark");
//會員帳號/密碼
foreach($arr as  $val){	
if(empty($_POST[$val])){
redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);
break;
}
}
 
$setvar="set 
unit='{$_POST['unit']}',
phone='{$_POST['phone']}',
fax='{$_POST['fax']}',
address='".phpconversion($conversion=array('of_cityid'=>$_POST['of_cityid'],'of_cityid1'=>$_POST['of_cityid1'],'of_cityid2'=>$_POST['of_cityid2']),$type="serialize")."',
remark='{$_POST['remark']}',
url='{$_POST['url']}',
target='{$_POST['target']}',
fb='{$_POST['fb']}',
line='{$_POST['line']}',
youtube='{$_POST['youtube']}',
maps='{$_POST['maps']}',	
enable='{$_POST['enable']}'  
where menuid='".$menuid."'";
update($dbname="neil_address",$set=$setvar);  
 

}


//新增全國單位
function save_news(){
 global $xoopsDB;	

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar="",$postvar=$_POST,$sqltags=array("unit","phone","fax","remark","url","of_cityid2","fb","line","youtube","maps"));  


//必填欄位驗證
$arr =array("unit","phone","of_cityid2","remark");
//會員帳號/密碼
foreach($arr as  $val){	
if(empty($_POST[$val])){
redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);
break;
}
}










$valuesvar="(
unit,phone,fax,address,remark,url,target,fb,line,youtube,maps,btnsort,enable) 
values(
'{$_POST['unit']}','{$_POST['phone']}','{$_POST['fax']}','".phpconversion($conversion=array('of_cityid'=>$_POST['of_cityid'],'of_cityid1'=>$_POST['of_cityid1'],'of_cityid2'=>$_POST['of_cityid2']),$type="serialize")."','{$_POST['remark']}','{$_POST['url']}','{$_POST['target']}','{$_POST['fb']}','{$_POST['line']}','{$_POST['youtube']}','{$_POST['maps']}','0','{$_POST['enable']}'
)";	  

insert($dbname="neil_address",$values=$valuesvar);




}



loadModuleAdminMenu(11);



echo $main;

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

	
	?>