File "data_view.php"

Full path: /www/geye/data_view.php
File size: 37.8 KiB (38707 bytes)
MIME-type: text/html
Charset: utf-8

Download   Open   Back

<HTML>
<HEAD>
<META Http-Equiv="Content-Type" Content="text/html;charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<TITLE>検査記録</TITLE>
<LINK REL="stylesheet" HREF="pict.css" TYPE="text/css">
</HEAD>
<BODY>

<style type="text/css">
.button {
  display       : inline-block;
  border-radius : 5%;          /* 角丸       */
  font-size     : 10pt;        /* 文字サイズ */
  text-align    : center;      /* 文字位置   */
  cursor        : pointer;     /* カーソル   */
  padding       : 6px 6px;     /* 余白       */
  background    : #808080;     /* 背景色     */
  color         : #ffffff;     /* 文字色     */
  line-height   : 1em;         /* 1行の高さ  */
  width         : 100px;       /* 横幅    */
}

.td-css1 { 
    border-right-style:none;
}
.td-css2 { 
    border-left-style:none; 
} 

</style>


<script type="text/javascript">
//-------------------------------------------------------------------------------------------------
//関数(javascript)
//-------------------------------------------------------------------------------------------------
//■チェック項目の操作(ダウンロード・削除)
function DataAction(status)
{
	//チェックボタンは配列に入っている
	checks = document.getElementsByName("check");

	var data_no = null;

	for(var i = 0; i < checks.length; i++)
	{
		if(checks[i].checked)
		{
			if(data_no == null)
			{
				data_no = checks[i].value;
			}
			else
			{
				 data_no = data_no + ","  + checks[i].value ;
			}
		}
	}
	console.log(data_no);
	if(data_no != null)
	{
		
		if(status == 1)
		{
			location.href = 'data_view.php?file_dl=' + data_no;
		}
		else
		{
			location.href = "data_view.php?del=" + data_no;
		}
	}
	else
	{
		location.href = "data_view.php";
	}

}


//■確認ボタンの切り替え処理
function CheckPush(id_,no_)
{
	//チェックボタンは配列に入っている
	confirmer_ = document.getElementsByName("confirmer_reg");
	implementation_date_ = document.getElementsByName("implementation_date");
	memo_ = document.getElementsByName("memo_reg");
	
	console.log(confirmer_[id_].value);
	console.log(implementation_date_ [id_].value);
	
	var conf = confirmer_[id_].value;
	var imp = implementation_date_[id_].value;	
	var memo = memo_[id_].value;	
	if(imp)
	{
		location.href = "data_view.php?chk=" + no_ + "&conf=" + conf + "&imp=" + imp + "&memo=" + memo;
	}
	else
	{
		alert('実施日を入力して下さい。');
	}
}

function CheckPush2(id_,no_,list_no_,inspection_id_,val_ct)
{
	//チェックボタンは配列に入っている
	confirmer_ = document.getElementsByName("confirmer_reg");
	implementation_date_ = document.getElementsByName("implementation_date");
	memo_ = document.getElementsByName("memo_reg");
	//value_ = document.getElementsByName("check_text");
	//確認項目のテキスト取得

	value_ = document.getElementsByName("check_text");
	var value_t;
	value_t = value_[0].value;
	for(var i = 1; i < val_ct; i++)
	{
		value_t += "," + value_[i].value;
	}
	console.log(confirmer_[id_].value);
	console.log(implementation_date_ [id_].value);
	console.log(value_t);
	
	var conf = confirmer_[id_].value;
	var imp = implementation_date_[id_].value;	
	var value = memo_[id_].value;

//	if(imp)
//	{
	location.href = "data_view.php?id_=" + no_ + "&inspection_id_=" + inspection_id_ + "&list_no_=" + list_no_ +"&chk=" + no_ + "&conf=" + conf + "&imp=" + imp + "&memo=" + value + "&tval2=" + value_t ;
//	}
//	else
//	{
//		alert('実施日を入力して下さい。');
//	}
}

function myfunc(id,list_no,cl,ct_cl,inspection_id)
{
	confirmer_ = document.getElementsByName("check_list");
	value_ = document.getElementsByName("check_text");
  console.log(confirmer_[cl].value + "____"+confirmer_[cl].checked);
  console.log(value_[cl].value);
  
  val = confirmer_[cl].value;
  chk = confirmer_[cl].checked;
  val2 = value_[cl].value;
  item = +cl+1;
  
	location.href = "data_view.php?id_=" + id + "&inspection_id_=" + inspection_id + "&list_no_=" + list_no + "&item_no=" + item + "&val=" + val + "&chk=" + chk + "&tval=" + val2 +"#" + id;
}


</script>


<?php
//-------------------------------------------------------------------------------------------------
//関数(php)
//-------------------------------------------------------------------------------------------------
//■フォルダ内のファイル削除($dirは該当ファイルがあるディレクトリの絶対パス)
function deleteData ($dir)
{
    if ($dirHandle = opendir ($dir)) {
        while (false !== ( $fileName = readdir ($dirHandle))) 
        {
            if ($fileName != "." && $fileName != ".." ) unlink ($dir.$fileName);
        }
        closedir ($dirHandle);
    }
}

