<?php 

require_once('scripts/sb_functions.php');


if (!signed_in()){
  global $logged_in;
  $logged_in = logged_in( true, true );
}
else{
    global $blog_permissions;
    if ( $blog_permissions['add']!=1 ){ 
	redirect_to_url('index.php');
    }
}


read_config();
sb_language( 'add' );


// Verify information being passed:
$redirect = true;
if ( array_key_exists( 'y', $_GET ) && 
     array_key_exists( 'm', $_GET ) && 
     array_key_exists( 'd', $_GET ) ) {
  // Dis-allow dots, and slashes to make sure the
  // user is not able to back-up a directory.
  //
  // Make sure the string lengths are correct.
  if ( strpos( $_GET[ "y" ], array( "/", ".", "\\", "%" ) ) === false && 
       strlen( $_GET["y"] ) == 2 &&
       strpos( $_GET[ "m" ], array( "/", ".", "\\", "%" ) ) === false && 
       strlen( $_GET["m"] ) == 2 &&
       strpos( $_GET[ "d" ], array( "/", ".", "\\", "%" ) ) === false && 
       strlen( $_GET["d"] ) == 2 ) {


      if ( array_key_exists( 'submit', $_POST ) ){
	  global $signed_in,$blog_permissions;

	  $timestamp = time();

	  $hours   = date("H", $timestamp);
	  $minutes = date("i", $timestamp);
	  $seconds = date("s", $timestamp);
	  $month   = date("m", $timestamp);
	  $day     = date("d", $timestamp);
	  $year    = date("y", $timestamp);

	  if (isset($_POST['y'])) $year = $_POST['y'];
	  if (isset($_POST['m'])) $month = $_POST['m'];
	  if (isset($_POST['d'])) $day = $_POST['d'];
	  if (isset($_POST['H'])) $hours = $_POST['H'];
	  if (isset($_POST['i'])) $minutes = $_POST['i'];
	  if (isset($_POST['s'])) $seconds = $_POST['s'];

	  if ($signed_in && $blog_permissions['add']==1){
	      $entry = write_event( stripslashes( $_POST['blog_subject'] ), 
				    stripslashes( $_POST['blog_text'] ) , 
				    stripslashes( $_POST['tb_ping'] ), 
				    $_POST[ "catlist" ],
				    $year,$month,$day,
				    $hours,$minutes,$seconds,
				    $_POST['repeat'],
				    $_POST['blog_editor']);
	      if ($entry != false){
		  redirect_to_url( "index.php?entry=".$entry );
	      }
	  }
      }
      else{
	  $redirect = false;
      }
  }
}



	
if ( $redirect === true ) {
  redirect_to_url( "index.php" );
}



$extra_header = '
	<script type="text/javascript">
	<!--
	// Validate the Form
	function validate_comment(theform) {
		if ( theform.blog_text.value=="" || theform.comment_name.value=="" || theform.comment_capcha.value=="" ) {
			alert("<?php echo( $lang_string["form_error"] ); ?>");
			return false;
		} else {
			return true;
		}
	}
	-->
	</script>
';

html_header($extra_header,true);


function page_content(){

    global $ok,$lang_string;

    if ( array_key_exists( 'submit', $_POST ) &&  $ok !== true ) {
	echo $lang_string[ 'error_add' ].$ok.'<p />';
	echo( '<a href="index.php">' . $lang_string[ 'home' ] . '</a><br /><br />' );
    }
    else{
	require_once('scripts/sb_blogeditor.php');
	editor_addevent();
    }
}



theme_pagelayout();
html_footer();


?>
