<?php

global $_opt, $doc_url, $slider_slug, $theme_setting_slug;
	   $skin = cloudfw_get_current_skin();

/*----------------------------------------------------------------------------------*/
// CloudFW Guide
$g_page = 'admin.php?page='.$theme_setting_slug.'&q=1&';

$guide["installing"] = array(
	'msg' => sprintf(__('Activate %s','cloudfw'), CLOUD_THEMENAME ), 
	'score' => 3,
	'done'	=> TRUE
	);

$guide["doc"] = array(
	'msg' => __('Take a look at theme documentation','cloudfw'), 
	'score' => 1,
	'url'	=> $doc_url,
	'custom_text'	=> array(__('mark as read','cloudfw'),__('mark as unread','cloudfw'))
	);

/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Visual','cloudfw')
	);

$guide["logo"] = array(
	'msg' 	=> __('Upload a logo image','cloudfw'), 
	'score' => 4,
	'url'	=> $g_page.'tab=general&jump=0',
	'done'	=> (!empty($_opt[PFIX."_logo"]["image"]) && $_opt[PFIX."_logo"]["image"] !== TMP_URL.'/lib/imgs/logo.png')? TRUE: FALSE,
	);

$guide["skin"] = array(
	'msg' 	=> __('Import a skin file or create your own color skin','cloudfw'), 
	'score' => 4,
	'url'	=> $g_page.'tab=skins&jump=0',
	'done'	=> ($skin["mode"] !== 'defined' && $skin["id"] !== PFIX.'_skin_default_data' ) ? TRUE: FALSE
	);

/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('General','cloudfw')
	);

$guide["head_foot"] = array(
	'msg'	=> __('Set header & footer layout','cloudfw'), 
	'score'	=> 2,
	'url'	=> $g_page.'tab=general&jump=0'
	);


$guide["widgets"] = array(
	'msg'	=> __('Manage sidebar, header and footer widgets','cloudfw'), 
	'score'	=> 2,
	'url'	=> admin_url('widgets.php'),
	);


/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Sliders','cloudfw')
	);


$guide["sample_sliders"] = array(
	'msg'	=> __('Generate sample sliders','cloudfw'), 
	'score'	=> 5,
	'url'	=> $g_page.'sliderCreateSample=true&nonce='.wp_create_nonce('cloudfw'),
	'done'	=> (!empty($_opt[PFIX."_slider_ids"]))? TRUE: FALSE,
	'help'	=> '<a class="inlink" href="admin.php?page='.$slider_slug.'">'.__('manage sliders','cloudfw').'</a>',
	'unlink'=> false
	);


/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Homepage','cloudfw')
	);

$guide["hmcontent"] = array(
	'msg'	=> __('Create & define sample homepage','cloudfw'), 
	'score'	=> 5,
	'url'	=> 'javascript:void(0);',
	'done'	=> (get_option('page_on_front'))? TRUE: FALSE,
	'help'	=> (get_option('page_on_front'))? '<a class="inlink" href="post.php?action=edit&post='.get_option('page_on_front').'">'.__('edit','cloudfw').'</a>': NULL,
	'unlink'=> false,
	'modal'	=> array('title' => 'Create Sample Homepage', 'id' => 'mb_guide_create_sliders')
	);


/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Blog','cloudfw')
	);

$guide["blogcreate"] = array(
	'msg'	=> __('Create & define blog page','cloudfw'), 
	'score'	=> 5,
	'url'	=> $g_page.'createBlog=true&nonce='.wp_create_nonce('cloudfw'),
	'done'	=> (get_option('page_for_posts'))? TRUE: FALSE,
	'help'	=> (get_option('page_for_posts'))? '<a class="inlink" href="post.php?action=edit&post='.get_option('page_for_posts').'">'.__('edit','cloudfw').'</a>': NULL,
	'unlink'=> true
	);

/*----------------------------------------------------------------------------------*/


$guide[] = array(
	'group'	=> __('Portfolio','cloudfw')
	);


$guide["portcatcreate"] = array(
	'msg'	=> __('Create some portfolio categories','cloudfw'), 
	'score'	=> 1,
	'url'	=> admin_url('edit-tags.php?taxonomy=cat-portfolio&post_type=portfolio'),
//	'done'	=> (count((array) get_terms('cat-portfolio', 'hide_empty=0'))>0)? TRUE: FALSE,
	);

$guide["portpostcreate"] = array(
	'msg'	=> __('Create some portfolio posts','cloudfw'), 
	'score'	=> 4,
	'url'	=> admin_url('post-new.php?post_type=portfolio'),
	'done'	=> (count((array) get_terms('cat-portfolio', 'hide_empty=0'))>0)? TRUE: FALSE,
	);

