<?php
/**
 * Template Quizes
 */
get_header();
?>
<div class="page-content ulp-single-quiz">
	<div class="ulp-quiz-main-title"><?php echo get_the_title();?></div>
	<?php $UlpPublicQuiz = new UlpPublicQuiz();?>
	<?php if($UlpPublicQuiz->is_main_section()): ?>
	<div class="ul-quiz-main-details">
    	<div class="ul-quiz-time">
			<i class="fa-ulp fa-quiz_time"></i>
			<?php
            echo _e('Time ','ulp'); ?>
             <span class="ulp-quiz-counts">
            <?php
            echo  $UlpPublicQuiz->getQuizTime();
            echo _e(' minute(s)','ulp');  ?>
            </span>
        </div>
        <div class="ul-quiz-questions-count">
			 <i class="fa-ulp fa-quiz_questions"></i>
    		 <span class="ulp-quiz-counts">
			<?php echo  $UlpPublicQuiz->getQuizQuestionsCount(); ?>
            </span>
            <?php echo _e(' Questions','ulp'); ?>
        </div>
		<?php if ($UlpPublicQuiz->getRetakeMeta() > 1):?>
        <div class="ul-quiz-retake">
			<i class="fa-ulp fa-quiz_retake"></i>
    		<?php echo _e('Retake  ','ulp');  ?>
            <span class="ulp-quiz-counts">
			<?php
            echo $UlpPublicQuiz->getRetakeAttempts();
			echo '/'. $UlpPublicQuiz->getRetakeMeta();
			?>
            </span>
        </div>
		<?php endif;?>

        <?php if ($UlpPublicQuiz->getRewardPoints() > 0):?>
        <div class="ul-quiz-rewardpoints">
			<i class="fa-ulp fa-quiz_reward"></i>
    		<?php echo _e('Reward Points  ','ulp');  ?>
            <span class="ulp-quiz-counts">
			<?php
            echo $UlpPublicQuiz->getRewardPoints();
			?>
            </span>
        </div>
		<?php endif;?>
        <div class="ul-quiz-grade">
    		<?php
			echo _e('Requires ','ulp');
			echo $UlpPublicQuiz->getGradeValue() . $UlpPublicQuiz->getGradeType();
			echo _e(' to pass the Quiz','ulp'); ?>
        </div>
   </div>
  <?php endif; ?>
	<?php if ($UlpPublicQuiz->getTheContent()):?>
		<div class="ul-quiz-main-summary">
		<?php echo $UlpPublicQuiz->getTheContent();?>
		</div>
	<?php endif;?>

	<?php if($UlpPublicQuiz->is_main_section()): ?>
	<div class="ulp-lesson-navigation-wrapper">
		<?php echo $UlpPublicQuiz->Navigation();?>
	</div>
   <?php endif;?>

	<?php if ($UlpPublicQuiz->getPagination()):?>
		<div class="ulp-pagination"><?php echo $UlpPublicQuiz->getPagination();?></div>
	<?php endif;?>
    <?php if($UlpPublicQuiz->is_main_section()): ?>
	  <?php if ($UlpPublicQuiz->CoursePermalink()):?>
          <div class="ulp-quiz-course-link">
          <div><?php _e('Back to', 'ulp');?></div>
          <?php echo $UlpPublicQuiz->CoursePermalink();?>
          </div>
      <?php endif; ?>
   <?php endif;?>
</div>

<!-- Ocean added code for count time user spent on this lesson page -->

<?php 

$duration_value = get_post_meta($UlpPublicQuiz->getQuizId(), 'quiz_time', TRUE);
$duration_type =  'm';

?>
<div id="timer"></div>
<script type="text/javascript">
  var timerVar = setInterval(countTimer, 1000);
  var totalSeconds = 0;
  function countTimer() {
       ++totalSeconds;
       var hour = Math.floor(totalSeconds /3600);
       var minute = Math.floor((totalSeconds - hour*3600)/60);
       var seconds = totalSeconds - (hour*3600 + minute*60);
       if(hour < 10)
         hour = "0"+hour;
       if(minute < 10)
         minute = "0"+minute;
       if(seconds < 10)
         seconds = "0"+seconds;

       if(totalSeconds%60 == 0){
        jQuery.ajax({
            type    : "post",
            url     : '<?php echo get_site_url(); ?>/wp-admin/admin-ajax.php',
            data    : {
                       action    : "ulp_user_custom_timer",
                       user_id   : '<?php echo get_current_user_id(); ?>',
                       course_id   : '<?php echo $UlpPublicQuiz->getCourseId(); ?>',
                       item_id   : '<?php echo $UlpPublicQuiz->getQuizId(); ?>',
                       item_type   : 'quiz',
                       duration   : '<?php echo $duration_value; ?>',
                       duration_type   : '<?php echo $duration_type; ?>',
            },
            success : function (response) {
              
            }
        });
       }
       jQuery("#timer").html(hour + ":" + minute + ":" + seconds);
    }
</script>

<?php
do_action( 'ulp_course_curriculum_item', $UlpPublicQuiz->getCourseId(), $UlpPublicQuiz->getQuizId() );

global $post;
//do_action('ulp_sidebars', @$post->ID);
get_footer();
