Web Programming >> PHP Programming
|
[목차] |
제21장 온라인 서점 쇼핑몰 만들기
4. 관리자 메뉴 - 제품관리
디렉토리 및 파일 구조는 다음과 같다. / -- shop/ -- admin/ --- product/ --(제품관리) | | | | | +-- list.html | | +-- postform.html.html | | +-- post.html | | +-- viewbody.html | | +-- modifyform.html | | +-- modify.html | | +-- deleteform.html | | +-- delete.html | | | +- order/ (주문관리) | | | +- admin.html (관리자 인증에 필요한 파일) | +- index.html (아이디와 암호를 입력하는 폼) | +- login_process.html (로그인 처리프로그램) | +- home.html (관리자 화면) | +- menu.html (메뉴) | +- welcome.html (환영 메시지) | +- logout.html (종료 프로그램) | +-- user_function.html (사용자 정의 함수들) | +-- dbconn.html (DB connect에 필요한 파일)
1. 제품 목록 보여주기(list.html)
파일명 : list.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>
<script language="javascript"> <!-- function checkUserSelect() { var check_nums = document.signform.elements.length; for(var i = 0; i < check_nums; i++) { var checkbox_obj = eval("document.signform.elements[" + i + "]"); if(checkbox_obj.checked == true) { break; } } if(i == check_nums) { alert("먼저 읽고자 하는 게시물을 선택하여 주십시오"); return; } else { document.signform.submit(); } } //--> </script> <body bgColor="#FFFFFF"> <? if(!$page) { $page = 1; }
$num_per_page = 10; $page_per_block = 10;
########## 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 현재페이지의 범위내에 출력할 결과레코드세트를 얻는다. ########## if(!eregi("[^[:space:]]+",$key)) { $query = "SELECT uid,name,part,author,price,remain FROM product ORDER BY uid DESC"; } else { $encoded_key = urlencode($key); $query = "SELECT uid,name,part,author,price,remain FROM product WHERE $keyfield LIKE '%$key%' ORDER BY uid 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); ?>
<form name="signform" method="post" action="read.html?page=<?echo("$page")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$encoded_key")?>">
<table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table> <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> Files)"); } else { echo("검색된 자료 : <b>$total_record</b> (Total <b>$total_record</b> Files)"); } ?> </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="#000000">번호</font></td> <td align="center" bgColor=#BBBBBB width=90> <font size=2 color="#000000">분류</font></td> <td align="center" bgColor=#BBBBBB width=150> <font size=2 color="#000000">제목</font></td> <td align="center" bgColor=#BBBBBB width=70> <font size=2 color="#000000">지은이</font></td> <td align="center" bgColor=#BBBBBB width=70> <font size=2 color="#000000">가격</font></td> <td align="center" bgColor=#BBBBBB width=40> <font size=2 color="#000000">수량</font></td> <td align="center" bgColor=#BBBBBB width=40> <font size=2 color="#000000">선 택</font></td> </tr> <? $time_limit = 60*60*24*$notify_new_article;
########## 게시물의 가상번호(게시물의 개수에 따른 일련번호) ########## $article_num = $total_record - $num_per_page*($page-1);
for($i = $first; $i <= $last; $i++) { $my_uid = mysql_result($result,$i,0); $my_name = mysql_result($result,$i,1); $my_part = mysql_result($result,$i,2); $my_author = mysql_result($result,$i,3); $my_price = mysql_result($result,$i,4); $my_remain = mysql_result($result,$i,5);
########## addslashes() 함수로 escape된 제목의 문자열을 원상복귀시킨다. ########## $my_subject = stripslashes($my_subject);
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_part</font></td>"); echo("<td bgColor=#EEEEEE align=\"center\"> <a href=\"viewbody.html?page=$page&number=$my_uid&keyfield=$keyfield&key=$encoded_key\" ><font size=2>$my_name</font></a></td>\n"); echo("<td bgColor=#EEEEEE align=\"center\"><font size=2>$my_author</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_remain</font></td>"); echo("<td bgColor=#EEEEEE align=\"center\"><font size=2><input type=\"checkbox\" name=\"check[]\" value=\"$my_uid\"></font></td>"); echo("</tr>"); $article_num--; } echo("</table>"); ?> </td></tr> </table>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td colspan="7" 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=\"list.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=\"list.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=\"list.html?page=$my_page&keyfield=$keyfield&key=$encoded_key\" onMouseOver=\"status='load next $page_per_block pages';return true;\" onMouseOut=\"status=''\">[다음 ${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="list.html" >목록</a> </td> <td align="right"><font size=2> <a href="javascript:checkUserSelect()" >선택하여 읽기</a> | <a href="postform.html" >등록</a> |
<? ########## 이전페이지가 존재할 경우 이전페이지로 가는 링크를 활성화시킨다. ########## if ($page > 1) { $page_num = $page - 1; echo("<a href=\"list.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">이전</a> | "); } else { echo("이전 | "); } ########## 게시물이 다음페이지에도 존재할 경우 다음페이지로 가는 링크를 활성화시킨다. ########## if ($IsNext > 0) { $page_num = $page + 1; echo("<a href=\"list.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">다음</a> </td>"); } else { echo("다음</td>"); } ?> </tr> </table> </form> <center> <form method="post" action="list.html"> <font size=-1> <select name="keyfield" size="1"> <option value="name">제목</option> <option value="author">지은이</option> <option value="info">내용</option> </select> </font> <input type="text" size="20" maxlength="30" name="key"> <font size=2><input type="submit" value="검색"></font> </form> </center> </body> </html>
2. 제품 등록(post.html,postform.html) 파일명 : postform.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> <script language="javascript"> <!-- function checkIt(form) { if(!form.name.value) { alert('이름을 입력하세요!'); form.name.focus(); return; } form.submit(); } //--> </script> <body bgColor="#FFFFFF"> <table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table>
<form name="signform" method="POST" ENCTYPE="multipart/form-data" action="post.html"> <table width="500" border="0" cellspacing="1" cellpadding="0" align="center"> <tr> <td bgColor="#000000"> <table width="500" border="0" cellspacing="1" cellpadding="5" align="center"> <tr> <td width="120" align="center" bgColor="#BBBBBB"><font size=2>분류 </font></td> <td width="380" bgColor="#EEEEEE"> <input type="text" name="part" size="20" maxlength="20"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>도서명</font></td> <td bgColor="#EEEEEE"> <input type="text" name="name" size="30" maxlength="50"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>지은이</font></td> <td bgColor="#EEEEEE"> <input type="text" name="author" size="30" maxlength="30"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>가격</font></td> <td bgColor="#EEEEEE"> <input type="text" name="price" size="15" maxlength="15"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>출판일</font></td> <td bgColor="#EEEEEE"> <input type="text" name="date" size="15" maxlength="15"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>재고량</font></td> <td bgColor="#EEEEEE"> <input type="text" name="remain" size="5" maxlength="5"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>등록할 파일</font></td> <td bgColor="#EEEEEE"> <input type="file" name="userfile" size="15"><font size=2>(Maximum : 20M)</font></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>자 료 소 개</font> </td> <td bgColor="#EEEEEE"><textarea name="info" cols="50" rows="10"></textarea> </tr> <tr> <td align="center" colspan="2" bgColor="#BBBBBB"> <font size=2> <input type="button" value="자료 등록" onClick="checkIt(this.form)"> <input type="reset" value="취 소"> </font> </td> </tr> </table> </td> </tr> </table> </form> </body> </html>
파일명 : post.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; }
if(!ereg("([^[:space:]]+)", $name)) { error("INVALID_NAME"); exit; }
if($userfile_name == "") { $userfile_name = ""; } else { ########## 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 등록한 파일이 업로드가 허용되지 않는 확장자를 갖는 파일인지를 검사한다. ########## $full_filename = explode(".", "$userfile_name"); $extension = $full_filename[sizeof($full_filename)-1];
if(strcmp($extension,"jpg") && strcmp($extension,"gif")) { error("NO_ACCESS_UPLOAD"); exit; } ########## 등록하려는 파일과 동일한 이름을 갖는 파일이 이미 존재하는지를 검사한다. ########## $same_file_exist = file_exists("$savedir/$userfile_name"); if($same_file_exist) { error("SAME_FILE_EXIST"); exit; }
########## 등록하려는 파일을 현재 자료실의 지정디렉토리에 저장 ########## if(!copy($userfile,"$savedir/$userfile_name")) { error("UPLOAD_COPY_FAILURE"); exit; }
########## 작업이 끝난후 임시디렉토리에 저장된 파일을 삭제한다. ########## if(!unlink($userfile)) { error("UPLOAD_DELETE_FAILURE"); exit; }
}
########## 데이터베이스에 입력값을 삽입한다. ########## $query = "INSERT INTO product (uid, part,name, author, price, date,info,remain,userfile) VALUES ('$new_uid', '$part','$name', '$author', $price, '$date', '$info', $remain, '$userfile_name')";
$result = mysql_query($query); if($result) { ########## 리스트 출력화면으로 이동한다. ########## echo ("<meta http-equiv='Refresh' content='0; URL=list.html'>"); } else { error("QUERY_ERROR"); exit; } ?>
3. 제품 수정하기(modifyform.html, modify.html)
파일명 : modifyform.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>
<script language="javascript"> <!-- function checkIt(form) { if(!form.name.value) { alert('이름을 입력하세요!'); form.name.focus(); return; } form.submit(); }
function focusIt() { document.signform.name.focus(); } //--> </script> <body bgColor="#FFFFFF" onLoad="focusIt()"> <?
######### 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 수정하고자 하는 글의 입력값을 뽑아낸다. ########## $query = "SELECT name,part,author,price,date,info,remain,userfile FROM product WHERE uid = $number"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; }
$my_name = mysql_result($result,0,0); $my_part = mysql_result($result,0,1); $my_author = mysql_result($result,0,2); $my_price = mysql_result($result,0,3); $my_date = mysql_result($result,0,4); $my_info = mysql_result($result,0,5); $my_remain = mysql_result($result,0,6); $my_filename = mysql_result($result,0,7);
########## addslashes() 함수로 escape된 제목과 본문의 문자열을 원상복귀시킨다. ##########
$my_info = stripslashes($my_info);
########## 검색문자열을 인코딩한다. ########## $encoded_key = urlencode($key); ?> <table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table>
<form name="signform" method="post" ENCTYPE="multipart/form-data" action="modify.html?page=<?echo("$page")?>&number=<?echo("$number")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$encoded_key ")?>">
<table width="502" border="0" cellspacing="1" cellpadding="0" align="center"> <tr> <td bgColor="#000000"> <table width="500" border="0" cellspacing="1" cellpadding="5" align="center"> <tr> <td width="120" align="center" bgColor="#BBBBBB"><font size=2>도서명</font></td> <td width="380" bgColor="#EEEEEE"> <input type="text" name="name" size="20" maxlength="10" value="<?echo ("$my_name")?>"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>분류</font></td> <td bgColor="#EEEEEE"> <input type="text" name="part" size="30" maxlength="40" value="<?echo ("$my_part")?>"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>지은이</font></td> <td bgColor="#EEEEEE"> <input type="text" name="author" size="35" maxlength="60" value="<?echo ("$my_author")?>"></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>출판일</font></td> <td bgColor="#EEEEEE"> <input type="text" name="date" size="40" maxlength="40" value='<?echo ("$my_date")?>'></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>가격</font></td> <td bgColor="#EEEEEE"> <input type="text" name="price" size="40" maxlength="40" value='<?echo ("$my_price")?>'></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>재고수량</font></td> <td bgColor="#EEEEEE"> <input type="text" name="remain" size="40" maxlength="40" value='<?echo ("$my_remain")?>'></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>등 록 파 일</font></td> <td bgColor="#EEEEEE"><font size=2> <input type="file" name="userfile" size="30"> <input type='hidden' name='o_userfile' value='<?echo("$my_filename");?>'><br> <?if($my_filename !="") echo("<img src=\"$savedir/$my_filename\" border=0>")?></font></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>도 서 소 개</font> </td> <td bgColor="#EEEEEE"><textarea name="info" cols="50" rows="5"><?echo("$my_info")?></textarea> </tr> <tr> <td align="center" colspan="2" bgColor="#BBBBBB"> <font size=2> <input type="button" value=" 수 정 " onClick="checkIt(this.form)"> <input type="reset" value=" 취 소 "> </font> </td> </tr> </table> </td></tr> </table> </form> </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; }
if(!ereg("([^[:space:]]+)", $name)) { error("INVALID_NAME"); exit; }
$info = addslashes($info);
$savedir = "../../product_files";
$filename = $o_userfile;
if(!strcmp($userfile,"none")) { $userfile_name = $filename; } else { if($filename != "") { $same_file_exist = file_exists("$savedir/$filename"); if($same_file_exist) { unlink("$savedir/$filename"); } }
########## 등록한 파일이 업로드가 허용되지 않는 확장자를 갖는 파일인지를 검사한다. $full_filename = explode(".", "$userfile_name");
$extension = $full_filename[sizeof($full_filename)-1];
if(strcmp($extension,"gif") && strcmp($extension,"jpg")) { error("NO_ACCESS_UPLOAD"); exit; }
########## 등록하려는 파일과 동일한 이름을 갖는 파일이 이미 존재하는지를 검사한다. $userfile_name_id = $userfile_name;
$userfile_id = 0; while(file_exists("$savedir/$userfile_name_id")) { $userfile_id = $userfile_id + 1; $userfile_name_id = $userfile_id."_".$userfile_name_id; }
if($userfile_id != 0) $userfile_name = $userfile_name_id; if(!copy($userfile,"$savedir/$userfile_name")) { error("UPLOAD_COPY_FAILURE"); exit; }
########## 작업이 끝난후 임시디렉토리에 저장된 파일을 삭제한다. ########## if(!unlink($userfile)) { error("UPLOAD_DELETE_FAILURE"); exit; } }
if($price == "") $price = 0;
$query = "UPDATE product SET name = '$name', part = '$part', author = '$author', price = $price, date = '$date',info = '$info',remain = $remain, userfile='$userfile_name' WHERE uid = $number";
$result = mysql_query($query); if (!$result) { error("QUERY_ERROR"); exit; } echo("<meta http-equiv='Refresh' content='0; URL=list.html?page=$page&keyfield=$keyfield&key=$encoded_key'>");
?>
4. 제품 삭제하기(delete.html, deleteform.html)
파일명 : deleteform.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> <script language="javascript"> <!-- function checkIt(form) { form.submit(); } //--> </script> <body bgColor="#FFFFFF"> <?
########## 그림파일이 저장될 디렉토리를 설정한다. ########## $savedir = "../../product_files";
######### 삭제하고자 하는 글의 입력값을 뽑아낸다. ########## $query = "SELECT name,author FROM product WHERE uid = $number"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; }
$my_name = mysql_result($result,0,0); $my_author = mysql_result($result,0,1);
########## addslashes() 함수로 escape된 제목의 문자열을 원상복귀시킨다. ########## $my_name = stripslashes($my_name);
########## 검색문자열을 인코딩한다. ########## $encoded_key = urlencode($key);
?> <form name="signform" method="post" action="delete.html?page=<?echo("$page")?>&number=<?echo("$number")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$encoded_key")?>"> <table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table>
<table width="502" border="0" cellspacing="1" cellpadding="0" align="center"> <tr> <td bgColor="#000000"> <table width="500" border="0" cellspacing="1" cellpadding="5" align="center"> <tr> <td width="120" align="center" bgColor="#BBBBBB"><font size=2>도서명</font></td> <td width="380" bgColor="#EEEEEE"><font size=2><?echo ("$my_name")?></font></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font size=2>지은이</font></td> <td bgColor="#EEEEEE"><font size=2><?echo ("$my_author")?></font></td> </tr> <tr> <td align="center" colspan="2" bgColor="#FFFFFF"> <font size=2> <input type="button" value="자료 삭제" onClick="checkIt(this.form)"> <input type="reset" value="취 소"> </font> </td> </tr> </table> </td></tr> </table> </form> </body> </html>
파일명 : 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; }
########## 그림파일이 저장될 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 디렉토리에서 삭제할 파일명을 가지고 온다. ########## $result = mysql_query("SELECT userfile FROM product WHERE uid = $number"); if(!$result) { error("QUERY_ERROR"); exit; }
$filename = mysql_result($result,0,0); $file = "${savedir}/$filename";
########## 디렉토리에서 선택한 레코드의 그림파일을 삭제한다. ########## if(!unlink($file)) { error("FILE_DELETE_FAILURE"); exit; }
########## 테이블에서 해당 파일의 레코드를 삭제한다. ########## $result = mysql_query("DELETE FROM product WHERE uid = $number"); if (!$result) { error("QUERY_ERROR"); exit; }
echo("<meta http-equiv='Refresh' content='0; URL=list.html?page=$page&keyfield=$keyfield&key=$encoded_key'>"); ?>
5. 제품 내용보기(viewbody.html)
파일명 : viewbody.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> <body bgColor="#FFFFFF"> <table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table> <?
########## 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 선택한 게시물의 입력값을 뽑아낸다. ########## $query = "SELECT uid,name,part,author,price,date,info,remain,userfile FROM product WHERE uid = $number"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; } $row1 = mysql_fetch_row($result);
$my_uid = $row1[0]; $my_name = $row1[1]; $my_part = $row1[2]; $my_author = $row1[3]; $my_price = $row1[4]; $my_date = $row1[5]; $my_info = $row1[6]; $my_remain = $row1[7]; $my_filename = $row1[8];
########## addslashes() 함수로 escape된 제목과 본문의 문자열을 원상복귀시킨다. $my_info = stripslashes($my_info);
########## 원칙상 제목에는 HTML 태그를 허용하지 않는다. ########## $my_info = htmlspecialchars($my_info);
########## 검색어가 있을 경우 검색어를 red color처리하여 출력한다. ########## if(!strcmp($keyfield,"info") && $key) { $my_info = eregi_replace("($key)", "<font color=red>\\1</font>", $my_info); } if(!strcmp($keyfield,"name") && $key) { $my_name = eregi_replace("($key)","<font color=red>\\1</font>",$my_name); } if(!strcmp($keyfield,"author") && $key) { $my_author = eregi_replace("($key)","<font color=red>\\1</font>",$my_author); }
########## 본문의 문자열을 개행처리한다. ########## $my_info = nl2br($my_info);
?> <table width=500 border=0 cellpadding=1 cellspacing="0" align="center"> <tr> <td bgColor="#000000"> <table width=500 border=0 cellpadding=5 cellspacing="1" align="center"> <tr> <td colspan="2" align="center" bgColor="#FFFFFF"><font color="#000000" size="2"><b><?echo("$my_name")?></b></font></td> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">글 쓴 이</font></td> <? echo("<td width=\"75%\" bgColor=\"#EEEEEE\"><font size=2>$my_author</font></td>"); ?> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">가격</font></td> <? echo("<td width=\"75%\" bgColor=\"#EEEEEE\"><font size=2>$my_price</font></td>"); ?> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">출 판 일</font></td> <td width="75%" bgColor="#EEEEEE"><font size="2"><?echo("$my_date")?></font></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font color="#000000" size="2">소 개</font></font></td> <td bgColor="#EEEEEE"><font size="2"><?echo("$my_info")?></font></td> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">그림</font></td> <td width="75%" bgColor="#EEEEEE"><font size="2"> <?if($my_filename !="") echo("<img src=\"$savedir/$my_filename\" border=\"0\" hspace=\"2\"> ")?></font></td> </tr> <tr> <td colspan="2" align="right" bgColor="#EEEEEE"> <? $encoded_key = urlencode($key); echo(" <A HREF=\"modifyform.html?page=$page&number=$number&keyfield=$keyfield&key=$encoded_key\" >수정</A> | <A HREF=\"deleteform.html?page=$page&number=$number&keyfield=$keyfield&key=$encoded_key\" >삭제</A>" ); ?> </td> </tr> </table> </td></tr> </table>
<script language="javascript"> <!-- function checkUserSelect() { var check_nums = document.signform.elements.length; for(var i = 0; i < check_nums; i++) { var checkbox_obj = eval("document.signform.elements[" + i + "]"); if(checkbox_obj.checked == true) { break; } } if(i == check_nums) { alert("먼저 읽고자 하는 게시물을 선택하여 주십시오"); return; } else { document.signform.submit(); } } //--> </script> <? if(!$page) { $page = 1; }
$num_per_page = 10; $page_per_block = 10;
########## 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "../../product_files";
########## 현재페이지의 범위내에 출력할 결과레코드세트를 얻는다. ########## if(!eregi("[^[:space:]]+",$key)) { $query = "SELECT uid,name,part,author,price,remain FROM product ORDER BY uid DESC"; } else { $encoded_key = urlencode($key); $query = "SELECT uid,name,part,author,price,remain FROM product WHERE $keyfield LIKE '%$key%' ORDER BY uid 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); ?>
<form name="signform" method="post" action="read.html?page=<?echo("$page")?>&keyfield=<?echo("$keyfield")?>&key=<?echo("$encoded_key")?>">
<table width="500" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제 품 관 리</font></b></td> </tr> </table> <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> Files)"); } else { echo("검색된 자료 : <b>$total_record</b> (Total <b>$total_record</b> Files)"); } ?> </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="#000000">번호</font></td> <td align="center" bgColor=#BBBBBB width=90> <font size=2 color="#000000">분류</font></td> <td align="center" bgColor=#BBBBBB width=150> <font size=2 color="#000000">제목</font></td> <td align="center" bgColor=#BBBBBB width=70> <font size=2 color="#000000">지은이</font></td> <td align="center" bgColor=#BBBBBB width=70> <font size=2 color="#000000">가격</font></td> <td align="center" bgColor=#BBBBBB width=40> <font size=2 color="#000000">수량</font></td> <td align="center" bgColor=#BBBBBB width=40> <font size=2 color="#000000">선 택</font></td> </tr> <? $time_limit = 60*60*24*$notify_new_article;
########## 게시물의 가상번호(게시물의 개수에 따른 일련번호) ########## $article_num = $total_record - $num_per_page*($page-1);
for($i = $first; $i <= $last; $i++) { $my_uid = mysql_result($result,$i,0); $my_name = mysql_result($result,$i,1); $my_part = mysql_result($result,$i,2); $my_author = mysql_result($result,$i,3); $my_price = mysql_result($result,$i,4); $my_remain = mysql_result($result,$i,5);
########## addslashes() 함수로 escape된 제목의 문자열을 원상복귀시킨다. ########## $my_subject = stripslashes($my_subject);
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_part</font></td>"); echo("<td bgColor=#EEEEEE align=\"center\"> <a href=\"viewbody.html?page=$page&number=$my_uid&keyfield=$keyfield&key=$encoded_key\" ><font size=2>$my_name</font></a></td>\n"); echo("<td bgColor=#EEEEEE align=\"center\"><font size=2>$my_author</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_remain</font></td>"); echo("<td bgColor=#EEEEEE align=\"center\"><font size=2><input type=\"checkbox\" name=\"check[]\" value=\"$my_uid\"></font></td>"); echo("</tr>"); $article_num--; } echo("</table>"); ?></td> </tr> </table> <table width="500" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td colspan="7" 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=\"list.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=\"list.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=\"list.html?page=$my_page&keyfield=$keyfield&key=$encoded_key\" onMouseOver=\"status='load next $page_per_block pages';return true;\" onMouseOut=\"status=''\">[다음 ${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="list.html" >목록</a> </td> <td align="right"><font size=2> <a href="javascript:checkUserSelect()" >선택하여 읽기</a> | <a href="postform.html" >등록</a> |
<? ########## 이전페이지가 존재할 경우 이전페이지로 가는 링크를 활성화시킨다. ########## if ($page > 1) { $page_num = $page - 1; echo("<a href=\"list.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">이전</a> | "); } else { echo("이전 | "); } ########## 게시물이 다음페이지에도 존재할 경우 다음페이지로 가는 링크를 활성화시킨다. ########## if ($IsNext > 0) { $page_num = $page + 1; echo("<a href=\"list.html?page=$page_num&keyfield=$keyfield&key=$encoded_key\">다음</a> </td>"); } else { echo("다음</td>"); } ?> </tr> </table> </form> <center> <form method="post" action="list.html"> <font size=-1> <select name="keyfield" size="1"> <option value="name">제목</option> <option value="author">지은이</option> <option value="info">내용</option> </select> </font> <input type="text" size="20" maxlength="30" name="key"> <font size=2><input type="submit" value="검색"></font> </form> </center> </body> </html>
|
[목차] |