<?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";	


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

//切割$setting陣列內容
$variablesplit=cuttingfunction($cutting=$variableok,$sign=";"); 
$xoops_theme = $GLOBALS['xoopsConfig']['theme_set'];



//允許傳送變數
$allowvar =array("op","nsn","url","blocktitle");

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





switch ($op){
   case "changelist":
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/playeradmin.php?op=default".changelist()."" ,0 , _MS_SHARED02);      
  break;   

 case "save_news":   
if(empty($_POST['content']))   redirect_header($_SERVER['PHP_SELF'],0 , _MS_SHARED90);   //空值判斷 	 
	 
redirect_header($_SERVER['PHP_SELF'].save_news(),0 , _MA_PLAYERADMINPHP07);   
break;

 case "updated":   
if(empty($_POST['content']))   redirect_header($_SERVER['PHP_SELF'].'?nsn='.$nsn.'',0 , _MS_SHARED90);   //空值判斷 
 redirect_header($_SERVER['PHP_SELF'].updated(),0 , _MS_SHARED02);   
break;
 
 default:

$main=playera_table();
}


function playera_table(){	
 global $xoopsDB,$variablesplit,$xoops_theme,$xoopsModule,$nsn,$url,$blocktitle;	
 
 
//判斷傳入值
if(!empty($url)) $neothemesflashlist['url']=base64_decode($url);
if(!empty($blocktitle)) $neothemesflashlist['content']=$blocktitle; 

$img_date = date("H:i:s");
if(empty($nsn)){  //新增
$playera_table_form['7']="<h3>"._MA_NEODWADMIN_NEWFLASHIMAGE."</h3>";
//POST類型
$playera_table_form['9']="<input type='hidden' name='op' value='save_news'>";
$neothemesflashlist['enable']=1;
$neothemesflashlist['target']=0;

}else{  //編輯
$playera_table_form['7']="<h3>"._MA_PLAYERADMINPHP11."</h3>";

//開啟neothemesflash資料表
$dbneme="neothemesflash";
$where="  where `nsn` = '".$nsn."'";  //where數值
//$neothemesflashlist=moduledb($dbneme,$where);
//批次轉換htmlspecialchars
$neothemesflashlist=htmlspecialcharsbatch($allowvar=array("content","url"),$eachvar=moduledb($dbneme,$where));

//檔名
$imgid="p".$neothemesflashlist['nsn']."";

//已上傳圖片
$playera_table_form['8']="<div class='form-group'>
	 <div class='col-sm-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/".$xoops_theme."/".$imgid.".png?state=".$img_date."' >
     </div></div>
	
   
  
		 <br /></div> 
</div>";

//POST類型
$playera_table_form['9']="<input type='hidden' name='op' value='updated'><input type='hidden' name='nsn' value='".$neothemesflashlist['nsn']."'>";
}


//圖片標題
$playera_table_form['0']=inputtext($class="",$name="content",$value="".$neothemesflashlist['content']."",$placeholder=""._MD_CONTACTENTER.""._MA_PLAYERADMINPHP03."",$id="");	
//圖片連結
$playera_table_form['1']=inputtext($class="",$name="url",$value="".$neothemesflashlist['url']."",$placeholder=""._MD_CONTACTENTER.""._MA_PLAYERADMINPHP04."",$id="");	

//圖片開啟方式
$playera_table_form['2']=radioinline($class="",$name="target",$text=array(_MS_SHARED31,_MS_SHARED32),$checked="".$neothemesflashlist['target'].""); 

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

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

//TABLE區塊
$dbneme="neothemesflash";
$where="  order by  nnumber  ASC"; 
$neothemesflashArr=databasetablewhile($dbneme,$where);  
foreach($neothemesflashArr as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="nnumber".$neothemesflashArr[$key]['nsn']."",$value="".$neothemesflashArr[$key]['nnumber']."",$placeholder="");	
//圖片
$td['img']="<div  class='thumbnail'><img title='".$neothemesflashArr[$key]['content']."'  src='".XOOPS_URL."/uploads/".$xoops_theme."/p".$neothemesflashArr[$key]['imgid'].".png?state=".$img_date."'></div>";
//狀態

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

//頁面開啟方式
$td['target']=pagemethod($types=$neothemesflashArr[$key]['target']);

if($neothemesflashArr[$key]['nsn']==$nsn){
$colorstyle[$key]="class='color1'";
}

	
$playera_table_form['6'].="<tr id='deletetr{$key}' ".$colorstyle[$key].">
        <td>".$td['nnumber']."</td>
        <td>".$td['img']."</td>
        <td>".$td['target']['text']."</td>
         <td>".$neothemesflashArr[$key]['post_date']."</td>
        <td>".$td['enable']."</td>
        <td>  <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/playeradmin.php?nsn=".$neothemesflashArr[$key]['nsn']."'  class='btn btn-sm btn-info  active'>"._MS_SHARED08."</a>   
      <a id='deletebotton{$key}' type='button' mane='156,".$neothemesflashArr[$key]['nsn'].",".$neothemesflashArr[$key]['content'].","._MA_PLAYERADMINPHP10.",,neothemesflash,".$xoopsModule->getVar("dirname").",,nsn'  class='btn btn-sm btn-danger   deleteeach'>"._MS_SHARED09."</a>     
  
      </tr>";
}

 
$playera_table_form['5']="
<table class='table basictable'>
    <thead>
      <tr>
      
        <th style='width: 9%'>"._MA_MARQUEETABLEPHP07."</th>
        <th style='width: 25%'>"._MA_PLAYERADMINPHP09."</th>
           <th style='width: 12%'>"._MA_MARQUEETABLEPHP09."</th>
            <th style='width: 14%'>"._MS_SHARED33."</th> 
               <th style='width: 10%'>"._MS_SHARED10."</th>  
                 <th style='width: 17%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$playera_table_form['6']."
     
    </tbody>
  </table>
