티스토리 뷰
1. show.php
<!-- 댓글 --> <form name="commentAdd" method="post" enctype="multipart/form-data"> <input type="hidden" name="cmtmode" value="insert"> <table> <input type="hidden" name="board_id" value="<?php echo $board_id?>" id="board_id"/> <input type="hidden" name="content_id" value="<?php echo $content_id?>" id="content_id"/> <input type="hidden" name="cmt_id" value="<?php echo $cmt_id?>" id="cmt_id"/> <colgroup> <col width="100px"> <col width="674px"> </colgroup> <tbody> <tr> <th>작성자</th> <td><input type="text" name="cmt_author" maxlength="5" id="cmt_author" value=""></td> </tr> <tr> <th>비밀번호</th> <td><input type="password" name="cmt_pwd" maxlength="4" id="cmt_pwd" value=""></td> </tr> <tr> <th>내용</th> <td><text name="cmt_content" maxlength="200" id="cmt_content" value=""></text></td> </tr> </tbody> </table> <button style="color: pink;" name="comment_Btn" id="comment_Btn" class="comment_Btn">등록</button> </form> <!-- //////////////////////////////////////////////////////////////////////////////////////////////////// --> <input type="hidden" name="page_id" id="page_id" value="<?php echo $page_id?>" /> <input type="hidden" name="board_id" id="board_id" value="<?php echo $board_id?>" /> <input type="hidden" name="content_id" id="content_id" value="<?php echo $content_id?>" /> <!-- <form method="post" id="comment_del" enctype="multipart/form-data"> --> <?php //hasCommentNext를 통해 리스트 계속 출력시킴 while($listComment = $boardComment->hasCommentNext()){ ?> <!-- hidden으로 cmtmode가 delete인 값을 index.php에서 찾아서 구동 --> <input type="hidden" name="cmtmode" value="delete"> <input type="hidden" name="cmt_author" value="<?php echo $listComment->cmt_author;?>"> <input type="hidden" name="cmt_content" value="<?php echo $listComment->cmt_content;?>"> <input type="hidden" name="cmt_date" value="<?php echo $listComment->cmt_date;?>"> <input type="hidden" name="cmt_id_del" id="cmt_id_del" value="<?php echo $listComment->cmt_id;?>"> <div id="show"> <!-- cmt_parent가 0인것은 메인댓글 --> <?php if($listComment->cmt_parent == 0){ ?> <hr> <span>글번호: <?php echo $listComment->cmt_id; ?></span>| <span>작성자: <?php echo $listComment->cmt_author; ?></span>| <span>내 용 : <?php echo nl2br($listComment->cmt_content); ?></span>| <span>작성일 : <?php echo $listComment->cmt_date; ?></span> <button style="color: pink;" name="display" id="display" class="display">댓글수정</button>| <button style="color: pink;" value="삭제" name="cmt_del" id="cmt_del" class="cmt_del" del_id="<?php echo $listComment->cmt_id;?>">삭제</button>| <button style="color: pink;" name="reply" id="reply" class="reply">답글작성</button> <?php //답댓글은 reply_resource로 가져와서 $listComment와 $listReply를 매칭시켜줌 $Reply=$boardComment->reply_resource; foreach($Reply as $listReply){ //답댓글은 답댓글의 cmt_parent 와 댓글의 cmt_id가 같을 시 cmt_id 하단에 생성 if($listReply->cmt_parent == $listComment->cmt_id){ ?> <br> <span>ㄴ글번호: <?php echo $listReply->cmt_id; ?></span>| <span>작성자: <?php echo $listReply->cmt_author; ?></span>| <span>내 용 : <?php echo nl2br($listReply->cmt_content); ?></span>| <span>작성일 : <?php echo $listReply->cmt_date; ?></span> <button style="color: pink;" name="reply_update_write" id="reply_update_write" class="reply_update_write" reply_update_write="<?php echo $listReply->cmt_pwd;?>">답글수정</button>| <button style="color: pink;" value="삭제" name="cmt_reply_del" id="cmt_reply_del" class="cmt_reply_del" del_reply_id="<?php echo $listReply->cmt_id;?>" reply_update_write="<?php echo $listReply->cmt_pwd;?>">답글삭제</button> <?php } } }?> </div> <!-- /////////////////////////////////////댓글수정//////////////////////////////////////////////////////// --> <div id="non_show" style="display: none;"> <form method="post" id="cmt_write"> <input type="hidden" name="cmtmode" value="update"> <!-- inputString은 비밀번호 프롬프트를 통해 값을 확인하여 비밀번호가 일치할 때만 수정 가능하도록 하기 위함 index.php에 값을 넘겨주기 위해 숨겨둠 --> <input type="hidden" name="inputString" value="inputString"> <input type="hidden" name="cmt_write_id" id="cmt_write_id" value="<?php echo $listComment->cmt_id;?>"> <input type="hidden" name="cmt_pwd" id="cmt_pwd" value="<?php echo $listComment->cmt_pwd;?>"> <span>글번호: <?php echo $listComment->cmt_id; ?></span>| <span>작성자: <input type="text" name="cmt_write_author" id="cmt_write_author" style="width: 100px" value="<?php echo $listComment->cmt_author; ?>"></span>| <span>내 용 : <input type="text" name="cmt_write_content" value="<?php echo nl2br($listComment->cmt_content); ?>"></span>| <button style="color: pink;" value="수정" name="cmt_write" id="cmt_write" class="cmt_write">수정</button>| </form> <button style="color: pink;" name="display1" id="display1" class="display1">수정취소</button> </div> <!-- /////////////////////////////////////답댓글//////////////////////////////////////////////////////// --> <div id="reply" style="display: none;"> <form method="post"> <input type="hidden" name="cmtmode" value="reply_insert"> <!-- 달고자 하는 댓글의 parent ID 설정 --> <input type="hidden" name="cmt_reply_id" id="cmt_reply_id" value="<?php echo $listComment->cmt_id;?>" /> <span>작성자: <input type="text" name="cmt_reply_author" maxlength="5" id="cmt_reply_author" style="width: 100px" value=""></span>| <span>비밀번호: <input type="password" name="cmt_reply_pwd" maxlength="4" id="cmt_reply_pwd" style="width: 50px" value=""></span>| <span>내 용 : <input type="text" name="cmt_reply_content" maxlength="200" id="cmt_reply_content" style="width: 250px" value=""></span>| <button style="color: pink;" name="reply_write" id="reply_write" class="reply_write">답글등록</button> </form> <button style="color: pink;" name="reply1" id="reply1" class="reply1">등록취소</button> </div> <!-- /////////////////////////////////////답댓글수정//////////////////////////////////////////////////////// --> <div id="reply_write" style="display: none;"> <form method="post" id="cmt_reply_update"> <?php $Reply=$boardComment->reply_resource; foreach($Reply as $listReply){ //답댓글 수정할 때 댓글은 빼고 답댓글만 수정하게 하기 위해서 설정 if($listReply->cmt_id != $listComment->cmt_id && $listReply->cmt_parent == $listComment->cmt_id){?> <input type="hidden" name="cmtmode" value="reply_update"> <!-- 달고자 하는 댓글의 parent ID 설정 --> <input type="hidden" name="cmt_reply_update_id" id="cmt_reply_update_id" value="<?php echo $listReply->cmt_id;?>" /> <input type="hidden" name="inputString_reply_update" value="inputString_reply_update"/> <span>글번호: <?php echo $listReply->cmt_id; ?></span>| <span>작성자: <input type="text" name="cmt_reply_update_author" maxlength="5" id="cmt_reply_update_author" style="width: 100px" value="<?php echo $listReply->cmt_author;?>" /></span>| <span>내 용 : <input type="text" name="cmt_reply_update_content" maxlength="200" id="cmt_reply_update_content" style="width: 250px" value="<?php echo $listReply->cmt_content;?>" /></span>| <?php } }?> <button style="color: pink;" name="reply_update_write_end" id="reply_update_write_end" class="reply_update_write_end" >답글수정완료</button> </form> <button style="color: pink;" name="reply2" id="reply2" class="reply2">수정취소</button> </div> <?php } ?>2. java script
jQuery(function($) { $("#comment_Btn").click(function() { if ($("#cmt_author").val() == "") { alert("이름을 입력하세요."); $("#cmt_author").focus(); return false; } else if ($("#cmt_pwd").val() == "") { alert("비밀번호를 입력하세요."); $("#cmt_pwd").focus(); return false; } else if ($("#cmt_content").val() == "") { alert("댓글 내용을 입력하세요."); $("#cmt_content").focus(); return false; } }) $(".cmt_del").click(function() { var id = $(this).attr("del_id"); var page_id = $("#page_id").attr("value"); var board_id = $("#board_id").attr("value"); var content_id = $("#content_id").attr("value"); var inputString = prompt('비밀번호를 입력하세요', ''); location.href = "/?page_id=" + page_id + "&board_id=" + board_id + "&page=show&content_id=" + content_id + "&cmtmode=delete&del_id=" + id + "&inputString=" + inputString; return false; }) $(".cmt_reply_del").click(function() { var inputString = prompt('비밀번호를 입력하세요', ''); var id = $(this).attr("del_reply_id"); var page_id = $("#page_id").attr("value"); var board_id = $("#board_id").attr("value"); var content_id = $("#content_id").attr("value"); location.href = "/?page_id=" + page_id + "&board_id=" + board_id + "&page=show&content_id=" + content_id + "&cmtmode=reply_delete&del_reply_id=" + id + "&inputString=" + inputString; return false; }) $(".display").click(function() { // 댓글수정 $(this).parent().next().css("display", "block"); // $(this).parent().css("display", "none"); }) $(".display1").click(function() { $(this).parent().prev().css("display", "block"); $(this).parent().css("display", "none"); }) $(".reply").click(function() { // 답글 작성 $(this).parent().next().next().css("display", "block"); // $(this).parent().css("display", "none"); }) $(".reply1").click(function() { // 답글 수정 취소 $(this).parent().prev().prev().css("display", "block"); $(this).parent().css("display", "none"); }) $(".reply_update_write").click(function() { // 답댓글 수정 $(this).parent().next().next().next().css("display", "block"); // $(this).parent().css("display", "none"); }) $(".reply2").click(function() { // 답댓글 수정취소 $(this).parent().next().next().next().css("display", "block"); $(this).parent().css("display", "none"); }) $(".cmt_write").click(function() { // 댓글 수정 var inputString = prompt('비밀번호를 입력하세요', ''); $("input:hidden[name='inputString']").val(inputString); var url = location.href; document.cmt_write.action = url; document.cmt_write.submit(); }) $(".reply_update_write_end").click(function() { // 답댓글 수정 var inputString_reply_update = prompt('비밀번호를 입력하세요', ''); $("input:hidden[name='inputString_reply_update']").val(inputString_reply_update); var url = location.href; document.cmt_reply_update.action = url; document.cmt_reply_update.submit(); }) });
'개발기록 > PHP' 카테고리의 다른 글
GNB 하단 이미지 페이지별로 다르게 넣고 싶을 때 (0) | 2017.04.13 |
---|---|
PC+MOBILE 일 경우 상단바 수정 (0) | 2017.04.13 |
버튼 클릭시 이메일로 내용 전송하기 (0) | 2017.04.05 |
라디오 버튼 선택 값 다른 페이지에서 불러오기 (0) | 2017.04.05 |
사용자페이지 내의 관리자화면 설정 (0) | 2017.04.05 |
댓글