$guide["portpagecreate"] = array(
	'msg'	=> __('Insert your portfolio into a page via shortcode generator','cloudfw'), 
	'score'	=> 3,
	'url'	=> admin_url('post-new.php?post_type=page'),
	);


/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Navigation Menu','cloudfw')
	);


$guide["navmenu"] = array(
	'msg'	=> __('Manage the navigation menu','cloudfw'), 
	'score'	=> 3,
	'url'	=> 'nav-menus.php',
	'done'	=> ( has_nav_menu( 'primary' ) )? TRUE: FALSE
	);


/*----------------------------------------------------------------------------------*/

$guide[] = array(
	'group'	=> __('Optional','cloudfw')
	);

$guide["mods_reg"] = array(
	'msg'	=> __('Activate custom registration module','cloudfw'), 
	'score'	=> 0,
	'url'	=> $g_page.'tab=general&jump=2',
	'done'	=> (_isOnOff($_opt[PFIX."_registration"]["activate"]) )? TRUE: FALSE
	);

$guide["mods_gmap"] = array(
	'msg'	=> __('Insert a Google maps api key','cloudfw'), 
	'score'	=> 0,
	'url'	=> $g_page.'tab=general&jump=3',
	'done'	=> (!empty($_opt[PFIX."_apis"]["gmap_api_key"]) )? TRUE: FALSE
	);

$guide["acga"] = array(
	'msg'	=> __('Insert your Google Analytics account information','cloudfw'), 
	'score'	=> 0,
	'url'	=> $g_page.'tab=system&jump=1',
	'done'	=> (!empty($_opt[PFIX."_ga_profile"]) )? TRUE: FALSE
	);

$guide["backup"] = array(
	'msg'	=> __('Backup all options','cloudfw'), 
	'score'	=> 0,
	'url'	=> $g_page.'tab=system&jump=2'
	);

$guide["vote"] = array(
	'msg'	=> __('Please vote the theme on ThemeForest','cloudfw'), 
	'score'	=> 0,
	'url'	=> get_template_item_page_url()
	);

/*----------------------------------------------------------------------------------*/

$total_score = $percent = 0;

foreach ($guide as $gid => $guide_item){
	if (isset($guide_item["score"]) && is_numeric($guide_item["score"]))
		(int)$total_score += $guide_item["score"];
	}

	$ratio = 100 / $total_score;
	$guide_done = $_opt[PFIX.'_setup_status'];


foreach ($guide as $gid => $guide_item){
	
	if (in_array($gid, (array)$guide_done) || $guide_item["done"]) {
		(int)$percent += ($ratio*$guide_item["score"]);
		$done = true;
		}else{$done = false; }
		
	if (isset($guide_item["group"])):
	
		$echo .= '<li class="group">'.$guide_item["group"].'</li>';
	
	else:
		if ( isset($guide_item["custom_text"]) && is_array($guide_item["custom_text"])){
			$undone_text = $guide_item["custom_text"][1];
			$done_text = $guide_item["custom_text"][0];
		}else {
			$undone_text = __('mark as undone','cloudfw');
			$done_text = __('mark as done','cloudfw');
		}
		
		if ($guide_item['modal']) {
			$modal = true;
			$modal_title = $guide_item['modal']['title'];
			$modal_id = $guide_item['modal']['id'];
			$modal_width = $guide_item['width'] ? $guide_item['width'] : 'm';
		} else {
			$modal = false;
		}

		
		$echo .= '<li id="'.$gid.'"';
		if ($done) $echo .= ' class="done"';
		$echo .= '>';
		if($guide_item["done"] == false) 
			if ($done) {
				$echo .= '<a href="#markit" class="markit">'.$undone_text.'</a>';
			} else {
				$echo .= '<a href="#markit" class="markit">'.$done_text.'</a>';
			}
		if (!empty($guide_item["help"])) $echo .= $guide_item["help"]; // HELP
		if (!empty($guide_item["url"]) && !($guide_item["unlink"] && $guide_item["done"] == true) ) 
			$echo .= '<a '._isso($modal, ' rel="'.$modal_id.'" title="'.$modal_title.'" width="'.$modal_width.'"').' href="'.$guide_item["url"].'" class="guide'._isso($modal, ' help').'">'.$guide_item["msg"].' <span class="rarr">&rarr;</span></a>'; 
		else 
			$echo .= '<span class="guide">'.$guide_item["msg"].'</span>';
		$echo .= '</li>';
	
	endif;
	
	}
	
$percent_write = ceil($percent);

?>

        
 <?php if ($in_ajax !== 'TRUE') echo
    '<script type="text/javascript">
                    
