<?php
/**
 * Template Course
 */
get_header();
global $post;
$course = new UlpCourse($post->ID);

if(is_user_logged_in() && $course->IsEntrolled()){
        
        /* Added check by ocean to restrict user by accessing other tabs before completing his'her profile information */
        
        $flag = false;
        $user_ID = get_current_user_id();
		$userData = get_user_meta( $user_ID );

// 		if(isset($userData['first_name'][0]) && $userData['first_name'][0] != '' &&  isset($userData['last_name'][0]) && $userData['last_name'][0] != '' && isset($userData['driverslicense'][0]) && $userData['driverslicense'][0] != '' && isset($userData['phone'][0]) && $userData['phone'][0] != '' && isset($userData['duidate'][0]) && $userData['duidate'][0] != '' && isset($userData['citation'][0]) && $userData['citation'][0] != '' && isset($userData['hearaboutus'][0]) && $userData['hearaboutus'][0] != '' && isset($userData['courtlocation1'][0]) && $userData['courtlocation1'][0] != '' && isset($userData['dateofbirth'][0]) && $userData['dateofbirth'][0] != ''){
		if(isset($userData['complete_profile'][0]) && $userData['complete_profile'][0] == 1){
		    $flag = true;
		}else{
		    if(isset($userData['first_name'][0]) && $userData['first_name'][0] != '' &&  isset($userData['last_name'][0]) && $userData['last_name'][0] != '' && isset($userData['driverslicense'][0]) && $userData['driverslicense'][0] != '' && isset($userData['phone'][0]) && $userData['phone'][0] != '' && isset($userData['duidate'][0]) && $userData['duidate'][0] != '' && isset($userData['citation'][0]) && $userData['citation'][0] != '' && isset($userData['hearaboutus'][0]) && $userData['hearaboutus'][0] != '' && isset($userData['courtlocation1'][0]) && $userData['courtlocation1'][0] != '' && isset($userData['dateofbirth'][0]) && $userData['dateofbirth'][0] != ''){
		        update_user_meta($user_ID, 'complete_profile', '1');
		        $flag = true;
		    }else{
		        update_user_meta($user_ID, 'complete_profile', '0');
		        $flag = false;
		    }
		}
		
        $current_url= $_SERVER['REQUEST_URI'];
        
		if(!$flag && !stripos($current_url,"ihc_ap_menu=profile")){
			wp_safe_redirect(get_home_url()."/arizona-dui-account-page/?ihc_ap_menu=profile");
	        exit;
		}
		
		if(!$flag){ ?>
		    <script>
		    setTimeout(function(){
		        jQuery('.ihc-ap-wrap h2 strong').css('color', '#dd3333');
		    }, 2000);
		        setTimeout(function(){ 
		            jQuery('.ihc-ap-wrap h2 strong').css('color', '#333333');
		        }, 5000);
		    </script>
		<?php }
		
		/* Ocean ends */

    
    
}

?>

