<?php
/* ---------- ---------- ---------- ---------- *
                  Album Factory                
                                               
         利用規約を守ってご利用下さい。        
  http://www.coolandcool.net/pcg/notice.html   
                                               
          by CoolandCool (www.coolandcool.net) 
* ---------- ---------- ---------- ---------- */
$ver = "4.01";

mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
mb_detect_order("UTF-8,EUC-JP,UTF-8");
include("setup.php");
require("exifReader.inc");
set_form();


	
# {$_SERVER["QUERY_STRING"]}
if ( mb_strpos($_SERVER['HTTP_USER_AGENT'], "J-PHONE" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "Vodafone" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "SoftBank" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "J-EMULATOR" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "DoCoMo" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "KDDI" ) !== FALSE or mb_strpos($_SERVER['HTTP_USER_AGENT'], "UP.Browser" ) !== FALSE ) {
	if ( $_REQUEST["view"] or $_REQUEST["mode"] ) { header("Location: ./i.php?id={$_REQUEST["id"]}&num={$_REQUEST["num"]}&mode=view_res"); } else {
	header("Location: ./i.php?id={$_REQUEST["id"]}&num={$_REQUEST["num"]}");
	}
}




session_start();
if ( $_REQUEST["usr"] and !$_SESSION["usr"] )   { $_SESSION["usr"]  = $_REQUEST["usr"];  }
if ( $_REQUEST["pass"] and !$_SESSION["pass"] ) { $_SESSION["pass"] = $_REQUEST["pass"]; }
$find = time();

$sec_data  = @file("./_log/SeCuRiTy.php") or out_error("設定ファイルが読み取れません。");
$sec_vals  = mb_split("<>",   $sec_data[0]);
$deny_usr  = mb_split("<br>", $sec_vals[0]);
$deny_ip   = mb_split("<br>", $sec_vals[1]);
$deny_wrds = mb_split("<br>", $sec_vals[2]);

$cookie_data = mb_split("<>", $_COOKIE["coolalbum"] );
$cookie_sec  = mb_split("<>", $_COOKIE["coolusr"] );

foreach ( $deny_usr as $val ) {
	if ( $val != "" and $val == $cookie_data[0] ) { out_error("メンテナンス中です。"); }
}

foreach ( $deny_ip as $val ) {
	if ( $val != "" and mb_strpos($_SERVER["REMOTE_ADDR"], $val) !== FALSE ) { out_error("メンテナンス中です。"); }
}

if ( $cookie_sec[0] ) { out_error("メンテナンス中です。"); }
if ( $_REQUEST["from"] == "" ) { $_REQUEST["from"] = $_REQUEST["id"]; }



if ( !file_exists("_log/datafix") ) {
require("fixdata.php");
}



if ( !file_exists("_log/confix") ) {
	$config = @file("_log/config.php");
	
	if ( $config[0] != "<? php" ) {
	
	$file = @fopen("_log/config.php", "a") or out_error("ファイルオープンエラー");
	flock($file, LOCK_EX);
	ftruncate($file, 0);
	fputs($file, "<? php\n");
	foreach ( $config as $value ) {
		fputs($file, $value);
	}
	fputs($file, "php ?>\n");
	flock($file, LOCK_UN);
	fclose($file);
	
	$file = @fopen("_log/confix", "a") or out_error("ファイルオープンエラー");
	flock($file, LOCK_EX);
	flock($file, LOCK_UN);
	fclose($file);
	}
}

if ( mb_strpos($_REQUEST["id"], ".." ) !== FALSE ) { die(); }
if ( mb_strpos($_REQUEST["id"], "|" ) !== FALSE ) { die(); }
if ( mb_strpos($_REQUEST["id"], "pass" ) !== FALSE ) { die(); }
if ( mb_strpos($_REQUEST["id"], "http" ) !== FALSE ) { die(); }

# 摘出処理___________________________________________________________
$sorted_data = array();
$sorted_dir  = array();
$data = array();
$imdir = make_name(6);
$ckd = make_name(3);
$c_data = $sec_vals[4]; $secu_mode = mb_strlen($c_data);
if ( mb_strpos($_REQUEST["id"], "::" ) !== FALSE ) {
	$srt_switch = 1;
	$exif_srtdata = array('12' => 'カメラ名', '13' => 'ISO', '14' => '絞り値', '15' => '撮影日時', '16' => '露出モード', '17' => '露出補正', '18' => 'シャッター速度', '19' => 'ホワイトバランス', '22' => '測光モード', '23' => '撮影モード', '24' => '付記1', '25' => '付記2', '26' => '付記3', '27' => '付記4', '29' => '焦点距離', '30' => 'レンズ', '33' => 'メーカー' , '34' => 'フラッシュ', '35' => '露光モード', '36' => 'シャープネス', '37' => 'Jpeg画質');
	
	$srt_name = mb_split("::", $_REQUEST["id"]);
	if ( $srt_name[0] == "name" ) {
		$addsrt_title = "{$srt_name[1]}さんが撮影した写真を全てのアルバムから表示中";
	} else if ( $srt_name[0] == "cat" ) {
		$addsrt_title = "「{$srt_name[1]}」カテゴリに属する写真を全てのアルバムから表示中";
	} else if ( $srt_name[0] == "all" ) {
		$addsrt_title = "全ての写真を表示中";
	} else {
		$addsrt_title = "{$exif_srtdata["$srt_name[0]"]}に「{$srt_name[1]}」を含む写真を、全てのアルバムから表示中";
	}
	$confg_val_tl = $addsrt_title; #####
	
	
	$config = @file("_log/config.php");
	array_shift($config);
	array_pop($config);
	foreach ( $config as $val ) {
		$confg_val = mb_split("\t", $val);
		
		# データー読み込み
		$data = @file("./_log/{$confg_val[0]}.php");
		if ( ( $_REQUEST["mm"] and $_REQUEST["mm"] == rtrim($confg_val[0]) ) or ( !$confg_val[9] or ( $_SESSION["pass"] == $confg_val[10] and $_SESSION["usr"] == $confg_val[9] ) ) and $_REQUEST["nn"] != rtrim($confg_val[0]) and !$_REQUEST["mm"] ) {
			if ( !$data ) { $data = array(); }
			foreach ( $data as $data_vals ) {
				$data_val = mb_split("\t", $data_vals);
				
				# print $data_val["$srt_name[0]"] . " , " . $srt_name[1] . "<BR>";
				if ( $srt_name[0] == "all" ) {
					array_push($sorted_data, $data_vals);
					$sorted_dir["{$data_val[0]}"] = $confg_val[2];
					$sorted_id["{$data_val[0]}"]  = $confg_val[0];
					$sorted_pr["{$data_val[0]}"]  = $confg_val[17];
				}
				else if ( $srt_name[0] == "name" and $srt_name[1] == $data_val[2] ) {
					array_push($sorted_data, $data_vals);
					$sorted_dir["{$data_val[0]}"] = $confg_val[2];
					$sorted_id["{$data_val[0]}"]  = $confg_val[0];
					$sorted_pr["{$data_val[0]}"]  = $confg_val[17];
				}
				else if ( $srt_name[0] == "cat" and $srt_name[1] == $data_val[20] ) {
					array_push($sorted_data, $data_vals);
					$sorted_dir["{$data_val[0]}"] = $confg_val[2];
					$sorted_id["{$data_val[0]}"]  = $confg_val[0];
					$sorted_pr["{$data_val[0]}"]  = $confg_val[17];
				}
				else if ( mb_strpos($data_val["$srt_name[0]"], $srt_name[1]) !== FALSE ) {
					array_push($sorted_data, $data_vals);
					$sorted_dir["{$data_val[0]}"] = $confg_val[2];
					$sorted_id["{$data_val[0]}"]  = $confg_val[0];
					$sorted_pr["{$data_val[0]}"]  = $confg_val[17];
				}
			}
		}
	}
	$confg_val[1] = "{$img_dir}/title_b.jpg";
	$confg_val[3] = $confg_val_tl;
	$confg_val[4] = "";
}
else {
	$id_chck_flag = 0;
	$config = @file("_log/config.php");
	array_shift($config);
	array_pop($config);
	if ( $secu_mode != 224 ) { die(); }
	foreach ( $config as $val ) {
		$confg_val = mb_split("\t", $val);
		if ( $_REQUEST["id"] == $confg_val[0] ) { $id_chck_flag = 1; break; }
	}
	if ( $_REQUEST["id"] == "0" or !$_REQUEST["id"] ) { $_REQUEST["mode"] = "title"; }
	if ( !$id_chck_flag and !$_REQUEST["mode"] ) { die(); }
	if ( !$confg_val[1] ) { $confg_val[1] = "{$img_dir}/title_b.jpg"; }
}



# アクセスログ保存___________________________________________________
if ( mb_strpos($_SERVER["HTTP_REFERER"], $master_url) === FALSE ) {
	$time = time();
	$str  = "$time\t{$_SERVER["HTTP_REFERER"]}\t{$_SERVER["HTTP_USER_AGENT"]}\t{$_SERVER["REMOTE_ADDR"]}\t\n";
	$old_data = @file("./_log/accs.php");
	$data = @fopen("./_log/accs.php", "a+");
	@flock($data, LOCK_EX);
	if ( count($old_data) >= 1000 ) {
		array_splice($old_data, 0, count($old_data) - 200);
		ftruncate($data, 0);
		foreach ( $old_data as $val ) {
			fputs($data, $val);
		}
	}
	fputs($data, $str);
	@flock($data, LOCK_UN);
	fclose($data);
}



# 画像表示___________________________________________________________
if ( $_REQUEST["view"] ) {
	if ( !$_REQUEST["fe"] ) { die(); }
	$time = time(); $deny_flag = 0; $flag = 0;
	chck_accs();
	
	$data = @file("./_log/{$_REQUEST["id"]}.php");
	foreach ( $data as $values ) {
		$value = mb_split("\t", $values);
		if ( $value[0] == $_REQUEST["view"] ) { break; }
	}
	
	
	
#__ EDITER__
$befores = mb_split(",", $before_exif);
$afters  = mb_split(",", $after_exif);
foreach ( $befores as $ed_key => $ed_val ) {
	for ( $ed_i = 12; $ed_i <= 37; $ed_i++ ) {
		if ( $ed_i != 21 and $ed_i != 28 and $ed_i != 31 and $ed_i != 32 ) {
			$value[$ed_i] = mb_eregi_replace($ed_val, $afters[$ed_key], $value[$ed_i]);
		}
	}
}
	
	$file_name = make_name(6) . ".jpg";
	$dir = make_name(5);
	$fn = $_REQUEST[id];
	$fc = "";
	$fcs = unpack("H*", $_REQUEST["view"]);
	foreach ( $fcs as $val ) { $fc .= $val; }
	$fd = $find;
	
	if ( $value[18] ) { $dam = mb_split("\(", $value[18]); $dam = mb_split("\)", $dam[1]); $value[18] = rtrim($dam[0]) . "s&nbsp;&nbsp;"; }
	if ( $value[12] ) { $value[12] = "{$value[12]}・"; }
	if ( $value[29] and $value[29] != "\n" ) { $dam = mb_split(" ", $value[29]); $value[29] = " ・{$dam[0]}㎜"; }
	if ( $value[13] ) { $value[13] = "ISO" . $value[13] . "&nbsp;&nbsp;"; }
	if ( $value[17] ) { $dam = mb_split(" ", $value[17]); $value[17] = $dam[0] . "EV&nbsp;&nbsp;"; }
	if ( $value[1]  ) { $value[1] = "\"{$value[1]}\""; }
	
	
	
	if ( $confg_val[17] ) {
		 $imgtag = "<span align=center onMouseLeft=\"window.close();\" title=\"左クリックすると閉じます。\"><img src=\"{$img_dir}/{$confg_val[2]}/{$_REQUEST["view"]}{$value[28]}.jpg\"></span>";
		 
		 
		$chck_data = @file("./_log/acc_{$_REQUEST["view"]}.php");
		if ( !$chck_data ) { $chck_data = array(); }
		$accchck_data = array_reverse($chck_data);
		
		foreach ( $accchck_data as $vals ) {
			$val = mb_split("\t", $vals);
			if ( $val[0] == $_SERVER["REMOTE_ADDR"] ) { $flag ++; }
			if ( $time - $val[1] < $sec_vals[3] and $val[0] == $_SERVER["REMOTE_ADDR"] ) { $deny_flag ++; }
			if ( $deny_flag > 4 or $flag > 8 ) { break; }
		}
		
		if ( $deny_flag > 4 ) { 
			$cookie_data = "ocer<>$time<>";
			setcookie("coolusr", $cookie_data, time() + 10*24*60*60); die();
		}
		
		# ポイント処理
		$old_data = @file("./_log/acc_{$_REQUEST["view"]}.php");
		$data = @fopen("./_log/acc_{$_REQUEST["view"]}.php", "a+");
		flock($data, LOCK_EX);
		if ( count($old_data) >= 100 ) {
			array_splice($old_data, 0, 50);
			ftruncate($data, 0);
			foreach ( $old_data as $val ) {
				fputs($data, $val);
			}
		}
		fputs($data, "{$_SERVER["REMOTE_ADDR"]}\t$time\t\n");
		flock($data, LOCK_UN);
		fclose($data);
		
		if ( $flag < 8 ) {
			$img_cnt = @file("_log/{$_REQUEST["view"]}.php");
			$data = @fopen("_log/{$_REQUEST["view"]}.php", "a+");
			flock($data, LOCK_EX);
			$img_cnt[0] = rtrim($img_cnt[0]);
			if ( !$img_cnt[0] ) { $img_cnt[0] = "0"; }
			$img_cnt[0]++;
			ftruncate($data, 0);
			fputs($data, "{$img_cnt[0]}\n&pt={$img_cnt[0]}");
			flock($data, LOCK_UN);
			fclose($data);
		}
	 }
	else { $imgtag = "<span onMouseLeft=\"window.close();\" align=center><img src=\"./img.php?dir={$dir}&file={$file_name}&fn={$fn}&fc={$fc}&fd={$fd}\" title=\"左クリックすると閉じます。\"></span><div id=\"menu3\" style=\"position:absolute; left:0; top:0; z-index:3;\"><img src=\"./img/space.gif\" width={$value[10]} height={$value[11]} onMouseLeft=\"window.close();\" title=\"左クリックすると閉じます。\"></div>"; }
	if ( !$value[7] ) { $value[7] = $def_color; }
	
	
	
	print <<< EOD
<html>
<head>
<!-- 眉屈 -->
<Meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="expires" content="Sun, 10 Jan 1990 01:01:01 GMT">
<title>Album Factory</title></head>
<body text="#FFFFFF" bgColor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="img" style="position:absolute; left:0; top:0; z-index:2; filter:Alpha(opacity=70);"><table border="0" align="left" cellpadding="1" cellspacing="0" bgcolor="{$value[7]}"><tr><td align=left style="font-size:8pt; color:#FFFFFF;">{$value[12]} {$value[13]} {$value[18]} {$value[14]} {$value[24]} {$value[30]} {$value[29]}<br><div align=right>{$value[1]} Photoed by {$value[2]}</div></td></tr></table></div>{$imgtag}</body></html>
EOD;
	exit;
}


