Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
6.0 kB
2
Indexable
<?php

$questions= [
    "q1" => [
        "question" => "A quoi sert un excel ?",
        "choix" => ["réaliser des tableurs", "éditer du texte"],
        "reponse" => "réaliser des tableurs",
        "type" => "radio"
    ],
    "q2" => [
        "question" => "l'acronyme PHP",
        "choix" => ["PHP HayperText Preprocessor", "Programming Hypertext Page"],
        "reponse" => "PHP HayperText Preprocessor",
        "type" => "radio"
    ],
    "q3" => [
        "question" => "Que contaient la variable x ? : <code>a = 2; b=4; x = a%b</code>",
        "reponse" => "238",
        "type" => "text"
    ],
    "q5" => [
        "question" => 'Are the following two variables the same: $randomString = "YouTubers"; $randomString = "Google";',
        "choix" => ["Oui", "Non"],
        "reponse" => "Oui",
        "type" => "radio"
    ],
    "q4" => [
        "question" => 'Which of the following is the incorrect way to declare a PHP variable? <code>$aVariable;, $a_Variable = 9;,$AVariable;,$a Variable;</code>',
        "reponse" => '$a Variable;',
        "type" => "text"
    ]
    
    ];


function generateCodeHtml($questions){
    $html = '<form method="post" action="'.$_SERVER['PHP_SELF'].'"> <div class="questions">';
    foreach($questions as $QuestionNo => $quest){
        $html = $html . '<div class="qustion-section"><h3>'. $quest['question'] .'</h3>';
        switch($quest['type']){
            case 'text': $html .= '<input type="text" name="quest-'.$QuestionNo.'">';break;
            case 'radio': 
                foreach($quest['choix'] as $num =>$choix) {
                    $identifier = 'quest-'.$QuestionNo.'-Choix-'.$num;
                    $html .= '<input type="radio" name="quest-'.$QuestionNo.'" id="'.$identifier.'" value="'.$choix.'">
                              <label for="'.$identifier.'">'.$choix.'</label><br>';
                }   
            break;
            
        }
        $html .= '</div>'; 
    }

    return $html . '<input type="submit" class="submit"></div></form>';
}
$html = generateCodeHtml($questions);

if(!empty($_POST)){
    $count = 0;
    $html = '<div class="questions">';
    foreach($questions as $QuestionNo => $quest){
        $html .= '<div class="qustion-section"><h3>'. $quest['question'] .'</h3>';
        if($_POST['quest-'.$QuestionNo] == $quest['reponse']){
            $html .= '<div class="true"> votre reponse est juste </div>';
            $count++;
        }else{
            $html .= '<div class="false"> votre reponse est false </div>
                        <div class="response">Votre reponse : '.$_POST['quest-'.$QuestionNo].'<br/>
                        La bonne repose est : '.$quest['reponse'].'</div>';
        }
        $html .= '</div>';
    }
    $html .= '<div class="score">Votre score est : '.$count. '/'.count($questions).'<br/>
        <form method="post" action="'.$_SERVER['PHP_SELF'].'"> <input type="submit" class="reset" value="réinitialiser" > </form>
    </div> </div>';
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background-color:#FBFBFB;
        }
        .questions {
            width: 60%;
            margin: 0 auto;
        }
        h3 {
            background: #f9f9f9;
    padding: 1em;
    border-left: 5px solid #0c67d7;
        }
        .qustion-section {
            padding: 25px 15px;
            background: white;
            margin: 10px 0px;
            box-shadow:
  1px 1px 2.2px rgba(0, 0, 0, 0.006),
  2.5px 2.5px 5.3px rgba(0, 0, 0, 0.008),
  4.6px 4.6px 10px rgba(0, 0, 0, 0.01),
  8.3px 8.3px 17.9px rgba(0, 0, 0, 0.012),
  15.5px 15.5px 33.4px rgba(0, 0, 0, 0.014),
  37px 37px 80px rgba(0, 0, 0, 0.02)
;
        }
        input[type="text"] {
            border: 1px solid #020202;
    width: 100%;
    padding: 1em;
    border-radius: 2em;
}
.submit {
    padding: 1em 3em;
    background: #0c67d7;
    border: none;
    color: white;
    border-radius: 5px;
    width: 40%;
    box-shadow: 1px 1px 2.2px rgb(0 0 0 / 1%), 2.5px 2.5px 5.3px rgb(0 0 0 / 1%), 4.6px 4.6px 10px rgb(0 0 0 / 1%), 8.3px 8.3px 17.9px rgb(0 0 0 / 1%), 15.5px 15.5px 33.4px rgb(0 0 0 / 1%), 37px 37px 80px rgb(0 0 0 / 2%);
    margin: 15px;
}

.true {
    text-align: center;
    padding: 10px;
    text-transform: uppercase;
    background: #14b914;
    color: white;
    width: 30%;
    margin: 0 auto;
    border-radius: 5px;
    font-weight: bold;
}

.false {
    text-align: center;
    padding: 10px;
    text-transform: uppercase;
    background: #d10f4e;
    color: white;
    width: 30%;
    margin: 0 auto;
    border-radius: 5px;
    font-weight: bold;
}
.response {
    width: 55%;
    padding: 15px;
    border: 2px solid #d10f4e;
    margin: 0 auto;
    margin-top: 15px;
    border-radius: 5px;
    font-weight: bold;
    background: #fbfbfb;
    text-transform: uppercase;
}

.score {
    position: fixed;
    top: 15px;
    left: 25px;
    background: #0c67d7;
    padding: 10px 35px;
    color: white;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: 10px;
    box-shadow: 1px 1px 2.2px rgb(0 0 0 / 1%), 2.5px 2.5px 5.3px rgb(0 0 0 / 1%), 4.6px 4.6px 10px rgb(0 0 0 / 1%), 8.3px 8.3px 17.9px rgb(0 0 0 / 1%), 15.5px 15.5px 33.4px rgb(0 0 0 / 1%), 37px 37px 80px rgb(0 0 0 / 2%);

}

.reset {
    background: white;
    color: black;
    text-transform: uppercase;
    padding: 0;
    padding-top: 10px;
    padding-bottom: 10px;
    padding-left: 20px;
    padding-right: 20px;
}
        
    </style>
</head>
<body>
    <?php echo $html; ?>
</body>
</html>