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


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


//取得模組mid值 
$mid=modulesmidvar($modulesid="neothemesadmin");


switch ($op){
   case "changelist":
$urlstring=changelist();  
redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/admin/randomidiom.php?op=default".$urlstring."" ,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 ,_MS_SHARED02);   
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=custommenu_table();
}


function custommenu_table(){	
 global $xoopsDB,$xoopsModule,$nsn,$url,$mid;	
 


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

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

//開啟neilrandomidiom資料表
$dbneme="neilrandomidiom";
$where="  where `nsn` = '".$nsn."'";  //where數值
//$neilrandomidiom=moduledb($dbneme,$where);

//批次轉換htmlspecialchars
$neilrandomidiom=htmlspecialcharsbatch($allowvar=array("content","author","icom"),$eachvar=moduledb($dbneme,$where));



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


//隨機小語內容
$table_form['0']=inputtextarea($class="",$name="content",$id="",$rows="10",$cols="80",$value=$neilrandomidiom['content']); 

//作者
$table_form['1']=inputtext($class="",$name="author",$value="".$neilrandomidiom['author']."",$placeholder=""._MA_NEILRANDOMIDIOM06."");


//顏色
$table_form['2']=inputtext($class="",$name="color",$value="".$neilrandomidiom['color']."",$placeholder=""._MA_NEILRANDOMIDIOM11."",$id="color");
//選擇器
$table_form['8']=inputtext($class="",$name="color",$value="#ff0000",$placeholder=""._MA_NEILRANDOMIDIOM11."",$id="colorWell",$typeval="color");

//ICON
$table_form['3']=inputtext($class="",$name="icom",$value="".$neilrandomidiom['icom']."",$placeholder=""._MA_NEILRANDOMIDIOM13."");


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

//TABLE區塊
$dbneme="neilrandomidiom";
$where="  order by  snid  ASC"; 
$neilrandomidiomArr=databasetablewhile($dbneme,$where);  
foreach($neilrandomidiomArr as $key=> $val){
	
//排序
$td['nnumber']=inputtext($class="",$name="snid".$neilrandomidiomArr[$key]['nsn']."",$value="".$neilrandomidiomArr[$key]['snid']."",$placeholder="");	


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



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

	
$table_form['6'].="<tr id='deletetr{$key}' ".$colorstyle[$key].">
        <td>".$td['nnumber']."</td>
        <td>".$neilrandomidiomArr[$key]['content']."<br>".sprintf(_MA_NEILRANDOMIDIOM08,$neilrandomidiomArr[$key]['author'])."</td>
        <td>".$neilrandomidiomArr[$key]['setuptime']."</td>	
        <td>".$td['enable']."</td>
        <td>  <a href='" .XOOPS_URL. "/modules/". $xoopsModule->getVar("dirname")."/admin/randomidiom.php?nsn=".$neilrandomidiomArr[$key]['nsn']."'  class='btn btn-sm btn-info  active'>"._MS_SHARED08."</a>   
        <a id='deletebotton{$key}' type='button' mane='133,".$neilrandomidiomArr[$key]['nsn'].",".strip_tags($neilrandomidiomArr[$key]['content']).","._MA_NEILRANDOMIDIOM15."'  class='btn btn-sm btn-danger  active deleteeach'>"._MS_SHARED09."</a></td>
      </tr>";
}

 
$table_form['5']="
<table class='table basictable'>
    <thead>
      <tr>
      
        <th style='width: 6%'>"._MA_MARQUEETABLEPHP07."</th>
        <th style='width: 30%'>"._MA_NEILRANDOMIDIOM04."</th>
           <th style='width: 9%'>"._MA_NEILRANDOMIDIOM07."</th>

               <th style='width: 6%'>"._MS_SHARED10."</th>  
                 <th style='width: 12%'>"._MS_SHARED07."</th>  
      </tr>
    </thead>
    <tbody>
   ".$table_form['6']."
     
    </tbody>
  </table>
";
 
$main.="

	<div class='container'>
  <h4>"._MA_NEILRANDOMIDIOM01."&nbsp;<label for='sel2'>Random small language management</label>&nbsp; <a class='btn btn-warning active'  href='" . XOOPS_URL . "/modules/".$xoopsModule->getVar("dirname")."/admin/randomidiom.php'>"._MS_SHARED25."</a>&nbsp; <a class='btn btn-info active'  href='" . XOOPS_URL . "/modules/system/admin.php?fct=blocksadmin&op=list&filter=1&selgen=".$mid."&selmod=-1&selgrp=-1&selvis=-1'>"._MA_BLOCKMENUSORTPHP02."</a> </h4>	
    <div class='row'>
    ";
//左邊區塊
$main.="
<form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-5'>".$table_form['7']."<hr />
 
 
 
<div  class='form-group'>	
<label class='col-sm-12 control-label'>"._MA_NEILRANDOMIDIOM04."</label>
 		 <div class='col-sm-12'> ".$table_form['0']." 
  	   <br /></div> 
 	 <hr />	</div> 	
 
 

<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_NEILRANDOMIDIOM06."</label>
 		 <div class='col-sm-9'> ".$table_form['1']." 
  	   <br /></div> 
 	 <hr />	</div> 	


<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_NEILRANDOMIDIOM11."</label>
<div class='col-sm-5'>".$table_form['2']." 	<span id='helpBlock' class='help-block'>"._MA_NEILRANDOMIDIOM12."</span></div>
<div class='col-sm-4'>".$table_form['8']."</div>
<hr /></div>
 	
 	
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_NEILRANDOMIDIOM13."</label>
 		 <div class='col-sm-9'> ".$table_form['3']." 
 	<span id='helpBlock' class='help-block'>"._MA_NEILRANDOMIDIOM14."</span>
  	   <br /></div> 
 	 <hr />	</div> 	 	
 	
			   	  
  	  
<div  class='form-group'>	
<label class='col-sm-3 control-label'>"._MA_NEILRANDOMIDIOM05."</label>
 		 <div class='col-sm-9'> ".$table_form['4']." 
  	   <br /><br /></div> 
 	 <hr />	</div> 	
  	  
 
  ".$table_form['9']."	
 <button  type='submit' class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED01."</button>
  	  
  	  </div>
   </form> 	  
  	  
    ";
//右邊區塊
$main.="
  <form method='post'  action='{$_SERVER['PHP_SELF']}' >	
  <div class='col-md-7'><h3>"._MA_NEILRANDOMIDIOM09."</h3><hr />
  ".$table_form['5']."
  <button  type='submit' name='op' value='changelist'   class='btn btn-primary btn-lg btn-block button'>"._MS_SHARED12."</button> 
  </div>
  </form>
  </div>";

    
    
$main.="
<script>
neillibrary_colorpicker(dcolor='{$neilrandomidiom['color']}', pickerid='#colorWell',colorid='#color')
</script> 
		
<script>
    $('.basictable').basictable({
        breakpoint: 640,
        orceResponsive: true,
    });
</script> 	
	
<script src='".XOOPS_URL."/modules/neillibrary/js/ckeditor/ckeditor.js'></script>
<script> 
// 定義自訂的工具列 'my'
var myToolbar = [
            { name: 'bar1', items: ['Source'] },
            { name: 'bar2', items: ['Cut', 'Copy', 'Undo', 'Redo'] },
         // { name: 'bar3', items: ['Image', 'EqnEditor', 'Table', 'HorizontalRule', 'Smiley', 'Link', 'Unlink'] },
            { name: 'bar4', items: ['NumberedList', 'BulletedList', 'RemoveFormat', 'Syntaxhighlight', 'CodeSnippet'] },      
         // { name: 'bar5', items: ['Blockquote', 'CreateDiv'] },
            { name: 'bar6', items: ['PageBreak', 'WidgetTemplateMenu', 'Uploadcare'] },
         // { name: 'bar7', items: ['Styles', 'Format', 'Font', 'FontSize'] },
            { name: 'bar7', items: ['Styles', 'Format',  'FontSize'] },
            { name: 'bar7-1', items: ['TextColor', 'BGColor', 'Bold', 'Italic', 'Underline', 'Strike'] },
            { name: 'bar8', items: ['Outdent', 'Indent'] },
            { name: 'bar9', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
         // { name: 'bar10', items: ['Find', 'Replace', 'SelectAll', 'FontAwesome'] }

];		
CKEDITOR.replace('content', {
    toolbar: 'my',
    skin: 'moono',
    height: '220',
    // 定義 'my' 工具列
    toolbar_my: myToolbar
});
</script>	
	";

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

  return $main;
}

//編輯按鈕
function updated(){
 global $xoopsDB,$nsn;	
 
//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar="",$postvar=$_POST,$sqltags=array("author","content"));  
 
$setvar="set content='".sqlinjectionfound($var=$_POST['content'])."',author='{$_POST['author']}',enable='{$_POST['enable']}' ,color='{$_POST['color']}' ,icom='{$_POST['icom']}' where nsn='".$nsn."'";
update($dbname="neilrandomidiom",$set=$setvar);  
 

}


//新增小語
function save_news(){
 global $xoopsDB;	

//去資料表標籤-去除空白跟HTML標籤
$_POST=strip_tagsremovesqlArr($allowvar="",$postvar=$_POST,$sqltags=array("author","content"));  
 
$valuesvar="(content,author,snid,enable,color,icom) values('{$_POST['content']}','{$_POST['author']}','0','{$_POST['enable']}','{$_POST['color']}','{$_POST['icom']}')";	  
$nsn=insert($dbname="neilrandomidiom",$values=$valuesvar);


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


}






//變更排序
function changelist(){
	
$dbneme="neilrandomidiom";
$where=" order by  snid  DESC";
$sort=databasetablewhile($dbneme,$where);
foreach($sort as $key=> $val){
$digital= 'snid'.$sort[$key]['nsn'];  
$setvar="set snid='{$_POST[$digital]}'   where nsn='".$sort[$key]['nsn']."'";
update($dbname="neilrandomidiom",$set=$setvar); 

}


}




loadModuleAdminMenu(10);
echo $main;

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