<?
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_common.php";      // shoptopmenu, leftmenu

function mkShopHistory(&$document, &$script, &$init, $usid) {
	global $PSYCHEID;

	$pmtypearray = array(
		"B" => "¹«ÅëÀåÀÔ±Ý",
		"C" => "½Å¿ëÄ«µå"
	);

	$sastatarray = array(
		"O" => "ÀÔ±ÝÈ®ÀÎÁß",
		"C" => "¹è¼ÛÁØºñÁß",
		"G" => "¹è¼ÛÁß",
		"F" => "¹è¼Û¿Ï·á",
		"X" => "Ãë¼Ò"
	);

# sastat: O ÁÖ¹®Á¢¼ö, C ½ÂÀÎ,
#         G ¹è¼ÛÁß(ÅÃ¹è ½Ã½ºÅÛ°ú ¿¬°èµÇ¸é È°¿ë),
#         F ¹è¼Û¿Ï·á, X Ãë¼Ò

	if (!$usid) $usid = $PSYCHEID;

	$result = mysql_query("select sg.said, gd.gdname
from sales as sa
left join sagoods as sg on sa.said = sg.said
left join goods as gd on sg.gdid = gd.gdid
where sa.usid = '$usid'
order by gd.gdprice3 desc");	// shopepay.php sendSMS()

	$gdnamearray = array();

	while (list($sai, $gdn) = mysql_fetch_row($result)) {
		$gdnamearray[$sai][] = $gdn;
	}

	$result = mysql_query("select
sa.said, sa.sadate, sa.sasum, sa.sastat, pm.pmname, pm.pmtype
from sales as sa
left join paymethods as pm on sa.pmid = pm.pmid
where sa.usid = '$usid'
order by sa.sadate desc, sa.said desc");

	$shophistorylist = "";

	$nosa = mysql_num_rows($result);

	if ($nosa) {
		while (
			list($sai, $sad, $sasm, $sast, $pmn, $pmtp)
			= mysql_fetch_row($result)
		) {
			$sogdna = sizeof($gdnamearray[$sai]);

			if ($sogdna > 1) {
				$gdnamestring
				= getShortString($gdnamearray[$sai][0], 20) .
				" ¿Ü " . ($sogdna-1) . "Á¾";
			} else {
				$gdnamestring
				= getShortString($gdnamearray[$sai][0], 28);
			}

			$sasmc = number_format($sasm);

			$shophistorylist .= <<<EOS
              <tr> 
                <td width="113" height="30" align="center" bgcolor="F3F3F3">$sad</td>
                <td width="216" align="center" bgcolor="F3F3F3"><a href="shoprecord.php?said=$sai" style="color: #1B7778;">$gdnamestring</a></td>
                <td width="100" align="center" bgcolor="F3F3F3">{$sasmc}¿ø</td>
                <td width="80" align="center" bgcolor="F3F3F3" >{$pmtypearray[$pmtp]}</td>
                <td width="91" align="center" bgcolor="F3F3F3"><font color="F37006">{$sastatarray[$sast]}</font></td>
              </tr>
EOS;
		}
	} else {
		$shophistorylist = <<<EOS
<tr>
<td height="60" align="center" bgcolor="F3F3F3">ÁÖ¹®/¹è¼Û ³»¿ªÀÌ ¾ø½À´Ï´Ù.</td>
</tr>

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; ÁÖ¹®¹è¼Û³»¿ª</font></td>
              </tr>
            </table>
            <table width="623" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="99"><img src="/shop/images/orderlist_t.gif" width="623" height="99"></td>
              </tr>
            </table>
            
            <br>
            <table width="600" border="0" cellspacing="0" cellpadding="5">
              <tr> 
                <td align="right" valign="bottom" ><img src="/shop/images/arrow_01.gif" align="absmiddle"> 
                  ÃÑ ÁÖ¹® °Ç¼ö <b>{$nosa}°Ç</b></td>
              </tr>
            </table> 
            <table width="600" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="5" bgcolor="54AEAF"></td>
              </tr>
              <tr> 
                <td height="2"></td>
              </tr>
            </table>
            <table width="600" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="15"><img src="/community/images/boxleft.gif" width="15" height="35"></td>
                <td width="570" background="/community/images/boxpat.gif"><table width="570" border="0" cellspacing="0" cellpadding="0">
<tr> 
                      <td width="103" align="center"><img src="/shop/images/orderlist_01.gif" width="44" height="12"></td>
                      <td width="1"><img src="/shop/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="224" align="center"><img src="/shop/images/orderlist_02.gif" width="53" height="12"></td>
                      <td width="1"><img src="/shop/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="103" align="center"><img src="/shop/images/orderlist_03.gif" width="43" height="12"></td>
                      <td width="1"><img src="/shop/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="83" align="center"><img src="/shop/images/orderlist_04.gif" width="43" height="12"></td>
                      <td width="1"><img src="/shop/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="73" align="center"><img src="/shop/images/orderlist_05.gif" width="43" height="12"></td>
					  
                    </tr>
                  </table></td>
                <td width="15"><img src="/community/images/boxright.gif" width="15" height="35"></td>
              </tr>
            </table>
            <table width="600" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="10"></td>
              </tr>
            </table>
            <table width="600" border="0" cellspacing="0" cellpadding="3">
<!-- ÁÖ¹®/¹è¼Û ³»¿ª ½ÃÀÛ -->

$shophistorylist

<!-- ÁÖ¹®/¹è¼Û ³»¿ª ³¡ -->
            </table>
           
            <br>
            <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;
}

## Start

if (!$PSYCHEID) {
	header("Location: https://www.prosigner.com/member/signin.php?from=$ReqURI");

	return;
}

mkShopHistory($document, $script, $init, $usid);

require "shop_template.php";
?>
