Plugin Directory

Changeset 3362701


Ignore:
Timestamp:
09/16/2025 05:18:41 PM (7 months ago)
Author:
prasunsen
Message:

improvement over the latest fix

Location:
chained-quiz/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chained-quiz/trunk/chained-quiz.php

    r3362561 r3362701  
    55Description: Create a chained quiz where the upcoming questions can depend on the previous answer
    66Author: Kiboko Labs
    7 Version: 1.3.4
     7Version: 1.3.5
    88Author URI: http://calendarscripts.info/
    99License: GPLv2 or later
  • chained-quiz/trunk/helpers/htmlhelper.php

    r3362561 r3362701  
    131131   
    132132    // If user is logged in, check if the completion belongs to them
    133     if (is_user_logged_in()) {
     133    if (is_user_logged_in() or $completion->user_id ) {
    134134        return ($completion->user_id == $user_ID);
    135135    } else {
  • chained-quiz/trunk/models/quiz.php

    r3362561 r3362701  
    167167         
    168168         $GLOBALS['chained_completion_id'] = $completion_id;
    169          $GLOBALS['chained_result_id'] = @$result->id;
     169         $GLOBALS['chained_result_id'] = $result->id ?? 0;
    170170         $output = do_shortcode($output);
    171171         $output = wpautop($output);
     
    176176         
    177177         // now insert in completed
    178          if(!empty($_COOKIE['chained_completion_id'.$quiz->id])) {           
    179             $wpdb->query( $wpdb->prepare("UPDATE ".CHAINED_COMPLETED." SET
    180                 quiz_id = %d, points = %f, result_id = %d, datetime = NOW(), ip = %s, user_id = %d,
    181                 snapshot = %s, source_url=%s, email=%s WHERE id=%d",
    182                 $quiz->id, $points, @$result->id, chained_user_ip(), $user_id, $output,
    183                 $source_url, $user_email, $completion_id));
     178         if(!empty($_COOKIE['chained_completion_id'.$quiz->id])) {
     179             // if for whatever reason it's already completed don't override it
     180             $is_completed = $wpdb->get_var($wpdb->prepare("SELECT id FROM ".CHAINED_COMPLETED."
     181                WHERE id=%d snapshot IS NOT NULL", $completion_id));
     182
     183             if(!$is_completed) {
     184                 $wpdb->query( $wpdb->prepare("UPDATE ".CHAINED_COMPLETED." SET
     185                    quiz_id = %d, points = %f, result_id = %d, datetime = NOW(), ip = %s, user_id = %d,
     186                    snapshot = %s, source_url=%s, email=%s WHERE id=%d",
     187                    $quiz->id, $points, @$result->id, chained_user_ip(), $user_id, $output,
     188                    $source_url, $user_email, $completion_id));
     189                 setcookie('chained_completion_id'.$quiz->id, '', time() - 30*24*3600, '/');
     190             }
    184191
    185192            $taking_id = $_COOKIE['chained_completion_id'.$quiz->id];
    186             setcookie('chained_completion_id'.$quiz->id, '', time() - 30*24*3600, '/');
     193
    187194         }   
    188195         else {
Note: See TracChangeset for help on using the changeset viewer.