<?php
include("../common.php");
include("common.php");
$where = BLOG_PATH."new";
include("include/sec.php");
include("../include/email.php");
include_once(S_ROOT.'./include/function_inter.php');
//$badwords_file = "../forum/badwords.txt";
//============
//$menu_blog = "<img src='/images/menu_this.jpg' border='0'>";
$titleHeader = $this_section;
$C_cat3 = "96;{$_site_name} Weekly Update ";
//============
$blog = new Blog();
$nav = "<a  href='/'>Home &gt;&gt;</a>  <a href='.'>".$this_section." &gt;&gt; </a> Post new";
if($_POST["st"]=="add" && $hotnetUser){
	request($blog->fields,array("postDate","parentID","rootID","series_parentID","userID","user"));
	$subjectC = $subject;
	$contentC = $content;
	//**********************************
	$subject = norm($subject);
	$content = norm($content);
	//**********************************
	$cat3 = $_REQUEST["cat3"];
	//$cat3 = $C_cat3;//temp !!!
	if($cat3) list($catID ,$catTitle)= split (";", $cat3);
	
	$postDate = $pTime;
	$parentID = "0";
	$userID = $hotnetMemberID;
	$user = $hotnetUser;
	$num_series = 0;
	$ip = $_SERVER['REMOTE_ADDR'];
	$sql = sqlInsert($blog->table,$blog->fields,"");
	if(mysql_query($sql)){
		$msg = "You have posted this info successfully!<br/><br/>";
		//-------------------
		if($_REQUEST["send_to_subscribers"]=="checked"){
			$body = bbs_decode($contentC);
			$productID = $blog->getMAXID("where userID='".$sys["memberID"]."'");			
			$hotnet = hotnet_url($productID,$subject);
			$body .= "<br/><br/>{$_site_name}<br/><br/>Permalink: {$_site}".BLOG_PATH."{$hotnet}"."<br/><br/>".date_mysql_au($pTime);
			$msg .= send_blog($subjectC,$body);
		}
		//--------------------
		refresh($_site.BLOG_PATH."caching/robot_new.php","caching/new.html");
		$msg .= "<br/><br/><a href='".BLOG_PATH."' class='link'>[Back to ".$this_section." home page]</a>";
		$onloadStr = "";
		$sys["sent_blog"] = true;
		$msg2 = "<div style='height:400px;padding-top:100px'>{$msg}</div>";
	}
	else{
		  $msg = "Failed to add.";
		  $select1 = "selected";
	}  
}
function send_blog($subject,$body){
	global $_site_name,$_admin_email;
	$t = mysql_query("select email,firstname,lastname from ".C_tpre."Member where newsletter='checked'");
	$between_delay = 10;//sleep every 10 seconds 
	$send_delay = 1;
	$count_sent = 0;
	$count_failed = 0;
	$body = stripslashes($body);
	for($sent=0;$row=mysql_fetch_array($t);$sent++){
		if(($sent % $between_delay)==0)     
			sleep($send_delay); 		
		$email = $row["email"];
		$firstname = $row["firstname"];
		$lastname = $row["lastname"];
		if($firstname || $lastname)
			$for = "for";
		else
			$for = "";							
		if(sendmail("{$_site_name}<{$_admin_email}>",$email,$subject,$body,"html","utf-8"))
			$count_sent++;
		else
			$count_failed++;	
	}
	$msg = "Result of sending this article to subscribers:<br>Sent: {$count_sent}<br>Failed: {$count_failed}";
	return $msg;
}
?>
<!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">
<? include($tps."elements/meta.inc")?>
<link rel="stylesheet" href="<?=BLOG_PATH?>include/style.css" type="text/css">
<? include($tps."elements/meta.inc")?>
<script language=javascript>
function check(thisForm){
   var a =thisForm.subject;
  var b =thisForm.content; 
  var c = thisForm.cat3;
  var fields = new Array(a,b,c);
   //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{
  	if(thisForm.send_to_subscribers.checked==true){
		var agree = confirm("Are you sure to send this article to all subscribers?!!");
		if (agree)
			return true ;
		else
			return false ;
	}
    thisForm.Submit.value = "submitting ..."
  	thisForm.Submit.disabled = true;
    return true;
  }  
}
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;
	}	
}
</script>
<script type=text/javascript>
<? include("caching/cats_js_s.html")?>
function display_cats(){
	var v = document.form1.cat2;
	for(i=1;i<cats.length;i++){
		var luke = cats[i][0];		
		v.options[i] = new Option(luke.substr(luke.indexOf(";")+1),luke);			    		
	}
}
function sub_cats(){
	var v1 = document.form1.cat2;
	var v2 = document.form1.cat3;
	var section = v1.selectedIndex;
	if(section>0){
		for(i=0;i<v2.length;i++){
			v2.options[i] = new Option("");
		}
		var test = cats[section][1];
		for(i=1;i<test.length;i++){
			var luke = test[i];		
	   		v2.options[i] = new Option(luke.substr(luke.indexOf(";")+1),luke);		
		}
	}
	else{
		for(i=0;i<v2.length;i++){
			v2.options[i] = new Option("");
		}
	}	
}
</script>
<script type="text/javascript" src="/include/js/bbs_encode.js"></script>
</HEAD>
<BODY onload="document.form1.subject.focus();display_cats()">
	<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">      
