<?php
if ( !defined( 'SMARTY_DIR' ) ) {
	include_once( '../init.php' );
}

include( 'sessioninc.php' );
include_once(LIB_DIR . 'blog_class.php');


$blog =& new Blog(true);

// If the preferences are missing, go to the settings page
//
if ( ! $blog->settingsExist($_SESSION['AdminId']) ) {

      header( 'location: blogsettings.php?error_name=nosetup' );
      exit;
}

$blog->loadSettings($_SESSION['AdminId']);

// Load template if load template button pushed
//
if ( $_POST['action'] == 'add_blog' && $_POST['load_template'] ) {

     $loadtemp = $blog->loadTemplate();

} elseif ( $_POST['action'] == 'add_blog' ) {
// Add Blog if save button pressed
//

      $blog->addBlog($_SESSION['AdminId']);

      if ( $blog->getErrorMessage() ) {

          $t->assign ( 'error_message', $blog->getErrorMessage() );
      } else {

          header( 'location: bloglist.php' );
          exit;
      }
}

// Set the values to show on the page
//
$data = $blog->getData();

// If there's a saved template, give the oportunity to use it
//
$t->assign( 'date_posted', $data['date_posted'] ) ;

$t->assign( 'loadtemp',  $loadtemp);
$t->assign( 'data',  $data);
unset($data);

$t->assign( 'docroot', DOC_ROOT );
$js = '<script type="text/javascript" src="'.DOC_ROOT.'javascript/calendar/epoch_classes.js"></script>';

$css = '<link rel="stylesheet" type="text/css" href="' . DOC_ROOT . 'javascript/calendar/epoch_styles.css" />';

$t->assign('addtional_javascript', $js );
$t->assign('addtional_css', $css );

$t->assign('gui_editor', $blog->settings['gui_editor']);


// Make the page
//

$t->assign('rendered_page', $t->fetch('admin/addblog.tpl') );

$t->display( 'admin/index.tpl' );

exit;

?>
