test.php
=====================================
<!DOCTYPE html>
<html>
<head>
<title>Report Responsive Web Design</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="stil_izvjesce.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div class="grid12">
<?php
/* Ako nismo odabrali polaznika, na ekranu imamo samo padajuci izbornik za odabrati polaznika kome radimo racun */
if (!isset($_GET["polaznici"]))
{
?>
<form action='test.php' method='get'>
<select name="polaznici" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT ime, prezime, id_polaznika
FROM polaznici_tecaja";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_polaznika"] == $_GET["polaznici"]) {
print "<option value=" . $row["id_polaznika"] . " selected>"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
else {
print "<option value=" . $row["id_polaznika"] . ">"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
}
?>
</select>
</form>
</div><!-- Kraj prvog ekrana na kojem se vidi samo padajuci izbornik za izbor polaznika -->
<?php
}
else
/* Ako smo odabrali polaznika, na ekranu vidimo lijevo podatke o polazniku a desno iste te podatke o primatelju racuna. Podatke primatelja racuna mozemo mjenjati jer
za polaznika moze platiti on a moze i firma, staratelj, donator. */
{
?>
<!-- Uvjek se ponavlja na ekranu padajuci izbornik koji je u div class12 -->
<div class="grid12">
<form action='test.php' method='get'>
<select name="polaznici" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT ime, prezime, id_polaznika
FROM polaznici_tecaja";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_polaznika"] == $_GET["polaznici"]) {
print "<option value=" . $row["id_polaznika"] . " selected>"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
else {
print "<option value=" . $row["id_polaznika"] . ">"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
}
?>
</select>
</form>
</div><!-- Kraj padajuceg izbornika za izbor polaznika na drugom ekranu kad je polaznik vec izabran -->
<!-- Ispod padajuceg izbornika na lijevoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun. Ovi su podaci samo tu radi kontrole, jer iste podatke imamo i na desnoj strani i ta desna strana puni tablicu Racuni. Ta desna strana su podaci primatelja racuna. -->
<!-- <form action='unesi_novi_racun.php' method='post'> -->
<div class="grid6">
<?php
$id_polaznika = $_GET["polaznici"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_polaznika, ime, prezime, ulicaibroj, grad, postanski_broj
FROM polaznici_tecaja
WHERE id_polaznika = $id_polaznika";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' name='id_polaznika'" . " " . "value=" . $row["id_polaznika"] . "></br>";
print "<input type='text' name='ime'" . " " . "value=" . $row["ime"] . "></br>";
print "<input type='text' name='prezime'" . " " . "value=" . $row["prezime"] . "></br>";
print "<input type='text' name='ulicaibroj'" . " " . "value=" . $row["ulicaibroj"] . "></br>";
print "<input type='text' name='grad'" . " " . "value=" . $row["grad"] . "></br>";
print "<input type='text' name='postanski_broj'" . " " . "value=" . $row["postanski_broj"] . "></br>";
}
?>
</div> <!-- Kraj polja s podacima polaznika na lijevoj strani -->
<div class="grid6"><!-- Ispod padajuceg izbornika na desnoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun, a koja mozemo mjenjati ili ostaviti istima, jer platitelj ne mora biti polaznik. Ovi podaci pune redak u tablici Racuni -->
<form action='unesi_novi_racun.php' method='post'>
<?php
$id_polaznika = $_GET["polaznici"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_polaznika, ime, prezime, ulicaibroj, grad, postanski_broj
FROM polaznici_tecaja
WHERE id_polaznika = $id_polaznika";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' name='id_polaznika'" . " " . "value=" . $row["id_polaznika"] . "></br>";
print "<input type='text' name='ime'" . " " . "value=" . $row["ime"] . "></br>";
print "<input type='text' name='prezime'" . " " . "value=" . $row["prezime"] . "></br>";
print "<input type='text' name='ulicaibroj'" . " " . "value=" . $row["ulicaibroj"] . "></br>";
print "<input type='text' name='grad'" . " " . "value=" . $row["grad"] . "></br>";
print "<input type='text' name='postanski_broj'" . " " . "value=" . $row["postanski_broj"] . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='text' name='skriveno'" . " " . "value='1'></br>";
}
?>
</div><!-- Kraj podataka primatelja na desnoj strani ekrana. Ti podaci pune tablicu Racuni. -->
<!-- Elementi forme za nacin placanja -->
<div class="grid12">
<input type="radio" name="nacin_placanja" value="1">Gotovina
<input type="radio" name="nacin_placanja" value="2">American
<input type="radio" name="nacin_placanja" value="3">Čekovi
<input type="radio" name="nacin_placanja" value="4">Diners
<input type="submit" value="Novi račun">
</form>
</div><!-- Kraj grid12 nacina placanja -->
<?php
}
?>
<?php
if (!isset($_GET["stranica"])) {
print "";
}
else {
$stranica = $_GET["stranica"];
switch ($stranica) {
case "3":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$idracuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$idracuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<?php
break;
case "4":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$id_racuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$id_racuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<div class="grid12"><!-- Podaci koji će puniti tablicu stavke racuna za odabrani broj racuna -->
<form action='unesi_novu_stavku_racuna.php' method='post'>
<?php
$id_tecaja = $_GET["tecajevi"];
print "<input type='text' name='id_racuna'" . " " . "value=" . $id_racuna . "></br>";
print "<input type='text' name='id_tecaja'" . " " . "value=" . $id_tecaja . "></br>";
print "<input type='text' name='cijena_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=" . "" . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='submit' value='Nova stavka'></br>";
?>
</div>
<?php
break;
case "5":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$id_racuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$id_racuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<div class="grid12"><!-- Podaci koji će puniti tablicu stavke racuna za odabrani broj racuna -->
<form action='unesi_novu_stavku_racuna.php' method='post'>
<?php
$id_tecaja = $_GET["tecajevi"];
print "<input type='text' name='id_racuna'" . " " . "value=" . $id_racuna . "></br>";
print "<input type='text' name='id_tecaja'" . " " . "value=" . $id_tecaja . "></br>";
print "<input type='text' name='cijena_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=" . "" . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='submit' value='Nova stavka'></br>";
?>
</div>
<table border=1>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT id_racuna, id_tecaja, cijena_obroka, broj_obroka, popust, CONCAT(FORMAT((cijena_obroka*broj_obroka*(1-popust)*100)/100, 2,'de_DE'), ' kn') AS iznos
FROM stavke_racuna
WHERE id_racuna = $id_racuna
ORDER BY id_tecaja ASC";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row["id_racuna"] . "</td>";
print "<td>" . $row["id_tecaja"] . "</td>";
print "<td>" . $row["cijena_obroka"] . "</td>";
print "<td>" . $row["broj_obroka"] . "</td>";
print "<td>" . $row["popust"] . "</td>";
print "<td>" . $row["iznos"] . "</td>";
print "</tr>";
}
?>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, cijena_obroka, broj_obroka, popust, CONCAT(FORMAT((Sum(cijena_obroka*broj_obroka*(1-popust)*100)/100), 2,'de_DE'), ' kn') AS sveukupno
FROM stavke_racuna
WHERE id_racuna = $id_racuna
GROUP BY id_racuna;";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' value=" . $row["sveukupno"] . ">";
$sveukupno = $row["sveukupno"];
}
?>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "UPDATE racuni
SET iznos_racuna = $sveukupno
WHERE id_racuna = $id_racuna";
$result = mysqli_query($link, $sql);
?>
<?php
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
}
?>
</div>
</body>
</html>
unesi_novu_stavku_racuna.php
===========================================
<?php
print $id_racuna = $_POST["id_racuna"];
print $id_tecaja = $_POST["id_tecaja"];
print $cijena_obroka = $_POST["cijena_obroka"];
print $broj_obroka = $_POST["broj_obroka"];
print $popust = $_POST["popust"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "INSERT INTO stavke_racuna (id_racuna, id_tecaja, cijena_obroka, broj_obroka,
popust)
VALUES ($id_racuna, $id_tecaja, '$cijena_obroka', $broj_obroka, $popust)";
$result = mysqli_query($link, $sql);
header("Location:test.php?tecajevi=&polaznici=5&stranica=5");
?>
=====================================
<!DOCTYPE html>
<html>
<head>
<title>Report Responsive Web Design</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="stil_izvjesce.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div class="grid12">
<?php
/* Ako nismo odabrali polaznika, na ekranu imamo samo padajuci izbornik za odabrati polaznika kome radimo racun */
if (!isset($_GET["polaznici"]))
{
?>
<form action='test.php' method='get'>
<select name="polaznici" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT ime, prezime, id_polaznika
FROM polaznici_tecaja";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_polaznika"] == $_GET["polaznici"]) {
print "<option value=" . $row["id_polaznika"] . " selected>"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
else {
print "<option value=" . $row["id_polaznika"] . ">"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
}
?>
</select>
</form>
</div><!-- Kraj prvog ekrana na kojem se vidi samo padajuci izbornik za izbor polaznika -->
<?php
}
else
/* Ako smo odabrali polaznika, na ekranu vidimo lijevo podatke o polazniku a desno iste te podatke o primatelju racuna. Podatke primatelja racuna mozemo mjenjati jer
za polaznika moze platiti on a moze i firma, staratelj, donator. */
{
?>
<!-- Uvjek se ponavlja na ekranu padajuci izbornik koji je u div class12 -->
<div class="grid12">
<form action='test.php' method='get'>
<select name="polaznici" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT ime, prezime, id_polaznika
FROM polaznici_tecaja";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_polaznika"] == $_GET["polaznici"]) {
print "<option value=" . $row["id_polaznika"] . " selected>"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
else {
print "<option value=" . $row["id_polaznika"] . ">"
. $row["ime"] . " " . $row["prezime"] . "</option>";
}
}
?>
</select>
</form>
</div><!-- Kraj padajuceg izbornika za izbor polaznika na drugom ekranu kad je polaznik vec izabran -->
<!-- Ispod padajuceg izbornika na lijevoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun. Ovi su podaci samo tu radi kontrole, jer iste podatke imamo i na desnoj strani i ta desna strana puni tablicu Racuni. Ta desna strana su podaci primatelja racuna. -->
<!-- <form action='unesi_novi_racun.php' method='post'> -->
<div class="grid6">
<?php
$id_polaznika = $_GET["polaznici"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_polaznika, ime, prezime, ulicaibroj, grad, postanski_broj
FROM polaznici_tecaja
WHERE id_polaznika = $id_polaznika";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' name='id_polaznika'" . " " . "value=" . $row["id_polaznika"] . "></br>";
print "<input type='text' name='ime'" . " " . "value=" . $row["ime"] . "></br>";
print "<input type='text' name='prezime'" . " " . "value=" . $row["prezime"] . "></br>";
print "<input type='text' name='ulicaibroj'" . " " . "value=" . $row["ulicaibroj"] . "></br>";
print "<input type='text' name='grad'" . " " . "value=" . $row["grad"] . "></br>";
print "<input type='text' name='postanski_broj'" . " " . "value=" . $row["postanski_broj"] . "></br>";
}
?>
</div> <!-- Kraj polja s podacima polaznika na lijevoj strani -->
<div class="grid6"><!-- Ispod padajuceg izbornika na desnoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun, a koja mozemo mjenjati ili ostaviti istima, jer platitelj ne mora biti polaznik. Ovi podaci pune redak u tablici Racuni -->
<form action='unesi_novi_racun.php' method='post'>
<?php
$id_polaznika = $_GET["polaznici"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_polaznika, ime, prezime, ulicaibroj, grad, postanski_broj
FROM polaznici_tecaja
WHERE id_polaznika = $id_polaznika";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' name='id_polaznika'" . " " . "value=" . $row["id_polaznika"] . "></br>";
print "<input type='text' name='ime'" . " " . "value=" . $row["ime"] . "></br>";
print "<input type='text' name='prezime'" . " " . "value=" . $row["prezime"] . "></br>";
print "<input type='text' name='ulicaibroj'" . " " . "value=" . $row["ulicaibroj"] . "></br>";
print "<input type='text' name='grad'" . " " . "value=" . $row["grad"] . "></br>";
print "<input type='text' name='postanski_broj'" . " " . "value=" . $row["postanski_broj"] . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='text' name='skriveno'" . " " . "value='1'></br>";
}
?>
</div><!-- Kraj podataka primatelja na desnoj strani ekrana. Ti podaci pune tablicu Racuni. -->
<!-- Elementi forme za nacin placanja -->
<div class="grid12">
<input type="radio" name="nacin_placanja" value="1">Gotovina
<input type="radio" name="nacin_placanja" value="2">American
<input type="radio" name="nacin_placanja" value="3">Čekovi
<input type="radio" name="nacin_placanja" value="4">Diners
<input type="submit" value="Novi račun">
</form>
</div><!-- Kraj grid12 nacina placanja -->
<?php
}
?>
<?php
if (!isset($_GET["stranica"])) {
print "";
}
else {
$stranica = $_GET["stranica"];
switch ($stranica) {
case "3":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$idracuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$idracuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<?php
break;
case "4":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$id_racuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$id_racuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<div class="grid12"><!-- Podaci koji će puniti tablicu stavke racuna za odabrani broj racuna -->
<form action='unesi_novu_stavku_racuna.php' method='post'>
<?php
$id_tecaja = $_GET["tecajevi"];
print "<input type='text' name='id_racuna'" . " " . "value=" . $id_racuna . "></br>";
print "<input type='text' name='id_tecaja'" . " " . "value=" . $id_tecaja . "></br>";
print "<input type='text' name='cijena_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=" . "" . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='submit' value='Nova stavka'></br>";
?>
</div>
<?php
break;
case "5":
?>
<div class="grid12">
<table border=1>
<tr>
<td>Id računa</td>
<td>Id polaznika</td>
<td>Ime primatelja</td>
<td>Prezime primatelja</td>
<td>Ulica i broj</td>
<td>Grad</td>
<td>Poštanski broj</td>
<td>Id način plaćanja</td>
<td>datum plaćanja</td>
<td>Rok plaćanja</td>
<td>Knjige</td>
<td>Iznos računa</td>
</tr>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, racuni.id_polaznika AS racuni_id_polaznika, polaznici_tecaja.ime AS polaznici_tecaja_ime, polaznici_tecaja.prezime AS polaznici_tecaja_prezime, polaznici_tecaja.ulicaibroj AS polaznici_tecaja_ulicaibroj, polaznici_tecaja.grad AS polaznici_tecaja_grad, polaznici_tecaja.postanski_broj AS polaznici_tecaja_postanski_broj, racuni.ime_primatelja AS racuni_ime_primatelja, racuni.prezime_primatelja AS racuni_prezime_primatelja, racuni.ulica_i_broj AS racuni_ulica_i_broj, racuni.grad AS racuni_grad, racuni.postanski_broj AS racuni_postanski_broj, racuni.id_nacin_placanja AS racuni_id_nacin_placanja, racuni.datum_placanja AS racuni_datum_placanja, racuni.rok_placanja AS racuni_rok_placanja, racuni.knjige AS racuni_knjige, racuni.iznos_racuna AS racuni_iznos_racuna
FROM polaznici_tecaja
INNER JOIN racuni
ON polaznici_tecaja.id_polaznika
= racuni.id_polaznika
ORDER BY id_racuna DESC LIMIT 1";
$result = mysqli_query($link, $sql);
$id_racuna = "";
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row['id_racuna'] . "</td>";
print "<td>" . $row['racuni_id_polaznika'] . "</td>";
print "<td>" . $row['racuni_ime_primatelja'] . "</td>";
print "<td>" . $row['racuni_prezime_primatelja'] . "</td>";
print "<td>" . $row['racuni_ulica_i_broj'] . "</td>";
print "<td>" . $row['racuni_grad'] . "</td>";
print "<td>" . $row['racuni_postanski_broj'] . "</td>";
print "<td>" . $row['racuni_id_nacin_placanja'] . "</td>";
print "<td>" . $row['racuni_datum_placanja'] . "</td>";
print "<td>" . $row['racuni_rok_placanja'] . "</td>";
print "<td>" . $row['racuni_knjige'] . "</td>";
print "<td>" . $row['racuni_iznos_racuna'] . "</td>";
print "</tr>";
$id_racuna = $row['id_racuna'];
}
?>
</table>
</div>
<div class="grid12">
<form action='test.php' method='get'>
<select name="tecajevi" onchange="this.form.submit();">
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_tecaja, naziv_tecaja
FROM tecajevi";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
if ($row["id_tecaja"] == $_GET["tecajevi"]) {
print "<option value=" . $row["id_tecaja"] . " selected>"
. $row["naziv_tecaja"] . "</option>";
}
else {
print "<option value=" . $row["id_tecaja"] . ">"
. $row["naziv_tecaja"] . "</option>";
}
}
?>
</select>
<?php
print "<input type='text' name='polaznici' value=" . $id_polaznika . ">";
?>
<input type="text" name="stranica" value=4 />
</form>
</div>
<div class="grid12"><!-- Podaci koji će puniti tablicu stavke racuna za odabrani broj racuna -->
<form action='unesi_novu_stavku_racuna.php' method='post'>
<?php
$id_tecaja = $_GET["tecajevi"];
print "<input type='text' name='id_racuna'" . " " . "value=" . $id_racuna . "></br>";
print "<input type='text' name='id_tecaja'" . " " . "value=" . $id_tecaja . "></br>";
print "<input type='text' name='cijena_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=" . "" . "></br>";
/* skriveni podatak je za treci ekran kad se pojavljuju podaci iz tablice Racuni. To su podaci upravo kreiranog racuna u ekranu 2, a to je ekran u kojem se nalazi 'skriveno', ovaj u kojem ovo pise. */
print "<input type='submit' value='Nova stavka'></br>";
?>
</div>
<table border=1>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT id_racuna, id_tecaja, cijena_obroka, broj_obroka, popust, CONCAT(FORMAT((cijena_obroka*broj_obroka*(1-popust)*100)/100, 2,'de_DE'), ' kn') AS iznos
FROM stavke_racuna
WHERE id_racuna = $id_racuna
ORDER BY id_tecaja ASC";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<tr>";
print "<td>" . $row["id_racuna"] . "</td>";
print "<td>" . $row["id_tecaja"] . "</td>";
print "<td>" . $row["cijena_obroka"] . "</td>";
print "<td>" . $row["broj_obroka"] . "</td>";
print "<td>" . $row["popust"] . "</td>";
print "<td>" . $row["iznos"] . "</td>";
print "</tr>";
}
?>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "SELECT DISTINCT id_racuna, cijena_obroka, broj_obroka, popust, CONCAT(FORMAT((Sum(cijena_obroka*broj_obroka*(1-popust)*100)/100), 2,'de_DE'), ' kn') AS sveukupno
FROM stavke_racuna
WHERE id_racuna = $id_racuna
GROUP BY id_racuna;";
$result = mysqli_query($link, $sql);
While ($row = mysqli_fetch_assoc($result))
{
print "<input type='text' value=" . $row["sveukupno"] . ">";
$sveukupno = $row["sveukupno"];
}
?>
<?php
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "UPDATE racuni
SET iznos_racuna = $sveukupno
WHERE id_racuna = $id_racuna";
$result = mysqli_query($link, $sql);
?>
<?php
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
}
?>
</div>
</body>
</html>
unesi_novu_stavku_racuna.php
===========================================
<?php
print $id_racuna = $_POST["id_racuna"];
print $id_tecaja = $_POST["id_tecaja"];
print $cijena_obroka = $_POST["cijena_obroka"];
print $broj_obroka = $_POST["broj_obroka"];
print $popust = $_POST["popust"];
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "INSERT INTO stavke_racuna (id_racuna, id_tecaja, cijena_obroka, broj_obroka,
popust)
VALUES ($id_racuna, $id_tecaja, '$cijena_obroka', $broj_obroka, $popust)";
$result = mysqli_query($link, $sql);
header("Location:test.php?tecajevi=&polaznici=5&stranica=5");
?>
Primjedbe
Objavi komentar