<? if(!$sys["sent_blog"]){?>        
      <table width="100%" border="0" cellpadding="2" cellspacing="2" >
        <form action='new' method="post" name="form1" id="form1" onsubmit="return check(this)">
          <tr valign="top" > 
            <td width="114" height="26" align="right" class="text_right">* Subject:</td>
            <td height="26" colspan="2" align="left"><input type="text" style="width:400px" name="subject" value="<?=$subject?>" /> 
              <br /> </td>
          </tr>
          <tr> 
            <td height="10" align="right" valign="top" class="text_right">Category:<br /> 
              <br />
              Hint:<br />
              select top category first</td>
            <td colspan="2" valign="top" align="left"><table width="350"  border="0" cellpadding="0" cellspacing="0">
                <tr valign="top"> 
                  <td width="120" height="16">* Top category</td>
                  <td width="114" >* Sub-category</td>
                </tr>
                <tr valign="top"> 
                  <td height="76" align="left"> 
                    <?php
if( $parentID && $parentTitle) $cat2 = $parentID.";".$parentTitle;
?>
                    <select size="12" name="cat2" onclick="sub_cats()" onblur="return" style="width:150px">
                      <option selected="selected" value="<?=$cat2?>"> 
                      <?=$op_arr[$cat2]?>
                      </option>
                    </select></td>
                  <td > 
                    <?php
if( $catID && $catTitle) $cat3 = $catID.";".$catTitle;
?>
                    <select size="12" name="cat3" style="width:150px">
                      <option selected="selected" value="<?=$cat3?>"> 
                      <?=$op_arr[$cat3]?>
                      </option>
                    </select></td>
                </tr>
              </table></td>
          </tr>
          
          <tr> 
            <td height="10" align="right" valign="top" class="text_right"> Content</td>
            <td colspan="2" valign="top" align="left"><table cellpadding="0" cellspacing="0" >
                <tr> 
                  <td align="left"> <table cellpadding="0" cellspacing="0">
                      <tr> 
                        <td align="left"><textarea name="content" id="des" style="width:400px; height:150px;border:#B7CBCF 1px solid"><?=$content?></textarea></td>
                      </tr>
                    </table></td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td height="23" align="right" valign="top" class="text_right">Photo:</td>
            <td height="23" colspan="2" align="left" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr valign="top"> 
                  <td width="533" height="79"><a href="javascript:addimage1('des')"><strong>[</strong>Enter 
                    a photo Full URL</a><strong>]</strong> (external link must 
                    be allowed)<br /> <br />
                    Or from your computer<br /> <iframe scrolling="No" frameborder="0" style="width:400px;height:120px" src="photo/upload.php"></iframe> 
                  </td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td height="23" align="right" valign="top" class="text_right">Tags:</td>
            <td height="23" colspan="2" align="left" valign="top"><input name="tags" type="text" value="<?=$tags?>" style="width:400px;" /> 
              <br />
              Hint: multiple tags are separated by commas</td>
          </tr>
          <tr> 
            <td height="23" align="right" class="text_right">Author: </td>
            <td height="23" colspan="2" align="left"> 
              <?=$sys["user"]?>
            </td>
          </tr>
          <tr> 
            <td height="23" align="right" class="text_right">&nbsp;</td>
            <td height="23" colspan="2" align="left"><input type="checkbox" name="send_to_subscribers" id="send_to_subscribers" value="checked" /> 
              <label for="send_to_subscribers"> send this article to all subscribers</label></td>
          </tr>
          <tr> 
            <td height="23" align="right" class="text_right">&nbsp;</td>
            <td width="261" height="23" align="left">&nbsp;</td>
            <td width="361"><input name="st" type="hidden" value="add" /> <input type='submit' name='Submit' value='Submit' /></td>
          </tr>
        </form>
      </table>
<?
}
else{
	echo $msg2;
}
?>	  
      		</div>		
			<!--col_r end-->
	  <div style="clear: both;">&nbsp;</div>	      
    	</div>		
	</div>
	<? include($tps."elements/footer.php")?>
</body>
</html>