#!/usr/bin/perl

require '../cgi-bin/cgi-lib.pl';
require '../cgi-bin/jcode.pl';
require '../cgi-bin/stdio.pl';
&decode;

#methodの方式
$method = "POST";

#このスクリプト名
$script = "hp_plan-shousai.cgi";

#特別企画用データの格納先
$top_data = "../cgi-bin/data/special.csv";

#画像ファイルの置き場所
$imgpath = "../cgi-bin/img_sp/";

#画像の最大サイズ
$MaxW = 230;
$MaxH = 173;

@list = ();
$i = 0;
open IN,"$top_data" or die &error("$top_dataが開けません");
while(<IN>){
	$list[$i] = $_;
	$i++;
}
close IN;

@data = split(/,/,$list[$in{'no'}]);
if(!$data[0]){ &error("不正なアクセスです<br>データが存在しません"); }

$picture2 = "$imgpath$data[12]";
	($type,$width,$height) = stdio::getImageSize($picture2);
	# 画像表示縮小
	if ($width > $MaxW || $height > $MaxH) {
		$W2 = $MaxW / $width;
		$H2 = $MaxH / $height;
		if ($W2 < $H2) { $key = $W2; }
		else { $key = $H2; }
		$width = int ($width * $key) || 1;
		$height = int ($height * $key) || 1;
	}

$picture3 = "$imgpath$data[13]";
	($type3,$width3,$height3) = stdio::getImageSize($picture3);
	# 画像表示縮小
	if ($width3 > $MaxW || $height3 > $MaxH) {
		$W2 = $MaxW / $width3;
		$H2 = $MaxH / $height3;
		if ($W2 < $H2) { $key = $W2; }
		else { $key = $H2; }
		$width3 = int ($width3 * $key) || 1;
		$height3 = int ($height3 * $key) || 1;
	}

$picture4 = "$imgpath$data[14]";
	($type4,$width4,$height4) = stdio::getImageSize($picture4);
	# 画像表示縮小
	if ($width4 > $MaxW || $height4 > $MaxH) {
		$W2 = $MaxW / $width4;
		$H2 = $MaxH / $height4;
		if ($W2 < $H2) { $key = $W2; }
		else { $key = $H2; }
		$width4 = int ($width4 * $key) || 1;
		$height4 = int ($height4 * $key) || 1;
	}

&header;

print <<"EOH";
<table width="750" border="0" cellspacing="0" cellpadding="0" align="center" height="100%">
  <tr> 
    <td bgcolor="#666666" width="1" rowspan="2"><img src="../common_img/spacer.gif" width="1" height="1"></td>
    <td bgcolor="#FFFFFF" valign="top"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td><!-- #BeginLibraryItem "/Library/menu.lbi" --><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="748">
