<?php
foreach(array_keys($_FILES) as  $val){	
if(!empty($_FILES[$val]['name'])  &&  !is_array($_FILES[$val]['type'])){	
$_FILES[$val]['name']=strtotime(date("Y-m-d H:i:s")).'.'.substr(strrchr($_FILES[$val]['name'], '.'), 1);
}
}

include_once 'header.php'; //XOOPS檔頭
include_once "../function.php";	
include_once "../class/themeset.php";
//上傳圖檔
include_once XOOPS_ROOT_PATH."/modules/neillibrary/class/imguploader.php";	

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


//先建構class($themesetclass)
$themesetclass   = new  themesetclass;  
$topvsplit =$themesetclass-> themespublicb($variableok,$setting); 
list($variableok,$setting) = $topvsplit;

//切割$setting陣列內容
$variablesplit=cuttingfunction($cutting=$variableok,$sign=";"); 


switch ($op){
 case "save_news":  
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=textblock_table();
}


function textblock_table(){	
global $xoopsDB,$xoopsModule,$textid;	
 
$img_date = date("H:i:s");
if(empty($textid)){  //新增
$textblock_table_form['7']="<h4>"._MA_TEXTBLOCKPHP02."</h4>";
//POST類型
$textblock_table_form['9']="<input type='hidden' name='op' value='save_news'>";
$neil_textblock['enable']=1;
$neil_textblock['target']=0;
}else{  //編輯
$textblock_table_form['7']="<h4>"._MA_TEXTBLOCKPHP03."</h4>";

//開啟neil_textblock資料表
//批次轉換htmlspecialchars
$neil_textblock=htmlspecialcharsbatch($allowvar=array("title","url","content"),$eachvar=moduledb($dbneme="neil_textblock",$where="  where `textid` = '".$textid."'"));

if(!empty($neil_textblock['imgid'])){
//已上傳圖片
$textblock_table_form['10']="<div id='imgidbox' class='form-group'>
	 <div class='col-md-12'> 
   <div class='text-center'> <h4><span id='helpBlock' class='help-block'>"._MA_PLAYERADMINPHP12."</span></h4> </div> 	
  <div class='row'>
    <div class='thumbnail'>   
        <img src='".XOOPS_URL."/uploads/".$xoopsModule->getVar("dirname")."/".$neil_textblock['imgid'].".png?state=".$img_date."' >
     </div></div>
	
   
  
		 <br /></div> 
</div>";
}

//POST類型
$textblock_table_form['9']="<input type='hidden' name='op' value='updated'><input type='hidden' name='textid' value='".$neil_textblock['textid']."'>";
}


//標題
$textblock_table_form['0']=inputtext($class="",$name="title",$value="".$neil_textblock['title']."",$placeholder=""._MS_SHARED21._MA_TEXTBLOCKPHP04."");

//上傳圖檔
$textblock_table_form['1']=typefile($multiple=false,$name="upfile",$id="blockimg",$class=""); 

//圖檔結
$textblock_table_form['2']=inputtext($class="",$name="url",$value="".$neil_textblock['url']."",$placeholder=""._MS_SHARED21._MA_TEXTBLOCKPHP05."");

//內容說明
$textblock_table_form['3']=inputtextarea($class="content",$name="content",$id="content",$rows="10",$cols="80",$value=$neil_textblock['content']); 


//連結開啟方式
$textblock_table_form['4']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked=$neil_textblock['target']); 


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


//TABLE區塊

$neil_textblockArr=databasetablewhile($dbneme="neil_textblock",$where="  order by  btnsort  ASC");  

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

$td['enable']=enable($envar=$neil_textblockArr[$key]['enable']);
$td['img']="<div  style='width: 100%'  class='thumbnail'><img title='".$neil_textblockArr[$key]['title']."'  src='".XOOPS_URL."/uploads/".$xoopsModule->getVar("dirname")."/".$neil_textblockArr [$key]['imgid'].".png?state=".$img_date."'></div>";
//頁面開啟方式
$td['target']=pagemethod($types=$neil_textblockArr[$key]['target']);

if($neil_textblockArr[$key]['textid']==$textid){
$colorstyle[$key]="color1";
}

	
$textblock_table_form['6'].="<tr class='deletetr{$key} tr ".$colorstyle[$key]."' id='".$neil_textblockArr[$key]['textid']."'  >
        <td>".$neil_textblockArr[$key]['textid']."</td>
        <td >".$td['img']."</td>
        <td>".$neil_textblockArr[$key]['title']."</td>        	
        <td>".$td['enable']."</td>
       <td>".$td['target']['text']."</td>       	
        <td><a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/".basename(__FILE__)."?textid=".$neil_textblockArr[$key]['textid']."'  class='btn btn-sm btn-info'>"._MS_SHARED08."</a>   
     <a id='deletebotton{$key}' type='button' mane='156,".$neil_textblockArr[$key]['textid'].",".$neil_textblockArr[$key]['unit'].","._MA_ADDRESS08.",,neil_textblock,".$xoopsModule->getVar("dirname").",,textid'  class='btn btn-sm btn-danger   deleteeach'>"._MS_SHARED09."</a>     
     </tr>";
}

 
$textblock_table_form['5']="
<table class='table sortable basictable' name='164,".$xoopsModule->getVar("dirname").",".$menutype.",".$pageid.",".$typesid.",".$sortid.",".$suid.",neil_textblock,textid'>
    <thead>
      <tr>
      
        <th style='width: 5%'>"._MS_SHARED06."</th>
        <th style='width: 15%'>"._MA_TEXTBLOCKPHP08."</th>
        <th style='width: 15%'>"._MA_TEXTBLOCKPHP04."</th>
              <th style='width: 6%'>"._MS_SHARED10."</th>  
                    <th style='width: 8%'>"._MA_PLAYERADMINPHP05."</th>        
                 <th style='width: 12%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$textblock_table_form['6']."
     
    </tbody>
  </table>
   <p  class='help-block text-center'>"._MS_SHARED143."</p>	   		
