<?php
session_start();

if (empty($_SESSION['amazon_order_id']) || !empty($_SESSION['step3'])) {
    session_destroy();
    header('Location:index.php');
}
if (!empty($_SESSION['step1']) && empty($_SESSION['step2'])) {
    header('location:step_1.php');
}
require_once("db/AppManager.php");
$pm = AppManager::getPM();
?>
<!DOCTYPE html>
<html lang="en">
<?php include './fragments/head.php'; ?>
<link href="https://afeld.github.io/emoji-css/emoji.css" rel="stylesheet">

<body style="background: #fff">
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.php">Playz $5 Rebate</a>
        </div>
    </nav>
    <div class="row center_">
        <div class="col-lg-12">
            <center> <img src="img/alllogo.jpg" width="30%"></img> </center>
        </div>
    </div>
    <div id="page-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-header">
                        We truly appreciate your business! Step 2/3
                    </h1>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-body">

                            <form method="post" action="function.php">
                                <?php
                                $sql = "SELECT * FROM questions WHERE page = 2";
                                $questions = $pm->fetchResult($sql);
                                $x = 1;
                                foreach ($questions as $key => $question) {
                                ?>
                                    <div class="row" id="question_<?php echo $key; ?>">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label><?php echo $x . ") " . $question['title']; ?></label>
                                                <div class="row">
                                                    <div class="col-md-3">
                                                        <?php echo $question['html']; ?>

                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <?php
                                    if ($x == 1) {
                                    ?>
                                        <div class="row" id="charity_list">
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label>Select Charity</label>
                                                    <div class="row">
                                                        <div class="col-md-3">
                                                            <select name="charity" class="form-control" id="charityReq">
                                                                <?php
                                                                $charity_lists = $pm->fetchResult("select * from charity");
                                                                if (!empty($charity_lists)) {
                                                                    foreach ($charity_lists as $charity) {
                                                                ?>
                                                                        <option value="<?php echo $charity['id']; ?>"><?php echo $charity['value']; ?></option>
                                                                <?php
                                                                    }
                                                                }
                                                                ?>
                                                            </select>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                <?php
                                    }
                                    $x++;
                                }
                                ?>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input type="hidden" name="action" value="step_3" required>
                                            <br>
                                            Please tell us your product experience on the next page. Just a few words is okay! <i class="em em-blush"></i> <button type="submit" class="btn btn-primary pull-right">Next</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php include 'fragments/js.php'; ?>

</body>

</html>