<?php
require("../../inc/header.inc");
require("../generalCsta/function.inc");
?>

<?php
echo "<form action=\"$PHP_SELF\" method=\"post\">";
$generalConf=parse_ini_file("general.conf",true);
$csvFieldName=GetRowCsv("./fieldConf/{$sysTypeNo}_name.csv");

$sql="show fields from {$generalConf[$sysTypeNo][DataTable]} where Field <> 'key_sys_id' and Field <> 'key_subsys_id' and Field <> 'key_type' and Field <> 'key_e1_tg' and Field <> 'csta_datetime' ";
$res=mysqli_query($pubConn,$sql);
$num=mysqli_num_rows($res);

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	unlink("./fieldConf/{$sysTypeNo}_flag.csv");
	$content="";
	for($i=0;$i<$num;$i++)
	{
		$param="field_$i";
		$value=$$param;
		//echo "$i={$value}<br>";
		if(strcasecmp($value,"on"))
			$content.="0";
		else
			$content.="1";
		if($i != ($num-1))
			$content.=",";
	}
	$content.="\n";
	file_put_contents("./fieldConf/{$sysTypeNo}_flag.csv",$content);
	
	echo "<script language=\"JavaScript\">\n";
	echo "window.close();\n";
	echo "</script>\n";
}

echo "{$generalConf[$sysTypeNo][PageTitle]}<br><br>";
echo "<b>Please select the fields to browse</b><br>";
echo "<table border=0 width=\"70%\">";
echo "<tr bgcolor=\"#E6E6E6\">";
echo "<td width=\"60%\">Name</td>";
echo "<td width=\"10%\">Flag</td>";
echo "</tr>";

$csvData=GetRowCsv("./fieldConf/{$sysTypeNo}_flag.csv");
if(0)
{
	echo "<pre>";
	print_r($csvData);
	echo "</pre>";
}

for($i=0;$i<$num;$i++)
{
	$row=@mysqli_fetch_array($res);
	echo "<tr>";
	echo "<td>{$csvFieldName[$i]}</td>";
	echo "<td>";
	if($csvData[$i] != 0)
		echo "<input type=\"checkbox\" checked name=\"field_$i\">";
	else
		echo "<input type=\"checkbox\" name=\"field_$i\">";
	echo "</td>";
	echo "</tr>";
}

echo "</table>";

echo "<br>";
echo "<input type=\"submit\" name=\"save\" value=\"Save\" class=\"button\">";
echo "<input type=\"hidden\" name=\"sysTypeNo\" value=\"$sysTypeNo\">";

echo "</form>";
?>