<!-- fwtable fwsrc="menu.png" fwbase="menu.gif" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="1" -->
  <tr>
   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="748">
	  <tr>
	   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="10" height="81" border="0"></td>
	   <td><img name="menu_r1_c2" src="../menu/menu_r1_c2.gif" width="119" height="81" border="0"></td>
	   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="619">
		  <tr>
		   <td><img name="menu_r1_c3" src="../menu/menu_r1_c3.gif" width="619" height="5" border="0"></td>
		  </tr>
		  <tr>
		   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="619">
			  <tr>
			   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="41" height="76" border="0"></td>
			   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="463">
				  <tr>
				   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="463">
					  <tr>
					   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="230" height="23" border="0"></td>
					   <td><img name="menu_r2_c10" src="../menu/menu_r2_c10.gif" width="233" height="23" border="0"></td>
					  </tr>
					</table></td>
				  </tr>
				  <tr>
				   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="463" height="6" border="0"></td>
				  </tr>
				  <tr>
				   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="463">
					  <tr>
					   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="1" height="21" border="0"></td>
					              <td><a href="../auction/auction.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c5','','../menu/menu_r4_c5_f2.gif',1)" ><img name="menu_r4_c5" src="../menu/menu_r4_c5.gif" width="109" height="21" border="0"></a></td>
					              <td><a href="../buy/buy.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c6','','../menu/menu_r4_c6_f2.gif',1)" ><img name="menu_r4_c6" src="../menu/menu_r4_c6.gif" width="85" height="21" border="0"></a></td>
					              <td><a href="../sell/sell.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c8','','../menu/menu_r4_c8_f2.gif',1)" ><img name="menu_r4_c8" src="../menu/menu_r4_c8.gif" width="86" height="21" border="0"></a></td>
					              <td><a href="../newcar/newcar.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c11','','../menu/menu_r4_c11_f2.gif',1)" ><img name="menu_r4_c11" src="../menu/menu_r4_c11.gif" width="109" height="21" border="0"></a></td>
					              <td><a href="../topics/topics.cgi" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c13','','../menu/menu_r4_c13_f2.gif',1)" ><img name="menu_r4_c13" src="../menu/menu_r4_c13.gif" width="73" height="21" border="0"></a></td>
					  </tr>
					</table></td>
				  </tr>
				  <tr>
				   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="463" height="5" border="0"></td>
				  </tr>
				  <tr>
				   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="463">
					  <tr>
					              <td><a href="hp_plan.cgi" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r6_c4','','../menu/menu_r6_c4_f2.gif',1)" ><img name="menu_r6_c4" src="../menu/menu_r6_c4.gif" width="122" height="21" border="0"></a></td>
					              <td><a href="../estimate/estimate.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r6_c7','','../menu/menu_r6_c7_f2.gif',1)" ><img name="menu_r6_c7" src="../menu/menu_r6_c7.gif" width="101" height="21" border="0"></a></td>
					              <td><a href="../shop/shop.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r6_c9','','../menu/menu_r6_c9_f2.gif',1)" ><img name="menu_r6_c9" src="../menu/menu_r6_c9.gif" width="82" height="21" border="0"></a></td>
					   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="158" height="21" border="0"></td>
					  </tr>
					</table></td>
				  </tr>
				</table></td>
			   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="36" height="76" border="0"></td>
			   <td><table bgcolor="#2f82ff" border="0" cellpadding="0" cellspacing="0" width="73">
				  <tr>
				   <td><img name="menu_r2_c15" src="../menu/menu_r2_c15.gif" width="73" height="23" border="0"></td>
				  </tr>
				  <tr>
				   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="73" height="6" border="0"></td>
				  </tr>
				  <tr>
				            <td><a href="../index.html" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r4_c15','','../menu/menu_r4_c15_f2.gif',1)" ><img name="menu_r4_c15" src="../menu/menu_r4_c15.gif" width="73" height="21" border="0"></a></td>
				  </tr>
				  <tr>
				   <td bgcolor="#2f82ff"><img src="../menu/spacer.gif" width="73" height="5" border="0"></td>
				  </tr>
				  <tr>
				            <td><a href="mailto:info\@teim.co.jp?subject=HP%82%A9%82%E7%82%CC%82%A8%96%E2%8D%87%82%B9" onMouseOut="MM_swapImgRestore();"  onMouseOver="MM_swapImage('menu_r6_c15','','../menu/menu_r6_c15_f2.gif',1)" ><img name="menu_r6_c15" src="../menu/menu_r6_c15.gif" width="73" height="21" border="0"></a></td>
				  </tr>
				</table></td>
			   <td><img name="menu_r2_c16" src="../menu/menu_r2_c16.gif" width="6" height="76" border="0"></td>
			  </tr>
			</table></td>
		  </tr>
		</table></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
   <td><img name="menu_r7_c1" src="../menu/menu_r7_c1.gif" width="748" height="11" border="0"></td>
  </tr>