";
 
$main.="<div class='container'>
  <h4>"._MA_PLAYERADMINPHP01."&nbsp;<label for='sel2'>themes Picture player admin</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/playeradmin.php'>"._MS_SHARED25."</a> </h4>	
    <div class='row'>
    ";
//左邊區塊
$main.="
<form method='post'  action='{$_SERVER['PHP_SELF']}' enctype='multipart/form-data'>	
  <div class='col-md-5'>".$playera_table_form['7']."<hr />
 
 
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP03."</label>
 		 <div class='col-sm-9'> ".$playera_table_form['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 
 
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP04."</label>
 		 <div class='col-sm-9'> ".$playera_table_form['1']." 
  	   <br /></div> 
 	 <hr />	</div> 	

<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP05."</label>
 		 <div class='col-sm-9'> ".$playera_table_form['2']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	

 
  <div class='form-group'>
    <label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP02."</label>   
     <div class='col-sm-9'>
    ".$playera_table_form['3']." <span id='helpBlock' class='help-block'>".$variablesplit['4']."</span>
     <div class='preview'></div>  
  
           </div> </div>
  <hr /> 
  			   
 ".$playera_table_form['8']." 			   	  
  	  
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_PLAYERADMINPHP06."</label>
 		 <div class='col-sm-9'> ".$playera_table_form['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
  	  
 
  ".$playera_table_form['9']."	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
  	  
  	  </div>
   </form> 	<br />  
  	  
    ";
//右邊區塊
$main.="
  <form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-7'><h3>"._MA_PLAYERADMINPHP08."</h3><hr />
  	  ".$playera_table_form['5']."
  	  
  
 
  	    <button  type='submit' name='op' value='changelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
    
  
    	  </div>
  	  	  
  	     </form> 
  	     	 
    ";
$main.="
</div>
	<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 
<script>previewfunction();</script>		
	";
 
if(!empty(modulesmidvar($modulesid="xLanguage",$var="isactive"))){
$main.="<script>neillibrary_llanguagetext(afterid='#buttonbar');</script>";
}
	
	


  return $main;
}

//編輯圖片
function updated(){
 global $xoopsDB,$variablesplit,$xoops_theme,$nsn;	
 
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar=array("url"),$postvar=$_POST,$sqltags=array("content"));   

 
$setvar="set content='{$_POST['content']}',url='{$_POST['url']}',target='{$_POST['target']}',imgid='".$nsn."',themesid='{$xoops_theme}',enable='{$_POST['enable']}'  where nsn='".$nsn."'";
update($dbname="neothemesflash",$set=$setvar);  
 
//製作圖片
if(!empty($_FILES['upfile']['name'])){ 	
save_pic($up_id="p".$nsn."",$width=$variablesplit[12],$height=$variablesplit[13],$modules="".$xoops_theme."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false,$upfile=$_FILES['upfile'],$type="1");
}
}


//新增圖片
function save_news(){
 global $xoopsDB,$variablesplit,$xoops_theme;	
 

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

$valuesvar="(nnumber,content,url,target,post_date,imgid,themesid,enable) values('0', '".$_POST['content']."', '".$_POST['url']."', '".$_POST['target']."', '".timedate($datevar="Y-m-d H:i:s")."', 'NULL', '".$xoops_theme."', '".$_POST['enable']."')";	  
$nsn=insert($dbname="neothemesflash",$values=$valuesvar);

//檔名
$imgid="p".$nsn."";
//製作圖片
if(!empty($_FILES['upfile']['name'])){ 	
//檔名
save_pic($up_id=$imgid,$width=$variablesplit[12],$height=$variablesplit[13],$modules="".$xoops_theme."",$plural=false,$convert="png",$arr=false,$process=1,$crop=false,$upfile=$_FILES['upfile'],$type="1");
}


//存入排序
$setvar="set nnumber='".$nsn."' , imgid='".$nsn."'  where nsn='".$nsn."'";
update($dbname="neothemesflash",$set=$setvar);


}






//變更排序
function changelist(){

$dbneme="neothemesflash";
$where=" order by  nnumber  DESC";
$sort=databasetablewhile($dbneme,$where);

foreach($sort as $key=> $val){
$digital= 'nnumber'.$sort[$key]['nsn'];   
	
$setvar="set nnumber='{$_POST[$digital]}'   where nsn='".$sort[$key]['nsn']."'";
update($dbname="neothemesflash",$set=$setvar); 
}


}




loadModuleAdminMenu(5);
echo $main;

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