eventreg.php 6.09 KB
<?php 
//*****************************************************************************
//* 
//* プログラム名:e-イベント
//* プログラムID:eventreg.php
//* 機能        :イベント登録処理
//* 作成者      :
//* 
//*****************************************************************************
ob_start();

//ソート手順の読み込み
require('function/sortrog.inc'); 

//ゼロ操作の読み込み
require('function/operatezero.inc');
require('function/tblctl.inc');
require('function/tblmake.inc');
fun_backhome($file_month);

list($event_ymd, $touroku_idx) = split(",", $kikan);
$eventy = substr($event_ymd, 0, 4);
$eventm = substr($event_ymd, 4, 2);
$eventd = substr($event_ymd, 6, 2); 
		 
// ログファイル名
$ddir = "data/event/";

if ($jun != ""){
	$from_date = $jyear.fun_addzero($jmon).$jun;
}else{
	$from_date = $fyear.fun_addzero($fmon).fun_addzero($fday);
}
$to_date = $tyear.fun_addzero($tmon).fun_addzero($tday);

// タグ無効化等の処理をする
$eventname = convstr($eventname);
$hpadrs = convstr($hpadrs);
$place = convstr($place);
$tipword = convstr($tipword);
$eventymd = $from_date;
list($key_ymd, $ev_idx)=split(",", $kikan);

//変更前の日付を取得
$befor_yy = substr($key_ymd, 0, 4);
$befor_mm = substr($key_ymd, 4, 2);
$befor_dd = substr($key_ymd, 6, 2);

//変更後の日付を取得
$after_yy = substr($eventymd, 0, 4);
$after_mm = substr($eventymd, 4, 2);
$after_dd = substr($eventymd, 6, 2);

// ログファイルを開く
$filename = "eventmst".fun_addzero($file_month).".csv";
$filename= $ddir.$filename;

$fp = @fopen($filename, "r+");

if ($fp == False){
	print("ファイルを開くのに失敗しました。<BR>\n");
	exit;
}

//	開始年月日と終了年月日が同じなら終了年月日は登録しない。
if ($from_date == $to_date){
	$tyear = "";
	$tmon = "";
	$tday = "";
}

// ファイルをロックする
set_file_buffer($fp, 0);
flock($fp, 2);
// ファイルポインタをファイルの先頭に戻す
rewind($fp);
// メッセージの読み込み数を数える変数を初期化する
$count = 0;
$lengs_cnt = 0;
$found = 0;

// ファイルの内容を読み込むクリアする元レコードの割り出し。
// とファイルのレコード件数を調べる。
while ($readbuf = fgetcsv($fp,4096)){
	$buf[$count] = $readbuf;
	list($mst_ymd, $mst_idx, $mstname, $mfyear, $mfmon, $mfday, $mtyear, $mtmon, $mtday, $m_place, $mhpadr, $mmsg) = $buf[$count];
	if (($mst_ymd == $key_ymd) && ($mst_idx == $ev_idx)){
		$sv_evidx = $buf[$count][1];
		$buf[$count] = "";
		$found = 1;
	}
	//$buf[$count][0]='"'.$buf[$count][0].'"';
	//$buf[$count][1]='"'.$buf[$count][1].'"';
	$buf[$count][2] = '"'.$buf[$count][2].'"';
	//$buf[$count][3]='"'.$buf[$count][3].'"';
	//$buf[$count][4]='"'.$buf[$count][4].'"';
	//$buf[$count][5]='"'.$buf[$count][5].'"';
	//$buf[$count][6]='"'.$buf[$count][6].'"';
	//$buf[$count][7]='"'.$buf[$count][7].'"';
	//$buf[$count][8]='"'.$buf[$count][8].'"';
	//$buf[$count][9]='"'.$buf[$count][9].'"';
	$buf[$count][10] = '"'.$buf[$count][10].'"';
	$buf[$count][11] = '"'.$buf[$count][11].'"';
	$count++;
}

