<?php
include("../../common.php");
include(S_ROOT."_admin/security.php");
include(S_ROOT."blog/include/Cats.php");
include(S_ROOT."blog/include/Blog.php");
include(S_ROOT."blog/caching/robot.php");
$Para = new Cats();
$Blog = new Blog();
$editor_type = "";
request($Blog->fields,array(""));
if($_POST["st"]=="add"){	
	$subject0 = norm($subject0);
	$subject1 = norm($subject1);
	$subject2 = norm($subject2);
	$subject3 = norm($subject3);
	$subject0 = str_replace("\$","",$subject0);//for split with $ later
	$content0 = norm($content0);
	$content1 = norm($content1);
	$content2 = norm($content2);
	$content3 = norm($content3);
	$postDate = $pTime;
	$userID = $sys["memberID"];
	$user = $sys["user"];
	$sql = sqlInsert($Blog->table,$Blog->fields,array(""));
	if($db->query($sql)){
		cache_new();
		cache_new_home();
		$msg = "<font color=red>You have added a new info successfully!</font><br>";		
	}
    else{
		$msg = "<font color=red>You have failed to add a new info.</font><br>";
	}
}
?>
<!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>
<title>calendar</title>
<? include(S_ROOT."_admin/elements/meta.inc.php");?>
<script type="text/javascript">
function remind(){
		var agree=confirm("Are you sure to delete this info?  Press OK to confirm.");
		if (agree)
			return true ;
		else
			return false ;
	}
function check(thisForm){
    var q =thisForm.subject0;
   var a =thisForm.content0;
   var b = thisForm.catID;
   var fields = new Array(q,a,b);
  //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){
    alert("Please enter the required info in the highlight field.");
	focusObj.focus();
    return false;
  }
  else{
      return true;
  }
}
</script>
<script language="JavaScript" src="/include/js/jquery.js"></script>
<script type="text/javascript" src="/include/js/jquery-ui.js"></script>
<script type="text/javascript" src="/include/js/sprinkle.js"></script>
<link rel="stylesheet" href="/include/css/tabs_style.css" type="text/css">
<script type="text/javascript">
    _editor_url  = "/library/xinha/";
    _editor_lang = "en";      // And the language we need to use in the editor.
</script>
<!-- Load up the actual editor core -->
<script type="text/javascript" src="/library/xinha/XinhaCore.js"></script>
<script type="text/javascript">
    xinha_editors = null;
    xinha_init    = null;
    xinha_config  = null;
    xinha_plugins = null;
    // This contains the names of textareas we will make into Xinha editors
    xinha_init = xinha_init ? xinha_init : function(){
      xinha_plugins = xinha_plugins ? xinha_plugins :
      [
        'DoubleClick','CharacterMap', 'SpellChecker', 'Linker','ExtendedFileManager'
      ];
      // THIS BIT OF JAVASCRIPT LOADS THE PLUGINS, NO TOUCHING  :)
      if(!Xinha.loadPlugins(xinha_plugins, xinha_init)) return;
      xinha_editors = xinha_editors ? xinha_editors :
      [
        'des0','des1','des2','des3'
      ];
       xinha_config = xinha_config ? xinha_config : new Xinha.Config();
       xinha_config.fullPage = false;
       xinha_config.CharacterMap.mode = 'panel';
	   
	    xinha_config.showLoading = true;
	   xinha_config.statusBar = false;
	   xinha_config.stripBaseHref = true;
	   xinha_config.baseHref = "<?php print 'http://'. $_SERVER['SERVER_NAME'] ?>";
	
	 
	    <?php  require_once S_ROOT.'library/xinha/contrib/php-xinha.php'; ?>
	    if (xinha_config.Linker) {
	      with(xinha_config.Linker) {
	      <?php 
	      xinha_pass_to_php_backend(
	      array(
	      'dir'          => '/library/xinha/',
	      'include'      => '/\.(php|shtml|html|htm|shtm|cgi|txt|doc|pdf|rtf|xls|csv)$/', // Regex or null
	      'exclude'      => null, // Regex or null
	      'dirinclude'   => null, // Regex or null
	      'direxclude'   => null // Regex or null
	      )
	      );
	      ?>
	    }
	    }
	    
	    xinha_config.ExtendedFileManager.use_linker = true;
	  
	  if (xinha_config.ExtendedFileManager) {
	         with (xinha_config.ExtendedFileManager) {
	            <?php	
	            // define backend configuration for the plugin
	            $IMConfig = array();
	            // the directories have to be writeable for php (that means 777 under linux)
	            $IMConfig['max_foldersize_mb'] = 10;
	            $IMConfig['files_dir'] = S_ROOT.'images/photo';
	            $IMConfig['images_dir'] = S_ROOT.'images/photo';
	            $IMConfig['files_url'] = '/images/photo/';
	            $IMConfig['images_url'] = '/images/photo/';
	            $IMConfig['images_enable_styling'] = false;
	            $IMConfig['max_filesize_kb_image'] = 400;
				$IMConfig['allow_upload'] = true;
	            // we can use the value 'max' to allow the maximium upload size defined in php_ini
	            $IMConfig['max_filesize_kb_link'] = 'max';
	            $IMConfig['allowed_link_extensions'] = array("jpg","gif","js","pdf","zip","txt","psd","png","html","swf","xml","xls");
	
	            xinha_pass_to_php_backend($IMConfig);
	
	            ?>
	        }
	  }   
	   
      xinha_editors   = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);  
      Xinha.startEditors(xinha_editors);
	 
    }
