<?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"];
list($id,$nothing) = split("-",$id,2);
//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"];
$nav = "<a href='/'>$_site_name home &gt;&gt;</a> <a href='.'>".$this_section." &gt;&gt; </a>
$parentTitle  <a class='gold' href='$catID/'>$catTitle</a>";
$path = path($row["postDate"]);	
//------------------------------------------------------------------------------------------

$isSuperMaster = false;
if($sys["isAdmin"] || $sys["isSuperMaster"] || $sys["isMaster"]){
	$go = true;
	$isSuperMaster = true;
}
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'];
	$face = $user;
	$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>";
	if($row["num_bbs"]>0)
		$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'>";
	$editAdmin = "<li style='list-style: square;'><a class='title_link' href='edit?id=$id&action=edit'>Edit this info</a></li><br/><br/>";
}
//======================hits
mysql_query("update $blog->table set hits=hits+1 where ID=$id");
?>
<!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><?=$row["subject"]?> - <?=$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>
function check(thisForm){
  var subject =thisForm.subject;  
  var fields = new Array(subject);
   //don't need to change the following lines 
  var error = false;
  var focusObj = null;
  var color1 = "#FF9900";
  var color2 = "#FFFFFF";
  
  for(i=0;i<fields.length;i++){
  	fields[i].style.background=color2;
	if(fields[i].value==""){
		fields[i].style.background=color1;
		if(!error)
			focusObj = fields[i];
		error=true;		
	}
  }  
  if(error){
  	focusObj.focus();
    alert("Please enter the required info in the highlight field.");
    return false;
  }
  else{
  	thisForm.auth.value="<?=passEncode($pDateC)?>";
    thisForm.Submit.value = "submitting ..."
  	thisForm.Submit.disabled = true;
    return true;
  }  
}
function remind(){
		var agree=confirm("Are you sure to delete this info? ");
		if (agree)
			return true ;
		else
			return false ;		
}
function add_tag(thisField){
	var tagField = document.form1.tags;
	if(tagField.value=="")
		tagField.value = thisField.value;
	else{
		if(tagField.value.indexOf(thisField.value)==-1)	
			tagField.value = tagField.value +" "+thisField.value;
	}	
}
function act(page,w,h){
	var win;   
   	win = open(page,"","location=no,directories=no,top=0, left=0,width="+w+",height="+h+",scrollbars=1,toolbar=0,resizable=1,status=1");
   	win.focus();		
}
function check_all(mode){
	with (document.forms["form3"]){
		if(mode==1){
			for (var n=0; n<elements.length; n++) {
				elements[n].checked = true;
			}
		}
		else if(mode==0){
			for (var n=0; n<elements.length; n++) {
				elements[n].checked = false;
			}
		}	
	}
}
var user = "";
function set_user(obj){
	if(obj.checked==true){
		user = document.form1.user.value;
		document.form1.user.value='Guest';
	}
	else{
		document.form1.user.value = user;
	}
}
</script>

<script type="text/javascript" src="../include/js/bbs_encode.js"></script>
<script language="javascript">
var max_len = 700;
function resize(elem) {
  if (elem == undefined || elem == null) return false;
  if (elem.width > max_len) elem.width = max_len;  
}
</script>
</HEAD>
<BODY>
	<div id="main_body"> 
    <? include($tps."elements/header.php")?>		
	 <div id="main_body2">       
        		
    <div id="col_l">
      <? include("panel_more.htm")?>
     </div>
    <div id="col_r"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td height="33" valign="top" style="padding-left:0px"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td height="10" valign="top"></td>
              </tr>
              <tr> 
                <td height="56" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td width="76%" valign="top"><table width="100%"  border="0" cellpadding="5" cellspacing="0">
                          <tr> 
                            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td height="18"> <font face="Verdana, Arial, Helvetica, sans-serif">
                                    <?=$nav?>
                                    </font></td>
                                </tr>
                              </table></td>
                          </tr>
                          <tr> 
                            <td align="center" class="msg"> <font face="Verdana, Arial, Helvetica, sans-serif">
                              <?=$msg1?>
                              </font></td>
                          </tr>
                          <tr> 
                            <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td><table width="100%" border="0" cellspacing="0" cellpadding="5">
                                      <tr> 
                                        <td valign="top"> <div class="text_left">	
                                            <font face="Verdana, Arial, Helvetica, sans-serif">
<?
echo "<table width=100% cellpadding=5 cellspacing=0>";
	$subject = $row["subject"];
	$content = bbs_decode($row["content"]);
	$content = decodeDes($content);
	$$p = $row["photo0"];
	if($$p){
		$path = path($row["postDate"]);
		$imageURL = "images/$path/".$$p;
		$photoStr =  "<div><img src='$imageURL'></div>";
	}	
	if($row["tags"]){
		$tagStr = "<div style='padding-top:10px'>".tag_to_link($row["tags"],BLOG_PATH."tag")."</div>";
	}
	echo "<tr><td class=title>".$subject."</td></tr><tr><td class=line_mid>".$photoStr.$content;
	//if($row["userID"])
		//$authorStr = "<a  href='/space/".urlencode($row["user"])."'>".$row["user"]."</a>";
	//else
		$authorStr = $row["user"];	
	echo "</td></tr><tr><td>".$row["postDate"]." Posted by: $authorStr $tagStr</td></tr>";
