Q&A BBS

$mainTableHeader
$menuTd
HTML_CODE; // 변수명 변경 foreach($_REQUEST as $k=>$v) { $$k=trim($v); } ///////////////////////////////////////////////////////////////////////////////////////// // Initial Value include("db.inc"); if(!$P) { $P="L";} if(!$Q) { $Q="L";} if($id) { $P="R"; $Q="R"; } if($T) { $tmp=substr($T,0,1); $len=strlen($T); $idx=substr($T,1,$len); switch ($tmp) { case M: $P="M"; break; case D: $Q="D"; break; case R: $P="W"; break; } } ///////////////////////////////////////////////////////////////////////////////////////// // 쿼리분기 switch ($Q) { ///////////////////////////////////////////////////////////////////////////////////////// // Write mode case W: if ($html=="Y"){ $text= str_replace("\n","
",$text); } else { $text= str_replace("&","&",$text); $text= str_replace("<","<",$text); $text= str_replace("<","<",$text); $text= str_replace("'",""",$text); // $text= str_replace(" "," ",$text); $text= str_replace("\n","
",$text); // $text=nl2br($text); } $sql="INSERT INTO $table VALUES('','$name','$email','$pw','$title','$category','$homepage','$html','$text','$link',now(),'$hit','','','','') "; mysql_query($sql,$conn); if(!$idx) { // idx뽑기 $Msql="SELECT MAX(idx) FROM $table "; $MRS=mysql_query($Msql,$conn); $idx=mysql_result($MRS,0,0); // update 문 $Usql="UPDATE $table SET ref='$idx', ridx='$idx' WHERE idx='$idx' "; mysql_query($Usql,$conn); } else { // idx뽑기 $Msql="SELECT MAX(idx) FROM $table "; $MRS=mysql_query($Msql,$conn); $idx2=mysql_result($MRS,0,0); // 해당 idx에 대한 reply용 데이터 추출 $Msql="SELECT ref, re_level, re_step, ridx FROM $table WHERE idx='$idx' "; $MRS=mysql_query($Msql,$conn); $ref=mysql_result($MRS,0,0); $re_level=mysql_result($MRS,0,1); $re_step2=mysql_result($MRS,0,2); $ridx=mysql_result($MRS,0,3); // reply 에 대한 전체update $Usql="UPDATE $table SET ref='$ref', re_level='$re_level'+1, re_step='$re_step2', ridx='$idx' WHERE idx='$idx2' "; mysql_query($Usql,$conn); // echo"$Usql
"; $Usql2="UPDATE $table SET re_step=re_step+1 WHERE ref='$ref' AND re_step >= '$re_step2' AND idx not like '$idx' "; // echo"$Usql2
"; mysql_query($Usql2,$conn); } echo"
"; die; break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // List mode case L: // 전체게시물수 $TRS=mysql_query("SELECT COUNT(*) FROM $table ",$conn); $TN=mysql_result($TRS,0,0); // page 수 체크하기 if($page) {$page2=$page-1; $Start=$page2*$Limit; $SQL="LIMIT $Start, $Limit ";} else { $page=1; $SQL="LIMIT 0, $Limit ";} // 일반쿼리 $sql="SELECT * FROM $table WHERE 1 "; if($keyword) { $keylen=strlen($keyword); $type=substr($keyword,0,1); $keyword2=substr($keyword,2,$keylen); // echo"$keyword2"; $TYPE=strtoupper($type); switch ($TYPE) { case S: $sql.="AND title like '%$keyword2%' "; break; case T: $sql.="AND text like '%$keyword2%' "; break; case A: $sql.="AND title like '%$keyword2%' OR text like '%$keyword2%' "; break; } } $sql.="ORDER BY ref DESC, re_step ASC, idx DESC "; $sql.=$SQL; // echo"$sql"; $RS=mysql_query($sql,$conn); $N=mysql_num_rows($RS); // 오늘 게시물 $TodayRS=mysql_query("SELECT count(*) FROM $table WHERE left(date,10)=left(now(),10)",$conn); $TodayArticleNum=mysql_result($TodayRS,0,0); break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // read(detail) mode case R: $tmp=substr($id,0,1); if($tmp=="R") { $len=strlen($id); $id2=substr($id,1,$len); $sql="SELECT * FROM $table WHERE idx=$id2 "; } else { $sql="SELECT * FROM $table WHERE idx=$id "; } $RS=mysql_query($sql,$conn); $N=mysql_num_rows($RS); break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // modify mode case M: if ($html=="Y"){ $text= str_replace("\n","
",$text); } else { $text= str_replace("&","&",$text); $text= str_replace("<","<",$text); $text= str_replace("<","<",$text); $text= str_replace("'",""",$text); // $text= str_replace(" "," ",$text); $text= str_replace("\n","
",$text); // $text=nl2br($text); } $sql="UPDATE $table SET name='$name', email='$email', title='$title', category='$category', homepage='$homepage', html='$html', text='$text', link='$link' WHERE idx='$idx' "; mysql_query($sql,$conn); echo"
"; die; break; ///////////////////////////////////////////////////////////////////////////////////////// // delete mode case D: $CHK=mysql_query("SELECT * FROM $table WHERE idx='$idx' AND pw='$pw' ",$conn); $N=mysql_num_rows($CHK); if ($N==false) { echo" "; die; } else { $sql="DELETE FROM $table WHERE idx='$idx' AND pw='$pw' "; mysql_query($sql,$conn); echo"
"; die; } break; ///////////////////////////////////////////////////////////////////////////////////////// // tag message mode case T: $sql="INSERT INTO $table2 VALUES('','$name','$message',now(),'$gidx') "; mysql_query($sql,$conn); echo"
"; die; break; } /// 쿼리 분기 끝 //////////////////////////////////////////////////////////////////////////////////// ?> bbs > cellpadding=0 cellspacing=0 align=center>
>"; $Head="reply of ".$idx." article"; } else { $Head="write"; } echo"
$Head
Notice!! ... \"*\" must be fill.
* Name
* Password
E-mail
* Title
Homepage
Tag use Yes
* Contents
Link
 
