File "index2.php"

Full path: /www/hm-genkai_t/_bk/index2.php
File size: 32.6 KiB (33384 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="hm.css" TYPE="text/css">-->
</HEAD>

<?php
$age =  $_SERVER['HTTP_USER_AGENT'];

if(strpos($age, "Windows") || strpos($age, "iPad"))
{

}
else
{
	print "<style type='text/css'>";
	print ".wrap {";
	print "  width: 100%;";
	print "}.table {";
	print "  width: 100%;";
	print "  table-layout: fixed;";
	print "}";
	print ".table td,";
	print ".table th {";
	print "  border: 1px solid #DFDFDF;";
	print "  padding: 1rem;";
	print "}";
	print ".table tr > td:first-child,";
	print ".table tr > th:first-child{";
	print "  width: 30%; ";// 最初のカラムだけ30%のwidthを確保
	print "}";
	print "div.content {";
	print "  width: 100%;";
	print "}";
	print "div.content pre {";
	print "  display: block;";
	print "  width: 100%;";
	print "  overflow-x: auto;";
	print "  overflow-y: hidden;";
	print "  height: auto;";
	print "}";
	print ".txt3{";
	print "  font-size: 160%;";
	print "}";
	print ".txt4{";
	print "  font-size: 120%;";
	print "}";
	print "</style>";
}




?>
<script type = "text/javascript">

function functionName(cm_ct_)
{
    var cid = document.forms['formName'].elements['campany'].value;
	var uid_name = 'user_' + cid;
	document.forms['formName'].elements[uid_name].style.display = "block";
	document.forms['formName'].elements[uid_name].disabled = false;
	
	for(var i = 1;i <= cm_ct_;i++)
	{
		if(i != cid)
		{
			//未選択のプルダウンを非表示
			var del_name = 'user_' + i;
			document.forms['formName'].elements[del_name].style.display = "none";
			document.forms['formName'].elements[del_name].disabled = true;
		}
	}
}

//ユーザーデータの読み込み
function data_read()
{
	var cid = document.forms['formName'].elements['campany'].value;
	var uid_name = 'user_' + cid;
	var uid = document.forms['formName'].elements[uid_name].value;
	var date_ = document.forms['formName'].elements['date_'].value;
	
	//日時データの再形成
	//const date = date_.replace(/-/g, '')

	console.log(cid);
	console.log(uid);
	window.location.href = "index2.php?cid=" + cid + "&uid=" + uid+ "&date=" + date_;
}

//日付データからユーザーデータ読み込み


//対象のデータの削除・確認
function delete_chk()
{
	var data_no = null;
	if(window.confirm('表示中のデータを削除してもよろしいですか?'))
	{
		console.log("delete_ok");
//		location.href = "data_regist.php?del=" + data_no ;
	} 
	else
	{
		location.href = "index2.php";
	}

}

</script>


<?php
//●プルダウン作成
//横幅,データタイプ,NAME,VALUE,selected
function Pulldown_create($width,$type_ ,$name_,$value_,$selected){
	print "<select name='" .$name_ ."' style='width:" .$width ."px;' class='txt3'>";
	
	$value_ct = count($value_);
	
	
	for($j= 1 ;$j < $value_ct;$j++)
	{
		if($type_ == 0)
		{
			$sel = ($value_[$j] == $selected) ? "selected" : "";
			print "<option value='" .$value_[$j]."' " .$sel ." >" .$value_[$j] ."</option>";
		}
		else
		{
			$split = explode("_",$value_[$j]);
			$sel = ($split[0] == $selected) ? "selected" : "";
			print "<option value='" .$split[0]."' " .$sel ." >" .$split[1] ."</option>";
		}
	}

	if ($selected == 999) $sel = "selected";
	print "<option value='999' " .$sel .">   </option>";
	print "</select>";
}

//●会社名プルダウン
function Pulldown_create_campany($width,$cm_ct_ ,$name_,$data_ ,$selected)
{
	
	print "<select name='" .$name_ ."' onChange='functionName(\"" .$cm_ct_ ."\")' style='width:" .$width ."px;' class='txt3'>";
	$value_ct = count($data_);
	for($j= 0 ;$j < $value_ct;$j++)
	{
		$sel_data = explode(",",$data_[$j]);
		$sel = ($sel_data[0] == $selected) ? "selected" : "";
		print "<option value='" .$sel_data[0] ."' " .$sel ." >" .$sel_data[2] ."</option>";
	}
	print "</select>";
}

//●ユーザー名プルダウン
function Pulldown_create_user($width ,$cm_ct_,$data_,$selected)
{
	$value_ct = count($data_);
	for($i= 0 ;$i < $cm_ct_;$i++)
	{
		$ii = $i+1;
		print "<select name='user_" .$ii ."'  onChange='data_read()' style='width:" .$width ."px;display:none' id='user_" .$ii ."' class='txt3'>";
//		print "<select name='user_" .$ii ."'  style='width:" .$width ."px;display:none'>";
		$value_ct = count($data_);
		for($j= 0 ;$j < $value_ct;$j++)
		{
			$sel_data = explode(",",$data_[$j]);
			if( $ii == $sel_data[1])
			{
				$sel = ($sel_data[0] == $selected) ? "selected" : "";
				print "<option value='" .$sel_data[0] ."' " .$sel ." >" .$sel_data[4] ."</option>";
			}
		}
		print "</select>";
	}
}

//●ラジオボタン作成
function Radio_create($type_ ,$name_,$value_,$selected)
{
	print "<div class='txt3' >";
	$value_ct = count($value_);

	for($j= 1 ;$j < $value_ct;$j++)
	{
		if($type_ == 0)
		{
			$sel = ($value_[$j] == $selected) ? "checked='checked'" : "";
			print "<input type='radio' name='" .$name_  ."' value='" .$value_[$j]."' " .$sel .">" .$value_[$j] ."&nbsp;&nbsp;&nbsp;";
		}
		else
		{
			$split = explode("_",$value_[$j]);
			$sel = ($split[0] == $selected) ? "checked='checked'" : "";
			print "<input type='radio' name='" .$name_  ."' value='" .$split[0]."' " .$sel ."  >" .$split[1] ."&nbsp;&nbsp;&nbsp;";
		}
	}
	print "</div>";
}

/////////////////////////////////////////////////////////////////////////
EXTRACT($_GET);
//print_r($_GET);
//print_r($_POST);


//●プルダウンリストの読み込み
$fp = fopen("./setting/list.csv","r");
$pull_list = array();
$list = array();

// ファイルを1行ずつ取得する
while ($line = fgets($fp)) {
  $pull_list[] =  "$line";
}

$ct = count($pull_list);

//各リストを,で分割
for($i = 0;$i < $ct;$i++)
{
	$list[] = explode(",",$pull_list[$i]);
}


//プルダウンリスト(ユーザー名)読み込み
$fp2 = fopen("./setting/user.csv","r");
$cp_id= 0;
$cp_list =array();
$user_list = array();

while ($line = fgets($fp2)) {
	$explode_tmp = explode(",",$line);
	$cp_id_tmp = $explode_tmp[1];
	if(($cp_id_tmp != null) && $cp_id_tmp <= 8)
	{
		if(($cp_id_tmp != null) && ($cp_id != $cp_id_tmp))
		{
			$cp_list[$cp_id] = $cp_id_tmp ."," .$explode_tmp[2] ."," .$explode_tmp[3];
			$cp_id = $cp_id + 1;
		}
		
		$user_list[] = $line;
	}
}

//●ユーザー数
$user_ct = count($user_list);

//●会社数
$cm_ct = count($cp_list);
fclose($fp);

//日付 デフォルト
$now_date = date("Y-m-d",time());

//登録処理
function ascToHex($string)
{
    $hex = dechex(ord($string));
    if (strlen($hex) == 1) $hex = '0' . $hex;
    $string = '\\' . $hex;
    return $string;
}

if($_POST['data_input'])
{
	//会社ID,ユーザーID,日付を取得
	$company_id = $_POST['campany'];
	$user_id = $_POST["user_" .$company_id];
	$date_ = $_POST['date_'];
	
	$now_date = $date_;
	//●ユーザーデータが存在するかチェック
	//日付・ユーザー名
	$csv_file_name = $date_ ."-" .str_pad($company_id,2,0,STR_PAD_LEFT) ."-" .str_pad($user_id,3,0,STR_PAD_LEFT) .".csv";
	//print $csv_file_name ."<BR>";
		
	$csv_data = "./data/" .$csv_file_name;
	
	//ユーザーマスタからユーザーを検索
	$fp2 = fopen("./setting/user.csv","r");
	while ($line = fgets($fp2))
	{
		$split = explode(",",$line);
		if($split[0] == $user_id)
		{
			$user_data = $line;
			break;
		}
	}
	fclose($fp2);
	
	//取得したユーザーデータを分割
	$user_data_ = explode(",",$user_data);
	$file_csv = fopen($csv_data, "w");
	
	
	//出力するデータの準備
	$bt_asa = ($_POST[asa] == 999) ? "":$_POST[asa];
	$bt_hiru = ($_POST[hiru] == 999) ? "":$_POST[hiru];
	$bt_yuu = ($_POST[yuu] == 999) ? "":$_POST[yuu];
	$pc_seki=  ($_POST[seki] == 0) ? "なし" : "有";
	$pc_iki=  ($_POST[iki] == 0) ? "なし" : "有";
	$pc_hana=  ($_POST[hana] == 0) ? "なし" : "有";
	$pc_nodo=  ($_POST[nodo] == 0) ? "なし" : "有";
	$pc_zutsu=  ($_POST[zutsu] == 0) ? "なし" : "有";
	$pc_geri=  ($_POST[geri] == 0) ? "なし" : "有";
	$pc_mikaku=  ($_POST[mikaku] == 0) ? "なし" : "有";
	$pc_kyukaku=  ($_POST[kyukaku] == 0) ? "なし" : "有";
	$pc_kentai=  ($_POST[kentai] == 0) ? "なし" : "有";

	print $user_data_[4] ."  様 のデータを登録しました" ."<BR>";	
	$output_title = "会社名,氏名,日付,体温(朝),体温(昼),体温(夕),せき,息苦しさ,鼻水・鼻づまり,のどの痛み,頭痛,腹痛・下痢,味覚異常,嗅覚異常,倦怠感,その他";
	$output_data = $user_data_[3] ."," .$user_data_[4] ."," .$date_ ."," .$bt_asa ."," .$bt_hiru ."," .$bt_yuu ."," .$pc_seki ."," .$pc_iki ."," .$pc_hana ."," .$pc_nodo ."," .$pc_zutsu ."," .$pc_geri ."," .$pc_mikaku ."," .$pc_kyukaku ."," .$pc_kentai ."," .$_POST[etc];
	
	//出力するデータのエンコードを変更
	$output_title_conv = mb_convert_encoding($output_title , "Shift-JIS", "UTF-8");
	$output_data_conv =  mb_convert_encoding($output_data  , "Shift-JIS", "UTF-8");

	//csvへ出力
	fwrite($file_csv,$output_title_conv ."\r\n");
	fwrite($file_csv, $output_data_conv ."\r\n");
	fclose($file_csv);

}
else if($_GET[cid])
{
	$company_id = $_GET[cid];
	$user_id = $_GET[uid];
	$date_ = $_GET[date];
	$now_date = $date_;
	
	//日付・ユーザー名
	$csv_file_name = $date_ ."-" .str_pad($company_id,2,0,STR_PAD_LEFT) ."-" .str_pad($user_id,3,0,STR_PAD_LEFT) .".csv";
	//print $csv_file_name ."<BR>";
		
	$csv_data = "./data/" .$csv_file_name;
	
	//ユーザーデータが存在するかチェック
	if (file_exists($csv_data))
	{
		//ユーザーのステータス取得
		$fp3 = fopen($csv_data,"r");
		while ($line = fgets($fp3))
		{
			$user_satatus = $line;
		}
		fclose($fp3);
		
		$user_st = explode(",",$user_satatus);
		
		//文字コード変換
		$user_st[6] = mb_convert_encoding($user_st[6] , "UTF-8", "Shift-JIS");
		$user_st[7] = mb_convert_encoding($user_st[7] , "UTF-8", "Shift-JIS");
		$user_st[8] = mb_convert_encoding($user_st[8] , "UTF-8", "Shift-JIS");
		$user_st[9] = mb_convert_encoding($user_st[9] , "UTF-8", "Shift-JIS");
		$user_st[10] = mb_convert_encoding($user_st[10] , "UTF-8", "Shift-JIS");
		$user_st[11] = mb_convert_encoding($user_st[11] , "UTF-8", "Shift-JIS");
		$user_st[12] = mb_convert_encoding($user_st[12] , "UTF-8", "Shift-JIS");
		$user_st[13] = mb_convert_encoding($user_st[13] , "UTF-8", "Shift-JIS");
		$user_st[14] = mb_convert_encoding($user_st[14] , "UTF-8", "Shift-JIS");
		$user_st[15] = mb_convert_encoding($user_st[15] , "UTF-8", "Shift-JIS");

		$bt_asa = ($_POST[asa] == 999) ? "":$_POST[asa];
		$bt_hiru = ($_POST[hiru] == 999) ? "":$_POST[hiru];
		$bt_yuu = ($_POST[yuu] == 999) ? "":$_POST[yuu];
		
		$_POST[asa] = ($user_st[3]) ? $user_st[3]:999;
		$_POST[hiru] = ($user_st[4]) ? $user_st[4]:999;
		$_POST[yuu] = ($user_st[5]) ? $user_st[5]:999;
		$_POST[seki] = (!strcmp($user_st[6],"なし")) ? 0 : 1;
		$_POST[iki] = (!strcmp($user_st[7],"なし")) ? 0 : 1;
		$_POST[hana] = (!strcmp($user_st[8],"なし")) ? 0 : 1;
		$_POST[nodo] = (!strcmp($user_st[9],"なし")) ? 0 : 1;
		$_POST[zutsu] = (!strcmp($user_st[10],"なし")) ? 0 : 1;
		$_POST[geri] = (!strcmp($user_st[11],"なし")) ? 0 : 1;
		$_POST[mikaku] = (!strcmp($user_st[12],"なし")) ? 0 : 1;
		$_POST[kyukaku] = (!strcmp($user_st[13],"なし")) ? 0 : 1;
		$_POST[kentai] = (!strcmp($user_st[14],"なし")) ? 0 : 1;
		$_POST[etc] = $user_st[15];
	}
	else
	{
		$_POST[asa] = 999;
		$_POST[hiru] = 999;
		$_POST[yuu] = 999;
		$_POST[seki] = 0;
		$_POST[iki] = 0;
		$_POST[hana] = 0;
		$_POST[nodo] = 0;
		$_POST[zutsu] = 0;
		$_POST[geri] = 0;
		$_POST[mikaku] = 0;
		$_POST[kyukaku] = 0;
		$_POST[kentai] = 0;
	}
}
else
{
	$_POST[asa] = 999;
	$_POST[hiru] = 999;
	$_POST[yuu] = 999;
	$_POST[seki] = 0;
	$_POST[iki] = 0;
	$_POST[hana] = 0;
	$_POST[nodo] = 0;
	$_POST[zutsu] = 0;
	$_POST[geri] = 0;
	$_POST[mikaku] = 0;
	$_POST[kyukaku] = 0;
	$_POST[kentai] = 0;
}

//ファイルの削除
if($_POST['data_delete'])
{
	//会社ID,ユーザーID,日付を取得
	$company_id = $_POST['campany'];
	$user_id = $_POST["user_" .$company_id];
	$date_ = $_POST['date_'];
	
	$now_date = $date_;
	//●ユーザーデータが存在するかチェック
	//日付・ユーザー名
	$csv_file_name = $date_ ."-" .str_pad($company_id,2,0,STR_PAD_LEFT) ."-" .str_pad($user_id,3,0,STR_PAD_LEFT) .".csv";
	//print $csv_file_name ."<BR>";
		
	$csv_data = "./data/" .$csv_file_name;
	
	//データの初期化(削除)
	$cmd_del = "rm -Rf " .$csv_data;
	if(!exec($cmd_del)) print "削除しました";
}


//■CSV出力処理
if($_POST[csv_])
{
	//日付-ユーザーID

	if(($_POST[csv_out1]) || ($_POST[csv_view1]))
	{
		//全て出力
		// ディレクトリハンドルの取得
		$dir_h = opendir( "./data/" ) ;
		// ファイル・ディレクトリの一覧を $file_list 配列に
		while (false !== ($file_list[] = readdir($dir_h))) ;
		// ディレクトリハンドルを閉じる
		closedir( $dir_h ) ;
		 
		// ファイル名(降順)にする
		sort($file_list) ;
		 
		 //出力ファイル名の設定
		$out_put_file_name = date("Y-m-d",time()) .".csv";
		$fp_csv = fopen("./data/" .$out_put_file_name ,"w");
		$item = mb_convert_encoding("日付,会社名,ユーザーID,氏名,体温(朝),体温(昼),体温(夕),せき,息苦しさ,鼻水・鼻づまり,のどの痛み,頭痛,腹痛・下痢,味覚異常,嗅覚異常,倦怠感,その他", "Shift-JIS", "UTF-8");
		fwrite($fp_csv,$item ."\n");
		//ディレクトリ内のファイル名を1つずつを取得
		foreach ( $file_list as $file_name )
		{
			//ファイルのみを表示
			if( (is_file( "./data/" . $file_name)) && (strlen($file_name) == 21) )
			{
				//fwrite($fp_csv,$file_name ."\n");

				$fp_d = fopen("./data/" . $file_name ,"r");
				$data_ = array();
				//$list_ = array();

				// ファイルを1行ずつ取得する
				while ($line = fgets($fp_d)) {
				  $data_[] =  $line;
				}
				//各リストを,で分割
				$list_ = explode(",",$data_[1]);
				$split = explode("-",$file_name);
				$regist_date_ = $split[0] ."-" .$split[1] ."-" .$split[2];
				$regist_gp_ = $split[3];
				$regist_id_ =  substr($split[4],0,3);
							
				//$regist_date_ = mb_convert_encoding($regist_date_ , "UTF-8", "Shift-JIS");
							
				$date_ =(!strcmp($now_date_,$regist_date_)) ? "":$regist_date_;
				fwrite($fp_csv, $date_ ."," .$list_[0] ."," .$regist_id_ ."," .$list_[1] ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]);
				fclose($fp_d);
				$now_date_ = $regist_date_;
				//print $file_name  ."<BR>";
			}
		}
		fclose($fp_csv);
	}
	else if(($_POST[csv_out2]) || ($_POST[csv_view2]))
	{
		//グループ(会社)ごと出力
		
		//$cm_ct
		// ディレクトリハンドルの取得
		$dir_h = opendir( "./data/" ) ;
		// ファイル・ディレクトリの一覧を $file_list 配列に
		while (false !== ($file_list[] = readdir($dir_h))) ;
		// ディレクトリハンドルを閉じる
		closedir( $dir_h ) ;
		 
		// ファイル名(降順)にする
		sort($file_list) ;
		
		//グループ数だけCSVファイルを出力
		for($g = 0;$g < $cm_ct;$g++)
		{
			//出力ファイル名の設定
			$g_no = $g + 1;
			$out_put_file_name = "g" .str_pad($g_no,2,0,STR_PAD_LEFT) .".csv";
			$fp_csv[$g_no] = fopen("./data/" .$out_put_file_name ,"w");
			$item = mb_convert_encoding("日付,ユーザーID,氏名,体温(朝),体温(昼),体温(夕),せき,息苦しさ,鼻水・鼻づまり,のどの痛み,頭痛,腹痛・下痢,味覚異常,嗅覚異常,倦怠感,その他", "Shift-JIS", "UTF-8");
			fwrite($fp_csv[$g_no],$item ."\n");
		}

		//ディレクトリ内のファイル名を1つずつを取得
		foreach ( $file_list as $file_name )
		{
			//ファイルのみを表示
			if( (is_file( "./data/" . $file_name)) && (strlen($file_name) == 21) )
			{
				//fwrite($fp_csv,$file_name ."\n");

				$fp_d = fopen("./data/" . $file_name ,"r");
				$data_ = array();
				//$list_ = array();

				// ファイルを1行ずつ取得する
				while ($line = fgets($fp_d)) {
				  $data_[] =  $line;
				}
				//各リストを,で分割
				$list_ = explode(",",$data_[1]);
				$split = explode("-",$file_name);
				$regist_date_ = $split[0] ."-" .$split[1] ."-" .$split[2];
				$regist_gp_ = intval($split[3]);
				$regist_id_ =  substr($split[4],0,3);
							
				//$regist_date_ = mb_convert_encoding($regist_date_ , "UTF-8", "Shift-JIS");
							
				$date_ =(!strcmp($now_date_[$regist_gp_],$regist_date_)) ? "":$regist_date_;
				fwrite($fp_csv[$regist_gp_], $date_  ."," .$regist_id_ ."," .$list_[1] ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]);
				fclose($fp_d);
				$now_date_[$regist_gp_] = $regist_date_;
				//print $file_name  ."<BR>";
			}
		}
		for($g = 0;$g < $cm_ct;$g++)
		{
			//出力ファイル名の設定
			$g_no = $g + 1;
			fclose($fp_csv[$g_no]);
		}
		//zipの作成
		$zip_path = "g01_" .str_pad($cm_ct,2,0,STR_PAD_LEFT) .".zip";
		//print $zip_path;
		$cmd_3 = "zip -jD " ."./data/" .$zip_path  ." ./data/g*";
		exec($cmd_3);
		$out_put_file_name = $zip_path;
		
	}
	else if(($_POST[csv_out3]) || ($_POST[csv_view3]))
	{
		//ユーザーID-日付
		//全て出力
		// ディレクトリハンドルの取得
		$dir_h = opendir( "./data/" ) ;
		// ファイル・ディレクトリの一覧を $file_list 配列に
		while (false !== ($file_list[] = readdir($dir_h))) ;
		// ディレクトリハンドルを閉じる
		closedir( $dir_h ) ;
		 
		// ファイル名(降順)にする
		sort($file_list) ;
		 
		 //出力ファイル名の設定
		$out_put_file_name = date("Y-m-d",time()) ."_2.csv";
		$fp_csv = fopen("./data/" .$out_put_file_name ,"w");
		$item = mb_convert_encoding("ユーザーID,氏名,会社名,日付,体温(朝),体温(昼),体温(夕),せき,息苦しさ,鼻水・鼻づまり,のどの痛み,頭痛,腹痛・下痢,味覚異常,嗅覚異常,倦怠感,その他", "Shift-JIS", "UTF-8");
		fwrite($fp_csv,$item ."\n");
		//ディレクトリ内のファイル名を1つずつを取得
		$user_data = array();
		foreach ( $file_list as $file_name )
		{
			//ファイルのみを表示
			if( (is_file( "./data/" . $file_name)) && (strlen($file_name) == 21) )
			{
				//fwrite($fp_csv,$file_name ."\n");

				$fp_d = fopen("./data/" . $file_name ,"r");
				$data_ = array();
				//$list_ = array();

				// ファイルを1行ずつ取得する
				while ($line = fgets($fp_d)) {
				  $data_[] =  $line;
				}
				//各リストを,で分割
				$list_ = explode(",",$data_[1]);
				$split = explode("-",$file_name);
				$regist_date_ = $split[0] ."-" .$split[1] ."-" .$split[2];
				$regist_gp_ = intval($split[3]);
				$regist_id_ =  intval(substr($split[4],0,3));
				
				$user_data[$regist_id_] .= (!$user_data[$regist_id_]) ? substr($split[4],0,3) ."," .$list_[1] ."," .$list_[0] ."," .$regist_date_  ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]: ",,," .$regist_date_ .","  .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15];
				//$regist_date_ = mb_convert_encoding($regist_date_ , "UTF-8", "Shift-JIS");
				//fwrite($fp_csv, $date_ ."," .$list_[0] ."," .$regist_id_ ."," .$list_[1] ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]);
				fclose($fp_d);
				
			}
		}
		$csv_output = "";
		for($u = 1;$u <= $user_ct;$u++)
		{
			if($user_data[$u])
			{
				$csv_output .=$user_data[$u];
			}
		}
		fwrite($fp_csv,$csv_output);
		
		//print $file_name  ."<BR>";
		fclose($fp_csv);
	}
	else if(($_POST[csv_out4]) || ($_POST[csv_view4]))
	{
		//グループ(会社)ごと出力
		
		//$cm_ct
		// ディレクトリハンドルの取得
		$dir_h = opendir( "./data/" ) ;
		// ファイル・ディレクトリの一覧を $file_list 配列に
		while (false !== ($file_list[] = readdir($dir_h))) ;
		// ディレクトリハンドルを閉じる
		closedir( $dir_h ) ;
		 
		// ファイル名(降順)にする
		sort($file_list) ;
		
		//グループ数だけCSVファイルを出力
		for($g = 0;$g < $cm_ct;$g++)
		{
			//出力ファイル名の設定
			$g_no = $g + 1;
			$out_put_file_name = "ug" .str_pad($g_no,2,0,STR_PAD_LEFT) .".csv";
			$fp_csv[$g_no] = fopen("./data/" .$out_put_file_name ,"w");
			$item = mb_convert_encoding("ユーザーID,氏名,日付,体温(朝),体温(昼),体温(夕),せき,息苦しさ,鼻水・鼻づまり,のどの痛み,頭痛,腹痛・下痢,味覚異常,嗅覚異常,倦怠感,その他", "Shift-JIS", "UTF-8");
			fwrite($fp_csv[$g_no],$item ."\n");
		}

		//ディレクトリ内のファイル名を1つずつを取得
		foreach ( $file_list as $file_name )
		{
			//ファイルのみを表示
			if( (is_file( "./data/" . $file_name)) && (strlen($file_name) == 21) )
			{
				//fwrite($fp_csv,$file_name ."\n");

				$fp_d = fopen("./data/" . $file_name ,"r");
				$data_ = array();
				//$list_ = array();

				// ファイルを1行ずつ取得する
				while ($line = fgets($fp_d)) {
				  $data_[] =  $line;
				}
				//各リストを,で分割
				$list_ = explode(",",$data_[1]);
				$split = explode("-",$file_name);
				$regist_date_ = $split[0] ."-" .$split[1] ."-" .$split[2];
				$regist_gp_ = intval($split[3]);
				$regist_id_ =  intval(substr($split[4],0,3));
				
				$user_data[$regist_gp_][$regist_id_] .= (!$user_data[$regist_gp_][$regist_id_]) ? substr($split[4],0,3) ."," .$list_[1] ."," .$regist_date_  ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]: ",,"  .$regist_date_ .","  .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15];
						
				//$regist_date_ = mb_convert_encoding($regist_date_ , "UTF-8", "Shift-JIS");
							
				//$date_ =(!strcmp($now_date_[$regist_gp_],$regist_date_)) ? "":$regist_date_;
				//fwrite($fp_csv[$regist_gp_], $date_  ."," .$regist_id_ ."," .$list_[1] ."," .$list_[3] ."," .$list_[4] ."," .$list_[5] ."," .$list_[6] ."," .$list_[7] ."," .$list_[8] ."," .$list_[9] ."," .$list_[10] ."," .$list_[11] ."," .$list_[12] ."," .$list_[13]."," .$list_[14]."," .$list_[15]);
				//fclose($fp_d);
				//$now_date_[$regist_gp_] = $regist_date_;
				//print $file_name  ."<BR>";
			}
		}
		
		
		$csv_output = "";
		for($u = 1;$u <= $user_ct;$u++)
		{
			if($user_data[$u])
			{
				$csv_output .=$user_data[$u];
			}
		}
		fwrite($fp_csv,$csv_output);
		
		//print $file_name  ."<BR>";
		
		
		for($g = 0;$g < $cm_ct;$g++)
		{
			$csv_output ="";
			$g_no = $g + 1;
			for($u = 1;$u <= $user_ct;$u++)
			{
				if($user_data[$g_no][$u])
				{
					$csv_output .=$user_data[$g_no][$u];
				}
			}
			fwrite($fp_csv[$g_no],$csv_output);
			//出力ファイル名の設定

			fclose($fp_csv[$g_no]);
		}
		//zipの作成
		$zip_path = "ug01_" .str_pad($cm_ct,2,0,STR_PAD_LEFT) .".zip";
		//print $zip_path;
		$cmd_3 = "zip -jD " ."./data/" .$zip_path  ." ./data/ug*";
		exec($cmd_3);
		$out_put_file_name = $zip_path;
		
	}
	if(($_POST[csv_view1]) || ($_POST[csv_view2]) || ($_POST[csv_view3]) || ($_POST[csv_view4]))
	{
		$csv_view_flag = 1;
	}
	else
	{
		header('Location: download.php?f=' .$out_put_file_name );
	}

}