echo "</table>";
?>
                                            </font></div>
                                          <div align="center"> <font face="Verdana, Arial, Helvetica, sans-serif">
                                            <?=$_REQUEST["msg"]?>
                                            </font></div>
                                          <font face="Verdana, Arial, Helvetica, sans-serif">
                                          <?
if($row["num_series"]>0){
?>
                                          </font>
                                          <table style="border:#cccccc 1px solid" width="100%" border="0" cellspacing="0" cellpadding="3">
                                            <tr> 
                                              <td height="21"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                  <tr> 
                                                    <td width="14%" height="19" bgcolor="#f3f3f3" class="title_olive"><font face="Verdana, Arial, Helvetica, sans-serif">Series</font></td>
                                                    <td width="86%" bgcolor="#f3f3f3">&nbsp;</td>
                                                  </tr>
                                                </table></td>
                                            </tr>
                                            <tr> 
                                              <td height="38" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="2">
<?
$t = mysql_query("select * from $blog->table where series_parentID=$id order by ID");
$from = 0;
while($row_s=mysql_fetch_array($t)){
	echo "<tr><td class=dot_gold width=10>.</td><td><a class=link href='page?id=$id&from=$from'>".$row_s["subject"]."</a> &nbsp; <font class=small>Date: ".$row_s["postDate"]."&nbsp; Replies: ".$row_s["num_bbs"]."</font></td></tr>";
	$from ++;
}
?>
                                                </table></td>
                                            </tr>
                                          </table>
                                          <font face="Verdana, Arial, Helvetica, sans-serif">
                                          <? }?>
                                          </font></td>
                                      </tr>
                                    </table></td>
                                </tr>
                                <tr> 
                                  <td><table width="100%" border="0" cellspacing="0" cellpadding="5">
                                      <tr> 
                                        <td height="18" class="text_left"><font face="Verdana, Arial, Helvetica, sans-serif" class="title_black">Comments:</font></td>
                                        <td class="text_left"> <font face="Verdana, Arial, Helvetica, sans-serif"> 
                                          <? if($row["num_bbs"]>100){ ?>
                                          <a class="link" href="hotnet_bbs?id=<?=$id?>">More 
                                          comments</a> 
                                          <? }?>
                                          </font></td>
                                      </tr>
                                      <tr> 
                                        <td height="53" colspan="2" class="text_left"> 
                                          <font face="Verdana, Arial, Helvetica, sans-serif">
