tanjam23

Untitled

Jun 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.91 KB | None | 0 0
  1. G6-DUSICA
  2. DAO
  3. <?php
  4. require_once '../config/db.php';
  5.  
  6. class DAOTelefoni {
  7. private $db;
  8.  
  9. private $INSERTTELEFON = "INSERT INTO telefoni (marka, cena) VALUES (?, ?)";
  10. private $GETTELEFONI = "SELECT * FROM telefoni WHERE marka = ? AND cena > ?";
  11.  
  12. public function __construct()
  13. {
  14. $this->db = DB::createInstance();
  15. }
  16.  
  17. public function insertTelefon($marka, $cena)
  18. {
  19. $statement = $this->db->prepare($this->INSERTTELEFON);
  20. $statement->bindValue(1, $marka);
  21. $statement->bindValue(2, $cena);
  22.  
  23. $result = $statement->fetch();
  24. $statement->execute();
  25.  
  26. }
  27.  
  28. public function getTelefoni($marka, $cena)
  29. {
  30.  
  31.  
  32. // 2. nacin
  33.  
  34. $statement = $this->db->prepare($this->GETTELEFONI);
  35. $statement->bindValue(1, $marka);
  36. $statement->bindValue(2, $cena);
  37. $result = $statement->fetch();
  38. $statement->execute();
  39.  
  40. $result = $statement->fetchAll();
  41. return $result;
  42. }
  43. }
  44. ?>
  45.  
  46. TEST GET
  47. <?php
  48. require_once '../telefoni/DAOTelefoni.php';
  49. $dao = new DAOTelefoni();
  50. ?>
  51.  
  52. <!DOCTYPE html>
  53. <html lang="en">
  54. <head>
  55. <meta charset="UTF-8">
  56. <title>Title</title>
  57. </head>
  58. <body>
  59. <?php
  60. $telefoni = $dao->getTelefoni("Nokia", 400.00);
  61. foreach ($telefoni as $t){
  62. echo $t['marka'] . " " . $t['cena'] . "<br>";
  63. }
  64. ?>
  65. </body>
  66. </html>
  67. TEST INSERT
  68. <?php
  69. require_once '../telefoni/DAOTelefoni.php';
  70. $dao = new DAOTelefoni();
  71. ?>
  72.  
  73. <!DOCTYPE html>
  74. <html lang="en">
  75. <head>
  76. <meta charset="UTF-8">
  77. <title>Title</title>
  78. </head>
  79. <body>
  80. <?php
  81. $dao->insertTelefon("Nokia", 999.00);
  82. ?>
  83. </body>
  84. </html>
  85. KONTROLER
  86. <?php
  87.  
  88. require_once '../telefoni/DAOTelefoni.php';
  89. session_start();
  90.  
  91. class controllerTelefona{
  92.  
  93. function goForma(){
  94. include '../telefoni/viewForma.php';
  95. }
  96.  
  97. function deleteSession(){
  98. if($_SESSION['telefon'] != ""){
  99. session_unset();
  100. session_destroy();
  101.  
  102. include '../telefoni/viewForma.php';
  103. }
  104. }
  105.  
  106.  
  107. function insertTelefon(){
  108.  
  109. // prvo kupi parametre
  110. $id = isset($_POST['id']) ? $_POST['id'] : "";
  111. $marka = isset($_POST['marka']) ? $_POST['marka'] : "";
  112. $cena = isset($_POST['cena']) ? $_POST['cena'] : "";
  113.  
  114. $dao = new DAOTelefoni();
  115.  
  116. if(!empty($marka) && !empty($cena)){
  117. if(is_numeric($cena)){
  118.  
  119. $telefon = $dao->insertTelefon($marka, $cena);
  120. $telefoni = $dao->getTelefoni($marka, $cena);
  121. $_SESSION['telefon'] = $telefoni;
  122.  
  123. include '../telefoni/viewPrikazTelefona.php';
  124. }
  125. else{
  126. $msg = "Cena mora biti broj";
  127. include "../telefoni/viewForma.php";
  128. }
  129. }
  130. else{
  131. $msg = "Polja su obavezna";
  132. include '../telefoni/viewForma.php';
  133. }
  134.  
  135. }
  136.  
  137. }
  138. ?>
  139. INDEX 1
  140. <?php
  141. require_once '../telefoni/controllerTelefona.php';
  142. $ct = new controllerTelefona();
  143.  
  144. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
  145.  
  146. switch ($_SERVER['REQUEST_METHOD']){
  147. case "GET":
  148. switch($action){
  149. case "goForma":
  150. $ct->goForma();
  151. break;
  152. case "deleteSession":
  153. $ct->deleteSession();
  154. break;
  155. }
  156. break;
  157. case "POST":
  158. switch($action){
  159. case "insert":
  160. $ct->insertTelefon();
  161. break;
  162. }
  163. break;
  164. default:
  165. header("Location: ../index.php");
  166. break;
  167. }
  168. ?>
  169. VIEW FORMA
  170. <?php
  171. $msg = isset($msg) ? $msg : "";
  172. ?>
  173. <!DOCTYPE html>
  174. <html lang="en">
  175. <head>
  176. <meta charset="UTF-8">
  177. <title>Title</title>
  178. </head>
  179. <body>
  180. <h1>Forma za prosledjivanje parametara</h1>
  181. <span style="color: purple;"><?php echo $msg;?></span><br><br>
  182. <form action="../telefoni/" method="POST">
  183. Marka: <input type="text" name="marka"><br><br>
  184. Cena: <input type="text" name="cena"><br><br>
  185. <input type="submit" name="action" value="insert"><br><br>
  186. </form>
  187. </body>
  188. </html>
  189.  
  190. PRIKAZ TELEFONA
  191.  
  192. <?php
  193. require_once '../telefoni/DAOTelefoni.php';
  194. $msg = isset($msg) ? $msg : "";
  195. if($_SESSION['telefon'] != "") {
  196. ?>
  197. <!DOCTYPE html>
  198. <html lang="en">
  199. <head>
  200. <meta charset="UTF-8">
  201. <title>Title</title>
  202. </head>
  203. <body>
  204. <?php echo $msg;?>
  205. <h1>Prikaz telefona</h1>
  206. <?php
  207. $dao = new DAOTelefoni();
  208. $telefoni = $dao->getTelefoni($marka, $cena);
  209. ?>
  210. <ul>
  211. <?php foreach ($telefoni as $t){ ?>
  212. <li><?php echo $t['marka'] . " " . $t['cena'];?></li>
  213. <?php }?>
  214. </ul>
  215.  
  216. <a href="../telefoni/?action=deleteSession">Resetuj / logout</a>
  217. </body>
  218. </html>
  219. <?php
  220. }
  221. else{
  222. header("Location: ../index.php");
  223. exit();
  224. }
  225.  
  226.  
  227. ?>
  228. INDEX 2
  229. <?php
  230.  
  231. header("Location: telefoni/?action=goForma");
  232. ?>
  233. DUSICA-REZULTATI
  234. <?php
  235. require_once '../config/db.php';
  236.  
  237. class DAORezultati {
  238. private $db;
  239.  
  240. private $INSERTREZ = "INSERT INTO rezultati (br_indexa, predmet, ocena) VALUES (?, ?, ?)";
  241. private $GETPROSEK = "SELECT AVG(ocena) AS prosek FROM rezultati WHERE br_indexa = ?";
  242.  
  243. public function __construct()
  244. {
  245. $this->db = DB::createInstance();
  246. }
  247. public function insertRezultat($br_indexa, $predmet, $ocena)
  248. {
  249.  
  250.  
  251. // 2. nacin
  252. $statement = $this->db->prepare($this->INSERTREZ);
  253. $statement->bindValue(1, $br_indexa);
  254. $statement->bindValue(2, $predmet);
  255. $statement->bindValue(3, $ocena);
  256.  
  257. $statement->execute();
  258. }
  259.  
  260. public function getProsekByIndex($br_indexa)
  261. {
  262.  
  263.  
  264. // 2. nacin
  265.  
  266. $statement = $this->db->prepare($this->GETPROSEK);
  267. $statement->bindValue(1, $br_indexa);
  268.  
  269. $statement->execute();
  270.  
  271. $result = $statement->fetch();
  272. return $result;
  273. }
  274. }
  275. ?>
  276. TEST AVG
  277. <?php
  278. require_once '../rezultati/DAORezultati.php';
  279. $dao = new DAORezultati();
  280. ?>
  281. <!DOCTYPE html>
  282. <html lang="en">
  283. <head>
  284. <meta charset="UTF-8">
  285. <title>Title</title>
  286. </head>
  287. <body>
  288. <?php
  289. $rez = $dao->getProsekByIndex("222/2016");
  290. print_r($rez);
  291. //var_dump($rez);
  292.  
  293. ?>
  294. </body>
  295. </html>
  296.  
  297. TEST INSERT
  298. <?php
  299. require_once '../rezultati/DAORezultati.php';
  300. $dao = new DAORezultati();
  301. ?>
  302. <!DOCTYPE html>
  303. <html lang="en">
  304. <head>
  305. <meta charset="UTF-8">
  306. <title>Title</title>
  307. </head>
  308. <body>
  309. <?php
  310. $dao->insertRezultat('222/2016', "Menadzment", 9);
  311. ?>
  312. </body>
  313. </html>
  314. KONTROLER
  315. <?php
  316.  
  317. require_once '../rezultati/DAORezultati.php';
  318. session_start();
  319.  
  320. class controllerRezultata{
  321.  
  322. function goForma(){
  323. include '../rezultati/viewForma.php';
  324. }
  325.  
  326. function logout(){
  327. if($_SESSION['rezultat'] != ""){
  328. session_unset();
  329. session_destroy();
  330. include '../rezultati/viewForma.php';
  331. }
  332. }
  333. function insertRez(){
  334.  
  335. $id = isset($_POST['id']) ? $_POST['id'] : "";
  336. $br_indexa = isset($_POST['br_indexa']) ? $_POST['br_indexa'] : "";
  337. $predmet = isset($_POST['predmet']) ? $_POST['predmet'] : "";
  338. $ocena = isset($_POST['ocena']) ? $_POST['ocena'] : "";
  339.  
  340. $dao = new DAORezultati();
  341.  
  342. if(!empty($br_indexa) && !empty($predmet) && !empty($ocena)){
  343. if(is_numeric($ocena)){
  344. $rezultat = $dao->insertRezultat($br_indexa, $predmet, $ocena);
  345. $prosek = $dao->getProsekByIndex($br_indexa);
  346. $_SESSION['rezultat'] = $br_indexa;
  347. include '../rezultati/viewPrikazRezultata.php';
  348. }
  349. else{
  350. $msg = "Ocena je broj";
  351. include "../rezultati/viewForma.php";
  352. }
  353. }
  354. else{
  355. $msg = "Poppuniti sva polja";
  356. include "'../rezultati/viewForma.php'";
  357. }
  358. }
  359. }
  360.  
  361. ?>
  362. INDEX 1
  363. <?php
  364.  
  365. require_once '../rezultati/controllerRezultata.php';
  366. $cr = new controllerRezultata();
  367. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
  368.  
  369. switch ($_SERVER['REQUEST_METHOD']){
  370. case "GET":
  371. switch ($action){
  372. case "goForma":
  373. $cr->goForma();
  374. break;
  375.  
  376. case "logout";
  377. $cr->logout();
  378. break;
  379. }
  380. break;
  381. case "POST":
  382. switch($action){
  383. case "insert":
  384. $cr->insertRez();
  385. break;
  386. }
  387. break;
  388. default:
  389. header("Loation: ../index.php");
  390. break;
  391. }
  392. ?>
  393. FORMA
  394. <?php
  395. $msg = isset($msg) ? $msg : "";
  396. ?>
  397.  
  398. <!DOCTYPE html>
  399. <html lang="en">
  400. <head>
  401. <meta charset="UTF-8">
  402. <title>Title</title>
  403. </head>
  404. <body>
  405. <h1>Forma za prosledjivanje prarametara</h1>
  406. <span style="color: green;"><?php echo $msg;?></span><br><br>
  407. <form action="../rezultati/" method="POST">
  408. Broj indeksa: <input type="text" name="br_indexa"><br><br>
  409. Predmet: <input type="text" name="predmet"><br><br>
  410. Ocena: <input type="text" name="ocena"><br><br>
  411. <input type="submit" name="action" value="insert"><br><br>
  412. </form>
  413. </body>
  414. </html>
  415. PRIKAZ REZULTATA
  416. <?php
  417. require_once '../rezultati/DAORezultati.php';
  418.  
  419. if($_SESSION['rezultat'] != "") {
  420.  
  421. ?>
  422.  
  423. <!DOCTYPE html>
  424. <html lang="en">
  425. <head>
  426. <meta charset="UTF-8">
  427. <title>Title</title>
  428. </head>
  429. <body>
  430. <h1>Prikaz prosecne ocene za datog studenta</h1>
  431. <?php
  432. $dao = new DAORezultati();
  433. $prosek = $dao->getProsekByIndex($_SESSION['rezultat']);
  434. ?>
  435. Broj indeksa: <?php echo $_SESSION['rezultat']; ?><BR><BR>
  436. Prosecna ocena: <?php echo implode(",", $prosek);?>
  437. <br><br>
  438. <a href="../rezultati/?action=logout">resetuj</a>
  439. </body>
  440. </html>
  441. <?php
  442. }
  443. else{
  444. header("Location: ../index.php");
  445. exit();
  446. }
  447.  
  448. ?>
  449. INDEX 2
  450. <?php
  451.  
  452. header("Location: rezultati/?action=goForma");
  453.  
  454. ?>
  455. <?php
  456. require_once '../config/db.php';
  457.  
  458. class DAOStudent {
  459. private $db;
  460.  
  461. private $STUDENTPOSTOJI="SELECT * FROM student WHERE id=?";
  462. private $UPDATESTUDENT="UPDATE student SET ime=?,prezime=?,brIndexa=? WHERE id=?";
  463. public function __construct()
  464. {
  465. $this->db = DB::createInstance();
  466. }
  467. public function getStudent($id){
  468. $statement = $this->db->prepare($this->STUDENTPOSTOJI);
  469. $statement->bindValue(1, $id);
  470.  
  471. $statement->execute();
  472. $result = $statement->fetch();
  473. return $result;
  474. }
  475. public function getStudentById($id)
  476. {
  477. $statement = $this->db->prepare($this->STUDENTPOSTOJI);
  478. $statement->bindValue(1, $id);
  479.  
  480. $statement->execute();
  481.  
  482. if ($result = $statement->fetch()){
  483. return true;
  484. }else{
  485. return false;
  486. }
  487.  
  488. }
  489.  
  490. public function update($id,$ime,$prezime,$brIndexa)
  491. {
  492. $statement = $this->db->prepare($this->UPDATESTUDENT);
  493. $statement->bindValue(1, $ime);
  494. $statement->bindValue(2, $prezime);
  495. $statement->bindValue(3, $brIndexa);
  496. $statement->bindValue(4, $id);
  497.  
  498. $statement->execute();
  499. }
  500. }
  501. ?>
  502. TEST DA LI POSTOJI
  503. <?php
  504. require_once '../student/DAOStudent.php';
  505. ?>
  506.  
  507. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  508. <html>
  509. <head>
  510. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  511. <title>Insert title here</title>
  512. </head>
  513. <body>
  514. <?php
  515. $dao=new DAOStudent();
  516. echo $dao->getStudentById(88);
  517. ?>
  518. </body>
  519. </html>
  520.  
  521. FLIGHT
  522.  
  523. <?php
  524. require 'flight/Flight.php';
  525. require_once '../student/DAOStudent.php';
  526.  
  527. Flight::route('/', function(){
  528. echo 'hello world!';
  529. });
  530.  
  531. Flight::route('GET /student/@id', function($id){
  532. $dao=new DAOStudent();
  533. $result=$dao->getStudentById($id);
  534. echo json_encode($result);
  535. });
  536. Flight::route('PUT /student/@id', function($id){
  537. $dao=new DAOStudent();
  538. $ime=Flight::request()->data->ime;
  539. $prezime=Flight::request()->data->prezime;
  540. $brIndexa=Flight::request()->data->brIndexa;
  541. $result=$dao->update($id,$ime,$prezime,$brIndexa);
  542. echo json_encode($result);
  543. });
  544.  
  545.  
  546. Flight::start();
  547.  
  548. KONTROLER STUDENT
  549.  
  550. <?php
  551. require_once 'DAOStudent.php';
  552. session_start();
  553.  
  554. class controllerStudent{
  555. function update(){
  556. $id=isset($_POST["id"])?$_POST['id']:"";
  557. $ime=isset($_POST["ime"])?$_POST['ime']:"";
  558. $prezime=isset($_POST["prezime"])?$_POST['prezime']:"";
  559. $indeks=isset($_POST["indeks"])?$_POST['indeks']:"";
  560.  
  561. $dao=new DAOStudent();
  562. $postoji=$dao->getStudentById($id);
  563. if ($postoji==true){
  564. if (!empty($ime)&&!empty($prezime)&&!empty($indeks)){
  565. $dao->update($id, $ime, $prezime, $indeks);
  566. $_SESSION["korisnik"]=$id;
  567. include 'prikaz.php';
  568. }else{
  569. $msg="Morate popuniti sva polja";
  570. include 'viewForma.php';
  571. }
  572. }else{
  573. $msg="Student sa datim brojem indeksa ne postoji";
  574. include 'viewForma.php';
  575. }
  576.  
  577. }
  578.  
  579. function delete(){
  580. if ($_SESSION["korisnik"]!=""){
  581. session_destroy();
  582. session_unset($_SESSION["korisnik"]);
  583. include 'viewForma.php';
  584. }
  585. }
  586. }
  587.  
  588. ?>
  589. INDEX
  590. <?php
  591. $action=isset($_REQUEST['action'])?$_REQUEST['action']:"";
  592. require_once 'controllerStudent.php';
  593.  
  594. switch ($_SERVER["REQUEST_METHOD"]){
  595. case "GET":
  596. switch ($action){
  597. case "forma":
  598. include 'viewForma.php';
  599. break;
  600. case "delete":
  601. $cs=new controllerStudent();
  602. $cs->delete();
  603. break;
  604. }
  605. break;
  606.  
  607. case "POST":
  608. switch ($action){
  609. case "Update":
  610. $cs=new controllerStudent();
  611. $cs->update();
  612. break;
  613. }
  614. break;
  615.  
  616. }
  617. ?>
  618. FORMA
  619. <?php
  620. $msg=isset($msg)?$msg:"";
  621. ?>
  622. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  623. <html>
  624. <head>
  625. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  626. <title>Insert title here</title>
  627. </head>
  628. <body>
  629. <?php
  630. echo $msg;
  631. ?>
  632. <form action="" method="post">
  633. ID: <input type="text" name="id" value><br>
  634. Ime: <input type="text" name="ime"><br>
  635. Prezime: <input type="text" name="prezime"><br>
  636. Indeks: <input type="text" name="indeks"><br>
  637. <input type="submit" name="action" value="Update">
  638. </form>
  639. </body>
  640. </html>
  641. PRIKAZ
  642. <?php
  643. require_once 'DAOStudent.php';
  644. if ($_SESSION["korisnik"]!=""){
  645. ?>
  646. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  647. <html>
  648. <head>
  649. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  650. <title>Insert title here</title>
  651. </head>
  652. <body>
  653. <?php
  654. $dao=new DAOStudent();
  655. $student=$dao->getStudent($_SESSION['korisnik'])
  656. ?>
  657. Id:<?php echo $student["id"]?><br>
  658. Ime:<?php echo $student["ime"]?><br>
  659. Prezime:<?php echo $student["prezime"]?><br>
  660. Broj indeksa:<?php echo $student["brIndexa"]?><br>
  661. <a href="../student/?action=delete">Resetuj</a>
  662.  
  663. </body>
  664. </html>
  665.  
  666. <?php
  667. }else{
  668. header("Location:../index.php");
  669. }
  670. ?>
  671. INDEX 2
  672. <?php
  673. header("Location:student/?action=forma")
  674. ?>
  675. DAO TELEFONI
  676. <?php
  677. require_once '../config/db.php';
  678.  
  679. class DAOProizvodjaci {
  680. private $db;
  681.  
  682. private $GETALLPROIZVODJACI = "SELECT * FROM proizvodjaci ORDER BY id ASC";
  683. private $UPDATEPROIZVODJACI = "UPDATE proizvodjaci SET naziv = ? WHERE id = ?";
  684.  
  685. public function __construct()
  686. {
  687. $this->db = DB::createInstance();
  688. }
  689.  
  690. public function getAllProizvodjaci()
  691. {
  692.  
  693. $statement = $this->db->prepare($this->GETALLPROIZVODJACI);
  694.  
  695. $statement->execute();
  696.  
  697. $result = $statement->fetchAll();
  698. return $result;
  699. }
  700.  
  701. public function updateProizvodjac($naziv, $id)
  702. {
  703.  
  704. $statement = $this->db->prepare($this->UPDATEPROIZVODJACI);
  705. $statement->bindValue(1, $naziv);
  706. $statement->bindValue(2, $id);
  707.  
  708. if ($statement->execute()) {
  709. return true;
  710. } else {
  711. return false;
  712. }
  713. }
  714.  
  715.  
  716. }
  717. ?>
  718. TEST DELETE T
  719. <?php
  720. require_once '../telefoni/DAOTelefoni.php';
  721. ?>
  722. <!DOCTYPE html>
  723. <html>
  724. <head>
  725. <meta charset="ISO-8859-1">
  726. <title>Insert title here</title>
  727. </head>
  728. <body>
  729. <?php
  730. $dao = new DAOTelefoni();
  731. $dao->deleteTelefoni(3);
  732.  
  733. ?>
  734. </body>
  735. </html>
  736. TEST GET ALL T
  737. <?php
  738. require_once '../telefoni/DAOTelefoni.php';
  739. ?>
  740. <!DOCTYPE html>
  741. <html>
  742. <head>
  743. <meta charset="ISO-8859-1">
  744. <title>Insert title here</title>
  745. </head>
  746. <body>
  747. <?php
  748. $dao = new DAOTelefoni();
  749. //$tel = $dao->getAllTelefoni();
  750. $t = $dao->getTelefonById(2);
  751. //foreach ($tel as $t)
  752. echo $t['id']." ".$t['naziv']." ".$t['cena']." ".$t['id_proizvodjaca']." ".$t['naziv']."<br>";
  753. ?>
  754. </body>
  755. </html>
  756. TEST UPADTE
  757. <?php
  758. require_once '../telefoni/DAOTelefoni.php';
  759. ?>
  760. <!DOCTYPE html>
  761. <html>
  762. <head>
  763. <meta charset="ISO-8859-1">
  764. <title>Insert title here</title>
  765. </head>
  766. <body>
  767. <?php
  768. $dao = new DAOTelefoni();
  769. $dao->updateTelefon(2000, 1);
  770.  
  771. ?>
  772. </body>
  773. </html>
  774. TEST GET ALL PROIZ
  775. <?php
  776. require_once '../proizvodjaci/DAOProizvodjaci.php';
  777. ?>
  778. <!DOCTYPE html>
  779. <html>
  780. <head>
  781. <meta charset="ISO-8859-1">
  782. <title>Insert title here</title>
  783. </head>
  784. <body>
  785. <?php
  786. $dao = new DAOProizvodjaci();
  787. $pr = $dao->getAllProizvodjaci();
  788.  
  789. foreach ($pr as $p)
  790. echo $p['id']." ".$p['naziv']."<br>";
  791. ?>
  792. </body>
  793. </html>
  794. TEST UPDATE PROZV
  795. <?php
  796. require_once '../proizvodjaci/DAOProizvodjaci.php';
  797. ?>
  798. <!DOCTYPE html>
  799. <html>
  800. <head>
  801. <meta charset="ISO-8859-1">
  802. <title>Insert title here</title>
  803. </head>
  804. <body>
  805. <?php
  806. $dao = new DAOProizvodjaci();
  807. $dao->updateProizvodjac("Samsung Group", 2);
  808.  
  809. ?>
  810. </body>
  811. </html>
  812. KONTROLER
  813. <?php
  814. require_once '../telefoni/DAOTelefoni.php';
  815.  
  816. class ControllerTelefoni {
  817.  
  818. function getAllTelefoni() {
  819. include '../telefoni/viewTelefoni.php';
  820. }
  821.  
  822. function deleteTelefon() {
  823. $id = isset($_GET['id'])? $_GET['id'] : "";
  824. $dao = new DAOTelefoni();
  825. $dao->deleteTelefoni($id);
  826.  
  827. include 'viewTelefoni.php';
  828. }
  829.  
  830. function goEditTelefon() {
  831. $id = isset($_GET['id'])? $_GET['id'] : "";
  832.  
  833. include '../telefoni/viewEditTelefoni.php';
  834. }
  835.  
  836. function updateTelefon() {
  837. $id = isset($_POST['id'])? $_POST['id'] : "";
  838. $cena = isset($_POST['cena'])? $_POST['cena'] : "";
  839. if (!empty($cena)) {
  840. if (is_numeric($cena)) {
  841. $dao = new DAOTelefoni();
  842. $telefon = $dao->updateTelefon($cena, $id);
  843.  
  844. include '../telefoni/viewTelefoni.php';
  845. } else {
  846. $msg = "Cena mora biti broj";
  847.  
  848. include '../telefoni/viewEditTelefoni.php';
  849. }
  850. } else {
  851. $msg = "Morate popuniti cenu";
  852.  
  853. include '../telefoni/viewEditTelefoni.php';
  854. }
  855. }
  856. }
  857.  
  858. ?>
  859. INDEX
  860. <?php
  861. require_once 'ControllerTelefoni.php';
  862.  
  863. $action = isset($_REQUEST['action'])? $_REQUEST['action'] : "goTelefoni";
  864.  
  865. $ct = new ControllerTelefoni();
  866.  
  867. switch ($_SERVER['REQUEST_METHOD']) {
  868. case "GET":
  869. switch ($action) {
  870. case "goTelefoni":
  871. $ct->getAllTelefoni();
  872. break;
  873.  
  874. case "delete":
  875. $ct->deleteTelefon();
  876. break;
  877. case "goedit":
  878. $ct->goEditTelefon();
  879. break;
  880. }
  881. break;
  882. case "POST":
  883. switch ($action) {
  884. case "Save":
  885. $ct->updateTelefon();
  886. break;
  887.  
  888. }
  889. break;
  890. }
  891. ?>
  892. FORMA
  893. <?php
  894. require_once '../telefoni/DAOTelefoni.php';
  895. $dao = new DAOTelefoni();
  896. $tel = $dao->getTelefonById($id);
  897. $msg = isset($msg)? $msg : "";
  898. ?>
  899. <!DOCTYPE html>
  900. <html>
  901. <head>
  902. <meta charset="ISO-8859-1">
  903. <title>Insert title here</title>
  904. </head>
  905. <body>
  906. <h1>Edit telefoni</h1>
  907. <?php echo $msg;?><br><br>
  908. <form action="../telefoni/" method="post">
  909. ID:<br><input type="hidden" name="id" value="<?php echo $tel['id'];?>"><?php echo $id;?><br><br>
  910. Naziv:<br> <?php echo $tel['naziv'];?><br><br>
  911. Cena:<br><input type="text" name="cena" placeholder="cena" value="<?php echo $tel['cena'];?>"><br><br>
  912. ID proizvodjaca: <br> <?php echo $tel['id_proizvodjaca'];?><br><br>
  913. Naziv proizvodjaca: <br> <?php echo $tel['naziv'];?><br><br>
  914. <input type="submit" name="action" value="Save">
  915. </form>
  916. </body>
  917. </html>
  918. VIEW TELEFONI
  919. <?php
  920. require_once '../telefoni/DAOTelefoni.php';
  921. $dao = new DAOTelefoni();
  922. $telefoni = $dao->getAllTelefoni();
  923. ?>
  924. <!DOCTYPE html>
  925. <html>
  926. <head>
  927. <meta charset="ISO-8859-1">
  928. <title>Insert title here</title>
  929. </head>
  930. <body>
  931. <h1>Telefoni</h1>
  932. <table>
  933. <tr>
  934. <th>ID</th>
  935. <th>Naziv</th>
  936. <th>Cena</th>
  937. <th>ID proizvodjaca</th>
  938. <th>Naziv proizvodjaca</th>
  939. <th>Edit</th>
  940. <th>Delete</th>
  941. </tr>
  942. <?php foreach ($telefoni as $telefon) {?>
  943. <tr>
  944. <td><?php echo $telefon['id'];?></td>
  945. <td><?php echo $telefon['naziv'];?></td>
  946. <td><?php echo $telefon['cena'];?></td>
  947. <td><?php echo $telefon['id_proizvodjaca'];?></td>
  948. <td><?php echo $telefon['naziv'];?></td>
  949. <td><a href="../telefoni/?action=goedit&id=<?php echo $telefon['id'];?>">Edit</a></td>
  950. <td><a href="../telefoni/?action=delete&id=<?php echo $telefon['id'];?>">Delete</a></td>
  951. </tr>
  952. <?php }?>
  953. </table>
  954. </body>
  955. </html>
Add Comment
Please, Sign In to add comment