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

$op=isset($_REQUEST['operating'])?$_REQUEST['operating']:"";
$roption=isset($_REQUEST['r'])?$_REQUEST['r']:"";
$setup=isset($_REQUEST['setup'])?$_REQUEST['setup']:"";



switch ($op){
 case "operating1":   	  
snidup(); 
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php",0 , _MA_NEODWADMIN_SHBU);    //設定已更新
break;


 case "operating2":   	  
sniddelete(); 
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php",0 , _MA_NEODWADMIN_SHBU);    //設定已更新
break;


 case "operating3": 
 updatematters();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php" ,0 , _MS_SHARED02);   
 	 
 break;	 

 case "cleardata": 

cleardata();
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php" ,0 , _MS_SHARED02);   
 	 
 break;	 







 default:
$main=contactustable();
}



function contactustable(){	
global $roption,$xoopsModule,$setup;	

	
$contactustableArr = array(); //建構陣列
//顯示全部
$i=0;
$contactustableArr[$i]['value']="contactustable.php?r=display";
$contactustableArr[$i]['title']=_MA_CONTACTUSTABLEPHP03;
$contactustableArr[$i]['id']="display";
$i++;
//已讀取
$contactustableArr[$i]['value']="contactustable.php?r=haveread";
$contactustableArr[$i]['title']=_MA_CONTACTUSTABLEPHP04;
$contactustableArr[$i]['id']="haveread";
$i++;
//未讀取
$contactustableArr[$i]['value']="contactustable.php?r=notread";
$contactustableArr[$i]['title']=_MA_CONTACTUSTABLEPHP05;
$contactustableArr[$i]['id']="notread";

//選擇狀態
foreach($contactustableArr as $key=> $val){
$contactustablebox.=optionselect($dataid=$contactustableArr[$key]['id'],$optionname=$contactustableArr[$key]['title'],$oid=$roption,$value=$contactustableArr[$key]['value']);
}

//選擇操作
$selectArr = array(); //建構陣列
//顯示全部
$i=0;
$selectArr[$i]['value']="operating1";
$selectArr[$i]['title']=_MA_CONTACTUSTABLEPHP23;
$selectArr[$i]['id']="operating1";
$i++;
$selectArr[$i]['value']="operating2";
$selectArr[$i]['title']=_MA_CONTACTUSTABLEPHP24;
$selectArr[$i]['id']="operating2";
$i++;

foreach($selectArr as $key=> $val){
$selectArrbox.=optionselect($dataid=$selectArr[$key]['id'],$optionname=$selectArr[$key]['title'],$oid="",$value=$selectArr[$key]['value']);
}





//讀取neothemesconfig資料表
$dbneme="neothemesconfig";
$where="  where `nsn` = '1'";  //where數值
//批次轉換htmlspecialchars
$neothemesconfig=htmlspecialcharsbatch($allowvar=array("contactmatters"),$eachvar=moduledb($dbneme,$where));

//聯絡事項
$contactmattersbox=inputtext($class="",$name="contactmatters",$value="".$neothemesconfig['contactmatters']."",$placeholder=""._MA_CONTACTUSTABLEPHP07."");


//備註說明
$remarkstextbox=inputtextarea($class="",$name="remarkstext",$id="remarkstext",$rows="0",$cols="0",$value="".$neothemesconfig['remarkstext']."");   

//全部核取
$checkboxall=checkbox($dataid=true,$name="checkboxall",$value="1",$optionname=_MA_CONTACTUSTABLEPHP09,$oid="");  


if(!empty($setup)){
$boxsetup=" <form method='post'  action='{$_SERVER['PHP_SELF']}'>	
     <div class='row'>    		 
   <div class='col-md-9'>    
   		   	 
 <div class='col-md-3'><h4> "._MA_CONTACTUSTABLEPHP02."</h4>
 		 </div>
 <div class='col-md-9'>".$contactmattersbox."    <span id='helpBlock' class='help-block'>"._MA_CONTACTUSTABLEPHP08."</span>   
 		 <p></div>
 		
 <div class='col-md-3'><h4> "._MA_CONTACTUSTABLEPHP29."</h4>
 		 </div>
 <div class='col-md-9'>".$remarkstextbox." <br /></div>
 		 </div>
 		
 		
  <div class='col-md-3'> 
   <input type='hidden' name='operating' value='operating3'> 	 
 <button  type='submit' class='btn btn-primary  btn-block button'>"._MS_SHARED15."</button><br />
 	  
<a class='btn btn-danger btn-block'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php'>"._MS_SHARED25."</a> 	  
 		 </div>	 		 	 
 		 	 
 		 	 	</div> </form>";


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





//解聯絡我們資料表
$dbneme="neocontactusform";

switch ($roption){
 case "haveread":   	  
 $where=" where `readtrue` = '1'  order by  cfid  DESC";   //where數值-修改
break;
 case "notread":   	  
 $where=" where `readtrue` = '0'  order by  cfid  DESC";   //where數值-修改
break;
 case "display":   	  
 $where="   order by  cfid  DESC";   //where數值-修改
break; 
 default:
 $where="  order by  cfid  DESC";   //where數值-修改
	 
}

list($neocontactusformArr,$bar)=databasetablewhilebar($dbneme,$where,$onepage="20",$allpage='10');	
foreach($neocontactusformArr as $key=> $val){
//核取按鈕
$cfid=$neocontactusformArr[$key]['cfid'];
$checkbox=checkbox($dataid=true,$name="readtrue{$cfid}",$value="1",$optionname="",$oid="");  


$sortList.=$neocontactusformArr[$key]['cfid'].','; //串接id
$sortArr['sortArr']="<input type='hidden' name='sortArr' value='".substr($sortList,0,-1)."'>"; //輸出樣板
	





//限制字串輸出長度
if(!empty(base64Judge($var=$neocontactusformArr[$key]['texe_user']))){  //base64判斷
$texe_user = mb_substr(base64_decode($neocontactusformArr[$key]['texe_user']),0,40,'utf8').'....'; 
}else{
$texe_user = mb_substr($neocontactusformArr[$key]['texe_user'],0,40,'utf8').'....'; 
}

//去除HTML
$texe_user=phpstrip_tags($notags=$texe_user);

//性別
switch ($neocontactusformArr[$key]['radiog']){
 case "male":   	  
$gender=_MA_CONTACTUSTABLEPHP21;
break;
 case "female":   	  
$gender=_MA_CONTACTUSTABLEPHP22;
break;
}

//讀取狀態
switch ($neocontactusformArr[$key]['readtrue']){
 case "0":   	  
$readtrue=_MA_CONTACTUSTABLEPHP19;
$readtruestyle="id=readtruestyle"; 
break;
 case "1":   	  
$readtrue=_MA_CONTACTUSTABLEPHP20;
 $readtruestyle=""; 
break;
}

//回覆狀態

if(!empty($neocontactusformArr[$key]['replytext'])){
$replytext=_MA_CONTACTUSTABLEPHP17;
}else{
$replytext=_MA_CONTACTUSTABLEPHP18;
}

//去除HTML
$name_user=phpstrip_tags($notags=$neocontactusformArr[$key]['name_user']);

$respond= empty($neocontactusformArr[$key]['enable']) ? _MA_CONTACTUSTABLEPHP27 : XoopsUser::getUnameFromId($neocontactusformArr[$key]['uid'],0); // get TRUE






$tdbox.="
 <tr ".$readtruestyle.">
        <td>".$checkbox."</td>
        <td>".$neocontactusformArr[$key]['cfidtime']."</td>
        <td>".$name_user."</td>
           <td>".$texe_user."</td> 
                  <td>".$gender."</td>
      <td >".$readtrue."</td>
          <td >".$replytext."</td>
          <td >".$respond."</td>
             <td ><a class='btn btn-success active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/contactusform.php?op=usercontent&cfid=".$neocontactusformArr[$key]['cfid']."'>"._MA_WATCHTHECONTENT."</a></td>

      </tr>

";

}






$table="
	  <table class='table basictable'>
    <thead>
      <tr>
        <th style='width: 1%;'>".$checkboxall."</th>
        <th style='width: 10%;'>"._MA_CONTACTUSTABLEPHP10."</th>
        <th style='width: 7%;'>"._MA_CONTACTUSTABLEPHP11."</th>
     <th>"._MA_CONTACTUSTABLEPHP12."</th> 
      <th style='width: 5%;'>"._MA_CONTACTUSTABLEPHP13."</th>
        <th style='width: 6%;'>"._MA_CONTACTUSTABLEPHP14."</th> 
                    <th style='width: 6%;'>"._MA_CONTACTUSTABLEPHP16."</th> 
            <th style='width: 6%;'>"._MA_CONTACTUSTABLEPHP26."</th> 

            <th>"._MA_CONTACTUSTABLEPHP15."</th> 
      </tr>
    </thead>
    ".$tdbox."
    <table>

";





$main.="<div class='container'>
	
   <div class='page-header'> 
   	   
   	   <div class='col-md-2' style='margin-top: 8px;'>
  		 	<select id='FriendLink' class='form-control' >
    <option value=''  data-id='1' >"._MA_CONTACTUSTABLEPHP06."</option>
    	".$contactustablebox."   
  </select>	
  		     </div> 	 
  <h3>"._MA_CONTACTUSTABLEPHP01."<small> &nbsp;Contact Us Management</small>&nbsp;&nbsp; <a class='btn btn-info active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php?setup=1'>"._MA_CONTACTUSTABLEPHP30."</a> <a class='btn btn-warning active' target='_blank' href='" . XOOPS_URL . "/modules/system/admin.php?fct=preferences&op=show&confcat_id=6'>"._MA_XOOPPSMAIL."</a></h3>
</div>
	
    
     <div class='form-group col-md-12'>
".$boxsetup."
 		 	 		
 		 	 		
   	<form method='post'  action='{$_SERVER['PHP_SELF']}'>	  
     ".$table."
     	 
     
     
     </div>

    <div class='row'>
  <div class='col-md-2'>	 	<select id='FriendLink' class='form-control' name='operating' >
    <option value=''  data-id='1' >"._MA_CONTACTUSTABLEPHP25."</option>
    	".$selectArrbox."   
  </select>	</div>  	 
  	     	 ".$sortArr['sortArr']."	
   <div class='col-md-1'><button class='btn btn-primary' type='submit' > "._MS_SHARED17."</button>  </div>   
     <div class='col-md-2'><a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php'>"._MS_SHARED25."</a></div>    		 	 
    	
     <div class='col-md-2'><a class='btn btn-danger active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php?operating=cleardata'>"._MA_CONTACTUSTABLEPHP28."</a></div>
    	
    	
    	 </div>        	 
     	 </form>
     	   <div class='col-sm-12'>
                  <div class='text-center'>
           	<nav>
  <ul class='pagination'> {$bar} </ul>
</nav> </div>
     	 </div>
     	 
     	 
    <script type=text/javascript src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></script>	  
    	
    <script src='".XOOPS_URL."/modules/neillibrary/js/ckeditor/ckeditor.js'></script>
<script>
CKEDITOR.replace('remarkstext' , {
toolbar : 'my' ,
skin: 'moono'	
	    });
</script>   	
<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 			  	 
     ";
 return $main;
}



//更新聯絡事項
function updatematters(){
  global $xoopsDB; 
  
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar="",$postvar=$_POST,$sqltags=array("contactmatters","remarkstext"));  
  
$setvar="set contactmatters='{$_POST['contactmatters']}' , remarkstext='{$_POST['remarkstext']}'  where nsn='1'";
update($dbname="neothemesconfig",$set=$setvar);
}



function snidup(){  //更改為已讀
  global $xoopsDB; 


foreach(cuttingfunction($cutting=$_POST['sortArr'],$sign=",") as  $val){
$keyname[$val]="readtrue".$val;	
if(!empty($_POST[$keyname[$val]])){ 
$setvar="set readtrue='".$_POST[$keyname[$val]]."'   where cfid='".$val."'";
update($dbname="neocontactusform",$set=$setvar); 
}
	}




	}





function sniddelete(){  //刪除
  global $xoopsDB;   
foreach(cuttingfunction($cutting=$_POST['sortArr'],$sign=",") as  $val){
$keyname[$val]="readtrue".$val;	
if(!empty($_POST[$keyname[$val]])){ 
deletefunction($where=" where `cfid` = '".$val."'",$dbneme="neocontactusform");  
}
	}

	}

//清空資料
function cleardata(){
truncatefunction($DBname="neocontactusform");
}



loadModuleAdminMenu(9);
echo $main;

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