<?php
$addon_path="../../";

include $addon_path."includes/config.php";
include $addon_path."includes/database.php";
include $addon_path."includes/keyword.php";
include $addon_path."includes/function.php";
include $addon_path."includes/session.php";

?>

<html>
<head>
<title><?php echo $sys_browser_title; ?></title>
<LINK REL="SHORTCUT ICON" HREF="images/pcart_logo.png" >

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

        
<meta http-equiv=content-type content="text/html; charset=GB2312">
    
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath1; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath2; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath3; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath4; ?>" rel=stylesheet >
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath5; ?>" rel=stylesheet >


<LINK href="<?php print $addon_path.$fontPath; ?>" rel=stylesheet>
    
    
    
    
    
<script language="javascript" src="<?php print $addon_path.$jsPath1; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath2; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath3; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath4; ?>"></script>
   
</head>


<script language="javascript" src="../../plugin/jquery/jquery-3.2.1.min.js" ></script>
<script language="javascript" src="../../plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js" ></script>


<link rel="stylesheet" href="../../plugin/jquery-ui-1.12.1.custom/jquery-ui.theme.css">
  
  <style>
  #sortable { list-style-type: none; margin: 0; padding: 0; width: 480px; }
  #sortable li { margin: 10px; font-size:12px;padding: 10px;  padding-top:10px;height: 36px; text-align:left;}
  
  </style>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#sortable" ).sortable();
    
    $( "#sortable" ).sortable({
	  axis: "y"
	});

    $( "#sortable" ).disableSelection();
  } );
  
  
  function compute_list()
  {
	var sortedIDs = $( "#sortable" ).sortable( "toArray" );  
	//alert(sortedIDs);  
	
	document.export_column_form.cols.value=sortedIDs;
	document.export_column_form.submit();
  }
  
  
  
  
  </script>



  
 <?php 
 
 
 
 //ksort($header_col);
 
 
 
 //========================PHP Processing====================================== 
  if ($_SERVER[REQUEST_METHOD] == 'POST') {
	  
	  
	  //clear all:
	  $query_clear ="delete from t_".$key_table_prefix."_export_setting_return ";
	  $result_clear = mysqli_query($dbconn,$query_clear);
	  
	 
	  
	  //-----------------------------------------------------------
	  
	  $column_array = explode(",",$_REQUEST["cols"]);
	  
	  $counter=1;
	  foreach($column_array as $column_field)
	  {
		
		$query_insert="insert into t_".$key_table_prefix."_export_setting_return 
				(
					exp_sorting,
					exp_field,
					exp_name,
					exp_status,
					created_date,
					modified_date
					
				)
				VALUES
				(
					'".$counter."',
					'".$column_field."',
					'".$_REQUEST["name_".$column_field]."',
					'".$_REQUEST["status_".$column_field]."',
					'".date("Y-m-d H:i:s")."',
					'".date("Y-m-d H:i:s")."'
					
					)
				";
		$result_insert = mysqli_query($dbconn,$query_insert);
		echo mysqli_error($dbconn);
		
		
		
		  
		  
		  $counter++;
		  
	  }
	  
	  
	  
	  
	  
	  
	  
	  displaymessage("Saved","CREATED");
	  
  
  
  
  }
  
  
  
  
  $query_get = "select * from t_".$key_table_prefix."_export_setting_return order by exp_sorting ";
  $result_get = mysqli_query($dbconn,$query_get);
  if(mysqli_num_rows($result_get)>0)
  {
	  
	while($line_get = mysqli_fetch_array($result_get,MYSQLI_ASSOC))
	{
	    
	    $header_col[$line_get["exp_field"]] = $line_get["exp_field"];
	    $header_col_status[$line_get["exp_field"]] = $line_get["exp_status"];
	    $header_col_name[$line_get["exp_field"]]=$line_get["exp_name"];
	  
  	}
  }
  else {
	  
	  
  }
  
  
  
  $query="describe t_".$key_table_prefix."_return_header; ";
  $result = mysqli_query($dbconn,$query);
  echo mysqli_error($dbconn);
  while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
  {
	 
	 if(substr($line["Field"],0,4)=="rth_")
	 {
			$header_col[$line["Field"]]=$line["Field"];
			if($header_col_name[$line["Field"]]=="")
			{
					$header_col_name[$line["Field"]]=$line["Field"];
			}
			
	 }
	 
	 
  }
  
  
  
  
  $query="describe t_".$key_table_prefix."_return_item; ";
  $result = mysqli_query($dbconn,$query);
  echo mysqli_error($dbconn);
  while($line = mysqli_fetch_array($result,MYSQLI_ASSOC))
  {
	 
	 if(substr($line["Field"],0,4)=="rti_")
	 {
			$header_col[$line["Field"]]=$line["Field"];
			if($header_col_name[$line["Field"]]=="")
			{
					$header_col_name[$line["Field"]]=$line["Field"];
			}
			
	 }
	 
	 
  }
  
  
  //========================PHP Processing======================================

  
  
  
  
echo "<form name='export_column_form' action='interface.php' method='POST'>";
echo "<input type=hidden name='cols' value='' >";
echo "<br>";
echo "<input type=button class='button button-blue' value='Save Setting' onclick=\"compute_list()\" align=left >";
	
echo "<div style='padding:3px;margin:3px;width:500px;text-align:center;overflow:hidden;' align=left >";

	 
	echo "<ul id='sortable'>";
		
	
	
	foreach($header_col as $col_key => $col_value)
	{
		
		echo "<li class=\"ui-state-default\" id='".$col_key."' >";
		
		echo "<div style='float:right;margin-right:10px;width:200px;'>";
		
		if($header_col_status[$col_key]=="YES")
		{
			echo "<input type=checkbox  name='status_".$col_key."' value='YES' checked> ";
		}
		else {
			echo "<input type=checkbox  name='status_".$col_key."' value='YES' > ";
		}
		
		echo "<input type=text class='textbox textbox-m' name='name_".$col_key."' value='".$header_col_name[$col_key]."' > ";
		echo "</div>";
		
			echo "<span class='fa fa-bars' style='margin:5px;'></span>";
			echo "".$col_key."";
			
		
			
			
		echo "</li>";
		
	}
	
	 
		
		
	echo "</ul>";
	 
	 
	 
	 
echo "</div>";
echo "</form>";
 
 
?>
 


<?php
include $addon_path."includes/end.php";
?>
