<?php
print "<html>";
print "<head>";
print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/ansys/config/css/style.css\">";
print "<link rel=\"shortcut icon\" href=\"/ansys/config/favicon.ico\">";
print "<title>退避管理システム</title>";
print "</head>";

print "<body>";
print "<center>";
print "<font size=\"3\"><b>";
print "退避管理システム<br>-表示番号編集-";
print "【五洋建設株式会社】";
print "</b></font>";
print "</center>";
print "<hr />";

try
{
	$conn = pg_connect("
	host	=	192.168.100.153
	dbname	=	cnbs
	user	=	postgres
	password=	am#71ZJ*
	");
	if (!$conn)
		throw new Exception("データベースへの接続に失敗");
	
	$selectWrk = "SELECT pid, dispno, tagid, useflg FROM nakagusuku.worker_position ORDER BY dispno;";
	//print $selectWrk. "<br>";
	$res = pg_query($conn, $selectWrk);
	if (!$res)
		throw new Exception("SQLエラー");
	
	print "<center><table border=\"1\" style=\"width:80%\">";
	print "<tr bgcolor=\"#ff6666\"><th>表示番号編集</th><th>id</th><th>表示番号</th><th>タグID</th><th>使用状況</th></tr>";
	
	$rowcnt = pg_num_rows($res);
	for($i = 0; $i < $rowcnt; $i++)
	{
		$row = pg_fetch_assoc($res, $i);
		//var_dump($row);
		//print "<br>";
		print "<tr align=\"center\">";
		print "<td><a href=\"./tag.php?pid=". $row["pid"]. "\">編集</a></td>";
		print "<td>". $row["pid"]. "</td>";
		print "<td>". $row["dispno"]. "</td>";
		print "<td>". $row["tagid"]. "</td>";
		$vuseflg = strcmp($row["useflg"], "t") == 0 ? "使用中" : "未使用";
		print "<td><a href=\"./use.php?pid=". $row["pid"]. "\">". $vuseflg. "</a></td>";
		print "</tr>";
	}
	print "</table></center>";
}
catch(Exception $exc)
{
	print "<font color=\"#ff0000\">";
	print $exc. "<br>";
	print "</font>";
}
pg_close($conn);

print "<p style=\"text-align:right;\">";
print "<a href=\"../index.html\">戻る</a>";
print "</p>";
print "<hr>";
print "<center>";
print "<font size=\"3\" face=\"Arial\"><b><i>";
print "penta-ocean";
print "</i></b></font>";
print "</center>";
?>
