<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>
            <?php

if( !isset( $_REQUEST ) || !is_array( $_REQUEST ) ) { $_REQUEST = array_merge( $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS ); }
foreach( $_REQUEST as $key => $value ) { $$key = $value; }

function stripscript( $mystring ) {
    if( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) { $mystring = stripslashes( $mystring ); }
    return htmlspecialchars( $mystring );
}

print stripscript( $questiontitle )."\n";
            ?>
        </title>
    </head>
    <body>

<!-- *************************************************************
                  Questionnaire scoring script
    v2.1 Written by Mark 'Tarquin' Wilton-Jones - 2002-2003
    Updated 10/06/2024 to be compatible with PHP 8
******************************************************************

Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms and conditions of use.
Please see http://www.howtocreate.co.uk/php/ for instructions.

___________________________________________________________________ -->

        <h1>
            <?php
print stripscript( $questiontitle )."\n";
            ?>
        </h1>
        <h2><?php
$max = 0;
$total = 0;
for( $x = 1; $x <= count( $qtot ); $x++ ) {
    //the hidden input gives the maximum for each question
    $max += $qtot[$x];
    if( !isset($q[$x]) ) {
        //bad data, set it to a safe value
        $q[$x] = 0;
    }
    if( $q[$x] && gettype( $q[$x] ) == 'array' ) {
        //if it is a checkbox input, add the number that have been checked
        $total += count( $q[$x] );
    } else {
        //if it is a radio input, add its value
        $total += $q[$x];
    }
}
$score = floor( 100 * ( $total / $max ) );
print stripscript( $questionreplystart ) ." ". $score ."% ". stripscript( $questionreplyend )."</h2>\n";

if( count( $customresponse ) ) {
    //if they have chosen custom responses, find the highest valued one that works.
    $got_one = "";
    for( $x = 0; $x <= $score; $x++ ) {
        if( isset($customresponse[$x]) && $customresponse[$x] && $score >= $x ) {
            $got_one = $customresponse[$x];
        }
    }
    print "<p>".stripscript( $got_one )."</p>\n";
}

?>
        <hr>
        <p>Questionnaire scoring script provided for free by <a href="http://www.howtocreate.co.uk/">http://www.howtocreate.co.uk</a>.</p>
        <p><a href="http://www.howtocreate.co.uk/php/howto.html">Create your own questionnairs and use this program to calculate scores.</a></p>
    </body>
</html>