<?php
$themename = "Elisium";

$shortname = "p2h";

$version = "1.1";

$option_group = $shortname.'_theme_option_group';
$option_name = $shortname.'_theme_options';

// Load stylesheet and jscript
add_action('admin_init', 'p2h_add_init');

function p2h_add_init() {
	$file_dir = get_template_directory_uri();

	wp_enqueue_style("p2hCss", $file_dir."/options/elisium-options.css", false, "1.0", "all");

	wp_enqueue_script("p2hScript", $file_dir."/options/elisium-options.js", false, "1.0");

}

// Create custom settings menu
add_action('admin_menu', 'p2h_create_menu');

function p2h_create_menu() {
	global $themename;
	//create new top-level menu
	add_theme_page( __( $themename.' Homepage Options' ), __( 'Elisium Homepage Options' ), 'edit_theme_options', basename(__FILE__), 'p2h_settings_page' );
}

// Register settings
add_action( 'admin_init', 'register_settings' );

function register_settings() {
   global $themename, $shortname, $version, $p2h_options, $option_group, $option_name;
  	//register our settings
	register_setting( $option_group, $option_name);
}

// Create theme options

global $p2h_options;

$p2h_options = array (
	
//SOCIAL MEDIA BUTTONS	

array("name" => __('Social Media Links','elisium'),

		"type" => "section"),

array("name" => __('Set the links to the social media accounts you have and the appropriate icons will appear.','elisium'),

		"type" => "section-desc"),

array("type" => "open"),

array("name" => __('Facebook','elisium'),

		"desc" => __('Link to your Facebook page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Facebook icon supressed.','elisium'),

		"id" => "facebookid",

		"type" => "text",

		"std" => ""),

array("name" => __('Twitter','elisium'),

		"desc" => __('Link to your Twitter page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Twitter icon supressed.','elisium'),

		"id" => "twitterid",

		"type" => "text",

		"std" => ""),

array("name" => __('Pinterest','elisium'),

		"desc" => __('Link to your Pinterest page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Pinterest icon supressed.','elisium'),

		"id" => "pinterestid",

		"type" => "text",

		"std" => ""),		

array("name" => __('Digg','elisium'),

		"desc" => __('Link to your Digg page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Digg icon supressed.','elisium'),

		"id" => "diggid",

		"type" => "text",

		"std" => ""),

array("name" => __('Youtube','elisium'),

		"desc" => __('Link to your Youtube page, <strong>with http://</strong>. It will be shown in the navigation bar. Leaving it blank will keep the Youtube icon supressed.','elisium'),

		"id" => "youtubeid",

		"type" => "text",

		"std" => ""),

array("type" => "close"),

//SLIDER CONTENT AND LINKS

array("name" => __('Homepage Slider','elisium'),

		"type" => "section"),

array("name" => __('Change the wording on the slides, the images and add links.','elisium'),

		"type" => "section-desc"),

array("type" =>"open"),

//SLIDE 1

array("name" => __('Slide 1 Title','elisium'),

		"desc" => __('Change the title on Slide 1.','elisium'),

		"id" => "slide1_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Slide 1 Text','elisium'),

		"desc" => __('Enter the text for Slider 1.','elisium'),

		"id" => "slide1_text",

		"std" => "",

		"type" => "textarea"),
		
array("name" => __('Slide 1 Link','elisium'),

		"desc" => __('Set the link for the Learn More button on Slider 1','elisium'),

		"id" => "slide1_link",

		"type" => "text",

		"std" => ""),

array("name" => __('Slide 1 Image Link','elisium'),

		"desc" => __('Set the link for your Slide 1 image','elisium'),

		"id" => "slide1_image_link",

		"type" => "text",

		"std" => ""),

//SLIDE 2

array("name" => __('Slide 2 Title','elisium'),

		"desc" => __('Change the title on Slide 2.','elisium'),

		"id" => "slide2_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Slide 2 Text','elisium'),

		"desc" => __('Enter the text for Slider 2.','elisium'),

		"id" => "slide2_text",

		"std" => "",

		"type" => "textarea"),
		
array("name" => __('Slide 2 Link','elisium'),

		"desc" => __('Set the link for the Learn More button on Slider 2','elisium'),

		"id" => "slide2_link",

		"type" => "text",

		"std" => ""),

array("name" => __('Slide 2 Image Link','elisium'),

		"desc" => __('Set the link for your Slide 2 image','elisium'),

		"id" => "slide2_image_link",

		"type" => "text",

		"std" => ""),
//SLIDE 3

array("name" => __('Slide 3 Title','elisium'),

		"desc" => __('Change the title on Slide 3.','elisium'),

		"id" => "slide3_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Slide 3 Text','elisium'),

		"desc" => __('Enter the text for Slider 3.','elisium'),

		"id" => "slide3_text",

		"std" => "",

		"type" => "textarea"),
		
array("name" => __('Slide 3 Link','elisium'),

		"desc" => __('Set the link for the Learn More button on Slider 3','elisium'),

		"id" => "slide3_link",

		"type" => "text",

		"std" => ""),

	
array("name" => __('Slide 3 Image Link','elisium'),

		"desc" => __('Set the link for your Slide 3 image','elisium'),

		"id" => "slide3_image_link",

		"type" => "text",

		"std" => ""),		
		
array("type" => "close"),

//PROMO 1 CONTENT AND LINKS

array("name" => __('Promo 1 Section (grey one)','elisium'),

		"type" => "section"),

array("name" => __('Change the wording on the grey promo section and add the correct link.','elisium'),

		"type" => "section-desc"),

array("type" =>"open"),

//PROMO 1

array("name" => __('Promo 1 Title','elisium'),

		"desc" => __('Change the title on Promo 1.','elisium'),

		"id" => "promo1_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Promo 1 Text','elisium'),

		"desc" => __('Enter the text for Promo 1.','elisium'),

		"id" => "promo1_text",

		"std" => "",

		"type" => "textarea"),

		
array("name" => __('Promo 1 Link','elisium'),

		"desc" => __('Set the link for the Find out More button on Promo 1','elisium'),

		"id" => "promo1_link",

		"type" => "text",

		"std" => ""),


array("type" => "close"),

//MAIN FEATURES TITLES, IMAGES AND CONTENT

array("name" => __('Main Features','elisium'),

		"type" => "section"),

array("name" => __('Here you can write about the main features/services your company provides','elisium'),

		"type" => "section-desc"),

array("type" =>"open"),

array("name" => __('Features section title','elisium'),

		"desc" => __('Change the title for the main features/services.','elisium'),

		"id" => "feature_title",

		"std" => "",

		"type" => "text"),

//FEATURE 1

array("name" => __('Feature 1 Image Link','elisium'),

		"desc" => __('Upload a new image via the media section and place the link here. It will replace the current image.','elisium'),

		"id" => "feature1_image",

		"type" => "text",

		"std" => ""),

array("name" => __('Feature 1 Title','elisium'),

		"desc" => __('Change the title on Feature 1.','elisium'),

		"id" => "feature1_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Feature 1 Text','elisium'),

		"desc" => __('Enter the text for Feature 1.','elisium'),

		"id" => "feature1_text",

		"std" => "",

		"type" => "textarea"),
		
//FEATURE 2

array("name" => __('Feature 2 Image Link','elisium'),

		"desc" => __('Upload a new image via the media section and place the link here. It will replace the current image.','elisium'),

		"id" => "feature2_image",

		"type" => "text",

		"std" => ""),

array("name" => __('Feature 2 Title','elisium'),

		"desc" => __('Change the title on Feature 2.','elisium'),

		"id" => "feature2_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Feature 2 Text','elisium'),

		"desc" => __('Enter the text for Feature 2.','elisium'),

		"id" => "feature2_text",

		"std" => "",

		"type" => "textarea"),


//FEATURE 3

array("name" => __('Feature 3 Image Link','elisium'),

		"desc" => __('Upload a new image via the media section and place the link here. It will replace the current image.','elisium'),

		"id" => "feature3_image",

		"type" => "text",

		"std" => ""),

array("name" => __('Feature 3 Title','elisium'),

		"desc" => __('Change the title on Feature 3.','elisium'),

		"id" => "feature3_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Feature 3 Text','elisium'),

		"desc" => __('Enter the text for Feature 3.','elisium'),

		"id" => "feature3_text",

		"std" => "",

		"type" => "textarea"),

//FEATURE 4

array("name" => __('Feature 4 Image Link','elisium'),

		"desc" => __('Upload a new image via the media section and place the link here. It will replace the current image.','elisium'),

		"id" => "feature4_image",

		"type" => "text",

		"std" => ""),

array("name" => __('Feature 4 Title','elisium'),

		"desc" => __('Change the title on Feature 4.','elisium'),

		"id" => "feature4_title",

		"std" => "",

		"type" => "text"),

array("name" => __('Feature 4 Text','elisium'),

		"desc" => __('Enter the text for Feature 4.','elisium'),

		"id" => "feature4_text",

		"std" => "",

		"type" => "textarea"),

array("type" => "close")

);

