<?
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 "mypage_common.php";

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

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

	if ($usid != $PSYCHEID && !$PsycheAdmin) {
		header("Location: https://www.prosigner.com/member/signin.php");

		return;
        }

	$document['main'] = <<<EOS
            <table width="748" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td>&nbsp;</td>
              </tr>
            </table>
            <table width="748" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="412" height="55" background="/images/subtitlebox_pat.gif" style="padding-left:30px"><img src="/mypage/images/subtitle_03.gif" width="188" height="26"></td>
                <td width="336" background="/images/subtitlebox_pat.gif" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td height="30" align="right" style="padding-right:10px"><img src="/images/locationbar_title.gif" width="65" height="11" align="absmiddle"><font color="2F89C2">È¨ 
                        &gt; ³»Á¤º¸ &gt; ÁÖ¹®¹è¼Û³»¿ª</font></td>
                    </tr>
                  </table></td>
              </tr>
            </table> 
            <br>
            <table width="670" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td><img src="/mypage/images/caption_02.gif" width="477" height="65"></td>
              </tr>
            </table>
            <br>
            <table width="670" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="5" bgcolor="3EA5DA"></td>
              </tr>
              <tr> 
                <td height="2"></td>
              </tr>
            </table>
            <table width="670" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="15"><img src="/community/images/boxleft.gif" width="15" height="35"></td>
                <td width="640" background="/community/images/boxpat.gif"><table width="640" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td width="80" align="center"><img src="/mypage/images/t_date.gif" width="43" height="11"></td>
                      <td width="1"><img src="/helpdesk/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="266" align="center"><img src="/mypage/images/t_order.gif" width="53" height="11"></td>
                      <td width="1"><img src="/helpdesk/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="120" align="center"><img src="/mypage/images/t_money.gif" width="42" height="11"></td>
                      <td width="1"><img src="/helpdesk/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="80" align="center"><img src="/mypage/images/t_method.gif" width="42" height="11"></td>
                      <td width="1"><img src="/helpdesk/images/boxtitlebar.gif" width="1" height="15"></td>
                      <td width="90" align="center"><img src="/mypage/images/t_condition.gif" width="42" height="11"></td>
                    </tr>
                  </table></td>
                <td width="15"><img src="/community/images/boxright.gif" width="15" height="35"></td>
              </tr>
            </table>
            <table width="670" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="10">&nbsp;</td>
              </tr>
            </table>
            <table width="670" border="0" cellspacing="0" cellpadding="0">

EOS;

	$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");

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

	$nosa = mysql_num_rows($result);

	if ($nosa) {
		$count = 0;

		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);

			if ($count++ % 2) {
				$bgcolor = "";
			} else {
				$bgcolor = "F3F3F3";
			}

			$document['main'] .= <<<EOS
              <tr> 
                <td width="104" height="25" align="center" bgcolor="$bgcolor">$sad</td>
                <td width="258" align="center" bgcolor="$bgcolor"><a href="/shop/shoprecord.php?said=$sai">$gdnamestring</a></td>
                <td width="120" align="center" bgcolor="$bgcolor">{$sasmc}¿ø</td>
                <td width="83" align="center" bgcolor="$bgcolor" >{$pmtypearray[$pmtp]}</td>
                <td width="105" align="center" bgcolor="$bgcolor"><font color="#CC3300">{$sastatarray[$sast]}</font></td>
              </tr>

EOS;
		}
	} else {
		$document['main'] .= <<<EOS
<tr>
<td height="60" align="center" bgcolor="F3F3F3">ÁÖ¹®/¹è¼Û ³»¿ªÀÌ ¾ø½À´Ï´Ù.</td>
</tr>

EOS;
	}

	$document['main'] .= <<<EOS
            </table>
            <table width="670" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td height="1" bgcolor="DDDDDD"></td>
              </tr>
            </table>
            
EOS;
}

## Start

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

	return;
}

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

require "mypage_template.php";
?>