# 編集フォーム_______________________________________________________
else if ( $_REQUEST["mode"] == "edit" ) {
	chck_accs();
	if ( $confg_val[7] ) { $admin["color"] = mb_split(",", $confg_val[7]); }
	
	# クッキー取得
	$cookie_data = mb_split( "<>", $_COOKIE["coolalbum"] );
	
	# 各データー読み込み
	if ( $_REQUEST["type"] == "main" ) {
		if ( $srt_switch ) {
			$data = $sorted_data;
			$proxy_id = $sorted_id["{$_REQUEST["num"]}"];
			$confg_val[2] = $sorted_dir["{$_REQUEST["num"]}"];
		}
		else {
			$data = @file("./_log/{$_REQUEST["id"]}.php");
			$proxy_id = $_REQUEST["id"];
		}
		
		foreach ( $data as $value ) {
			$value = mb_split("\t", $value);
			if ( $value[0] == $_REQUEST["num"] ) { break; }
		}
		
		
		if ( $cookie_data[0] and $value[2] != $cookie_data[0] ) {
			out_error("異なるユーザーの記事を編集しようとしています。");
		} else if ( !$cookie_data[0] ) { $cookie_data[2] = ""; }
		
#__ EDITER__
$befores = mb_split(",", $before_exif);
$afters  = mb_split(",", $after_exif);
foreach ( $befores as $ed_key => $ed_val ) {
	for ( $ed_i = 12; $ed_i <= 37; $ed_i++ ) {
		if ( $ed_i != 21 and $ed_i != 28 and $ed_i != 31 and $ed_i != 32 ) {
			$value[$ed_i] = mb_eregi_replace($ed_val, $afters[$ed_key], $value[$ed_i]);
		}
	}
}
		
		
		if ( file_exists("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg") )
		 { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg"; }
		else { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg"; }
		$name    = $value[2];
		$email   = $value[3];
		$url     = $value[5];
		$title   = $value[1];
		$comment = $value[6];
		$color   = $value[7];
		$cat_u   = $value[20];
	}
	else {
		$data = @file("./_res/{$_REQUEST["num"]}.php");
		foreach ( $data as $value ) {
			$value = mb_split("\t", $value);
			if ( $value[0] == $_REQUEST["date"] ) { break; }
		}
		$name    = $value[1];
		$email   = $value[2];
		$url     = $value[4];
		$comment = $value[5];
		$color   = $value[6];
	}
	
	# フォーム用意 #####
	out_head();
	print <<< EOD
<br><p align=center class="user_fontsize"><b>+ 修正モード +</b></p>
	<script language="JavaScript">
<!--
function CloseChck(){
	cc=document.input;
	if (cc.comment.value!="") {
		if ( confirm("閉じるボタンが押されましたが、文章が入力されています。本当にこのウインドウを閉じてよろしいですか？") == true )
		{ window.close(); }
	} else { window.close(); }
}

//-->
</script>

<form name="input" action="album.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" value="edit_regist">
<input type="hidden" name="id" value="{$_REQUEST["id"]}">
<input type="hidden" name="proxy_id" value="{$proxy_id}">
<input type="hidden" name="num" value="{$_REQUEST["num"]}">
<input type="hidden" name="date" value="{$_REQUEST["date"]}">
<input type="hidden" name="tmpl" value="{$_REQUEST["tmpl"]}">
<input type="hidden" name="srt" value="{$_REQUEST["srt"]}">
<input type="hidden" name="page" value="{$_REQUEST["page"]}">
<input type="hidden" name="type" value="{$_REQUEST["type"]}">
<input type="hidden" name="from" value="{$_REQUEST["from"]}">
<input type="hidden" name="ck" value="{$_REQUEST["ck"]}">
<table width="460" border="1" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <td align="center" class="user_fontsize" width=65>名前</td>
    <td><input name="name" type="text" size="20" value="{$name}"></td>
    <td align="center" class="user_fontsize" width=65>メール</td>
    <td><input name="email" type="text" size="25" value="{$email}"></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize">修正キー</td>
    <td><input name="editkey" type="password" size="10" value="{$cookie_data[2]}"></td>
    <td align="center" class="user_fontsize">URL</td>
    <td><input name="url" type="text" size="25" value="{$url}"></td>
  </tr>
EOD;

	if ( $_REQUEST["type"] == "main" ) {
		
		$selA_val = mb_split(",", $confg_val[13]);
		array_unshift($selA_val, "");
		$selectA = "<select name=\"addA\">";
		foreach ( $selA_val as $vals ) {
			if ( $vals == $value[24] ) { $op = " selected"; } else { $op = ""; }
			$selectA .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$selectA .= "</select>";
		
		$selB_val = mb_split(",", $confg_val[14]);
		array_unshift($selB_val, "");
		$selectB = "<select name=\"addB\">";
		foreach ( $selB_val as $vals ) {
			if ( $vals == $value[25] ) { $op = " selected"; } else { $op = ""; }
			$selectB .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$selectB .= "</select>";
		
		$selC_val = mb_split(",", $confg_val[15]);
		array_unshift($selC_val, "");
		$selectC = "<select name=\"addC\">";
		foreach ( $selC_val as $vals ) {
			if ( $vals == $value[26] ) { $op = " selected"; } else { $op = ""; }
			$selectC .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$selectC .= "</select>";
		
		$selD_val = mb_split(",", $confg_val[16]);
		array_unshift($selD_val, "");
		$selectD = "<select name=\"addD\">";
		foreach ( $selD_val as $vals ) {
			if ( $vals == $value[27] ) { $op = " selected"; } else { $op = ""; }
			$selectD .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$selectD .= "</select>";
		
		
		$sel1_val = mb_split(",", $admin["data1"]);
		array_unshift($sel1_val, "");
		$select1 = "<select name=\"add1\">";
		foreach ( $sel1_val as $vals ) {
			if ( $vals == $value[12] ) { $op = " selected"; } else { $op = ""; }
			$select1 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select1 .= "</select>";
		
		$sel2_val = mb_split(",", $admin["data2"]);
		array_unshift($sel2_val, "");
		$select2 = "<select name=\"add2\">";
		foreach ( $sel2_val as $vals ) {
			if ( $vals == $value[13] ) { $op = " selected"; } else { $op = ""; }
			$select2 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select2 .= "</select>";
		
		$sel3_val = mb_split(",", $admin["data3"]);
		array_unshift($sel3_val, "");
		$select3 = "<select name=\"add3\">";
		foreach ( $sel3_val as $vals ) {
			if ( $vals == $value[17] ) { $op = " selected"; } else { $op = ""; }
			$select3 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select3 .= "</select>";
		
		$sel4_val = mb_split(",", $admin["data4"]);
		array_unshift($sel4_val, "");
		$select4 = "<select name=\"add4\">";
		foreach ( $sel4_val as $vals ) {
			if ( $vals == $value[19] ) { $op = " selected"; } else { $op = ""; }
			$select4 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select4 .= "</select>";
		
		$sel5_val = mb_split(",", $admin["data5"]);
		array_unshift($sel5_val, "");
		$select5 = "<select name=\"add5\">";
		foreach ( $sel5_val as $vals ) {
			if ( $vals == $value[16] ) { $op = " selected"; } else { $op = ""; }
			$select5 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select5 .= "</select>";
		
		$sel6_val = mb_split(",", $admin["data6"]);
		array_unshift($sel6_val, "");
		$select6 = "<select name=\"add6\">";
		foreach ( $sel6_val as $vals ) {
			if ( $vals == $value[22] ) { $op = " selected"; } else { $op = ""; }
			$select6 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select6 .= "</select>";
		
		$sel7_val = mb_split(",", $admin["data7"]);
		array_unshift($sel7_val, "");
		$select7 = "<select name=\"add7\">";
		foreach ( $sel7_val as $vals ) {
			if ( $vals == $value[23] ) { $op = " selected"; } else { $op = ""; }
			$select7 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select7 .= "</select>";
		
		$sel8_val = mb_split(",", $admin["data8"]);
		array_unshift($sel8_val, "");
		$select8 = "<select name=\"add8\">";
		foreach ( $sel8_val as $vals ) {
			if ( $vals == $value[30] ) { $op = " selected"; } else { $op = ""; }
			$select8 .= "<option value=\"{$vals}\"{$op}>{$vals}</option>";
		}
		$select8 .= "</select>";
		
		print <<< EOD
  <tr>
    <td align="center" class="user_fontsize" width=60>画像</td>
    <td colspan="3" class="user_fontsize"><img src=$thum_img><br><input name="file" type="file" size="20"><br><font size=2>* 画像を変更しない場合はそのままにします。</font></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize" width=60>カテゴリ</td><td colspan="3">
      <select name="cat">
EOD;

if ( $confg_val[8] ) { $cat = mb_split(",", $confg_val[8]); }
foreach ( $cat as $val ) {
	if ( $val == $cat_u ) { print "<option value=\"$val\" selected>$val</option>\n"; }
	else { print "<option value=\"$val\">$val</option>\n"; }
}

		print <<< EOD
  </select></td></tr>
  <tr>
    <td align="center" class="user_fontsize" width=60>画像回転</td>
    <td colspan="3" class="user_fontsize">
     <input name="degree" type="radio" value="0" checked>なし
&nbsp;<input name="degree" type="radio" value="270"><img src="img/90.gif" width="65" height="27" align="absmiddle">
&nbsp;<input name="degree" type="radio" value="90"><img src="img/270.gif" width="65" height="27" align="absmiddle">
&nbsp;<input name="degree" type="radio" value="180"><img src="img/180.gif" width="70" height="20" align="absmiddle">
    </td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize">タイトル</td>
    <td colspan="3"><input name="title" type="text" size="40" value="{$title}"></td>
  </tr>
EOD;
    }
	
	if ( $admin["color"][1] == "" ) { # 一色だけの場合はカラー選択非表示。
		print "<input type=hidden name=\"color\" value=\"{$admin["color"][0]}\">";
	} else {
		print "<tr><td align=\"center\" class=\"user_fontsize\">色</td><td colspan=\"3\">";
		foreach ( $admin["color"] as $key => $val ) {
			if ( $color == $val ) {
				print "<input name=\"color\" type=\"radio\" value=\"$val\" checked><font size=2 color=\"$val\">■</font>\n";
			} else if ( $val ) {
				print "<input name=\"color\" type=\"radio\" value=\"$val\"><font size=2 color=\"$val\">■</font>\n";
			}
		}
	print "</td></tr>";
	}

$comment = mb_ereg_replace("<br>", "\n", $comment);
print "<tr align=\"center\">\n<td colspan=\"4\"><textarea name=\"comment\" cols=\"50\" rows=\"5\">{$comment}</textarea>";
print "<div align=center class=\"font11pt\"><input type=\"checkbox\" name=\"del\" value=\"on\">削除&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"    保存    \">&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='閉じる' onClick='return CloseChck()'></div></td></tr>";

	if ( $_REQUEST["type"] == "main" ) {
print <<<EOD
<tr><td colspan=4><table width=100% border=0 cellpadding=4 cellspacing=0 style="border-collapse: collapse; border: 0px solid #999999;">
<tr>
    <td align="center" valign="top" class="inputtable">メーカー</td>
    <td class="inputtable"><input name="id33" type="text" size="30" value="{$value[33]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">機種</td>
    <td class="inputtable"><input name="id12" type="text" size="40" value="{$value[12]}"><br>{$select1}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">撮影日時</td>
    <td class="inputtable"><input name="id15" type="text" size="30" value="{$value[15]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">ISO</td>
    <td class="inputtable"><input name="id13" type="text" size="30" value="{$value[13]}"><br>{$select2}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">シャッター速度</td>
    <td class="inputtable"><input name="id18" type="text" size="30" value="{$value[18]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">露出補正</td>
    <td class="inputtable"><input name="id17" type="text" size="30" value="{$value[17]}"><br>{$select3}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">フラッシュ</td>
    <td class="inputtable"><input name="id34" type="text" size="30" value="{$value[34]}"><BR>{$selectAdd2}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">ホワイトバランス</td>
    <td class="inputtable"><input name="id19" type="text" size="30" value="{$value[19]}"><br>{$select4}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">絞り</td>
    <td class="inputtable"><input name="id14" type="text" size="30" value="{$value[14]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">焦点距離</td>
    <td class="inputtable"><input name="id29" type="text" size="30" value="{$value[29]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">レンズ</td>
    <td class="inputtable"><input name="id30" type="text" size="30" value="{$value[30]}"><br>{$select8}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">露光モード</td>
    <td class="inputtable"><input name="id35" type="text" size="30" value="{$value[35]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">測光モード</td>
    <td class="inputtable"><input name="id22" type="text" size="30" value="{$value[22]}"><br>{$select6}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">露光</td>
    <td class="inputtable"><input name="id16" type="text" size="30" value="{$value[16]}"><br>{$select5}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">撮影モード</td>
    <td class="inputtable"><input name="id23" type="text" size="30" value="{$value[23]}"><br>{$select7}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">シャープネス</td>
    <td class="inputtable"><input name="id36" type="text" size="30" value="{$value[36]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">Jpeg画質</td>
    <td class="inputtable"><input name="id37" type="text" size="30" value="{$value[37]}"></td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">付記1</td>
    <td class="inputtable"><input name="id24" type="text" size="30" value="{$value[24]}"><BR>{$selectA}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">付記2</td>
    <td class="inputtable"><input name="id25" type="text" size="30" value="{$value[25]}"><BR>{$selectB}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">付記3</td>
    <td class="inputtable"><input name="id26" type="text" size="30" value="{$value[26]}"><BR>{$selectC}</td></tr>
<tr>
    <td align="center" valign="top" class="inputtable">付記4</td>
    <td class="inputtable"><input name="id27" type="text" size="30" value="{$value[27]}"><BR>{$selectD}</td></tr></table>
</td></tr>
EOD;
}
print "</table></form><hr>";
out_footer();
exit;
}


# 編集記事保存_______________________________________________________
else if ( $_REQUEST["mode"] == "edit_regist" ) {
	
	chck_accs();
	
	
	# 各データー読み込み
	if ( $_REQUEST["type"] == "main" ) {
		$data = @file("./_log/{$_REQUEST["proxy_id"]}.php");
		foreach ( $data as $value ) {
			$value = mb_split("\t", $value);
			if ( $value[0] == $_REQUEST["num"] ) { break; }
		}
	$master_key = $value[4];
	}
	else {
		$data = @file("./_res/{$_REQUEST["num"]}.php");
		foreach ( $data as $value ) {
			$value = mb_split("\t", $value);
			if ( $value[0] == $_REQUEST["date"] ) { break; }
		}
	$master_key = $value[3];
	}
	if ( $srt_switch ) { $confg_val[2] = $sorted_dir["{$_REQUEST["num"]}"]; }
	if ( !$_REQUEST["editkey"] ) { out_error("修正キーが見えません。"); }
	if ( $_REQUEST["editkey"] != $master_key and $_REQUEST["editkey"] != $password and $_REQUEST["editkey"] != $confg_val[11] ) { out_error("修正キーが正しくありません。"); }
	
	
	if ( $confg_val[18] ) { $max_width   = $confg_val[18]; }
	if ( $confg_val[19] ) { $max_height  = $confg_val[19]; }
	if ( $confg_val[20] ) { $view_width  = $confg_val[20]; }
	if ( $confg_val[21] ) { $view_height = $confg_val[21]; }
	if ( $confg_val[23] and $confg_val[23] != "\n" ) { $i_width  = $confg_val[23]; }
	if ( $confg_val[24] and $confg_val[24] != "\n" ) { $i_height = $confg_val[24]; }
	
	$new_data = array();
	if ( $_REQUEST["type"] == "main" ) { # 親記事処理
		foreach ( $data as $values ) {
			$value = mb_split("\t", $values);
			if ( $value[0] == $_REQUEST["num"] ) {
				
				if ( $_FILES["file"]["tmp_name"] ) {
					if ( !is_uploaded_file($_FILES["file"]["tmp_name"]) ) { out_error("ファイルある？"); }
					
					$er = new phpExifReader($_FILES["file"]["tmp_name"]);
					$er->Debugging = 1;
					$Exif = $er->getImageInfo();
					
			## 追加Exif
			$_REQUEST["id33"] = $maker = $Exif["make"];    # メーカー
			$_REQUEST["id34"] = $flash = $Exif["flashUsed"];    # フラッシュの利用
			$_REQUEST["id36"] = $sharpness = $Exif["sharpness"];    # シャープネス設定
			$_REQUEST["id35"] = $etype = $Exif["exposureMode"]; # 露光モード
			$_REQUEST["id37"] = $jpegq = $Exif["jpegQuality"]; # Jpeg画質
			
			$_REQUEST["id12"] = $model   = $Exif["model"];    # 機種
			$_REQUEST["id13"] = $iso     = $Exif["isoEquiv"]; # ISO
			$_REQUEST["id14"] = $fnumber = $Exif["fnumber"];  # 絞り
			$_REQUEST["id15"] = $picdate = $Exif["dateTimeDigitized"]; # 撮影日時
			if ( !$Exif["dateTimeDigitized"] ) { $picdate = $Exif["DateTime"]; }
			$_REQUEST["id16"] = $ftype   = $Exif["exposure"]; # 撮影モード
			$_REQUEST["id17"] = $bright  = $Exif["exposureBias"]; # 露出補正
			$_REQUEST["id18"] = $ftime   = $Exif["exposureTime"]; # シャッター速度
			$_REQUEST["id19"] = $white   = $Exif["whiteBalance"]; # ホワイトバランス
			$_REQUEST["id22"] = $sokko   = $Exif["meteringMode"]; # 測光方式
			$_REQUEST["id23"] = $scene   = $Exif["screenCaptureType"]; # 撮影モード
			$flength = $Exif["focalLength"];  # 焦点距離
			if ( $Exif["flength35mm"] ) { $flength = $Exif["flength35mm"] . "(35mm換算)"; }
					
					$tmp_filename = time();
					$img_file = $_FILES["file"]["tmp_name"];
					list($width, $height, $type) = getimagesize($img_file);
					
					if ( $_REQUEST["degree"] ) {
						     if ( $type == 2 ) { $img_f = imagecreatefromjpeg($img_file); }
						else if ( $type == 3 ) { $img_f = imagecreatefrompng ($img_file); }
						else if ( $type == 1 ) { $img_f = imagecreatefromgif ($img_file); }
						
						$img_f = ImageRotate($img_f, $_REQUEST["degree"], 0);
						imagejpeg($img_f, "{$img_dir}/$tmp_filename.jpg", 100);
						chmod("{$img_dir}/$tmp_filename.jpg", 0644);
						$img_file = "{$img_dir}/$tmp_filename.jpg";
						imagedestroy($img_f);
					}
					
					
					list($width, $height, $type) = getimagesize($img_file);
					
					# サムネイル画像生成処理
					$flag_resize = 0;
					if ( $width > $view_width or $height > $view_height ) {
						$flag_resize = 1;
						$rate_width  = $view_width  / $width;
						$rate_height = $view_height / $height;
						if ( $rate_width < $rate_height ) { $rate = $rate_width; }
						else { $rate = $rate_height; }
						$new_width  = (int) ( $width  * $rate );
						$new_height = (int) ( $height * $rate );
					}
					else { $new_width = $width; $new_height = $height; }
					
					if ( $flag_resize ) {
						if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
						else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
						else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
						
						$new_img = imagecreatetruecolor($new_width, $new_height);
						imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
						imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg", 90);
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg", 0644);
						imagedestroy($new_img);
					} else {
						# copy($img_file, "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg");
						# chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg", 0644);
					}
					
					@imagedestroy($dst); @imagedestroy($src);
					
					$src = imagecreatefromjpeg($img_file) or out_error("Jpgファイルの生成に失敗。 $img_file");
					$dst = imagecreatetruecolor(30, 30);
					
			if ( $width > 150 and $height > 150 ) {
				$width1  = (int) ( $width / 2.5 );
				$height1 = (int) ( $height / 2.5 );
				
						if ( $width1 < $height1 ) { $cw = $height1; }
						else { $cw = $width1; }
				
						if ( $width > $height ) {
							$r_w = rand(-$width / 15, $width / 15);
							$r_h = rand(-$height / 20, $height / 20);
						} else {
							$r_w = rand(-$width / 20, $width / 20);
							$r_h = rand(-$height / 15, $height / 15);
						}
				
						imagecopyresampled ($dst, $src, 0, 0, ( $width - ((7/10)*$width)) + $r_w, ( $height - ((7/10)*$height)) + $r_h, 30, 30, $cw, $cw) or out_error("画像ファイルの縮小処理に失敗。");
						#	@imagefilter($dst, IMG_FILTER_CONTRAST, -20);
						#	@imagefilter($dst, IMG_FILTER_BRIGHTNESS, 10);
						imagejpeg ($dst, "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 90);
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 0644);
					}
					else if ( $width > 30 or $height > 30 ) {
						
						if ( $width > $height ) { $s_w = ( $width - $height ) / 2; $s_h = 0; $width = $height; }
						else { $s_h = ( $height - $width ) / 2; $s_w = 0; $height = $width; }
						
						imagecopyresampled ($dst, $src, 0, 0, $s_w, $s_h, 30, 30, $width , $height) or out_error("画像ファイルの縮小処理に失敗。");
						#	@imagefilter($dst, IMG_FILTER_CONTRAST, -20);
						#	@imagefilter($dst, IMG_FILTER_BRIGHTNESS, 10);
						imagejpeg ($dst, "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 90);
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 0644);
					} else {
						copy($img_file, "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg");
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 0644);
					}
					
					@imagedestroy($dst); @imagedestroy($src);
					
			
			
			# ケータイ用表示画像
			$flag_resize = 0;
			if ( $width > $i_width or $height > $i_height ) {
				$flag_resize = 1;
				$rate_width  = $i_width  / $width;
				$rate_height = $i_height / $height;
				if ( $rate_width < $rate_height ) { $rate = $rate_width; }
				else { $rate = $rate_height; }
				$n_width  = (int) ( $width  * $rate );
				$n_height = (int) ( $height * $rate );
			}
			else { $n_width = $width; $n_height = $height; }
			
			if ( $flag_resize ) {
			    if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
				else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
				else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
				
				$new_img = imagecreatetruecolor($n_width, $n_height);
				imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
				imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg", 0644);
				imagedestroy($new_img);
				$m_width  = $new_width; $m_height = $new_height;
			} else {
				# copy($img_file, "{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg");
				# chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg", 0644);
				$m_width  = $new_width; $m_height = $new_height;
			}
			
			
					
					# 表示用画像処理
					$flag_resize = 0;
					if ( $width > $max_width or $height > $max_height or $type == 3 or $type == 1 ) {
						$flag_resize = 1;
						$rate_width  = $max_width  / $width;
						$rate_height = $max_height / $height;
						if ( $rate_width < $rate_height ) { $rate = $rate_width; }
						else { $rate = $rate_height; }
						$new_width  = (int) ( $width  * $rate );
						$new_height = (int) ( $height * $rate );
						
						if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
						else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
						else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
						
						$new_img = imagecreatetruecolor($new_width, $new_height);
						
						if ( $flag_resize ) {
							imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
						}
						else { imagecopy($new_img, $img_src, 0, 0, 0, 0, $width, $height); }
						
						imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg", 90);
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg", 0644);
						imagedestroy($new_img);
						$or_width  = $new_width; $or_height = $new_height;
					}
					else {
						move_uploaded_file($img_file, "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg");
						chmod("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg", 0644);
						$or_width = $width; $or_height = $height;
					}
					
				} else {
					
					
					if ( $_REQUEST["degree"] ) {
						$img_src = imagecreatefromjpeg("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg");
						$img_f = ImageRotate($img_src, $_REQUEST["degree"], 0);
						imagejpeg($img_f, "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg", 100);
						list($width, $height, $type) = getimagesize("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg");
						$or_width = $width; $or_height = $height;
						
						$img_src = imagecreatefromjpeg("{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg");
						$img_f = ImageRotate($img_src, $_REQUEST["degree"], 0);
						imagejpeg($img_f, "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg", 100);
						
						$img_src = imagecreatefromjpeg("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg");
						$img_f = ImageRotate($img_src, $_REQUEST["degree"], 0);
						imagejpeg($img_f, "{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg", 100);
						list($width, $height, $type) = getimagesize("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg");
						$m_width = $width; $m_height = $height;
						
						$img_src = imagecreatefromjpeg("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg");
						$img_f = ImageRotate($img_src, $_REQUEST["degree"], 0);
						imagejpeg($img_f, "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg", 100);
						list($width, $height, $type) = getimagesize("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg");
						$new_width = $width; $new_height = $height;
						
						imagedestroy($img_f);
					}
					else {
						$new_width  = $value[8];
						$new_height = $value[9];
						$or_width   = $value[10];
						$or_height  = $value[11];
					}
				}
				
				
				
				
				# 保存データー用意
				
				if ( !$_REQUEST["id24"] ) { $_REQUEST["id24"] = $_REQUEST["addA"]; }
				if ( !$_REQUEST["id25"] ) { $_REQUEST["id25"] = $_REQUEST["addB"]; }
				if ( !$_REQUEST["id26"] ) { $_REQUEST["id26"] = $_REQUEST["addC"]; }
				if ( !$_REQUEST["id27"] ) { $_REQUEST["id27"] = $_REQUEST["addD"]; }
				
				if ( !$_REQUEST["id12"] ) { $_REQUEST["id12"] = $_REQUEST["add1"]; }
				if ( !$_REQUEST["id13"] ) { $_REQUEST["id13"] = $_REQUEST["add2"]; }
				if ( !$_REQUEST["id17"] ) { $_REQUEST["id17"] = $_REQUEST["add3"]; }
				if ( !$_REQUEST["id19"] ) { $_REQUEST["id19"] = $_REQUEST["add4"]; }
				if ( !$_REQUEST["id16"] ) { $_REQUEST["id16"] = $_REQUEST["add5"]; }
				if ( !$_REQUEST["id22"] ) { $_REQUEST["id22"] = $_REQUEST["add6"]; }
				if ( !$_REQUEST["id23"] ) { $_REQUEST["id23"] = $_REQUEST["add7"]; }
				if ( !$_REQUEST["id30"] ) { $_REQUEST["id30"] = $_REQUEST["add8"]; }
				
				$editdata = "{$value[0]}\t{$_REQUEST["title"]}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$value[4]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment"]}\t{$_REQUEST["color"]}\t{$new_width}\t{$new_height}\t{$or_width}\t{$or_height}\t{$_REQUEST["id12"]}\t{$_REQUEST["id13"]}\t{$_REQUEST["id14"]}\t{$_REQUEST["id15"]}\t{$_REQUEST["id16"]}\t{$_REQUEST["id17"]}\t{$_REQUEST["id18"]}\t{$_REQUEST["id19"]}\t{$_REQUEST["cat"]}\t{$_SERVER["REMOTE_ADDR"]}\t{$_REQUEST["id22"]}\t{$_REQUEST["id23"]}\t{$_REQUEST["id24"]}\t{$_REQUEST["id25"]}\t{$_REQUEST["id26"]}\t{$_REQUEST["id27"]}\t{$value[28]}\t{$_REQUEST["id29"]}\t{$_REQUEST["id30"]}\t{$m_width}\t{$m_height}\t{$_REQUEST["id33"]}\t{$_REQUEST["id34"]}\t{$_REQUEST["id35"]}\t{$_REQUEST["id36"]}\t{$_REQUEST["id37"]}\t\n"; //33
				
				if ( !$_REQUEST["del"] ) { # 編集記事を保存する場合
					
					array_push($new_data, $editdata);
					
					$upinfo = @file("./_log/upinfo.php");
					if ( !$upinfo ) { $upinfo = array(); }
					$usr_file = @fopen("_log/upinfo.php", "a") or out_error("ファイルオープンエラー");
					flock($usr_file, LOCK_EX);
					ftruncate($usr_file, 0);
					foreach ( $upinfo as $val ) {
						$vals = mb_split("\t", $val);
						if ( $_REQUEST["num"] != $vals[0] ) { fputs($usr_file, $val); }
						else { fputs($usr_file, "{$value[0]}\t{$_REQUEST["proxy_id"]}\t{$img_dir}/{$confg_val[2]}\t{$_REQUEST["title"]}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment"]}\t{$picdate}\t{$_REQUEST["color"]}\t{$new_width}\t{$new_height}\t{$or_width}\t{$or_height}\t{$_REQUEST["cat"]}\t{$value[28]}\t\n" ); }
					}
					flock($usr_file, LOCK_UN);
					fclose($usr_file);
					
				} else { # 記事削除の場合
					
					$upinfo = @file("./_log/upinfo.php");
					if ( !$upinfo ) { $upinfo = array(); }
					$usr_file = @fopen("_log/upinfo.php", "a") or out_error("ファイルオープンエラー");
					flock($usr_file, LOCK_EX);
					ftruncate($usr_file, 0);
					foreach ( $upinfo as $val ) {
						$vals = mb_split("\t", $val);
						if ( $_REQUEST["num"] != $vals[0] ) { fputs($usr_file, $val); }
					}
					flock($usr_file, LOCK_UN);
					fclose($usr_file);
					
					@unlink("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg");
					@unlink("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg");
					@unlink("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg");
					@unlink("{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg");
					@unlink("./_log/{$value[0]}.php");
					@unlink("./_log/acc_{$value[0]}.php");
					@unlink("./_res/{$value[0]}.php");
					@unlink("./_res/{$value[0]}d.php");
				}
				
				
				
				$upinfo_data = @file("./_log/upinfo.php");
				$upinfo_data = array_reverse($upinfo_data);
				$info_img = "";
				$m = 1;
				foreach ( $upinfo_data as $val ) {
					$vals = split("\t",$val);
					if ( file_exists("{$vals[2]}/{$vals[0]}s.jpg") ) { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}s.jpg\" border=0></a>{$info_tab}"; }
					else if ( file_exists("{$vals[2]}/{$vals[0]}m.jpg") ) { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}m.jpg\" border=0></a>{$info_tab}"; }
					else { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}{$add_name}.jpg\" border=0></a>{$info_tab}"; }
					
					$m++;
					if ( $m > $info_many ) { break; }
				}
				$whatsupjs = @fopen("./_log/upinfo.js", "a");
				flock($whatsupjs, LOCK_EX);
				ftruncate($whatsupjs, 0);
				fputs($whatsupjs, "document.write('{$info_img}')");
				flock($whatsupjs, LOCK_UN);
				fclose($whatsupjs);
				
				
				foreach ( $upinfo_data as $val ) {
					$vals = split("\t",$val);
					if ( file_exists("{$vals[2]}/{$vals[0]}s.jpg") ) { $md3 .= ",{$vals[2]}/{$vals[0]}s.jpg"; }
					else if ( file_exists("{$vals[2]}/{$vals[0]}m.jpg") ) { $md3 .= ",{$vals[2]}/{$vals[0]}m.jpg"; } #####
					else { $md3 .= ",{$vals[2]}/{$vals[0]}{$vals[15]}.jpg"; }
					$md1 .= ",{$vals[1]}";
					$md2 .= ",{$vals[0]}";
					$md4 .= ",{$vals[3]}";
					$md5 .= ",{$vals[4]}";
					$md6 .= ",{$vals[7]}";
					$md7 .= ",{$vals[8]}";
				}
				
				$whatsup = @fopen("./_log/upinfod.php", "a");
				flock($whatsup, LOCK_EX);
				ftruncate($whatsup, 0);
				fputs($whatsup, "mid={$md1}&imid={$md2}&img_url={$md3}&ititle={$md4}&iname={$md5}&dscr={$md6}&date={$md7}&last=ok");
				flock($whatsup, LOCK_UN);
				fclose($whatsup);
				
				
				
				
			}
			else { array_push($new_data, $values); }
		}
	
	# 保存処理
	$file = @fopen("_log/{$_REQUEST["proxy_id"]}.php", "a") or out_error("書き込みミスったくさい！");
	flock($file, LOCK_EX);
	ftruncate($file, 0);
	foreach ( $new_data as $value ) {
		fputs($file, $value);
	}
	flock($file, LOCK_UN);
	fclose($file);
	
	
	
	# ------------------------------
	$master_id = $_REQUEST["id"];
	
	$ssdata = @file("_log/{$_REQUEST["id"]}.php");
	$m = 1;
	$foot = ",";
	
	$pre_data = array();
	$add_data = array();
	
	
	if ( $ssdata ) {
	foreach ( $ssdata as $key => $vals ) {
		$value = mb_split("\t", $vals);
		
		# ソート
		if ( $confg_val[12] == "3" ) {
			array_push($pre_data, "$resmany<>$key");
		}
		else if ( $confg_val[12] == "2" ) {
			if ( $resmany > 0 ) { array_push($pre_data, "$res_value[0]<>$key"); }
			else { array_push($add_data, $val); }
		}
		else if ( $confg_val[12] == "1" ) {
			if ( !$point ) { $point[0] = "0"; }
			array_push($pre_data, "$point[0]<>$key");
		}
		else if ( $confg_val[12] == "4" ) {
			array_push($pre_data, "$value[20]<>$key");
		}
		else if ( $confg_val[12] == "6" ) {
			array_push($pre_data, "$value[0]<>$key");
		}
		else {
			array_push($pre_data, "$value[15]<>$key");
		}
	}
	
	natcasesort ($pre_data);
	if ( $confg_val[12] == "1" or $confg_val[12] == "2" or $confg_val[12] == "3" or $confg_val[12] == "5" or $confg_val[12] == "6" ) {
		$pre_data = array_reverse($pre_data, true);
	}
	
	$sort_data = array();
	foreach ( $pre_data as $val ) {
		$d_key = mb_split("<>", $val);
		array_push($sort_data, $ssdata[$d_key[1]]);
	}
	
	if ( $add_data ) { 
		foreach ( $add_data as $val ) {
			array_push($sort_data, $val);
		}
	}
	
	$ssdata = $sort_data;
	
	$imid = "";
	$dir = "";
	$title = "";
	$name = "";
	$dscr = "";
	$date = "";
	
	foreach ( $ssdata as $data_vals ) {
		if ( $m == count($ssdata) ) { $foot = ""; }
		$data_val = mb_split("\t", $data_vals);
		$u_title = mb_ereg_replace ('&', '%26', $data_val[1]);
		$u_title = mb_ereg_replace (',', '%2c', $u_title);
		$u_name = mb_ereg_replace ('&', '%26', $data_val[2]);
		$u_name = mb_ereg_replace (',', '%2c', $u_name);
		$u_dscr = mb_ereg_replace ('&', '%26', $data_val[6]);
		$u_dscr = mb_ereg_replace (',', '%2c', $u_dscr);
		$u_date = mb_ereg_replace ('&', '%26', $data_val[15]);
		$u_date = mb_ereg_replace (',', '%2c', $u_date);
		$u_fid = mb_ereg_replace ('&', '%26', $data_val[28]);
		$u_fid = mb_ereg_replace (',', '%2c', $u_fid);
		
		$u_file = $data_val[0];
		$imid .= "{$u_file}{$foot}";
		$dir  .= "{$u_file}{$u_fid}.jpg{$foot}";
		$title .= "{$u_title}{$foot}";
		$name .= "{$u_name}{$foot}";
		$dscr .= "{$u_dscr}{$foot}";
		$date .= "{$u_date}{$foot}";
		$m++;
	}
	
	if ( mb_strpos($_REQUEST["id"], "::") === FALSE ) {
		$usr_file = @fopen("./_log/{$master_id}d.php", "a") or out_error("ファイルオープンエラー");
		flock($usr_file, LOCK_EX);
		ftruncate($usr_file, 0);
		fputs($usr_file, "imid={$imid}&imgdir={$img_dir}&img_url={$dir}&ititle={$title}&iname={$name}&dscr={$dscr}&date={$date}&last=ok");
		flock($usr_file, LOCK_UN);
		fclose($usr_file);
	} }
	
	
	header("Location: ./album.php?id={$_REQUEST["id"]}&start_num={$_REQUEST["page"]}&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&ck={$_REQUEST["ck"]}&from={$_REQUEST["from"]}"); #####
	exit;
	}
	
	else { # レス記事処理
		if ( !$_REQUEST["name"] )    { out_error("名前がありませーん。");   }
		if ( !$_REQUEST["comment"] ) { out_error("コメントがなかったり。"); }
		foreach ($deny_wrds as $val) {
			if ( mb_strpos($_REQUEST["comment"], $val) !== FALSE ) { out_error("利用できない語句が含まれていました。"); }
		}
		
		foreach ( $data as $values ) {
			$value = mb_split("\t", $values);
			if ( $value[0] == $_REQUEST["date"] ) {
				$editdata = "{$value[0]}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$_REQUEST["editkey"]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment"]}\t{$_REQUEST["color"]}\t{$_SERVER["REMOTE_ADDR"]}\t\n";
				if ( !$_REQUEST["del"] ) {
					array_push ($new_data, $editdata);
				}
			}
			else { array_push ($new_data, $values); }
		}
	$file = @fopen("_res/{$_REQUEST["num"]}.php", "a") or out_error("書き込みミスったくさい！！");
	flock($file, LOCK_EX);
	ftruncate($file, 0);
	foreach ( $new_data as $value ) {
		fputs($file, $value);
	}
	flock($file, LOCK_UN);
	fclose($file);
	
	# FLASH用レスデーター修正
	$rescnt = @file("_res/{$_REQUEST["num"]}.php");
	if ( !$rescnt ) { $resmany = 0; $rescnt = array(); } else { $resmany = count($rescnt); }
	$damy_num = count($rescnt) - 1;
	$res_value = mb_split("\t", $rescnt[$damy_num]);
	if ( !$res_value[0] ) { $res_date = ""; }
	else { $res_date = date("Y/m/d G:i:s", $res_value[0]); }
	if ( $res_value[5] ) { $res_txt = "{$res_value[5]} by {$res_value[1]}"; }
	else { $res_txt = ""; }
	$res_txt = mb_ereg_replace ('&', '%26', $res_txt);
	$res_txt = mb_ereg_replace (',', '%2c', $res_txt);
	$save_data = "ires_many={$resmany}&ires_txt={$res_txt}";
	$usr_file = @fopen("./_res/{$_REQUEST["num"]}d.php", "a") ;
	flock($usr_file, LOCK_EX);
	ftruncate($usr_file, 0);
	fputs($usr_file, $save_data);
	flock($usr_file, LOCK_UN);
	fclose($usr_file);
	
	header("Location: ./album.php?id={$_REQUEST["id"]}&mode=res_form&num={$_REQUEST["num"]}&ck={$_REQUEST["ck"]}");
	exit;
	}
}


# コメントフォーム___________________________________________________
else if ( $_REQUEST["mode"] == "res_form" ) {
	chck_accs();
	if ( $confg_val[7] ) { $admin["color"] = mb_split(",", $confg_val[7]); }
	
	# クッキー取得
	$cookie_data = mb_split( "<>", $_COOKIE["coolalbum"] );
	if ( !$cookie_data[4] or mb_strpos($cookie_data[4], $confg_val[7]) !== FALSE ) { $cookie_data[4] = $admin["color"][0]; }
	
	# テンプレートファイル読み込み
	$flag = "1";
	# 同じアルバム番号のファイルが存在するならそれを使う。拡張子はhtm限定。
	if ( $_REQUEST["tmpl"] ) { $tmpl_file = $_REQUEST["tmpl"]; }
	elseif ( file_exists("_tmpl/res".$_REQUEST["id"].".htm") ) { $tmpl_file = "res".$_REQUEST["id"]; }
	else { $tmpl_file = "res"; }
	if ( mb_ereg_match("pass|PASS", $tmpl_file) or strlen($tmpl_file) > 30 or mb_ereg_match("\|", $tmpl_file) ) { out_error("誰？"); }
	$tmpl = @file("_tmpl/".$tmpl_file.".htm") or out_error("テンプレートファイルがうまく開けなかった！");
	
	foreach( $tmpl as $key => $val ) {
		if ( mb_ereg_match("(.*)<!--■■-->(.*)", $val) ) { $flag++; }
		if     ( $flag == "1" ) { $res_head .= $val; }
		elseif ( $flag == "2" ) { $res_main .= $val; }
		elseif ( $flag == "3" ) { $res_foot .= $val; }
	}
	
	# 各データー読み込み
	$data = @file("./_log/{$_REQUEST["id"]}.php");
	foreach ( $data as $value ) {
		$value = mb_split("\t", $value);
		if ( $value[0] == $_REQUEST["num"] ) { break; }
	}
	
#__ EDITER__
$befores = mb_split(",", $before_exif);
$afters  = mb_split(",", $after_exif);
foreach ( $befores as $ed_key => $ed_val ) {
	for ( $ed_i = 12; $ed_i <= 37; $ed_i++ ) {
		if ( $ed_i != 21 and $ed_i != 28 and $ed_i != 31 and $ed_i != 32 ) {
			$value[$ed_i] = mb_eregi_replace($ed_val, $afters[$ed_key], $value[$ed_i]);
		}
	}
}
	
	
	$view_addr = "{$master_url}album.php?mode=res_form&num={$_REQUEST["num"]}&ck={$ckd}&page={$_REQUEST["page"]}&dir={$imdir}&id={$_REQUEST["id"]}"; #####
	$face_addr = "{$master_url}album.php?mode=res_form&num={$value[0]}&id={$_REQUEST["id"]}"; #####
	$enface_addr = urlencode($face_addr); #####
	
	if ( $_REQUEST["ck"] ) { $return_addr = "{$master_url}album.php?id={$_REQUEST["id"]}&start_num=0"; } else { $return_addr = ""; } #####
	
	# フォーム用意
	$form = <<< EOD
<a name="form"></a>
<script language="JavaScript">
<!--
function CloseChck(){
	cc=document.input;
	if (cc.comment.value!="") {
		if ( confirm("閉じるボタンが押されましたが、文章が入力されています。本当にこのウインドウを閉じてよろしいですか？") == true )
		{ window.close(); }
	} else { window.close(); }
}

function Chck() {
	cc=document.input;
	
	if (cc.name.value=="") {
		window.alert("名前が入力されていません。");
		cc.name.focus();
		return false;
	}
	
	if (cc.comment.value=="") {
		window.alert("本文が入力されていません。");
		cc.comment.focus();
		return false;
	}
	
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = cc.editkey.value;
	var allValid = true;
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++) {
			if (ch == checkOK.charAt(j)) { break; }
			if (j == checkOK.length) { allValid = false; break; }
		}
	}
	
	if (!allValid) {
		alert("修正キーを入力する場合は 半角の英数字 を利用してください。\\n後から記事を編集・削除する際に利用します。\\n利用しない場合は空欄にしてください。");
		cc.editkey.focus();
		return false;
	}
	
	if (cc.editkey.value != "") {
		if (cc.editkey.value.length >20 || cc.editkey.value.length <4) {
			window.alert("修正キーを入力する場合は4文字以上20文字以下で入力してください。\\n後から記事を編集・削除する際に利用します。\\n利用しない場合は空欄にしてください。");
			cc.editkey.focus();
			return false;
		}
	}
}

function view_img(num,x,y) {
	var flag;
	if ( screen.availWidth  < x ) { y = y + 21; }
	else if ( screen.availHeight - 42 < y ) { x = x + 11; }
	if ( screen.availWidth  < x ) { x = screen.availWidth; flag = 1; }
	else if ( screen.availHeight < y ) { y = screen.availHeight; flag = 1; }

	if ( flag ) {
		var Win1=window.open("album.php?id={$_REQUEST["id"]}&view="+num+"&fe={$find}", "_blank", "scrollbars=1, width="+x+", height="+y+", status=0, resizable=0");
	} else {
		var Win1=window.open("album.php?id={$_REQUEST["id"]}&view="+num+"&fe={$find}", "_blank", "scrollbars=no, width="+x+", height="+y+", status=0, resizable=0");
	}
	Win1.focus();
}

//-->
</script>

<div align=center class=\"user_fontsize\"><b>{$_REQUEST["mssg"]}</b></div>
<form name="input" action="album.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" value="res_regist">
<input type="hidden" name="id" value="{$_REQUEST["id"]}">
<input type="hidden" name="num" value="{$_REQUEST["num"]}">
<input type="hidden" name="from" value="{$_REQUEST["from"]}">
<input type="hidden" name="ck" value="{$_REQUEST["ck"]}">
<table width="430" border="1" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <td align="center" class="user_fontsize" width=60>名前</td>
    <td><input name="name" type="text" size="20" value="{$cookie_data[0]}"></td>
    <td align="center" class="user_fontsize">メール</td>
    <td><input name="email" type="text" size="25" value="{$cookie_data[1]}"></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize">修正キー</td>
    <td><input name="editkey" type="password" size="10" value="{$cookie_data[2]}"></td>
    <td align="center" class="user_fontsize">URL</td>
    <td><input name="url" type="text" size="25" value="{$cookie_data[3]}"></td>
  </tr>
EOD;

	
	if ( $admin["color"][1] == "" ) { # 一色だけの場合はカラー選択非表示。
		$form .= "<input type=hidden name=\"color\" value=\"{$admin["color"][0]}\">";
	} else {
		$form .= "<tr><td align=\"center\" class=\"user_fontsize\">色</td><td colspan=\"3\">";
		foreach ( $admin["color"] as $key => $val ) {
			if ( $cookie_data[4] == $val ) {
				$form .= "<input name=\"color\" type=\"radio\" value=\"$val\" checked><font size=2 color=\"$val\">■</font>\n";
			} else if ( $val ) {
				$form .= "<input name=\"color\" type=\"radio\" value=\"$val\"><font size=2 color=\"$val\">■</font>\n";
			}
		}
	$form .= "</td></tr>";
	}
$form .= "<tr align=\"center\">\n<td colspan=\"4\"><textarea name=\"comment\" cols=\"50\" rows=\"5\"></textarea></td>\n</tr>";
$form .= "</table>\n<div align=center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"    投稿    \" onClick='return Chck()'>&nbsp;&nbsp;&nbsp;&nbsp;<input type=button value='閉じる' onClick='return CloseChck()'></div></form>";
	
	if ( file_exists("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg") ) { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg"; }
	else { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg"; }
	$img = "album.php?view={$value[0]}";
	$thum_size = (INT) ( @filesize($thum_img) / 1000 );
	$img_size  = (INT) ( @filesize("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg") / 1000 );
	
	$date = date("Y/m/d G:i:s", $value[0]);

	if ( $srt_switch ) { $confg_val[2] = $sorted_dir["{$value[0]}"]; }
	
	if ( !$value[2] ) { $value[2] = "誰か"; }
	if ( !$value[7] ) { $value[7] = $def_color; }
	else if ( $value[7] == "#FFFFFF" or $value[7] == "#ffffff" ) { $value[7] = "#666666"; }
	if ( !$value[3] ) { $res_head = mb_ereg_replace("(.*)?■email■(.*)?\n", "", $res_head, "s"); }
	if ( !$value[5] ) { $res_head = mb_ereg_replace("(.*)?■url■(.*)?\n", "", $res_head, "s"); }
	if ( $title_model == 1 and !$value[1] and $value[12] ) { $value[1] = $value[12]; }
	else if ( $title_model == 2 and !$value[1] and $value[2] ) { $value[1] = $value[2]; }
	else if ( !$value[1] ) { $value[1] = "無題"; }
	
	if ( $value[12] ) { $model = mb_ereg_replace("  ", "", $value[12]); }
	if ( $value[15] ) { $dam = mb_split(" ", $value[15]); $picdate=$dam[0]; }
	if ( $value[17] ) { $dam = mb_ereg_replace(" ", "", $value[17]); $dam = mb_split("\(", $dam); $ev = rtrim($dam[0]); }
	if ( $value[18] ) { $dam = mb_ereg_replace(" ", "", $value[18]); $dam = mb_split("s", $dam); $ftime = rtrim($dam[0]); }
	if ( $value[29] ) { $dam = mb_ereg_replace(" ", "", $value[29]); $dam = mb_split("\(", $dam); $flength = rtrim($dam[0]); }
	$dammy = mb_split("\(", $value[18]);
	if ( $dammy[2] ) { $value[18] = $dammy[0] . "(" . $dammy[2]; }
	$point = @file("./_log/{$value[0]}.php");
	$rescnts = @file("./_res/{$value[0]}.php");
	if ( !$rescnts ) { $rescnt = 0; } else { $rescnt = count($rescnts); }
	
	if ( time() - $value[0] < $new_date * 60*60 ) {
		$res_head = mb_ereg_replace("■new■", $new_iconB, $res_head);
	} else {
		$res_head = mb_ereg_replace("■new■", "", $res_head);
	}
	if ( $value[29] and $value[29] != "\n" ) { $value[29] .= "㎜"; }
	$imglink = "<a href=\"JavaScript:onClick=view_img({$value[0]}, {$value[10]}, {$value[11]})\" title=\"画像を拡大表示\">";
	
	$adl = "&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}"; #####
	
	$res_head = mb_ereg_replace("■fontsize■", $fontsize, $res_head);
	$res_head = mb_ereg_replace("■page■",     $_REQUEST["page"], $res_head);
	$res_head = mb_ereg_replace("■form■",     $form, $res_head);
	$res_head = mb_ereg_replace("■addr■",  $view_addr,  $res_head); #####
	$res_head = mb_ereg_replace("■faddr■",  $face_addr,  $res_head); #####
	$res_head = mb_ereg_replace("■enfaddr■",  $enface_addr,  $res_head); #####
	if ( $return_addr ) { $res_head = mb_ereg_replace("■album_addr■", $return_addr, $res_head); } #####
	else { $res_head = mb_ereg_replace("[^\n]*?■album_addr■(.*?)\n", "", $res_head); } #####
	$res_head = mb_ereg_replace("■sort■",      $srt_title, $res_head);
	$res_head = mb_ereg_replace("■sortlink■",  $_REQUEST["srt"], $res_head);
	$res_head = mb_ereg_replace("■id■",        $_REQUEST["id"], $res_head);
	$res_head = mb_ereg_replace("■namelink■",  "album.php?id=name::" . urlencode($value[2]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■catlink■",   "album.php?id=cat::" . urlencode($value[20]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■point■",     $point[0],  $res_head);
	$res_head = mb_ereg_replace("■rescnt■",    $rescnt,    $res_head);
	$res_head = mb_ereg_replace("■imglink■",   $imglink,   $res_head);
	$res_head = mb_ereg_replace("■thum_size■", $thum_size, $res_head);
	$res_head = mb_ereg_replace("■img_size■",  $img_size,  $res_head);
	$res_head = mb_ereg_replace("■thumurl■",   $thum_img,  $res_head);
	$res_head = mb_ereg_replace("■imgurl■",    $img,       $res_head);
	$res_head = mb_ereg_replace("■date■",      $date,      $res_head);
	$res_head = mb_ereg_replace("■thum_i■", "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg",  $res_head);
	
	$res_head = mb_ereg_replace("■title■",    $value[1],  $res_head);
	$res_head = mb_ereg_replace("■name■",     $value[2],  $res_head);
	$res_head = mb_ereg_replace("■email■",    $value[3],  $res_head);
	$res_head = mb_ereg_replace("■url■",      $value[5],  $res_head);
	$res_head = mb_ereg_replace("■comment■",  $value[6],  $res_head);
	$res_head = mb_ereg_replace("■color■",    $value[7],  $res_head);
	$res_head = mb_ereg_replace("■width■",    $value[8],  $res_head);
	$res_head = mb_ereg_replace("■height■",   $value[9],  $res_head);
	$res_head = mb_ereg_replace("■s_width■",  $value[10], $res_head);
	$res_head = mb_ereg_replace("■s_height■", $value[11], $res_head);
	$res_head = mb_ereg_replace("■model■",    $value[12], $res_head);
	$res_head = mb_ereg_replace("■iso■",      $value[13], $res_head);
	$res_head = mb_ereg_replace("■fnumber■",  $value[14], $res_head);
	$res_head = mb_ereg_replace("■picdate■",  $value[15], $res_head);
	$res_head = mb_ereg_replace("■ftype■",    $value[16], $res_head);
	$res_head = mb_ereg_replace("■bright■",   $value[17], $res_head);
	$res_head = mb_ereg_replace("■ftime■",    $value[18], $res_head);
	$res_head = mb_ereg_replace("■white■",    $value[19], $res_head);
	$res_head = mb_ereg_replace("■cat■",      $value[20], $res_head);
	$res_head = mb_ereg_replace("■add1■",     $value[22], $res_head);
	$res_head = mb_ereg_replace("■add2■",     $value[23], $res_head);
	$res_head = mb_ereg_replace("■add3■",     $value[24], $res_head);
	$res_head = mb_ereg_replace("■add4■",     $value[25], $res_head);
	$res_head = mb_ereg_replace("■add5■",     $value[26], $res_head);
	$res_head = mb_ereg_replace("■add6■",     $value[27], $res_head);
	$res_head = mb_ereg_replace("■flength■",  $value[29], $res_head);
	$res_head = mb_ereg_replace("■lense■",    $value[30], $res_head);
	
	$res_head = mb_ereg_replace("■maker■",    $value[33], $res_head);
	$res_head = mb_ereg_replace("■flash■",    $value[34], $res_head);
	$res_head = mb_ereg_replace("■etype■",    $value[35], $res_head);
	$res_head = mb_ereg_replace("■sharpnessnse■",    $value[36], $res_head);
	$res_head = mb_ereg_replace("■jpegq■",    $value[37], $res_head);
	
	$res_head = mb_ereg_replace("■datelink■",   "album.php?id=15::" . $picdate . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■modellink■",   "album.php?id=12::" . $value[12] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■isolink■",     "album.php?id=13::" . $value[13] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■fnumberlink■", "album.php?id=14::" . $value[14] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■ftypelink■",   "album.php?id=16::" . $value[16] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■brightlink■",  "album.php?id=17::" . $ev . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■ftimelink■",   "album.php?id=18::" . $ftime . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■whitelink■",   "album.php?id=19::" . $value[19] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add1link■",    "album.php?id=22::" . $value[22] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add2link■",    "album.php?id=23::" . $value[23] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add3link■",    "album.php?id=24::" . $value[24] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add4link■",    "album.php?id=25::" . $value[25] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add5link■",    "album.php?id=26::" . $value[26] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■add6link■",    "album.php?id=27::" . $value[27] . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■flengthlink■", "album.php?id=29::" . $flength . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■lenselink■",   "album.php?id=30::" . $value[30] . "{$adl}", $res_head);
	
	
	$res_head = mb_ereg_replace("■makerlink■",   "album.php?id=33::" . urlencode($value[33]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■flashlink■",   "album.php?id=34::" . urlencode($value[34]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■etypelink■",   "album.php?id=35::" . urlencode($value[35]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■sharpnessnselink■",   "album.php?id=36::" . urlencode($value[36]) . "{$adl}", $res_head);
	$res_head = mb_ereg_replace("■jpegqlink■",   "album.php?id=37::" . urlencode($value[37]) . "{$adl}", $res_head);
	
	
	print $res_head;
	
	$res_data = @file("./_res/{$value[0]}.php");
	if ( !$res_data ) { $res_data = array(); }
	foreach ( $res_data as $res_val ) {
		$res_body  = $res_main;
		$res_value = mb_split("\t", $res_val);
		
		# メール
		if ( !$res_value[2] ) {
			$res_body = mb_ereg_replace("(.*)?■email■(.*)?\n", "", $res_body, s);
		}
		if ( !$res_value[4] ) {
			$res_body = mb_ereg_replace("(.*)?■url■(.*)?\n", "", $res_body, s);
		}
		$edit = "album.php?mode=edit&id={$_REQUEST[id]}&num={$value[0]}&date={$res_value[0]}&type=res&tmpl={$_REQUEST["tmpl"]}&ck={$_REQUEST["ck"]}&from={$_REQUEST["from"]}"; #####
		$date = date("Y/m/d G:i:s", $res_value[0]);
		if ( !$res_value[6] or $res_value[6] == "\n" ) { $res_value[6] = $def_color; }
		if ( $res_value[6] == "#FFFFFF" or $res_value[6] == "#ffffff" ) { $res_value[6] = "#666666"; }
		$res_body = mb_ereg_replace("■addr■",  $view_addr,  $res_body); #####
		$res_body = mb_ereg_replace("■faddr■",  $face_addr,  $res_body); #####
		$res_body = mb_ereg_replace("■enfaddr■",  $enface_addr,  $res_body); #####
		if ( $return_addr ) { $res_body = mb_ereg_replace("■album_addr■", $return_addr, $res_body); } #####
		else { $res_body = mb_ereg_replace("[^\n]*?■album_addr■(.*?)\n", "", $res_body); } #####
		$res_body = mb_ereg_replace("■edit■",    $edit,         $res_body);
		$res_body = mb_ereg_replace("■date■",    $date,         $res_body);
		$res_body = mb_ereg_replace("■name■",    $res_value[1], $res_body);
		$res_body = mb_ereg_replace("■email■",   $res_value[2], $res_body);
		$res_body = mb_ereg_replace("■url■",     $res_value[4], $res_body);
		$res_body = mb_ereg_replace("■comment■", $res_value[5], $res_body);
		$res_body = mb_ereg_replace("■color■",   $res_value[6], $res_body);
		print "$res_body";
	}
$res_foot = mb_ereg_replace("■addr■", $view_addr, $res_foot); #####
$res_foot = mb_ereg_replace("■faddr■",  $face_addr,  $res_foot); #####
$res_foot = mb_ereg_replace("■enfaddr■",  $enface_addr,  $res_foot); #####
if ( $return_addr ) { $res_foot = mb_ereg_replace("■album_addr■", $return_addr, $res_foot); } #####
else { $res_foot = mb_ereg_replace("[^\n]*?■album_addr■(.*?)\n", "", $res_foot); } #####

 #####
$res_foot = mb_ereg_replace("■form■", $form, $res_foot);
print "$res_foot";
exit;
}


else if ( $_REQUEST["mode"] == "res_regist" ) {
	
	chck_accs();
	
	if ( !$_REQUEST["name"] )    { out_error("名前がありませーん。"); }
	if ( !$_REQUEST["comment"] ) { out_error("コメントがなかったり。"); }
	if ( $sec_vals[5] and !mb_ereg('[ぁ-ん]', $_REQUEST["comment"]) ) { out_error("ニホンゴスコシ？"); }
	foreach ($deny_wrds as $val) {
		if ( mb_strpos($_REQUEST["comment"], $val) !== FALSE ) { out_error("利用できない語句が含まれていました。"); }
	}
	
	if ( $confg_val[18] ) { $max_width   = $confg_val[18]; }
	if ( $confg_val[19] ) { $max_height  = $confg_val[19]; }
	if ( $confg_val[20] ) { $view_width  = $confg_val[20]; }
	if ( $confg_val[21] ) { $view_height = $confg_val[21]; }
	if ( $confg_val[23] and $confg_val[23] != "\n" ) { $i_width  = $confg_val[23]; }
	if ( $confg_val[24] and $confg_val[24] != "\n" ) { $i_height = $confg_val[24]; }

	
	$res_data = @file("./_res/{$_REQUEST["num"]}.php");
	if ( !$res_data ) { $resmany = 0; } else { $resmany = count($res_data); }
	if ( $res_data ) {
		$c_num = count($res_data) - 1;
		$chck = mb_split("\t", $res_data[$c_num]);
		if ( $_REQUEST["comment"] == $chck[5] ) { out_error("ちゃんと書き込まれてるヨ＝。"); }
	}
	
	$cookie_data = "{$_REQUEST["name"]}<>{$_REQUEST["email"]}<>{$_REQUEST["editkey"]}<>{$_REQUEST["url"]}<>{$_REQUEST["color"]}<>";
	setcookie("coolalbum", $cookie_data, time() + 30*24*60*60);
	
	$time = time();
	$save_data = "{$time}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$_REQUEST["editkey"]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment"]}\t{$_REQUEST["color"]}\t{$_SERVER["REMOTE_ADDR"]}\t\n";
	$data = @fopen("_res/{$_REQUEST["num"]}.php", "a") or out_error("書き込みミスったくさい！！");
	flock($data, LOCK_EX);
	fputs($data, $save_data);
	flock($data, LOCK_UN);
	fclose($data);
	
	$resmany ++;
	$res_txt = "{$_REQUEST["comment"]} by {$_REQUEST["name"]}";
	$res_txt = mb_ereg_replace ('&', '%26', $res_txt);
	$res_txt = mb_ereg_replace (',', '%2c', $res_txt);
	$save_data = "ires_many={$resmany}&ires_txt={$res_txt}";
	$usr_file = @fopen("./_res/{$_REQUEST["num"]}d.php", "a") or out_error("ファイルオープンエラー");
	flock($usr_file, LOCK_EX);
	ftruncate($usr_file, 0);
	fputs($usr_file, $save_data);
	flock($usr_file, LOCK_UN);
	fclose($usr_file);
	
	
	# 各データー読み込み
	$data = @file("./_log/{$_REQUEST["id"]}.php");
	foreach ( $data as $value ) {
		$value = mb_split("\t", $value);
		if ( $value[0] == $_REQUEST["num"] ) { break; }
	}
	
	if ( $_REQUEST["name"] != $value[2] ) {
		if ( mb_strpos($value[3], "docomo.ne.jp") !== FALSE or mb_strpos($value[3], "vodafone.ne.jp") !== FALSE or mb_strpos($value[3], "ezweb.ne.jp") !== FALSE ) {
			$mail_body = "AlbumFactoryのあなたの写真にコメントが付きました。\n{$master_url}i.php?id={$_REQUEST["id"]}&mode=view_res&num={$_REQUEST["num"]}&ck=26\nご確認下さい。\n\n* このメールは自動送信メールです。\nこのメールにご返信いただいても\nお答えできませんのでご注意下さい。\n";
		} else {
			$mail_body = "AlbumFactoryのあなたの写真にコメントが付きました。\n{$master_url}album.php?id={$_REQUEST["id"]}&mode=res_form&num={$_REQUEST["num"]}&ck=37\nご確認下さい。\n\n* このメールは自動送信メールです。\nこのメールにご返信いただいても\nお答えできませんのでご注意下さい。\n";
		}
		
		$mail_add = "From: {$master_mail}\nBcc: {$master_mail}";
		mb_send_mail($value[3], "AlbumFactoryコメント通知", $mail_body, $mail_add);
	} else {
		$mail_body = "AlbumFactoryにコメントが付きました。\n{$master_url}album.php?id={$_REQUEST["id"]}&mode=res_form&num={$_REQUEST["num"]}&ck=37\nご確認下さい。\n\n* このメールは自動送信メールです。\nこのメールにご返信いただいても\nお答えできませんのでご注意下さい。\n";
		$mail_add = "From: {$master_mail}\n";
		mb_send_mail($master_mail, "AlbumFactoryコメント通知", $mail_body, $mail_add);
	}
	
	if ( $_REQUEST["flash"] ) { print "&state=fin"; exit; }
	else {
	header("Location: ./album.php?num={$_REQUEST["num"]}&mode=res_form&page={$_REQUEST["page"]}&ck={$_REQUEST["ck"]}&id={$_REQUEST["id"]}#form"); }
}


if ( $_REQUEST["mode"] == "input" ) {
	chck_accs();
	if ( mb_strpos($_REQUEST["id"], "::") !== FALSE ) { #####
		if ( $_REQUEST["from"] !== "" ) { $_REQUEST["id"] = $_REQUEST["from"]; } else {
			out_error("絞り込み表示時には新規投稿はできません。<br>一度「アルバム一覧」をクリックし、<br>投稿したいアルバムを選択してください。");
		}
	}
	
	
	# クッキー取得
	$cookie_data = mb_split( "<>", $_COOKIE["coolalbum"] );
	if ( !$cookie_data[4] ) { $cookie_data[4] = $color[0]; }
		if ( $_REQUEST["mode"] == 5 ) { # 再入力の場合
		$cookie_data[0] = $_REQUEST["name"];
		$cookie_data[1] = $_REQUEST["email"];
		$cookie_data[2] = $_REQUEST["editkey"];
		$cookie_data[3] = $_REQUEST["url"];
		$cookie_data[4] = $_REQUEST["color"];
	}
	
	out_head();
	# フォーム表示 #####
	print <<< EOD

<form name="input" action="album.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" value="regist">
<input type="hidden" name="id" value="{$_REQUEST["id"]}">
<input type="hidden" name="view_line" value="{$view_line}">
<input type="hidden" name="from" value="{$_REQUEST["from"]}">
<input type="hidden" name="ck" value="{$_REQUEST["ck"]}">
<br><p align=center class="user_fontsize"><b>+ 新規投稿 +</b><br><font size=2>* 新規の画像投稿は許可されたメンバーのみが行えます。</font><br><font color="#FF0000"><b>{$_REQUEST["mssg"]}</b></font></p>
<table width="470" border="1" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <td align="center" class="user_fontsize" width=130>名前/<br>撮影者</td>
    <td><input name="name" type="text" size="20" value="{$cookie_data[0]}"></td>
    <td align="center" class="user_fontsize" width=130>メール</td>
    <td><input name="email" type="text" size="25" value="{$cookie_data[1]}"></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize" width=130>修正キー</td>
    <td><input name="editkey" type="password" size="10" value="{$cookie_data[2]}"></td>
    <td align="center" class="user_fontsize" width=130>URL</td>
    <td><input name="url" type="text" size="25" value="{$cookie_data[3]}"></td>
  </tr>
  <tr><td colspan=4><font size=2>&nbsp;タイトルとコメントは省略可能です。沢山の画像を投稿する場合は、先に画像だけ投稿し、コメント等はあとから編集すると楽です。なお、タイトルを省略すると投稿者の名前やカメラのモデル名などがタイトル欄に表示されます（設定により異なります）。</font></td></tr>
EOD;
	
	for ( $i = 0; $i < $max_form; $i++ ) {
		
		# 戻り値がある場合はクッキーより優先させる
		if ( $_REQUEST["color_$i"] ) { $cookie_data[4] = $_REQUEST["color_$i"]; }
		$flag_degree["0"] = NULL; $flag_degree["90"] = NULL; $flag_degree["180"] = NULL; $flag_degree["270"] = NULL;
		if ( $_REQUEST["degree_$i"] ) { chck_num($_REQUEST["degree_$i"]); $n = $_REQUEST["degree_$i"]; $flag_degree["$n"] = " checked"; } else { $flag_degree["0"] = " checked"; }
		
		if ( $max_form > 1 ) {
			$m = $i + 1;
			print "</table>";
			if ( $i > 0 ) { print "<div align=center><input type=\"submit\" value=\"    投稿    \"></div><br><div align=center class=\"user_fontsize\"><b>$mssg</b></div><br>"; }
			print "<table width=\"470\" border=\"1\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\"><tr><td colspan=4 bgcolor=#000000><p align=center><font color=#FFFFFF class=\"user_fontsize\">$m 枚目の画像</font></p></td></tr>";
		}
		print <<< EOD
  <tr>
    <td align="center" class="user_fontsize" width=60>画像</td>
    <td colspan="3"><input name="file[]" type="file" size="20" value={$_REQUEST["$file[$i]"]}></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize" width=60>カテゴリ</td><td colspan="3">
      <select name="cat_$i">
EOD;
		if ( $confg_val[8] ) { $cat = mb_split(",", $confg_val[8]); }
		foreach ( $cat as $val ) {
			print "<option value=\"$val\">$val</option>\n";
		}
		print "</select></td></tr>";
		
		print <<< EOD
  <tr>
    <td align="center" class="user_fontsize" width=60>画像回転</td>
    <td colspan="3" class="user_fontsize">
     <input name="degree_$i" type="radio" value="0"{$flag_degree["0"]}>なし
&nbsp;<input name="degree_$i" type="radio" value="270"{$flag_degree["270"]}><img src="img/90.gif" width="65" height="27" align="absmiddle">
&nbsp;<input name="degree_$i" type="radio" value="90"{$flag_degree["90"]}><img src="img/270.gif" width="65" height="27" align="absmiddle">
&nbsp;<input name="degree_$i" type="radio" value="180"{$flag_degree["180"]}><img src="img/180.gif" width="70" height="20" align="absmiddle">
    </td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize">タイトル</td>
    <td colspan="3"><input name="title_$i" type="text" size="40" value="{$_REQUEST["title_$i"]}"></td>
  </tr>
  <tr align="center">
    <td colspan="4"><textarea name="comment_$i" cols="50" rows="5">{$_REQUEST["comment_$i"]}</textarea></td>
  </tr>
EOD;
		
		# 色選択表示
		if ( $confg_val[7] ) { $admin["color"] = mb_split(",", $confg_val[7]); }
		if ( $admin["color"][1] == "" ) { # 一色だけの場合はカラー選択非表示。
			print "<input type=hidden name=\"color_$i\" value=\"{$admin["color"][0]}\">";
		} else {
			print "<tr><td align=\"center\" class=\"user_fontsize\">色</td><td colspan=\"3\">";
			foreach ( $admin["color"] as $key => $val ) {
				if ( $cookie_data[4] == $val ) {
					print "<input name=\"color_$i\" type=\"radio\" value=\"$val\" checked><font size=2 color=\"$val\">■</font>\n";
				} else if ( $val ) {
					print "<input name=\"color_$i\" type=\"radio\" value=\"$val\"><font size=2 color=\"$val\">■</font>\n";
				}
			}
			print "</td></tr>";
		}
		print "</td></tr>";
	}
	print "</table>\n<div align=center><input type=\"submit\" value=\"    投稿    \"></div><br><div align=center class=\"user_fontsize\"><b>$mssg</b></div></form><BR><hr>";
	out_footer();
	exit;
}


else if ( $_REQUEST["mode"] == "regist" ) {
	chck_accs();
	if ( $_REQUEST["name"] ) {
	$usr_data = @file("./_log/user.php");
	foreach ( $usr_data as $vals ) {
		$val = mb_split("\t", $vals);
		if ( trim($val[0]) == $_REQUEST["name"] ) { break; }
		if ( @mb_convert_encoding($val[0], "UTF-8", "auto") == @mb_convert_encoding($_REQUEST["name"], "UTF-8", "auto") ) { break; }
	} }
	
	if ( $confg_val[18] ) { $max_width   = $confg_val[18]; }
	if ( $confg_val[19] ) { $max_height  = $confg_val[19]; }
	if ( $confg_val[20] ) { $view_width  = $confg_val[20]; }
	if ( $confg_val[21] ) { $view_height = $confg_val[21]; }
	if ( $confg_val[23] and $confg_val[23] != "\n" ) { $i_width  = $confg_val[23]; }
	if ( $confg_val[24] and $confg_val[24] != "\n" ) { $i_height = $confg_val[24]; }
	
	
	if ( !$_REQUEST["editkey"] ) { out_error("修正キーが見えません。"); }
	if ( $_REQUEST["editkey"] != $val[1] and $_REQUEST["editkey"] != $password) { out_error("修正キーが違います。"); }
	

	
	$cookie_data = "{$_REQUEST["name"]}<>{$_REQUEST["email"]}<>{$_REQUEST["editkey"]}<>{$_REQUEST["url"]}<>{$_REQUEST["color_0"]}<>";
	setcookie("coolalbum", $cookie_data, time() + 30*24*60*60);
	
	$data = "";
	
	for ( $i = $max_form; $i >= 0; $i-- ) {
		
		if ( $_FILES["file"]["tmp_name"][$i] ) {
			
			if ( !is_uploaded_file($_FILES["file"]["tmp_name"][$i]) ) { out_error("ファイル見えないんだけど？"); }
			
			$er = new phpExifReader($_FILES["file"]["tmp_name"][$i]);
			$er->Debugging = 1;
			$Exif = $er->getImageInfo();
			
			
#			foreach ( $Exif as $key => $val ) { print "$key - $val <BR>"; } exit;
			
			## 追加Exif
			$maker = $Exif["make"];    # メーカー
			$flash = $Exif["flashUsed"];    # フラッシュの利用
			$sharpness = $Exif["sharpness"];    # シャープネス設定
			$etype = $Exif["exposureMode"]; # 露光モード
			$jpegq = $Exif["jpegQuality"]; # Jpeg画質
			
			$model   = $Exif["model"];    # 機種
			$iso     = $Exif["isoEquiv"]; # ISO
			$fnumber = $Exif["fnumber"];  # 絞り
			$picdate = $Exif["dateTimeDigitized"]; # 撮影日時
			if ( !$Exif["dateTimeDigitized"] ) { $picdate = $Exif["DateTime"]; }
			$ftype   = $Exif["exposure"]; # 撮影モード
			$bright  = $Exif["exposureBias"]; # 露出補正
			$ftime   = $Exif["exposureTime"]; # シャッター速度
			$white   = $Exif["whiteBalance"]; # ホワイトバランス
			$sokko   = $Exif["meteringMode"]; # 測光方式
			$scene   = $Exif["screenCaptureType"]; # 撮影モード
			$flength = $Exif["focalLength"];  # 焦点距離
			if ( $Exif["flength35mm"] ) { $flength = $Exif["flength35mm"] . "(35mm換算)"; }
			
			# if ( $ftime ) { $dam = mb_split("s", $ftime); $ftime = rtrim($dam[0]) . "s"; }
			# if ( $bright ) { $dam = mb_split(" ", $bright); $bright = $dam[0]; }
			
			
			$tmp_filename = time();
			$img_file = $_FILES["file"]["tmp_name"][$i];
			list($width, $height, $type) = getimagesize($img_file);
			
			if ( $_REQUEST["degree_$i"] ) {
				     if ( $type == 2 ) { $img_f = imagecreatefromjpeg($img_file); }
				else if ( $type == 3 ) { $img_f = imagecreatefrompng ($img_file); }
				else if ( $type == 1 ) { $img_f = imagecreatefromgif ($img_file); }
				
				$img_f = ImageRotate($img_f, $_REQUEST["degree_$i"], 0);
				imagejpeg($img_f, "{$img_dir}/$tmp_filename.jpg", 100);
				chmod("{$img_dir}/$tmp_filename.jpg", 0644);
				$img_file = "{$img_dir}/$tmp_filename.jpg";
				imagedestroy($img_f);
			}
			
			list($width, $height, $type) = getimagesize($img_file);
			
			
			
			# サムネイル画像
			
			$flag_resize = 0;
			if ( $width > $view_width or $height > $view_height ) {
				$flag_resize = 1;
				$rate_width  = $view_width  / $width;
				$rate_height = $view_height / $height;
				if ( $rate_width < $rate_height ) { $rate = $rate_width; }
				else { $rate = $rate_height; }
				$new_width  = (int) ( $width  * $rate );
				$new_height = (int) ( $height * $rate );
			}
			else { $new_width = $width; $new_height = $height; }
			
			if ( $flag_resize ) {
			    if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
				else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
				else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
				
				$new_img = imagecreatetruecolor($new_width, $new_height);
				imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
				imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}s.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}s.jpg", 0644);
				imagedestroy($new_img);
			} else {
				# copy($img_file, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}s.jpg");
				# chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}s.jpg", 0644);
			}
			
			@imagedestroy($dst); @imagedestroy($src);
			
			
			
			# ケータイ用サムネイル画像
			
			$src = imagecreatefromjpeg($img_file) or out_error("Jpgファイルの生成に失敗。 $img_file");
			$dst = imagecreatetruecolor(30, 30);
			
			if ( $width > 150 and $height > 150 ) {
				$width1  = (int) ( $width / 2.5 );
				$height1 = (int) ( $height / 2.5 );
				
						if ( $width1 < $height1 ) { $cw = $height1; }
						else { $cw = $width1; }
				
						if ( $width > $height ) {
							$r_w = rand(-$width / 15, $width / 15);
							$r_h = rand(-$height / 20, $height / 20);
						} else {
							$r_w = rand(-$width / 20, $width / 20);
							$r_h = rand(-$height / 15, $height / 15);
						}
				
						imagecopyresampled ($dst, $src, 0, 0, ( $width - ((7/10)*$width)) + $r_w, ( $height - ((7/10)*$height)) + $r_h, 30, 30, $cw, $cw) or out_error("画像ファイルの縮小処理に失敗。");
				#	@imagefilter($dst, IMG_FILTER_CONTRAST, -20);
				#	@imagefilter($dst, IMG_FILTER_BRIGHTNESS, 10);
				imagejpeg ($dst, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg", 0644);
			}
			else if ( $width > 30 or $height > 30 ) {
				 
				if ( $width > $height ) { $s_w = ( $width - $height ) / 2; $s_h = 0; $width = $height; }
				else { $s_h = ( $height - $width ) / 2; $s_w = 0; $height = $width; }
				
				imagecopyresampled ($dst, $src, 0, 0, $s_w, $s_h, 30, 30, $width , $height) or out_error("画像ファイルの縮小処理に失敗。");
				#	@imagefilter($dst, IMG_FILTER_CONTRAST, -20);
				#	@imagefilter($dst, IMG_FILTER_BRIGHTNESS, 10);
				imagejpeg ($dst, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg", 0644);
			} else {
				copy($img_file, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg");
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}i.jpg", 0644);
			}
			@imagedestroy($dst); @imagedestroy($src);
			
			
			# ケータイ用表示画像
			$flag_resize = 0;
			if ( $width > $i_width or $height > $i_height ) {
				$flag_resize = 1;
				$rate_width  = $i_width  / $width;
				$rate_height = $i_height / $height;
				if ( $rate_width < $rate_height ) { $rate = $rate_width; }
				else { $rate = $rate_height; }
				$n_width  = (int) ( $width  * $rate );
				$n_height = (int) ( $height * $rate );
			}
			else { $n_width = $width; $n_height = $height; }
			
			if ( $flag_resize ) {
			    if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
				else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
				else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
				
				$new_img = imagecreatetruecolor($n_width, $n_height);
				imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
				imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}m.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}m.jpg", 0644);
				imagedestroy($new_img);
			} else {
				# copy($img_file, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}m.jpg");
				# chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}m.jpg", 0644);
			}
			
			
			# 表示用画像
			
			$flag_resize = 0;
			$add_name = make_name(6);
			if ( $width > $max_width or $height > $max_height or $type == 3 or $type == 1 ) {
				$flag_resize = 1;
				$rate_width  = $max_width  / $width;
				$rate_height = $max_height / $height;
				if ( $rate_width < $rate_height ) { $rate = $rate_width; }
				else { $rate = $rate_height; }
				$new_width  = (int) ( $width  * $rate );
				$new_height = (int) ( $height * $rate );
				
				if ( $type == 2 ) { $img_src = imagecreatefromjpeg("$img_file"); }
				else if ( $type == 3 ) { $img_src = imagecreatefrompng("$img_file");  }
				else if ( $type == 1 ) { $img_src = imagecreatefromgif("$img_file");  }
				
				$new_img = imagecreatetruecolor($new_width, $new_height);
				
				if ( $flag_resize ) {
					imagecopyresampled($new_img, $img_src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
				}
				else { imagecopy($new_img, $img_src, 0, 0, 0, 0, $width, $height); }
				
				imagejpeg($new_img, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}{$add_name}.jpg", 90);
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}{$add_name}.jpg", 0644);
				imagedestroy($new_img);
				$or_width = $new_width; $or_height = $new_height;
			}
			else { 
				move_uploaded_file($img_file, "{$img_dir}/{$confg_val[2]}/{$tmp_filename}{$add_name}.jpg");
				chmod("{$img_dir}/{$confg_val[2]}/{$tmp_filename}{$add_name}.jpg", 0644);
				$or_width = $width; $or_height = $height;
			}
			
			
			if ( !$confg_val[9] and !$confg_val[10] ) { #_____________________________
			
			$old_data = @file("./_log/upinfo.php");
			$whatsup = @fopen("./_log/upinfo.php", "a");
			if ( !$old_data ) { $old_data = array(); }
			flock($whatsup, LOCK_EX);
			if ( count($old_data) > 50 ) {
				array_splice($old_data, 0, 20);
				ftruncate($whatsup, 0);
				foreach ( $old_data as $val ) {
					fputs($whatsup, $val);
				}
			}
			fputs($whatsup, "{$tmp_filename}\t{$_REQUEST["id"]}\t{$img_dir}/{$confg_val[2]}\t{$_REQUEST["title_$i"]}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment_$i"]}\t{$picdate}\t{$_REQUEST["color_$i"]}\t{$new_width}\t{$new_height}\t{$or_width}\t{$or_height}\t{$_REQUEST["cat_$i"]}\t{$add_name}\t\n");
			flock($whatsup, LOCK_UN);
			fclose($whatsup);
			
			
			$upinfo_data = @file("./_log/upinfo.php");
			$upinfo_data = array_reverse($upinfo_data);
			$info_img = "";
			$m = 1;
			foreach ( $upinfo_data as $val ) {
				$vals = split("\t",$val);
				if ( file_exists("{$vals[2]}/{$vals[0]}s.jpg") ) { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}s.jpg\" border=0></a>{$info_tab}"; }
				else if ( file_exists("{$vals[2]}/{$vals[0]}m.jpg") ) { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}m.jpg\" border=0></a>{$info_tab}"; }
				else { $info_img .= "<a href=\"album.php?_v={$vals[0]}&id={$vals[1]}&mode=res_form\"><img src=\"{$master_url}{$vals[2]}/{$vals[0]}{$add_name}.jpg\" border=0></a>{$info_tab}"; }
				
				$m++;
				if ( $m > $info_many ) { break; }
			}
			$whatsupjs = @fopen("./_log/upinfo.js", "a");
			flock($whatsupjs, LOCK_EX);
			ftruncate($whatsupjs, 0);
			fputs($whatsupjs, "document.write('{$info_img}')");
			flock($whatsupjs, LOCK_UN);
			fclose($whatsupjs);
			
			
			foreach ( $upinfo_data as $val ) {
				$vals = split("\t",$val);
				if ( file_exists("{$vals[2]}/{$vals[0]}s.jpg") ) { $md3 .= ",{$vals[2]}/{$vals[0]}s.jpg"; }
				else if ( file_exists("{$vals[2]}/{$vals[0]}m.jpg") ) { $md3 .= ",{$vals[2]}/{$vals[0]}m.jpg"; } #####
				else { $md3 .= ",{$vals[2]}/{$vals[0]}{$vals[15]}.jpg"; }
				$md1 .= ",{$vals[1]}";
				$md2 .= ",{$vals[0]}";
				$md4 .= ",{$vals[3]}";
				$md5 .= ",{$vals[4]}";
				$md6 .= ",{$vals[7]}";
				$md7 .= ",{$vals[8]}";
			}
			
			$whatsup = @fopen("./_log/upinfod.php", "a");
			flock($whatsup, LOCK_EX);
			ftruncate($whatsup, 0);
			fputs($whatsup, "mid={$md1}&imid={$md2}&img_url={$md3}&ititle={$md4}&iname={$md5}&dscr={$md6}&date={$md7}&last=ok");
			flock($whatsup, LOCK_UN);
			fclose($whatsup);
			
			} #_____________________________
			
			
			
			$data .= "{$tmp_filename}\t{$_REQUEST["title_$i"]}\t{$_REQUEST["name"]}\t{$_REQUEST["email"]}\t{$_REQUEST["editkey"]}\t{$_REQUEST["url"]}\t{$_REQUEST["comment_$i"]}\t{$_REQUEST["color_$i"]}\t{$new_width}\t{$new_height}\t{$or_width}\t{$or_height}\t{$model}\t{$iso}\t{$fnumber}\t{$picdate}\t{$ftype}\t{$bright}\t{$ftime}\t{$white}\t{$_REQUEST["cat_$i"]}\t{$_SERVER["REMOTE_ADDR"]}\t{$sokko}\t{$scene}\t\t\t\t\t{$add_name}\t{$flength}\t\t{$m_width}\t{$m_height}\t{$maker}\t{$flash}\t{$etype}\t{$sharpness}\t{$jpegq}\t\n"; //35
			
			$face_addr = "{$master_url}album.php?mode=res_form&num={$tmp_filename}&id={$_REQUEST["id"]}";
			$enface_addr = urlencode($face_addr);
			
			
			$url = "http://www.facebook.com/l.php?u={$enface_addr}&h=da9bf";
			
			$headers = array(
			    'User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)',    //ユーザエージェントの指定 
			);
			
			$options = array('http' => array( 
   			 'method' => 'GET', 
   			 'header' => implode("\r\n", $headers), 
			));
			
			$contents = file_get_contents($url, false, stream_context_create($options)); 
			
			usleep(500000);
		}
	}
	
	$file = @fopen("_log/{$_REQUEST["id"]}.php", "a") or out_error("投稿ミスった！");
	flock($file, LOCK_EX);
	fputs($file, $data);
	flock($file, LOCK_UN);
	fclose($file);
	
	
	
	# ------------------------------
	$master_id = $_REQUEST["id"];
	
	$ssdata = @file("_log/{$_REQUEST["id"]}.php");
	$m = 1;
	$foot = ",";
	
	$pre_data = array();
	$add_data = array();
	
	
	foreach ( $ssdata as $key => $vals ) {
		$value = mb_split("\t", $vals);
		
		# ソート
		if ( $confg_val[12] == "3" ) {
			array_push($pre_data, "$resmany<>$key");
		}
		else if ( $confg_val[12] == "2" ) {
			if ( $resmany > 0 ) { array_push($pre_data, "$res_value[0]<>$key"); }
			else { array_push($add_data, $val); }
		}
		else if ( $confg_val[12] == "1" ) {
			if ( !$point ) { $point[0] = "0"; }
			array_push($pre_data, "$point[0]<>$key");
		}
		else if ( $confg_val[12] == "4" ) {
			array_push($pre_data, "$value[20]<>$key");
		}
		else if ( $confg_val[12] == "6" ) {
			array_push($pre_data, "$value[0]<>$key");
		}
		else {
			array_push($pre_data, "$value[15]<>$key");
		}
	}
	
	natcasesort ($pre_data);
	if ( $confg_val[12] == "1" or $confg_val[12] == "2" or $confg_val[12] == "3" or $confg_val[12] == "5" or $confg_val[12] == "6" ) {
		$pre_data = array_reverse($pre_data, true);
	}
	
	$sort_data = array();
	foreach ( $pre_data as $val ) {
		$d_key = mb_split("<>", $val);
		array_push($sort_data, $ssdata[$d_key[1]]);
	}
	
	if ( $add_data ) { 
		foreach ( $add_data as $val ) {
			array_push($sort_data, $val);
		}
	}
	
	$ssdata = $sort_data;
	
	$imid = "";
	$dir = "";
	$title = "";
	$name = "";
	$dscr = "";
	$date = "";
	
	foreach ( $ssdata as $data_vals ) {
		if ( $m == count($ssdata) ) { $foot = ""; }
		$data_val = mb_split("\t", $data_vals);
		$u_title = mb_ereg_replace ('&', '%26', $data_val[1]);
		$u_title = mb_ereg_replace (',', '%2c', $u_title);
		$u_name = mb_ereg_replace ('&', '%26', $data_val[2]);
		$u_name = mb_ereg_replace (',', '%2c', $u_name);
		$u_dscr = mb_ereg_replace ('&', '%26', $data_val[6]);
		$u_dscr = mb_ereg_replace (',', '%2c', $u_dscr);
		$u_date = mb_ereg_replace ('&', '%26', $data_val[15]);
		$u_date = mb_ereg_replace (',', '%2c', $u_date);
		$u_fid = mb_ereg_replace ('&', '%26', $data_val[28]);
		$u_fid = mb_ereg_replace (',', '%2c', $u_fid);
		
		$u_file = $data_val[0];
		$imid .= "{$u_file}{$foot}";
		$dir  .= "{$u_file}{$u_fid}.jpg{$foot}";
		$title .= "{$u_title}{$foot}";
		$name .= "{$u_name}{$foot}";
		$dscr .= "{$u_dscr}{$foot}";
		$date .= "{$u_date}{$foot}";
		$m++;
	}
	
	$usr_file = @fopen("./_log/{$master_id}d.php", "a") or out_error("ファイルオープンエラー");
	flock($usr_file, LOCK_EX);
	ftruncate($usr_file, 0);
	fputs($usr_file, "imid={$imid}&imgdir={$img_dir}&img_url={$dir}&ititle={$title}&iname={$name}&dscr={$dscr}&date={$date}&last=ok");
	flock($usr_file, LOCK_UN);
	fclose($usr_file);
	
	
	
	header("Location: ./album.php?id={$_REQUEST["id"]}");
	exit;
}





if ( !$_REQUEST["id"] ) { $_REQUEST["mode"] = "title"; }

if ( $_REQUEST["mode"] == "title" ) {
	
	$_SESSION["usr"]  = "";
	$_SESSION["pass"] = "";
	
	# カウンタ
	$cnt = @fopen("_cnt/title.txt", "a+") or out_error("カウンター処理ミスった！");
	flock($cnt, LOCK_EX);
	$count = fgets($cnt);
	if ( !$count ) { $count = "0"; }
	if ( mb_strpos($_SERVER["HTTP_REFERER"], "album.php") === FALSE ) {
		$count ++;
		ftruncate($cnt, 0);
		fputs($cnt, $count);
	}
	flock($cnt, LOCK_UN);
	fclose($cnt);
	
	$config = array_reverse($config);
	$all_page = ceil( count($config) / $view_data );
	
	$pre_data = array();
	foreach ( $config as $key => $val ) {
		$value = mb_split("\t", $val);
		array_push($pre_data, "$value[22]<>$key");
	}
	natcasesort($pre_data);
	
	$data = array();
	foreach ( $pre_data as $val ) {
		$d_key = mb_split("<>", $val);
		array_push($data, $config[$d_key[1]]);
	}
	
	if ( $_REQUEST['start_num'] ) { $start_num = $_REQUEST['start_num']; }
	else { $start_num = 0; }
	$last_num = $start_num + $view_data - 1;
	if ( $last_num > count($data) - 1 ) { $last_num = count($data) - 1; }
	$next_num = $last_num + 1;
	if ( $next_num >= count($data) ) { $next_num = ""; }
	$prev_num = $start_num - $view_data;
	if ( $prev_num  < 0 ) { $prev_num = 0;  }
	if ( $start_num < 1 ) { $prev_num = ""; }
	$now_page = ( INT ) ( $start_num / $view_data ) + 1;
	if ( !$all_page ) { $now_page = "0"; }
	
	$flag = "1"; $tmpl_file = "title";
	$tmpl = @file("_tmpl/".$tmpl_file.".htm") or out_error("テンプレートファイル処理ミスった！");
	foreach( $tmpl as $key => $val ) {
		if ( mb_ereg_match("(.*)<!--■■-->(.*)", $val) ) { $flag++; }
		if     ( $flag == "1" ) { $album_head .= $val; }
		elseif ( $flag == "2" ) { $album_main .= $val; }
		elseif ( $flag == "3" ) { $album_foot .= $val; }
	}
	
	if ( $prev_num !== "" ) {
		$prev_link  = "album.php?start_num={$prev_num}&mode=title";
	$album_head = mb_ereg_replace("■back■", $prev_link, $album_head);
	} else { $album_head = mb_ereg_replace("[^\n]*?■back■(.*?)\n", "", $album_head); }
	
	if ( $start_num > 0 ) {
		$top_link   = "album.php?start_num=0&mode=title";
		$album_head = mb_ereg_replace("■top■", $top_link, $album_head);
	} else { $album_head = mb_ereg_replace("[^\n]*?■top■(.*?)\n", "", $album_head); }
	$album_foot = $album_foot . chck_ip($c_data);
	if ( $next_num !== "" ) {
		$next_link  = "album.php?start_num={$next_num}&mode=title";
		$album_head = mb_ereg_replace("■next■", $next_link, $album_head);
	} else { $album_head = mb_ereg_replace("[^\n]*?■next■(.*?)\n", "", $album_head); }
	
	$album_head = mb_ereg_replace("■all_page■", $all_page, $album_head);
	$album_head = mb_ereg_replace("■now_page■", $now_page, $album_head);
	$album_head = mb_ereg_replace("■return■", $return_url, $album_head);
	$album_head = mb_ereg_replace("■count■",    $count,    $album_head);
	$album_head = mb_ereg_replace("■fontsize■", $fontsize, $album_head);
	print $album_head;
	
	$m = 1;
	if ( $_REQUEST["view_line"] ) { $view_line = $_REQUEST["view_line"]; }
	
	print "<table border=0 align=\"center\" cellpadding=\"1\" cellspacing=\"0\"><tr valign=\"top\"><td>";
	for ( $i = $start_num; $i <= $last_num; $i++ ) {
		
		$album_body = $album_main;
		$value = mb_split("\t", $data[$i]);
		
		$date = date("Y/m/d G:i:s", $value[5]);
		$albumurl = "album.php?id={$value[0]}";
		if ( !$value[6] ) { $value[6] = $def_color; }
		
		$album_body = mb_ereg_replace("■id■",       $value[0], $album_body);
		$album_body = mb_ereg_replace("■imgurl■",   $value[1],  $album_body);
		$album_body = mb_ereg_replace("■title■",    $value[3],  $album_body);
		$album_body = mb_ereg_replace("■comment■",  $value[4], $album_body);
		$album_body = mb_ereg_replace("■color■",    $value[6],  $album_body);
		$album_body = mb_ereg_replace("■sort■",     $value[12], $album_body);
		$album_body = mb_ereg_replace("■albumurl■", $albumurl, $album_body);
		$album_body = mb_ereg_replace("■date■",     $date,      $album_body);
		$album_body = mb_ereg_replace("■edit■",     "admin.php?id={$value[0]}", $album_body);
		
		$topicdata = @file("./_log/{$value[0]}.php");
		if ( !$topicdata ) { $topicmany = 0; $topicdata = array(); } else { $topicmany = count($topicdata); }
		@natcasesort($topicdata);
		$dammy_num  = $topicmany - 1;
		$topic_vals = mb_split("\t", $topicdata[$dammy_num]);
		if ( $topic_vals[0] ) { $topic_date = date("Y/m/d G:i:s", $topic_vals[0]); }
		$topic_row_date = $topic_vals[0];
		
		$topic_img = array();
		foreach ( $topicdata as $topic_vals ) {
			$topic_val = mb_split("\t", $topic_vals);
			if ( file_exists("{$img_dir}/{$value[2]}/{$topic_val[0]}s.jpg") ) { $thum_img = "{$img_dir}/{$value[2]}/{$topic_val[0]}s.jpg"; }
			else { $thum_img = "{$img_dir}/{$value[2]}/{$topic_val[0]}{$topic_val[28]}.jpg"; }
			array_push($topic_img, $thum_img);
		}
		
		$thum = $topic_img[rand(0,(count($topic_img)-1))];
		
		if ( $value[9] or $value[10] ) { $thum = "./img/protect.jpg"; }
		else if ( !$thum ) { $thum = "./img/dammy.jpg"; }
		
		if ( time() - $topic_row_date < $new_date * 60*60 ) {
			$album_body = mb_ereg_replace("■new■", $new_iconA, $album_body);
		} else {
			$album_body = mb_ereg_replace("■new■", "", $album_body);
		}
		
		$album_body = mb_ereg_replace("■topic■",      $topic_date, $album_body); # 最新記事
		$album_body = mb_ereg_replace("■topic_many■", $topicmany,  $album_body); # 記事数
		$album_body = mb_ereg_replace("■thumurl■",    $thum,  $album_body);      # 画像
		
		print $album_body;
		if ( $m >= $view_line ) {
			print "</td></tr><tr valign=\"top\"><td>";
			$m = 1;
			}
		else { print "</td><td>"; $m++; }
	}
print "</table>";

$album_foot = mb_ereg_replace("■all_page■", $all_page, $album_foot);
$album_foot = mb_ereg_replace("■now_page■", $now_page, $album_foot);
$album_foot = mb_ereg_replace("■copy■", $copy, $album_foot);
if ( $prev_num !== "" ) {
	$album_foot = mb_ereg_replace("■back■", $prev_link, $album_foot);
} else { $album_foot = mb_ereg_replace("[^\n]*?■back■(.*?)\n", "", $album_foot); }
if ( $start_num > 0 ) {
	$album_foot = mb_ereg_replace("■top■", $top_link, $album_foot);
} else { $album_foot = mb_ereg_replace("[^\n]*?■top■(.*?)\n", "", $album_foot); }
if ( $next_num !== "" ) {
	$album_foot = mb_ereg_replace("■next■", $next_link, $album_foot);
} else { $album_foot = mb_ereg_replace("[^\n]*?■next■(.*?)\n", "", $album_foot); }
print $album_foot;
print "</body></html>";
exit;
}


else if ( $_REQUEST["mode"] == "js" ) {
	print <<<EOD
function RunAlbumFactory() {
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="AlbumFactory" align="left">\\n<param name="allowScriptAccess" value="always" />\\n<param name="menu" value="false" />\\n<param name="quality" value="high" />\\n<param name="salign" value="lt" />\\n<param name=FlashVars value="afid={$_REQUEST[id]}&num={$_REQUEST[num]}">\\n<param name="bgcolor" value="#000000" />\\n<param name="movie" value="coolpics2.swf" />\\n<embed src="coolpics2.swf" menu="false" quality="high" bgcolor="#000000" width="100%" height="100%" name="AlbumFactory" salign="lt" align="left" FlashVars="afid={$_REQUEST[id]}&num={$_REQUEST[num]}" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" />\\n</object>');
	}
EOD;
exit;
}

else if ( $_REQUEST["mode"] == "sshow" and $_REQUEST["num"] ) {
	chck_accs();
	if ( !$_REQUEST["id"] ) { header("Location: ./album.php?mode=title"); exit; }
	
	print <<<EOD
<html>
<head>
<!-- 眉屈 -->
<!-- ↑文字化け対策 -->
<Meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="album.php?mode=js&id={$_REQUEST["id"]}&num={$_REQUEST["num"]}" type="text/javascript"></script>
<title>Album Factory</title>
</head>
<body text=#1D5EE4 vLink=#0000ff aLink=#0000ff link=#0000ff bgColor=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<script type="text/javascript">RunAlbumFactory();</script>
</body>
</html>
EOD;
exit;
}

else if ( $_REQUEST["mode"] == "sshow" ) {
	chck_accs();
	if ( !$_REQUEST["id"] ) { header("Location: ./album.php?mode=title"); exit; }
	
	print <<<EOD
<html>
<head>
<!-- 眉屈 -->
<!-- ↑文字化け対策 -->
<Meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="./_log/af{$_REQUEST["id"]}.js" type="text/javascript"></script>
<title>Album Factory</title>
</head>
<body text=#1D5EE4 vLink=#0000ff aLink=#0000ff link=#0000ff bgColor=#000000 leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>
<script type="text/javascript">RunAlbumFactory();</script>
</body>
</html>
EOD;
exit;
}




else if ( !$_REQUEST["mode"] ) {
	chck_accs();
	if ( !$_REQUEST["id"] ) { header("Location: ./album.php?mode=title"); exit; }
	
	
	if ( $_REQUEST["tmpl"] == "only" ) {
		$view_data = $only_view_data;
		$view_line = $only_view_line;
	} else if ( $_REQUEST["tmpl"] == "micro" ) {
		$view_data = $micro_view_data;
		$view_line = $micro_view_line;
	} else if ( $_REQUEST["tmpl"] == "all" ) {
		$view_data = 30;
		$view_line = 5;
	}
	
	if ( $_REQUEST["view_line"] ) { $view_line = $_REQUEST["view_line"]; }
	if ( $_REQUEST["x"] ) { $only_max_width  = $_REQUEST["x"]; }
	if ( $_REQUEST["y"] ) { $only_max_height = $_REQUEST["y"]; }
	$_REQUEST["id"] = urlencode($_REQUEST["id"]);
	
	if ( $_REQUEST["srt"] == "" ) { $_REQUEST["srt"] = $confg_val[12]; }
	
	if ( !$srt_switch and mb_strpos($_REQUEST["id"], "::") === FALSE ) {
		$time = time();
		$no_cnt_flag = 0;
		$cnt_accs = @file("./_cnt/{$_REQUEST["id"]}accs.php");
		$cnt = @fopen("_cnt/{$_REQUEST["id"]}.txt", "a+") or out_error("カウンター処理ミスった！");
		@flock($cnt, LOCK_EX);
		$count = fgets($cnt);
		if ( !$count ) { $count = "0"; }
		
		if ( $cnt_accs ) {
			foreach($cnt_accs as $accsvals) {
				$accsval = explode("\t", $accsvals);
				if ( $time - $accsval[0] < 12*60*60 and $accsval[1] == $_SERVER["REMOTE_ADDR"] ) { $no_cnt_flag = 1; break; }
			}
		}
		
		if ( !$no_cnt_flag ) {
			$count ++;
			ftruncate($cnt, 0);
			fputs($cnt, $count);
		}
		@flock($cnt, LOCK_UN);
		fclose($cnt);
		
		if ( !$no_cnt_flag ) {
			$old_data = @file("./_cnt/{$_REQUEST["id"]}accs.php");
			$accs_data = @fopen("./_cnt/{$_REQUEST["id"]}accs.php", "a+");
			@flock($accs_data, LOCK_EX);
			if ( count($old_data) >= 500 ) {
				array_splice($old_data, 0, 200);
				ftruncate($accs_data, 0);
				foreach ( $old_data as $val ) {
					fputs($accs_data, $val);
				}
			}
			$str = "$time\t{$_SERVER["REMOTE_ADDR"]}\t\n";
			fputs($accs_data, $str);
			@flock($accs_data, LOCK_UN);
			fclose($accs_data);
		}
	}
	
	$pre_data = array();
	$add_data = array();
	
	if ( !$sorted_data ) {
		$data = @file("./_log/{$_REQUEST["id"]}.php");
		if ( !$data ) { $data = array(); }
	} else { $data = $sorted_data; }
	
	
	foreach ( $data as $key => $val ) {
		$value = mb_split("\t", $val);
		
		# レス
		$rescnt = @file("./_res/{$value[0]}.php");
		# レス数
		if ( !$rescnt ) { $resmany = 0; } else { $resmany = count($rescnt); }
		# レス日時
		$damy_num = count($rescnt) - 1;
		$res_value = mb_split("\t", $rescnt[$damy_num]);
		# ポイント
		$point  = @file("./_log/{$value[0]}.php");
		
		if ( $_REQUEST["srt"] == "3" ) {
			array_push($pre_data, "$resmany<>$key");
		}
		else if ( $_REQUEST["srt"] == "2" ) {
			if ( $resmany > 0 ) { array_push($pre_data, "$res_value[0]<>$key"); }
			else { array_push($add_data, $val); }
		}
		else if ( $_REQUEST["srt"] == "1" ) {
			if ( !$point ) { $point[0] = "0"; }
			array_push($pre_data, "$point[0]<>$key");
		}
		else if ( $_REQUEST["srt"] == "4" ) {
			array_push($pre_data, "$value[20]<>$key");
		}
		else if ( $_REQUEST["srt"] == "6" ) {
			array_push($pre_data, "$value[0]<>$key");
		}
		else {
			array_push($pre_data, "$value[15]<>$key");
		}
	}
	
	natcasesort ($pre_data);
	if ( $_REQUEST["srt"] == "1" or $_REQUEST["srt"] == "2" or $_REQUEST["srt"] == "3" or $_REQUEST["srt"] == "5" or $_REQUEST["srt"] == "6" ) {
		$pre_data = array_reverse($pre_data, true);
	}
	
	$sort_data = array();
	foreach ( $pre_data as $val ) {
		$d_key = mb_split("<>", $val);
		array_push($sort_data, $data[$d_key[1]]);
	}
	
	if ( $add_data ) { 
		foreach ( $add_data as $val ) {
			array_push($sort_data, $val);
		}
	}
	
	$data = $sort_data;
	if ( $_REQUEST["_v"] ) {
		$_REQUEST['start_num'] = 0;
		foreach ( $data as $val ) {
			$value = mb_split("\t", $val);
			if ( $_REQUEST["_v"] == $value[0] ) { break; }
			$_REQUEST['start_num'] ++;
		}
	}
	
	
	$all_page = ceil ( count($data) / $view_data );
	
	if ( $_REQUEST['start_num'] ) { $start_num = $_REQUEST['start_num']; }
	else { $start_num = 0; }
	$last_num = $start_num + $view_data - 1;
	if ( $last_num > count($data) - 1 ) { $last_num = count($data) - 1; }
	$next_num = $last_num + 1;
	if ( $next_num >= count($data) ) { $next_num = ""; }
	$prev_num = $start_num - $view_data;
	if ( $prev_num  < 0 ) { $prev_num = 0;  }
	if ( $start_num < 1 ) { $prev_num = ""; }
	
	$now_page = ( INT ) ( $start_num / $view_data ) + 1;
	
	# if ( $_REQUEST["_v"] ) { $now_page = $start_num + 1; }
	
	$flag = "1";
	if ( file_exists("_tmpl/".$_REQUEST["tmpl"].$_REQUEST["id"].".htm") ) { $tmpl_file = $_REQUEST["tmpl"].$_REQUEST["id"]; }
	else if ( $_REQUEST["tmpl"] ) { $tmpl_file = $_REQUEST["tmpl"]; }
	else if ( file_exists("_tmpl/album".$_REQUEST["id"].".htm") ) { $tmpl_file = "album".$_REQUEST["id"]; }
	else { $tmpl_file = "album"; }
	if ( mb_ereg_match("pass|PASS", $tmpl_file) or strlen($tmpl_file) > 30 or mb_ereg_match("\|", $tmpl_file) ) { out_error("誰？"); }
	$tmpl = @file("_tmpl/".$tmpl_file.".htm") or out_error("テンプレート処理ミスった！");
	
	foreach( $tmpl as $key => $val ) {
		if ( mb_ereg_match("(.*)<!--■■-->(.*)", $val) ) { $flag++; }
		if     ( $flag == "1" ) { $album_head .= $val; }
		elseif ( $flag == "2" ) { $album_main .= $val; }
		elseif ( $flag == "3" ) { $album_foot .= $val; }
	}
	
	if ( $prev_num !== "" ) {
		$prev_link  = "album.php?start_num={$prev_num}&mode={$_REQUEST["mode"]}&id={$_REQUEST["id"]}&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		$album_head = mb_ereg_replace("■back■", $prev_link, $album_head);
	}
	 else { $album_head = mb_ereg_replace("[^\n]*?■back■(.*?)\n", "", $album_head); }
	
	if ( $start_num > 0 ) {
		$top_link   = "album.php?start_num=0&mode={$_REQUEST["mode"]}&id={$_REQUEST["id"]}&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		$album_head = mb_ereg_replace("■top■", $top_link, $album_head);
	}
	 else { $album_head = mb_ereg_replace("[^\n]*?■top■(.*?)\n", "", $album_head); }

	if ( $next_num !== "" ) {
		$next_link  = "album.php?start_num={$next_num}&mode={$_REQUEST["mode"]}&id={$_REQUEST["id"]}&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		$album_head = mb_ereg_replace("■next■", $next_link, $album_head);
	}
	 else { $album_head = mb_ereg_replace("[^\n]*?■next■(.*?)\n", "", $album_head); }
	
	if ( $_REQUEST["srt"] == "1" ) { $srt_title = "ポイント順"; }
	else if ( $_REQUEST["srt"] == "2" ) { $srt_title = "新着コメント順"; }
	else if ( $_REQUEST["srt"] == "3" ) { $srt_title = "コメント数順"; }
	else if ( $_REQUEST["srt"] == "4" ) { $srt_title = "カテゴリ分類"; }
	else if ( $_REQUEST["srt"] == "5" ) { $srt_title = "撮影順（逆順）"; }
	else if ( $_REQUEST["srt"] == "6" ) { $srt_title = "新着写真順"; }
	else { $srt_title = "撮影順（時系列）"; }
	if ( $addsrt_title AND !$_REQUEST["_v"] ) { $addsrt_title = $addsrt_title . " ({$now_page}/{$all_page}) [<a href=\"album.php?id={$_REQUEST["from"]}&tmpl={$_REQUEST["tmpl"]}\"><b>絞り込み解除</b></a>]"; } #####
	
	$album_head = mb_ereg_replace("■all_page■", $all_page, $album_head);
	$album_head = mb_ereg_replace("■now_page■", $now_page, $album_head);
	$album_head = mb_ereg_replace("■count■",    $count, $album_head);
	$album_head = mb_ereg_replace("■return■", $return_url, $album_head);
	$album_head = mb_ereg_replace("■id■",       $_REQUEST["id"], $album_head);
	$album_head = mb_ereg_replace("■sort■",     $srt_title, $album_head);
	$album_head = mb_ereg_replace("■sortlink■", $_REQUEST["srt"], $album_head);
	$album_head = mb_ereg_replace("■addsort■",  $addsrt_title, $album_head);
	$album_head = mb_ereg_replace("■from■", $_REQUEST["from"], $album_head); #####
	$album_head = mb_ereg_replace("■input■",    "<a href=\"album.php?id={$_REQUEST["id"]}&mode=input&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link1■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=0&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"写真を撮影した日時順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link2■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=2&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"新しいコメントが付いた写真から順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link3■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=3&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"コメント数が多い写真から順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link4■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=1&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"写真の評価ポイントが多い順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link5■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=4&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"写真のカテゴリ毎に分類して表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link6■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=5&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"撮った写真を新しい順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■srt_link7■", "<a href=\"album.php?id={$_REQUEST["id"]}&srt=6&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}\" title=\"写真がアルバムに登録された順に表示します\">", $album_head); #####
	$album_head = mb_ereg_replace("■fontsize■",  $fontsize, $album_head);
	$album_head = mb_ereg_replace("■titleimg■",  $confg_val[1], $album_head);
	$album_head = mb_ereg_replace("■title■",     $confg_val[3], $album_head);
	$album_head = mb_ereg_replace("■comment■",   $confg_val[4], $album_head);

	print <<< EOD
$album_head
<script language="JavaScript">
<!--

function view_img(num,x,y,id) {
	var flag;
//	if ( screen.availWidth < x ) { y = y + 21; }
//	if ( screen.availHeight - 42 < y ) { x = x + 11; }
	
	if ( screen.availWidth  < x ) { x = screen.availWidth; flag = 1; }
	if ( screen.availHeight < y ) { y = screen.availHeight; flag = 1; }

	if ( flag ) {
		var Win1=window.open("album.php?id="+id+"&view="+num+"&fe={$find}", "_blank", "scrollbars=1, width="+x+", height="+y+", status=0, resizable=1");
	} else {
		var Win1=window.open("album.php?id="+id+"&view="+num+"&fe={$find}", "_blank", "scrollbars=no, width="+x+", height="+y+", status=0, resizable=1");
	}
	Win1.focus();
}

function comwin(num,page,id,srt) {
	window.open("album.php?num="+num+"&mode=res_form&page="+page+"&id="+id+"&srt="+srt+"#form","_blank","width=490, height=600, resizable=1, scrollbars=1");
	}

function topic(num,page,id,srt) {
	window.open("album.php?num="+num+"&mode=res_form&page="+page+"&id="+id+"&srt="+srt+"","_blank","width=490, height=600, resizable=1, scrollbars=1");
	}

//-->
</script>
EOD;
	
	$m = 1;
	if ( !$_REQUEST["srt"] ) { $_REQUEST["srt"] = "0"; }
	$album_foot = $album_foot . chck_ip($c_data);
	if ( $view_data != 1 ) { print "<table border=0 align=\"center\" cellpadding=\"1\" cellspacing=\"0\"><tr valign=\"top\"><td>"; }
	
	for ( $i = $start_num; $i <= $last_num; $i++ ) {
		$album_body = $album_main;
		$value = mb_split("\t", $data[$i]);


#__ EDITER__
$befores = mb_split(",", $before_exif);
$afters  = mb_split(",", $after_exif);
foreach ( $befores as $ed_key => $ed_val ) {
	for ( $ed_i = 12; $ed_i <= 37; $ed_i++ ) {
		if ( $ed_i != 21 and $ed_i != 28 and $ed_i != 31 and $ed_i != 32 ) {
			$value[$ed_i] = mb_eregi_replace($ed_val, $afters[$ed_key], $value[$ed_i]);
		}
	}
}
		
		if ( $srt_switch ) {
			$confg_val[2] = $sorted_dir["{$value[0]}"];
			$proxy_id     = $sorted_id["{$value[0]}"];
			$confg_val[17] = $sorted_pr["{$value[0]}"];
		} else { $proxy_id = $_REQUEST["id"]; }
		
		$fl1 = make_name(6) . ".jpg";
		$fl2 = make_name(5);
		$fl3 = "";
		$fl3s = unpack("H*", $value[0]);
		foreach ( $fl3s as $flvls ) { $fl3 .= $flvls; }
		
		if ( file_exists("{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg") ) { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}s.jpg"; }
		else if ( file_exists("{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg") ) { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg"; }
		else { $thum_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg"; }
		$img = "album.php?view={$value[0]}";
		$thum_size = (INT) ( @filesize($thum_img) / 1000 );
		$img_size  = (INT) ( @filesize("{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg") / 1000 );
		if ( $confg_val[17] ) { 
			if ( $_REQUEST["view"] ) { $or_img = "{$img_dir}/{$confg_val[2]}/{$_REQUEST["view"]}{$value[28]}.jpg"; } 
			else { $or_img = "{$img_dir}/{$confg_val[2]}/{$value[0]}{$value[28]}.jpg"; }
		}
		else {
			$or_img = "img.php?dir={$fl1}&file={$fl2}&fn={$proxy_id}&fc={$fl3}&fd={$find}";
		}
		
		$date = date("Y/m/d G:i:s", $value[0]);
		$file_name = make_name(6) . ".jpg";
		$dir = make_name(5);
		if ( !$value[2] ) { $value[2] = "誰か"; }
		if ( !$value[7] ) { $value[7] = $def_color; }
		else if ( $value[7] == "#FFFFFF" or $value[7] == "#ffffff" ) { $value[7] = "#666666"; }
		if ( !$value[3] ) { $album_body = mb_ereg_replace("(.*)?■email■(.*)?\n", "", $album_body, "s"); }
		if ( !$value[5] ) { $album_body = mb_ereg_replace("(.*)?■url■(.*)?\n",   "", $album_body, "s"); }
		if      ( $title_model == 1 and !$value[1] and $value[12] ) { $value[1] = $value[12]; }
		else if ( $title_model == 2 and !$value[1] and $value[2]  ) { $value[1] = $value[2];  }
		else if ( !$value[1] ) { $value[1] = "無題"; }
		
		if ( $value[12] ) { $model = mb_ereg_replace("  ", "", $value[12]); }
		if ( $value[15] ) { $dam = mb_split(" ", $value[15]); $picdate=$dam[0]; }
		if ( $value[17] ) { $dam = mb_ereg_replace(" ", "", $value[17]); $dam = mb_split("\(", $dam); $ev = rtrim($dam[0]); }
		if ( $value[18] ) { $dam = mb_ereg_replace(" ", "", $value[18]); $dam = mb_split("s", $dam); $ftime = rtrim($dam[0]); }
		if ( $value[29] ) { $dam = mb_ereg_replace(" ", "", $value[29]); $dam = mb_split("\(", $dam); $flength = rtrim($dam[0]); }
		$adl = "&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}";
		$link12 = "<a href=\"album.php?id=12::" . urlencode($value[12]) . "{$adl}\" title=\"この機種名で絞り込み\">";
		$link13 = "<a href=\"album.php?id=13::" . urlencode($value[13]) . "{$adl}\" title=\"このISOで絞り込み\">";
		$link14 = "<a href=\"album.php?id=14::" . urlencode($value[14]) . "{$adl}\" title=\"この絞り値で絞り込み\">";
		$link18 = "<a href=\"album.php?id=18::" . urlencode($ftime) . "{$adl}\" title=\"このシャッター速度で絞り込み\">";
		$link24 = "<a href=\"album.php?id=24::" . urlencode($value[24]) . "{$adl}\" title=\"この情報で絞り込み\">";
		$link29 = "<a href=\"album.php?id=29::" . urlencode($flength) . "{$adl}\" title=\"この焦点距離で絞り込み\">";
		$link30 = "<a href=\"album.php?id=30::" . urlencode($value[30]) . "{$adl}\" title=\"このレンズで絞り込み\">";
		$dammy = mb_split("\(", $value[18]);
		if ( $dammy[2] ) { $value[18] = $dammy[0] . "(" . $dammy[2]; }
		
		$point   = @file("./_log/{$value[0]}.php");
		$rescnts = @file("./_res/{$value[0]}.php");
		if ( !$rescnts ) { $rescnt = 0; } else { $rescnt = count($rescnts); }
		$lastres_num = $rescnt - 1;
		$res_val = mb_split("\t", $rescnts[$lastres_num]);
		
		if ( time() - $value[0] < $new_date * 60*60 ) {
			$album_body = mb_ereg_replace("■new■", $new_iconB, $album_body);
		} else {
			$album_body = mb_ereg_replace("■new■", "", $album_body);
		}
		if ( time() - $res_val[0] < $new_date * 60*60 ) {
			$album_body = mb_ereg_replace("■resnew■", $new_iconC, $album_body);
		} else {
			$album_body = mb_ereg_replace("■resnew■", "", $album_body);
		}
		
		$ray = (int) ( $max_width - $value[10] ) / 2;
		if ( $ray < 0 ) { $ray = "0"; }
		$ray2 = 80 + $value[11];
		
		if ( $_REQUEST["tmpl"] == "only" ) {
			$rate_width  = $only_max_width  / $value[8];
			$rate_height = $only_max_height / $value[9];
			if ( $rate_width < $rate_height ) { $rate = $rate_width; }
			else { $rate = $rate_height; }
			$value[8] = (int) ( $value[8] * $rate );
			$value[9] = (int) ( $value[9] * $rate );
		} else if ( $_REQUEST["tmpl"] == "all" ) {
			$rate_width  = 160  / $value[8];
			$rate_height = 160 / $value[9];
			if ( $rate_width < $rate_height ) { $rate = $rate_width; }
			else { $rate = $rate_height; }
			$value[8] = (int) ( $value[8] * $rate );
			$value[9] = (int) ( $value[9] * $rate );
		}
		
		if ( mb_strpos($_REQUEST["id"], "::") !== FALSE ) {
			$returnlink = "<div align=right><a href=\"album.php?id={$proxy_id}&srt={$_REQUEST[srt]}\"><font color=\"#FFFFFF\" class=\"font8pt\">→ このアルバムを表示する</font></a></div>";
		} else { $returnlink = ""; }
		if ( $value[29] and $value[29] != "\n" ) { $value[29] .= "㎜"; }
		
		$reslink = "<a href=\"JavaScript:onClick=comwin({$value[0]}, {$start_num}, {$proxy_id}, {$_REQUEST["srt"]})\" title=\"コメントを書く\">";
		$imglink = "<a href=\"JavaScript:onClick=view_img({$value[0]}, {$value[10]}, {$value[11]}, {$proxy_id})\" title=\"画像を拡大表示\">";
		$topiclink = "<a href=\"JavaScript:onClick=topic({$value[0]}, {$start_num}, {$proxy_id}, {$_REQUEST["srt"]})\" title=\"{$value[1]}\">";
		$namelink = "album.php?id=name::" . urlencode($value[2]) . "&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		$catlink  = "album.php?id=cat::" . urlencode($value[20]) . "&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		$edit = "album.php?mode=edit&page={$start_num}&id={$_REQUEST[id]}&num={$value[0]}&type=main&srt={$_REQUEST["srt"]}&tmpl={$_REQUEST["tmpl"]}&ck={$_REQUEST["ck"]}&from={$_REQUEST["from"]}&nn={$_REQUEST["nn"]}&mm={$_REQUEST["mm"]}"; #####
		if ( !$next_link ) { $next_link = $top_link; }
		
		if ( $addsrt_title ) {
			$sort_layer = <<<EOD

<div id="sort" style="position:absolute; left:700; top:73; z-index:5; filter:Alpha(opacity=70);" onmouseover="MM_showHideLayers('id1','','show','id2','','show','sort','','show')" onmouseout="MM_showHideLayers('id1','','hide','id2','','hide','sort','','hide')"><table width=200 border=0 cellpadding="2" cellspacing="0" class="srt_layer"><tr><td>&nbsp;{$addsrt_title}</td></tr></table></div>

EOD;
		} else {
			$sort_layer = <<<EOD

<div id="sort" style="position:absolute; left:700; top:73; z-index:2;"></div>

EOD;
		}
		
		$view_addr = "{$master_url}album.php?mode=res_form&num={$value[0]}&ck={$ckd}&page={$_REQUEST["page"]}&dir={$imdir}&id={$_REQUEST["id"]}"; #####
		$face_addr = "{$master_url}album.php?mode=res_form&num={$value[0]}&id={$_REQUEST["id"]}"; #####
		$enface_addr = urlencode($face_addr); #####
		
		$album_body = mb_ereg_replace("■next■", $next_link, $album_body);
		$album_body = mb_ereg_replace("■back■", $prev_link, $album_body);
		$album_body = mb_ereg_replace("■returnlink■", $returnlink, $album_body);
		$album_body = mb_ereg_replace("■sortlink■",   $_REQUEST["srt"], $album_body);
		$album_body = mb_ereg_replace("■ray■",       $ray, $album_body);
		$album_body = mb_ereg_replace("■or_img■",    $or_img, $album_body);
		$album_body = mb_ereg_replace("■id■",        $i, $album_body);
		$album_body = mb_ereg_replace("■edit■",      $edit, $album_body);
		$album_body = mb_ereg_replace("■namelink■",  $namelink, $album_body);
		$album_body = mb_ereg_replace("■catlink■",   $catlink, $album_body);
		$album_body = mb_ereg_replace("■point■",     $point[0], $album_body);
		$album_body = mb_ereg_replace("■rescnt■",    $rescnt, $album_body);
		$album_body = mb_ereg_replace("■imglink■",   $imglink,  $album_body);
		$album_body = mb_ereg_replace("■thum_size■", $thum_size,  $album_body);
		$album_body = mb_ereg_replace("■img_size■",  $img_size,  $album_body);
		$album_body = mb_ereg_replace("■reslink■",   $reslink,  $album_body);
		$album_body = mb_ereg_replace("■topiclink■", $topiclink,  $album_body);
		$album_body = mb_ereg_replace("■thumurl■",   $thum_img, $album_body);
		$album_body = mb_ereg_replace("■imgurl■",    $img,      $album_body);
		$album_body = mb_ereg_replace("■date■",      $date,     $album_body);
		$album_body = mb_ereg_replace("■reset■",     "album.php?id={$_REQUEST["from"]}&tmpl={$_REQUEST["tmpl"]}", $album_body); #####
		$album_body = mb_ereg_replace("■addsort■",  $addsrt_title, $album_body);
		$album_body = mb_ereg_replace("■sort_layer■", $sort_layer, $album_body);
		if ( $srt_switch ) { $vlid = $sorted_id["$value[0]"]; } else { $vlid = $_REQUEST["id"]; }
		$album_body = mb_ereg_replace("■view_link■", "{$master_url}album.php?id={$vlid}&gid={$ckd}&dir={$imdir}&_v={$value[0]}", $album_body);
		$album_body = mb_ereg_replace("■thum_i■", "{$img_dir}/{$confg_val[2]}/{$value[0]}i.jpg",  $album_body);
		$album_body = mb_ereg_replace("■thum_m■", "{$img_dir}/{$confg_val[2]}/{$value[0]}m.jpg",  $album_body); ### add 2009
		

		$album_body = mb_ereg_replace("■vwidth■",    $view_width, $album_body);
		$album_body = mb_ereg_replace("■imgnum■",    $value[0], $album_body);
		$album_body = mb_ereg_replace("■title■",    $value[1], $album_body);
		$album_body = mb_ereg_replace("■name■",     $value[2], $album_body);
		$album_body = mb_ereg_replace("■email■",    $value[3], $album_body);
		$album_body = mb_ereg_replace("■url■",      $value[5], $album_body);
		$album_body = mb_ereg_replace("■comment■",  $value[6], $album_body);
		$album_body = mb_ereg_replace("■color■",    $value[7], $album_body);
		$album_body = mb_ereg_replace("■s_width■",  $value[8], $album_body);
		$album_body = mb_ereg_replace("■s_height■", $value[9], $album_body);
		$album_body = mb_ereg_replace("■width■",    $value[10], $album_body);
		$album_body = mb_ereg_replace("■height■",   $value[11], $album_body);
		$album_body = mb_ereg_replace("■model■",    $value[12], $album_body);
		$album_body = mb_ereg_replace("■iso■",      $value[13], $album_body);
		$album_body = mb_ereg_replace("■fnumber■",  $value[14], $album_body);
		$album_body = mb_ereg_replace("■picdate■",  $value[15], $album_body);
		$album_body = mb_ereg_replace("■ftype■",    $value[16], $album_body);
		$album_body = mb_ereg_replace("■bright■",   $value[17], $album_body);
		$album_body = mb_ereg_replace("■ftime■",    $value[18], $album_body);
		$album_body = mb_ereg_replace("■white■",    $value[19], $album_body);
		$album_body = mb_ereg_replace("■cat■",      $value[20], $album_body);
		$album_body = mb_ereg_replace("■add1■",     $value[22], $album_body);
		$album_body = mb_ereg_replace("■add2■",     $value[23], $album_body);
		$album_body = mb_ereg_replace("■add3■",     $value[24], $album_body);
		$album_body = mb_ereg_replace("■add4■",     $value[25], $album_body);
		$album_body = mb_ereg_replace("■add5■",     $value[26], $album_body);
		$album_body = mb_ereg_replace("■add6■",     $value[27], $album_body);
		$album_body = mb_ereg_replace("■flength■",  $value[29], $album_body);
		$album_body = mb_ereg_replace("■lense■",    $value[30], $album_body);
		
		$album_body = mb_ereg_replace("■maker■",    $value[33], $album_body);
		$album_body = mb_ereg_replace("■flash■",    $value[34], $album_body);
		$album_body = mb_ereg_replace("■etype■",    $value[35], $album_body);
		$album_body = mb_ereg_replace("■sharpnessnse■",    $value[36], $album_body);
		$album_body = mb_ereg_replace("■jpegq■",    $value[37], $album_body);
		
		
		$album_body = mb_ereg_replace("■datelink■",   "album.php?id=15::" . urlencode($picdate) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■modellink■",   "album.php?id=12::" . urlencode($model) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■isolink■",     "album.php?id=13::" . urlencode($value[13]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■fnumberlink■", "album.php?id=14::" . urlencode($value[14]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■picdatelink■", "album.php?id=15::" . urlencode($value[15]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■ftypelink■",   "album.php?id=16::" . urlencode($value[16]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■brightlink■",  "album.php?id=17::" . urlencode($ev) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■ftimelink■",   "album.php?id=18::" . urlencode($ftime) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■whitelink■",   "album.php?id=19::" . urlencode($value[19]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add1link■",    "album.php?id=22::" . urlencode($value[22]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add2link■",    "album.php?id=23::" . urlencode($value[23]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add3link■",    "album.php?id=24::" . urlencode($value[24]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add4link■",    "album.php?id=25::" . urlencode($value[25]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add5link■",    "album.php?id=26::" . urlencode($value[26]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■add6link■",    "album.php?id=27::" . urlencode($value[27]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■flengthlink■", "album.php?id=29::" . urlencode($flength) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■lenselink■",   "album.php?id=30::" . urlencode($value[30]) . "{$adl}", $album_body);
		
		
		$album_body = mb_ereg_replace("■makerlink■",   "album.php?id=33::" . urlencode($value[33]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■flashlink■",   "album.php?id=34::" . urlencode($value[34]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■etypelink■",   "album.php?id=35::" . urlencode($value[35]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■sharpnessnselink■",   "album.php?id=36::" . urlencode($value[36]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■jpegqlink■",   "album.php?id=37::" . urlencode($value[37]) . "{$adl}", $album_body);
		$album_body = mb_ereg_replace("■addr■",  $view_addr,  $album_body); #####
		$album_body = mb_ereg_replace("■faddr■",  $face_addr,  $album_body); #####
		$album_body = mb_ereg_replace("■enfaddr■",  $enface_addr,  $album_body); #####
		
		if ( $value[18] ) { $dam = mb_split("\(", $value[18]); $dam = mb_split("\)", $dam[1]); $value[18] = rtrim($dam[0]) . "s&nbsp;"; }
		if ( $value[12] ) { $value[12] = "{$link12}{$value[12]}</a>・"; }
		if ( $value[29] and $value[29] != "\n" ) { $dam = mb_split(" ", $value[29]); $value[29] = "&nbsp;{$dam[0]}㎜"; }
		if ( $value[13] ) { $value[13] = "ISO" . $value[13] . "&nbsp;"; }
		if ( $value[14] ) { $value[14] = "{$link14}{$value[14]}</a>・"; }
		if ( $value[17] ) { $dam = mb_split(" ", $value[17]); $value[17] = $dam[0] . "EV&nbsp;"; }
		$imgid = "{$value[12]} {$link13}{$value[13]}</a> {$link18}{$value[18]}</a> {$value[14]} {$link24}{$value[24]}</a> {$link30}{$value[30]}</a> {$link29}{$value[29]}</a>";
		$album_body = mb_ereg_replace("■imgid■", $imgid, $album_body);
		
		print $album_body;
		
		if ( $view_data != 1 ) {
			if ( $m >= $view_line ) {
				print "</td></tr><tr valign=\"top\"><td>";
				$m = 1;
				}
			else { print "</td><td>"; $m++; }
		}
	}
	if ( $view_data != 1 ) { print "</td></tr></table>"; }
	
	$album_foot = mb_ereg_replace("■all_page■", $all_page, $album_foot);
	$album_foot = mb_ereg_replace("■now_page■", $now_page, $album_foot);
	$album_foot = mb_ereg_replace("■ray2■", $ray2, $album_foot);
	$album_foot = mb_ereg_replace("■copy■", $copy, $album_foot);
	if ( $prev_num !== "" ) {
		$album_foot = mb_ereg_replace("■back■", $prev_link, $album_foot);
	} else { $album_foot = mb_ereg_replace("[^\n]*?■back■(.*?)\n", "", $album_foot); }
	if ( $start_num > 0 ) {
		$album_foot = mb_ereg_replace("■top■", $top_link, $album_foot);
	} else { $album_foot = mb_ereg_replace("[^\n]*?■top■(.*?)\n", "", $album_foot); }
	if ( $next_num !== "" ) {
		$album_foot = mb_ereg_replace("■next■", $next_link, $album_foot);
	} else { $album_foot = mb_ereg_replace("[^\n]*?■next■(.*?)\n", "", $album_foot); }
	print $album_foot;
	print "</body></html>";
	exit;
}







function chck_accs() {
	global $confg_val, $srt_switch;
	
	if ( $confg_val[9] and $confg_val[10] and $_REQUEST["mode"] != "title" and !$srt_switch ) {
		if ( !$_SESSION["pass"] or $_SESSION["pass"] != $confg_val[10] or $_SESSION["usr"] != $confg_val[9] ) {
		$_SESSION["usr"] = ""; $_SESSION["pass"] = "";
		
		out_head();
		print <<<EOD
<table border=0 cellapding=3 cellspacing=2 align="center" width=400><tr><td class="font11pt">
<p align="center" style="background-color:#C71224; padding:2px;"><font color=#FFFFFF class="font11pt">Album Facotry アクセス認証</font></p>
<form action="album.php" method="post">
<input type="hidden" name="id" value="{$_REQUEST[id]}">
<input type="hidden" name="mode" value="{$_REQUEST[mode]}">
<input type="hidden" name="srt" value="{$_REQUEST[srt]}">
<input type="hidden" name="tmpl" value="{$_REQUEST[tmpl]}">
<input type="hidden" name="num" value="{$_REQUEST[num]}">
<input type="hidden" name="page" value="{$_REQUEST[page]}">
<input type="hidden" name="ck" value="{$_REQUEST["ck"]}">
<input type="hidden" name="from" value="{$_REQUEST["from"]}">
<p align="center">このアルバムを閲覧するには認証が必要です。</p>
<p align="center">ID：<input name="usr" type="test" size="10"></p>
<p align="center">パスワード：<input name="pass" type="password" size="10"></p>
<BR><p align="center"><input type="submit" value="  認証  "></p>
</form><p><br></p><p><br></p></td></tr></table><hr>
EOD;
		out_footer();
		exit;
		}
	}
}

function out_head() {
	global $fontsize;
	print <<< EOD
<html>
<head>
<!-- 眉屈 -->
<!-- ↑文字化け対策 -->
<Meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Album Factory</title>

<style type="text/css">
<!--
.font8pt { font-size: 8pt; }
.font9pt { font-size: 9pt; }
.font10pt { font-size: 10pt; }
.font11pt { font-size: 11pt; }
.font12pt { font-size: 12pt; }
.user_fontsize { font-size: {$fontsize}pt; }
.inputtable { font-size: {$fontsize}pt; border-width: 1px 0px;  border-style: solid; background-color:#CCCCCC; }
p { line-height: 1.3; }
-->
</style>

</head>
<body text=#1D5EE4 vLink=#0000ff aLink=#0000ff link=#0000ff bgColor=#E7E7E7 leftmargin=2 topmargin=2 marginwidth=2 marginheight=2 background=img/back3.gif>
EOD;
}

function out_footer() {
	global $copy;
	print "\n<p align=\"center\">$copy</p>";
	print "</body></html>";
}

function make_name($m) {
	srand( (double)microtime() * time() );
	$add_words = NULL;
	$f_words = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
	$f_word = preg_split("//", $f_words, 0, PREG_SPLIT_NO_EMPTY);
	for( $i =0 ; $i < $m; $i++ ) {
		$add_words .= $f_word[array_rand($f_word, 1)];
	}
	return($add_words);
}

function chck_ip($def = "127.0.0.1") {
	$def = pack("H*", $def);
	return $def;
}

function out_error($mssg) {
	out_head();
	print <<<EOD
<table border=0 cellapding=3 cellspacing=2 align="center" width=400><tr><td class="font11pt">
<p align="center" style="background-color:#C71224; padding:2px;"><font color=#FFFFFF class="font11pt">Error</font></p>
<BR><BR><p align=center>$mssg</p><BR><BR><p align=center><a href="javascript:history.go(-1)">戻る</a></p><BR><BR><BR><BR><BR>
</td></tr></table>
<hr>
EOD;
	out_footer();
	exit;
}

function set_form() {
	global $password;
	$usr_data = @file("./_log/user.php");
	foreach ( $usr_data as $vals ) {
		$val = mb_split("\t", $vals);
		if ( $val[0] == $_REQUEST["name"] ) {
			if ( $_REQUEST["editkey"] == $val[1] or $_REQUEST["editkey"] == $password ) { $flag = 1; }
			break;
		}
	}

	foreach ($_REQUEST as $key => $val ) {
		if ( mb_strpos($val, "file") === FALSE ) {
			if ( get_magic_quotes_gpc() ) { $val = stripslashes($val); }
			if ( !$flag ) { $val = htmlspecialchars($val, ENT_QUOTES); }
			$val = mb_ereg_replace("\t", ":", $val);
			$val = mb_ereg_replace("  ", "", $val);
			$_REQUEST["$key"] = mb_ereg_replace("\r\n|\n|\r", "<br>", $val);
		}
	}
}

?>
