Potrebno predznanje
Još moram napraviti:
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">
<!-- STRANICA 1 -->
<div class="grid12">
<?php
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><!-- STRANICA 1 KRAJ -->
<?php
}
else
{
?>
<!-- STRANICA 2 -->
<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"><!-- Na desnoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun. Te podatke 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>";
}
?>
</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
}
?>
<!-- Do sad sam koristio if ... else a od sad dalje koristim switch ... case -->
<?php
if (!isset($_GET["stranica"])) {
print "";
}
else {
$stranica = $_GET["stranica"];
switch ($stranica) {
case "3":
?>
<!-- STRANICA 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
$id_racuna = "";
$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);
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>
<?php
break;
case "4":
?>
<!-- STRANICA 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"];
$id_polaznika = $_GET["polaznici"];
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=50" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=1" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=0" . "" . "></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='id_tecaja' value=" . $id_tecaja . ">";
print "<input type='text' name='id_polaznika' value=" . $id_polaznika . ">";
print "<input type='submit' value='Nova stavka'></br>";
?>
<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>";
}
?>
</table>
<?php
$sveukupno = "";
$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);
?>
</div>
<?php
break;
case "5":
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
}
?>
</div>
</body>
</html>
unesi_novu_stavku_racuna.php
=====================================
<?php
$id_tecaja = $_POST["id_tecaja"];
$id_polaznika = $_POST["id_polaznika"];
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=$id_tecaja&polaznici=$id_polaznika&stranica=4");
?>
unesi_novi_racun.php
==========================
<?php
print $id_polaznika = $_POST["id_polaznika"];
print $ime = $_POST["ime"];
print $prezime = $_POST["prezime"];
print $ulica_i_broj = $_POST["ulicaibroj"];
print $grad = $_POST["grad"];
print $postanski_broj = $_POST["postanski_broj"];
print $nacin_placanja = $_POST["nacin_placanja"];
print $datum_placanja = date("Y-m-d H:i:s");
print $rok_placanja = date('Y-m-d H:i:s', strtotime(date("Y-m-d H:i:s"). ' + 15 days'));
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "INSERT INTO racuni (id_polaznika, ime_primatelja, prezime_primatelja,
ulica_i_broj, grad, postanski_broj, id_nacin_placanja, datum_placanja, rok_placanja)
VALUES ($id_polaznika, '$ime', '$prezime', '$ulica_i_broj', '$grad', '$postanski_broj', $nacin_placanja, '$datum_placanja', '$rok_placanja')";
$result = mysqli_query($link, $sql);
header("Location:test.php?polaznici=$id_polaznika&stranica=3");
?>
Još moram napraviti:
- izmjene u "stored procedure" kod upita gdje je potrebno,
- edit računa i stavaka
- delete računa i stavaka
- update računa i stavaka
- tisak računa (izvješće kod Accessa)
- email računa
- dizajn računa
- dokumentacija - kod mene je to knjiga iz koje se može učiti
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">
<!-- STRANICA 1 -->
<div class="grid12">
<?php
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><!-- STRANICA 1 KRAJ -->
<?php
}
else
{
?>
<!-- STRANICA 2 -->
<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"><!-- Na desnoj strani su polja popunjena s podacima odabranog polaznika, polaznika za kojeg radimo racun. Te podatke 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>";
}
?>
</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
}
?>
<!-- Do sad sam koristio if ... else a od sad dalje koristim switch ... case -->
<?php
if (!isset($_GET["stranica"])) {
print "";
}
else {
$stranica = $_GET["stranica"];
switch ($stranica) {
case "3":
?>
<!-- STRANICA 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
$id_racuna = "";
$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);
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>
<?php
break;
case "4":
?>
<!-- STRANICA 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"];
$id_polaznika = $_GET["polaznici"];
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=50" . "" . "></br>";
print "<input type='text' name='broj_obroka'" . " " . "value=1" . "" . "></br>";
print "<input type='text' name='popust'" . " " . "value=0" . "" . "></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='id_tecaja' value=" . $id_tecaja . ">";
print "<input type='text' name='id_polaznika' value=" . $id_polaznika . ">";
print "<input type='submit' value='Nova stavka'></br>";
?>
<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>";
}
?>
</table>
<?php
$sveukupno = "";
$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);
?>
</div>
<?php
break;
case "5":
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
}
?>
</div>
</body>
</html>
unesi_novu_stavku_racuna.php
=====================================
<?php
$id_tecaja = $_POST["id_tecaja"];
$id_polaznika = $_POST["id_polaznika"];
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=$id_tecaja&polaznici=$id_polaznika&stranica=4");
?>
unesi_novi_racun.php
==========================
<?php
print $id_polaznika = $_POST["id_polaznika"];
print $ime = $_POST["ime"];
print $prezime = $_POST["prezime"];
print $ulica_i_broj = $_POST["ulicaibroj"];
print $grad = $_POST["grad"];
print $postanski_broj = $_POST["postanski_broj"];
print $nacin_placanja = $_POST["nacin_placanja"];
print $datum_placanja = date("Y-m-d H:i:s");
print $rok_placanja = date('Y-m-d H:i:s', strtotime(date("Y-m-d H:i:s"). ' + 15 days'));
$link = mysqli_connect("localhost", "root", "", "mariva");
$sql = "INSERT INTO racuni (id_polaznika, ime_primatelja, prezime_primatelja,
ulica_i_broj, grad, postanski_broj, id_nacin_placanja, datum_placanja, rok_placanja)
VALUES ($id_polaznika, '$ime', '$prezime', '$ulica_i_broj', '$grad', '$postanski_broj', $nacin_placanja, '$datum_placanja', '$rok_placanja')";
$result = mysqli_query($link, $sql);
header("Location:test.php?polaznici=$id_polaznika&stranica=3");
?>
Primjedbe
Objavi komentar