File "index2_20200514.php"

Full path: /www/hm-genkai_t/_bk/index2_20200514.php
File size: 28.32 KiB (28999 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 = "index.php?cid=" + cid + "&uid=" + uid+ "&date=" + date_;
}

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

</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);


//●プルダウンリストの読み込み
$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;
}



//■CSV出力処理
if(($_POST[csv_out1]) || ($_POST[csv_out2]) || ($_POST[csv_out3]) || ($_POST[csv_out4]))
{
	//日付-ユーザーID

	if($_POST[csv_out1])
	{
		//全て出力
		// ディレクトリハンドルの取得
		$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])
	{
		
		//グループ(会社)ごと出力
		
		//$cm_ct
		// ディレクトリハンドルの取得
		$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";
		//グループ数だけ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])
	{
		//ユーザー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]: ",," .$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_ = 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
	{
		//グループごと出力
		
		//グループ(会社)ごと出力
		
		//$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;
		
	}

	header('Location: download.php?f=' .$out_put_file_name );

/*
	//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 " .$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";
	print $zip_path;
	$cmd_3 = "zip -r " .$zip_path  ." /geye/*";
	exec($cmd_3);
	print $cmd_3 ;
	$file_name = $file_name_date .".zip";
	//exit;
	*/

}

//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 "</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_out2' VALUE='CSV出力(グループ)' 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_out4' VALUE='CSV出力(グループ)' style='width:120px;height:20px;font-size:8pt'>";
print "</TD>";
print "</TR>";
print "</form>";
print "</TABLE>";
print "</div>";
print "</div>";


//print "<input type=\"submit\" name=\"btnPrint\" value=\"csv出力\" style=\"width:90px\">"; 


?>

</BODY>
</HTML>

PHP File Manager