";
 
$main.="

	<div class='container'>
  <h4>"._MA_TEXTBLOCKPHP01."&nbsp;<label for='sel2'>Introduction block management</label>&nbsp; <a class='btn btn-warning'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/".basename(__FILE__)."'>"._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='textblockbox' class='col-md-5'>".$textblock_table_form['7']."<hr />
<form method='post'  action='{$_SERVER['PHP_SELF']}' enctype='multipart/form-data'>	 
 

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_TEXTBLOCKPHP04."</label>
 		 <div class='col-md-9'> ".$textblock_table_form['0']." 
 	<span id='helpBlocktitle' class='red blockeach4'>"._MS_SHARED22."</span>
  	   <br /><br /></div> 
 	 	</div>

  <div class='row'>
    <label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP02."</label>   
     <div class='col-md-9'>
    ".$textblock_table_form['1']." 
      	<span id='helpBlockimgid' class='red blockeach4'>"._MS_SHARED22."</span> 
     <div class='preview' name=true></div>  
  <br />
           </div> </div>
".$textblock_table_form['10']."


<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_TEXTBLOCKPHP05."</label>
 		 <div class='col-md-9'> ".$textblock_table_form['2']." 
  	   <br /></div> 
 		</div> 	
 
 
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_BLOCKMENUSORTPHP13."</label>
 		 <div class='col-md-9'> ".$textblock_table_form['4']." 
  	   <br /><br /></div> 
 		</div> 	 
 
 
<div  class='row'>	
<label class='col-md-12 control-label'>"._MA_TEXTBLOCKPHP06."</label>
 		 <div class='col-md-12'> ".$textblock_table_form['3']." 
<span id='helpBlockcontent' class='red blockeach4'>"._MS_SHARED22."</span>	
  	   <br /><br /></div> 
 		</div> 	
 	
<div  class='row'>	
<label class='col-md-3 control-label'>"._MS_SHARED44."</label>
 		 <div class='col-md-9'> ".$textblock_table_form['8']." 
  	   <br /><br /></div> 
 		</div> 	 	   	  
   

  	  
 
  ".$textblock_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-7'><h4>"._MA_TEXTBLOCKPHP07."</h4><hr />
  	  ".$textblock_table_form['5']."
    	  </div>
  	  	  

  	     	 
    ";
$main.="
</div>



<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>  
<script src='".XOOPS_URL."/modules/neillibrary/js/ckeditor/ckeditor.js'></script>
<script>
CKEDITOR.replace('content' , {
toolbar : 'my' ,
skin: 'moono'	
	    });
</script>  
<script>neothemesadmin_textblockform();previewfunction();</script>
	";
 
 
if(!empty(modulesmidvar($modulesid="xLanguage",$var="isactive"))){
$main.="<script>neillibrary_llanguagetext(afterid='#buttonbar');</script>";
}	
	


  return $main;
}

//編輯簡介區塊
function updated(){
 global $xoopsDB,$variablesplit,$xoopsModule,$textid;		 

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



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


if(!empty($_FILES['upfile']['name'])){ 	
//製作圖片
save_pic($up_id="block_".$textid."",$width=$variablesplit[20],$height="0",$modules="".$xoopsModule->getVar("dirname")."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false,$upfile=$_FILES['upfile'],$type="1");
}


 
$setvar="set 
title='{$_POST['title']}',
url='{$_POST['url']}',
target='{$_POST['target']}',
content='{$_POST['content']}',
enable='{$_POST['enable']}'
where textid='".$textid."'";
update($dbname="neil_textblock",$set=$setvar);  
}


//新增簡介區塊
function save_news(){
 global $xoopsDB,$variablesplit,$xoopsModule;	

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



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

$valuesvar="(
title,url,target,imgid,content,btnsort,enable) 
values(
'{$_POST['title']}','{$_POST['url']}','{$_POST['target']}','','{$_POST['content']}','0','{$_POST['enable']}'
)";	  


$textid=insert($dbname="neil_textblock",$values=$valuesvar);


if(!empty($_FILES['upfile']['name'])){ 	
//製作圖片
save_pic($up_id="block_".$textid."",$width=$variablesplit[20],$height="0",$modules="".$xoopsModule->getVar("dirname")."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false,$upfile=$_FILES['upfile'],$type="1");
}

//儲存圖檔檔名
$setvar="set imgid='block_".$textid."'   where textid='".$textid."'";
update($dbname="neil_textblock",$set=$setvar); 


}



loadModuleAdminMenu(12);



echo $main;

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

	
	?>