</table><!-- #EndLibraryItem --></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
        <tr> 
          <td height="26"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="29%"><img src="../common_img/spacer.gif" width="25" height="16"><img src="img/title.gif"></td>
                <td width="71%" class="main">毎月ティムから限定数台の車をご奉仕中!!</td>
              </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td valign="top"> 
            <table width="75%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#F5F7DF">
              <tr> 
                <td width="6" height="3"><img src="../common_img/waku/orange_tl.gif" width="6" height="3"></td>
                <td background="../common_img/waku/orange_tm.gif" colspan="5" height="3"><img src="../common_img/waku/orange_tm.gif" width="6" height="3"></td>
                <td width="6" height="3"><img src="../common_img/waku/orange_tr.gif" width="6" height="3"></td>
              </tr>
              <tr> 
                <td width="6" background="../common_img/y_ml.gif" height="6"><img src="../common_img/spacer.gif" width="1" height="1"><img src="../common_img/spacer.gif" width="6" height="6"></td>
                <td bgcolor="#FBE2A2" height="6" class="topics_title" colspan="5"><img src="img/car.gif" width="19" height="9"><span class="car_title">$data[0]</span></td>
                <td width="6" background="../common_img/y_mr.gif" height="6"><img src="../common_img/spacer.gif" width="1" height="1"><img src="../common_img/spacer.gif" width="6" height="6"></td>
              </tr>
              <tr> 
                <td width="6" height="3"><img src="../common_img/waku/orange_bl.gif" width="6" height="3"></td>
                <td background="../common_img/y_bm.gif" colspan="5" height="3"><img src="../common_img/waku/orange_bm.gif" width="6" height="3"></td>
                <td width="6" height="3"><img src="../common_img/waku/orange_br.gif" width="6" height="3"></td>
              </tr>
              <tr> 
                <td width="6" rowspan="4" background="../common_img/wy_ml.gif"><img src="../common_img/spacer.gif" width="6" height="6"></td>
                <td bgcolor="#F5F7DF" height="2" align="center" valign="middle" colspan="5"><img src="../common_img/spacer.gif" width="5" height="3"></td>
                <td width="6" rowspan="4" background="../common_img/wy_mr.gif" bgcolor="#F6F6F6">　</td>
              </tr>
              <tr> 
                <td bgcolor="#F5F7DF" class="main" height="172" align="center" valign="middle" width="232"> 
                  <table width="100" border="0" cellspacing="0" cellpadding="1" bgcolor="#333333">
                    <tr> 
                      <td valign="middle"><a href="javascript:newwindow('$picture2')"><img src="$picture2" width="$width" height="$height" border="0"></a></td>
                    </tr>
                  </table>
                </td>
                <td bgcolor="#F5F7DF" class="main" height="1" align="center" valign="middle" width="5" rowspan="2"><img src="../common_img/spacer.gif" width="5" height="10"></td>
                <td bgcolor="#F5F7DF" height="172" valign="middle" width="239"> 
                  <table width="100" border="0" cellspacing="0" cellpadding="1" bgcolor="#333333">
                    <tr> 
                      <td valign="middle"><a href="javascript:newwindow('$picture3')"><img src="$picture3" width="$width3" height="$height3" border="0"></a></td>
                    </tr>
                  </table>
                </td>
                <td bgcolor="#F5F7DF" height="172" valign="top" width="5"><img src="../common_img/spacer.gif" width="5" height="5"> 
                </td>
                <td bgcolor="#F5F7DF" height="172" valign="middle" width="33"> 
                  <table width="100" border="0" cellspacing="0" cellpadding="1" bgcolor="#333333">
                    <tr> 
                      <td valign="middle"><a href="javascript:newwindow('$picture4')"><img src="$picture4" width="$width4" height="$height4" border="0"></a></td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr> 
                <td bgcolor="#F5F7DF" class="main" height="2" align="center" valign="middle" width="232"><img src="../common_img/spacer.gif" width="5" height="5"></td>
                <td bgcolor="#F5F7DF" class="main" valign="top" colspan="3" height="2"><img src="../common_img/spacer.gif" width="5" height="5"></td>
              </tr>
              <tr> 
                <td bgcolor="#F5F7DF" class="main" height="1" align="center" valign="middle">
                  <div align="left"><a href="javascript:history.back()">←前の画面に戻る</a></div>
                </td>
                <td bgcolor="#F5F7DF" class="main" height="1" align="center" valign="middle">　</td>
                <td bgcolor="#F5F7DF" class="main" height="1" align="center" valign="middle" colspan="3"> 
                  <div align="right" class="price">$data[1]万円</div>
                </td>
              </tr>
              <tr> 
                <td width="6" height="6"><img src="../common_img/wy_bl.gif" width="6" height="6"></td>
                <td background="../common_img/wy_bm.gif" colspan="5"><img src="../common_img/spacer.gif" width="6" height="6"></td>
                <td width="6" height="6"><img src="../common_img/wy_br.gif" width="6" height="6"></td>
              </tr>
            </table>
            
          </td>
        </tr>
      </table>
    </td>
    <td bgcolor="#666666" width="1" rowspan="2"><img src="../common_img/spacer.gif" width="1" height="1"></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" valign="top"><!-- #BeginLibraryItem "/Library/copy.lbi" --><img name="index_r14_c1" src="../index_img/index_r14_c1.gif" width="748" height="18" border="0"><!-- #EndLibraryItem --></td>
  </tr>
</table>
</body>
</html>
EOH

exit;

###################################################################
# ヘッダー [ &header ]
###################################################################
sub header {

print "Content-type: text/html\n\n";
print <<"EOH";
<html>
<head>
<title>TEIM ：ホームページ特別企画</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<link rel="stylesheet" href="../teim.css" type="text/css">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function newwindow(a) {
	nwin = window.open("", "Newwindow","toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1");
	nwin.document.open();
	nwin.document.write("<HTML><HEAD>");
	nwin.document.write("<TITLE>TEIM：画像表\示</TITLE>");
	nwin.document.write("<BODY>");
	nwin.document.write("<IMG SRC="+a+">"); 
	nwin.document.write("</BODY></HTML>");
	nwin.document.close();
}

//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="../common_img/bg.gif" onLoad="MM_preloadImages('../menu/menu_r4_c5_f2.gif','../menu/menu_r4_c6_f2.gif','../menu/menu_r4_c8_f2.gif','../menu/menu_r4_c11_f2.gif','../menu/menu_r4_c13_f2.gif','../menu/menu_r6_c4_f2.gif','../menu/menu_r6_c7_f2.gif','../menu/menu_r6_c9_f2.gif','../menu/menu_r4_c15_f2.gif')">
EOH

}

