<?php

    $db = new SQLite3('./api/.db.db');
	$rows = $db->query('SELECT * FROM updates');
    $row = $rows->fetchArray();
    
    if (isset($_POST['update']))
    {
        $db->exec("UPDATE updates SET version='".$_POST['version']."', version_code='".$_POST['version_code']."', url='".$_POST['url']."', al_version='".$_POST['al_version']."' WHERE id='1'");
        header("Location: add_update.php");
    }

    include ('includes/header.php');
?>

<div class="has-sidebar-left has-sidebar-tabs">
    <div class="container-fluid relative animatedParent animateOnce p-lg-5">
        <div class="col-md-8 mx-auto">
            <div class="card-body">
                <div class="card bg-primary text-white">
                    <div class="card-header card-header-warning">
                        <center>
                            <h2><i class="icon icon-window-restore"></i> Add In-App Updates</h2>
                        </center>
                    </div>

                    <div class="card-body">
                            <form method="post">
                                <div class="form-group">
								<center><h3>ApkTime</h3></center>
                                    <label class="form-label " for="version" >Version</label>
                                    <input class="form-control" id="version" name="version" value="<?=$row['version'] ?>" type="text"/>
                                </div>             
                                <div class="form-group">
                                    <label class="form-label " for="version_code" >Version Code</label>
                                    <input class="form-control" id="version_code" name="version_code" value="<?=$row['version_code'] ?>" type="text"/>
                                </div>
                                <div class="form-group">
                                    <label class="form-label " for="url" >APK URL</label>
                                    <input class="form-control" id="url" name="url" value="<?=$row['url'] ?>" type="text"/>
                                </div>
                                <div class="form-group">
								<center><h3>AppLinked</h3></center>
                                    <label class="form-label " for="al_version" >AppLinked Verion</label>
                                    <input class="form-control" id="al_version" name="al_version" value="<?=$row['al_version'] ?>" type="text"/>
                                </div>
                                <div class="form-group">
                                    <center>
                                        <button class="btn btn-info " name="update" type="submit">
                                            <i class="icon icon-check"></i> Submit
                                        </button>
                                    </center>
                                </div>
                            </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include ('includes/footer.php');?>

</body>
</html>