function p2h_settings_page() {
   global $themename, $shortname, $version, $p2h_options, $option_group, $option_name;
?>

<div class="wrap">
<div class="options_wrap">
<?php screen_icon(); ?><h2><?php echo $themename; ?> <?php _e('Theme Options','elisium'); ?></h2>
<p class="top-notice"><?php _e('Customize your WordPress blog with these settings. ','elisium'); ?></p>
<?php if ( isset ( $_POST['reset'] ) ): ?>
<?php // Delete Settings
global $wpdb, $themename, $shortname, $version, $p2h_options, $option_group, $option_name;
delete_option('p2h_theme_options');
wp_cache_flush(); ?>
<div class="updated fade"><p><strong><?php _e( $themename. ' options reset.' ); ?></strong></p></div>

<?php elseif ( isset ( $_REQUEST['updated'] ) ): ?>
<div class="updated fade"><p><strong><?php _e( $themename. ' options saved.' ); ?></strong></p></div>
<?php endif; ?>

<form method="post" action="options.php">

<?php settings_fields( $option_group ); ?>

<?php $options = get_option( $option_name ); ?>

<?php foreach ($p2h_options as $value) {
if ( isset($value['id']) ) { $valueid = $value['id'];}

switch ( $value['type'] ) {

case "section":

?>

	<div class="section_wrap">

	<h3 class="section_title"><?php echo $value['name']; ?>

<?php break;

case "section-desc":

?>

	<span><?php echo $value['name']; ?></span></h3>

	<div class="section_body">

<?php

break;

case 'text':

?>

	<div class="options_input options_text">

		<div class="options_desc"><?php echo $value['desc']; ?></div>

		<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>

		<input name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( isset( $options[$valueid]) ){ esc_attr_e($options[$valueid]); } else { esc_attr_e($value['std']); } ?>" />

	</div>

<?php

break;

case 'textarea':

?>

	<div class="options_input options_textarea">

		<div class="options_desc"><?php echo $value['desc']; ?></div>

		<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>

		<textarea name="<?php echo $option_name.'['.$valueid.']'; ?>" type="<?php echo $option_name.'['.$valueid.']'; ?>" cols="" rows=""><?php if ( isset( $options[$valueid]) ){ esc_attr_e($options[$valueid]); } else { esc_attr_e($value['std']); } ?></textarea>

	</div>

<?php

break;

case 'select':

?>

	<div class="options_input options_select">

		<div class="options_desc"><?php echo $value['desc']; ?></div>

		<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>

		<select name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>">

		<?php foreach ($value['options'] as $option) { ?>

				<option <?php if ($options[$valueid] == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>

		</select>

	</div>

<?php

break;

case "radio":

?>

	<div class="options_input options_select">

		<div class="options_desc"><?php echo $value['desc']; ?></div>

		<span class="labels"><label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label></span>

		  <?php foreach ($value['options'] as $key=>$option) { 
			if ( isset ( $options[$valueid] ) ) {
				if ($key == $options[$valueid] ) {
					$checked = "checked=\"checked\"";
					} else {
						$checked = "";
					}
			}else{
				if($key == $value['std']){
					$checked = "checked=\"checked\"";
				}else{
					$checked = "";
				}
			}?>

			<input type="radio" id="<?php echo $option_name.'['.$valueid.']'; ?>" name="<?php echo $option_name.'['.$valueid.']'; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />

			<?php } ?>

	</div>

<?php

break;

case "checkbox":

?>

	<div class="options_input options_checkbox">

		<div class="options_desc"><?php echo $value['desc']; ?></div>

		<?php if( isset( $options[$valueid] ) ){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>

		<input type="checkbox" name="<?php echo $option_name.'['.$valueid.']'; ?>" id="<?php echo $option_name.'['.$valueid.']'; ?>" value="true" <?php echo $checked; ?> />

		<label for="<?php echo $option_name.'['.$valueid.']'; ?>"><?php echo $value['name']; ?></label>

	 </div>

<?php

break;

case "close":

?>

</div><!--#section_body-->

</div><!--#section_wrap-->

<?php
break;

}

}

?>

<span class="submit">
<input class="button button-primary" type="submit" name="save" value="<?php _e('Save All Changes', 'elisium') ?>" />
</span>
</form>

<form method="post" action="">

<span class="button-right" class="submit">

<input class="button button-secondary" type="submit" name="reset" value="<?php _e('Reset/Delete Settings', 'elisium') ?>" />
<input type="hidden" name="action" value="reset" />
<span><?php _e('Caution: All entries will be deleted from database. Press when starting afresh or completely removing the theme.','elisium') ?></span>

</span>

</form>
</div><!--#options-wrap-->
</div>

<?php } ?>