###########################################################
# エラー処理 [ &error ]
###########################################################
sub error{

	if ($lockflag) { &unlock; }

	print "Content-type: text/html\n\n";
	print "<HTML><HEAD><TITLE>ERROR</TITLE></HEAD>\n";
	print "<BODY bgcolor=\"#FFFFFF\"><br><br>\n";
	print "<center><b><font color=\"#FF0000\">ERROR!!</font></b><br>\n";
	print "<H4>$_[0]</H4><HR color=\"#CCCCCC\"><br><br>\n";
if($_[1] eq "1"){
	print "<input type=\"button\" value=\"閉じる\" onClick=\"window.close()\"></center></BODY></HTML>\n";
}else{
	print "<input type=\"button\" value=\"戻る\" onClick=\"history.back()\"></center></BODY></HTML>\n";
}
	exit;
}

#----------------#
#  デコード処理  #
#----------------#
sub decode {
	&ReadParse;
	while (($key,$val) = each %in) {
		if ($key ne "upfile") {
			# シフトJISコードに変換
			&jcode'convert(*val, "sjis", "", "z");
			
#			$val =~ s/\://g;
			$val =~ s/\,//g;
			
			# タグ処理
			$val =~ s/&/&amp;/g;
			$val =~ s/"/&quot;/g;
#			$val =~ s/</&lt;/g;
#			$val =~ s/>/&gt;/g;

			# 改行処理
			if ($key eq "comment") {
				$val =~ s/\r\n/<BR>/g;
				$val =~ s/\r/<BR>/g;
				$val =~ s/\n/<BR>/g;
			}
#			 else {
#				$val =~ s/\r//g;
#				$val =~ s/\n//g;
#			}
		}
		$in{$key} = $val;
	}
	$mode = $in{'mode'};
	$page = $in{'page'};
	$in{'url'} =~ s/^http\:\/\///;
	if ($in{'sub'} eq "") { $in{'sub'} = "無題"; }

	# 日時の取得
	$ENV{'TZ'} = "JST-9";
	$times = time;
	($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime($times));
	$year = $year + 1900;
	$mon++;
	if ($mon  < 10) { $mon  = "0$mon";  }
	if ($mday < 10) { $mday = "0$mday"; }
	if ($hour < 10) { $hour = "0$hour"; }
	if ($min  < 10) { $min  = "0$min";  }
	if ($sec  < 10) { $sec  = "0$sec";  }

	# 日時のフォーマット
	@week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	$date = sprintf("%04d/%02d/%02d(%s) %02d:%02d",
			$year,$mon,$mday,$week[$wday],$hour,$min);
	$date1 = "$year$mon$mday$hour$min$sec";
	$date2 = "$year/$mon/$mday";
}


#--------------#
#  ロック処理  #
#--------------#
sub lock {
	# 1分以上古いロックは削除する
	if (-e $lockfile) {
		local($mtime) = (stat($lockfile))[9];
		if ($mtime < time - 60) { &unlock; }
	}
	local($retry) = 5;
	# symlink関数式ロック
	if ($lockkey == 1) {
		while (!symlink(".", $lockfile)) {
			if (--$retry <= 0) { &error('LOCK is BUSY'); }
			sleep(1);
		}
	# mkdir関数式ロック
	} elsif ($lockkey == 2) {
		while (!mkdir($lockfile, 0755)) {
			if (--$retry <= 0) { &error('LOCK is BUSY'); }
			sleep(1);
		}
	}
	$lockflag=1;
}

#--------------#
#  ロック解除  #
#--------------#
sub unlock {
	if ($lockkey == 1) { unlink($lockfile); }
	elsif ($lockkey == 2) { rmdir($lockfile); }
	$lockflag=0;
}

###########################################################
# エラー探し [ &info ]
###########################################################
sub info {

	print "Content-type: text/html\n\n";
	print"<HTML>\n";
	print"<HEAD>\n";
	print"<TITLE></TITLE>\n";
	print"</HEAD>\n";
	print"<BODY>\n";
	print"<p align=\"center\">$_[0]</p>\n";
	print"</BODY>\n";
	print"</HTML>\n";
	exit;
}