<?php
include("../common.php");
include("common.php");
//============
$titleHeader = $this_section;
//============
$blog = new Blog();
$Cats = new Cats();
$pDateC = $pDate;//stupid, no other way, for javascript var
$id = $_REQUEST["id"];
//navigation ---------------------------------------------------------------------------------
$sql = "SELECT child.*,parent.ID as catID,parent.title as catTitle, 
grandparent.ID as parentID,grandparent.title as parentTitle 
FROM ".$Cats->table." grandparent, ".$Cats->table." parent, ".$blog->table." child 
WHERE parent.ID = child.catID and grandparent.ID=parent.parentID and child.ID=$id order by child.ID asc";	
$t = mysql_query($sql);
$row = mysql_fetch_array($t);
$parentID = $row["parentID"];
$parentTitle = $row["parentTitle"];
$catTitle = $row["catTitle"];
$catID = $row["catID"];
$hotnet = $id.".html";
$nav = "<a  href='/'>Home &gt;&gt;</a> <a  href='.'>".$this_section." &gt;&gt; </a>
$parentTitle &gt;&gt; <a  href='$catID/'>$catTitle</a> &gt;&gt; <a href='".BLOG_PATH."$hotnet'>".$row["subject"]."</a>";	
//------------------------------------------------------------------------------------------
$isSuperMaster = false;
if(c$sys["isAdmin"] || $sys["isSuperMaster"] || $sys["isMaster"]){
	$go = true;
	$isSuperMaster = true;
}
//----------------------------------access right end
if($_POST["st"]=="reply" && $pDateC==passDecode($_POST["auth"])){
	request($blog->fields,array("pDate"));
	$subject = norm($subject);		
	$content = norm($content);
	$tags = norm($tags);	
	$rootID = $id;
	$parentID = $id;
	$postDate = $pTime;
	$ip = $_SERVER['REMOTE_ADDR'];
	//======== user face caching in db for fast loading
	/*if($_SESSION[C_memberID] && $_REQUEST["bbs_hidden"]!="checked"){
		$userID = $_SESSION[C_memberID];
		$Member = new Member();
		$Member->setID($_SESSION[C_memberID]);
		$sex = $Member->row["sex"];				
		$photo_small = $Member->row["photo_small"];
		$face = $Member->row["face"];
		$username = $Member->row["nickname"]==""?$Member->row["user"]:$Member->row["nickname"];
		$blog_url = "$site/space/".urlencode($username)."";	
		$blogStr = "<a class=link target=_blank href='$blog_url'>".$username."</a> <input size=40 onclick='this.select()' type=text style='border:#cccccc 1px dotted;' value='$blog_url'>";		
		if($photo_small)
			$face = "<a target=_blank href='$blog_url'><img width=48 height=48 src='/chat/userphotos/".$_SESSION[C_memberID]."_small.".$photo_small."' style='border:#FFFFFF 2px solid' align=absmiddle></a> $blogStr";
		else if($face)
			$face = "<a target=_blank href='$blog_url'><img width=48 height=48 src='/bbs/userface/".$face.".gif' style='border:#FFFFFF 2px solid' align=absmiddle></a> $blogStr";
		else if($sex=="0"){
			$face = "<a target=_blank href='$blog_url'><img src='/images/cool/face_boy_mid.gif' border=0 align=absmiddle></a> $blogStr";	
		}
		else if($sex=="1"){
			$face = "<img src='/images/cool/face_girl_mid.gif' border=0 align=absmiddle> $blogStr";
		}
	}
	else{
		$face = "<img src='/images/cool/face_unknow.gif' border=0 align=absmiddle style='border:#FFFFFF 2px solid'> Î´ÑéÖ¤ÓÃ»§ $user";
	}*/
	$face = "";
	$face = addslashes($face);
	$room = $row["room_max"]+1;		
	$sql = sqlInsert($blog->table,$blog->fields,array("num_bbs","num_series","series_parentID"));
	if(mysql_query($sql)){					
 		$blog->add_bbs($id);
		$msg = "You have posted successfully!";
	}
	else
		$msg = "Failed to reply";
}
else if($isSuperMaster && $_POST["Submit"]=="Delete selected info"){
	//=============================
	$dArr = array();
	$j = 0;
	for($i=0;$i<$num_list;$i++){
		$d = "d".$i;
		$d = $_REQUEST[$d];
		if($d){
			$dArr[$j]= $d;
			$j++;
		}	
	}
	//=============================
	$cc = count($dArr);
	for($i=0;$i<$cc;$i++){
		$bbsID = $dArr[$i];
		if(mysql_query("delete from $blog->table where ID='$bbsID'")){			
			$blog->remove_bbs($id);
		}		
	}	
}
if($isSuperMaster){
	$photoPost = "  <a href='javascript:' onclick=addimage()><strong>[</strong>Photo<img src='/library/htmlarea/images/ed_image.gif' width='18' height='18' align='absmiddle' border='0'  style='cursor: hand;'></a><strong>]</strong>";
	$deleteAdmin = "<input type=button value='un-Select all' onclick='check_all(0)'><input type=button value='Select all' onclick='check_all(1)'><input onclick='return remind()' type=submit name=Submit value='Delete selected info'>";
}
//======================hits
mysql_query("update $blog->table set hits=hits+1 where ID=$id");
$titleHeader = $this_section;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<META name="description" content="<?=$_meta_des?>">
<META name="keywords" content="<?=$_meta_keyword?>">
<meta name="robots" content="follow,index">
<title><?=$titleHeader?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="<?=BLOG_PATH?>include/style.css" type="text/css">
<? include($tps."elements/meta.inc")?>
<script language="javascript">
var max_len = 450;
function resize(elem) {
  if (elem == undefined || elem == null) return false;
  if (elem.width > max_len) elem.width = max_len;  
}
</script>
</HEAD>
<BODY>
	<div id="wrapper"> 
    <? include($tps."elements/header.php")?>		
	 <div id="main_body2">       
      		<div id="col_l">
         	<? include("panel_more.htm")?>
	  		</div>		  
            <div id="col_r">
        <div class="title" style="padding-bottom:15px;"><img src="/images/photo/blog_title.jpg" width="160" height="76" /></div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            
            <td  valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                <tr> 
                  <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr> 
                        <td height="18"> 
                          <?=$nav?>
                        </td>
                      </tr>
                    </table></td>
                </tr>
                <tr> 
                  <td align="center"> 
                    <?=$msg1?>
                  </td>
                </tr>
                <tr> 
                  <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                      <tr> 
                        <td valign="top"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                            <tr> 
                              <td align="center"> 
                                <?=$msg1?>
                              </td>
                            </tr>
                            <tr> 
                              <td valign="top"> 
                                <!------- search result start ------>
                                <table width="100%" height="66"  border="0" cellpadding= "cellspacing=0">
                                  <tr> 
                                    <td height="30" align="left" valign="middle"><a href='<?=$ID?>'> 
                                      <?=$subject?>
                                      </a></td>
                                  </tr>
                                  <tr> 
                                    <td height="30" align="middle" valign="middle"> 
                                      <?php
