Web Programming >> PHP Programming
|
[목차] |
제21장 온라인 서점 쇼핑몰 만들기
5. 관리자 메뉴 - 주문관리
디렉토리 및 파일 구조는 다음과 같다. / -- shop/ -- admin/ --- product/ --(제품관리) | | | | | +-- list.html | | +-- postform.html.html | | +-- post.html | | +-- viewbody.html | | +-- modifyform.html | | +-- modify.html | | +-- deleteform.html | | +-- delete.html | | | +- order/ --(주문관리) | | | | | +-- index.html | | +-- viewuser.html | | +-- modify.html | | +-- delete.html | | | +- admin.html (관리자 인증에 필요한 파일) | +- index.html (아이디와 암호를 입력하는 폼) | +- login_process.html (로그인 처리프로그램) | +- home.html (관리자 화면) | +- menu.html (메뉴) | +- welcome.html (환영 메시지) | +- logout.html (종료 프로그램) | +-- user_function.html (사용자 정의 함수들) | +-- dbconn.html (DB connect에 필요한 파일)
1. 주문 관리 프로그램
파일명 : index.html <? include "../../user_function.html"; include "../../dbconn.html";
include("../admin.html");
if(!$user_id || strcmp($row->logindate,$user_logindate)) { echo ("<meta http-equiv='Refresh' content='0; URL=../'>"); exit; } ?>
<html>
<head> <title>관리자 메뉴-제품관리</title> </head> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; font-size: 10pt; } a:hover { text-decoration : underline; font-size: 10pt; color : red; } //--> </style> <?
########### 한 페이지당 출력할 게시물의 수 $num_per_page = 10;
########### 게시물 출력목록 하단에 링크를 걸 페이지의 개수 $page_per_block = 10;
echo ("<meta http-equiv='Refresh' content='10; URL=./?task=$task'>"); ?>
<script language="javascript"> <!-- function profileWindow(ref) { var window_left = (screen.width-700)/2; var window_top = (screen.height-500)/2; location.href="./?task=order"; window.open(ref,"profileWin",'width=700,height=500,status=no,scrollbars=yes,top=' + window_top + ',left=' + window_left + ''); } //--> </script>
<body bgColor="#FFFFFF"> <?
if(!$page) { $page = 1; }
echo("<p align=center><font size=2><b>◎◎◎ [주문 관리 프로그램 - 관리자용] ◎◎◎ </b></font></p>");
########## 현재페이지의 범위내에 출력할 결과레코드세트를 얻는다. ########## if(!eregi("[^[:space:]]+",$key)) { $query = "SELECT uid,name,phone,status,signdate FROM sold where status > '0' ORDER BY signdate DESC"; } else { $encoded_key = urlencode($key); $query = "SELECT uid,name,phone,status,signdate FROM sold WHERE status > '0' AND $keyfield LIKE '%$key%' ORDER BY signdate DESC"; } $result= mysql_query($query); if (!$result) { error("QUERY_ERROR"); exit; }
$total_record = mysql_num_rows($result);
########## 현재의 페이지에서 출력할 게시물의 범위를 결정한다. ########## if(!$total_record) { $first = 1; $last = 0; } else { $first = $num_per_page*($page-1); $last = $num_per_page*$page;
$IsNext = $total_record - $last; if($IsNext > 0) { $last -= 1; } else { $last = $total_record - 1; } }
########## 전체 페이지수를 계산한다. ########## $total_page = ceil($total_record/$num_per_page); ?>
<table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td width="80"> </td> <td width="340" align="center"> <font size="2">
<? if(!eregi("[^[:space:]]+",$key)) { echo("총 등록 주문 : <b>$total_record</b> (Total <b>$total_record</b> 개)"); } else { echo("검색된 등록 주문 : <b>$total_record</b> (Total <b>$total_record</b> 개)"); } ?> </font> </td> <td width="80" align="right"><font size=2>( <font color="red"><? echo("$page") ?></font> / <font color="red"><? echo("$total_page") ?></font> )</font></td> </tr> </table> <table width=500 border=0 cellpadding=1 cellspacing="0" align="center"> <tr> <td bgColor="#000000"> <table border="0" width="500" align="center" cellspacing="1" cellpadding="2"> <tr> <td align="center" bgColor="#BBBBBB" width=40><font size=2 color="#ffffff">번호</font></td> <td align="center" bgColor="#BBBBBB" width=80><font size=2 color="#ffffff">날짜</font></td> <td align="center" bgColor="#BBBBBB" width=60><font size=2 color="#ffffff">이름</font></td> <td align="center" bgColor="#BBBBBB" width=80><font size=2 color="#ffffff">전화</font></td> <td align="center" bgColor="#BBBBBB" width=80><font size=2 color="#ffffff">가격</font></td> <td align="center" bgColor="#BBBBBB" width=80><font size=2 color="#ffffff">상태</font></td> <td align="center" bgColor="#BBBBBB" width=40><font size=2 color="#ffffff">배달</font></td> <td align="center" bgColor="#BBBBBB" width=40><font size=2 color="#ffffff">삭제</font></td> </tr>
<? $time_limit = 60*60*24*$notify_new_article;
########## 게시물의 가상번호(게시물의 개수에 따른 일련번호) ########## $article_num = $total_record - $num_per_page*($page-1); $cnt = 0; for($i = $first; $i <= $last; $i++) { $my_uid = mysql_result($result,$i,0); $my_name = mysql_result($result,$i,1); $my_phone = mysql_result($result,$i,2); $my_status = mysql_result($result,$i,3); $my_signdate = mysql_result($result,$i,4); if($my_status == "1") { $my_status = "<font color=red><b>주문</b></font>"; $cnt ++; } if($my_status == "2") $my_status = "배달";
$query1="SELECT sum(price) FROM sale_bag WHERE user_uid=$my_uid "; $result1 = mysql_query($query1); if (!$result1) { error("QUERY_ERROR"); exit; } $my_price = mysql_result($result1,0,0);
$my_signdate = date("Y-m-d H:i",$my_signdate);
echo("<tr>"); echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2>$article_num</font></td>");
########## 회원 이름 및 이메일주소 ########## echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2>$my_signdate</font></td>"); echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2> <a href=\"javascript:profileWindow('viewuser.html?mode=form&page=$page&number=$my_uid&keyfield=$keyfield&key=$encoded_key')\" >$my_name</a></font></td>"); echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2>$my_phone</font></td>"); echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2>$my_price</font></td>"); echo(" <td bgColor=#EEEEEE align=\"center\"><font size=2>$my_status</font></td>");
echo("<td bgColor=#EEEEEE align=\"center\"><font size=2> <a href=\"modify.html?mode=form&page=$page&number=$my_uid&keyfield=$keyfield&key=$encoded_key\">V</a></font></td>"); echo("<td bgColor=#EEEEEE align=\"center\"><font size=2> <a href=\"delete.html?mode=form&page=$page&number=$my_uid&keyfield=$keyfield&key=$encoded_key\">X</a></font></td>"); echo("</tr>");
$article_num--; }
echo("</table>"); ?> </td></tr> </table>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td align="center"> <? ########## 게시물 목록 하단의 각 페이지로 직접 이동할 수 있는 페이지링크에 대한 설정을 한다. ########## $total_block = ceil($total_page/$page_per_block); $block = ceil($page/$page_per_block);
$first_page = ($block-1)*$page_per_block; $last_page = $block*$page_per_block;
if($total_block <= $block) { $last_page = $total_page; }
########## 이전페이지블록에 대한 페이지 링크 ########## if($block > 1) { $my_page = $first_page; echo("<font size=2><a href=\"index.html?page=$my_page&keyfield=$keyfield&key=$encoded_key\">[이전 ${page_per_block}개]</a></font>"); }
########## 현재의 페이지 블럭범위내에서 각 페이지로 바로 이동할 수 있는 하이퍼링크를 출력한다. for($direct_page = $first_page+1; $direct_page <= $last_page; $direct_page++) { if($page == $direct_page) { echo("<font size=2><b>[$direct_page]</b></font>"); } else { echo("<font size=2><a href=\"index.html?page=$direct_page&keyfield=$keyfield&key=$encoded_key\">[$direct_page]</a></font>"); } }
########## 다음페이지블록에 대한 페이지 링크 ########## if($block < $total_block) { $my_page = $last_page+1; echo("<font size=2><a href=\"index.html?page=$my_page&keyfield=$keyfield&key=$encoded_key\">[다음 ${page_per_block}개]</a></font>"); } ?> </td> </tr> </table>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td align="left"> <a href="index.html">목록</a> </td> <td align="right"> <? ########## 이전페이지가 존재할 경우 이전페이지로 가는 링크를 활성화시킨다. ########## if ($page > 1) { $page_num = $page - 1; echo("<a href=\"index.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">이전</a> | "); } else { echo("<font size=2>이전 | "); }
########## 게시물이 다음페이지에도 존재할 경우 다음페이지로 가는 링크를 활성화시킨다. ########## if ($IsNext > 0) { $page_num = $page + 1; echo("<a href=\"index.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">다음</a></td>"); } else { echo("<font size=2>다음</td>"); } ?>
</tr> </table>
</form>
<center> <form method="post" action="index.html"> <font size=-1> <select name="keyfield" size="1"> <option value="name">성명</option> </select> </font> <input type="text" size="20" maxlength="30" name="key"> <font size=2><input type="submit" value="검색"></font> </form><br> </center> <? if($cnt > 0) { ?> <embed src="./allim.wav" width="0" height="0" border="0" hidden="false" PLUGINSPAGE="http://music.leelab.co.kr/mpie4ful.exe" autorewind="true" autostart="true" loop="true" type="application/x-mplayer2" > <? } ?> </body> </html>
파일명 : viewuser.html
<? include "../../user_function.html"; include "../../dbconn.html";
include("../admin.html");
if(!$user_id || strcmp($row->logindate,$user_logindate)) { echo ("<meta http-equiv='Refresh' content='0; URL=../'>"); exit; }
########## 전달된 변수 $mode의 값이 "form"일 경우 수정양식을 출력한다. if(!strcmp($mode,"form")) { ?>
<html> <head> <title>온라인 주문 신청서</title> </head> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; font-size: 10pt; } a:hover { text-decoration : underline; font-size: 10pt; color : red; } td { text-decoration : none; font-size: 10pt; } //--> </style>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<div align='center'><table border='0' cellpadding='0' width='500'> <tr> <td width='500'><p align='center'><font size='3'><b>상품 주문서 확인 </b></font></td> </tr> <tr> <td width='500'> <p align='right'><b>주문번호 : <?echo("$number");?></b> <p align='left'>상품 갯수 확인 <div align='center'><table border width='500' bordercolor="white"> <tr> <td width='142' height='14' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>상 품</font></td> <td width='142' height='14' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>단 가</font></td> <td width='142' height='14' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>수 량</font></td> </tr> <? $query="SELECT uid,product_uid,amount,price FROM sale_bag WHERE user_uid = $number"; $result = mysql_query($query); //echo("$query"); if (!$result) { error("QUERY_ERROR"); exit; } $rows = mysql_num_rows($result); $total_price = 0;
for($i=0;$i<$rows; $i++) { $sale_uid = mysql_result($result,$i,0); $product_uid = (int)mysql_result($result,$i,1); $amount = (int)mysql_result($result,$i,2); $product_price = (int)mysql_result($result,$i,3); $product_price = number_format($product_dc_price);
$total_price = ($product_dc_price * $amount) + $total_price;
$query1="SELECT uid,part,name,price FROM product WHERE uid=$product_uid"; $result1 = mysql_query($query1); //echo("$query1"); if (!$result1) { error("QUERY_ERROR"); exit; } $part = mysql_result($result1,0,1); $product_name = mysql_result($result1,0,2); ?> <tr> <td width='142' height='16' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><?echo("$product_name");?></td> <td width='142' height='16'bordercolor="green"> <p align='center'><?echo("$product_price");?></td> <td width='142' height='16'bordercolor="green"> <p align='center'><?echo("$amount");?>개</td> </tr> <? }
$query="SELECT uid,name,phone,address,desp FROM sold WHERE uid=$number"; $result = mysql_query($query);
//echo("$query"); if (!$result) { error("QUERY_ERROR"); exit; } $name = mysql_result($result,0,1); $phone = mysql_result($result,0,2); $address = mysql_result($result,0,3);
$total_price = number_format($total_price);
?> </table> <p align='right'><b>총합 : <?echo("$total_price");?> 원</b></div> <p align='left'>배달 주소 확인 <div align='center'> <table border width='500' bordercolor="white"> <tr> <td width='120' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>이 름</font></td> <td width='380' bordercolor="green"><p> <?echo("$name");?></td> </tr> <tr> <td width='120' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>연락처(전화번호)</font></td> <td width='380' bordercolor="green"><p> <?echo("$phone");?></td> </tr> <tr> <td width='120' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>배달 주소</font></td> <td width='380' bordercolor="green"> <p> <?echo("$address");?></td> </tr> <tr> <td width='120' height='95' bgcolor="#70FFB9" bordercolor="green"> <p align='center'><font size='2'>전하는 말</font></td> <td width='380' height='95' bordercolor="green"> <p align='left'> <?echo("$desp");?></td> </tr> </table></div> <p> </td> </tr> <tr> <td width='500'><p align='center'><font face='굴림'></td> </tr> <tr> <td width='500'><p><font face='굴림'><hr width='80%' with='80%'></font></td> </tr> <tr> <td width='500'><p align='center'> <font face='굴림' size='2'>Copyrightⓒ 2000 </font> <a href='mailto:jklee@leelab.co.kr'> <font face='굴림' size='2'><b>LeeLAB's</b></font></a> <font face='굴림' size='2'> All Rights Reserved.<br></font></td> </tr> </table></div>
<p> </p> </body> </html>
<? } ?>
파일명 : modify.html
<? include "../../user_function.html"; include "../../dbconn.html";
include("../admin.html");
if(!$user_id || strcmp($row->logindate,$user_logindate)) { echo ("<meta http-equiv='Refresh' content='0; URL=../'>"); exit; }
########## 전달된 변수 $mode의 값이 "form"일 경우 수정양식을 출력한다. ########## if(!strcmp($mode,"form")) {
########## 현재 로그인한 사용자의 데이터를 회원테이블에서 가져온다. ########## $query = "SELECT name,desp FROM sold WHERE uid = '$number'"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; } $row = mysql_fetch_object($result);
?> <html> <head> <title>온라인 쇼핑몰</title> <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; } a:hover { text-decoration : underline; color : red; } TABLE, TD, TR, TH { font-size : 10pt; } //--> </style> </head>
<body bgcolor="#FFFFFF">
<? $php_self = basename($PHP_SELF); ?>
<form name="signform" method="POST" action="./modify.html?mode=process&page=<?echo("$page")?>&number=<?echo("$number")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$key")?>">
<table width="652" cellspacing="1" cellpadding="0" border="0" align="center"> <tr><td align="center" bgColor="#000000">
<table width="650" cellspacing="1" cellpadding="5" border="0" align="center">
<tr> <td width="640" align="center" bgColor="#FFFFFF" colspan=4>주문 결과를 입력하는 곳입니다.</td> </tr> <tr> <td width="140" bgColor="#BBBBBB" align="center">주문번호</td> <td width="500" bgColor="#EEEEEE" colspan="3"> <?echo("$number")?> </td> </tr> <tr> <td width="140" bgColor="#BBBBBB" align="center">주문상태</td> <td width="500" bgColor="#EEEEEE" colspan="3"> <select name="status"> <option value="0">쇼핑중</option> <option value="1">주문</option> <option value="2" selected>배달완료</option> </select> </td> </tr> <tr> <td width="140" bgColor="#BBBBBB" align="center">설명</td> <td width="500" bgColor="#EEEEEE" colspan="3"> <textarea name='desp' cols='50' rows='3' ><?echo("$row->desp")?></textarea> </td> </tr>
<!------------------------- 등록버튼 ---------------------------> <tr> <td align="center" colspan="4" bgColor="#FFFFFF"> <font size=2> <input type="submit" value="수정 하기" > <input type="reset" value="다시 입력"> </font> </td> </tr>
</table>
</td></tr> </table><p>
</form> <center> <font size=2> <a href="./">목록</a>
</font> </center>
</body> </html> <? ########## 전달된 변수 $mode의 값이 "process"일 경우 입력양식의 값으로 갱신한다. } else if(!strcmp($mode,"process")) {
########## 사용자가 입력양식에 입력한대로 회원정보를 갱신한다.########## $query = "UPDATE sold SET status ='$status', desp='$desp' WHERE uid = $number'";
// echo("$query"); $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; }
$encoded_key = urlencode($key); echo("<meta http-equiv='Refresh' content='0; URL=./index.html?page=$page&keyfield=$keyfield&key=$encoded_key'>");
########## 전달된 변수 $mode의 값이 "mode"나 "process"가 아닐 경우 스크립트의 실행을 종료한다. } else { error("UPDATE_MEMBER_INVALID_MODE"); exit; } ?>
파일명 : delete.html
<? include "../../user_function.html"; include "../../dbconn.html";
include("../admin.html");
if(!$user_id || strcmp($row->logindate,$user_logindate)) { echo ("<meta http-equiv='Refresh' content='0; URL=../'>"); exit; }
########## 전달된 변수 $mode의 값이 "form"일 경우 삭제확인화면을 출력한다. ########## if(!strcmp($mode,"form")) {
########## 현재 로그인한 사용자의 데이터를 회원테이블에서 가져온다. ########## $query = "SELECT uid,name FROM sold WHERE uid = '$number'"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; } $row = mysql_fetch_object($result); ?> <html> <head> <title>온라인 쇼핑몰</title> <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; } a:hover { text-decoration : underline; color : red; } TABLE, TD, TR, TH { font-size : 10pt; } //--> </style> </head>
<body bgcolor="#FFFFFF">
<? $php_self = basename($PHP_SELF); ?>
<form name="signform" method="POST" action="<?echo("$php_self")?>?mode=process&page=<?echo("$page")?>&number=<?echo("$number")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$key")?>">
<table width="500" cellspacing="1" cellpadding="0" border="0" align="center"> <tr><td align="center" bgColor="#000000">
<table width="500" cellspacing="1" cellpadding="5" border="0" align="center"> <tr> <td width="500" align="center" bgColor="#FFFFFF" colspan=2> <?echo("<b>$row->name</b>")?>님의 주문사항을 <font color=red>삭제합니다 </font>.</td> </tr> <tr> <td width="140" bgColor="#BBBBBB" align="center">성 명</td> <td width="500" bgColor="#EEEEEE" > <?echo("$row->name")?> </td> </tr> <tr> <td align="center" colspan="2" bgColor="#FFFFFF"> <font size=2> <input type="submit" value='<?echo("$row->name")?>의 주문사항을 삭제합니다'> </font> </td> </tr>
</table>
</td></tr> </table><p>
</form> <center> <font size=2> <a href="./">목록</a>
</font> </center>
</body> </html> <? ########## 전달된 변수 $mode의 값이 "process"일 경우 입력양식의 값으로 갱신한다. } else if(!strcmp($mode,"process")) {
########## 회원데이터를 데이터베이스에서 삭제한다. ########## $result = mysql_query("DELETE FROM sold WHERE uid = '$number'"); if(!$result) { error("QUERY_ERROR"); exit; }
$result = mysql_query("DELETE FROM sale_bag WHERE user_uid = '$number'"); if(!$result) { error("QUERY_ERROR"); exit; }
########## 회원목록 출력화면으로 이동한다. ########## $encoded_key = urlencode($key); echo("<meta http-equiv='Refresh' content='0; URL=./?page=$page&keyfield=$keyfield&key=$encoded_key'>");
########## 전달된 변수 $mode의 값이 "mode"나 "process"가 아닐 경우 스크립트의 실행을 종료한다. } else { error("UPDATE_MEMBER_INVALID_MODE"); exit; } ?>
|
[목차] |