File "data_view_OLD20200623.php"
Full path: /www/geye/OLD/data_view_OLD20200623.php
File size: 30.48 KiB (31216 bytes)
MIME-type: text/html
Charset: utf-8
<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>
<div id="result"></div>
<!--
<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('実施日を入力して下さい。');
}
}
function CheckPush2(id_,no_,list_no_,inspection_id_)
{
//チェックボタンは配列に入っている
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?id_=" + no_ + "&inspection_id_=" + inspection_id_ + "&list_no_=" + list_no_ +"&chk=" + no_ + "&conf=" + conf + "&imp=" + imp + "&memo=" + memo;
// }
// else
// {
// alert('実施日を入力して下さい。');
// }
}
function myfunc(id,list_no,cl,ct_cl,inspection_id)
{
confirmer_ = document.getElementsByName("check_list");
console.log(confirmer_[cl].value + "____"+confirmer_[cl].checked);
val = confirmer_[cl].value;
chk = confirmer_[cl].checked;
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 + "#" + id;
}
function CheckList(chk)
{
//チェックボタンは配列に入っている
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('実施日を入力して下さい。');
}
}
//if(window == window.parent) {
// document.getElementById('result').innerHTML = 'iframeで読み込まれていないです';
// 自分自身が親でない(iframeで読み込まれている場合)
//} else {
// document.getElementById('result').innerHTML = 'iframeで読み込まれています';
//}
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);
}
}
//■元画像からサムネイル画像の作成
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++)
{
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_ ."'>" .$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_ ."'>";
print "<img src='" .$thum_name ."' alt='" .$file_list[$fct] ."'></a>";
print " ";
}
}
}
}
//------------------------------------------------------------------------------------------------
//初期値設定
//------------------------------------------------------------------------------------------------
//$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/';
//GETデータの出力(データ抽出)
EXTRACT($_GET);
//print_r($_GET);
//print_r($_POST);
//-------------------------------------------------------------------------------------------------
// 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("接続エラー");
//-------------------------------------------------------------------------------------------------
// 調書に使用する項目リストを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($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_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($file_dl)
{
//データidの分割
$id_ = explode(",",$file_dl);
$id_count_ = count($id_);
for($k = 0;$k < $id_count_ ;$k++)
{
//zip用ファイルの初期化(削除)
$cmd_del = "rm -Rf " .$zip_dir ."*";
exec($cmd_del);
//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 " .$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";
//print 'http://penta-02.ptgw.net/geye/download.php?u=3&f=' .$file_name;
header('Location: http://penta-02.ptgw.net/geye/download.php?u=3&f=' .$file_name );
}
//-------------------------------------------------------------------------------------------------
// データの一覧表の作成
//-------------------------------------------------------------------------------------------------
//print "<script type='text/javascript'>";
//print alert('実施日を入力して下さい。');
//print "</script>";
if(!$_POST['record_chk'] && !$_GET['list_no_'])
{
//■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 "<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 "チェック項目の ";
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\" WIDTH='3000'>";
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' 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 "<TH WIDTH='10'><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 ." </TD>";
print "<TD>" .$construction ." </TD>";
//●確認者 実施日
print "<TD>" .$inspection_name ." </TD>";
print "<TD>" .$supervision_engineer ." </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 " </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>";
}
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_'];
//検査項目名から確認項目を取得
$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);
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 .= "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>");
}
}
}
//■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='3000'>";
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 ."'><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 "<TH WIDTH='20' ROWSPAN='2' BGCOLOR='white'>";
print "<INPUT TYPE='submit' NAME='chk_f[]' VALUE='更新' onclick='CheckPush2(0,\"" .$no ."\",\"" .$list_no ."\",\"" .$inspection_id ."\" );' >";
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 ." </TD>";
print "<TD>" .$construction ." </TD>";
//●確認者 実施日
print "<TD>" .$inspection_name ." </TD>";
print "<TD>" .$supervision_engineer ." </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'>";
//●調書
$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'];
$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>";
}
print "<BR>";
}
}
}
closedir($dh);
}
}
print " </TD>";
//●写真の表示
print "<TD ALIGN='left'>";
DlLinkMake(2,$no,0,$save_dir,$pict_dir,0);
print " </TD>";
//●記事の表示
print "<TD><INPUT TYPE='text' size='25' NAME='memo_reg' VALUE='" .$memo ."' " .$disabled ." ></TD>";
print "</TR>";
print "</TABLE>";
}
?>
</BODY>
</HTML>