if ($befor_mm == $after_mm){
	$buf[$count][0] = $eventymd;
	if ($key_ymd != $eventymd){
		$buf[$count][1] = fun_eveidx($buf, $count, $eventymd);
	}else{
		$buf[$count][1] = $sv_evidx;
	}
	$buf[$count][2] = '"'.$eventname.'"';
	$buf[$count][3] = $fyear;
	$buf[$count][4] = fun_addzero($fmon);
	$buf[$count][5] = fun_addzero($fday);
	$buf[$count][6] = $tyear;
	$buf[$count][7] = fun_addzero($tmon);
	$buf[$count][8] = fun_addzero($tday);
	$buf[$count][9] = $place;
	$buf[$count][10] = '"'.$hpadrs.'"';
	$buf[$count][11] = '"'.$tipword.'"';
	$count++;
}

array_multisort($buf, SORT_ASC);

fun_writetbl($buf, $count, $fp);

// ファイルのロックを解除して、ファイルを閉じる
flock($fp, 3);
fclose($fp);

//登録処理
if ($befor_mm != $after_mm){
	$filename = "eventmst".fun_addzero($after_mm).".csv";
	$filename = $ddir.$filename;

	$fp_new = @fopen($filename, "r+");
	if ($fp_new == False){
		print("ファイルを開くのに失敗しました。<BR>\n");
		exit;
	}

	if ($from_date == $to_date){
		$tyear = "";
		$tmon = "";
		$tday = "";
	}

	//ファイルをロックする
	set_file_buffer($fp_new, 0);
	flock($fp_new, 2);

	// ファイルポインタをファイルの先頭に戻す
	// メッセージの読み込み数を数える変数を初期化する
	$n_count = 0;
	while ($newrec = fgetcsv($fp_new, 4096)){
		$newbuf[$n_count] = $newrec;
		$n_count++;
	}

	$newbuf[$n_count][0] = $eventymd; 
	$newbuf[$n_count][1] = fun_eveidx($newbuf, $n_count, $eventymd);
	$newbuf[$n_count][2] = '"'.$eventname.'"';
	$newbuf[$n_count][3] = $fyear;
	$newbuf[$n_count][4] = fun_addzero($fmon);
	$newbuf[$n_count][5] = fun_addzero($fday);
	$newbuf[$n_count][6] = $tyear;
	$newbuf[$n_count][7] = fun_addzero($tmon);
	$newbuf[$n_count][8] = fun_addzero($tday);
	$newbuf[$n_count][9] = $place;
	$newbuf[$n_count][10] = '"'.$hpadrs.'"';
	$newbuf[$n_count][11] = '"'.$tipword.'"';
	$n_count++;
		
	if ($from_date < $to_date){
		$out_date = $from_date;
		while($out_date <= $to_date){
			$out_date = date("Ymd", strtotime($out_date." 1 day"));
			$newbuf[$n_count][0] = $out_date; 
			$newbuf[$n_count][1] = fun_eveidx($newbuf, $n_count, $out_date);
			$newbuf[$n_count][2] = '"'.$eventname.'"';
			$newbuf[$n_count][3] = $fyear;
			$newbuf[$n_count][4] = fun_addzero($fmon);
			$newbuf[$n_count][5] = fun_addzero($fday);
			$newbuf[$n_count][6] = $tyear;
			$newbuf[$n_count][7] = fun_addzero($tmon);
			$newbuf[$n_count][8] = fun_addzero($tday);
			$newbuf[$n_count][9] = $place;
			$newbuf[$n_count][10] = '"'.$hpadrs.'"';
			$newbuf[$n_count][11] = '"'.$tipword.'"';
			$n_count++;
		}
	}

	array_multisort($newbuf, SORT_ASC);
	fun_writetbl($newbuf, $n_count, $fp_new);
	flock($fp_new, 3);
	fclose($fp_new);
}

?>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=shift_jis">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>E_イベント管理者用画面</TITLE>

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function load_screen(){
	document.event_cal.action = "adminimenu.php";
	document.event_cal.method = "POST";
	document.event_cal.submit();
}
-->
</SCRIPT>
</HEAD>

<BODY onLoad="return load_screen();">
<form name="event_cal">
<INPUT type ="hidden" name="main_year" value ="<?php echo $main_year; ?>">
<INPUT type ="hidden" name="main_mon"  value ="<?php echo $main_mon; ?>">
<INPUT type ="hidden" name="syori"     value ="<?php echo $syori; ?>">
</form>
</BODY>
</HTML>