hmm, well I have not changed plugin code. I have just added my own to some pages which shouldnt break plugin functionliaty.
Here is code for FinishQuiz function.
global $wpdb;
$quizName = $_SESSION['wpsqt']['current_id'];
if ( $_SESSION['wpsqt'][$quizName]['details']['use_wp'] == 'yes'){
$objUser = wp_get_current_user();
$_SESSION['wpsqt'][$quizName]['person']['name'] = $objUser->user_login;
$_SESSION['wpsqt'][$quizName]['person']['email'] = $objUser->user_email;
}
$personName = (isset($_SESSION['wpsqt'][$quizName]['person']['name'])) ? $_SESSION['wpsqt'][$quizName]['person']['name'] : 'Anonymous';
$timeTaken = microtime(true) - $_SESSION['wpsqt'][$quizName]['start_time'];
$totalPoints = 0;
$correctAnswers = 0;
$canAutoMark = true;
foreach ( $_SESSION['wpsqt'][$quizName]['sections'] as $quizSection ){
if ( $this->_type != "quiz" || ( isset($quizSection['can_automark']) && $quizSection['can_automark'] == false) ){
$canAutoMark = false;
break;
}
foreach ( $quizSection['questions'] as $question ){
$totalPoints += $question['points'];
}
if ( !isset($quizSection['stats']) ) {
continue;
}
if ( isset($quizSection['stats']['correct']) ){
$correctAnswers += $quizSection['stats']['correct'];
}
}
if ( $canAutoMark === true ){
$_SESSION['wpsqt']['current_score'] = $correctAnswers." correct out of ".$totalPoints;
} else {
$_SESSION['wpsqt']['current_score'] = "quiz can't be auto marked";
}
if ( $correctAnswers !== 0 ){
$percentRight = ( $correctAnswers / $totalPoints ) * 100;
} else {
$percentRight = 0;
}
if ( !isset($_SESSION['wpsqt'][$quizName]['details']['store_results']) || $_SESSION['wpsqt'][$quizName]['details']['store_results'] !== "no" ){
$wpdb->query(
$wpdb->prepare("INSERT INTO <code>".WPSQT_TABLE_RESULTS."</code> (timetaken,person,sections,item_id,person_name,ipaddress,score,total,percentage)
VALUES (%d,%s,%s,%d,%s,%s,%d,%d,%d)",
array($timeTaken,
serialize($_SESSION['wpsqt'][$quizName]['person']),
serialize($_SESSION['wpsqt'][$quizName]['sections']),
$_SESSION['wpsqt'][$quizName]['details']['id'],
$personName,$_SERVER['REMOTE_ADDR'],$correctAnswers,$totalPoints,$percentRight ) )
);
$_SESSION['wpsqt']['result_id'] = $wpdb->insert_id;
} else {
$_SESSION['wpsqt']['result_id'] = null;
}
$emailAddress = get_option('wpsqt_contact_email');
if ( $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant' ){
$emailTrue = true;
} elseif ( $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-100'
&& $percentRight == 100 ) {
$emailTrue = true;
} elseif ( $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-75'
&& $percentRight > 75 ){
$emailTrue = true;
} elseif ( $_SESSION['wpsqt'][$quizName]['details']['notificaton_type'] == 'instant-50'
&& $percentRight > 50 ){
$emailTrue = true;
} elseif ( $_SESSION['wpsqt'][$quizName]['details']['send_user'] == 'yes' ) {
$emailTrue = true;
}
if ( isset($emailTrue) ){
Wpsqt_Mail::sendMail();
}
require_once Wpsqt_Core::pageView('site/'.$this->_type.'/finished.php');
if ( $this->_type == "survey" ){
$this->_cacheSurveys();
}
/* Custome code */
global $current_user;
get_currentuserinfo();
$quizId = $_SESSION['wpsqt'][$quizName]['details']['id'];
$resultId = $_SESSION['wpsqt']['result_id'];
$user_id = $current_user->ID;
$query = "INSERT INTO <code>user_quizes</code> (
<code>id</code> ,
<code>user_id</code> ,
<code>quiz_id</code> ,
<code>result_id</code>
)
VALUES (
NULL , $user_id ,$quizId, '$resultId'
);";
$wpdb->query($query);
/* Custom Code */
unset($_SESSION['wpsqt']['result_id']);
}
The onnly other other change which i have made is i am posting form through AJAX by serializing fields.
And here is my code for this purpose.
var formData = jQuery("#form").serialize();
jQuery.ajax({
type: "POST",
url: " <?php echo esc_url($_SERVER["REQUEST_URI"]); ?>",
data: formData,
success: function(msg){
}
});
Can you please figure out what could be wrong?