Beispiel #1
0
<?php

session_start();
$nb_steps = get_steps();
/* Token generation and initialization of the current step */
if (empty($_SESSION['step'])) {
    $_SESSION['step'] = 1;
    $_SESSION["token"] = generate_random_string();
} else {
    if ($_SESSION['step'] > $nb_steps) {
        $_SESSION['step'] = 1;
        $_SESSION["token"] = generate_random_string();
    }
}
/* If some datas have been submited, we go to the next step */
if (!empty($_POST) && $_SESSION['step'] <= $nb_steps) {
    $id_answer = trim($_POST["id_answer"]);
    $token = $_SESSION["token"];
    $step = $_SESSION["step"];
    if (check_answer($id_answer, $step)) {
        $_SESSION["step"]++;
        add_user_answer($token, $id_answer);
        if ($_SESSION['step'] > $nb_steps) {
            header("Location:result.php");
        }
    }
}
$progress = $_SESSION['step'] / $nb_steps * 100;
$question = get_question($_SESSION['step']);
$answers = get_answers($_SESSION['step']);
<tr>
    <td align=right>Signed Confidentiality Agreement:</td>
    <td>
        <input name="signed_confidentiality" type="checkbox" <?php 
echo $tutor_info['signed_confidentiality'] ? 'checked' : '';
?>
 />
    </td>
</tr>
<tr>
    <td valign="top" align='right'>Availability:</td>
    <td>
    <?php 
availability_matrix(get_tutor_avail($tutor_id));
?>
    </td>
</tr>
<tr>
    <td align='right'>Notes:</td>
    <td><textarea rows=4 cols=80 name="notes"><?php 
echo $tutor_info['notes'];
?>
</textarea></td>
</tr>
</table>
<?php 
question_table("tutor", get_answers(null, $tutor_id));
?>
<input type="submit" value="Submit">
</form>
function get_answered_poll($question_id, $admin = false)
{
    $answers = get_answers($question_id);
    // get answers with asociated information
    $number_of_answers = get_number_of_answers($question_id);
    $title = get_question_title($question_id);
    $rating = get_question_rating($question_id);
    $num_ppl = get_number_of_people_voted($question_id);
    $html = "<div id='answered_poll'>\n<pre>";
    $html .= "<h1>{$title}</h1>\n";
    $html .= "<p>This question has an average rating of {$rating}/10. <br />{$num_ppl} ";
    $html .= ($num_ppl == 1 ? "person has " : "people have ") . "voted.</p>\n";
    $count = 0;
    foreach ($answers as $answer) {
        $votes = "Vote" . ($answer['votes_for'] > 1 ? "s" : "");
        $percent = $answer['votes_for'] / $num_ppl * 100;
        $percent = round($percent, 2);
        $div_id = "bar" . $count++;
        $html .= "<p>{$answer['answer']}\t<div id=\"{$div_id}\" class='bar_class'></div>{$percent}% \t{$answer['votes_for']} {$votes}</p>\n";
        $html .= "<script>\n";
        $int_percent = (int) $percent;
        // the int of the percent
        $html .= <<<END
\t\t\t\$(function(){
\t\t\t\t\$("#{$div_id}").progressbar({
\t\t\t\t\tvalue: {$int_percent}
\t\t\t\t});
\t\t\t});

END;
        $html .= "</script>";
    }
    $html .= "\n</pre></div>";
    if (!$admin) {
        return $html;
    }
    $html .= "<p>This question was made by " . get_made_by($question_id) . ".</p>";
    $html .= get_comments_html($question_id);
    return $html;
}
?>
 </td>
</tr>
<tr><td align="right">Times per week:</td>
    <td><input name="times_per_week" value="<?php 
echo $request_info['times_per_week'];
?>
"></td>
</tr>
<tr>
    <td align='right'>Notes:</td>
    <td><textarea name="notes" rows=4 cols=80><?php 
echo $request_info['notes'];
?>
</textarea></td>
</tr>
</table>
<?php 
question_table("student", get_answers($request_id));
?>
<input type="submit" value="Submit">
</form>
<form>
<input type="hidden" name="page" value="cancel_request">
<input type="hidden" name="request_id" value="<?php 
echo $request_id;
?>
">
<input type="submit" value="Cancel">
</form>
Beispiel #5
0
function ans_test()
{
    print_r(get_answers('hdu1000'));
}
function get_question_content($examID, $examName, $examCat, $questionID, $questionName, $questionType)
{
    $answers = get_answers($questionID, $questionType);
    $html = "<input type='hidden' id='exam_name' value='{$examName}' />";
    $html .= "<input type='hidden' id='exam_cat' value='{$examCat}' />";
    $html .= "<input type='hidden' id='exam_id' value='{$examID}' />";
    $html .= "<input type='hidden' id='question_id' value='{$questionID}' />";
    $html .= "<input id='old_question' type='text' autocomplete='off' placeholder='What is the question?' size='100' maxlength='200' value='{$questionName}'/>";
    switch ($questionType) {
        case 'single_answers':
            $html .= "<h4>The Answer</h4>\n";
            $html .= "<input type='text' maxlength='100' placeholder='What is the answer?' autocomplete='off' id='single_answer_text' value='{$answers[0][0]}'>\n";
            $html .= "<script>var selected = 'single';</script>";
            break;
        case 'mult_answers':
            $html .= "<h4>The Answers</h4>";
            $limit = count($answers);
            for ($i = 0; $i < 10; $i++) {
                $value = "";
                $checked = "";
                if ($i < $limit) {
                    $value = $answers[$i][0];
                    if ($answers[$i][2] == 'true') {
                        $checked = "checked";
                    }
                }
                $html .= "<input type='checkbox' name='mult_answer[]' value='{$i}' {$checked}>\t<input type='text' maxlength='100' autocomplete='off' name='mult_answer_text[]' class='mult_answer_text' value=\"{$value}\"><br /><br />\n";
            }
            $html .= "<script>var selected = 'multiple';</script>";
            break;
        case 'keyword_answers':
            $html .= "<h4>The Keywords</h4>";
            $limit = count($answers);
            for ($i = 0; $i < 10; $i++) {
                $value = "";
                if ($i < $limit) {
                    $value = $answers[$i][0];
                }
                $html .= "<input type='text' value='{$value}' maxlength='100' autocomplete='off' name='keyword_text[]' class='keyword_text'><br /><br />\n";
            }
            $html .= "<script>var selected = 'written';</script>";
            break;
        default:
            go_home();
            // prevent users accesses an invalid category
    }
    $html .= "<br /><button id='edit_question_button'>edit Question</button>\n";
    return $html;
}