<?php
/************************
Blog Class 2005 - 2007 - 2/2009,7/2010
Author: Shengjiang Lu
************************/
class Blog{
    var $fields = array("catID","rootID","parentID","userID","user","face","subject0","subject1","subject2","subject3",
						"content0","content1","content2","content3","access","postDate","tags","series_parentID","num_bbs","num_series","smile","ip","room","room_max","photo0");
	var $table = "blog_details";
	var $row;
	var $ID;
	var $catID;
	var $subject,$content,$tags;	
	var $access,$user,$userID;
	var $pDate;
	function Blog(){}
	function find($ID){
		$this->ID = $ID;
		$t = mysql_query("select * from $this->table where ID='$ID'");
		if($row=mysql_fetch_array($t)){
			$this->row = $row;
		}
	}
	function setID($ID){
		$this->ID = $ID;
		$t = mysql_query("select * from $this->table where ID='$ID'");
		if($row=mysql_fetch_array($t)){
			$this->row = $row;
		}
	}
	function add_series($ID){
		mysql_query("update $this->table set num_series=num_series+1 where ID='$ID'");
	}
	function remove_series($ID){
		mysql_query("update $this->table set num_series=num_series-1 where ID='$ID'");
	}
	function add_bbs($ID){
		mysql_query("update $this->table set num_bbs=num_bbs+1,room_max=room_max+1 where ID='$ID'");
	}
	function remove_bbs($ID){
		$sql = "update $this->table set num_bbs=num_bbs-1 where ID='$ID'";
		mysql_query($sql);
	}
	function score($action,$memberID){
		$score = 0;
		$wealth = 0;	
		switch($action){
		case "new_subject":
			$score = 2;
			$wealth = 1;
			$articleStr = "posts_blog=posts_blog+1,";
			break;
		case "reply":
			$score = 1;
			$wealth = 0.5;
			$articleStr = "posts_blog=posts_blog+1,";
			break;
		case "featured":
			$score = 2;
			$wealth = 1.5;
			break;
		case "delete":
			$score = -3;
			$wealth = -5;
			$articleStr = "posts_blog=posts_blog-1,";
			break;	
		}
		mysql_query("update Member set $articleStr wealth=wealth+$wealth,score=score+$score  where memberID='$memberID'");
		$this->user_update($memberID);
	}
	function user_update($memberID){
		$t_cl = mysql_query("select score from Member where memberID='$memberID'");
		$row_cl = mysql_fetch_array($t_cl);
		$user_class  = $row_cl["userClass"];
		$wealth = $row_cl["score"];
		if($wealth>50000)
			$user_class = "class13";
		else if($wealth>30000)
			$user_class = "class12";
		else if($wealth>10000)
			$user_class = "class11";
		else if($wealth>5000)
			$user_class = "class10";
		else if($wealth>4000)
			$user_class = "class9";
		else if($wealth>3000)
			$user_class = "class8";
		else if($wealth>2000)
			$user_class = "class7";
		else if($wealth>1000)
			$user_class = "class6";
		else if($wealth>500)
			$user_class = "class5";
		else if($wealth>100)
			$user_class = "class4";
		else if($wealth>50)
			$user_class = "class3";
		else if($wealth>0)
			$user_class = "class2";
		else 
			$user_class = "class1";															
		mysql_query("update Member set userClass='$user_class'  where memberID='$memberID'");
	}
	function getMAXID($where=""){
		$t = mysql_query("select max(ID) from $this->table $where");
	 	$row = mysql_fetch_array($t);
	 	$productID = $row[0];
		return $productID;
	}
}
?>