Ejemplo n.º 1
0
/**
 * This will scan all the content pages that wordpress outputs for our special code. If the code is found, it will replace the requested quiz.
 */
function watupro_shortcode($attr)
{
    global $wpdb, $post;
    $exam_id = $attr[0];
    $contents = '';
    if (!is_numeric($exam_id)) {
        return $contents;
    }
    watupro_vc_scripts();
    ob_start();
    // select exam
    $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE id=%d", $exam_id));
    if (watupro_intel()) {
        WatuPROIntelligence::conditional_scripts($exam_id);
    }
    watupro_conditional_scripts($exam);
    // passed question ids?
    if (!empty($attr['question_ids'])) {
        $passed_question_ids = $attr['question_ids'];
    }
    // submitting without ajax?
    if (!empty($_POST['no_ajax']) and !empty($exam->no_ajax)) {
        require WATUPRO_PATH . "/show_exam.php";
        $contents = ob_get_clean();
        $contents = apply_filters('watupro_content', $contents);
        return $contents;
    }
    // other cases, show here
    if (empty($_GET['waturl']) or !$exam->shareable_final_screen) {
        // showing the exam
        if ($exam->mode == 'practice' and watupro_intel()) {
            WatuPracticeController::show($exam);
        } else {
            include WATUPRO_PATH . '/show_exam.php';
        }
        $contents = ob_get_contents();
    } else {
        // showing taking results
        $url = @base64_decode($_GET['waturl']);
        list($exam_id, $tid) = explode("|", $url);
        if (!is_numeric($exam_id) or !is_numeric($tid)) {
            return $contents;
        }
        // must check if public URL is allowed
        $taking = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_TAKEN_EXAMS . " WHERE ID=%d", $tid));
        $contents = WatuPRO::cleanup($taking->details, 'web');
        $post->ID = 0;
        $post->comment_status = 'closed';
    }
    ob_end_clean();
    $contents = apply_filters('watupro_content', $contents);
    return $contents;
}
Ejemplo n.º 2
0
 function display_unresolved($output)
 {
     $output = WatuPRO::cleanup($output, 'web');
     // now remove correct-answer style
     $output = str_replace('correct-answer', '', $output);
     $output = str_replace('user-answer-unrevealed', 'user-answer', $output);
     // do it back & forth to avoid nasty bug
     $output = str_replace('user-answer', 'user-answer-unrevealed', $output);
     // remove hardcoded correct/incorrect images if any
     // (for example we may have these in fill the gaps questions)
     $output = str_replace('<img src="' . WATUPRO_URL . '/correct.png" hspace="5">', '', $output);
     $output = str_replace('<img src="' . WATUPRO_URL . '/wrong.png" hspace="5">', '', $output);
     return $output;
 }
Ejemplo n.º 3
0
        ?>
</a></p>
		<?php 
    }
    // end if not $advanced_settings['show_only_snapshot']
}
// end if not export
?>
	
	
	<?php 
if (empty($_GET['export'])) {
    ?>
	<div id="detailsText" style="background:#EEE;padding:5px;">	
	<p><?php 
    echo WatuPRO::cleanup($taking->details, 'web');
    ?>
</p>
	</div>
	<?php 
}
?>
	
	<?php 
