public function __construct() { $time = time() - getLastLogin($_SESSION["user_id"]); $this->buildings = getBuildings($_SESSION["user_id"]); $this->buildingsworkers = getBuildingsWorkers($_SESSION["user_id"]); $this->userid = $_SESSION["user_id"]; $this->population = getPopulation($_SESSION["user_id"]); $this->food = getFood($_SESSION["user_id"]) * ($this->getFoodProduction() * $time); $this->water = getWater($_SESSION["user_id"]) * ($this->getWaterProduction() * $time); }
<?php require_once "functions.php"; $gary = "0"; if (isset($_SESSION["logged_in_user"])) { $gary = "1"; } if (isset($_GET["logout"])) { session_destroy(); header("Location: login.php"); } $food_array = getFood(); if (isset($_GET["counter"])) { $food = $_GET["food_id"]; foodCount($food); } ?> <p><a href="index.html">Tagasi</a> pealehele.</p> <?php if ($gary == "1") { echo "<p><a href='dataKeeper.php'>Tagasi</a> laohoidja lehele.</p>"; echo "<a href='?logout=1'>Logi välja</a>"; } ?> <h2>Laos leiduvad toiduained</h2> <table border="1"> <tr> <th>Id</th>
function render_body() { if ($_GET['action'] == 'pridej-objednavku') { echo ' <form action="objednavky.php?action=pridej-objednavku2" method="POST"> <select name="stul"> ' . getTables() . ' </select> Stul<br /> Jidlo<br /> <select name="jidlo"> ' . getFood() . ' </select> <input type="text" name="mnozstvi" size="3" value="1">x pocet kusu<br /> <input type="submit" value="Pridej jidlo"> </form>'; } elseif ($_GET['action'] == 'pridej-objednavku2') { if (is_numeric($_POST['mnozstvi'])) { $jidlo = MyDB::getInstance()->getResults('SELECT * FROM jidelni_listek WHERE id = ' . MyDB::escape($_POST['jidlo'])); $cena = $jidlo[0]['cena']; for ($i = 1; $i <= $_POST['mnozstvi']; $i++) { MyDB::getInstance()->exec('INSERT INTO objednavka ("id_jidla","id_stolu","datum","cena") VALUES (' . MyDB::escape($_POST['jidlo']) . ', ' . MyDB::escape($_POST['stul']) . ', DATETIME("now"), "' . $cena . '")'); //echo 'INSERT INTO objednavka ("id_jidla","id_stolu","datum","cena") VALUES ('.MyDB::escape($_POST['jidlo']).', '.MyDB::escape($_POST['stul']).', DATETIME("now"), "'.$cena.'")'; } echo '<meta http-equiv="refresh" content="0;URL=\'objednavky.php\'">'; } else { echo 'Zadejte platné množství!'; } } elseif ($_GET['action'] == 'zaplatit') { MyDB::getInstance()->exec('UPDATE objednavka SET zaplaceno = 1 WHERE id = ' . MyDB::escape($_GET['id'])); echo '<meta http-equiv="refresh" content="0;URL=\'objednavky.php\'">'; } elseif ($_GET['action'] == 'zrusit') { MyDB::getInstance()->exec('DELETE FROM objednavka WHERE id = ' . MyDB::escape($_GET['id'])); echo '<meta http-equiv="refresh" content="0;URL=\'objednavky.php\'">'; } else { return ' <h1>Nezaplacené objednávky</h1> <table class="datatable"> <thead> <tr> <th>Stůl (salónek)</th> <th>Jídlo</th> <th>Čas</th> <th>Cena</th> <th>Možnosti</th> </tr> </thead> <tbody> ' . displayOrders('neplacene') . ' </tbody> </table> <br /><br /> <p><a href="objednavky.php?action=pridej-objednavku"><img src="images/add.png" />Pridej jidlo</a></p> <h1>Zaplacené objednávky</h1> <table class="datatable"> <thead> <tr> <th>Stůl (salónek)</th> <th>Jídlo</th> <th>Čas</th> <th>Cena</th> <th>Možnosti</th> </tr> </thead> <tbody> ' . displayOrders('placene') . ' </tbody> </table> '; } }
<?php include 'db_helper.php'; if ($_GET['f'] == 'getfood' && $_GET['id']) { getFood($_GET['id']); } function getFood($user) { $dbQuery = sprintf("SELECT freq , per from User_Info where ID = '%s'", mysql_real_escape_string($user)); $result = getDBResultRecord($dbQuery); echo json_encode($result); }