<?php 
	require_once('scripts/sb_functions.php');
	global $logged_in;
	$logged_in = logged_in( true, false );
	
	read_config();
	
	global $blog_config;
	if ( isset( $_POST[ 'blog_language' ] ) ) {
		$blog_config[ 'blog_language' ] = $_POST[ 'blog_language' ];
	} else if ( isset( $_GET[ 'blog_language' ] ) ) {	
		$blog_config[ 'blog_language' ] = $_GET[ 'blog_language' ];
	}
	
//	require_once('languages/' . $blog_config[ 'blog_language' ] . '/strings.php');
	sb_language( 'install02' );

html_header();


	function page_content() {
		global $lang_string, $user_colors, $blog_config;
		sb_language( 'install02' );
			
		echo( '<h2>' . $lang_string[ 'title' ] . '</h2>' );
		echo( $lang_string[ 'instructions' ] . '<p />' );
		
		echo( '<div class="hr"><hr /></div>' );
		
		$result = create_folder( 'config' );
		$result = $result + create_folder( 'content' );
		$result = $result + create_folder( 'images' );
		
		// $result = $result + initialize_blocks();

		echo( '<div class="hr"><hr /></div>' );
		
		if ( $result < 0 ) {
			echo( $lang_string[ 'help' ] . '<p />' );
			echo( '<a href="install02.php?blog_language=' . $blog_config[ 'blog_language' ] . '">' . $lang_string[ 'try_again' ] . '</a><p />' );
		} else {
			echo( $lang_string[ 'success' ] . '<p />' );
			echo( '<a href="install03.php?blog_language=' . $blog_config[ 'blog_language' ] . '">' . $lang_string[ 'continue' ] . '</a><p />' );
		}
		
	}
	function create_folder( $dir ) {
		global $lang_string;
		
		echo( '<b>' . $dir . '</b> - ' );
		
		if ( !file_exists( $dir ) ) {
			// Creating Folder
			$oldumask = umask( 0 );
			$ok = my_mkdir( $dir, 0777 );
			umask( $oldumask );
			
			if ( !file_exists( $dir ) ) {
				// Failed
				echo( $lang_string[ 'folder_failed' ] . '<br />' );
				return( -1 );
				
			} else {
				// Worked
				echo( $lang_string[ 'folder_success' ] . '<br />' );
				return( 0 );
			}
			
		} else {
			// Folder Already Exists
			echo( $lang_string[ 'folder_exists' ] . '<br />' );
			return( 0 );
		}
	}
theme_pagelayout();
html_footer();
?>

