Hits: 41186

List

Try: ca/tecreations/ViewFile.php -- Online


<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/Base.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/QA.php";
$uid = $_SESSION['uid'];

$a1 = $a2 = $a3 = $q1 = $q2 = $q3 = $a1_err = $a2_err = $a3_err = "";

if (isset($_REQUEST['a1']) && isset($_REQUEST['a2']) && isset($_REQUEST['a3'])) {
    $a1 = $_REQUEST['a1'];
    $a2 = $_REQUEST['a2'];
    $a3 = $_REQUEST['a3'];
    if (empty($a1)) $a1_err = "Empty";
    if (isset($_REQUEST['q1']) && isset($_REQUEST['q2']) && isset($_REQUEST['q3'])) {
        $q1 = $_REQUEST['q1'];
        $q2 = $_REQUEST['q2'];
        $q3 = $_REQUEST['q3'];
    }
}
if ($q1 == $q2 && $q1 != "") $a2_err = "Cannot select the same question twice.";
if ($q1 == $q3 && $q1 != "") $a3_err = "Cannot select the same question twice.";
if ($q2 == $q3 && $q2 != "") $a3_err = "Cannot select the same question twice.";
if (isset($_REQUEST['q1']) && empty($q1)) $a1_err = "You must select a question.";
if (isset($_REQUEST['q2']) && empty($q2)) $a2_err = "You must select a question.";
if (isset($_REQUEST['q3']) && empty($q3)) $a3_err = "You must select a question.";
if (!empty($a1) && !empty($a2) && !empty($a3) && $a1_err == "" && $a2_err == "" && $a3_err == "") {
    $qa->setA1($uid,mysqli_real_escape_string($qa->mysqli,strtolower($a1)));
    $qa->setA2($uid,mysqli_real_escape_string($qa->mysqli,strtolower($a2)));
    $qa->setA3($uid,mysqli_real_escape_string($qa->mysqli,strtolower($a3)));
    $qa->setQ1($uid,$q1);
    $qa->setQ2($uid,$q2);
    $qa->setQ3($uid,$q3);
    header("Location: $PREFIX_DIR/Apps/Welcome.php");
}

include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/start.php";
?>
    <title>Change Security</title>
    <style type="text/css">
        .wrapper { width: 600px; padding: 25px; }
    </style>
    <script src="/Global.js"></script>
</head>
<body onmousedown="resetTimeout();" onmouseup="resetTimeout();" 
    onmousemove="resetTimeout();" onkeydown="resetTimeout();" 
    onload="timeoutObject=setTimeout('logout()',<?php GLOBAL $TIMEOUT; echo $TIMEOUT; ?>);">
    <?php 
        $chPassActive = "active";
        include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/header_start.php"; 
        if (isset($_SESSION['level'])) {
            if ($_SESSION['level'] == 9) include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/Apps/Admin.php";
            if ($_SESSION['level'] == 1) include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/Apps/Unprivileged.php";
            include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/menu/logout.php";
        } else die("Unauthorized: Level not set.");
        include_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/header_finish.php"; 
    ?>
    <div class="wrapper">
        <h2><center>Security Questions and Answers</center></h2>
        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="get">
            <div class="form-group">
                <label>Question 1</label>
                <select name="q1" class="form-control" autofocus>
                    <option value="0" <?php if ($q1 == 0) print("selected"); ?>>Select a question from this list.</option>
                    <?php
                        $result = $qa->select("SELECT id, text FROM $QUESTIONS");
                        $count = $result['count'];
                        for($i = 0; $i < $count;$i++) {
                            $row = $result['rows'][$i];
                            print("<option");
                            if ($row['id'] == $q1) print(" selected");
                            print(" value='" . $row['id'] . "'>" . $row['text'] . "</option>\n");
                            
                        }
                    ?>
                </select>
            </div>    
            <div class='form-group <?php echo (!empty($a1_err)) ? 'has-error' : ''; ?>'">
                <label>Response</label>
                <input autocomplete=off type="text" name="a1" class="form-control" value="<?php echo htmlspecialchars($a1); ?>">
                <span class="help-block"><?php echo $a1_err; ?></span>
            </div>    
            <div class="form-group">
                <label>Question 2</label>
                <select name="q2" class="form-control">
                    <option value="0" <?php if ($q1 == 0) print("selected"); ?>>Select a question from this list.</option>
                    <?php
                        $result = $qa->select("SELECT id, text FROM $QUESTIONS");
                        $count = $result['count'];
                        for($i = 0; $i < $count;$i++) {
                            $row = $result['rows'][$i];
                            print("<option");
                            if ($row['id'] == $q2) print(" selected");
                            print(" value='" . $row['id'] . "'>" . $row['text'] . "</option>\n");
                            
                        }
                    ?>
                </select>
            </div>    
            <div class="form-group <?php echo (!empty($a2_err)) ? 'has-error' : ''; ?>">
                <label>Response</label>
                <input autocomplete=off type="text" name="a2" class="form-control" value="<?php echo htmlspecialchars($a2); ?>">
                <span class="help-block"><?php echo $a2_err; ?></span>
            </div>    
            <div class="form-group">
                <label>Question 3</label>
                <select name="q3" class="form-control">
                    <option value="0" <?php if ($q1 == 0) print("selected"); ?>>Select a question from this list.</option>
                    <?php
                        $result = $qa->select("SELECT id, text FROM $QUESTIONS");
                        $count = $result['count'];
                        for($i = 0; $i < $count;$i++) {
                            $row = $result['rows'][$i];
                            print("<option");
                            if ($row['id'] == $q3) print(" selected");
                            print(" value='" . $row['id'] . "'>" . $row['text'] . "</option>\n");
                            
                        }
                    ?>
                </select>
            </div>    
            <div class="form-group <?php echo (!empty($a3_err)) ? 'has-error' : ''; ?>">
                <label>Response</label>
                <input autocomplete=off type="text" name="a3" class="form-control" value="<?php echo htmlspecialchars($a3); ?>">
                <span class="help-block"><?php echo $a3_err; ?></span>
            </div>    
            <div class="form-group">
                <input type="submit" class="btn btn-primary" value="Submit">
                <input type="reset" class="btn btn-default" value="Reset">
            </div>
        </form>
    </div>    
</body>
</html>