Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- G6-DUSICA
- DAO
- <?php
- require_once '../config/db.php';
- class DAOTelefoni {
- private $db;
- private $INSERTTELEFON = "INSERT INTO telefoni (marka, cena) VALUES (?, ?)";
- private $GETTELEFONI = "SELECT * FROM telefoni WHERE marka = ? AND cena > ?";
- public function __construct()
- {
- $this->db = DB::createInstance();
- }
- public function insertTelefon($marka, $cena)
- {
- $statement = $this->db->prepare($this->INSERTTELEFON);
- $statement->bindValue(1, $marka);
- $statement->bindValue(2, $cena);
- $result = $statement->fetch();
- $statement->execute();
- }
- public function getTelefoni($marka, $cena)
- {
- // 2. nacin
- $statement = $this->db->prepare($this->GETTELEFONI);
- $statement->bindValue(1, $marka);
- $statement->bindValue(2, $cena);
- $result = $statement->fetch();
- $statement->execute();
- $result = $statement->fetchAll();
- return $result;
- }
- }
- ?>
- TEST GET
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- $dao = new DAOTelefoni();
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <?php
- $telefoni = $dao->getTelefoni("Nokia", 400.00);
- foreach ($telefoni as $t){
- echo $t['marka'] . " " . $t['cena'] . "<br>";
- }
- ?>
- </body>
- </html>
- TEST INSERT
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- $dao = new DAOTelefoni();
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <?php
- $dao->insertTelefon("Nokia", 999.00);
- ?>
- </body>
- </html>
- KONTROLER
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- session_start();
- class controllerTelefona{
- function goForma(){
- include '../telefoni/viewForma.php';
- }
- function deleteSession(){
- if($_SESSION['telefon'] != ""){
- session_unset();
- session_destroy();
- include '../telefoni/viewForma.php';
- }
- }
- function insertTelefon(){
- // prvo kupi parametre
- $id = isset($_POST['id']) ? $_POST['id'] : "";
- $marka = isset($_POST['marka']) ? $_POST['marka'] : "";
- $cena = isset($_POST['cena']) ? $_POST['cena'] : "";
- $dao = new DAOTelefoni();
- if(!empty($marka) && !empty($cena)){
- if(is_numeric($cena)){
- $telefon = $dao->insertTelefon($marka, $cena);
- $telefoni = $dao->getTelefoni($marka, $cena);
- $_SESSION['telefon'] = $telefoni;
- include '../telefoni/viewPrikazTelefona.php';
- }
- else{
- $msg = "Cena mora biti broj";
- include "../telefoni/viewForma.php";
- }
- }
- else{
- $msg = "Polja su obavezna";
- include '../telefoni/viewForma.php';
- }
- }
- }
- ?>
- INDEX 1
- <?php
- require_once '../telefoni/controllerTelefona.php';
- $ct = new controllerTelefona();
- $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
- switch ($_SERVER['REQUEST_METHOD']){
- case "GET":
- switch($action){
- case "goForma":
- $ct->goForma();
- break;
- case "deleteSession":
- $ct->deleteSession();
- break;
- }
- break;
- case "POST":
- switch($action){
- case "insert":
- $ct->insertTelefon();
- break;
- }
- break;
- default:
- header("Location: ../index.php");
- break;
- }
- ?>
- VIEW FORMA
- <?php
- $msg = isset($msg) ? $msg : "";
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <h1>Forma za prosledjivanje parametara</h1>
- <span style="color: purple;"><?php echo $msg;?></span><br><br>
- <form action="../telefoni/" method="POST">
- Marka: <input type="text" name="marka"><br><br>
- Cena: <input type="text" name="cena"><br><br>
- <input type="submit" name="action" value="insert"><br><br>
- </form>
- </body>
- </html>
- PRIKAZ TELEFONA
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- $msg = isset($msg) ? $msg : "";
- if($_SESSION['telefon'] != "") {
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <?php echo $msg;?>
- <h1>Prikaz telefona</h1>
- <?php
- $dao = new DAOTelefoni();
- $telefoni = $dao->getTelefoni($marka, $cena);
- ?>
- <ul>
- <?php foreach ($telefoni as $t){ ?>
- <li><?php echo $t['marka'] . " " . $t['cena'];?></li>
- <?php }?>
- </ul>
- <a href="../telefoni/?action=deleteSession">Resetuj / logout</a>
- </body>
- </html>
- <?php
- }
- else{
- header("Location: ../index.php");
- exit();
- }
- ?>
- INDEX 2
- <?php
- header("Location: telefoni/?action=goForma");
- ?>
- DUSICA-REZULTATI
- <?php
- require_once '../config/db.php';
- class DAORezultati {
- private $db;
- private $INSERTREZ = "INSERT INTO rezultati (br_indexa, predmet, ocena) VALUES (?, ?, ?)";
- private $GETPROSEK = "SELECT AVG(ocena) AS prosek FROM rezultati WHERE br_indexa = ?";
- public function __construct()
- {
- $this->db = DB::createInstance();
- }
- public function insertRezultat($br_indexa, $predmet, $ocena)
- {
- // 2. nacin
- $statement = $this->db->prepare($this->INSERTREZ);
- $statement->bindValue(1, $br_indexa);
- $statement->bindValue(2, $predmet);
- $statement->bindValue(3, $ocena);
- $statement->execute();
- }
- public function getProsekByIndex($br_indexa)
- {
- // 2. nacin
- $statement = $this->db->prepare($this->GETPROSEK);
- $statement->bindValue(1, $br_indexa);
- $statement->execute();
- $result = $statement->fetch();
- return $result;
- }
- }
- ?>
- TEST AVG
- <?php
- require_once '../rezultati/DAORezultati.php';
- $dao = new DAORezultati();
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <?php
- $rez = $dao->getProsekByIndex("222/2016");
- print_r($rez);
- //var_dump($rez);
- ?>
- </body>
- </html>
- TEST INSERT
- <?php
- require_once '../rezultati/DAORezultati.php';
- $dao = new DAORezultati();
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <?php
- $dao->insertRezultat('222/2016', "Menadzment", 9);
- ?>
- </body>
- </html>
- KONTROLER
- <?php
- require_once '../rezultati/DAORezultati.php';
- session_start();
- class controllerRezultata{
- function goForma(){
- include '../rezultati/viewForma.php';
- }
- function logout(){
- if($_SESSION['rezultat'] != ""){
- session_unset();
- session_destroy();
- include '../rezultati/viewForma.php';
- }
- }
- function insertRez(){
- $id = isset($_POST['id']) ? $_POST['id'] : "";
- $br_indexa = isset($_POST['br_indexa']) ? $_POST['br_indexa'] : "";
- $predmet = isset($_POST['predmet']) ? $_POST['predmet'] : "";
- $ocena = isset($_POST['ocena']) ? $_POST['ocena'] : "";
- $dao = new DAORezultati();
- if(!empty($br_indexa) && !empty($predmet) && !empty($ocena)){
- if(is_numeric($ocena)){
- $rezultat = $dao->insertRezultat($br_indexa, $predmet, $ocena);
- $prosek = $dao->getProsekByIndex($br_indexa);
- $_SESSION['rezultat'] = $br_indexa;
- include '../rezultati/viewPrikazRezultata.php';
- }
- else{
- $msg = "Ocena je broj";
- include "../rezultati/viewForma.php";
- }
- }
- else{
- $msg = "Poppuniti sva polja";
- include "'../rezultati/viewForma.php'";
- }
- }
- }
- ?>
- INDEX 1
- <?php
- require_once '../rezultati/controllerRezultata.php';
- $cr = new controllerRezultata();
- $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
- switch ($_SERVER['REQUEST_METHOD']){
- case "GET":
- switch ($action){
- case "goForma":
- $cr->goForma();
- break;
- case "logout";
- $cr->logout();
- break;
- }
- break;
- case "POST":
- switch($action){
- case "insert":
- $cr->insertRez();
- break;
- }
- break;
- default:
- header("Loation: ../index.php");
- break;
- }
- ?>
- FORMA
- <?php
- $msg = isset($msg) ? $msg : "";
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <h1>Forma za prosledjivanje prarametara</h1>
- <span style="color: green;"><?php echo $msg;?></span><br><br>
- <form action="../rezultati/" method="POST">
- Broj indeksa: <input type="text" name="br_indexa"><br><br>
- Predmet: <input type="text" name="predmet"><br><br>
- Ocena: <input type="text" name="ocena"><br><br>
- <input type="submit" name="action" value="insert"><br><br>
- </form>
- </body>
- </html>
- PRIKAZ REZULTATA
- <?php
- require_once '../rezultati/DAORezultati.php';
- if($_SESSION['rezultat'] != "") {
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <h1>Prikaz prosecne ocene za datog studenta</h1>
- <?php
- $dao = new DAORezultati();
- $prosek = $dao->getProsekByIndex($_SESSION['rezultat']);
- ?>
- Broj indeksa: <?php echo $_SESSION['rezultat']; ?><BR><BR>
- Prosecna ocena: <?php echo implode(",", $prosek);?>
- <br><br>
- <a href="../rezultati/?action=logout">resetuj</a>
- </body>
- </html>
- <?php
- }
- else{
- header("Location: ../index.php");
- exit();
- }
- ?>
- INDEX 2
- <?php
- header("Location: rezultati/?action=goForma");
- ?>
- <?php
- require_once '../config/db.php';
- class DAOStudent {
- private $db;
- private $STUDENTPOSTOJI="SELECT * FROM student WHERE id=?";
- private $UPDATESTUDENT="UPDATE student SET ime=?,prezime=?,brIndexa=? WHERE id=?";
- public function __construct()
- {
- $this->db = DB::createInstance();
- }
- public function getStudent($id){
- $statement = $this->db->prepare($this->STUDENTPOSTOJI);
- $statement->bindValue(1, $id);
- $statement->execute();
- $result = $statement->fetch();
- return $result;
- }
- public function getStudentById($id)
- {
- $statement = $this->db->prepare($this->STUDENTPOSTOJI);
- $statement->bindValue(1, $id);
- $statement->execute();
- if ($result = $statement->fetch()){
- return true;
- }else{
- return false;
- }
- }
- public function update($id,$ime,$prezime,$brIndexa)
- {
- $statement = $this->db->prepare($this->UPDATESTUDENT);
- $statement->bindValue(1, $ime);
- $statement->bindValue(2, $prezime);
- $statement->bindValue(3, $brIndexa);
- $statement->bindValue(4, $id);
- $statement->execute();
- }
- }
- ?>
- TEST DA LI POSTOJI
- <?php
- require_once '../student/DAOStudent.php';
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao=new DAOStudent();
- echo $dao->getStudentById(88);
- ?>
- </body>
- </html>
- FLIGHT
- <?php
- require 'flight/Flight.php';
- require_once '../student/DAOStudent.php';
- Flight::route('/', function(){
- echo 'hello world!';
- });
- Flight::route('GET /student/@id', function($id){
- $dao=new DAOStudent();
- $result=$dao->getStudentById($id);
- echo json_encode($result);
- });
- Flight::route('PUT /student/@id', function($id){
- $dao=new DAOStudent();
- $ime=Flight::request()->data->ime;
- $prezime=Flight::request()->data->prezime;
- $brIndexa=Flight::request()->data->brIndexa;
- $result=$dao->update($id,$ime,$prezime,$brIndexa);
- echo json_encode($result);
- });
- Flight::start();
- KONTROLER STUDENT
- <?php
- require_once 'DAOStudent.php';
- session_start();
- class controllerStudent{
- function update(){
- $id=isset($_POST["id"])?$_POST['id']:"";
- $ime=isset($_POST["ime"])?$_POST['ime']:"";
- $prezime=isset($_POST["prezime"])?$_POST['prezime']:"";
- $indeks=isset($_POST["indeks"])?$_POST['indeks']:"";
- $dao=new DAOStudent();
- $postoji=$dao->getStudentById($id);
- if ($postoji==true){
- if (!empty($ime)&&!empty($prezime)&&!empty($indeks)){
- $dao->update($id, $ime, $prezime, $indeks);
- $_SESSION["korisnik"]=$id;
- include 'prikaz.php';
- }else{
- $msg="Morate popuniti sva polja";
- include 'viewForma.php';
- }
- }else{
- $msg="Student sa datim brojem indeksa ne postoji";
- include 'viewForma.php';
- }
- }
- function delete(){
- if ($_SESSION["korisnik"]!=""){
- session_destroy();
- session_unset($_SESSION["korisnik"]);
- include 'viewForma.php';
- }
- }
- }
- ?>
- INDEX
- <?php
- $action=isset($_REQUEST['action'])?$_REQUEST['action']:"";
- require_once 'controllerStudent.php';
- switch ($_SERVER["REQUEST_METHOD"]){
- case "GET":
- switch ($action){
- case "forma":
- include 'viewForma.php';
- break;
- case "delete":
- $cs=new controllerStudent();
- $cs->delete();
- break;
- }
- break;
- case "POST":
- switch ($action){
- case "Update":
- $cs=new controllerStudent();
- $cs->update();
- break;
- }
- break;
- }
- ?>
- FORMA
- <?php
- $msg=isset($msg)?$msg:"";
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- echo $msg;
- ?>
- <form action="" method="post">
- ID: <input type="text" name="id" value><br>
- Ime: <input type="text" name="ime"><br>
- Prezime: <input type="text" name="prezime"><br>
- Indeks: <input type="text" name="indeks"><br>
- <input type="submit" name="action" value="Update">
- </form>
- </body>
- </html>
- PRIKAZ
- <?php
- require_once 'DAOStudent.php';
- if ($_SESSION["korisnik"]!=""){
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao=new DAOStudent();
- $student=$dao->getStudent($_SESSION['korisnik'])
- ?>
- Id:<?php echo $student["id"]?><br>
- Ime:<?php echo $student["ime"]?><br>
- Prezime:<?php echo $student["prezime"]?><br>
- Broj indeksa:<?php echo $student["brIndexa"]?><br>
- <a href="../student/?action=delete">Resetuj</a>
- </body>
- </html>
- <?php
- }else{
- header("Location:../index.php");
- }
- ?>
- INDEX 2
- <?php
- header("Location:student/?action=forma")
- ?>
- DAO TELEFONI
- <?php
- require_once '../config/db.php';
- class DAOProizvodjaci {
- private $db;
- private $GETALLPROIZVODJACI = "SELECT * FROM proizvodjaci ORDER BY id ASC";
- private $UPDATEPROIZVODJACI = "UPDATE proizvodjaci SET naziv = ? WHERE id = ?";
- public function __construct()
- {
- $this->db = DB::createInstance();
- }
- public function getAllProizvodjaci()
- {
- $statement = $this->db->prepare($this->GETALLPROIZVODJACI);
- $statement->execute();
- $result = $statement->fetchAll();
- return $result;
- }
- public function updateProizvodjac($naziv, $id)
- {
- $statement = $this->db->prepare($this->UPDATEPROIZVODJACI);
- $statement->bindValue(1, $naziv);
- $statement->bindValue(2, $id);
- if ($statement->execute()) {
- return true;
- } else {
- return false;
- }
- }
- }
- ?>
- TEST DELETE T
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao = new DAOTelefoni();
- $dao->deleteTelefoni(3);
- ?>
- </body>
- </html>
- TEST GET ALL T
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao = new DAOTelefoni();
- //$tel = $dao->getAllTelefoni();
- $t = $dao->getTelefonById(2);
- //foreach ($tel as $t)
- echo $t['id']." ".$t['naziv']." ".$t['cena']." ".$t['id_proizvodjaca']." ".$t['naziv']."<br>";
- ?>
- </body>
- </html>
- TEST UPADTE
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao = new DAOTelefoni();
- $dao->updateTelefon(2000, 1);
- ?>
- </body>
- </html>
- TEST GET ALL PROIZ
- <?php
- require_once '../proizvodjaci/DAOProizvodjaci.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao = new DAOProizvodjaci();
- $pr = $dao->getAllProizvodjaci();
- foreach ($pr as $p)
- echo $p['id']." ".$p['naziv']."<br>";
- ?>
- </body>
- </html>
- TEST UPDATE PROZV
- <?php
- require_once '../proizvodjaci/DAOProizvodjaci.php';
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <?php
- $dao = new DAOProizvodjaci();
- $dao->updateProizvodjac("Samsung Group", 2);
- ?>
- </body>
- </html>
- KONTROLER
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- class ControllerTelefoni {
- function getAllTelefoni() {
- include '../telefoni/viewTelefoni.php';
- }
- function deleteTelefon() {
- $id = isset($_GET['id'])? $_GET['id'] : "";
- $dao = new DAOTelefoni();
- $dao->deleteTelefoni($id);
- include 'viewTelefoni.php';
- }
- function goEditTelefon() {
- $id = isset($_GET['id'])? $_GET['id'] : "";
- include '../telefoni/viewEditTelefoni.php';
- }
- function updateTelefon() {
- $id = isset($_POST['id'])? $_POST['id'] : "";
- $cena = isset($_POST['cena'])? $_POST['cena'] : "";
- if (!empty($cena)) {
- if (is_numeric($cena)) {
- $dao = new DAOTelefoni();
- $telefon = $dao->updateTelefon($cena, $id);
- include '../telefoni/viewTelefoni.php';
- } else {
- $msg = "Cena mora biti broj";
- include '../telefoni/viewEditTelefoni.php';
- }
- } else {
- $msg = "Morate popuniti cenu";
- include '../telefoni/viewEditTelefoni.php';
- }
- }
- }
- ?>
- INDEX
- <?php
- require_once 'ControllerTelefoni.php';
- $action = isset($_REQUEST['action'])? $_REQUEST['action'] : "goTelefoni";
- $ct = new ControllerTelefoni();
- switch ($_SERVER['REQUEST_METHOD']) {
- case "GET":
- switch ($action) {
- case "goTelefoni":
- $ct->getAllTelefoni();
- break;
- case "delete":
- $ct->deleteTelefon();
- break;
- case "goedit":
- $ct->goEditTelefon();
- break;
- }
- break;
- case "POST":
- switch ($action) {
- case "Save":
- $ct->updateTelefon();
- break;
- }
- break;
- }
- ?>
- FORMA
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- $dao = new DAOTelefoni();
- $tel = $dao->getTelefonById($id);
- $msg = isset($msg)? $msg : "";
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <h1>Edit telefoni</h1>
- <?php echo $msg;?><br><br>
- <form action="../telefoni/" method="post">
- ID:<br><input type="hidden" name="id" value="<?php echo $tel['id'];?>"><?php echo $id;?><br><br>
- Naziv:<br> <?php echo $tel['naziv'];?><br><br>
- Cena:<br><input type="text" name="cena" placeholder="cena" value="<?php echo $tel['cena'];?>"><br><br>
- ID proizvodjaca: <br> <?php echo $tel['id_proizvodjaca'];?><br><br>
- Naziv proizvodjaca: <br> <?php echo $tel['naziv'];?><br><br>
- <input type="submit" name="action" value="Save">
- </form>
- </body>
- </html>
- VIEW TELEFONI
- <?php
- require_once '../telefoni/DAOTelefoni.php';
- $dao = new DAOTelefoni();
- $telefoni = $dao->getAllTelefoni();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <h1>Telefoni</h1>
- <table>
- <tr>
- <th>ID</th>
- <th>Naziv</th>
- <th>Cena</th>
- <th>ID proizvodjaca</th>
- <th>Naziv proizvodjaca</th>
- <th>Edit</th>
- <th>Delete</th>
- </tr>
- <?php foreach ($telefoni as $telefon) {?>
- <tr>
- <td><?php echo $telefon['id'];?></td>
- <td><?php echo $telefon['naziv'];?></td>
- <td><?php echo $telefon['cena'];?></td>
- <td><?php echo $telefon['id_proizvodjaca'];?></td>
- <td><?php echo $telefon['naziv'];?></td>
- <td><a href="../telefoni/?action=goedit&id=<?php echo $telefon['id'];?>">Edit</a></td>
- <td><a href="../telefoni/?action=delete&id=<?php echo $telefon['id'];?>">Delete</a></td>
- </tr>
- <?php }?>
- </table>
- </body>
- </html>
Add Comment
Please, Sign In to add comment