-
-
Save Darkry/804583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class AddController { | |
public function __construct() { | |
require 'model/WriteModel.php'; | |
} | |
public function newPost($name,$text) { | |
$addModel = new WriteModel($name, $text); | |
return $addModel; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class DbModel { | |
public $id_spojeni; | |
function __construct() { | |
$server = "127.0.0.1"; // jm�no serveru | |
$login = "root"; // p�ihla�ovac� jm�no | |
$heslo_dat = ""; // heslo | |
$databaze = "visitbook"; // n�zev datab�ze | |
$this->id_spojeni = MySQL_Connect($server, $login, $heslo_dat) or die("Nepodařilo se připojit k databázi"); // p�ipojen� k datab�zi | |
MySQL_Select_DB($databaze) or die("Nepodařilo se otevřít databázi"); // v�b�r datab�ze | |
mysql_query("SET NAMES 'utf8'"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
error_reporting(E_ALL); | |
require 'controller/PostsController.php'; | |
require 'model/DbModel.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=utf-8"> | |
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection"> | |
<title>Návštěvní kniha - OOP | |
</title> | |
</head> | |
<body> | |
<h1>Návštěvní kniha</h1> | |
<?php | |
$controller = new PostsController; | |
$posts = $controller->posts(); | |
if(isset($_POST["name"])) { | |
require 'controller/AddController.php'; | |
$newPost = new AddController(); | |
$addPost = $newPost->newPost($_POST["name"], $_POST["text"]); | |
if($addPost == true) | |
echo "<h3>Příspěvek byl úspěšně přidán!</h3><br>Pokud svůj příspěvek nevidíte obnovte nejdříve stránku!"; | |
else | |
echo "Příspěvek se nepodařilo přidat. Někde je chyba!"; | |
} | |
?> | |
<div id="prispevky" style="width: 80%; margin-left: 10%"> | |
<form name="post" action="index.php" method="post" onSubmit="return check()"> | |
<table> | |
<tr><td style="text-align: right;"><label for="name">Jméno:</label></td><td><input type="text" name="name"></td></tr> | |
<tr><td style="text-align: right;"><label for="text">Text:</label></td><td><textarea name="text" rows="7" cols="50"></textarea></td></tr> | |
<tr><td></td><td style="text-align: right;"><input type="submit" name="submit"></td></tr> | |
</table> | |
</form> | |
<?php | |
foreach($posts as $arr => $id) { | |
echo "<b>". $id[0] ."</b> <div style=\"float: right;\">". $id[1] ."</div><br>". $id[2] ."<br><hr>"; | |
} | |
?> | |
</div> | |
<script type="text/javascript"> | |
var cesta; | |
function check() { | |
cesta = document.post; | |
if(cesta.name.value=="" || cesta.text.value=="") { | |
alert('Musíte vyplnit všechny povinné údaje'); | |
return false; | |
} | |
else | |
return true; | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class PostsController { | |
public $model; | |
function posts() { | |
require "model/ReadModel.php"; | |
$this->model = new ReadModel; | |
$prispevky = $this->model->ReadPosts(); | |
return $prispevky; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy.src.files=false | |
copy.src.target= | |
index.file=index.php | |
run.as=LOCAL | |
url=http://127.0.0.1:8888/oop/navstevni%20kniha%20v%20oop/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include.path=${php.global.include.path} | |
php.version=PHP_53 | |
source.encoding=UTF-8 | |
src.dir=. | |
tags.asp=false | |
tags.short=true | |
web.root=. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://www.netbeans.org/ns/project/1"> | |
<type>org.netbeans.modules.php.project</type> | |
<configuration> | |
<data xmlns="http://www.netbeans.org/ns/php-project/1"> | |
<name>navstevni kniha v oop</name> | |
</data> | |
</configuration> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class ReadModel extends DbModel { | |
function ReadPosts() { | |
$select = mysql_query("SELECT * FROM prispevky ORDER BY Datum DESC",$this->id_spojeni); | |
$posts = array(); | |
while($radek = mysql_fetch_array($select)) { | |
$posts[] = $radek; | |
} | |
return $posts; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CSS Document */ | |
body { | |
background: lightblue; | |
width: 800px; | |
margin: 0 auto; | |
padding: 0; | |
} | |
h1 { | |
text-align: center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- phpMyAdmin SQL Dump | |
-- version 3.3.8 | |
-- http://www.phpmyadmin.net | |
-- | |
-- Počítač: 127.0.0.1 | |
-- Vygenerováno: Neděle 30. ledna 2011, 21:49 | |
-- Verze MySQL: 5.1.52 | |
-- Verze PHP: 5.3.3 | |
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; | |
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | |
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | |
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | |
/*!40101 SET NAMES utf8 */; | |
-- | |
-- Databáze: `visitbook` | |
-- | |
-- -------------------------------------------------------- | |
-- | |
-- Struktura tabulky `prispevky` | |
-- | |
CREATE TABLE IF NOT EXISTS `prispevky` ( | |
`Jmeno` varchar(30) CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL, | |
`Datum` datetime NOT NULL, | |
`Text` text CHARACTER SET utf8 COLLATE utf8_czech_ci NOT NULL, | |
`ID` int(11) NOT NULL AUTO_INCREMENT, | |
PRIMARY KEY (`ID`) | |
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ; | |
-- | |
-- Vypisuji data pro tabulku `prispevky` | |
-- | |
INSERT INTO `prispevky` (`Jmeno`, `Datum`, `Text`, `ID`) VALUES | |
('Kryštof', '2011-01-18 09:15:30', 'Ahoj, tohle je zkouška', 1), | |
('Darkry', '2011-01-04 09:15:50', 'čau, tohle je taky zkouška!', 2), | |
('Darkry', '2011-01-30 21:45:41', 'Další pokus. Tentokrát už přidávám příspěvek!', 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class WriteModel extends DbModel { | |
public function __construct($name,$text) { | |
$addPost = mysql_query("INSERT INTO prispevky(Jmeno,Datum,Text) VALUES ('$name', NOW(), '$text' )"); | |
if($addPost) | |
return true; | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment