<?php 

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

	$db = new SQLite3('./api/.db.db');
	$rows = $db->query("SELECT COUNT(*) as count FROM rss");
    $row = $rows->fetchArray();
	$numRows = $row['count'];
    if ($numRows == 0)
    {
        $db->exec("INSERT INTO rss(description) VALUES('yourcodehere')");
    }
    $res = $db->query('SELECT * FROM rss');
    $ress = $db->query('SELECT * FROM rss');

    $rowss = $res->fetchArray();
	$description = $rowss['description'];
    $folder = ("location: ./".$description."");
	if(isset($_POST['rss']))
	{
		$db->exec("UPDATE rss SET description='".$_POST["description"]."' WHERE id='1'");
		rename($description, $_POST['description']);
		//header("Location: applogin.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-lg 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-lock"></i>Manage Entry Code</h2>
                        </center>
                    </div>
                    <?php while ($rowss = $ress->fetchArray()) {?>
                    <div class="card-body">
                        <div class="col-12">
                        	<form method="post"> 
								<div class="form-group">
									<label class="form-label">AppLinked Entry Code</label>
									<input class="form-control" id="description" name="description" value="<?=$rowss['description'] ?>" type="text" >
								</div>

								<hr>
								<center>
									<button type="submit" name="rss" class="btn btn-info">
										<i class="icon icon-check"></i>Save
									</button>
								</center>
							</form>
    					</div>
    					<?php } ?>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

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

</body>
</html>