<?php
require_once "BaseDB.class.php";
// ログインをするクラス
class Comment extends BaseDB
{
public function loadComment( $comid='' )
{
$qstring = "select comid,topicid,dt,ipaddr,hostname,comname,mailaddr," .
"title,body from b_comments where comid=$comid";
//クエリを実行
$qresult = mysql_query($qstring);
if(!$qresult){
$this->errorm = "DB Error:[$qstring]";
$this->errors++;
return false;
}
if(!$fresult = mysql_fetch_array($qresult))
{
$this->errorm = "コメント情報がありません。";
$this->errors++;
return false;
}
$this->comid = $fresult['comid'];
$this->topicid = $fresult['topicid'];
$this->dt = $fresult['dt'];
$this->ipaddr = $fresult['ipaddr'];
$this->hostname = $fresult['hostname'];
$this->comname = $fresult['comname'];
$this->mailaddr = $fresult['mailaddr'];
$this->title = $fresult['title'];
$this->body = $fresult['body'];
return true;
}
public function saveComment() /* 投稿ボタンをおしたら */
{
if( $this->comid == 0 ){ /* comidがゼロの場合、新規登録 */
$qstring = "insert into b_comments (topicid,dt,ipaddr,hostname,comname,mailaddr,title,body)values(" .
"$this->topicid,NOW(),'$this->ipaddr','$this->hostname','$this->comname','$this->mailaddr','$this->title','$this->body')";
} else { /*コメントIDがある場合は、上書き登録になります。*/
$qstring = "update b_comments set ".
"comname = '$this->comname', ".
"mailaddr = '$this->mailaddr', ".
"title = '$this->title', ".
"body = '$this->body' ".
" where comid='$this->comid'";
}
//クエリを実行
$qresult = mysql_query($qstring);
if(!$qresult){
$this->errorm = "DB Error:[$qstring]";
$this->errors++;
return false;
}
return true;
}
public function getComments($topicid=0)
{
if( $topicid == 0 ){ /* $topicidのIDがゼロの場合は全てのコメントを取得します。コメント管理の時に使います */
$qstring = "select comid,topicid,DATE_FORMAT( dt,'%Y/%m/%d %T') as postdatef," .
"comname,mailaddr,title,body " .
" from b_comments order by comid";
} else { /* $topicidのIDがある場合はIDに紐づくコメントを取得します */
$qstring = "select comid,topicid,DATE_FORMAT( dt,'%Y/%m/%d %T') as postdatef," .
"comname,mailaddr,title,body " .
" from b_comments where topicid=$topicid order by comid";
}
//クエリを実行
$qresult = mysql_query($qstring);
if(!$qresult){
$this->errorm = "DB Error:[$qstring]";
$this->errors++;
echo $this->errorm ;
return false;
}
$all = array();
while( $rec = mysql_fetch_assoc($qresult) ){
$rec['bodyf'] = ereg_replace( "\n","<br>", $rec['body'] );
$rec['bodyf'] = ereg_replace( "<br><br>","</p>\n<p>", $rec['bodyf'] );
$rec['bodyf'] = '<p>' . $rec['bodyf'] . '</p>';
$all[] = $rec;
}
return $all;
}
public function deleteComment( $id ) /* 管理画面でコメントを削除する時に使います */
{
$qstring = "delete from b_comments where comid = $id";
//クエリを実行
$qresult = mysql_query($qstring);
if(!$qresult){
$this->errorm = "DB Error:[$qstring]";
$this->errors++;
return false;
}
return true;
}
// プロパティ参照
function __get( $property )
{
return $this->$property;
}
// プロパティセット
function __set( $property, $value )
{
$this->$property = $value;
}
} //クラス終了
?>
0 件のコメント:
コメントを投稿