//■元画像からサムネイル画像の作成
function ThumbnailMake($tmp_dir_,$in_pict,$out_pict,$x_size,$y_size)
{
	
    list($width, $hight) = getimagesize($tmp_dir_ .$in_pict);	 // 元の画像名を指定してサイズを取得

    $baseImage = imagecreatefromjpeg($tmp_dir_.$in_pict); 	// 元の画像から新しい画像を作る準備
    $image = imagecreatetruecolor($x_size, $y_size); // サイズを指定して新しい画像のキャンバスを作成

    // 画像のコピーと伸縮
    imagecopyresampled($image, $baseImage, 0, 0, 0, 0, $x_size, $y_size, $width, $hight);

    // コピーした画像を出力する
    $name_replace = str_replace("." ,"_s.",$in_pict);
    
    $out_pict = $out_pict. $name_replace;
    imagejpeg($image , $out_pict);
}

//■ファイルのダウンロードリンク作成(テキスト・画像サムネイル)
//DlLinkMake(リンクタイプ[1:テキスト、2:画像],データid,ファイルのパス1,ファイルのパス2,表内の位置)
function DlLinkMake($dl_type_,$id_,$inspection_id,$save_dir_,$dir_path_,$chkbox_flag)
{
    $dir = $save_dir_ .$id_ .$dir_path_;
	if (is_dir($dir)) 
	{
	    if ($dh = opendir($dir)) {
	        while (($file = readdir($dh)) !== false)
	        {
	        	if ( $file != "." && $file != ".." )
	        	{
       				$time_list[] = filemtime($dir .$file);    //ソート用にファイル時刻を取得
        			$file_list[] = $file; 
				}
	        }
	        closedir($dh);
	        array_multisort($time_list,SORT_ASC,$file_list);
	    }
		$f_count = count($file_list);

		for($fct=0;$fct < $f_count;$fct++)
		{
			$fct2 = $fct+1;
			if($dl_type_ == 0)
			{
				print $file_list[$fct] ."<BR>";
			}
			else if($dl_type_ == 1)
			{
				//$list_no = filemtime($dir .$file);
				$list_no = $time_list[$fct];
				print "<a href='download.php?u=" .$dl_type_ ."&f=" .$file_list[$fct] ."&id=" .$id_ ."' target='_blank' rel='noopener'>" .$file_list[$fct] ."</a><BR>";
				print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
				print "<INPUT TYPE='submit' NAME='record_chk' VALUE='確認'> ";
				print "<INPUT TYPE='hidden' NAME='id_' VALUE='" .$id_ ."'> ";
				print "<INPUT TYPE='hidden' NAME='list_no_' VALUE='" .$list_no ."'> ";
				print "<INPUT TYPE='hidden' NAME='inspection_id_' VALUE='" .$inspection_id ."'> ";
				print "</form>";
			}
			else
			{
				$thum_name = "./inspection/" .$id_ ."/pict_s/" .str_replace("." ,"_s." ,$file_list[$fct]);
				print "<a href='download.php?u=" .$dl_type_ ."&f=" .$file_list[$fct]  ."&id=" .$id_ ."' target='_blank' rel='noopener'>";
				print "<img src='" .$thum_name ."' alt='" .$file_list[$fct] ."'></a>";
				print "&nbsp;&nbsp;";
				if(($fct2 % 6) == 0) print "<BR>";
			}
	    }
	}
}

//------------------------------------------------------------------------------------------------
//初期値設定
//------------------------------------------------------------------------------------------------
//$age =  $_SERVER['HTTP_USER_AGENT'];

//print $age ."<BR>";





//アップロード時の保存パス
//$record_dir = '/www/geye/inspection/record/';
//$pict_dir = '/www/geye/inspection/pict/';
//$pict_dir_s = '/www/geye/inspection/pict_s/';

//■アップロード時の保存パス
$save_dir = "/www/geye/inspection/";
$record_dir = "/record/";
$pict_dir = "/pict/";
$pict_dir_s = "/pict_s/";
$delete_dir = "/delete/";
$upload_pict_dir = "/www/geye/pict/";
//print time();

//zip保存用
$zip_dir = '/geye/';

//削除時のPOSTのデータを取得
$del = $_POST['del'];
$yes_ = $_POST['yes_'];
$no_ = $_POST['no_'];

//GETデータの出力(データ抽出)
EXTRACT($_GET);
//print_r($_GET);
//print_r($_POST);

//-------------------------------------------------------------------------------------------------
// DB接続設定(サーバ/データベース/ユーザ/パスワード)
//-------------------------------------------------------------------------------------------------
$sv = "localhost";
$dbname = "geye";
$user = "postgres";
$pass = "postgres";
$conn = pg_connect("host=$sv dbname=$dbname user=$user password=$pass") or die("接続エラー");

//-------------------------------------------------------------------------------------------------
// 調書に使用する項目リストをDBから取得
//-------------------------------------------------------------------------------------------------
//$sql_item = "SELECT * FROM check_item_name ORDER BY id;";
//$res_item = pg_query($conn,$sql_item);
//$count_item = pg_num_rows($res_item);

