PHP 프로그래밍

본문 바로가기
사이트 내 전체검색


Web Programming >> PHP Programming
[목차]
제28장 카드메일발송 프로그램

    2. 카드관리 프로그램 - 사용자용

 

1. 파일들의 구조

/ -- bbs/ -+-  admin/ --  ecard/ --+(관리자화면-카드관리)

           |                       |

           |                       +-- index.html

           |                       +-- postform.html

           |                       +-- post.html

           |                       +-- deleteform.html

           |                       +-- delete.html

           |                       +-- viewcard.html

           |

           +-- ecard/ --+

           |            |

           |            +-- img_files/

           |            |

           |            +-- index.html

           |            +-- leelab-ecard.html

           |            +-- leelab-step1.html

           |            +-- leelab-preview.html

           |            +-- leelab-send.html

           |

           +-- memu.html

           +-- dbconn.html

           +-- user_function.html

 

 

 

2. 사용자용 카드발송 프로그램

파일명 : index.html

<?

session_start();

if(!$user_id || !$user_name) {

        echo "<SCRIPT>location.replace('login.html');</SCRIPT>";

        exit;

}

########## 입력값에 대한 타당성 검사를 수행한다. ###########

include "../user_function.html";

########## 데이터베이스에 연결한다. ##########

include "../dbconn.html";

?>

<html>

<head>

<title>Leelab - 카드보내기</title>

</head>

<body bgcolor="<?echo("$bodybgcolor")?>" text="black" link="blue" vlink="purple" alink="red" topMARGIN=0 leftmargin=0>

<table width=800 border=0 BGCOLOR="#FFFFFF" cellpadding="3" cellspacing="0" align=center>

<tr>

<td valign="top" align=center colspan=2>

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

<?

if(!strcmp($task,"step1") )

        include "./leelab-step1.html";

else if(!strcmp($task,"preview") )

        include "./leelab-preview.html";

else if(!strcmp($task,"send") )

        include "./leelab-send.html";

else

        include "./leelab-ecard.html";

?>

</td>

</tr>

</table>

</body>

</html>

 

 $task변수에 따라 작업이 분기됩니다. 아무것도 없을 때 목록을 보여주고 있습니다.

파일명 : leelab-ecard.html (목록보여주기)

<?

session_start();

if(!$user_id || !$user_name) {

        echo "<SCRIPT>location.replace('../login.html');</SCRIPT>";

        exit;

}

$query = "SELECT DISTINCT cat1 FROM ecard order by cat1";

$result= mysql_query($query);

if (!$result) {

   error("QUERY_ERROR");

   exit;

}

$total_record = mysql_num_rows($result);  

if($total_record && !$part) $part = mysql_result($result,0,0);

for($i = 0; $i < $total_record; $i++) {

    $my_part = mysql_result($result,$i,0);   

?>

 [ <?if(!strcmp($my_part,$part)) echo("<b>");?><A HREF="./?part=<?echo $my_part;?>"><?echo $my_part;?></A><?if(!strcmp($my_part,$part)) echo("</b>");?> ]

&nbsp;&nbsp;

<?

}

if(!$page) {

   $page = 1;

}

$num_per_page = 3;

$page_per_block = 10;

########## 파일이 저장될 자료실의 디렉토리를 설정한다. ##########

$savedir = "../../ecard/img_files";

########## 현재페이지의 범위내에 출력할 결과레코드세트를 얻는다. ##########

$query = "SELECT uid,cat1,cat2,file FROM ecard WHERE cat1='$part' 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);

?>

<table width=500 border=0 cellpadding=0 cellspacing="0" align="center">

<tr>

   <td bgColor="#FFFFFF">

<table border="0" width="500" align="center" cellspacing="1" cellpadding="2">

<?

$time_limit = 60*60*24*$notify_new_article;

########## 게시물의 가상번호(게시물의 개수에 따른 일련번호) ##########

$article_num = $total_record - $num_per_page*($page-1);

$j=0;

