<?php
session_start();
if (empty($_SESSION['amazon_order_id'])) {
    header('Location:index.php');
}
if(!empty($_SESSION['step2']))
{
	header('location:step_2.php');
}
require_once ("db/AppManager.php");
$pm = AppManager::getPM();
?>
<!DOCTYPE html>
<?php include 'fragments/head.php'; ?>
<body style="background: #fff">
<script src="js/MyJs.js"></script>
    <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="">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">
                        Please complete all steps of the rebate process!
                    </h1>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <?php
                            if (!empty($_SESSION['amazon_order_id'])) {
                                $sql = "SELECT * FROM item WHERE amazon_order_id = '" . $_SESSION['amazon_order_id'] . "'";
                                $order_img = $pm->fetchResult($sql);
                                foreach ($order_img as $order) {
                                    ?>
                                    <center><img src="<?php echo $order['item_url'] ?>"> </center>
                                    <br>
                                    <?php
                                }
                            }
                            ?>
                            <form method="post" action="function.php">
                                <?php
                                $sql = "SELECT * FROM questions WHERE page = 1";
                                $questions = $pm->fetchResult($sql);
                                $x = 1;
                                foreach ($questions as $key => $question) {
                                    ?>
                                    <div class="row">
                                        <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
                                    $x++;
                                }
                                ?>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input type="hidden" name="action" value="step_2" required>
                                            <br>
                                            <button type="submit"  class="btn btn-primary pull-right" name="stept2_success">Next</button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php include 'fragments/js.php'; 
	?>
</body>
</html>