"; break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // List mode case L: echo" "; if($N==1){ echo""; } if ($N==true) { for($a=0;$a<$N;$a++) { $idx=mysql_result($RS,$a,idx); // $category=mysql_result($RS,$a,category); $title=mysql_result($RS,$a,title); $hit=mysql_result($RS,$a,hit); $date=mysql_result($RS,$a,date); $Tdate=substr($date,0,10); $Today=date('Y')."-".date('m')."-".date('d'); $date2=substr($date,0,4).".".substr($date,5,2).".".substr($date,8,2); $name=mysql_result($RS,$a,name); $re_level=mysql_result($RS,$a,re_level); if($re_level>0) { for($b=0;$b<$re_level;$b++) { $re.="    ";} $re.="";} $NUM=$TN-(($page-1)*$Limit); $n=$NUM-$a; ////////////////////////////////////////////////////// tag message 갯수 $Tsql="SELECT count(*) FROM $table2 WHERE gidx='$idx'"; $ReS=mysql_query($Tsql,$conn); $TNUM=mysql_result($ReS,0,0); /////////////////////////////////////////////////////////////// echo" "; $re=""; } } else { echo" "; } $PageNum=ceil($TN/$Limit); // 전체 page 갯수 $ListNum=ceil($PageNum/$Limit2); // 전체 page list 갯수 echo""; ///////////////////////////////////////////////////////////////////////////////////////// echo"
\"today's : $TodayArticleNum / Total : $TN  
#TitleNameViewRegist date
"; echo""; } else { echo" bgcolor=$oddcolor>"; } echo"
$n $re $title "; if ($TNUM>0) {echo"($TNUM)"; } if ($Tdate==$Today) { echo"\"today's"; } echo" $name$hit$date2
No article exist.
total $PageNum page"; ////////////////////////////////////////////////////////////////////////////////////// // page list if($TN>$Limit) { if(!$PNL) { $PNL=0; $StartNum=0; $EndNum=$PageNum+1;} else { $StartNum=$Limit2*$PNL; $EndNum=$StartNum+$Limit2+1; } if($PNL>=1) { $PNL-=1; echo ""; $PNL+=1;} echo" [ "; $StartNum+=1; // echo"st=$StartNum"; if($EndNum>$PageNum) { for($L=$StartNum;$L<$EndNum;$L++) { if ($page==$L) { echo"$L"; } else {echo"$L"; } echo" "; } } echo"]"; if ($PNL+1<$ListNum) { $PNL+=1; echo "";} } echo"   
"; break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // read(detail) mode case R: $idx=mysql_result($RS,0,idx); $name=mysql_result($RS,0,name); $email=mysql_result($RS,0,email); $title=mysql_result($RS,0,title); $category=mysql_result($RS,0,category); $homepage=mysql_result($RS,0,homepage); $hlen=strlen($homepage); $html=mysql_result($RS,0,html); $text=mysql_result($RS,0,text); $link=mysql_result($RS,0,link); $date=mysql_result($RS,0,date); $hit=mysql_result($RS,0,hit); $ref=mysql_result($RS,0,ref); $re_level=mysql_result($RS,0,re_level); echo"
article infomation
Title  $title
Name  $name "; if($email) { echo"$email "; } if($hlen>7) { echo"$homepage "; } echo"
Regist date  $date
Link  $link
View  $hit
Content

$text

Comment~

"; // tag message 용 쿼리 $Tsql="SELECT * FROM $table2 WHERE gidx='$idx' ORDER BY idx DESC "; $ReS=mysql_query($Tsql,$conn); // echo"$Tsql"; $NN=mysql_num_rows($ReS); for($a=0;$a<$NN;$a++) { $tag_name=mysql_result($ReS,$a,name); $message=mysql_result($ReS,$a,message); $tag_date=mysql_result($ReS,$a,date); $tag_date=substr($tag_date,0,10); $tmp=$a%2; if($tmp==0) { echo""; } else {echo""; } echo""; } echo"
$tag_name ($tag_date) :  $message
Name : Comment :
 
"; // 삭제방지 쿼리 $Xsql="SELECT COUNT(*) FROM $table WHERE ref='$ref' AND re_level='$re_level'+1 AND ridx='$idx' "; // echo"$Xsql"; $XRS=mysql_query($Xsql,$conn); $XN=mysql_result($XRS,0,0); if($XN<1) { echo" "; } echo"
"; // 조회수 증가 $hit+=1; mysql_query("UPDATE $table SET hit='$hit' WHERE idx='$idx'",$conn); break; ///////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// // modify mode case M: $sql="SELECT * FROM $table WHERE idx=$idx "; $RS=mysql_query($sql,$conn); $N=mysql_num_rows($RS); $idx=mysql_result($RS,0,idx); $name=mysql_result($RS,0,name); $email=mysql_result($RS,0,email); $title=mysql_result($RS,0,title); $category=mysql_result($RS,0,category); $homepage=mysql_result($RS,0,homepage); $html=mysql_result($RS,0,html); $text=mysql_result($RS,0,text); $text=str_replace("
","",$text); $link=mysql_result($RS,0,link); $date=mysql_result($RS,0,date); $hit=mysql_result($RS,0,hit); echo"
Modify article
Notice!! \"*\" must fill.
* Name
* Password
E-mail
* Title
Homepage
Tag use Yes
* Content
Link
 
"; break; ///////////////////////////////////////////////////////////////////////////////////////// } ?>