<?php
/**
 * Template Leasons
 */
get_header();
$UlpPublicLesson = new UlpPublicLesson();
$videoLesson = new \Indeed\Ulp\PublicSection\VideoLesson( $UlpPublicLesson->getLessonId() );

$course = new UlpCourse($UlpPublicLesson->getCourseId());
// var_dump($course->IsEntrolled());
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 */

    
    
}
?>
<?php do_action('ulp_before_single_lesson');?>

<div class="page-content ulp-lesson-wrapp">
	<?php if ($UlpPublicLesson->FeatureImage()):?>
			<div class="ulp-lesson-main-featureimage">
					<img src="<?php echo $UlpPublicLesson->FeatureImage();?>" />
			</div>
	<?php endif;?>
	<?php while (have_posts()):?>
		<?php the_post();?>
		<div class="ulp-lesson-main-title"><?php the_title();?></div>
        
		  <?php if ( $videoLesson->isYoutube() ):?>
                  <div class="ulp-lesson-video-warpper">
                      <div id="ulp_youtube_player"></div>
                  </div>
          <?php elseif ( $videoLesson->isVimeo() ):?>
                  <div class="ulp-lesson-video-warpper">
                      <div id="ulp_vimeo_player" allow="autoplay"></div>
                  </div>
          <?php endif;?>
          
	    <div class="ulp-lesson-main-content"><?php the_content();?></div>
	<?php endwhile;?>


  <div class="ulp-lesson-navigation-wrapper">
  	<?php echo $UlpPublicLesson->Navigation();?>
  </div>
  <div class="ulp-lesson-complete-button-wrapper">
  	<?php echo $UlpPublicLesson->CompleteButton();?>
  </div>
  <?php if ($UlpPublicLesson->CoursePermalink()):?>
      <div class="ulp-lesson-course-link">
      	<div><?php _e('Back to', 'ulp');?></div>
      	<?php echo $UlpPublicLesson->CoursePermalink();?>
      </div>
  <?php endif; ?>
</div>
<?php do_action( 'ulp_after_single_lesson' );?>
<?php do_action( 'ulp_course_curriculum_item', $UlpPublicLesson->getCourseId(), $UlpPublicLesson->getLessonId() );?>
<?php
global $post;
get_footer();
