evententry.php 6.2 KB
<?PHP 
header("Content-type: text/html; charset=shift-jis");

include('./include/smarty.conf');

//セッション開始
require_once("./include/session_start.inc");

include("./ini.php");
$o_smarty->assign('_USR_ROOT_URL_', $_USR_ROOT_URL_."/".$_SESSION["PHP_CAL_FOLDER"]."/calendar.php");


ob_start();

$home ="main_menu.php"; 
require('function/sortrog.inc');
require('function/operatezero.inc'); 
require('function/tblctl.inc');
require('function/tblmake.inc');
fun_backhome($hiduke);

list($eventy,$eventm,$eventd)=split(",",$hiduke);
$intCnt = $eventy;
$opt1 = "";
$opt1 .= "<option value=".$intCnt;
if ($fyear==$intCnt){
	$opt1 .= " selected";
}
$opt1 .= ">".$intCnt."年</option>";
$o_smarty->assign('opt1',$opt1);

$opt2 = "";
for ($intCnt = 1 ; $intCnt <= 12 ; $intCnt++) {
	if (strlen($intCnt)==1){
		$opt2 .= "<option value=0".$intCnt;
	}else{
		$opt2 .= "<option value=".$intCnt;
	}

	if ($eventm == $intCnt){
		$opt2 .= " selected";
	}
	$opt2 .= ">".$intCnt."月</option>";
}
$o_smarty->assign('opt2',$opt2);

$opt3 = "";
for ($intCnt = 1 ; $intCnt <= 31 ; $intCnt++) {
	if (strlen($intCnt)==1){
		$opt3 .= "<option value=0".$intCnt;
	}else{
		$opt3 .= "<option value=".$intCnt;
	}

	if ($eventd == $intCnt){
		$opt3 .= " selected";
	}
	$opt3 .= ">".$intCnt."日</option>";
}
$o_smarty->assign('opt3',$opt3);

$opt4 = "";
for ($intCnt = $eventy ; $intCnt <= $eventy+1 ; $intCnt++) {
	$opt4 .= "<option value=".$intCnt;
	if ($eventy==$intCnt){
		$opt4 .= " selected";
	}
	$opt4 .= ">".$intCnt."年</option>";
}
$o_smarty->assign('opt4',$opt4);

$opt5 = "";
for ($intCnt = 1 ; $intCnt <= 12 ; $intCnt++) {
	if (strlen($intCnt)==1){
		$opt5 .= "<option value=0".$intCnt;
	}else{
		$opt5 .= "<option value=".$intCnt;
	}

	if ($eventm == $intCnt){
		$opt5 .= " selected";
	}
	$opt5 .= ">".$intCnt."月</option>";
}
$o_smarty->assign('opt5',$opt5);

$opt6 = "";
for ($intCnt = 1 ; $intCnt <= 31 ; $intCnt++) {
	if (strlen($intCnt)==1){
		$opt6 .= "<option value=0".$intCnt;
	}else{
		$opt6 .= "<option value=".$intCnt;
	}

	if ($eventd == $intCnt){
		$opt6 .= " selected";
	}
	$opt6 .= ">".$intCnt."日</option>";
}
$o_smarty->assign('opt6',$opt6);

$o_smarty->assign('hidHiduke',"<input type=\"hidden\" name=\"hiduke\" value =$hiduke>");

$o_smarty->assign('dd', $dd);
$o_smarty->assign('home', $home);
$o_smarty->assign('pageName', $pageName);

//	カレンダー画面から引き継いだ情報を展開する。
		list($eventy,$eventm,$eventd)=split(",",$hiduke);
// Keyの日付を作成する。		
		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);
		 
