<?php 
	require_once('scripts/sb_functions.php');
	global $logged_in;
	$logged_in = logged_in( true, true );
	
	read_config();	
	sb_language( 'colors' );
	
	$color_def = theme_default_colors();
	$post_array = array();
	array_push( $post_array, 'name' );
	if ( array_key_exists( 'save_btn', $_POST ) == true && $_POST[ 'scheme_name' ] != '' && $_POST[ 'scheme_file' ] != '' ) {
		$str = str_replace( '|', ':', $_POST[ 'scheme_name' ] );
		array_push( $post_array, $str );
	} else {
		array_push( $post_array, 'custom' );
	}
	
	for ( $i = 0; $i < count( $color_def ); $i++ ) {
		$id = $color_def[$i][ 'id' ];
		$color = sb_stripslashes( $_POST[ $id ] );
		array_push( $post_array, $id );
		array_push( $post_array, $color );
	}
	
	// Check if we should save color scheme, or just update colors on web site.
	if ( array_key_exists( 'save_btn', $_POST ) == true && $_POST[ 'scheme_name' ] != '' && $_POST[ 'scheme_file' ] != '' ) {
		$ok = write_colors( $post_array, $_POST[ 'scheme_file' ] );
	} else {
		$ok = write_colors( $post_array, NULL );
	}
	
	if ( $ok === true ) {
		redirect_to_url( 'colors.php' );
	}

html_header('',false);

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

theme_pagelayout();
html_footer();

?>
