<!DOCTYPE html>
<?php
require_once ("db/AppManager.php");
$pm = AppManager::getPM();
session_start();
if (empty($_SESSION['user_name'])) {
    header('Location:login.php');
}
$sql = "SELECT * FROM amazon_key";
$key = $pm->fetchResult($sql);
?>
<?php include 'fragments/head.php'; ?>
<body style="background: #fff"> 
    <div id="wrapper">
        <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">Amazon Survey</a>
            </div>
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <a class="navbar-brand" href="logout.php" style="float: right">Logout</a>
                <ul class="nav navbar-nav side-nav">
                    <li class="">
                        <a href="manage_questions.php"><i class="fa fa-fw fa-dashboard"></i> Manage Questions</a>
                    </li>
                    <li class="active">
                        <a href=""><i class="fa fa-fw fa-key"></i> Amazon Key</a>
                    </li>
                    <li class="">
                        <a href="charity_list.php"><i class="fa fa-fw fa-list"></i>Charity List</a>
                    </li>
                    <li class="">
                        <a href="#" id="modelpopforpasschange"><i class="fa fa-fw fa fa-cog"></i>Manage Password</a>
                    </li>
                </ul>
            </div>
        </nav>
        <div id="page-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                            Amazon MWS Key
                        </h1>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6"> <?php
                        if (!empty($_GET['success']) && $_GET['success'] == "inserted") {
                            ?>
                            <div class="alert alert-success">
                                <strong>Success!</strong> Your Amazon key inserted successfully!
                            </div>
                            <?php
                        } else if (!empty($_GET['success']) && $_GET['success'] == "updated") {
                            ?>
                            <div class="alert alert-success">
                                <strong>Success!</strong> Your Amazon key updated successfully!
                            </div>
                            <?php
                        }
                        ?>
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <h3 class="panel-title">Amazon Key Manage <?php echo ($key[0]['market_place'] != 'cn' ? 'selected' : ''); ?> </h3>
                            </div>
                            <div class="panel-body">
                                <form  method="POST" action="function.php"> 
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Market Place Name : </label>
                                                <select class="form-control" name="market_place" required>
                                                    <option <?php echo ($key[0]['market_place'] == '' ? 'selected' : ''); ?> value="">Select Marketplace</option>
                                                    <option <?php echo ($key[0]['market_place'] == 'cn' ? 'selected' : ''); ?> value="cn">China</option>
                                                    <option <?php echo ($key[0]['market_place'] == 'in' ? 'selected' : ''); ?> value="in">India</option>
                                                    <option <?php echo ($key[0]['market_place'] == 'fr' ? 'selected' : ''); ?> value="fr">France</option>
                                                    <option <?php echo ($key[0]['market_place'] == 'de' ? 'selected' : ''); ?> value="de">Germany</option>
                                                    <option <?php echo($key[0]['market_place'] == 'it' ? 'selected' : ''); ?> value="it">Italy</option>
                                                    <option <?php echo($key[0]['market_place'] == 'nl' ? 'selected' : ''); ?> value="nl">Netherlands</option>
                                                    <option <?php echo($key[0]['market_place'] == 'es' ? 'selected' : ''); ?> value="es">Spain</option>
                                                    <option <?php echo($key[0]['market_place'] == 'co.uk' ? 'selected' : ''); ?> value="co.uk">United Kingdom</option>
                                                    <option <?php echo($key[0]['market_place'] == 'ca' ? 'selected' : ''); ?> value="ca">Canada</option>
                                                    <option <?php echo($key[0]['market_place'] == 'mx' ? 'selected' : ''); ?> value="mx">Mexico</option>
                                                    <option <?php echo($key[0]['market_place'] == 'com' ? 'selected' : ''); ?> value="com">United States</option>
                                                    <option <?php echo($key[0]['market_place'] == 'com.au' ? 'selected' : ''); ?> value="com.au">Australia</option>
                                                    <option <?php echo($key[0]['market_place'] == 'com.br' ? 'selected' : ''); ?> value="com.br">Brazil</option>
                                                </select>                                                
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Aws Access Key ID</label>
                                                <input type="text" class="form-control" value="<?php echo $key[0]['aws_access_key_id'] ?>" name="aws_access_key_id" placeholder="" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Aws Secret Access Key</label>
                                                <input type="text" class="form-control"  value="<?php echo $key[0]['aws_secret_key_id'] ?>" name="aws_secret_key_id" placeholder="" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Merchant ID</label>
                                                <input type="text" class="form-control"  value="<?php echo $key[0]['merchant_id'] ?>" name="merchant_id" placeholder="" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Market Place ID</label>
                                                <input type="text" class="form-control" value="<?php echo $key[0]['market_place_id'] ?>"  name="market_place_id" placeholder="" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <input type="hidden" name="action" value="amazon_key">
                                                <button  class="btn btn-primary pull-right" id="btnSave" type="submit"> Save  
                                                    <i class="fa fa-spinner fa-spin fa-fw" id="lodding_spinner" style="display:none;"></i>
                                                    <span class="sr-only">Loading...</span>
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

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

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