jQuery(document).ready(function() {
						
guide_per_value = jQuery("#pbar-percent").html();
jQuery("#pbar-bar").animate({"width": guide_per_value+"%"},2000);


						
jQuery(".markit").live("click",function(){

										
jQuery("#to-do-loading").show();

el = jQuery(this);
id = el.parent("li").attr("id");
if (!id) id = "__dontshowanymore";
operation = (el.parent("li").hasClass("done")) ? "undone": "done";
guide_per_value_old = jQuery("#pbar-percent-old").html();

jQuery.ajax({
  url: "'.TMP_ADMIN.'/ajax/guide.php",
  cache: false,
  data: ({id : id, op : operation, old_val : guide_per_value_old }),
  success: function(data) {
	jQuery("#guide").html(data);
	
	guide_per_value = jQuery("#pbar-percent").html();
	jQuery("#pbar-bar").animate({"width": guide_per_value+"%"},2000);
	jQuery("#to-do-loading").hide();

	
  }
});

return false;

}); //end of click
	});

    </script>
    
    ';?>


<?php if ($in_ajax !== 'TRUE') echo '<div id="guide">' ?>
<div class="framework_container">

    <div class="header"></div>
    
    <div class="content">
        
        <div class="head">
        
          <div id="to-do-loading" class="small_loading"></div> <div class="icon wand"></div>  <h1><?php _e('Configuration Wizard: Positive','cloudfw'); ?></h1>
        
        </div>
        <?php 

			echo '<span id="pbar-percent" style="display:none;">',($percent_write <10) ? 10:$percent_write,'</span> <span id="pbar-percent-old" style="display:none;">'.$percent_write.'</span>';
		
		?>
        <div id="pbar">
        		
                <div id="pbar-bar" style="width:<?php if(isset($percent_old) && $percent_old >10) echo $percent_old; else echo 10; ?>%;">
                
                	<div id="pbar-in-center"><span id="pbar-value"><?php echo $percent_write;?></span>%</div>
                    <div id="pbar-in-left"></div>
                    <div id="pbar-in-right"></div>
                
                </div>
        	
        </div>

       <div class="clear"></div>
       
       <div class="module" style="padding: 0 30px;">
              
       		<div class="grid fullpage">
                        
            	<ul class="todolist">
                   <?php echo $echo;?>
                </ul>            
            
            </div>

            
       <div class="clear"></div>
       
                   <?php if ($percent_write == 100) echo '<div style="text-align:center;">'.__('Theme Configuration Completed','cloudfw').'&nbsp;&nbsp;&nbsp;<a id="closetodolist" href="javascript:void(0);" class="small-button small-brown markit"><span>'.__('Hide The Wizard','cloudfw').'</span></a></div> <div class="clear"></div>';?>

       
       </div>
       
       
    </div>

</div> 
            
<?php if ($in_ajax !== 'TRUE') {

	echo '</div>' ?>

<span style="display: none; height: auto;" id="mb_guide_create_sliders">

<div style="padding: 20px 20px 0;">

<div class="clear"></div>

<form  class="slider_forms" action="<?php echo $g_page; ?>createHomepage=true&nonce=<?php echo wp_create_nonce('cloudfw'); ?>" method="POST">

    <div class="sg-title"><?php _e('Homepage Slider','cloudfw'); ?>:</div> 
    <span class="select">
    <select id="sliderID" name="sliderID" class="input" style="width:400px;" >

    <?php 
	
		echo '<option value=""></option>';
		$sliders = get_option(PFIX.'_slider_ids');
		
		if (is_array($sliders)): foreach ((array) $sliders as $slider_id_ => $slider){
			
			if ($slider["type"] == 'default_slider') continue;
			
			$option = '<option value="'.$slider_id_.'">';
            $option .=  esc_attr($slider["title"]);
            $option .= '</option>';
            ${'echo_'.$slider["type"]} .=  $option;
			
		} endif;
		
		
		$theme_sliders = cloudfw_sliders();
		
		foreach ($theme_sliders as $slider_id => $slider_item) {
				
			if (${'echo_'.$slider_id})
			echo '
			<optgroup label="'.$slider_item["name"].'">	'.${'echo_'.$slider_id}.'</optgroup>
			';
							
		}		

         
    ?>
         
    </select>
    </span>
    <div class="clear"></div>
    <div><a href="<?php echo $g_page.'createSliders=true&nonce='.wp_create_nonce('cloudfw'); ?>"><?php _e('Create Sample Sliders','cloudfw'); ?></a></div>
	
	<div class="divider"></div>

	<div class="clear"></div>
	<div style="margin-top: 10px !important;" class="small-button small-sky"><input type="submit" value="<?php _e('Create Sample Homepage','cloudfw'); ?>"></div>

   	</form>


<div class="clear"></div>

</div>
</span>

<?php } ?>