<?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'];

//讀取neothemesconfig資料表
$configList=moduledb($dbneme="neothemesconfig",$where=" where `nsn` = '1'");
//字串轉陣列
$fieldsplit=phpconversion($conversion=$configList['field'],$type="unserialize"); 

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

//接收變數區
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']."?op=default".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']."?op=default".updated(),0 , _MS_SHARED02);
	break;
	default:
	$main=playera_table($mid=modulesmidvar($modulesid="neothemesadmin"));
}


function playera_table($mid=""){	
global $xoopsDB,$variablesplit,$xoops_theme,$xoopsModule,$nsn,$url,$blocktitle,$typeval,$fieldsplit;	
 
$type_text=empty($typeval) ? '-'._MA_PLAYERADMINPHP13:'-'._MA_PLAYERADMINPHP14; 
$variablesplit['4']=empty($typeval) ? $variablesplit['4']: sprintf(_MA_PLAYERADMINPHP16,$fieldsplit[24],$fieldsplit[25]); 

//判斷傳入值
if(!empty($url)) $list_val['url']=base64_decode($url);
if(!empty($blocktitle)) $list_val['content']=$blocktitle; 

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

}else{  //編輯
$form_val['7']="<h4>"._MA_PLAYERADMINPHP11."<small>".$type_text."</small></h4>";

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

//檔名
$imgid=empty($list_val['typeval']) ? "p".$list_val['nsn']."" : "b".$list_val['nsn'].""; 
//資料夾
$imgfile=empty($list_val['typeval']) ? $xoops_theme : $xoopsModule->getVar("dirname"); 

//已上傳圖片
$form_val['8']="
	 <div 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/".$imgfile."/".$imgid.".png?state=".$img_date."' >
     </div></div>
	 <br /></div> 
     </div>";

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


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

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

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

//是否啟用
$form_val['4']=radioinline($class="",$name="enable",$text=array(_MS_SHARED04,_MS_SHARED03),$checked="".$list_val['enable'].""); 
 
//選擇撥放器功能
$form_val['10']=radioinline($class="",$name="typeval",$text=array(_MA_PLAYERADMINPHP13,_MA_PLAYERADMINPHP14),$checked="".$list_val['typeval']."");  


//選擇按鈕樣式
$r_Arr = array(); //建構陣列
//顯示全部
$i=0;
$r_Arr[$i]['value']="0";
$r_Arr[$i]['title']=_MA_PLAYERADMINPHP13._MS_SHARED20;
$r_Arr[$i]['url']="playeradmin.php?typeval=0";

$i++;
$r_Arr[$i]['value']="1";
$r_Arr[$i]['title']=_MA_PLAYERADMINPHP14._MS_SHARED20;
$r_Arr[$i]['url']="playeradmin.php?typeval=1";
$i++;

foreach($r_Arr as $key=> $val){
$form_val['11'].=optionselect($dataid=$r_Arr[$key]['value'],$optionname=$r_Arr[$key]['title'],$oid="".$typeval."",$value=$r_Arr[$key]['url']);

}





//TABLE區塊
$default_DB=empty($typeval) ? "`typeval` = '0'": "`typeval` = '".$typeval."'"; 
$dbneme="neothemesflash";
$where=" where ".$default_DB."  order by  nnumber  ASC"; 
foreach($img_Arr=databasetablewhile($dbneme,$where) as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="nnumber".$img_Arr[$key]['nsn']."",$value="".$img_Arr[$key]['nnumber']."",$placeholder="");	
//圖片
if(empty($typeval)){
$td['img_name']="p";
$td['img_file']=$xoops_theme;
}else{
$td['img_name']="b";
$td['img_file']=$xoopsModule->getVar("dirname");
}
	
//$td['img_name']=empty($typeval) ? "p": "b"; 

$td['img']="<div  class='thumbnail'><img title='".$img_Arr[$key]['content']."'  src='".XOOPS_URL."/uploads/".$td['img_file']."/".$td['img_name']."".$img_Arr[$key]['imgid'].".png?state=".$img_date."'></div>";
//狀態

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

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

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

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

 
$form_val['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>
   ".$form_val['6']."
     
    </tbody>
  </table>
";
 
$main.="<div class='container'>
  <h2>"._MA_PLAYERADMINPHP01."&nbsp;<label for='sel2'>Picture player admin</label>&nbsp; <a class='btn btn-warning'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/playeradmin.php'>"._MS_SHARED25."</a>&nbsp; <a class='btn btn-info'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".$mid."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a> </h2>	
   
    <div class='row'>
    ";
//左邊區塊
$main.="

  <div class='col-md-4'>".$form_val['7']."<hr />
<form method='post'  action='{$_SERVER['PHP_SELF']}' enctype='multipart/form-data'>	 
 
 
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP03."</label>
 		 <div class='col-md-9'> ".$form_val['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 
 
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP04."</label>
 		 <div class='col-md-9'> ".$form_val['1']." 
  	   <br /></div> 
 	 <hr />	</div> 	

<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP05."</label>
 		 <div class='col-md-9'> ".$form_val['2']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	

 
  <div class='row'>
    <label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP02."</label>   
     <div class='col-md-9'>
    ".$form_val['3']." <span id='helpBlock' class='help-block'>".$variablesplit['4']."</span>
     <div class='preview'></div>  
  
           </div> </div>
  <hr /> 
  			   
 ".$form_val['8']." 			   	  
  	  
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP06."</label>
 		 <div class='col-md-9'> ".$form_val['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
  	  
<div  class='row'>	
<label class='col-md-3 control-label'>"._MA_PLAYERADMINPHP15."</label>
 		 <div class='col-md-9'> ".$form_val['10']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	  	  
  	  
 
  ".$form_val['9']."	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
     </form>	  
  	  </div>
 	<br />  
  	  
    ";
//右邊區塊
$main.="

  <div class='col-md-8'>
  <form method='post'  action='{$_SERVER['PHP_SELF']}' >	  	  
  	  <h4>"._MA_PLAYERADMINPHP08.$type_text." </h4>
  	  	  <select id='FriendLink' class='form-control' >".$form_val['11']."</select>
  	  <hr /> ".$form_val['5']."
    <input type='hidden' name='typeval' value='".$typeval."'>
  	<button  type='submit' name='op' value='changelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
    
    	     </form> 
    	  </div>
  	  	  

  	     	 
    ";
$main.="
</div>
	<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 
<script>previewfunction();</script><script src='".XOOPS_URL."/modules/neillibrary/js/menujs/newbase.js'></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,$typeval,$fieldsplit,$xoopsModule;	
 
//去資料表標籤-去除空白跟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']}' ,typeval='{$_POST['typeval']}'  where nsn='".$nsn."'";
update($dbname="neothemesflash",$set=$setvar);  
 
//製作圖片
if(!empty($_FILES['upfile']['name'])){ 	
	
if(!empty($_POST['typeval'])){
//區塊撥放器
//檔名
$imgid="b".$nsn."";		
$width=$fieldsplit[24];
$height=$fieldsplit[25];
$modules=$xoopsModule->getVar("dirname");
}else{
//布景撥放器
//檔名
$imgid="p".$nsn."";		
$width=$variablesplit[12];
$height=$variablesplit[13];
$modules=$xoops_theme;
}	

	
save_pic($up_id=$imgid,$width,$height,$modules,$plural=false,$convert="png",$arr=false,$process=1,$crop=false,$upfile=$_FILES['upfile'],$type="1");
}

return combinationvar($Arrvar=array("typeval"));
}


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

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

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





//製作圖片
if(!empty($_FILES['upfile']['name'])){ 	

	
if(!empty($_POST['typeval'])){
//區塊撥放器
//檔名
$imgid="b".$nsn."";		
$width=$fieldsplit[24];
$height=$fieldsplit[25];
$modules=$xoopsModule->getVar("dirname");
}else{
//布景撥放器
//檔名
$imgid="p".$nsn."";		
$width=$variablesplit[12];
$height=$variablesplit[13];
$modules=$xoops_theme;
}		


save_pic($up_id=$imgid,$width,$height,$modules,$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);



return combinationvar($Arrvar=array("typeval"));
}






//變更排序
function changelist(){
global $typeval;	

$typeval=empty($typeval) ? '0' : $typeval; 

$dbneme="neothemesflash";
$where="  where `typeval` = '".$typeval."' 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); 
}


return combinationvar($Arrvar=array("typeval"));
}




loadModuleAdminMenu(5);
echo $main;

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