<?
session_start();

$document = array();
$script = "";
$init = "";

require "../lib/getnpost.php";
require "../lib/config.php";
require "../lib/dbconnect.php";
require "../lib/auth.php";
require "../lib/common.php";

require "shop_config.php";	// $stnamearray
require "shop_common.php";      // shoptopmenu, leftmenu

function CheckGDID($gdid){
	global $DBCONNECT;

	// ¸ÕÀú gdid°¡ ÀÖ´Â Áö °Ë»ç
	$sql="select count(*) from goods where gdid='$gdid'";
	$res=mysql_result(mysql_query($sql,$DBCONNECT),0);
	if ($res==0):
		echo "<script language=\"javascript\">window.alert('Á¸ÀçÇÏÁö ¾Ê´Â ¾ÆÀÌµðÀÔ´Ï´Ù.');history.go(-1);</script>";
	else:
		$sql="select gdvisible from goods where gdid='$gdid'";
		$res=mysql_result(mysql_query($sql,$DBCONNECT),0);
		if ($res=="N"):
			echo "<script language=\"javascript\">window.alert('ÆÇ¸ÅÇÏÁö ¾Ê´Â »óÇ°ÀÔ´Ï´Ù.');document.location.href='http://www.prosigner.com/shop/shopmain.php';</script>";
		endif;
	endif;

} // gdid¸¦ °Ë»çÇØ¼­ »ç¿ëÁßÀÌÁö ¾ÊÀ¸¸é °æ°íÃ¢ Ãâ·Â ÈÄ ¸ÞÀÎ È­¸éÀ¸·Î ÀÌµ¿ÇÏ°Ô ÇÏ´Â ÇÔ¼ö

CheckGDID($gdid);

