body.php
5 years ago
content.php
5 years ago
no_course_belongs.php
5 years ago
previous-attempts.php
5 years ago
single_quiz_contents.php
5 years ago
top.php
5 years ago
body.php
462 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package TutorLMS/Templates |
| 4 | * @version 1.5.7 |
| 5 | */ |
| 6 | |
| 7 | |
| 8 | global $post; |
| 9 | $currentPost = $post; |
| 10 | |
| 11 | $quiz_id = get_the_ID(); |
| 12 | $is_started_quiz = tutor_utils()->is_started_quiz(); |
| 13 | |
| 14 | $previous_attempts = tutor_utils()->quiz_attempts(); |
| 15 | $attempted_count = is_array($previous_attempts) ? count($previous_attempts) : 0; |
| 16 | $questions_order = tutor_utils()->get_quiz_option($quiz_id, 'questions_order', 'rand'); |
| 17 | $attempts_allowed = tutor_utils()->get_quiz_option($quiz_id, 'attempts_allowed', 0); |
| 18 | $passing_grade = tutor_utils()->get_quiz_option($quiz_id, 'passing_grade', 0); |
| 19 | $feedback_mode = tutor_utils()->get_quiz_option($quiz_id, 'feedback_mode', 0); |
| 20 | |
| 21 | $attempt_remaining = $attempts_allowed - $attempted_count; |
| 22 | $quiz_answers = array(); |
| 23 | ?> |
| 24 | |
| 25 | <div id="tutor-quiz-body" class="tutor-quiz-body tutor-quiz-body-<?php the_ID(); ?>"> |
| 26 | <?php |
| 27 | |
| 28 | do_action('tutor_quiz/body/before', $quiz_id); |
| 29 | |
| 30 | if ($is_started_quiz){ |
| 31 | $quiz_attempt_info = tutor_utils()->quiz_attempt_info($is_started_quiz->attempt_info); |
| 32 | $quiz_attempt_info['date_time_now'] = date("Y-m-d H:i:s", tutor_time()); |
| 33 | |
| 34 | $time_limit_seconds = tutor_utils()->avalue_dot('time_limit.time_limit_seconds', $quiz_attempt_info); |
| 35 | $question_layout_view = tutor_utils()->get_quiz_option($quiz_id, 'question_layout_view'); |
| 36 | !$question_layout_view ? $question_layout_view = 'single_question' : 0; |
| 37 | |
| 38 | $hide_quiz_time_display = (bool) tutor_utils()->avalue_dot('hide_quiz_time_display', $quiz_attempt_info); |
| 39 | $hide_question_number_overview = (bool) tutor_utils()->avalue_dot('hide_question_number_overview', $quiz_attempt_info); |
| 40 | |
| 41 | $remaining_time_secs = (strtotime($is_started_quiz->attempt_started_at) + $time_limit_seconds ) - strtotime($quiz_attempt_info['date_time_now']); |
| 42 | |
| 43 | $remaining_time_context = tutor_utils()->seconds_to_time_context($remaining_time_secs); |
| 44 | $questions = tutor_utils()->get_random_questions_by_quiz(); |
| 45 | ?> |
| 46 | |
| 47 | <div class="quiz-head-meta-info"> |
| 48 | <?php |
| 49 | if ( ! $hide_quiz_time_display){ |
| 50 | ?> |
| 51 | <div class="time-remaining"> |
| 52 | <?php _e('Time remaining : '); ?> <span id="tutor-quiz-time-update" data-attempt-settings="<?php echo esc_attr(json_encode($is_started_quiz)) ?>" data-attempt-meta="<?php echo esc_attr(json_encode($quiz_attempt_info)) ?>"><?php echo $remaining_time_context; ?></span> |
| 53 | </div> |
| 54 | <?php } ?> |
| 55 | </div> |
| 56 | |
| 57 | <?php |
| 58 | if (is_array($questions) && count($questions)) { |
| 59 | ?> |
| 60 | <div id="tutor-quiz-attempt-questions-wrap" data-question-layout-view="<?php echo $question_layout_view; ?>"> |
| 61 | |
| 62 | <?php |
| 63 | if ($question_layout_view === 'question_pagination'){ |
| 64 | $question_i = 0; |
| 65 | ?> |
| 66 | <div class="tutor-quiz-questions-pagination"> |
| 67 | <ul> |
| 68 | <?php |
| 69 | foreach ($questions as $question) { |
| 70 | $question_i++; |
| 71 | echo "<li><a href='#quiz-attempt-single-question-{$question->question_id}' class='tutor-quiz-question-paginate-item'>{$question_i}</a> </li>"; |
| 72 | } |
| 73 | ?> |
| 74 | </ul> |
| 75 | </div> |
| 76 | <?php |
| 77 | } |
| 78 | ?> |
| 79 | |
| 80 | <form id="tutor-answering-quiz" method="post"> |
| 81 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 82 | <input type="hidden" value="<?php echo $is_started_quiz->attempt_id; ?>" name="attempt_id"/> |
| 83 | <input type="hidden" value="tutor_answering_quiz_question" name="tutor_action"/> |
| 84 | <?php |
| 85 | $question_i = 0; |
| 86 | foreach ($questions as $question) { |
| 87 | $question_i++; |
| 88 | $question_settings = maybe_unserialize($question->question_settings); |
| 89 | |
| 90 | $style_display = ($question_layout_view !== 'question_below_each_other' && $question_i == 1) ? 'block' : 'none'; |
| 91 | if ($question_layout_view === 'question_below_each_other'){ |
| 92 | $style_display = 'block'; |
| 93 | } |
| 94 | |
| 95 | $next_question = isset($questions[$question_i]) ? $questions[$question_i] : false; |
| 96 | ?> |
| 97 | <div id="quiz-attempt-single-question-<?php echo $question->question_id; ?>" class="quiz-attempt-single-question quiz-attempt-single-question-<?php echo $question_i; ?>" style="display: <?php echo $style_display; ?> ;" <?php echo $next_question ? "data-next-question-id='#quiz-attempt-single-question-{$next_question->question_id}'" : '' ; ?> data-quiz-feedback-mode="<?php echo $feedback_mode; ?>" > |
| 98 | |
| 99 | <?php echo "<input type='hidden' name='attempt[{$is_started_quiz->attempt_id}][quiz_question_ids][]' value='{$question->question_id}' />"; |
| 100 | |
| 101 | |
| 102 | $question_type = $question->question_type; |
| 103 | |
| 104 | $rand_choice = false; |
| 105 | if($question_type == 'single_choice' || $question_type == 'multiple_choice'){ |
| 106 | $choice = maybe_unserialize($question->question_settings); |
| 107 | if(isset($choice['randomize_question'])){ |
| 108 | $rand_choice = $choice['randomize_question'] == 1 ? true : false; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | $answers = tutor_utils()->get_answers_by_quiz_question($question->question_id, $rand_choice); |
| 113 | $show_question_mark = (bool) tutor_utils()->avalue_dot('show_question_mark', $question_settings); |
| 114 | $answer_required = (bool) tutils()->array_get('answer_required', $question_settings); |
| 115 | |
| 116 | echo '<h4 class="question-text">'; |
| 117 | if ( ! $hide_question_number_overview){ |
| 118 | echo $question_i. ". "; |
| 119 | } |
| 120 | echo stripslashes($question->question_title); |
| 121 | echo '</h4>'; |
| 122 | |
| 123 | if ($show_question_mark){ |
| 124 | echo '<p class="question-marks"> '.__('Marks : ', 'tutor').$question->question_mark.' </p>'; |
| 125 | } |
| 126 | |
| 127 | $question_description = nl2br( stripslashes($question->question_description) ); |
| 128 | if ($question_description){ |
| 129 | echo "<p class='question-description'>{$question_description}</p>"; |
| 130 | } |
| 131 | ?> |
| 132 | |
| 133 | <div class="tutor-quiz-answers-wrap question-type-<?php echo $question_type; ?> <?php echo $answer_required? 'quiz-answer-required':''; ?> "> |
| 134 | <?php |
| 135 | if ( is_array($answers) && count($answers) ) { |
| 136 | foreach ($answers as $answer){ |
| 137 | $answer_title = stripslashes($answer->answer_title); |
| 138 | $answer->is_correct ? $quiz_answers[] = $answer->answer_id : 0; |
| 139 | |
| 140 | if ( $question_type === 'true_false' || $question_type === 'single_choice' ) { |
| 141 | ?> |
| 142 | <label class="answer-view-<?php echo $answer->answer_view_format; ?>"> |
| 143 | <div class="quiz-answer-input-body"> |
| 144 | <?php |
| 145 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 146 | ?> |
| 147 | <div class="quiz-answer-image-wrap"> |
| 148 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 149 | </div> |
| 150 | <?php |
| 151 | } |
| 152 | ?> |
| 153 | <div class="quiz-answer-input-bottom"> |
| 154 | <div class="quiz-answer-input-field"> |
| 155 | <input name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>]" type="radio" value="<?php echo $answer->answer_id; ?>"> |
| 156 | <span> </span> |
| 157 | <?php |
| 158 | if ($answer->answer_view_format !== 'image'){ echo $answer_title;} |
| 159 | ?> |
| 160 | </div> |
| 161 | </div> |
| 162 | </div> |
| 163 | </label> |
| 164 | <?php |
| 165 | }elseif ($question_type === 'multiple_choice'){ |
| 166 | ?> |
| 167 | <label class="answer-view-<?php echo $answer->answer_view_format; ?>"> |
| 168 | |
| 169 | |
| 170 | <div class="quiz-answer-input-body"> |
| 171 | <?php if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ ?> |
| 172 | <div class="quiz-answer-image-wrap"> |
| 173 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 174 | </div> |
| 175 | <?php } ?> |
| 176 | |
| 177 | <div class="quiz-answer-input-bottom"> |
| 178 | <div class="quiz-answer-input-field"> |
| 179 | <input name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][]" type="checkbox" value="<?php echo $answer->answer_id; ?>"> |
| 180 | <span> </span> |
| 181 | <?php if ($answer->answer_view_format !== 'image'){ |
| 182 | echo $answer_title; |
| 183 | } ?> |
| 184 | </div> |
| 185 | </div> |
| 186 | </div> |
| 187 | </label> |
| 188 | <?php |
| 189 | } |
| 190 | elseif ($question_type === 'fill_in_the_blank'){ |
| 191 | ?> |
| 192 | <p class="fill-in-the-blank-field"> |
| 193 | <?php |
| 194 | $count_dash_fields = substr_count($answer_title, '{dash}'); |
| 195 | if ($count_dash_fields){ |
| 196 | |
| 197 | $dash_string = array(); |
| 198 | $input_data = array(); |
| 199 | for($i=1; $i <=$count_dash_fields; $i ++){ |
| 200 | $dash_string[] = '{dash}'; |
| 201 | $input_data[] = "<input type='text' name='attempt[{$is_started_quiz->attempt_id}][quiz_question][{$question->question_id}][]' class='fill-in-the-blank-text-input' />"; |
| 202 | } |
| 203 | echo str_replace($dash_string, $input_data, $answer_title); |
| 204 | } |
| 205 | ?> |
| 206 | </p> |
| 207 | <?php |
| 208 | } |
| 209 | elseif ($question_type === 'ordering'){ |
| 210 | ?> |
| 211 | <div class="question-type-ordering-item"> |
| 212 | <div class="answer-title"> |
| 213 | <?php |
| 214 | if ($answer->answer_view_format !== 'image'){ |
| 215 | echo "<p class='tutor-quiz-answer-title'>{$answer_title}</p>"; |
| 216 | } |
| 217 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 218 | ?> |
| 219 | <div class="quiz-answer-image-wrap"> |
| 220 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 221 | </div> |
| 222 | <?php |
| 223 | } |
| 224 | ?> |
| 225 | </div> |
| 226 | <span class="answer-sorting-bar"><i class="tutor-icon-menu-2"></i> </span> |
| 227 | <input type="hidden" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answers][]" value="<?php echo $answer->answer_id; ?>" > |
| 228 | </div> |
| 229 | <?php |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Question type matchind and image matching |
| 235 | */ |
| 236 | if ($question_type === 'matching' || $question_type === 'image_matching'){ |
| 237 | ?> |
| 238 | <div class="quiz-answers-type-matching-wrap <?php echo 'answer-type-'.$question_type ?> "> |
| 239 | <div class="quiz-draggable-rand-answers"> |
| 240 | <?php |
| 241 | $rand_answers = tutor_utils()->get_answers_by_quiz_question($question->question_id, true); |
| 242 | foreach ($rand_answers as $rand_answer){ |
| 243 | ?> |
| 244 | <div class="quiz-draggable-answer-item"> |
| 245 | <?php |
| 246 | if ($question_type === 'matching'){ |
| 247 | echo '<span class="draggable-answer-title">'.stripslashes($rand_answer->answer_two_gap_match).'</span>'; |
| 248 | }else{ |
| 249 | echo '<span class="draggable-answer-title">'.stripslashes($rand_answer->answer_title).'</span>'; |
| 250 | } |
| 251 | ?> |
| 252 | <span class="draggable-answer-icon"> <i class="tutor-icon-menu-2"></i> </span> |
| 253 | <input type="hidden" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answers][]" value="<?php echo $rand_answer->answer_id; ?>" > |
| 254 | </div> |
| 255 | <?php |
| 256 | } |
| 257 | ?> |
| 258 | </div> |
| 259 | |
| 260 | <div class="quiz-answer-matching-items-wrap"> |
| 261 | <?php |
| 262 | foreach ($answers as $answer){ |
| 263 | ?> |
| 264 | <div class="quiz-answer-item-matching"> |
| 265 | <div class="quiz-answer-matching-title"> |
| 266 | <?php |
| 267 | if ($question_type === 'matching') { |
| 268 | |
| 269 | if ($answer->answer_view_format !== 'image'){ |
| 270 | echo '<p class="tutor-quiz-answer-title">'.stripslashes($answer->answer_title).'</p>'; |
| 271 | } |
| 272 | if ($answer->answer_view_format === 'image' || $answer->answer_view_format === 'text_image'){ |
| 273 | ?> |
| 274 | <div class="quiz-answer-image-wrap"> |
| 275 | <img src="<?php echo wp_get_attachment_image_url($answer->image_id, 'full') ?>" /> |
| 276 | </div> |
| 277 | <?php |
| 278 | } |
| 279 | }elseif (intval($answer->image_id)){ |
| 280 | echo '<img src="'.wp_get_attachment_image_url($answer->image_id, 'full').'" />'; |
| 281 | } |
| 282 | ?> |
| 283 | </div> |
| 284 | <div class="quiz-answer-matching-droppable"></div> |
| 285 | </div> |
| 286 | <?php |
| 287 | } |
| 288 | ?> |
| 289 | |
| 290 | </div> |
| 291 | </div> |
| 292 | <?php |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * For Open Ended Question Type |
| 298 | */ |
| 299 | if ($question_type === 'open_ended' || $question_type === 'short_answer'){ |
| 300 | ?> |
| 301 | <textarea class="question_type_<?php echo $question_type; ?>" name="attempt[<?php echo |
| 302 | $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>]"></textarea> |
| 303 | <?php |
| 304 | if ($question_type === 'short_answer') { |
| 305 | $get_option_meta = tutor_utils()->get_quiz_option($quiz_id); |
| 306 | if(isset($get_option_meta['short_answer_characters_limit'])){ |
| 307 | if($get_option_meta['short_answer_characters_limit'] != "" ){ |
| 308 | $characters_limit = tutor_utils()->avalue_dot('short_answer_characters_limit', $quiz_attempt_info); |
| 309 | echo '<p class="answer_limit_desc">'. __('characters remaining', 'tutor' ) .' :<span class="characters_remaining">'.$characters_limit.'</span> </p>'; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | if ($question_type === 'open_ended') { |
| 314 | $get_option_meta = tutor_utils()->get_quiz_option($quiz_id); |
| 315 | if(isset($get_option_meta['open_ended_answer_characters_limit'])){ |
| 316 | if($get_option_meta['open_ended_answer_characters_limit'] != "" ){ |
| 317 | $characters_limit = $get_option_meta['open_ended_answer_characters_limit']; |
| 318 | echo '<p class="answer_limit_desc">'. __('characters remaining', 'tutor' ) .' :<span class="characters_remaining">'.$characters_limit.'</span> </p>'; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | |
| 325 | if ($question_type === 'image_answering'){ |
| 326 | ?> |
| 327 | <div class="quiz-image-answering-wrap"> |
| 328 | <?php |
| 329 | foreach ($answers as $answer){ |
| 330 | ?> |
| 331 | <div class="quiz-image-answering-answer"> |
| 332 | <?php |
| 333 | if (intval($answer->image_id)){ |
| 334 | ?> |
| 335 | <div class="quiz-image-answering-image-wrap"> |
| 336 | <?php echo '<img src="'.wp_get_attachment_image_url($answer->image_id, 'full').'" />'; ?> |
| 337 | </div> |
| 338 | |
| 339 | <div class="quiz-image-answering-input-field-wrap"> |
| 340 | <input type="text" name="attempt[<?php echo $is_started_quiz->attempt_id; ?>][quiz_question][<?php echo $question->question_id; ?>][answer_id][<?php echo $answer->answer_id; ?>]" > |
| 341 | </div> |
| 342 | <?php |
| 343 | } |
| 344 | ?> |
| 345 | </div> |
| 346 | <?php |
| 347 | } |
| 348 | ?> |
| 349 | </div> |
| 350 | <?php |
| 351 | } |
| 352 | ?> |
| 353 | |
| 354 | <div class="answer-help-block"></div> |
| 355 | |
| 356 | </div> |
| 357 | |
| 358 | <?php |
| 359 | if ($question_layout_view !== 'question_below_each_other'){ |
| 360 | if ($next_question){ |
| 361 | ?> |
| 362 | <div class="quiz-answer-footer-bar"> |
| 363 | <div class="quiz-footer-button"> |
| 364 | <button type="button" value="quiz_answer_submit" class="tutor-button |
| 365 | tutor-success tutor-quiz-answer-next-btn"><?php _e( 'Answer & Next Question', 'tutor' ); ?></button> |
| 366 | </div> |
| 367 | </div> |
| 368 | <?php |
| 369 | }else{ |
| 370 | ?> |
| 371 | <div class="quiz-answer-footer-bar"> |
| 372 | <div class="quiz-footer-button"> |
| 373 | <button type="submit" name="quiz_answer_submit_btn" value="quiz_answer_submit" class="tutor-button tutor-success"><?php |
| 374 | _e( 'Submit Quiz', 'tutor' ); ?></button> |
| 375 | </div> |
| 376 | </div> |
| 377 | <?php |
| 378 | } |
| 379 | } |
| 380 | ?> |
| 381 | </div> |
| 382 | |
| 383 | <?php |
| 384 | } |
| 385 | |
| 386 | if ($question_layout_view === 'question_below_each_other'){ |
| 387 | ?> |
| 388 | <div class="quiz-answer-footer-bar"> |
| 389 | <div class="quiz-footer-button"> |
| 390 | <button type="submit" name="quiz_answer_submit_btn" value="quiz_answer_submit" class="tutor-button |
| 391 | tutor-success"><?php _e( 'Submit Quiz', 'tutor' ); ?></button> |
| 392 | </div> |
| 393 | </div> |
| 394 | <?php } ?> |
| 395 | |
| 396 | </form> |
| 397 | </div> |
| 398 | |
| 399 | <?php |
| 400 | |
| 401 | }else{ |
| 402 | ?> |
| 403 | <div class="start-quiz-wrap"> |
| 404 | <form id="tutor-finish-quiz" method="post"> |
| 405 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 406 | |
| 407 | <input type="hidden" value="<?php echo $quiz_id; ?>" name="quiz_id"/> |
| 408 | <input type="hidden" value="tutor_finish_quiz_attempt" name="tutor_action"/> |
| 409 | |
| 410 | <button type="submit" class="tutor-button" name="finish_quiz_btn" value="finish_quiz"> |
| 411 | <i class="icon-floppy"></i> <?php _e( 'Finish', 'tutor' ); ?> |
| 412 | </button> |
| 413 | </form> |
| 414 | </div> |
| 415 | |
| 416 | <?php |
| 417 | } |
| 418 | }else{ |
| 419 | if ($attempt_remaining > 0 || $attempts_allowed == 0) { |
| 420 | do_action('tuotr_quiz/start_form/before', $quiz_id); |
| 421 | ?> |
| 422 | <div class="start-quiz-wrap"> |
| 423 | <form id="tutor-start-quiz" method="post"> |
| 424 | <?php wp_nonce_field( tutor()->nonce_action, tutor()->nonce ); ?> |
| 425 | |
| 426 | <input type="hidden" value="<?php echo $quiz_id; ?>" name="quiz_id"/> |
| 427 | <input type="hidden" value="tutor_start_quiz" name="tutor_action"/> |
| 428 | |
| 429 | <button type="submit" class="tutor-button" name="start_quiz_btn" value="start_quiz"> |
| 430 | <i class="icon-hourglass-1"></i> <?php _e( 'Start Quiz', 'tutor' ); ?> |
| 431 | </button> |
| 432 | </form> |
| 433 | </div> |
| 434 | |
| 435 | <?php |
| 436 | do_action('tuotr_quiz/start_form/after', $quiz_id); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | |
| 441 | if ($previous_attempts){ |
| 442 | do_action('tutor_quiz/previous_attempts_html/before', $previous_attempts, $quiz_id); |
| 443 | |
| 444 | ob_start(); |
| 445 | tutor_load_template('single.quiz.previous-attempts', compact('previous_attempts', 'quiz_id')); |
| 446 | $previous_attempts_html = ob_get_clean(); |
| 447 | echo apply_filters('tutor_quiz/previous_attempts_html', $previous_attempts_html, $previous_attempts, $quiz_id); |
| 448 | |
| 449 | do_action('tutor_quiz/previous_attempts/after', $previous_attempts, $quiz_id); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | |
| 454 | tutor_next_previous_pagination(); |
| 455 | |
| 456 | do_action('tutor_quiz/body/after', $quiz_id); |
| 457 | ?> |
| 458 | </div> |
| 459 | |
| 460 | <script> |
| 461 | window.tutor_quiz_context = '<?php echo strrev(base64_encode(json_encode($quiz_answers))); ?>'; |
| 462 | </script> |