for($i = $first; $i <= $last; $i++) {

   $my_uid = mysql_result($result,$i,0);

   $my_cat1 = mysql_result($result,$i,1);

   $my_cat2 = mysql_result($result,$i,2);

   $my_file = mysql_result($result,$i,3);

   if(!$j) {

           echo("<tr>");

           $j ++;

   }

?>

<td width='150' align="center">

   <?

   if($my_cat2 == "0") echo("<img src=\"$savedir/$my_file\" border=\"0\" hspace=\"2\" width='150' height='113'> ");

   else {

   ?>

<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width=150 height=113>

<param name="movie" value="<?echo("$savedir/$my_file");?>">

<embed src="<?echo("$savedir/$my_file");?>" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width=150 height=113>

</embed>

</object>

   <?

   }

   ?>

<a href="./?part=<?echo("$part")?>&task=step1&number=<?echo("$my_uid")?>&page=<?echo("$page")?>">선택</a>

</td>

   

<?

   if($j==3) {

           echo("</tr>");

           $j = 0;

   }

}

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=\"index.html?part=$part&page=$my_page\" >[이전 ${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?part=$part&page=$direct_page\">[$direct_page]</a></font>");

   }

}

########## 다음페이지블록에 대한 페이지 링크 ##########

if($block < $total_block) {

   $my_page = $last_page+1;

   echo("<font size=2><a href=\"index.html?part=$part&page=$my_page\" 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="index.html?part=<?echo("$part")?>&" >목록</a>

   </td>

   <td align="right"><font size=2>

<?

########## 이전페이지가 존재할 경우 이전페이지로 가는 링크를 활성화시킨다. ##########

if ($page > 1) {

   $page_num = $page - 1;

   echo("<a href=\"index.html?part=$part&page=$page_num\">이전</a> | ");

} else {

   echo("이전 | ");

}

########## 게시물이 다음페이지에도 존재할 경우 다음페이지로 가는 링크를 활성화시킨다. ##########

if ($IsNext > 0) {

   $page_num = $page + 1;   

   echo("<a href=\"index.html?part=$part&page=$page_num\">다음</a> </td>");

} else {

   echo("다음</td>");

}

?>

</tr>

</table>

 

파일명 : leelab-step1.html

1단계로 받는사람과 보내는 사람, 내용을 입력하는 곳입니다.

 

<?

session_start();

 

if(!$user_id || !$user_name) {

        echo "<SCRIPT>location.replace('../login.html');</SCRIPT>";

        exit;

}

 

########## 파일이 저장될 자료실의 디렉토리를 설정한다. ##########

$savedir = "../../ecard/img_files";

 

########## 선택한 게시물의 입력값을 뽑아낸다. ##########

$query = "SELECT uid,cat1,cat2,file FROM ecard WHERE uid = $number";

$result = mysql_query($query);

if(!$result) {

   error("QUERY_ERROR");

   exit;

}

$row1 = mysql_fetch_row($result);

 

$my_uid = $row1[0];

$my_cat1 = $row1[1];

$my_cat2 = $row1[2];     

$my_file = $row1[3];

 

if(!$fromName) $fromName = $member_name;

if(!$fromMail) $fromMail = $member_email;

 

?>

<script language=javascript>

function submitWhere(address)

{

f=document.formMain;

f.task.value = address;

 

f.submit();

}

</script>

<form name=formMain method=post action='./'>

<table width="428" border="0" cellspacing="0" cellpadding="0">

<tr>

<td align="center">   <?

   if($my_cat2 == "0") echo("<img src=\"$savedir/$my_file\" border=\"0\" hspace=\"2\"> ");

   else {

   ?>

<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width=400 height=300>

<param name="movie" value="<?echo("$savedir/$my_file");?>">

<embed src="<?echo("$savedir/$my_file");?>" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width=400 height=300>

</embed>

</object>

   <?

   }

   ?></td>

</tr>

</table><br>

<table width="428" border="0" cellspacing="0" cellpadding="0">

<tr>

<td>받는사람</td>

</tr>

<tr>

<td>-------------------------------------------------------------</td>

</tr>

<tr>

<td height="40">이름 :

        <input type="text" name="toName" value="<?echo("$toName");?>" size="14" style="width=110; font: 9pt 굴림; border:1 solid #81B8A9;" onMouseOver = "this.style.backgroundColor = '#ECFEFA'" onMouseOut = "this.style.backgroundColor = '#FFFFFF'"">&nbsp;&nbsp;&nbsp;

        E-Mail :

        <input type="text" name="toMail" value="<?echo("$toMail");?>" width="20" size="20" style="width=150; font: 9pt 굴림; border:1 solid #81B8A9;" onMouseOver = "this.style.backgroundColor = '#ECFEFA'" onMouseOut = "this.style.backgroundColor = '#FFFFFF'"">

</td>

</tr>

<tr>

<td>-------------------------------------------------------------</td>

</tr>

<tr>

<td>보내는 사람</td>

</tr>

<tr>

<td>-------------------------------------------------------------</td>

</tr>

<tr>

<td height="40">이름 :

        <input type="text" name="fromName" value="<?echo("$fromName");?>" size="14" maxlength="20" style="width=110; font: 9pt 굴림; border:1 solid #81B8A9;" onMouseOver = "this.style.backgroundColor = '#ECFEFA'" onMouseOut = "this.style.backgroundColor = '#FFFFFF'"">

        &nbsp;&nbsp;&nbsp;

        E-Mail :

        <input type="text" name="fromMail" value="<?echo("$fromMail");?>" readonly width="20" size="20" maxlength="30" style="width=150; font: 9pt 굴림; border:1 solid #81B8A9;" onMouseOver = "this.style.backgroundColor = '#ECFEFA'" onMouseOut = "this.style.backgroundColor = '#FFFFFF'"">

</td>

</tr>

<tr>

<td height="22">&nbsp;&nbsp;<font color="#666666">*

        보내는 이메일주소가 잘못된 경우 개인정보변경에서 수정을 하시면 됩니다.</font></td>

</tr>

<tr>

<td>-------------------------------------------------------------</td>

</tr>

<tr>

<td> &nbsp; <br>

        <textarea name="content" cols="60" style="width=415; font: 9pt 굴림; border:1 solid #666666;" rows="10" onMouseOver = "this.style.backgroundColor = '#F2F0F0'" onMouseOut = "this.style.backgroundColor = '#FFFFFF'""><?echo("$content");?></textarea>

</td>

</tr>

<tr>

<INPUT TYPE="hidden" name="part" value="<?echo("$part");?>">

<INPUT TYPE="hidden" name="number" value="<?echo("$number");?>">

<INPUT TYPE="hidden" name="page" value="<?echo("$page");?>">

<INPUT TYPE="hidden" name="task" value="">

<td align="right"><INPUT TYPE="button" onclick='submitWhere("preview");' value="미리보기">&nbsp;&nbsp;&nbsp;<INPUT TYPE="button"  onclick='submitWhere("send");' value="보내기">&nbsp;&nbsp;&nbsp;</td>

</tr>

 

</table>

</form>

 

파일명 : leelab-preview.html

미리보기 화면입니다.

 

<?

session_start();

 

if(!$user_id || !$user_name) {

        echo "<SCRIPT>location.replace('../login.html');</SCRIPT>";

        exit;

}

 

########## 파일이 저장될 자료실의 디렉토리를 설정한다. ##########

$savedir = "../../ecard/img_files";

 

########## 선택한 게시물의 입력값을 뽑아낸다. ##########

$query = "SELECT uid,cat1,cat2,file FROM ecard WHERE uid = $number";

$result = mysql_query($query);

if(!$result) {

   error("QUERY_ERROR");

   exit;

}

$row1 = mysql_fetch_row($result);

 

$my_uid = $row1[0];

$my_cat1 = $row1[1];

$my_cat2 = $row1[2];     

$my_file = $row1[3];

?>

<script language=javascript>

function submitWhere(address)

{

f=document.formMain;

f.task.value = address;

 

f.submit();

}

</script>

<form name=formMain method=post action='./'>

 

<TABLE width="500" border="0" cellspacing="0" cellpadding="0">

<TR>

        <TD align="center">

   <?

   if($my_cat2 == "0") echo("<img src=\"$savedir/$my_file\" border=\"0\" hspace=\"2\"> ");

   else {

   ?>

<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width=400 height=300>

<param name="movie" value="<?echo("$savedir/$my_file");?>">

<embed src="<?echo("$savedir/$my_file");?>" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width=400 height=300>

</embed>

</object>

   <?

   }

   ?>

   </TD>

</TR>

<TR>

        <TD align=center>

        <TABLE width=400 height=100 bgcolor=#EEEEEE border=1 cellspacing="0" cellpadding="0">

<TR>

        <TD><ul>

        Dear <b><?echo("$toName");?></b><p>

<?echo(htmlspecialchars(nl2br($content)));?>

</ul></TD>

</TR>

</TABLE>

        </TD>

</TR>

<TR>

<INPUT TYPE="hidden" name="part" value="<?echo("$part");?>">

<INPUT TYPE="hidden" name="number" value="<?echo("$number");?>">

<INPUT TYPE="hidden" name="page" value="<?echo("$page");?>">

<INPUT TYPE="hidden" name="task" value="">

 

<INPUT TYPE="hidden" name="toName" value="<?echo("$toName");?>">

<INPUT TYPE="hidden" name="toMail" value="<?echo("$toMail");?>">

<INPUT TYPE="hidden" name="fromName" value="<?echo("$fromName");?>">

<INPUT TYPE="hidden" name="fromMail" value="<?echo("$fromMail");?>">

<INPUT TYPE="hidden" name="content" value="<?echo("$content");?>">

<td align="center"><INPUT TYPE="button" onclick='submitWhere("step1");' value="수정하기">&nbsp;&nbsp;&nbsp;<INPUT TYPE="button"  onclick='submitWhere("send");' value="보내기">&nbsp;&nbsp;&nbsp;</td></TR>

</TABLE>

</form>

 

파일명 : leelab-send.html

보내기 화면입니다.

 

<?

session_start();

 

if(!$user_id || !$user_name) {

        echo "<SCRIPT>location.replace('../login.html');</SCRIPT>";

        exit;

}

 

########## 파일이 저장될 자료실의 디렉토리를 설정한다. ##########

$savedir = "http://www.leelab.co.kr/bbs/ecard/img_files";

// 본인의 사이트에 맞게 수정하기 바랍니다.

 

########## 선택한 게시물의 입력값을 뽑아낸다. ##########

$query = "SELECT uid,cat1,cat2,file FROM ecard WHERE uid = $number";

$result = mysql_query($query);

if(!$result) {

   error("QUERY_ERROR");

   exit;

}

$row1 = mysql_fetch_row($result);

 

$my_uid = $row1[0];

$my_cat1 = $row1[1];

$my_cat2 = $row1[2];     

$my_file = $row1[3];

 

$text = "<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 align=\"center\">";

 

if($my_cat2 == "0") $text .= "<img src=\"$savedir/$my_file\" border=\"0\" hspace=\"2\">";

else {

        $text .= "<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash\" width=400 height=300><param name=\"movie\" value=\"$savedir/$my_file\"><embed src=\"$savedir/$my_file\" pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width=400 height=300></embed></object>";

}

$text .= "

  </TD>

</TR>

<TR>

        <TD align=center>

        <TABLE width=400 height=100 bgcolor=#EEEEEE border=1 cellspacing=\"0\" cellpadding=\"0\">

<TR>

        <TD><ul>

Dear <b>$toName</b><p>

$content</ul></TD>

</TR>

</TABLE>";

 

$headers .= "From: $fromMail($fromName)\r\n";

$headers .= "X-Mailer: Lee LAB\r\n";

 

$headers .= "Content-Type: text/html; charset=euc-kr\r\n";

$body .= $text;

 

$subject = $my_cat1;

mail($toMail,$subject,$body,$headers);

 

echo "

 

<TABLE WIDTH=100%>

<TR>

<TD HEIGHT=280 VALIGN=MIDDLE ALIGN=CENTER><FONT SIZE=2 COLOR=BLUE>메일을 발송하였습니다.</FONT></TD>

</TR>

</TABLE>

";

 

?>

 

 

[목차]

개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.