<div class="page-content ulp-course-wrapp ulp-course-enrolled">
	 <h1><?php the_title();?></h1>
        <div class="ulp-top-section">
        <?php if( $course->IsFeatured()): ?>
            <span class="ulp-sale"><span class="ulp-text-sale"><?php _e('NEW', 'ulp');?></span></span>
        <?php endif;?>
		<?php if ($course->FeatureImage()):?>
				<div class="ulp-feat-img-wrapp">
                	<div class="ultp-feat-img-single-course" style="min-width:<?php echo Ulp_Global_Settings::get('ulp_singlecourse_imagesize_width');?>px; height:<?php echo Ulp_Global_Settings::get('ulp_singlecourse_imagesize_height');?>px; background-image:url('<?php echo $course->FeatureImage();?>');">
                    </div>
				</div>
		<?php endif;?>
        </div>
	<div class="ulp-main-section">
			<div class="ulp-left-content">
            	<div class="ulp-short-description"><?php  echo $course->Excerpt();?></div>
            	<div class="ulp-course-progress-wrapp">
                	<h2><?php echo __('You are Enrolled in this Service ', 'ulp'); ?><span><?php echo __('Enrollment Date: ', 'ulp'); ?><?php echo $course->EntrolledDate(false);?></span></h2>
                    <div class="ulp-progress-details"><?php echo __('In Progress ', 'ulp'); ?><?php echo $course->Progress();?><span><?php echo ' ('.__(' you must complete the course before ', 'ulp').$course->ExpireDate(false).' )';?></span></div>
            		<div class="ulp-progress-bar">
									<div class="ulp-progress-completed" style="width:<?php echo $course->Progress();?>;"></div>
                </div>
				<?php echo do_shortcode("[ulp-finish-course-bttn course_id={$post->ID}]");?>

                	<div class="ulp-course-results">
					<?php $course_results = $course->CourseResult();
                        if($course_results['grade'] > 0){
                            echo __('Your course grade is: ', 'ulp').'<strong>'.$course_results['grade'].'/'.$course->PassingValue().'</strong>.';
							if($course_results['course_passed'] == 1){
						 		echo __(' You have Passed the Course!', 'ulp');
						 	}elseif($course_results['course_passed'] == 0){
						 		echo __(' You have not passed the Course!', 'ulp');
						 	}
                        }

                    /*if ($course->IsEntrolled() && $course->IsCompleted()):?>
                            <h3><?php _e('Course Completed', 'ulp');?></h3>
                    <?php endif; */ ?>
					</div>

            	</div>
  			 <?php echo do_shortcode("[ulp_watch_list_bttn course_id={$post->ID} show='button']");?>
			  <?php echo do_shortcode("[ulp_notes_form course_id={$post->ID}]");?>
            </div>
            <div class="ulp-right-sidebar">
            <ul class="ulp-top-details">
                  <li>
                      <div class="ulp-avatar">
                          <img src="<?php echo $course->AuthorImage(); ?>" />
                      </div>
                      <label><?php echo __('Teacher ', 'ulp'); ?></label>
                      <strong><?php  echo $course->Author(FALSE);?></strong>
                  </li>
                  <!--<li>
                      <label><?php echo __('Students ', 'ulp'); ?></label>
                      <strong><?php  echo $course->TotalStudents() . '/'.$course->MaxEnrolledStudents().' '. __('Students ', 'ulp');;?></strong>
                  </li>-->
                  <li>
                      <label><?php echo __('Category ', 'ulp'); ?></label>
                      <strong><?php  echo  $course->Categories(TRUE);?></strong>
                  </li>
                  <li>
                      <label><?php echo $course->TotalModules() .__(' Modules ', 'ulp') ;?></label>
                      <strong><?php echo $course->TotalLessons(). __(' Lessons ', 'ulp') . '/'. $course->TotalQuizes() . __(' Quizzes ', 'ulp');?></strong>
                  </li>
                  <?php if($course->Difficulty() != ''): ?>
                  <li>
                      <label><?php echo __('Difficulty ', 'ulp'); ?></label>
                      <strong><?php  echo  $course->Difficulty();?></strong>
                  </li>
                  <?php endif; ?>
                  <?php if($course->CourseTimePeriod() != ''): ?>
                  <li>
                      <label><?php echo __('Estimated Time ', 'ulp'); ?></label>
                      <strong><?php  echo  $course->CourseTimePeriod();?></strong>
                  </li>
                  <?php endif; ?>
                  <?php if($course->RewardPoints()): ?>
                  <!--<li>
                      <label><?php echo __('Reward Points', 'ulp'); ?></label>
                      <strong><?php  echo  $course->RewardPoints(). __(' points', 'ulp');?></strong>
                  </li>-->
                  <?php endif; ?>
              </ul>
            </div>
     </div>

     <div class="ulp-single-course-menu-wrapper">
     	<?php do_action('ulp_before_print_single_course', $post->ID);?>
     </div>

     <div class="ulp-single-course-content-wrapper" id="ulp_single_course_overview_page" >

      <div class="ulp-single-course-content-description">
		<?php while (have_posts()):?>
            <?php the_post();?>
            <?php the_content();?>
        <?php endwhile;?>
	   </div>
		 
		 <?php echo do_shortcode( "[ulp-course-curriculum course_id={$post->ID}]" );?>

    <div class="ulp-single-course-alsobought">
		<?php echo do_shortcode("[ulp_students_also_bought course_id='{$post->ID}']");?>
	</div>

    <div class="ulp-single-course-instructor">
		<?php echo do_shortcode("[ulp_about_the_instructor instructor_id='{$course->AuthorID()}']");?>
	</div>

	<?php if($course->Additional_Instructors()): ?>
    	<div class="ulp-single-course-instructors">
        	<h2><?php _e("Course Instructors ", 'ulp'); ?></h2>
            <div class="ulp-course-instructors-list">
            	<?php foreach($course->Additional_Instructors() as $object){
					$user_info = get_userdata($object);
					?>
                <div class="ulp-course-instructor">
                  <img src="<?php echo esc_url( get_avatar_url( $object )); ?>"/>
                  <div class="ulp-instructor-name"><?php echo $user_info->last_name .  " " . $user_info->first_name; ?></div>
                </div>
				<?php } ?>
                <div class="ulp-clear"></div>
            </div>
        </div>
    <?php endif; ?>

    <!--<div class="ulp-single-course-reviews">
		<?php echo do_shortcode("[ulp_review_form course_id={$post->ID}]");?>
		<?php echo do_shortcode("[ulp_reviews_awesome_box course_id={$post->ID}]");?>
		<?php echo do_shortcode("[ulp_list_reviews course_id={$post->ID}]");?>
        <div class="ulp-course ulp-course-the-rating-wrapp">
			<div class="<?php echo 'ulp-rating-' . $course->Rating();?>"></div>
		</div>
    </div>-->

    <div class="ulp-single-course-more-courses-by">
		<?php echo do_shortcode("[ulp-more-courses-by instructor_id={$course->AuthorID()} course_id={$post->ID} limit=3]"); ?>
    </div>

	</div>
	<?php do_action('ulp_after_single_course', '', true);?>


    <div class="ulp-single-course-notes ulp-display-none" id="ulp_single_course_notes_page">
        <h2><?php _e("Your Course Notes", 'ulp'); ?></h2>
    	<?php echo do_shortcode("[ulp_list_notes course_id={$post->ID}]");?>
	</div>

    <?php do_action('ulp_single_course_after_overview_content', $post->ID);?>

</div>



<?php //do_action('ulp_sidebars', $post->ID);?>
<?php get_footer();?>
