File "data_view_org.php"
Full path: /www/geye/OLD/data_view_org.php
File size: 20.6 KiB (21096 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>
<!--
<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 myfunc(id,list_no,cl) {
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 + "&list_no_=" + list_no + "&item_no=" + item + "&val=" + val + "&chk=" + chk;
}
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('実施日を入力して下さい。');
}
}
</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);
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("接続エラー");
//-------------------------------------------------------------------------------------------------
//フォームアクション処理(削除・確認画面・ダウンロード)
//-------------------------------------------------------------------------------------------------
//■削除処理
if($del)
{
$DelSql = "UPDATE inspection_record_t 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_t SET ";
$sql_chup .= "confirmer = '" .$conf ."', ";
$sql_chup .= "implementation_date = '" .$imp ."',";
$sql_chup .= "memo = '" .$memo ."'";
$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 );
}
//-------------------------------------------------------------------------------------------------
// データの一覧表の作成
//-------------------------------------------------------------------------------------------------
if(!$_POST['record_chk'] && !$_GET['list_no_'])
{
//■DBから最新データの抽出
$sql_v = "SELECT * FROM inspection_record_t 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' 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];
$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) ? '--------':'確認済';
print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";
//●確認者・実施日のテキストボックスの有効/無効切り替え
$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>" .$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>";
//●調書
for($cp = 0 ;$cp < $record_ct;$cp++)
{
$cp2 = $cp+1;
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>" ." ";
// print "<TD><INPUT TYPE='submit' NAME='record_chk[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
print "<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='" .$no ."'> ";
print "<INPUT TYPE='hidden' NAME='list_no_' VALUE='" .$cp2 ."'> ";
print "</form>";
}
}
}
print "</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 " ";
}
}
}
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_'];
//■項目がチェックされた場合、DBをアップデート
if($_GET['list_no_'])
{
$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'];
$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 ;
$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_t 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_t 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_t 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 ." ORDER BY sort_no;";
$res_cl = pg_query($conn,$sql_cl);
$ct_cl = pg_num_rows($res_cl);
//■DBからチェックリストの項目名を抽出
$sql_item = "SELECT * FROM check_item_name WHERE on_flag=true ORDER BY id;";
$res_item = pg_query($conn,$sql_item);
$ct_item = pg_num_rows($res_item);
for($it =0;$it< $ct_item;$it++)
{
$row_item = pg_fetch_array($res_item,$it);
$id_item = $row_item['id'];
$item_name[$id_item] = $row_item['name'];
}
//■データ表の作成
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' 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='CheckPush(0,\"" .$no ."\");' >";
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[10];
$updatetime = $row[11];
$regdatetime = $row[12];
$chk_flag = ($row[13] === f) ? '--------':'確認済';
print "<TR ALIGN='center' ROWSPAN='" .$record_ct ."'>";
//●確認者・実施日のテキストボックスの有効/無効切り替え
$disabled = ($row[13] === 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'>";
//●調書
for($cp = 0 ;$cp < $record_ct;$cp++)
{
if($record[$cp])
{
$record_name = $record[$cp];
$record_name_v = explode("_",$record[$cp]);
if($cp+1 == $list_no)
{
if (file_exists($record_dir .$record_name))
{
print "<a href='download.php?u=1&f=" .$record_name ."'>" .$record_name_v[2] ."</a>" ." ";
print "<BR>";
// print "<TD><INPUT TYPE='submit' NAME='record_chk[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' ></TD>";
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 $row_cl['chk'] ;
//myfunc(value)$record_no
print "<INPUT TYPE='checkbox' NAME='check_list' VALUE='" .$cl_id ."' ".$checked ." onchange='myfunc(\"" .$no ."\",\"" .$list_no ."\",\"" .$cl ."\",\"" .$ct_cl ."\");' >" .$item_name[$cl_id] ."<BR>";
//print "<INPUT TYPE='submit' NAME='record_chk[]' VALUE='$chk_flag' onclick='CheckPush(\"" .$i ."\",\"" .$no ."\");' >";
//$row_item = pg_fetch_array($res_item,$it);
//$id_item = $row_item['id'];
//$item_name[$id_item] = $row_item['name'];
}
print "<BR>";
}
}
}
}
print " </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 " ";
}
}
}
print " </TD>";
//●記事の表示
print "<TD><INPUT TYPE='text' size='25' NAME='memo_reg' VALUE='" .$memo ."' " .$disabled ." ></TD>";
print "</TR>";
print "</TABLE>";
}
?>
</BODY>
</HTML>