<?php
$t = mysql_query("select * from $blog->table where parentID=$id order by ID desc limit 0,100");
$c = 0;
echo "<form name='form3' action='hotnet' method=post>";
while($row2=mysql_fetch_array($t)){ 
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 class='listing_div'>
	<tr><td class='title_white'><font class='room_num'> # ".$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>";
echo "<input type='hidden' name='id' value='$id'></form>";
?>
                                          
                                          </font>
                                          <div align="center"> <font face="Verdana, Arial, Helvetica, sans-serif"> 
                                            <? if($row["num_bbs"]>100){ ?>
                                            <a class="link" href="hotnet_bbs?id=<?=$id?>">More 
                                            comments</a> 
                                            <? }?>
                                            </font></div></td>
                                      </tr>
                                      <tr> 
                                        <td height="53" colspan="2"><table width="100%" cellpadding="0" cellspacing="0" >
                                            <tr> 
                                              <td  height="270" valign="top" > 
                                                <table class="td_white" width="100%"  height="332" cellpadding="0"  cellspacing="0">
                                                  <tr> 
                                                    <td height="330" valign="top" > 
                                                      <form action="hotnet" method="post" name="form1" id="form1"  onsubmit="return check(this)">
                                                        <table  width="100%" border="0" cellpadding="5" cellspacing="0" >
                                                          <tr> 
                                                            <td height="26" colspan="3" valign="top" > 
                                                              <font face="Verdana, Arial, Helvetica, sans-serif"><nobr> 
                                                              </nobr></font><nobr> 
                                                              <table class="td_white" width="100%" border="0" cellpadding="0" cellspacing="0" >
                                                                <tr > 
                                                                  <td height="28" class="small" style="padding-left:10px"><font face="Verdana, Arial, Helvetica, sans-serif">Reply: 
                                                                    <a name="comments"></a> 
                                                                    <?=$row["subject"]?>
                                                                    </font></td>
                                                                </tr>
                                                              </table>
                                                              </nobr></td>
                                                          </tr>
                                                          <tr class="td_white"> 
                                                            <td align="right" valign="top" class="text_right" ><font face="Verdana, Arial, Helvetica, sans-serif">*First 
                                                              line:</font></td>
                                                            <td colspan="2" valign="top" ><font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              <input name="subject" type="text"   style="width:500px;" value="" size="55" maxlength="60" />
                                                              </font></td>
                                                          </tr>
                                                          <tr class="td_white"> 
                                                            <td width="80" height="123" align="right" valign="top" class="text_right" ><font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              More:</font></td>
                                                            <td colspan="2" valign="top" ><font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              <textarea name="content" style="width:500px;height:100px" wrap="VIRTUAL" id="des"></textarea>
                                                              </font></td>
                                                          </tr>
                                                          <tr valign="top" class="td_white">
                                                            <td height="44" align="right" class="text_right" >Photo:</td>
                                                            <td colspan="2" class="small" ><table width="100%" border="0" cellpadding="0" cellspacing="0">
                                                                <tr valign="top"> 
                                                                  <td width="533" ><a href="javascript:addimage1('des')"><strong>[</strong>Enter full URL</a><strong>]</strong>( 
                                                                    must be allowed external link)
																	<? if($sys["isAdmin"] || $sys["blogAdmin"]){?>
																	<br /> 
                                                                    <br />
                                                                    Or from your 
                                                                    computer<br /> 
                                                                    <iframe scrolling="No" frameborder="0" style="width:100%;height:120px" src="photo/upload.php"></iframe> 
																	<? }?>
                                                                  </td>
                                                                </tr>
                                                              </table></td>
                                                          </tr>
                                                          <tr valign="top" class="td_white"> 
                                                            <td height="44" align="right" class="text_right" ><font face="Verdana, Arial, Helvetica, sans-serif">Tags:</font></td>
                                                            <td colspan="2" class="small" ><font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              <input name="tags" type="text"  style="width:500px;" value="<?=$tags?>" size="75" maxlength="100" />
                                                              <br />
                                                              Multiple tags are 
                                                              separated with commas</font></td>
                                                          </tr>
                                                          <!--<tr class="td_white"> 
                                                              <td align="right" valign="top" class="text_right" >&nbsp;</td>
                                                              <td colspan="2" ><table width="378" border="0" cellpadding="0" cellspacing="0">
                                                                  <tr> 
                                                                    <td width="71" height="28"><input type="radio" name="smile" value="1" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/1.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="73"><input type="radio" name="smile" value="2" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/2.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="72"><input type="radio" name="smile" value="3" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/3.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="72"><input type="radio" name="smile" value="4" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/4.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="72"><input type="radio" name="smile" value="5" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/5.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="72"><input type="radio" name="smile" value="6" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/6.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td width="75"><input type="radio" name="smile" value="7" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/7.gif" width="20" height="20" align="absmiddle" /></td>
                                                                  </tr>
                                                                  <tr> 
                                                                    <td height="22"><input type="radio" name="smile" value="8" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/8.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="9" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/9.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="10" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/10.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="11" /> 
                                                                      <img  alt="" src="/library/bbs/images/smile/11.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="12" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/12.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="13" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/13.gif" width="20" height="20" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="14" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/14.gif" width="19" height="18" align="absmiddle" /></td>
                                                                  </tr>
                                                                  <tr> 
                                                                    <td height="27"><input type="radio" name="smile" value="15" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/15.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="16" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/16.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="17" /> 
                                                                      <img alt="cool" src="/library/bbs/images/smile/17.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="18" /> 
                                                                      <img alt="cool" src="/library/bbs/images/smile/18.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="19" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/19.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input type="radio" name="smile" value="20" /> 
                                                                      <img alt="" src="/library/bbs/images/smile/20.gif" width="19" height="18" align="absmiddle" /></td>
                                                                    <td><input alt="" type="radio" name="smile" value="" />
                                                                      No</td>
                                                                  </tr>
                                                                </table></td>
                                                            </tr>-->
                                                          <tr class="td_white"> 
                                                            <td height="43" align="right" class="text_right" ><font face="Verdana, Arial, Helvetica, sans-serif">Author:</font></td>
                                                            <td colspan="2" class="td_white" ><font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              <input type="text" name="user" value="<?=$sys["user"]==""?"Guest":$sys["user"]?>" />
                                                              <? if($sys["memberID"]) echo "Anonymous: <input type='checkbox' name='bbs_hidden' value='checked' onclick='set_user(this)'>"?>
                                                              </font></td>
                                                          </tr>
                                                          <tr class="td_white"> 
                                                            <td width="80" class="text_right" >&nbsp;</td>
                                                            <td class="td_white" > 
                                                              <font face="Verdana, Arial, Helvetica, sans-serif"> 
                                                              <input type="hidden" name="auth" value="" />
                                                              <input type="hidden" name="catID" value="<?=$catID?>" />
                                                              <input type="hidden" name="id" value="<?=$id?>" />
                                                              <input name="st" type="hidden" id="st" value="reply" />
                                                              <input type='submit' name='Submit' value='Submit'/>
                                                              <br />
                                                              </font></td>
                                                            <td width="156" class="td_white" >&nbsp;</td>
                                                          </tr>
                                                        </table>
                                                      </form></td>
                                                  </tr>
                                                </table></td>
                                            </tr>
                                          </table></td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></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>