Login | Join | OpenID | RSS Feed
코멘트 수정하기
최광용 Lv. 14 llllllllll 
487 hit since 2005/02/21 23:41

modify link 만들기

먼저 $a_del 형식의 modify link를 만든다. 제로보드에서 <?=$a_modify_comment>Modify</a> 형식으로 사용하게 되는 링크 변수다. zeroboard root에 있는 view.php 파일을 열고 코멘트 출력 부분을 찾는다.

if($c_data[ismember]) {
 if($c_data[ismember]==$member[no]||$is_admin||$member[level]<=$setup[grant_delete])
 {
  $a_del="<a onfocus=blur() href='del_comment.php?$href$sort&no=$no&c_no=$c_data[no]' title='Delete'>";
  $a_modify_comment = "<a onfocus=blur() href='view.php?id=$id&no=$data[no]&c_no=$c_data[no]&page=$page' title='Modify'>";
 }
 else
 {
  $a_del=" <Zeroboard ";
  $a_modify_comment = " <Zeroboard ";
 }
}
else
{
 $a_del="<a onfocus=blur() href='del_comment.php?$href$sort&no=$no&c_no=$c_data[no]'>";
 $a_modify_comment = " <Zeroboard ";
}

위와 같이 $a_del을 설정해 주는 부분이 있다. $a_modify_comment 변수도 적당히 설정해준다. Modify를 실행 해 주는 파일은 view.php, 즉 자기 자신이다. 코멘트를 쓸 때와 똑 같은 화면에서 코멘트를 수정하게 될 것이다.

코멘트 수정 버튼 만들기

Modify link가 만들어졌으니 이제 이것을 스킨에 추가한다. Skin 디렉토리에 보면 view_comment.php 파일이 존재한다. Modify 링크를 적당한 곳에 넣어준다.

<?=$a_modify_comment?>+</a>

코멘트 수정 화면 보여주기

앞에서도 언급했듯이 comment를 쓰는 화면과, 코멘트를 수정하는 화면은 같다. view.php에 넘겨주는 인수로 c_no가 있는데, 이것이 수정될 코멘트 번호이다. 수정을 하려면 이전 내용을 출력해 주어야 하므로 이미 DB에 기록된 comment를 읽어온다. view.php 파일 윗부분.

$_dbTimeStart = getmicrotime();
$data=mysql_fetch_array(mysql_query("select * from  $t_board"."_$id  where no='$no'"));
$_dbTime += getmicrotime()-$_dbTimeStart;

//cky
$ismember = $data[ismember];
if ($c_no)
{
// comment data
 $query = "select * from zetyx_board_comment_"."$id where no=$c_no";
 $res = mysql_query($query, $connect) or error(mysql_error());
 $row = mysql_fetch_array($res);
 
 $modify_comment = stripslashes(trim($row[memo])); // 기록된 comment

 if (!($member[no] == $row[ismember] || $is_admin))
 {
  error("뭔가 이상하다...");
 }
}

if(!$data[no]) Error("선택하신 게시물이 존재하지 않습니다","zboard.php?$href$sort");


그리고 보통 comment를 수정하는 부분이 페이지의 제일 아랫쪽에 있으므로 페이지를 강제로 스크롤 시켜서 맨 아래로 이동시킨다.

if ($c_no)
{
 ?>
 <script language=javascript>
 <!--
 
 var sRepeat=null;
 
 function doScrollerIE() {
  scroll (0, 1000);
  
  if (sRepeat == null) sRepeat = setInterval("doScrollerIE()", 100);
  
  return false;
 }
 
 window.document.onmouseout = new Function("clearInterval(sRepeat);sRepeat=null");
  
 window.document.ondragstart = new Function("return false");
 
 doScrollerIE();
 
 document.write.memo.focus();
 
 // -->
 </script>

<?
} // if ($c_no)


간단하게 구현 할 수 있을 것 같은데, scroll 함수만 가지고는 제대로 동작이 안 되었다.

다음으로 comment내용을 폼에 뿌려준다. skin 디렉토리의 view_write_comment.php에 $modify_comment를 넣어주면 된다.

<textarea name=memo rows=4 cols=87 class=rini_textarea><?=$modify_comment?></textarea></td>

그리고 c_no를 실제 기록하는 파일인 comment_ok.php에 알려줘야 하므로 hidden 속성들 밑에 추가해 넣는다.

<input type=hidden name=c_no value="<?=$c_no?>">

DB에 기록

DB 기록은 comment_ok.php가 한다. 기록 하기 전 c_no 값이 존재하면 이전의 data를 수정해준다. $name, $memo를 addslashes 시키는 부분 다음에 넣는게 적당하다고 생각된다. DB를 읽어서 c_no에 해당하는 comment가 존재하면 memo만 업데이트 해주고 페이지 이동한다.

// comment_modify
if ($c_no &gt; 0)
{
 // check
 $query = "select * from zetyx_board_comment_"."$id where no=$c_no";
 $res = mysql_query($query, $connect) or error(mysql_error());
 $row = mysql_fetch_array($res);
 
 if (!($member[no]==1 || $member[no]==$row[ismember]))
 {
  error("뭔가 이상하다.");
 }
 
 $query = "update zetyx_board_comment_"."$id set memo='$memo' where no=$c_no";
 mysql_query($query, $connect) or error(mysql_error());

 @mysql_close($connect);
 
// 페이지 이동
 movepage("$view_file_link?id=$id&page=$page&page_num=$page_num&select_arrange=$select_arrange&desc=$des&sn=$sn&ss=$ss&
    sc=$sc&keyword=$keyword&no=$no&category=$category");
 
}


아마도 더 체크해야 할 부분이나, 특수한 상황에서 제대로 동작하지 않는 부분이 있을지도 모르겠다. 고쳐야 될 곳을 발견하는 사람을 주저하지말고 이 글을 수정해 줄 것.