<?php
function swift_import_export_form(){
swift_admin_header();
GLOBAL $swift_options,$swift_design_options;
?>
<style>
.ui-tabs .ui-tabs-nav,div.wrap{background:none}
textarea{margin:20px 0;padding:10px;border:solid  10px #DFDFDF}
</style>
<div id="import-export" style="padding:20px">

<div id="import-export-explanation" class="explain">
	<?php _e( 'You can import/export options from one site to another from this page.', 'swift' ); ?><br />
	<?php _e( 'You can also share your color and font options with other Swiftler\'s, just give them the color/font options export string.', 'swift' ); ?><br />
	<?php _e( 'To export, copy the text strings from here to the blog where you want to import, and do the reverse for import.', 'swift' ); ?><br />
	<?php _e( 'Please make sure you are pasting the strings in the correct fields, pasting design options in site options or in any other field will delete the settings.', 'swift' ); ?>
</div>
	
<h2><?php _e( 'Swift Options', 'swift' ); ?></h2>
	<input type="checkbox" name="swift_options_import" value="true" id="swift_options_import" />
	<label for="swift_options_import"><em><?php _e( 'Check this box to import Swift site options', 'swift' ); ?></em></label>	
<textarea name="swift_options" style="width:100%" rows="15"><?php echo base64_encode(serialize ($swift_options) ); ?></textarea>
<h2><?php _e( 'Design Options', 'swift' ); ?></h2>
<input type="checkbox" name="swift_design_options_import" value="true" id="swift_design_options_import" />
<label for="swift_design_options_import"><em><?php _e( 'Check this box to import Swift design options', 'swift' ); ?></em></label>	
	
<textarea name="swift_design_options" style="width:100%" rows="15"><?php echo base64_encode(serialize ($swift_design_options) ); ?></textarea>
<h2><?php _e( 'Color options', 'swift' ); ?></h2>
<input type="checkbox" name="swift_color_options_import" value="true" id="swift_color_options_import" />
<label for="swift_color_options_import"><em><?php _e( 'Check this box to import only color options', 'swift' ); ?></em></label>	
	
<textarea name="swift_color_options" style="width:100%" rows="15"><?php echo base64_encode(serialize ( swift_get_color_options() ) ); ?></textarea>
<h2><?php _e( 'Font options', 'swift' ); ?></h2>
<input type="checkbox" name="swift_font_options_import" value="true" id="swift_font_options_import" />
	<label for="swift_font_options_import"><em><?php _e( 'Check this box to import only font options', 'swift' ); ?></em></label>	
	
<textarea name="swift_font_options" style="width:100%" rows="15"><?php echo base64_encode(serialize (swift_get_font_options())); ?></textarea>
</div>
<?php 
}
?>
<?php 
function swift_get_color_options(){
	GLOBAL $swift_design_options_init;
	$start	= array_keys($swift_design_options_init, 'color_options_start');
	$end	= array_keys($swift_design_options_init, 'color_options_end');
	
	$temp = array_slice( $swift_design_options_init, $start[0], $end[0] - $start[0] ) ;
	
	$temp_options = get_option('SwiftOptions');
	$values = $temp_options['design_options'];
	
	$return_array = array();
	
	foreach( $temp as $option ){
		if( is_array($option) && $option['datatype'] != 'none' ){
			$return_array[ $option['id'] ] = $values[$option['id']];
		}
	}
	return $return_array;
	
}
function swift_get_font_options(){
	GLOBAL $swift_design_options_init;
	$start	= array_keys($swift_design_options_init, 'font_options_start');
	$end	= array_keys($swift_design_options_init, 'font_options_end');
	
	$temp = array_slice( $swift_design_options_init, $start[0], $end[0] - $start[0] ) ;
	
	$temp_options = get_option('SwiftOptions');
	$values = $temp_options['design_options'];
		
	$return_array = array();
	
	foreach( $temp as $option ){
		if($option['datatype'] == 'text'){
			$return_array[ $option['id'] ] = $values[$option['id']];
		}
		if( is_array($option) && $option['datatype'] == 'font' ){
			$return_array[ $option['id'].'_enable' ] = $values[$option['id'].'_enable'];
			$return_array[ $option['id'].'_family' ] = $values[$option['id'].'_family'];
			$return_array[ $option['id'].'_size' ] = $values[$option['id'].'_size'];
			$return_array[ $option['id'].'_size_unit' ] = $values[$option['id'].'_size_unit'];
			$return_array[ $option['id'].'_lh' ] = $values[$option['id'].'_lh'];
			$return_array[ $option['id'].'_lh_unit' ] = $values[$option['id'].'_lh_unit'];
			$return_array[ $option['id'].'_weight' ] = $values[$option['id'].'_weight'];
			$return_array[ $option['id'].'_transform' ] = $values[$option['id'].'_transform'];
			$return_array[ $option['id'].'_style' ] = $values[$option['id'].'_style'];
		}
	}
	return $return_array;
	
}

function swift_import_options($data){
	$temp_options = get_option('SwiftOptions');
	
	if( isset($data['swift_options_import']) && $data['swift_options_import']){
		$temp = base64_decode($data['swift_options']);
		$temp = unserialize($temp);
		
		if( is_array($temp))
		$temp_options['site_options'] = $temp;
	}
	
	if( isset($data['swift_design_options_import']) && $data['swift_design_options_import']){
		$temp = base64_decode($data['swift_design_options']);
		$temp = unserialize($temp);
		if( is_array($temp))
		$temp_options['design_options'] = $temp;
	}
	
	if( isset($data['swift_color_options_import']) && $data['swift_color_options_import']){
		$temp = base64_decode($data['swift_color_options']);
		$temp = unserialize($temp);
		
		if( is_array($temp)){
		
			$original_options = get_option('swift_design_options');
			
			foreach( $temp as $key => $choice ){
				$original_options[$choice] = $temp[$choice];
			}
			$temp_options['design_options'] = $original_options;
		}
		
	}	

	if( isset($data['swift_font_options_import']) && $data['swift_font_options_import']){
		$temp = base64_decode($data['swift_font_options']);
		$temp = unserialize($temp);
		
		if( is_array($temp)){
		
			$original_options = get_option('swift_design_options');
			
			foreach( $temp as $key => $choice ){
				$original_options[$choice] = $temp[$choice];
			}
			
			$temp_options['design_options'] = $original_options;
			
			
		}
		
	}			
	update_option('SwiftOptions', $temp_options);
}
?>