if (empty($advanced_settings['show_only_snapshot'])) {
    if (empty($_GET['export'])) {
        ?>
 <div id="detailsTable" style="display:none;"> <?php 
    }
    ?>
	
Ejemplo n.º 4
0
$output .= str_replace($replace_these, $with_these, wpautop(stripslashes($exam->final_screen), false));
$output = watupro_parse_answerto($output, $taking_id);
$email_output = str_replace($replace_these, $with_these, wpautop(stripslashes($exam->email_output), false));
$email_output = watupro_parse_answerto($email_output, $taking_id);
// store this taking
$_watu->update_taking($taking_id, $achieved, $grade, $output, $percent, $grade_obj, $catgrades);
// send API call
do_action('watupro_completed_exam', $taking_id);
if (watupro_intel() and !empty($exam->fee) and !empty($exam->pay_always)) {
    do_action('watupro_completed_paid_exam', $taking_id, $exam);
}
$output = apply_filters('watupro_content', $output);
$email_output = apply_filters('watupro_content', $email_output);
// show output on the screen
if (empty($do_redirect)) {
    print WatuPRO::cleanup($output, 'web');
} else {
    echo "WATUPRO_REDIRECT:::" . $do_redirect;
}
// update taking output with the filters
$wpdb->query($wpdb->prepare("UPDATE " . WATUPRO_TAKEN_EXAMS . " SET details=%s WHERE ID=%d", $output, $taking_id));
if (!empty($exam->email_output)) {
    $output = $email_output;
}
// here maybe replace output with email output
// clear any timer related info for this exam
delete_user_meta($user_ID, "start_exam_" . $exam->ID);
// email details if required
$_watu->email_results($exam, $output, @$grade_obj->ID);
if (empty($exam->no_ajax)) {
    exit;
Ejemplo n.º 5
0
    function email_results($exam, $output, $grade_id = null)
    {
        global $user_ID, $user_email;
        $headers = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
        $headers .= 'From: ' . watupro_admin_email() . "\r\n";
        $admin_output = $output = WatuPRO::cleanup($output);
        if (strstr($output, "{{{split}}}")) {
            $parts = explode("{{{split}}}", $output);
            $output = trim($parts[0]);
            $admin_output = trim($parts[1]);
        }
        $admin_subject = __('User results on %%QUIZ_NAME%%', 'watupro');
        $user_subject = __('Your results on %%QUIZ_NAME%%', 'watupro');
        if (!empty($exam->email_subject)) {
            $email_subject = stripslashes($exam->email_subject);
            if (strstr($email_subject, '{{{split}}}')) {
                list($user_subject, $admin_subject) = explode('{{{split}}}', $email_subject);
            } else {
                $user_subject = $admin_subject = $email_subject;
            }
        }
        $output = '<html><head><title>' . __('Your results on ', 'watupro') . $exam->name . '</title>
			</head>
			<html><body>' . $output . '</body></html>';
        // echo $output;
        if (!is_user_logged_in() or !empty($_POST['taker_email'])) {
            $user_email = @$_POST['taker_email'];
        }
        // user setting may override the var
        if ($exam->email_taker and is_user_logged_in() and get_user_meta($user_ID, 'watupro_no_quiz_mails', true)) {
            $exam->email_taker = false;
        }
        // now email user
        if ($exam->email_taker and $user_email) {
            // check for grade-related restrictions
            $advanced_settings = unserialize(stripslashes($exam->advanced_settings));
            if (!empty($advanced_settings['email_grades']) and is_array($advanced_settings['email_grades']) and !in_array($grade_id, $advanced_settings['email_grades'])) {
                $dont_email_taker = true;
            }
            $user_subject = str_replace('%%QUIZ_NAME%%', stripslashes($exam->name), $user_subject);
            if (empty($dont_email_taker)) {
                wp_mail($user_email, $user_subject, $output, $headers);
            }
        }
        if ($exam->email_admin) {
            // if user is logged in, let admin know who is taking the test
            $output = $admin_output;
            // echo($output);
            $user_data = $user_email;
            if (!empty($_POST['taker_name'])) {
                $user_data .= " ({$_POST['taker_name']})";
            }
            if (!empty($user_email)) {
                $output = "Details of {$user_data}:<br><br>" . $output;
            }
            $admin_email = empty($exam->admin_email) ? get_option('admin_email') : $exam->admin_email;
            $admin_subject = str_replace('%%QUIZ_NAME%%', stripslashes($exam->name), $admin_subject);
            wp_mail($admin_email, $admin_subject, $output, $headers);
        }
    }