File "data_view_20200519.php"

Full path: /www/db_bk/bk/OLD/data_view_20200519.php
File size: 11.33 KiB (11599 bytes)
MIME-type: text/html
Charset: utf-8

Download   Open   Back

<HTML>
<HEAD>
<META Http-Equiv="Content-Type" Content="text/html;charset=UTF-8">
<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;       /* 横幅    */
}

</style>
-->

<script type="text/javascript">
//-------------------------------------------------------------------------------------------------
//関数(javascript)
//-------------------------------------------------------------------------------------------------
//■チェック項目の削除
function goDeleteServlet()
{
	//チェックボタンは配列に入っている
	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 ;
			}
		}
	}
	
	if(data_no != null)
	{
		if(window.confirm("No." +data_no + 'を削除してもよろしいですか?'))
		{
			location.href = "data_view.php?del=" + data_no ;
		} 
		else
		{
			location.href = "data_view.php";
		}
	}
	else
	{
		if(window.confirm('削除のチェックが選択されていません'))
		{}
		else
		{}
	}
}


//■ファイルダウンロード
function dlServlet()
{

	//チェックボタンは配列に入っている
	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 ;
			}
		}
	}
	
	if(data_no != null)
	{
		if(window.confirm('選択した項目をダウンロードしますか?'))
		{
			location.href = "data_view.php?file_dl=" + data_no ;
		} 
		else
		{
			location.href = "data_view.php";
		}
	}
	else
	{
		if(window.confirm('チェックが選択されていません'))
		{}
		else
		{}
	}

}

//■確認ボタンの切り替え処理
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('実施日を入力して下さい。');
	}
}
</script>


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

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

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

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


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


//-------------------------------------------------------------------------------------------------
//フォームアクション処理(削除・確認画面・ダウンロード)
//-------------------------------------------------------------------------------------------------
//■削除処理
if($del)
{
	$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>";
}

//■確認処理
if($chk)
{
	//現在の確認状況を取得
	$sql_ch = "SELECT * FROM inspection_record 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 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>";
}

//■ダウンロード処理
if($file_dl)
{
	//データidの分割
	$id_ = explode(",",$file_dl);
	$id_count_ = count($id_);

	for($k = 0;$k < $id_count_ ;$k++)
	{
		//zip用ファイルの初期化(削除)
		deleteData($zip_dir);

		//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 " .$record_dir .$id_[$k] ."_*" ." " .$zip_sub_dir_rec;
		$cmd_2 = "cp -a " .$pict_dir .$id_[$k] ."_*" ." " .$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";
	header('Location: http://penta-02.ptgw.net/geye/download.php?u=3&f=' .$file_name );

}

//-------------------------------------------------------------------------------------------------
// データの一覧表の作成
//-------------------------------------------------------------------------------------------------
//■DBから最新データの抽出
$sql_v = "SELECT * FROM inspection_record WHERE del_flag ='false' ORDER BY id DESC;";
$res_v = pg_query($conn,$sql_v);
$ct_v = pg_num_rows($res_v);

//■フォームボタンの作成(ダウンロード・削除)
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 "<INPUT TYPE='submit' NAME='download' VALUE='ダウンロード' onclick='dlServlet()' class='button'>";
print "<INPUT TYPE='submit' NAME='delite' VALUE='削除' onclick='goDeleteServlet()' class='hoge button'>";

//■データ表の作成
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='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'>調書</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++)
{
	print "<TR ALIGN='center'>";
	$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];
	$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[10];
	$updatetime =  $row[11];
	$regdatetime =  $row[12];
	$chk_flag = ($row[13] === f) ? '--------':'確認済';

	//●確認者・実施日のテキストボックスの有効/無効切り替え
	$disabled = ($row[13] === 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><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>";

	//●調書
	for($cp = 0 ;$cp < $record_ct;$cp++)
	{
		if($record[$cp])
		{
			$record_name = $record[$cp];
			$record_name_v = explode("_",$record[$cp]);
			
			if (file_exists($record_dir .$record_name))
			{
				print "<a href='download.php?u=1&f=" .$record_name ."'>" .$record_name_v[2] ."</a>" ."&nbsp;&nbsp;";
				print "<BR>";
			}
		}
	}

	print "&nbsp;</TD>";

	//●写真の表示
	print "<TD>";
	for($cp = 0 ;$cp < $pict_ct;$cp++)
	{
		if($pict[$cp])
		{
			if (file_exists($pict_dir .$pict[$cp]))
			{
				$thum_name = "inspection/pict_s/" .str_replace("." ,"_s." ,$pict[$cp]);
				//print $thum_name ."<BR>";
				$pict_name = $pict[$cp];
				print "<a href='download.php?u=2&f=" .$pict_name ."'.><img src='" .$thum_name ."' alt='" .$pict_name ."'></a>";
				print "&nbsp;&nbsp;";
			}
		}
	}
	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