<?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?operating=setup" ,0 , _MS_SHARED02);
	break;
	
	case "setup": 
    $main=contactussetup();
	break;
	
	case "cleardata": 
	cleardata();
	redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php" ,0 , _MS_SHARED02);
	break;

   default:
   $main=contactustable();
}






//表單設定
function contactussetup(){
global $xoopsModule,$xoopsModuleConfig;	

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

//聯絡事項
$box['contactmatters']=inputtext($class="",$name="contactmatters",$value="".$listval['contactmatters']."",$placeholder=""._MA_CONTACTUSTABLEPHP07."");
//備註說明
$box['remarkstext']=inputtextarea($class="",$name="remarkstext",$id="remarkstext",$rows="0",$cols="0",$value="".$listval['remarkstext']."");   


if(empty($xoopsModuleConfig['neothemesadmin12'])){ 
for ($i=1 ; $i<=5 ; $i++ ) {
$formList[$i]=0;
}
}else{
foreach($Arr=phpconversion($conversion=$xoopsModuleConfig['neothemesadmin12'],$type="unserialize") as $key=> $val){
$formList[$key]=$val;
}
}
for ($i=1 ; $i<=7 ; $i++ ) {

if($i==7){
//$defaultform[$i]=radioinline($class="",$name="form[".$i."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$formList[$i],$id="form".$i); 
$defaultform[$i]=inputtext($class="",$name="form[".$i."]",$value=$formList[$i],$placeholder=_MS_SHARED21._MA_CONTACTUSTABLEPHP37,$id="form".$i);

}else{
$defaultform[$i]=radioinline($class="",$name="form[".$i."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$formList[$i],$id="form".$i); 
}



}





$settingsbox="
<div class='row' style='margin: 15px 0px 0px -15px;'>	
<label class='col-md-2'>"._MA_CONTACTUSTABLEPHP33."</label>
<div class='col-md-4'> ".$defaultform['1']."</div> 
<label class='col-md-2 formbox1'>"._MS_SHARED229."</label>
<div class='col-md-4 formbox1'> ".$defaultform['2']."    </div> 
</div>
	
<div class='row' style='margin: 10px 0px 0px -15px;'>		
<label class='col-md-2'>"._MA_CONTACTUSTABLEPHP35."</label>
<div class='col-md-4'> ".$defaultform['3']."</div> 
<label class='col-md-2 formbox3'>"._MS_SHARED229."</label>
<div class='col-md-4 formbox3'> ".$defaultform['4']."    </div> 	
</div>

<div class='row' style='margin: 10px 0px 0px -15px;'>	
<label class='col-md-2'>"._MA_CONTACTUSTABLEPHP37."</label>
<div class='col-md-4'> ".$defaultform['5']."</div> 
<label class='col-md-2 formbox5'>"._MS_SHARED229."</label>
<div class='col-md-4 formbox5'> ".$defaultform['6']."    </div> 	
<br /><br />	
	
<label class='col-md-2 formbox5'>"._MA_CONTACTUSTABLEPHP38."</label>
<div class='col-md-10 formbox5'> ".$defaultform['7']."
<span id='helpBlock' class='help-block'>"._MA_CONTACTUSTABLEPHP39."</span>
</div> 	
</div> 	

	

		

";

foreach(array("1","3","5") as $key=> $val){
$settingsbox.="<script>neothemesadmin_defaultformsettings(formid=".$val.");</script>";
}




$main="
	<form method='post'  action='{$_SERVER['PHP_SELF']}'>	
	<div class='container'>
    <div class='page-header'> 
    <h3>"._MA_CONTACTUSTABLEPHP31."<small> &nbsp;Contact Us Form settings</small>&nbsp;&nbsp;<a class='btn btn-danger'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php'>"._MA_CONTACTUSTABLEPHP34."</a></h3>
    </div>

    <div class='row'>    		 
   	<div class='col-md-3'><h4> "._MA_CONTACTUSTABLEPHP32."</h4></div>
    <div class='col-md-9'>".$settingsbox."<br /></div>
   	<div class='col-md-3'><h4> "._MA_CONTACTUSTABLEPHP02."</h4></div>
    <div class='col-md-9'>".$box['contactmatters']."  <span id='helpBlock' class='help-block'>"._MA_CONTACTUSTABLEPHP08."</span><br /><br /></div>
    <div class='col-md-3'><h4> "._MA_CONTACTUSTABLEPHP29."</h4></div>
    <div class='col-md-9'>".$box['remarkstext']." <br />
    <input type='hidden' name='operating' value='operating3'> 	 
    <button type='submit' class='btn btn-primary  btn-block btn-lg'>"._MS_SHARED15."</button></div>
    </div>
    
    </div>
 	</form>	 	 	
    <script src='".XOOPS_URL."/modules/neillibrary/js/ckeditor/ckeditor.js'></script>
    <script>
    CKEDITOR.replace('remarkstext' , {
    toolbar : 'my' ,
    skin: 'moono'	
	});
    $('.basictable').basictable({
    breakpoint: 640,
    orceResponsive: true,
    });	
    </script>  		 	 	
 	";

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




return $main;

}





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

	
$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']);
}







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








//解聯絡我們資料表
$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 btn-sm'  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: 8%;'>"._MA_CONTACTUSTABLEPHP16."</th> 
            <th style='width: 6%;'>"._MA_CONTACTUSTABLEPHP26."</th> 

            <th  style='width: 12%;'>"._MA_CONTACTUSTABLEPHP15."</th> 
      </tr>
    </thead>
    ".$tdbox."
    <table>

";





$main.="
  <div class='container'>	
  <div class='page-header row'> 
  <div class='col-md-2' >
  <select id='FriendLink' class='form-control' >
  <option value=''  data-id='1' >"._MA_CONTACTUSTABLEPHP06."</option>
  ".$contactustablebox."   
  </select>	
  </div> 
  <div class='col-md-10' >		        	 
  <h3>"._MA_CONTACTUSTABLEPHP01."<small> &nbsp;Contact Us Management</small>&nbsp;&nbsp; <a class='btn btn-info'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php?operating=setup'>"._MA_CONTACTUSTABLEPHP30."</a> <a target='_blank' class='btn btn-success'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/contactusform.php'>"._MA_CONTACTUSTABLEPHP36."</a> <a class='btn btn-warning' target='_blank' href='" . XOOPS_URL . "/modules/system/admin.php?fct=preferences&op=show&confcat_id=6'>"._MA_XOOPPSMAIL."</a></h3>
  </div></div>
	
    
     <div class='form-group col-md-12'>	 	 		
   	<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'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php'>"._MS_SHARED25."</a></div>    		 	 
    	
     <div class='col-md-2'><a class='btn btn-danger'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/contactustable.php?operating=cleardata'>"._MA_CONTACTUSTABLEPHP28."</a></div>
    	
    	
    	 </div>        	 
     	 </form>
     	 	 <br />

    
<nav aria-label='Page navigation example'>
  <ul class='pagination justify-content-center'>
{$bar}
  </ul>
</nav>
     	 
     	 
    <script type=text/javascript src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></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);

//聯絡表單設定
update($dbname="config",$set="set conf_value='".phpconversion($conversion=$_POST['form'],$type="serialize")."'  where conf_name='neothemesadmin12'");

}



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檔尾		
	
	?>