</script>

<script type="text/javascript">
$(document).ready(function(){
	xinha_init();
	$("#des0").css("width","680px");
	$("#des0").css("height","400px");
	$("#des1").css("width","680px");
	$("#des1").css("height","400px");
	$("#des2").css("width","680px");
	$("#des2").css("height","400px");
	$("#des3").css("width","680px");
	$("#des3").css("height","400px");
	 
});
</script>

</head>
<body onLoad="document.form1.subject0.focus()">
<?php echo $msg?> 
<form name=form1 method=post action="<?php echo $PHP_SELF?>" onSubmit=" return check(this)">
  <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
      <td colspan="2" align="left" valign="top"><strong>1) Title </strong>
        <!--widget start-->
        <div id="tabvanilla" class="widget">
          <ul class="tabnav">
            <li><a href="#tab0">English</a></li>
            <li><a href="#tab1">Chinese</a></li>
            <li><a href="#tab2">Japanese</a></li>
            <li><a href="#tab3">Korean</a></li>
          </ul>
          <div id="tab0" class="tabdiv"><input name="subject0" type="text" value="<?=$subject0?>" style="width:500px" maxlength=80></div>          
          <div id="tab1" class="tabdiv" style="display:none;"><input name="subject1" type="text" value="<?=$subject1?>" style="width:500px" maxlength=80></div>
          
          <div id="tab2" class="tabdiv"  style="display:none;"><input name="subject2" type="text" value="<?=$subject2?>" style="width:500px" maxlength=80></div>
          
          <div id="tab3" class="tabdiv"  style="display:none;"><input name="subject3" type="text" value="<?=$subject3?>" style="width:500px" maxlength=80></div>
        </div>
        <!--widget end--></td>
    </tr>
    <tr align="left">
      <td colspan="2"><strong>2) Description</strong></td>
    </tr>
    <tr >
      <td colspan="2" align="left"><!--widget start-->
        <div id="tabvanilla2" class="widget">
          <ul class="tabnav">
            <li><a href="#tab0_2">English</a></li>
            <li><a href="#tab1_2">Chinese</a></li>
            <li><a href="#tab2_2">Japanese</a></li>
            <li><a href="#tab3_2">Korean</a></li>
          </ul>
         <div id="tab0_2" class="tabdiv"><textarea name="content0" id="des0" style="width:500px;height:200px"><?=$content0?></textarea></div>
			
			<div id="tab1_2" class="tabdiv" style="display:block;"><textarea name="content1" id="des1" style="width:500px;height:200px"><?=$content1?></textarea></div>
            
            <div id="tab2_2" class="tabdiv" style="display:block;"><textarea name="content2" id="des2" style="width:500px;height:200px"><?=$content2?></textarea></div>
            
            <div id="tab3_2" class="tabdiv" style="display:block;"><textarea name="content3" id="des3" style="width:500px;height:200px"><?=$content3?></textarea></div>
        </div>
        <!--widget end--></td>
    </tr>
    <tr>
      <td width="14%"><strong>3) Category</strong></td>
      <td width="86%" align="left"><?
echo "<select name='catID'><option></option>";
$str = display_cat(0,"",0);
function display_cat($parentID,$dash,$deep){
	global $db,$Para;
	$tpre = C_tpre;
	$re = "";
	$t = $db->query("select * from $Para->table where parentID='{$parentID}' order by orderNum desc");
	$dash .= "_";
	$deep++;
	while($row=$db->fetch($t)){
		$catTitle = $row["title0"];
		$catID = $row["ID"];
		$indexStr = "{$dash}|{$deep}|";	
		$re .= "<option value='{$catID}'>{$indexStr} {$catTitle}</option>";
		$re .= display_cat($catID,$dash,$deep);		
	}
	return $re;
}
$str .= "<option value=''></option>";
echo str_replace("value='".$catID."'","selected='selected' value='".$catID."'",$str);
echo "</select>";
?></td>
    </tr>
    <tr>
      <td align="left">&nbsp;</td>
      <td align="center"><input type="hidden" name="st" value="add" />
      <input type="submit" name="Submit" value="Add" /></td>
    </tr>
  </table>
</form>
</body>
</html>
