CrestRoad/laravel/resources/views/lms/quiz.blade.php

228 lines
10 KiB
PHP

<!DOCTYPE html>
<html lang="en">
<head>
@include('layouts.shared/title-meta', ['title' => 'Form'])
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
</head>
<div id="pageloader">
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
</div>
<body class="loading">
<div class="account-pages">
<div class="card bg-pattern">
<div class="card-body p-3 row form-body">
@if (Session::has('error'))
<div class="alert alert-danger">{{ Session::get('error') }}</div>
<br>
@endif
@if (session('success'))
<div class=" alert alert-success">{{ session('success') }}
</div>
<br>
@endif
<div class="col-12">
<h4 class="page-title">{{ $quiz->title }}</h4>
</div>
@if ($quiz->limit_attempts == 'Yes' && $quiz->number_attempts <= $quiz->existing_attempts)
<h4 class="header-title mt-3"> You have already submitted the Quiz for the maximum
number of times allowed. </h4>
@else
<!-- <h5 class="header-title mt-3"> Allowed attempts: {{ $quiz->number_attempts }} </h5>
<h5 class="header-title mt-3"> Attempts done: {{ $quiz->existing_attempts }} </h5> -->
<form id="quiz-form" enctype="multipart/form-data">
<input type="hidden" name="quiz_id" value="{{ $quiz->id }}">
<input type="hidden" name="time_taken" id="time_taken" value="">
@csrf
@php
$qc = 1;
$ols = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
@endphp
@foreach ($questions as $question)
<h4 class="header-title mt-3">{{ $qc }}) {{ $question->question }}
</h4>
@php
$ac = 0;
@endphp
@foreach ($question->options as $ans)
<div class="radio radio-success mb-2">
<input type="radio" name="answer[{{ $question->id }}]"
id="answer_{{ $question->id }}_{{ $ac }}"
value="{{ $ac }}" {{ $ac == 0 ? 'required' : '' }}>
<label for="answer_{{ $question->id }}_{{ $ac }}">
{{ $ols[$ac] }}) {{ $ans->option }}
</label>
</div>
@php
$ac++;
@endphp
@endforeach
@php
$qc++;
@endphp
@endforeach
<div class="text-center d-grid mt-3">
<button class="btn btn-primary" type="submit" id="submit-btn"> Submit
</button>
</div>
</form>
@endif
</div> <!-- end card-body -->
<div class="card-body p-3 row message-body">
<div class="col-12">
<h4 class="page-title">{{ $quiz->title }}</h4>
</div>
<div class="col-12">
<h2>Your response are successfully submitted.</h2>
</div>
<div class="col-12">
@if ($quiz->show_score)
<div class="alert alert-success bg-success text-white border-0 show_score_wrapper"
role="alert">
</div>
@endif
<div class="alert text-white border-0 show_quiz_result" role="alert"></div>
</div>
<div class="col-12">
@if ($quiz->show_answers)
@php
$qc = 1;
$ols = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
@endphp
@foreach ($questions as $question)
<h4 class="header-title mt-3">{{ $qc }}) {{ $question->question }}
</h4>
@php
$ac = 0;
@endphp
@foreach ($question->options as $ans)
<p style="margin-bottom:5px"
class="{{ $ans->is_correct ? 'text-success fw-bold ' : '' }}">
{{ $ols[$ac] }}) {{ $ans->option }}</p>
@php
$ac++;
@endphp
@endforeach
@php
$qc++;
@endphp
@endforeach
@endif
</div>
@if ($quiz->show_score)
<div class="alert alert-success bg-success text-white border-0 show_score_wrapper" role="alert">
</div>
@endif
<div class="alert text-white border-0 show_quiz_result" role="alert"></div>
<hr />
<div class="button-list col-12">
<button class="btn btn-success float-end" id="next-btn">I've completed this Quiz. Take me to Next Lesson</button>
<button class="btn btn-info float-end" id="reload-btn">I will take the Quiz again</button>
</div>
</div>
</div>
<!-- end card -->
<!-- end container -->
</div>
<!-- end page -->
<style type="text/css">
#pageloader {
background: rgba(255, 255, 255, 0.8);
display: none;
height: 100%;
position: fixed;
width: 100%;
z-index: 9999;
}
#pageloader img {
left: 50%;
margin-left: -32px;
margin-top: -32px;
position: absolute;
top: 50%;
}
</style>
@include('layouts.shared/footer-script')
<script src="{{ URL::asset('assets/js/jquery-sparkline/jquery-sparkline.min.js') }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/TimeMe.js/0.0.0/timeme.min.js" integrity="sha512-d/2frHWM/2O5PkFHnlgbxhBO0r65Dek5PVVs8wPZeXyP8Vu6dSlCRLeNa9zec8O0apaX+RfGvbxi/QBK+GxpUQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.message-body').hide()
$('#quiz-form').on('submit', function(event) {
event.preventDefault();
$("#pageloader").fadeIn();
$('#time_taken').val(TimeMe.getTimeOnCurrentPageInSeconds());
$.ajax({
type: "POST",
url: '/lmsquizsubmit',
data: $('#quiz-form').serialize(),
success: function(data) {
console.log(data)
$("#pageloader").fadeOut();
if (data.status == 'success') {
$('.message-body').show()
$('.form-body').hide()
//console.log(data)
$('.show_score_wrapper').html('You answered <strong> ' + data
.submission.correct_answers + ' correct out of ' + data
.submission.total_questions +
' </strong>questions<br />You took <strong>' + data
.submission.time_taken + ' sec</strong> to submit the Quiz')
if( (data.submission.correct_answers/data.submission.total_questions)*100 >= {{ $quiz->passing_percent }} ) {
$('.show_quiz_result').html('You have Successfully cleared the Quiz and can move to the next lesson.').addClass('alert-success').addClass('bg-success')
} else {
$('#next-btn').prop('disabled', true)
$('.show_quiz_result').html('Sorry, you have fallen short of few correct answer. We will recomend you to go through the lessons again and reattempt the quiz.').addClass('alert-danger').addClass('bg-danger')
}
}
},
});
});
TimeMe.initialize({
currentPageName: "my-home-page", // current page
idleTimeoutInSeconds: 10, // seconds
});
// $('#post-media-btn').click(function(){
//
// });
$('#next-btn').on('click', function(event){
$("#pageloader").fadeIn();
$.ajax({
type: "GET",
url: 'lmsarticlemarkcomplete?article={{$quiz->id}}&type=quiz',
processData: false,
contentType: false,
success: function( data ) {
console.log(data)
$("#pageloader").fadeOut();
if(data.status == 'success') {
window.top.invokenext('{{$quiz->id}}');
} else {
}
},
});
});
$('#reload-btn').on('click', function(event){
window.location.reload();
});
});
</script>
</body>
</html>