//-------------------------------------------------------------------------------------------------
//検査項目のリストをDBから取得
//-------------------------------------------------------------------------------------------------
//■DBから最新データの抽出
/*
$sql_i = "SELECT DISTINCT(inspection_id),inspection_name  FROM check_item_name2 WHERE del_flag ='false' ORDER BY inspection_id;";
$res_i = pg_query($conn,$sql_i);
$ct_i = pg_num_rows($res_i);
$inspection_id_ = array();
$inspection_name_ = array();
for($z=0;$z < $ct_i;$z++)
{
	$row = pg_fetch_array($res_i,$z);
	$id_ = $row['inspection_id'];
	$inspection_id_[$id_] = $row['inspection_id'];
	$inspection_name_[$id_] = $row['inspection_name'];
}
*/
//-------------------------------------------------------------------------------------------------
// アップロードされた画像の振り分け
//-------------------------------------------------------------------------------------------------
if($_POST['pictupload'])
{
	$sql_p = "SELECT * FROM inspection_record WHERE del_flag=false ORDER BY scheduled_date desc;";
	$res_p = pg_query($conn,$sql_p);
	$count_p = pg_num_rows($res_p);

	//対象データの期間(デフォルト3時間)
	$range_1 = 10800;	//秒
	$range_2 = 10800;	//秒
	for($p=0;$p<$count_p;$p++)
	{
		$row_p = pg_fetch_array($res_p,$p);
		$id = $row_p['id'];
		$schedul_unix = strtotime($row_p['scheduled_date']);
		$schedul_date = date("Ymd" ,$schedul_unix);
		
		//希望日から*時間前
		$past_unix = $schedul_unix - $range_1;
		$past_date = date("Ymd" ,$past_unix);
		
		//希望日から*時間後
		$future_unix = $schedul_unix + $range_2;
		$future_date = date("Ymd" ,$future_unix);
		
		//今日のフォルダ画像を検索
		$upload_pict_dir_ = $upload_pict_dir .$schedul_date;
	    if ($dirHandle = opendir ($upload_pict_dir_))
	    {
	        while ( false !== ( $fileName = readdir ( $dirHandle)))
	        {
	            if ( $fileName != "." && $fileName != ".." )
	            {
	            	//ファイルの更新時間
	            	$file_datetime = filemtime($upload_pict_dir_ ."/" .$fileName);
	            	//print $id ."_" .$past_unix  ."_" .$file_datetime ."_" .$future_unix ."<BR>";
	            	
	            	if(($past_unix < $file_datetime) && ($file_datetime < $future_unix))
	            	{
	            		//print $id ."_" .$past_unix  ."_" .$file_datetime ."_" .$future_unix ."_" .$fileName ."<BR>";
	            		copy($upload_pict_dir_ ."/" .$fileName , $save_dir .$id .$pict_dir.$fileName );
	            		ThumbnailMake($save_dir .$id .$pict_dir,$fileName,$save_dir .$id .$pict_dir_s ,77,75);
	            	}
	            }
	        }
	        closedir ( $dirHandle );
	    }

		if($schedul_date != $past_date)
		{
			print "前日";
			//前日のフォルダ画像を検索
			$upload_pict_dir_ = $upload_pict_dir .$past_date;
			//print $upload_pict_dir_ ."<BR>";
		    if ($dirHandle = opendir ($upload_pict_dir_))
		    {
		        while ( false !== ( $fileName = readdir ( $dirHandle)))
		        {
		            if ( $fileName != "." && $fileName != ".." )
		            {
		            	//ファイルの更新時間
		            	$file_datetime = filemtime($upload_pict_dir_ ."/" .$fileName);
		            	//print $id ."_" .$past_unix  ."_" .$file_datetime ."_" .$future_unix ."<BR>";
		            	
		            	if(($past_unix < $file_datetime) && ($file_datetime < $future_unix))
		            	{
		            		//print $id ."_" .$past_unix  ."_" .$file_datetime ."_" .$future_unix ."<BR>";
		            		copy($upload_pict_dir_ ."/" .$fileName , $save_dir .$id .$pict_dir.$fileName );
		            		ThumbnailMake($save_dir .$id .$pict_dir,$fileName,$save_dir .$id .$pict_dir_s ,77,75);
		            	}
		            }
		        }
		        closedir ( $dirHandle );
		    }
		}

		if($schedul_date != $future_date)
		{
			print "後日";
			//後日のフォルダ画像を検索
			$upload_pict_dir_ = $upload_pict_dir .$future_date;
			//print $upload_pict_dir_ ."<BR>";
		    if ($dirHandle = opendir ($upload_pict_dir_))
		    {
		        while ( false !== ( $fileName = readdir ( $dirHandle)))
		        {
		            if ( $fileName != "." && $fileName != ".." )
		            {
		            	//ファイルの更新時間
		            	$file_datetime = filemtime($upload_pict_dir_ ."/" .$fileName);
		            	
		            	if(($past_unix < $file_datetime) && ($file_datetime < $future_unix))
		            	{
		            		//print $id ."_" .$past_unix  ."_" .$file_datetime ."_" .$future_unix ."<BR>";
		            		copy($upload_pict_dir_ ."/" .$fileName , $save_dir .$id .$pict_dir.$fileName );
		            		ThumbnailMake($save_dir .$id .$pict_dir,$fileName,$save_dir .$id .$pict_dir_s ,77,75);
		            	}
		            }
		        }
		        closedir ( $dirHandle );
		    }
		}


	}
}

//-------------------------------------------------------------------------------------------------
//フォームアクション処理(削除・確認画面・ダウンロード)
//-------------------------------------------------------------------------------------------------
//■確認処理
if($chk)
{
	/*
	//現在の確認状況を取得
	$sql_ch = "SELECT * FROM inspection_record_t WHERE id = " .$chk ." AND del_flag ='false' ;";
	$res_ch = pg_query($conn,$sql_ch);
	$row_ch = pg_fetch_array($res_ch,0);
	
	$chk_flag = ($row_ch['chk_flag'] == 'f') ? "true" : "false";
	
	$sql_chup = "UPDATE inspection_record_t SET ";
	$sql_chup .= "confirmer = '" .$conf ."', ";
	$sql_chup .= "implementation_date = '" .$imp ."',";
	$sql_chup .= "memo = '" .$memo ."',";
	$sql_chup .= "chk_flag = '" .$chk_flag ."' ";
	$sql_chup .= " WHERE id = " .$chk .";";
	
	if (!($res_chup = pg_query($conn, $sql_chup ))) ;//print pg_last_error() ."<BR>";
	*/
	
	//現在の確認状況を取得
	$sql_chup = "UPDATE inspection_record SET ";
	$sql_chup .= ($conf) ? "confirmer = '" .$conf ."'," : "confirmer = null,";
	$sql_chup .= ($imp) ? "implementation_date = '" .$imp ."'," : "implementation_date = null,";
	$sql_chup .= ($memo) ? "memo = '" .$memo ."'" : "memo = null";
	$sql_chup .= " WHERE id = " .$chk .";";
	
	if (!($res_chup = pg_query($conn, $sql_chup ))) ;//print pg_last_error() ."<BR>";
}