// 送信ボタンが押されたときは、フォームの内容をファイルに保存する
	if ($submit != ""){ 
		// タグ無効化等の処理をする
		//$eventname = convstr($eventname);
		//$hpadrs = convstr($hpadrs);
		//$place = convstr($place);
		//$tipword = convstr($tipword);
		$eventymd = $from_date;
		//変更後の日付を取得
		$after_yy = substr($eventymd,0,4);
		$after_mm = substr($eventymd,4,2);
		$after_dd = substr($eventymd,6,2);

		// ログファイル名###
		$ddir = "./calendar/".$_SESSION["PHP_CAL_FOLDER"]."/data/event/";


		//イベント登録
		if (trim($to_date) ==""){
			$int_E_date=date("z",mktime(0,0,0,$after_mm,$after_dd,$after_yy));
		}else{
			$after_to_yy = substr($to_date,0,4);
			$after_to_mm = substr($to_date,4,2);
			$after_to_dd = substr($to_date,6,2);
			$int_E_date=date("z",mktime(0,0,0,$after_to_mm,$after_to_dd,$after_to_yy));
		}
		$int_S_date=date("z",mktime(0,0,0,$after_mm,$after_dd,$after_yy));


	
		for($intdateCnt = 0; $intdateCnt < ($int_E_date -$int_S_date+1) ; $intdateCnt++){

			//期間1、期間2の編集
			$str_wk_dd = $after_dd + $intdateCnt;

			$str_wk_dd = fun_addzero($str_wk_dd);
			$str_edit_date=date("Ymd",mktime(0,0,0,$after_mm,$str_wk_dd,$after_yy));
			
			//echo "日付".$str_edit_date."<BR>";

			//変更後の日付を取得
			$after_yy2 = substr($str_edit_date,0,4);
			$after_mm2 = substr($str_edit_date,4,2);
			$after_dd2 = substr($str_edit_date,6,2);

			//入力日付が引き継ぎ情報から変更された場合
			//if (fun_addzero($eventm) != $after_mm){
			//	$eventm = $after_mm;
			//}

			$logfile = "eventmst".$after_mm2.".csv";
			//$logfile = "eventmst".fun_addzero($eventm).".csv";
			$filename = $ddir.$logfile;

		// ログファイルを開く
			$fp = @fopen("$filename", "r+");
			if ($fp == False)
			{
				echo $filename = $ddir.$logfile;
				print("ファイルを開くのに失敗しました。<BR>\n");
				exit;
			}
			/*
			if ($from_date == $to_date){
				$tyear = "";
				$tmon = "";
				$tday = "";
			}
			*/
				// ファイルをロックする
				set_file_buffer($fp, 0);
				flock($fp, 2);
				// ファイルポインタをファイルの先頭に戻す
				rewind($fp);
				// メッセージの読み込み数を数える変数を初期化する
				$count = 0;
				// ファイルの最後まで読み込む
				while ($readbuf = fgetcsv_reg($fp,4096))
				{
						$buf[$count] = $readbuf;
						$count++;
				}
				
				// 配列の最後に、入力されたメッセージを追加する
				//echo $str_edit_date."<BR>";
				$buf[$count][0]=$str_edit_date; 
				$buf[$count][1]=fun_eveidx($buf,$count,$str_edit_date);
				$buf[$count][2]=$eventname;
				$buf[$count][3]=$fyear;
				$buf[$count][4]=fun_addzero($after_mm);
				$buf[$count][5]=fun_addzero($after_dd);
				$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;
				usort($buf,idxsort);
				usort($buf,mycmp);
				// ファイルポインタを先頭に戻す
				rewind($fp);

			// メッセージをファイルに書き込む
			for ($i = 0; $i <= $count; $i++){
				$tbl_save = join(",",$buf[$i]);
				//echo join(",",$buf[$i])."<BR>";
				fputs($fp, $tbl_save . "\n");
			}
			unset($buf);
			// ファイルのロックを解除して、ファイルを閉じる
			flock($fp, 3);
			fclose($fp);
		}

		/* ---------------------------------------------------------------------- */

			$mmanu = "<script>location.replace('main_menu.php');</script>";
	}
	$o_smarty->assign('mmanu', $mmanu);

$o_smarty->assign('PHP_CAL_NAME',$_SESSION["PHP_CAL_NAME"]);
$o_smarty->assign('PHP_manual_NM',"<a href='../e-manual/' target='_blank'>");

	$o_smarty->display('evententry_t.tpl');


$o_smarty->display('header.tpl');

	$o_smarty->display('evententry_f.tpl');

?>