$condStr = " where rootID='$id' and parentID<>'0'";
$sortStr = "";
If($sortBy) $sortStr = " order by $sortBy"; else  $sortStr = " order by ID desc"; 	
if (!isset($step)) $step = 5;
if (!isset($from)) $from = 0;
$sql="SELECT * FROM $table_details $condStr $sortStr limit ".$from.",".$step;
$tsql = "SELECT count(ID) as total from $table_details $condStr";
$result = mysql_query($sql) or die(mysql_error());
$tquery = mysql_query($tsql) or die(mysql_error());
$trows = mysql_fetch_array($tquery);
$count = $trows['total'];
if($count == "0") echo "Your search yielded no result.<br>";
?>
                                      <div class="head"><?php echo $msg?> 
                                        <?=search_results($from,$step,$count);?>
                                      </div>
                                      <table width="100%" cellspacing="0" cellpadding="5">
                                        <?php
$str=$color='';
$swapC = "";
$c = 0;
$bgcolorC = 0;
echo "<form name='form3' action='hotnet_bbs' method='post'>";
while($row2=mysql_fetch_array($result)){ 
	echo "<table width=100% cellpadding=0 cellspacing=0>";
	$ID = $row2["ID"];
	$subject = bbs_decode($row2["subject"]); 
	$user = $row2["user"];
	$pDate = $row2["postDate"];
	if($row2["face"]!="")
		$face = $row2["face"];
	else
		$face = "";	
	$smile = $row2["smile"];
	if($smile) {
		$smile = $smile.".gif";
		$smile = "<img src='/library/bbs/images/smile/$smile' align=absmiddle>";
	}
	//$str = _substr(htmlencode($row2["content"]),299);
	//$chars = count($row2["content"]);
	//$str = fsubstr(($row2["content"]), 0, 299,$chars,"hotnet_bbs_details?id=$ID");
	//$str = str_replace("\n","<br>",$str);
	$str = bbs_decode($row2["content"]);
	$d = "d".$c;
	$c++;	
	if($isSuperMaster){
		$edit = "<input name=$d type=checkbox value='$ID'> ".$row2["ip"]."  
		 <b>[</b><a href=javascript:act('hotnet_bbs_edit?id=$id&detailID=$ID',680,550)>Edit</a><b>]</b><br>";		
	}
	else{
		$pos = strrpos($ip,".");
		$ip = substr($ip,0,$pos).".*";
		$edit = "";
	}
	if($row2["tags"])
		$tagStr2 = "<div style='padding-top:10px'>".tag_to_link($row2["tags"],BLOG_PATH."tag")."</div>";
	else
		$tagStr2 = "";	
	echo "<tr><td><table width=100% cellspacing=0 cellpadding=5 style='border-bottom:#333333 1px solid'>
	<tr><td class='title_white'><font style='color:#FFFFFF;border:#FFCC00 1px solid;padding:1px;background:#000000;height:15px'> # ".$row2["room"]." </font>&nbsp;$smile $subject</td></tr><tr><td class='line_mid'>".$str."</td> 
	</tr><tr><td> $face <font class='small'>$pDate</font> $tagStr2</td></tr><tr><td>$edit</td></tr></table></td></tr><tr><td height=10></td></tr>";
	echo "<input type='hidden' name='num_list' value='$c'> </table>";
}
echo "<div align='center'>$deleteAdmin</div><input type='hidden' name='id' value='$id'></form>";
$param="sortBy=$sortBy&id=$id";
$colspan=1;
echo "<tr><td colspan=$colspan>".pages($from,$step,$count,$param)."</td></tr>";
?>
                                      </table></td>
                                  </tr>
                                </table>
                                <!------- search result end ------>
                              </td>
                            </tr>
                          </table></td>
                      </tr>
                    </table></td>
                </tr>
              </table></td>
          </tr>
        </table>
      </div>		
	  <!--col_r end-->
	  <div style="clear: both;">&nbsp;</div>	      
    </div>
	<? include($tps."elements/footer.php")?>
	</div>
</body>
</html>