//-------------------------------------------------------------------------------------------------
// データの一覧表の作成
//-------------------------------------------------------------------------------------------------
//■削除処理
if($yes_)
{
	$DelSql = "UPDATE inspection_record SET ";
	$DelSql .= "del_flag = 'TRUE' ";
	$DelSql .= " WHERE id IN (" .$del .");";
	
	if (!($resDelSql = pg_query($conn, $DelSql))) print pg_last_error() ."<BR>";
	print "対象のデータを削除しました" ."<BR>";

	//削除対象のIDを初期化
	$del = "";
}
else if($no_)
{
	//削除対象のIDを初期化
	$del = "";
}

//■削除確認
if($del)
{
	print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";

	//■DBから最新データの抽出
	$sql_v = "SELECT * FROM inspection_record WHERE id in(" .$del .") AND del_flag ='false' ORDER BY id DESC;";
	$res_v = pg_query($conn,$sql_v);
	$ct_v = pg_num_rows($res_v);

	//■フォームボタンの作成(ダウンロード・削除)
	print "以下のデータを削除してもよろしいですか?<BR>";
	print "<INPUT TYPE='submit' NAME='yes_' VALUE='はい' class='button'>";
	print "<INPUT TYPE='submit' NAME='no_' VALUE='いいえ' class='button'>";
	print "<INPUT TYPE='hidden' NAME='del' VALUE='" .$del ."' class='button'>";
	print "</form>";
	//■データ表の作成
	print "<TABLE BORDER=\"1\" WIDTH='2000'>";
	print "<TR BGCOLOR='blue'>";
	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >No</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>確認</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>希望日</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>場所</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>工種</FONT></TH>";
	print "<TH WIDTH='120'><FONT SIZE ='2' COLOR='white'>検査項目</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>管理技術者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>確認者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>実施日</FONT></TH>";
	print "<TH WIDTH='50'><FONT SIZE ='2' COLOR='white' COLSPAN='2'>調書</FONT></TH>";
	print "<TH WIDTH='50'><FONT SIZE ='2' COLOR='white'>写真</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>記事</FONT></TH>";
	print "</TR>";

	for($i = 0 ;$i < $ct_v;$i++)
	{
		$row = pg_fetch_array($res_v,$i);

		$no = $row[0];
		$scheduled_date = date("Y/m/d" ,strtotime($row[1])) ."<BR>" .date("H:i" ,strtotime($row[1]));
		$place =  $row[2];
		$construction =  $row[3];
		$inspection_name = $row[4];
		$inspection_id = $row['inspection_id'];
		$supervision_engineer = $row[5];
		$confirmer = $row[6];
		$implementation_date = ($row[7]) ? date("Y-m-d" ,strtotime($row[7])) : "";
		$memo =  $row[8];
		$updatetime =  $row[9];
		$regdatetime =  $row[10];
		$chk_flag = ($row[11] === f) ? '--------':'確認済';

		print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";

		//●確認者・実施日のテキストボックスの有効/無効切り替え
		$disabled = "disabled='disabled'";

		print "<TD>" .$no ."</TD>";
		//print "<TD><INPUT TYPE='submit' NAME='chk_f[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
		print "<TD>" .$chk_flag ."</TD>";

		print "<TD><FONT SIZE ='2'>" .$scheduled_date ."</FONT></TD>";
		print "<TD>" .$place ."&nbsp;</TD>";
		print "<TD>" .$construction ."&nbsp;</TD>";


		//●確認者 実施日
		print "<TD>" .$inspection_name ."&nbsp;</TD>";
		print "<TD>" .$supervision_engineer ."&nbsp;</TD>";
		print "<TD>" .$confirmer ."&nbsp;</TD>";
		print "<TD><INPUT TYPE='date' size='10' NAME='implementation_date' VALUE='" .$implementation_date ."' "  .$disabled ."></TD>";

		//●調書
		print "<TD>";
		DlLinkMake(0,$no,$inspection_id,$save_dir,$record_dir,0);
		print "</TD>";

		//●写真の表示
		print "<TD ALIGN='left'>";
		DlLinkMake(2,$no,0,$save_dir,$pict_dir,0);
		print "&nbsp;</TD>";

		//●記事の表示
		print "<TD>" .$memo ."</TD>";
		print "</TR>";
	}
	print "</TABLE>";
}
else if($file_dl)
{
	//■ダウンロード処理
	//$file_dl = 0;
	//データidの分割
	$id_ = explode(",",$file_dl);
	$id_count_ = count($id_);

	//zip用ファイルの初期化(削除)
	$cmd_del = "rm -Rf " .$zip_dir ."*";
	exec($cmd_del);
	//deleteData($zip_dir);

	for($k = 0;$k < $id_count_ ;$k++)
	{
		//ZIP用のフォルダの作成
		$zip_sub_dir = $zip_dir.$id_[$k];
		mkdir($zip_sub_dir , 0777);
		$zip_sub_dir_rec = $zip_sub_dir ."/record/";
		$zip_sub_dir_pict = $zip_sub_dir ."/pict/";
		mkdir($zip_sub_dir_rec , 0777);
		mkdir($zip_sub_dir_pict , 0777);
		
		//対象ファイルをコピー
		$cmd_1 = "cp -a " .$save_dir .$id_[$k] .$record_dir  ."*" ." " .$zip_sub_dir_rec;
		$cmd_2 = "cp -a " .$save_dir .$id_[$k] .$pict_dir  ."*" ." " .$zip_sub_dir_pict;
		
		exec($cmd_1);
		exec($cmd_2);
	}
	//zipの作成
	$file_name_date = date("YmdHis" ,time());
	$zip_path = $zip_dir .$file_name_date .".zip";
	//$zip_path = $id_[$k] .".zip";
	$cmd_3 = "zip -r " .$zip_path  ." /geye/*";
	exec($cmd_3);
	//print $cmd_3 ;
	$file_name = $file_name_date .".zip";
	$link = "http://penta-02.ptgw.net/geye/download.php?u=3&f=" .$file_name;



	print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
	print "<INPUT TYPE='submit' NAME='reload' VALUE='一覧へ戻る' class='button'>";
	print "</form>";

	print "【データのダウンロード】";
	print "<BR>";
	print "&nbsp;&nbsp;&nbsp;";
	print "<a href='download.php?u=3&f=" .$file_name ."' target='_blank' rel='noopener'>" .$file_name ."</a>";
//	header("Location: $link");
//	header('Location: https://penta-02.ptgw.net/geye/download.php?u=3&f=' .$file_name );
	print "<BR><BR>";

	print "【データ内容】";
	//if($_POST[''])
	//■DBから最新データの抽出
	$sql_v = "SELECT * FROM inspection_record WHERE id in(" .$file_dl .") AND del_flag ='false' ORDER BY id DESC;";
	$res_v = pg_query($conn,$sql_v);
	$ct_v = pg_num_rows($res_v);

	//■フォームボタンの作成(ダウンロード・削除)
//print "</form>";
	//■データ表の作成
	print "<TABLE BORDER=\"1\" WIDTH='2000'>";
	print "<TR BGCOLOR='blue'>";
	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >No</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>確認</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>希望日</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>場所</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>工種</FONT></TH>";
	print "<TH WIDTH='120'><FONT SIZE ='2' COLOR='white'>検査項目</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>管理技術者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>確認者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>実施日</FONT></TH>";
	print "<TH WIDTH='50'><FONT SIZE ='2' COLOR='white' COLSPAN='2'>調書</FONT></TH>";
	print "<TH WIDTH='50'><FONT SIZE ='2' COLOR='white'>写真</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>記事</FONT></TH>";
	print "</TR>";

	for($i = 0 ;$i < $ct_v;$i++)
	{
		$row = pg_fetch_array($res_v,$i);

		$no = $row[0];
		$scheduled_date = date("Y/m/d" ,strtotime($row[1])) ."<BR>" .date("H:i" ,strtotime($row[1]));
		$place =  $row[2];
		$construction =  $row[3];
		$inspection_name = $row[4];
		$inspection_id = $row['inspection_id'];
		$supervision_engineer = $row[5];
		$confirmer = $row[6];
		$implementation_date = ($row[7]) ? date("Y-m-d" ,strtotime($row[7])) : "";
		$memo =  $row[8];
		$updatetime =  $row[9];
		$regdatetime =  $row[10];
		$chk_flag = ($row[11] === f) ? '--------':'確認済';

		print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";

		//●確認者・実施日のテキストボックスの有効/無効切り替え
		$disabled = "disabled='disabled'";

		print "<TD>" .$no ."</TD>";
		//print "<TD><INPUT TYPE='submit' NAME='chk_f[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
		print "<TD>" .$chk_flag ."</TD>";

		print "<TD><FONT SIZE ='2'>" .$scheduled_date ."</FONT></TD>";
		print "<TD>" .$place ."&nbsp;</TD>";
		print "<TD>" .$construction ."&nbsp;</TD>";


		//●確認者 実施日
		print "<TD>" .$inspection_name ."&nbsp;</TD>";
		print "<TD>" .$supervision_engineer ."&nbsp;</TD>";
		print "<TD>" .$confirmer ."&nbsp;</TD>";
		print "<TD><INPUT TYPE='date' size='10' NAME='implementation_date' VALUE='" .$implementation_date ."' "  .$disabled ."></TD>";

		//●調書
		print "<TD>";
		DlLinkMake(0,$no,$inspection_id,$save_dir,$record_dir,0);
		print "</TD>";

		//●写真の表示
		print "<TD ALIGN='left'>";
		DlLinkMake(2,$no,0,$save_dir,$pict_dir,0);
		print "&nbsp;</TD>";

		//●記事の表示
		print "<TD>" .$memo ."</TD>";
		print "</TR>";
	}
	print "</TABLE>";

}
else if(!$_POST['record_chk'] && !$_GET['list_no_'])
{
	//if($_POST[''])
	//■DBから最新データの抽出
	$sql_v = "SELECT * FROM inspection_record WHERE del_flag ='false' ORDER BY scheduled_date DESC;";
	$res_v = pg_query($conn,$sql_v);
	$ct_v = pg_num_rows($res_v);

	//■フォームボタンの作成(ダウンロード・削除)
	print "<TABLE>";
	print "<TR>";
	print "<TD>";
	print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
	print "<INPUT TYPE='submit' NAME='reload' VALUE='画面更新' class='button'>";
	print "</form>";
	print "</TD>";
//	print "<TD>";
//	print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
//	print "<INPUT TYPE='submit' NAME='pictupload' VALUE='サーバー画像自動振分け'>";
//	print "</form>";
//	print "</TD>";
	print "</TABLE>";
//	print "<form enctype='multipart/form-data' action='download.php' method='post'>";
	print "チェック項目の ";
	print "<INPUT TYPE='submit' NAME='download' VALUE='ダウンロード' onclick='DataAction(1)' class='button'>";
	print "<INPUT TYPE='submit' NAME='delete' VALUE='削除' onclick='DataAction(2)' class='hoge button'>";
//print "</form>";
	//■データ表の作成
	print "<TABLE BORDER=\"1\" WIDTH='2500'>";
//	print "<TABLE BORDER=\"1\">";
	print "<TR BGCOLOR='blue'>";
	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >CB</FONT></TH>";
	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >No</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>確認</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>希望日</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>場所</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>工種</FONT></TH>";
	print "<TH WIDTH='300'><FONT SIZE ='2' COLOR='white'>検査項目</FONT></TH>";
	print "<TH WIDTH='150'><FONT SIZE ='2' COLOR='white'>管理技術者</FONT></TH>";
	print "<TH WIDTH='150'><FONT SIZE ='2' COLOR='white'>確認者</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>実施日</FONT></TH>";
	print "<TH WIDTH='400'><FONT SIZE ='2' COLOR='white' COLSPAN='2'>調書</FONT></TH>";
	print "<TH WIDTH='500'><FONT SIZE ='2' COLOR='white'>写真</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>記事</FONT></TH>";
	print "<TH WIDTH='60'><FONT SIZE ='2' COLOR='white'>登録</FONT></TH>";
	print "</TR>";

	for($i = 0 ;$i < $ct_v;$i++)
	{
		$row = pg_fetch_array($res_v,$i);

		$no = $row[0];
		$scheduled_date = date("Y/m/d" ,strtotime($row[1])) ."<BR>" .date("H:i" ,strtotime($row[1]));
		$place =  $row[2];
		$construction =  $row[3];
		$inspection_name = $row[4];
		$inspection_id = $row['inspection_id'];
		$supervision_engineer = $row[5];
		$confirmer = $row[6];
		$implementation_date = ($row[7]) ? date("Y-m-d" ,strtotime($row[7])) : "";
		$memo =  $row[8];
		$updatetime =  $row[9];
		$regdatetime =  $row[10];
		$chk_flag = ($row[11] === f) ? '--------':'確認済';

		print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";

		//●確認者・実施日のテキストボックスの有効/無効切り替え
		//$disabled = ($row[11] === f) ? "":"disabled='disabled'";


		print "<TD><INPUT TYPE='checkbox' NAME='check' VALUE='$no' ></TD>";
		print "<TD>" .$no ."</TD>";
		//print "<TD><INPUT TYPE='submit' NAME='chk_f[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
		print "<TD>" .$chk_flag ."</TD>";

		print "<TD><FONT SIZE ='2'>" .$scheduled_date ."</FONT></TD>";
		print "<TD>" .$place ."&nbsp;</TD>";
		print "<TD>" .$construction ."&nbsp;</TD>";


		//●確認者 実施日
		print "<TD>" .$inspection_name ."&nbsp;</TD>";
		print "<TD>" .$supervision_engineer ."&nbsp;</TD>";
		print "<TD><INPUT TYPE='text' size='10' NAME='confirmer_reg' VALUE='" .$confirmer ."' "  .$disabled ." ></TD>";
		print "<TD><INPUT TYPE='date' size='10' NAME='implementation_date' VALUE='" .$implementation_date ."' "  .$disabled ."></TD>";

		//●調書
		print "<TD>";
		DlLinkMake(1,$no,$inspection_id,$save_dir,$record_dir,0);
		print "</TD>";

		//●写真の表示
		print "<TD ALIGN='left'>";
		DlLinkMake(2,$no,0,$save_dir,$pict_dir,0);
		print "&nbsp;</TD>";

		//●記事の表示
		print "<TD><INPUT TYPE='text' size='25' NAME='memo_reg' VALUE='" .$memo ."' "  .$disabled ." ></TD>";
		print "<TD><INPUT TYPE='submit' NAME='chk_f[]' VALUE='登録' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
		print "</TR>";
	}
	print "</TABLE>";
//	print "</form>";
}
else
{
	$no = ($_POST['id_']) ? $_POST['id_'] : $_GET['id_'];
	$list_no = ($_POST['list_no_']) ? $_POST['list_no_']: $_GET['list_no_'];
	$inspection_id = ($_POST['inspection_id_']) ? $_POST['inspection_id_'] : $_GET['inspection_id_'];
	$text_value = ($_POST['tval']) ? $_POST['tval'] :$_GET['tval'];
	
	
	//検査項目名から確認項目を取得
	$sql_item = "SELECT * FROM check_item_name2 WHERE inspection_id = " .$inspection_id ." AND del_flag=false ORDER BY sort_no;";
	$res_item = pg_query($conn,$sql_item);
	$count_item = pg_num_rows($res_item);
	$date_time = date("Y-m-d H:i:s",time());
	$item_name = array();
	for($ict = 0;$ict < $count_item;$ict++)
	{
		$row_item = pg_fetch_array($res_item,$ict);
		$item_name[$ict] = $row_item['item_name'];
		//調書出力用のデータが存在しているかを確認
		$sql_record = "SELECT * FROM record_check_list WHERE data_no=" .$no ." AND inspection_id = " .$row_item['inspection_id'] ." AND list_no=" .$list_no ." AND item_no=" .$row_item['item_id'] ." AND del_flag=false;";
		$res_record = pg_query($conn,$sql_record);

		$count_record = pg_num_rows($res_record);
//print $sql_record ."<BR>";
		if(!$count_record)
		{
			//データの登録
			$sql_list_ins = "INSERT INTO record_check_list(data_no, inspection_id,list_no ,item_no,sort_no,regdatetime)";
	        $sql_list_ins .= "VALUES (";
	        $sql_list_ins .= $no .",";
	        $sql_list_ins .= $row_item['inspection_id'] .",";
	        $sql_list_ins .= $list_no .",";
	        $sql_list_ins .= $row_item['item_id'] .",";
	        $sql_list_ins .= $row_item['sort_no'] .",";
	        $sql_list_ins .= "'" .$date_time ."')";
	        $res_list_ins = pg_query($conn,$sql_list_ins);
			//$res_list_ins = pg_query($conn,$sql_list_ins) or die(pg_last_error() ."<BR>" .$sql_list_ins);
		}
	}


	//確認チェックリストが未登録の場合はDB作成


	//■項目がチェックされた場合、DBをアップデート
	if($_GET['list_no_'])
	{
		
		if($_GET['item_no'])
		{
			//編集中のIDをテキストファイルに出力
			//キャプチャ画像と結びつけるため
			$fp_id = fopen("editing_id.txt","w");
			fwrite($fp_id,$no ."," .$list_no ."," .$_GET['item_no']);
			fclose($fp_id);
			/////////////////////////////////////
			
			$regdate = date("Y-m-d H:i:s",time());
			$sql_up = "UPDATE record_check_list SET ";
			$sql_up .= ($_GET['chk']=='true') ? "regdatetime='" .$regdate ."'," :"";
			$sql_up .= ($text_value) ? "value='" .$text_value ."'," :"";
			$sql_up .= "chk=" .$_GET['chk'];
			$sql_up .= " WHERE data_no=" .$no ." AND list_no=" .$list_no ." AND item_no=" .$_GET['item_no'] ." AND del_flag=false";
			$res_up =  pg_query($conn,$sql_up)OR DIE (pg_last_error() .$sql_up ."<BR>");
			
			
			
			//確認が全て終わっているか確認・終わっていれば確認済みにする
			$sel_ct = "SELECT count(data_no = " .$no ." or null) AS data_ct,count(chk=true or null) AS chk_ct FROM record_check_list WHERE data_no=" .$no ." AND del_flag=false" ;
			$res_ct = pg_query($conn,$sel_ct);
			$row_ct = pg_fetch_array($res_ct,0);
			
			if($row_ct['data_ct'] == $row_ct['chk_ct'])
			{
				$sql_up2 = "UPDATE inspection_record SET ";
				$sql_up2 .= "chk_flag=true";
				$sql_up2 .= " WHERE id=" .$no ;
				$res_up2 =  pg_query($conn,$sql_up2)OR DIE (pg_last_error() .$sql_up2 ."<BR>");
			}
			else
			{
				$sql_up2 = "UPDATE inspection_record SET ";
				$sql_up2 .= "chk_flag=false";
				$sql_up2 .= " WHERE id=" .$no ;
				$res_up2 =  pg_query($conn,$sql_up2)OR DIE (pg_last_error() .$sql_up2 ."<BR>");
			}
		}
		
		
		if($_GET['tval2'])
		{
			$tval_ =  explode(",",$_GET['tval2']);
			$tval_ct = count($tval_);
			for($tv = 0;$tv < $tval_ct;$tv++)
			{
				$item_no_reg = $tv + 1;
				//if($tval_[$tv])
				//{
					$sql_up = "UPDATE record_check_list SET ";
					$sql_up .= "value='" .$tval_[$tv] ."'";
					$sql_up .= " WHERE data_no=" .$no ." AND list_no=" .$list_no ." AND item_no=" .$item_no_reg ." AND del_flag=false";
					$res_up =  pg_query($conn,$sql_up)OR DIE (pg_last_error() .$sql_up ."<BR>");
				//}
			}
		}
		
		
	}

	//■DBから最新データの抽出
	$sql_v = "SELECT * FROM inspection_record WHERE id=" .$no .";";
	$res_v = pg_query($conn,$sql_v);
	$ct_v = pg_num_rows($res_v);

	//■DBからチェックリストの抽出
	$sql_cl = "SELECT * FROM record_check_list WHERE data_no=" .$no ." AND list_no=" .$list_no ." AND del_flag=false ORDER BY sort_no;";
	$res_cl = pg_query($conn,$sql_cl);
	$ct_cl = pg_num_rows($res_cl);
	
	//■DBからチェックリストの項目名を抽出
	//for($ict =0;$ict< $count_item;$ict++)
	//{
	//	$row_item = pg_fetch_array($res_item,$ict);
	//	$id_item = $row_item['id'];
	//	$item_name[$id_item] = $row_item['name'];
	//}


	//■データ表の作成
	print "<TABLE BORDER=\"1\" WIDTH='2500'>";
	print "<TR BGCOLOR='blue'>";
//	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >CB</FONT></TH>";
	print "<TH WIDTH='20'><FONT SIZE ='2' COLOR='white' >No</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>確認</FONT></TH>";
	print "<TH WIDTH='130'><FONT SIZE ='2' COLOR='white'>希望日</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>場所</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>工種</FONT></TH>";
	print "<TH WIDTH='120'><FONT SIZE ='2' COLOR='white'>検査項目</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>管理技術者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>確認者</FONT></TH>";
	print "<TH WIDTH='100'><FONT SIZE ='2' COLOR='white'>実施日</FONT></TH>";
	print "<TH WIDTH='50' id='" .$no ."' COLSPAN='2'><FONT SIZE ='2' COLOR='white'>調書</FONT></TH>";
	print "<TH WIDTH='50'><FONT SIZE ='2' COLOR='white'>写真</FONT></TH>";
	print "<TH WIDTH='200'><FONT SIZE ='2' COLOR='white'>記事</FONT></TH>";
	print "<TH WIDTH='20' ROWSPAN='2' BGCOLOR='white'>";
	print "<INPUT TYPE='submit' NAME='chk_f[]' VALUE='更新' onclick='CheckPush2(0,\"" .$no ."\",\"" .$list_no ."\",\"" .$inspection_id ."\",\"" .$ct_cl ."\" );' >";
	print "<form enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
	print "<INPUT TYPE='submit' NAME='reload' VALUE='戻る'>";
	print "</form>";
	print "</TH>";

	print "</TR>";

	$row = pg_fetch_array($res_v,0);

	$no = $row[0];
	$scheduled_date = date("Y/m/d" ,strtotime($row[1])) ."<BR>" .date("H:i" ,strtotime($row[1]));
	$place =  $row[2];
	$construction =  $row[3];
	$inspection_name = $row[4];
	$supervision_engineer = $row[5];
	$confirmer = $row[6];
	$implementation_date = ($row[7]) ? date("Y-m-d" ,strtotime($row[7])) : "";
//	$record =  explode(",",$row[8]);
//	$record_ct = count($record);
//	$pict =  explode(",",$row[9]);
//	$pict_ct = count($pict);

	$memo =  $row[8];
	$updatetime =  $row[9];
	$regdatetime =  $row[10];
	$chk_flag = ($row[11] === f) ? '--------':'確認済';

	print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";

	//●確認者・実施日のテキストボックスの有効/無効切り替え
	//$disabled = ($row[11] === f) ? "":"disabled='disabled'";


	print "<TD>" .$no ."</TD>";
	//print "<TD><INPUT TYPE='submit' NAME='chk_f[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
	print "<TD>" .$chk_flag ."</TD>";
	print "<TD><FONT SIZE ='2'>" .$scheduled_date ."</FONT></TD>";
	print "<TD>" .$place ."&nbsp;</TD>";
	print "<TD>" .$construction ."&nbsp;</TD>";


	//●確認者 実施日
	print "<TD>" .$inspection_name ."&nbsp;</TD>";
	print "<TD>" .$supervision_engineer ."&nbsp;</TD>";
	print "<TD><INPUT TYPE='text' size='10' NAME='confirmer_reg' VALUE='" .$confirmer ."' "  .$disabled ." ></TD>";
	print "<TD><INPUT TYPE='date' size='10' NAME='implementation_date' VALUE='" .$implementation_date ."' "  .$disabled ."></TD>";
//	print "<TD><input type='date' name='implementation_date' value=''></input></TD>";

	print "<TD ALIGN='left' class='td-css1'>";
	//●調書
    $dir = $save_dir .$no .$record_dir;
	if (is_dir($dir)) 
	{
	    if ($dh = opendir($dir)) {
	        while (($file = readdir($dh)) !== false)
	        {
	        	if ( $file != "." && $file != ".." )
	        	{
					$list_no_ = filemtime($dir .$file);
					if($list_no_ == $list_no)
					{
						print "<a href='download.php?u=" .$dl_type_ ."&f=" .$file ."&id=" .$no ."'>" .$file ."</a><BR>";
						print "<BR>";
						for($cl =0;$cl< $ct_cl;$cl++)
						{
							$row_cl = pg_fetch_array($res_cl,$cl);
							$cl_id = $row_cl['item_no'];
							$chk = $row_cl['chk'];
							$value = $row_cl['value'];
							$checked = ($row_cl['chk'] === t) ? "checked" : "";
							print "<INPUT TYPE='checkbox' NAME='check_list' VALUE='" .$cl_id ."' ".$checked ." onchange='myfunc(\"" .$no ."\",\"" .$list_no ."\",\"" .$cl ."\",\"" .$ct_cl ."\",\"" .$inspection_id ."\");' >" .$item_name[$cl] ."<BR>";
							$text .=  "<INPUT TYPE='text' size='10' NAME='check_text' VALUE='" .$value ."'>" ."<BR>";
							
							//$test .= "<INPUT TYPE='text' size='10' NAME='confirmer_reg' VALUE='" .$confirmer ."' "  .$disabled ." >";
						}
						print "<BR>";

					}
				}
	        }
	        closedir($dh);
	    }
	}

	print "&nbsp;</TD>";
	print "<TD class='td-css2'>" .$text ."</TD>";
	//●写真の表示
	print "<TD ALIGN='left'>";
	DlLinkMake(2,$no,0,$save_dir,$pict_dir,0);

	print "&nbsp;</TD>";

	//●記事の表示
	print "<TD><INPUT TYPE='text' size='25' NAME='memo_reg' VALUE='" .$memo ."' "  .$disabled ." ></TD>";
	print "</TR>";

	print "</TABLE>";

}


?>

</BODY>
</HTML>

PHP File Manager