if(!$csv_view_flag)
{
	//print "<body bgcolor onLoad='functionName_t(\"" .$user_list ."\");data_read()'>";
	print "<body onLoad='functionName(\"" .$cm_ct ."\")'>";
	print "<form name='formName' enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";

	print "<div class='wrap'>";
	print "<TABLE BORDER='1' class='table'>";
	print "<TR>";
	print "<TD COLSPAN='2'  ALIGN='center' class='txt3'>" ."会社名" ."</TD>";
	print "<TD WIDTH='150'>";
	print Pulldown_create_campany(250,$cm_ct,"campany",$cp_list,$company_id);
	print "</TD>";
	print "</TR>";

	print "<TR>";
	print "<TD COLSPAN='2'  ALIGN='center' class='txt3'>" ."氏名" ."</TD>";
	print "<TD WIDTH='150'>";

	print Pulldown_create_user(250,$cm_ct,$user_list,$user_id);
	print "</TD>";
	print "</TR>";

	print "<TR>";
	print "<TD COLSPAN='2'  ALIGN='center' class='txt3'>" ."日付" ."</TD>";
	print "<TD WIDTH='150'>";
	print "<input type='date' name='date_' value='" .$now_date ."'  onChange='data_read()' style='width:250px;' class='txt3'></input>";
	print "</TD>";
	print "</TR>";


	//print "<select name='user_" .$ii ."'  onChange='data_read(\"user_" .$ii ."\")' style='width:" .$width ."px;display:none' id='user_" .$ii ."' class='txt3'>";



	print "<TR ALIGN='center'>";
	print "<TD ROWSPAN='3'  WIDTH='40' class='txt3'>" ."体温" ."</TD>";
	print "<TD WIDTH='120' class='txt3'>" ."朝" ."</TD>";
	print "<TD ALIGN='left' class='txt3'>";

	print Pulldown_create(150,0,"asa",$list[2],$_POST[asa]);
	print "℃" ."</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."昼" ."</TD>";
	print "<TD ALIGN='left' class='txt3'>";
	print Pulldown_create(150,0,"hiru",$list[3],$_POST[hiru]);
	print "℃" ."</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."夕" ."</TD>";
	print "<TD ALIGN='left' class='txt3'>";
	print Pulldown_create(150,0,"yuu",$list[4],$_POST[yuu]);
	print "℃" ."</TD>";
	print "</TR>";

	print "<TR ALIGN='center'>";
	print "<TD ROWSPAN='10' class='txt3'>" ."体調" ."</TD>";
	print "<TD  class='txt3'>" ."せき" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'seki',$list[5],$_POST[seki]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."息苦しさ" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'iki',$list[6],$_POST[iki]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."鼻水・鼻づまり" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'hana',$list[7],$_POST[hana]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."のどの痛み" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'nodo',$list[8],$_POST[nodo]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."頭痛" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'zutsu',$list[9],$_POST[zutsu]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."腹痛・下痢" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'geri',$list[10],$_POST[geri]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."味覚異常" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'mikaku',$list[11],$_POST[mikaku]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."嗅覚異常" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'kyukaku',$list[12],$_POST[kyukaku]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."倦怠感" ."</TD>";
	print "<TD ALIGN='left'>";
	print Radio_create(1,'kentai',$list[13],$_POST[kentai]);
	print "</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD class='txt3'>" ."その他" ."</TD>";
	if($_POST[etc]) $etc_value = " value = '" .$_POST[etc] ."'"; 
	print "<TD ALIGN='left'>" ."<INPUT TYPE='text' size='20' NAME='etc' " .$etc_value ." class='txt3'>" ."</TD>";
	print "</TR>";
	print "<TR ALIGN='center'>";
	print "<TD COLSPAN='3'>";
	print "<INPUT TYPE='submit' NAME='data_input' VALUE='登録' style='width:300px;height:40px;font-size:15pt'>";
	print "<INPUT TYPE='submit' NAME='data_delete' VALUE='削除' onclick='delete_chk()' style='width:100px;height:40px;font-size:15pt'>";
	print "</TD>";
	print "</TR>";
	print "</form>";
	print "<form name='csv' enctype='multipart/form-data' action='$_SERVER[PHP_SELF]' method='post'>";
	print "<TR>";
	print "<TD COLSPAN='2'>";
	print "日付-ユーザーID順";
	print "</TD>";
	print "<TD>";
	print "<INPUT TYPE='submit' NAME='csv_out1' VALUE='CSV出力(全て)' style='width:120px;height:20px;font-size:8pt'>";
	print "<INPUT TYPE='submit' NAME='csv_view1' VALUE='データ表示' style='width:120px;height:20px;font-size:8pt'>";
	print "<BR>";
	print "<INPUT TYPE='submit' NAME='csv_out2' VALUE='CSV出力(グループ別)' style='width:120px;height:20px;font-size:8pt'>";
	print "<INPUT TYPE='submit' NAME='csv_view2' VALUE='データ表示' style='width:120px;height:20px;font-size:8pt'>";
	print "</TD>";
	print "</TR>";

	print "<TR>";
	print "<TD COLSPAN='2'>";
	print "ユーザーID-日付順";
	print "</TD>";
	print "<TD>";
	print "<INPUT TYPE='submit' NAME='csv_out3' VALUE='CSV出力(全て)' style='width:120px;height:20px;font-size:8pt'>";
	print "<INPUT TYPE='submit' NAME='csv_view3' VALUE='データ表示' style='width:120px;height:20px;font-size:8pt'>";
	print "<BR>";
	print "<INPUT TYPE='submit' NAME='csv_out4' VALUE='CSV出力(グループ別)' style='width:120px;height:20px;font-size:8pt'>";
	print "<INPUT TYPE='submit' NAME='csv_view4' VALUE='データ表示' style='width:120px;height:20px;font-size:8pt'>";
	print "<INPUT TYPE='hidden' NAME='csv_' VALUE='1'>";
	print "</TD>";
	print "</TR>";
	print "</form>";
	print "</TABLE>";
	print "</div>";
	print "</div>";
}
else
{
	print "<TABLE><TR><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='reload' VALUE='画面更新' class='button'>";
	print "<INPUT TYPE='hidden' NAME='csv_out1' VALUE='" .$_POST[csv_out1] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_out2' VALUE='" .$_POST[csv_out2] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_out3' VALUE='" .$_POST[csv_out3] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_out4' VALUE='" .$_POST[csv_out4] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_view1' VALUE='" .$_POST[csv_view1] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_view2' VALUE='" .$_POST[csv_view2] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_view3' VALUE='" .$_POST[csv_view3] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_view4' VALUE='" .$_POST[csv_view4] ."'>";
	print "<INPUT TYPE='hidden' NAME='csv_' VALUE='1'>";
	print "</form>";
	print "</TD>";
	print "</TR>";
	print "</TABLE>";
	print "<INPUT TYPE='hidden' NAME='csv_' VALUE='1'>";
	print "</form>";
	
	if($_POST[csv_view1] || $_POST[csv_view3])
	{
		//CSVファイルを開く
		$fp_c = fopen("./data/" .$out_put_file_name,"r");

		$list = array();
		$data = array();
		
		// ファイルを1行ずつ取得する
		while ($line = fgets($fp_c))
		{
		  $list[] =  "$line";
		}

		$ct = count($list);
		
		
		//print mb_convert_encoding($list[$i], "UTF-8", "Shift-JIS") ."<BR>";
		
		print "<TABLE BORDER='1'>";
		//各リストを,で分割
		for($i = 0;$i < $ct;$i++)
		{
			$data = explode(",",$list[$i]);
			$data_ct = count($data);
			print "<TR>";
			$TD_start = ($i == 0) ? "<TH BGCOLOR='blue'><FONT SIZE ='2' COLOR='white'>" :"<TD>";
			$TD_end = ($i == 0) ? "</FONT></TH>" :"</TD>";

			for($d = 0;$d < $data_ct;$d++)
			{
				print $TD_start;
				print mb_convert_encoding($data[$d], "UTF-8", "Shift-JIS");
				print $TD_end;
			}
			print "</TR>";
		}
		print "</TABLE>";
		fclose($fp_c);
	}
	else if($_POST[csv_view2] || $_POST[csv_view4])
	{
		$file_type = ($_POST[csv_view2]) ? "g" : "ug";
		//グループ数だけCSVファイルを出力
		for($g = 0;$g < $cm_ct;$g++)
		{
			//会社名の取得
			$campany_data = explode(",",$cp_list[$g]);
			$campany_name = $campany_data[2];

			//読み込むファイルを設定
			$g_no = $g + 1;
			$out_put_file_name = $file_type .str_pad($g_no,2,0,STR_PAD_LEFT) .".csv";

			//CSVファイルを開く
			$fp_gc = fopen("./data/" . $out_put_file_name ,"r");
			$list = array();
			$data = array();

			// ファイルを1行ずつ取得する
			while ($line = fgets($fp_gc))
			{
			  $list[] =  "$line";
			}

			$ct = count($list);

			print "■" .$campany_name ."<BR>";
			print "<TABLE BORDER='1'>";
			//各リストを,で分割
			for($i = 0;$i < $ct;$i++)
			{
				$data = explode(",",$list[$i]);
				$data_ct = count($data);
				print "<TR>";
				$width ="";
				$TD_start = ($i == 0) ? "<TH BGCOLOR='blue'><FONT SIZE ='2' COLOR='white'>" :"<TD><FONT SIZE ='2'>";
				$TD_end = ($i == 0) ? "</FONT></TH>" :"</FONT></TD>";

				for($d = 0;$d < $data_ct;$d++)
				{
					print $TD_start;
					print mb_convert_encoding($data[$d], "UTF-8", "Shift-JIS");
					print $TD_end;
				}
				print "</TR>";
			}
			print "</TABLE>";
			fclose($fp_c);
			print "<BR>";
		}
	}
}


?>

</BODY>
</HTML>

PHP File Manager