/** * Function called when user is requesting a retake of a quiz. Lots of checking * needs to go on here for security reasons to ensure that they don't manipulate * their own progress (or somebody elses). */ function WPCW_AJAX_units_handleQuizRetakeRequest() { // Security check if (!wp_verify_nonce(WPCW_arrays_getValue($_POST, 'progress_nonce'), 'wpcw-progress-nonce')) { die(__('Security check failed!', 'wp_courseware')); } // Get unit and quiz ID $unitID = intval(WPCW_arrays_getValue($_POST, 'unitid')); $quizID = intval(WPCW_arrays_getValue($_POST, 'quizid')); // Get the post object for this quiz item. $post = get_post($unitID); if (!$post) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not request a retake for the quiz.', 'wp_courseware') . ' ' . __('Could not find training unit.', 'wp_courseware')); die; } // Initalise the unit details $fe = new WPCW_UnitFrontend($post); // #### Get associated data for this unit. No course/module data, then it's not a unit if (!$fe->check_unit_doesUnitHaveParentData()) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not request a retake for the quiz.', 'wp_courseware') . ' ' . __('Could not find course details for unit.', 'wp_courseware')); die; } // #### User not allowed access to content if (!$fe->check_user_canUserAccessCourse()) { echo $fe->message_user_cannotAccessCourse(); die; } // #### See if we're in a position to retake this quiz? if (!$fe->check_quizzes_canUserRequestRetake()) { echo WPCW_UnitFrontend::message_createMessage_error(__('Error - could not request a retake for the quiz.', 'wp_courseware') . ' ' . __('You are not permitted to retake this quiz.', 'wp_courseware')); die; } // Trigger the upgrade to progress so that we're allowed to retake this quiz. $fe->update_quizzes_requestQuizRetake(); // Only complete if allowed to continue. echo $fe->render_detailsForUnit(false, true); die; }