1. 쪽지함 제작
페이지 정보
작성자 관리자 댓글 8건 조회 8,534회 작성일 21-05-16 17:18본문
1. 쪽지함 제작
첨부파일
- message_css.zip (1.5K) 53회 다운로드 | DATE : 2021-05-16 17:24:01
댓글목록
관리자님의 댓글
관리자 작성일
create table message (
num int not null auto_increment,
send_id char(20) not null,
rv_id char(20) not null,
subject char(200) not null,
content text not null,
regist_day char(20),
primary key(num)
);
관리자님의 댓글
관리자 작성일
header.php 수정
상단 메인메뉴에 쪽지함을 추가한다.
<div id="menu_bar">
<ul>
<li><a href="index.php">HOME</a></li>
<li><a href="message_form.php">쪽지함</a></li>
</ul>
</div>
관리자님의 댓글
관리자 작성일
message_view.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지함 > 쪽지보기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="message_box">
<h3 class="title">
<?php
$mode = $_GET["mode"];
$num = $_GET["num"];
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from message where num=$num";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
$send_id = $row["send_id"];
$rv_id = $row["rv_id"];
$regist_day = $row["regist_day"];
$subject = $row["subject"];
$content = $row["content"];
$content = str_replace(" ", " ", $content);
$content = str_replace("\n", "<br>", $content);
if ($mode=="send")
$result2 = mysqli_query($con, "select name from members where id='$rv_id'");
else
$result2 = mysqli_query($con, "select name from members where id='$send_id'");
$record = mysqli_fetch_array($result2);
$msg_name = $record["name"];
if ($mode=="send")
echo "송신 쪽지함 > 내용보기";
else
echo "수신 쪽지함 > 내용보기";
?>
</h3>
<ul id="view_content">
<li>
<span class="col1"><b>제목 :</b> <?=$subject?></span>
<span class="col2"><?=$msg_name?> | <?=$regist_day?></span>
</li>
<li>
<?=$content?>
</li>
</ul>
<ul class="buttons">
<li><button onclick="location.href='message_box.php?mode=rv'">수신 쪽지함</button></li>
<li><button onclick="location.href='message_box.php?mode=send'">송신 쪽지함</button></li>
<li><button onclick="location.href='message_response_form.php?num=<?=$num?>'">답변 쪽지</button></li>
<li><button onclick="location.href='message_delete.php?num=<?=$num?>&mode=<?=$mode?>'">삭제</button></li>
</ul>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>
관리자님의 댓글
관리자 작성일
message_box.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지함>목록보기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="message_box">
<h3>
<?php
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$mode = $_GET["mode"];
if ($mode=="send")
echo "송신 쪽지함 > 목록보기";
else
echo "수신 쪽지함 > 목록보기";
?>
</h3>
<div>
<ul id="message">
<li>
<span class="col1">번호</span>
<span class="col2">제목</span>
<span class="col3">
<?php
if ($mode=="send")
echo "받은이";
else
echo "보낸이";
?>
</span>
<span class="col4">등록일</span>
</li>
<?php
$con = mysqli_connect("localhost", "user1", "12345", "sample");
if ($mode=="send")
$sql = "select * from message where send_id='$userid' order by num desc";
else
$sql = "select * from message where rv_id='$userid' order by num desc";
$result = mysqli_query($con, $sql);
$total_record = mysqli_num_rows($result); // 전체 글 수
$scale = 10;
// 전체 페이지 수($total_page) 계산
if ($total_record % $scale == 0)
$total_page = floor($total_record/$scale);
else
$total_page = floor($total_record/$scale) + 1;
// 표시할 페이지($page)에 따라 $start 계산
$start = ($page - 1) * $scale;
$number = $total_record - $start;
for ($i=$start; $i<$start+$scale && $i < $total_record; $i++)
{
mysqli_data_seek($result, $i);
// 가져올 레코드로 위치(포인터) 이동
$row = mysqli_fetch_array($result);
// 하나의 레코드 가져오기
$num = $row["num"];
$subject = $row["subject"];
$regist_day = $row["regist_day"];
if ($mode=="send")
$msg_id = $row["rv_id"];
else
$msg_id = $row["send_id"];
$result2 = mysqli_query($con, "select name from members where id='$msg_id'");
$record = mysqli_fetch_array($result2);
$msg_name = $record["name"];
?>
<li>
<span class="col1"><?=$number?></span>
<span class="col2"><a href="message_view.php?mode=<?=$mode?>&num=<?=$num?>"><?=$subject?></a></span>
<span class="col3"><?=$msg_name?>(<?=$msg_id?>)</span>
<span class="col4"><?=$regist_day?></span>
</li>
<?php
$number--;
}
mysqli_close($con);
?>
</ul>
<ul id="page_num">
<?php
if ($total_page>=2 && $page >= 2)
{
$new_page = $page-1;
echo "<li><a href='message_box.php?mode=$mode&page=$new_page'>◀ 이전</a> </li>";
}
else
echo "<li> </li>";
// 게시판 목록 하단에 페이지 링크 번호 출력
for ($i=1; $i<=$total_page; $i++) {
if ($page == $i) { // 현재 페이지 번호 링크 안함
echo "<li><b> $i </b></li>";
} else {
echo "<li> <a href='message_box.php?mode=$mode&page=$i'> $i </a> <li>";
}
}
if ($total_page>=2 && $page != $total_page)
{
$new_page = $page+1;
echo "<li> <a href='message_box.php?mode=$mode&page=$new_page'>다음 ▶</a> </li>";
}
else
echo "<li> </li>";
?>
</ul> <!-- page -->
<ul class="buttons">
<li><button onclick="location.href='message_box.php?mode=rv'">수신 쪽지함</button></li>
<li><button onclick="location.href='message_box.php?mode=send'">송신 쪽지함</button></li>
<li><button onclick="location.href='message_form.php'">쪽지 보내기</button></li>
</ul>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>
관리자님의 댓글
관리자 작성일
message_insert.php
<meta charset='utf-8'>
<?php
$send_id = $_GET["send_id"];
$rv_id = $_POST['rv_id'];
$subject = $_POST['subject'];
$content = $_POST['content'];
$subject = htmlspecialchars($subject, ENT_QUOTES);
$content = htmlspecialchars($content, ENT_QUOTES);
$regist_day = date("Y-m-d (H:i)"); // 현재의 '년-월-일-시-분'을 저장
if(!$send_id) {
echo("
<script>
alert('로그인 후 이용해 주세요! ');
history.go(-1)
</script>
");
exit;
}
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from members where id='$rv_id'";
$result = mysqli_query($con, $sql);
$num_record = mysqli_num_rows($result);
if($num_record)
{
$sql = "insert into message (send_id, rv_id, subject, content, regist_day) ";
$sql .= "values('$send_id', '$rv_id', '$subject', '$content', '$regist_day')";
mysqli_query($con, $sql); // $sql 에 저장된 명령 실행
} else {
echo("
<script>
alert('수신 아이디가 잘못 되었습니다!');
history.go(-1)
</script>
");
exit;
}
mysqli_close($con); // DB 연결 끊기
echo "
<script>
location.href = 'message_box.php?mode=send';
</script>
";
?>
관리자님의 댓글
관리자 작성일
message_delete.php
<meta charset='utf-8'>
<?php
$num = $_GET["num"];
$mode = $_GET["mode"];
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "delete from message where num=$num";
mysqli_query($con, $sql);
mysqli_close($con); // DB 연결 끊기
if($mode == "send")
$url = "message_box.php?mode=send";
else
$url = "message_box.php?mode=rv";
echo "
<script>
location.href = '$url';
</script>";
?>
관리자님의 댓글
관리자 작성일
파일명 : message_response_form.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지함>답변쪽지 보내기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<section>
<div id="message_box">
<h3 id="write_title">답변 쪽지 보내기</h3>
<?php
$num = $_GET["num"];
$con = mysqli_connect("localhost", "user1", "12345", "sample");
$sql = "select * from message where num=$num";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
$send_id = $row["send_id"];
$rv_id = $row["rv_id"];
$subject = $row["subject"];
$content = $row["content"];
$subject = "RE: ".$subject;
$content = "> ".$content;
$content = str_replace("\n", "\n>", $content);
$content = "\n\n\n-----------------------------------------------\n".$content;
$result2 = mysqli_query($con, "select name from members where id='$send_id'");
$record = mysqli_fetch_array($result2);
$send_name = $record["name"];
?>
<form name="message_form" method="post" action="message_insert.php?send_id=<?=$userid?>">
<input type="hidden" name="rv_id" value="<?=$send_id?>">
<div id="write_msg">
<ul>
<li>
<span class="col1">보내는 사람 : </span>
<span class="col2"><?=$userid?></span>
</li>
<li>
<span class="col1">수신 아이디 : </span>
<span class="col2"><?=$send_name?>(<?=$send_id?>)</span>
</li>
<li>
<span class="col1">제목 : </span>
<span class="col2"><input name="subject" type="text" value="<?=$subject?>"></span>
</li>
<li id="text_area">
<span class="col1">글 내용 : </span>
<span class="col2">
<textarea name="content"><?=$content?></textarea>
</span>
</li>
</ul>
<button type="button" onclick="message_form.submit()">보내기</button>
</div>
</form>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>
관리자님의 댓글
관리자 작성일
message_fomr.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>쪽지보내기</title>
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/message.css">
</head>
<body>
<header>
<?php include "header.php";?>
</header>
<?php
if (!$userid )
{
echo("<script>
alert('로그인 후 이용해주세요!');
history.go(-1);
</script>
");
exit;
}
?>
<section>
<div id="message_box">
<h3 id="write_title">쪽지 보내기</h3>
<ul class="top_buttons">
<li><span><a href="message_box.php?mode=rv">수신 쪽지함 </a></span></li>
<li><span><a href="message_box.php?mode=send">송신 쪽지함</a></span></li>
</ul>
<form name="message_form" method="post" action="message_insert.php?send_id=<?=$userid?>">
<div id="write_msg">
<ul>
<li>
<span class="col1">보내는 사람 : </span>
<span class="col2"><?=$userid?></span>
</li>
<li>
<span class="col1">수신 아이디 : </span>
<span class="col2"><input name="rv_id" type="text"></span>
</li>
<li>
<span class="col1">제목 : </span>
<span class="col2"><input name="subject" type="text"></span>
</li>
<li id="text_area">
<span class="col1">내용 : </span>
<span class="col2">
<textarea name="content"></textarea>
</span>
</li>
</ul>
<button type="button" onclick="message_form.submit();">보내기</button>
</div>
</form>
</div> <!-- message_box -->
</section>
<footer>
<?php include "footer.php";?>
</footer>
</body>
</html>