<?php
/* ---------- ---------- ---------- ---------- *
                  Album Factory                
                                               
         利用規約を守ってご利用下さい。        
  http://www.coolandcool.net/pcg/notice.html   
                                               
          by CoolandCool (www.coolandcool.net) 
* ---------- ---------- ---------- ---------- */
mb_internal_encoding("SJIS");
mb_regex_encoding("SJIS");
include("setup.php");
require("exifReader.inc");


# FTPアクセスパスの設定。AlbumFactoryを設置した絶対パス（サーバーのルートフォルダからのパス）を「ftp://」から記述する。サイトのルートフォルダからではなく、サーバーのルートフォルダからのパスを書く必要があるので注意。

$ftp_path = "ftp://*****.net/www/af/";





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

if ( !$_REQUEST["id"] ) {
	
	$str = ereg_replace("ftp://", "ftp://username:password\@", $ftp_path);
	
	$_REQUEST["id"] = $_REQUEST["idd"];
	out_head();
	print <<< EOD

	<form name="input" action="auto.php" method="post">
<br><p align=center class="user_fontsize"><b>+ 画像自動投稿 +</b><br>
	<font size=2>* <a href="{$str}auto/" target=_blank>autoフォルダ</a>に入れた画像を、指定のアルバムにアップロードします。</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=60>名前/<br>撮影者</td>
    <td><input name="name" type="text" size="20" value="{$cookie_data[0]}"></td>
    <td align="center" class="user_fontsize" width=60>メール</td>
    <td><input name="email" type="text" size="25" value="{$cookie_data[1]}"></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize" width=60>修正キー</td>
    <td><input name="editkey" type="password" size="10" value="{$cookie_data[2]}"></td>
    <td align="center" class="user_fontsize" width=60>URL</td>
    <td><input name="url" type="text" size="25" value="{$cookie_data[3]}"></td>
  </tr>
  <tr>
    <td align="center" class="user_fontsize" width=60>カテゴリ</td><td>
      <select name="cat">
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><td align=\"center\" class=\"user_fontsize\">アルバム</td><td><input name=\"id\" type=\"text\" size=\"3\" value=\"{$_REQUEST["idd"]}\"></td></tr>";
	
	# 色選択表示
	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\" 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>";
	}
	print "</table>\n<BR><BR><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;
}

if ( $_REQUEST["editkey"] ) {
	$cookie_data = "{$_REQUEST["name"]}<>{$_REQUEST["email"]}<>{$_REQUEST["editkey"]}<>{$_REQUEST["url"]}<>{$_REQUEST["color"]}<>";
	setcookie("coolalbum", $cookie_data, time() + 30*24*60*60);
	$cookie_data = array();
	$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"];
} else {
	$cookie_data = mb_split( "<>", $_COOKIE["coolalbum"] );
	}
	
$config = @file("_log/config.php");
array_shift($config);
array_pop($config);
foreach ( $config as $val ) {
	$confg_val = mb_split("\t", $val);
	if ( $_REQUEST["id"] == $confg_val[0] ) { break; }
}
if ( !$confg_val[1] ) { $confg_val[1] = "{$img_dir}/title_b.jpg"; }


$usr_data = @file("./_log/user.php");
foreach ( $usr_data as $vals ) {
	$val = mb_split("\t", $vals);
	if ( $val[0] == $cookie_data[0] ) { break; }
}

if ( !$cookie_data[2] ) { out_error("修正キーが見えません。"); }
if ( $cookie_data[2] != $val[1] and $cookie_data[2] != $password) { out_error("修正キーが違います。"); }


$flag = 0;
$vals = mb_split(",", $val[2]);
if ( $val[0] != "all" ) {
	foreach ( $vals as $allowid ) {
		if ( $_REQUEST["id"] == $allowid ) { $flag = 1; }
	}
} else { $flag = 1; }

if ( !$flag ) { out_error("知らない人はダメヨ！"); }


if ( !$_REQUEST["num"] ) {
	
	$dir = dir("./auto/");
	while( $file = $dir -> read() ) {
		if ( eregi("([^\.]+)\.jpg", $file) ) { $dirname[] = $file; }
	}
	$dir->close();
	
	$autof = @fopen("./_log/auto.php", "a");
	flock($autof, LOCK_EX);
	ftruncate($autof, 0);
	foreach ( $dirname as $val ) {
		fputs($autof, "$val\n");
	}
	flock($autof, LOCK_UN);
	fclose($autof);
	$num = 0;
} else { 
	$dirname = @file("_log/auto.php");
	$num = $_REQUEST["num"];
}


	$all = count($dirname);
	
	$auto_value = rtrim($dirname[$num]);
	if ( !$auto_value ) {
	
	$dir = dir("./auto/");
	while( $file = $dir -> read() ) {
		if ( eregi("([^\.]+)\.jpg", $file) ) { unlink("auto/{$file}"); }
	}
	$dir->close();
	header("Location: ./album.php?id={$_REQUEST["id"]}");
	}

	if ( !$cookie_data[4] ) { $cookie_data[4] = $color[0]; }
	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[22] ) { $i_width  = $confg_val[22]; }
	if ( $confg_val[23] ) { $i_height = $confg_val[23]; }
			
			
			$a_file = "./auto/$auto_value";
			
			$er = new phpExifReader($a_file);
			$er->Debugging = 1;
			$Exif = $er->getImageInfo();
			
			## 追加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 = $a_file;
			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", 80);
				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 {
				copy($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"]}\t{$cookie_data[0]}\t{$cookie_data[1]}\t{$cookie_data[3]}\t{$_REQUEST["comment"]}\t{$picdate}\t{$cookie_data[4]}\t{$new_width}\t{$new_height}\t{$or_width}\t{$or_height}\t{$_REQUEST["cat"]}\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"]}\t{$cookie_data[0]}\t{$cookie_data[1]}\t{$cookie_data[2]}\t{$cookie_data[3]}\t{$_REQUEST["comment"]}\t{$cookie_data[4]}\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"]}\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
			sleep(1);
	

	$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);
	
	$num++;
	
	print <<<EOD
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="1;URL=auto.php?id={$_REQUEST["id"]}&mode=auto&num={$num}&cat={$_REQUEST["cat"]}">
<title>AlbumFactory 自動画像アップロード</title>
</head><body bgcolor=#000000 text = #FFFFFF>
<BR><BR><BR><BR><center>更新中… ({$num}/{$all})<BR><BR>このウインドウを閉じないで下さい。</center>
</body></html>
EOD;
exit;


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 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">ヤバイ！！</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 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; }
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>";
}

?>