<?php 
	require_once('scripts/sb_functions.php');
	global $logged_in;
	$logged_in = logged_in( true, true );
	
	read_config();
	
//	require_once('languages/' . $blog_config[ 'blog_language' ] . '/strings.php');
	sb_language( 'setup' );
	
	$temp_max_entries = intval( $_POST[ 'blog_max_entries' ] );
	if ( $temp_max_entries <= 0) {
		$temp_max_entries = 5;
	}

        // new in pppBLOG 0.3.1:
	$temp_entry_width = intval( $_POST[ 'blog_entry_width' ] );
	if ( $temp_entry_width <= 0) {
		$temp_entry_width = 550;
	}
	$temp_menu_width = intval( $_POST[ 'blog_menu_width' ] );
	if ( $temp_menu_width <= 0) {
		$temp_menu_width = 170;
	}
	$temp_pic_width = intval( $_POST[ 'blog_max_pic_width' ] );
	if ( $temp_pic_width <= 0) {
		$temp_pic_width = 500;
	}
	if ( $temp_pic_width > $temp_entry_width-50) {
	  $temp_pic_width = $temp_entry_width-50;
	}
	$temp_pic_height = intval( $_POST[ 'blog_max_pic_height' ] );
	if ( $temp_pic_height <= 0) {
		$temp_pic_height = 550;
	}
	$temp_thumb_width = intval( $_POST[ 'blog_thumb_width' ] );
	if ( $temp_thumb_width <= 0) {
		$temp_thumb_width = 550;
	}
	if ( $temp_thumb_width > $temp_entry_width-50) {
	  $temp_thumb_width = $temp_entry_width-50;
	}
	$temp_thumb_height = intval( $_POST[ 'blog_thumb_height' ] );
	if ( $temp_thumb_height <= 0) {
		$temp_thumb_height = 550;
	}
	$temp_thumbs_per_page = intval( $_POST[ 'blog_thumbs_per_page' ] );
	if ( $temp_thumbs_per_page <= 0) {
		$temp_thumbs_per_page = 15;
	}
        //////////////////////////////////

	
	$tag_array = array( 'b', 'i', 'strong', 'em', 'del', 'ins', 'strike', 'img', 'url', 'blockquote', 'hN', 'pre', 'code', 'html' );
	$temp_array = array();
	for ( $i = 0; $i < count( $tag_array ); $i++ ) {
		$tag = $tag_array[$i];
		if ( $_POST[ $tag ] == 'on' ) {
			array_push( $temp_array, $tag );
		}
	}
	$comment_tags_allowed = implode( ',', $temp_array );

$ok = write_config( sb_stripslashes( $_POST[ 'blog_title' ] ),
		    sb_stripslashes( $_POST[ 'blog_author' ] ),
		    sb_stripslashes( $_POST[ 'blog_email' ] ),
		    sb_stripslashes( $_POST[ 'blog_footer' ] ),
		    $_POST[ 'blog_language' ],
		    $_POST[ 'blog_entry_order' ],
		    $_POST[ 'blog_comment_order' ],
		    ( $_POST[ 'blog_enable_comments' ] == 'on' ),
		    $temp_max_entries,
		    ( $_POST[ 'blog_comments_popup' ] == 'on' ),
		    $comment_tags_allowed,
		    ( $_POST[ 'blog_enable_gzip_txt' ] == 'on' ),
		    ( $_POST[ 'blog_enable_gzip_output' ] == 'on' ),
		    ( $_POST[ 'blog_email_notification' ] == 'on' ),
		    ( $_POST[ 'blog_send_pings' ] == 'on' ),
		    sb_stripslashes( $_POST[ 'blog_ping_urls' ] ),
		    ( $_POST[ 'blog_enable_voting' ] == 'on' ),
		    ( $_POST[ 'blog_trackback_enabled' ] == 'on' ),
		    ( $_POST[ 'blog_trackback_auto_discovery' ] == 'on' ),
		    // new in pppBLOG 0.3.1:
		    $temp_entry_width,
		    $temp_pic_width,
		    $temp_pic_height,
		    $temp_thumb_width,
		    $temp_thumb_height,
		    $temp_thumbs_per_page,
		    // sb_stripslashes( $_POST[ 'blog_pic_extensions' ] )
		    ( $_POST[ 'blog_enable_signup' ] == 'on' ),
		    $_POST[ 'blog_mimetex' ],
		    $temp_menu_width,
		    $_POST['blog_fckeditor'],
		    $_POST['disable_comment_capcha'],
		    $_POST['blog_album_style'],
		    ( $_POST['blog_hide_header'] =='on' ),
		    ( $_POST['blog_hide_title'] =='on' ),
		    ( $_POST['blog_hide_header_searchbox'] =='on' ),
		    ( $_POST['blog_hide_header_links'] =='on' )
		    );
	
if ( $ok === true ) {
  redirect_to_url( 'index.php' );
}

html_header('',false);

function page_content() {
    global $lang_string, $user_colors, $ok;
    if ( $ok !== true ) {
	echo( $lang_string[ 'error' ] . $ok . '<p />' );
    }
    echo( '<a href="index.php">' . $lang_string[ 'home' ] . '</a><br /><br />' );
}

theme_pagelayout();
html_footer();

?>