function mkShopView(&$document, &$script, &$init, $gdid, $gdcat, $page, $stnum) {
	global $PsycheAdmin;
	global $SHOP_GIMGURI, $SHOP_GIMGDEFAULT, $LOG_SHOP;
	global $gdcatarray, $stnamearray;

	$result = mysql_query("select
gdname, gdtype, gdprice1, gdprice2, gdprice3, gdprice4,
gdimage1, gdimage2, gdimage2x, gdimage2y, gdweight, gdseq,
gdnew, gdrecomm, gdevent, gdpopular, gdmaker,
gdtime, gdbonus, gdstat, gdvisible
from goods
where gdid = '$gdid'");

	list(
		$gdname, $gdtype, $gdprice1, $gdprice2, $gdprice3, $gdprice4,
		$gdimage1, $gdimage2, $gdimage2x, $gdimage2y, $gdweight, $gdseq,
		$gdnew, $gdrecomm, $gdevent, $gdpopular, $gdmaker,
		$gdtime, $gdbonus, $gdstat, $gdvisible
	) = mysql_fetch_row($result);

	if (false) {
		$gdprice = $gdprice1;
	} elseif (false) {
		$gdprice = $gdprice2;
	} elseif (true) {
		$gdprice = $gdprice3;
	} else {
		$gdprice = $gdprice4;
	}

	$sgqty = 1;
	$sgsum = $gdprice;

	$gdpricec = number_format($gdprice) . "¿ø";
	$sgsumc = number_format($sgsum);

	$gdweight = number_format($gdweight, 2) . "kg";
	$gdbonusc = number_format($gdbonus) . "¿ø";

	if ($gdimage2) {
		$gdimage2uri = $SHOP_GIMGURI . "/" . $gdimage2;
	} elseif ($gdimage1) {
		$gdimage2uri = $SHOP_GIMGURI . "/" . $gdimage1;
	} else {
		$gdimage2uri = $SHOP_GIMGURI . "/" . $SHOP_GIMGDEFAULT;
	}

	$result = mysql_query("select goid, goname
from gdoptions
where gdid = '$gdid'
order by goname");

	if (mysql_num_rows($result)) {
		$gdoptionrow = <<<EOS
                    <tr> 
                      <td align="center" valign="top" style="padding: 3px;"><img src="/shop/images/st_06.gif" width="70" height="21"></td>
                      <td style="padding: 3px;">
<select id="goid" name="goid">

EOS;

		while (list($goi, $gon) = mysql_fetch_row($result)) {
			$gdoptionrow .= <<<EOS
<option value="$goi">$gon</option>

EOS;
		}

		$gdoptionrow .= <<<EOS
</select>
                      </td>
                    </tr>
                    <tr> 
                      <td height="1" colspan="2" bgcolor="E3E4E3"></td>
                    </tr>

EOS;
	} else {
		$gdoptionrow = "";
	}

	$sgqtyselectstring = <<<EOS
<select id="sgqty" name="sgqty" style="width: 38px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

EOS;

	if ($PsycheAdmin) {
		$shopadminstring = <<<EOS
<br />
<input type="button" value="»óÇ° Á¤º¸ ¼öÁ¤" style="width: 120px;"
 onclick="modShop()">

EOS;

		$script .= <<<EOS
function modShop() {
	open("/admin/shopmod.php?gdid=$gdid", "ShopMod", "width=550,height=600,status=yes,scrollbars=yes");
}

EOS;
	} else {
		$shopadminstring = "";
	}

	if (!$gdcat) $gdcat = "0";

	$gdcatstring = <<<EOS
<a href="shoplist.php?gdcat=$gdcat&page=$page" style="color: #00355E;">{$gdcatarray[$gdcat][0]}</a>

EOS;

	if (!$stnum) $stnum = 1;

	$sttabarray = array(
		1 => array("tap_01.gif", "tap_011.gif"),
		2 => array("tap_02.gif", "tap_021.gif"),
		3 => array("tap_03.gif", "tap_031.gif"),
		4 => array("tap_04.gif", "tap_041.gif")
	);

	for ($i = 1; $i <= 4; $i++) {
		if ($i == $stnum) {
			$sttabimgstring[$i] = <<<EOS
<img src="/shop/images/{$sttabarray[$i][1]}" width="99" height="24" border="0">
EOS;
		} else {
			$sttabimgstring[$i] = <<<EOS
<img src="/shop/images/{$sttabarray[$i][0]}" width="99" height="24" border="0">
EOS;
		}
	}

	$document['main'] .= <<<EOS
      <table width="938" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="160" valign="top" background="/shop/images/left_pat.gif">
            <img src="/shop/images/left_pat.gif" width="160" />
            <!--shop leftamenu//------------>

            {$document['leftmenu']}

            <!--//shop leftamenu------------>
          </td>
          <td width="623" height="673" align="center" valign="top">
            <table width="623" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="69" height="26" align="center" background="/shop/images/mall_locationbar_title_bg.gif"><img src="/shop/images/mall_locationbar_title.gif"></td>
                <td width="434" background="/shop/images/mall_locationbar_title_bg.gif"><font color="00355E"><a href="/" style="color: #00355E;">È¨</a> &gt; <a href="/shop/shopmain.php" style="color: #00355E;">¼îÇÎ¸ô</a> &gt; $gdcatstring</font></td>
              </tr>
            </table>
            <table width="623" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td><img src="/shop/images/{$gdcatarray[$gdcat][2]}" width="623" height="71"></td>
              </tr>
            </table>
<a name="st"></a>
            <table width="623" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="17" background="/shop/images/display_start.gif">&nbsp;</td>
              </tr>
            </table> 
<form id="spvform" action="{$_SERVER['PHP_SELF']}" method="post">
            <table width="580" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="320" valign="top"> 
                  <table width="320" border="0" cellpadding="0" cellspacing="5" bgcolor="EDEDED">
                    <tr>
                      <!-- height="280" -->
                      <td height="200" align="center">
<!--  height="280" -->
<table border="0" cellpadding="0" cellspacing="0" width="310" height="200" bgcolor="#FFFFFF">
<tr>
<td align="center">
<!-- /shop/images/blank_img.gif -->
<img src="$gdimage2uri" /></td>
</tr>
</table>
                        </td>
                    </tr>
                  </table>
                  <table width="320" border="0" cellspacing="0" cellpadding="3">
<tr>
                      <td align="right" valign="bottom"><!--<img src="/shop/images/b_zoom.gif" width="58" height="17">--></td>
                    </tr>
                  </table> </td>
                <td width="260" align="right" valign="top"><table width="250" border="0" cellspacing="0" cellpadding="0">
<tr> 
                      <td height="40"> <img src="/shop/images/ball.gif" width="11" height="11" align="absmiddle"> 
                        <span style="color: #2C6E40; font-size: 11pt; font-weight: bold;">$gdname</span></td>
                    </tr>
                    <tr bgcolor="E3E4E3"> 
                      <td height="3"></td>
                    </tr>
                  </table>
                  <table width="250" border="0" cellspacing="0" cellpadding="0">
<tr> 
                      <td width="85" align="center" style="padding: 3px;"><img src="/shop/images/st_04.gif" width="70" height="21"></td>
                      <td width="315" style="padding: 3px;">$gdmaker</td>
                    </tr>
                    <tr> 
                      <td height="1" colspan="2" bgcolor="E3E4E3"></td>
                    </tr>
                    <tr> 
                      <td align="center" style="padding: 3px;"><img src="/shop/images/st_01.gif" width="70" height="21"></td>
                      <td style="padding: 3px;">$gdpricec</td>
                    </tr>
                    <tr> 
                      <td height="1" colspan="2" bgcolor="E3E4E3"></td>
                    </tr>
                    <tr> 
                      <td align="center" valign="top" style="padding: 3px;"><img src="/shop/images/st_02.gif" width="70" height="21"></td>
                      <td style="padding: 3px;">$gdbonusc</td>
                    </tr>
                    <tr> 
                      <td height="1" colspan="2" bgcolor="E3E4E3"></td>
                    </tr>
$gdoptionrow
                    <tr> 
                      <td align="center" valign="top" style="padding: 3px;"><img src="/shop/images/st_05.gif" width="70" height="21"></td>
                      <td style="padding: 3px;">$sgqtyselectstring</td>
                    </tr>
                    <tr> 
                      <td height="1" colspan="2" bgcolor="E3E4E3"></td>
                    </tr>
                  </table>
                  <table width="250" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="10"></td>
                    </tr>
                  </table>
<!--
                  <table width="250" border="0" cellspacing="0" cellpadding="0">
                    <tr align="center"> 
                      <td><table width="45" border="0" cellpadding="0" cellspacing="1" bgcolor="D2D3D2">
                          <tr> 
                            <td height="43" align="center"><img src="/shop/images/blank_img.gif" width="43" height="43"></td>
                          </tr>
                        </table></td>
                      <td><table width="45" border="0" cellpadding="0" cellspacing="1" bgcolor="D2D3D2">
                          <tr> 
                            <td height="43" align="center"><img src="/shop/images/blank_img.gif" width="43" height="43"></td>
                          </tr>
                        </table></td>
                      <td><table width="45" border="0" cellpadding="0" cellspacing="1" bgcolor="D2D3D2">
                          <tr> 
                            <td height="43" align="center"><img src="/shop/images/blank_img.gif" width="43" height="43"></td>
                          </tr>
                        </table></td>
                      <td><table width="45" border="0" cellpadding="0" cellspacing="1" bgcolor="D2D3D2">
                          <tr> 
                            <td height="43" align="center"><img src="/shop/images/blank_img.gif" width="43" height="43"></td>
                          </tr>
                        </table></td>
                      <td><table width="45" border="0" cellpadding="0" cellspacing="1" bgcolor="D2D3D2">
                          <tr> 
                            <td height="43" align="center"><img src="/shop/images/blank_img.gif" width="43" height="43"></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table>
-->    

              <table width="250" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td height="10"></td>
                    </tr>
                  </table> 
                  <table width="250" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><a href="javascript:addCart()"><img src="/shop/images/b_cart01.gif" width="116" height="30" border="0"></a>
<!-- <img src="/shop/images/b_wishlist.gif" width="116" height="30" border="0"> --><br>
$shopadminstring
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
<input type="hidden" id="gdid" name="gdid" value="$gdid" />
</form>
            <br>
            <table width="623" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="23" background="/shop/images/tap_pat.gif">&nbsp;</td>
                <td width="105" align="center" background="/shop/images/tap_pat.gif"><a href="{$_SERVER['PHP_SELF']}?gdid=$gdid&gdcat=$gdcat&page=$page&stnum=1#st">{$sttabimgstring[1]}</a></td>
                <td width="105" align="center" background="/shop/images/tap_pat.gif"><a href="{$_SERVER['PHP_SELF']}?gdid=$gdid&gdcat=$gdcat&page=$page&stnum=2#st">{$sttabimgstring[2]}</a></td>
                <td width="105" align="center" background="/shop/images/tap_pat.gif"><a href="{$_SERVER['PHP_SELF']}?gdid=$gdid&gdcat=$gdcat&page=$page&stnum=3#st">{$sttabimgstring[3]}</a></td>
                <td width="105" align="center" background="/shop/images/tap_pat.gif"><a href="{$_SERVER['PHP_SELF']}?gdid=$gdid&gdcat=$gdcat&page=$page&stnum=4#st">{$sttabimgstring[4]}</a></td>
                <td width="180" background="/shop/images/tap_pat.gif">&nbsp;</td>
              </tr>
            </table> 
            <br>
            <table width="580" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center">
<!-- Shop Text -->
<table style="width: 580px; height: 350px;">
<tr>
<td style="vertical-align: top;">

EOS;

	if ($PsycheAdmin) {
		$document['main'] .= <<<EOS
<form>
<input type="button" value="³»¿ë ¼öÁ¤" style="width: 80px;"
 onclick="modShopText($stnum)">
</form>
<br />

EOS;

		$script .= <<<EOS
function modShopText(n) {
	open("/admin/shoptextmod.php?gdid=$gdid&stnum=" + n, "ShopTextMod", "width=500,height=450,status=yes");
}

EOS;
	}

	$result = mysql_query("select $stnamearray[$stnum] from
goods
where gdid = '$gdid'");

	list($shoptext) = mysql_fetch_row($result); 

	$document['main'] .= $shoptext;

	$document['main'] .= <<<EOS
</tr>
</td>
</table>

<!-- <iframe id="sptext" name="sptext" style="height: 350px; width: 580px;" scrolling="auto" border="0" frameborder="0" framespacing="0" marginheight="0" src="shoptext.php?gdid=$gdid&stnum=1"></iframe> -->
                </td>
              </tr>
            </table>
            <br>
          </td>
          <td width="155" align="right" valign="top" background="/shop/images/right_pat.gif" style="padding-right:5px;padding-top:8px">{$document['rightbanner']}</td>
        </tr>
      </table>

EOS;

	$script .= <<<EOS
function addCart() {
	sgqty_el = document.getElementById("sgqty");

	sgqty = parseInt(sgqty_el.options[sgqty_el.selectedIndex].value);

	window.location.href = "shopcartadd.php?gdid=$gdid&sgqty=" + sgqty;
}

EOS;

	logActivity(
		$LOG_SHOP,
		$gdid."\t".$_SERVER['REMOTE_ADDR']."\t".
		$_SESSION['PSYCHEID']."\t".$_SESSION['PSYCHENAME']."\t".
		$gdname
	);
}

# Start

if (!$gdid) {
	header("Location: .");

	return;
}

mkShopView($document, $script, $init, $gdid, $gdcat, $page, $stnum);

require "shop_template.php";
?>
