Created
December 26, 2023 16:08
-
-
Save sandeepjain2015/b6b5c8d0094382eb4f30d22e91a6c8b1 to your computer and use it in GitHub Desktop.
Add popup box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Previous attempts | |
* | |
* @package Tutor\Templates | |
* @subpackage Single\Quiz | |
* @author Themeum <support@themeum.com> | |
* @link https://themeum.com | |
* @since 1.6.4 | |
*/ | |
use TUTOR\Input; | |
$previous_attempts = tutor_utils()->quiz_attempts(); | |
$attempted_count = is_array( $previous_attempts ) ? count( $previous_attempts ) : 0; | |
$attempts_allowed = tutor_utils()->get_quiz_option( $quiz_id, 'attempts_allowed', 0 ); | |
$attempt_remaining = (int) $attempts_allowed - (int) $attempted_count; | |
$feedback_mode = tutor_utils()->get_quiz_option( $quiz_id, 'feedback_mode', 0 ); | |
?> | |
<style> | |
.modal { | |
display: none; | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
background-color: rgba(0, 0, 0, 0.7); | |
justify-content: center; | |
align-items: center; | |
z-index: 200; | |
} | |
.modal-content { | |
background-color: #fff; | |
padding: 20px; | |
border-radius: 8px; | |
text-align: center; | |
} | |
.modal h2 { | |
color: #4CAF50; | |
} | |
.modal p { | |
margin-bottom: 20px; | |
} | |
.modal button { | |
padding: 10px 20px; | |
background-color: #4CAF50; | |
color: #fff; | |
border: none; | |
border-radius: 4px; | |
cursor: pointer; | |
} | |
.last-quiz-close { | |
position: absolute; | |
top: 0px; /* Adjust the top value as needed */ | |
right: 0px; /* Adjust the right value as needed */ | |
color: black; | |
border: 1px solid red; | |
} | |
</style> | |
<?php | |
$last_quiz = current($previous_attempts); | |
$passing_grade = tutor_utils()->get_quiz_option( $last_quiz->ID, 'passing_grade', 0 ); | |
$earned_percentage = $last_quiz->earned_marks > 0 ? ( number_format( ( $last_quiz->earned_marks * 100 ) / $last_quiz->total_marks ) ) : 0; | |
$modal_id = $earned_percentage >= $passing_grade ? 'passModal' : 'failModal'; | |
?> | |
<div id="<?php echo esc_attr($modal_id); ?>" class="modal"> | |
<div class="modal-content"> | |
<a class="last-quiz-close" href="#">×</a> | |
<?php if ($earned_percentage >= $passing_grade) : ?> | |
<h2>Congratulations!</h2> | |
<p>You have passed the quiz.</p> | |
<img src="https://c.tenor.com/L6YLWbYrUZwAAAAC/tenor.gif"/> | |
<?php else : ?> | |
<h2>Sorry!</h2> | |
<p>You need to retake the video module again.</p> | |
<button onclick="redirectToModule()">Go to Module</button> | |
<?php endif; ?> | |
</div> | |
</div> | |
<script> | |
// Display the appropriate modal based on PHP condition | |
<?php if ($earned_percentage >= $passing_grade) : ?> | |
document.getElementById('passModal').style.display = 'flex'; | |
<?php else : ?> | |
document.getElementById('failModal').style.display = 'flex'; | |
<?php endif; ?> | |
function closeModal() { | |
document.getElementById('passModal').style.display = 'none'; | |
} | |
function redirectToModule() { | |
// Redirect to the module URL | |
window.location.href = 'path/to/redirect/module'; | |
} | |
</script> | |
<?php | |
if ( Input::has( 'view_quiz_attempt_id' ) ) { | |
// Load single attempt details if ID provided. | |
$attempt_id = Input::get( 'view_quiz_attempt_id', 0, Input::TYPE_INT ); | |
if ( $attempt_id ) { | |
$user_id = get_current_user_id(); | |
$attempt_data = tutils()->get_attempt( $attempt_id ); | |
tutor_load_template_from_custom_path( | |
tutor()->path . '/views/quiz/attempt-details.php', | |
array( | |
'attempt_id' => $attempt_id, | |
'attempt_data' => $attempt_data, | |
'user_id' => $user_id, | |
'context' => 'course-single-previous-attempts', | |
) | |
); | |
return; | |
} | |
} | |
tutor_load_template_from_custom_path( | |
tutor()->path . '/views/quiz/attempt-table.php', | |
array( | |
'attempt_list' => $previous_attempts, | |
'context' => 'course-single-previous-attempts', | |
) | |
); | |
if ( 'retry' == $feedback_mode && ( ( $attempt_remaining > 0 || 0 == $attempts_allowed ) && $previous_attempts ) ) { | |
do_action( 'tutor_quiz/start_form/before', $quiz_id ); | |
?> | |
<div class="tutor-quiz-btn-grp tutor-mt-32"> | |
<form id="tutor-start-quiz" method="post"> | |
<?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> | |
<input type="hidden" value="<?php echo esc_attr( $quiz_id ); ?>" name="quiz_id"/> | |
<input type="hidden" value="tutor_start_quiz" name="tutor_action"/> | |
<button type="submit" class="tutor-btn tutor-btn-primary tutor-btn-md start-quiz-btn" name="start_quiz_btn" value="start_quiz"> | |
<?php esc_html_e( 'Start Quiz', 'tutor' ); ?> | |
</button> | |
</form> | |
</div> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment