*** Rozhovory ***
___________________
# -*- coding: utf8 -*- from math import * from Tkinter import * import numpy as np import matplotlib.pyplot as plt ObjectWindow = Tk() ObjectWindow.geometry('1150x520') ObjectWindow.title("Skřivánek (finallos)") class Funkce_cisla: def Object_set_0(self): Object_Display.insert (END, "0") def Object_set_1(self): Object_Display.insert (END, "1") def Object_set_2(self): Object_Display.insert (END, "2") def Object_set_3(self): Object_Display.insert (END, "3") def Object_set_4(self): Object_Display.insert (END, "4") def Object_set_5(self): Object_Display.insert (END, "5") def Object_set_6(self): Object_Display.insert (END, "6") def Object_set_7(self): Object_Display.insert (END, "7") def Object_set_8(self): Object_Display.insert (END, "8") def Object_set_9(self): Object_Display.insert (END, "9") Funkce_cisla = Funkce_cisla() class Funkce_znamenka: def Object_set_multiply(self): Object_Display.insert (END, "*") def Object_set_div(self): Object_Display.insert (END, "/") def Object_set_plus(self): Object_Display.insert (END, "+") def Object_set_minus(self): Object_Display.insert (END, "-") def Object_set_power(self): Object_Display.insert (END, "**") def Object_set_leftside(self): Object_Display.insert (END, "(") def Object_set_rightside(self): Object_Display.insert (END, ")") Funkce_znamenka = Funkce_znamenka() class Funkce_goniometricke: def Object_set_sin(self): Object_Display.insert (END, "sin") def Object_set_cos(self): Object_Display.insert (END, "cos") def Object_set_tan(self): Object_Display.insert (END, "tan") def Object_set_cotg(self): Object_Display.insert (END, "1/tan") Funkce_goniometricke = Funkce_goniometricke() class Funkce_vedlejsi: def Action_Refresh(self): Object_Display.delete(0, END) def Action_Konec(self): ObjectWindow.destroy() def Action_do_it(self): vyraz=Object_Display.get() #print vyraz #print eval (vyraz) try:#eval vyhodnoti retezec a vypocte vysledek=str(eval(vyraz)) except: vysledek=" ERROR!!! " Object_Display.delete(0, END) Object_Display.insert(END, vysledek) Funkce_vedlejsi = Funkce_vedlejsi() class Funkce_vypocetni: def function_Dec_to_Bin (self, *args): a = int(GUI.decimal.get()) b = a i = 0 while b/2**i > 1: i = i + 1 biarray = np.zeros(i + 1) for j in range (i, -1, -1): test = b % 2 if test == 0: biarray [j] = 0 else: biarray [j] = 1 b = b/2 #z = np.array_str(biarray) #binary.set(z) GUI.binresult.config(text=str(biarray)) print b print biarray def function_soucet(self): # bez OOP lze odebrat self Ax=(GUI.bodAx.get()) Ay=(GUI.bodAy.get()) Bx=(GUI.bodBx.get()) By=(GUI.bodBy.get()) x = Ax + Bx y = Ay + By plt.subplot(211) plt.plot([0,Ax],[0,Ay])# vektor A plt.plot([0,Bx],[0,By])# vektor B plt.plot([0,x],[0,y]) # součet vektorů A a B plt.axis([0, 20, 0, 15]) plt.show() def function_soucin(self): # bez OOP lze odebrat self Ax=int(GUI.bodAx.get()) Ay=int(GUI.bodAy.get()) Bx=int(GUI.bodBx.get()) By=int(GUI.bodBy.get()) x = np.array([Ax,Ay]) y = np.array([Bx,By]) dot1 = (Ax*Bx) dot2 = (Ay*By) plt.subplot(211) plt.plot([0,Ax],[0,Ay])# vektor A plt.plot([0,Bx],[0,By])# vektor B plt.plot([0, dot1],[0, dot2]) # součin vektorů A a B plt.axis([0, 20, 0, 15]) plt.show() def function_kvad_rce(self): d=(GUI.kvad.get()) e=(GUI.lin.get()) f=(GUI.absol.get()) a=int(d) b=int(e) c=int(f) root=((b*b)-(4*a*c)) if root < 0: root=abs(complex(root)) j=complex(0,1) x1ia = -b+j+sqrt(root) x1ib = 2 * a x1 = x1ia/x1ib x2ia = -b-j+sqrt(root) x2ib = 2 * a x2 = x1ia/x1ib result1 = x1 result2 = x2 GUI.kvadresult.config(text=str(result1)) GUI.kvadresult2.config(text=str(result2)) return x1,x2 else: x1a = -b+sqrt(root) x1b = 2 * a x1 = x1a/x1b x2a = -b-sqrt(root) x2b = 2 * a x2 = x2a/x2b result1 = x1 result2 = x2 GUI.kvadresult.config(text=str(result1)) GUI.kvadresult2.config(text=str(result2)) return x1,x2 Funkce_vypocetni = Funkce_vypocetni() class Funkce_grafy: def function_graph_sinus(self): obor_hodnot=int(GUI.oborhodnotSIN.get()) ax = plt.subplot(111) t = np.arange(0.0, 5.0, 0.01) s = np.sin(2*np.pi*t) s = s * obor_hodnot line, = plt.plot(t, s, lw=2) plt.ylim(-5,5) plt.show() def function_graph_cosinus(self): obor_hodnot=int(GUI.oborhodnotCOS.get()) ax = plt.subplot(111) t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) s = s * obor_hodnot line, = plt.plot(t, s, lw=2) plt.ylim(-5,5) plt.show() def function_graph_tangens(self): x = np.arange(-10, 10.01, 0.01) plt.subplot(211) plt.plot(x, np.tan(x)) plt.ylim(-15, 15) plt.show() def function_graph_arctg(self): x = np.linspace(-10, 10) plt.plot(x, np.arctan(x)) plt.axis('tight') plt.show() Funkce_grafy = Funkce_grafy() Object_Display = Entry(ObjectWindow) Object_Display.config(width=35, fg="red", bg="white", font=20) Object_Display.grid(row=0, columnspan=3, padx="30", pady="30") class GUI: Object_Button_1 = Button(ObjectWindow, text="1", command=Funkce_cisla.Object_set_1, relief=GROOVE, fg="red",bg="white",) Object_Button_1.grid(row=2, column=0, sticky=EW) Object_Button_2 = Button(ObjectWindow, text="2", command=Funkce_cisla.Object_set_2, relief=GROOVE, fg="red",bg="white",) Object_Button_2.grid(row=2, column=1, sticky=EW) Object_Button_3 = Button(ObjectWindow, text="3", command=Funkce_cisla.Object_set_3, relief=GROOVE, fg="red",bg="white",) Object_Button_3.grid(row=2, column=2, sticky=EW) Object_Button_4 = Button(ObjectWindow, text="4", command=Funkce_cisla.Object_set_4, relief=GROOVE, fg="red",bg="white",) Object_Button_4.grid(row=3, column=0, sticky=EW) Object_Button_5 = Button(ObjectWindow, text="5", command=Funkce_cisla.Object_set_5, relief=GROOVE, fg="red",bg="white",) Object_Button_5.grid(row=3, column=1, sticky=EW) Object_Button_6 = Button(ObjectWindow, text="6", command=Funkce_cisla.Object_set_6, relief=GROOVE, fg="red",bg="white",) Object_Button_6.grid(row=3, column=2, sticky=EW) Object_Button_7 = Button(ObjectWindow, text="7", command=Funkce_cisla.Object_set_7, relief=GROOVE, fg="red",bg="white",) Object_Button_7.grid(row=4, column=0, sticky=EW) Object_Button_8 = Button(ObjectWindow, text="8", command=Funkce_cisla.Object_set_8, relief=GROOVE, fg="red",bg="white",) Object_Button_8.grid(row=4, column=1, sticky=EW) Object_Button_9 = Button(ObjectWindow, text="9", command=Funkce_cisla.Object_set_9, relief=GROOVE, fg="red",bg="white",) Object_Button_9.grid(row=4, column=2, sticky=EW) Object_Button_0 = Button(ObjectWindow, text="0", command=Funkce_cisla.Object_set_0, relief=GROOVE, fg="red",bg="white",) Object_Button_0.grid(row=5, column=1, sticky=EW) Object_Button_div = Button(ObjectWindow, text="/", command=Funkce_znamenka.Object_set_div, relief=GROOVE, bg="white") Object_Button_div.grid(row=5, column=0, sticky=EW) Object_Button_plus = Button(ObjectWindow, text="+", command=Funkce_znamenka.Object_set_plus, relief=GROOVE, bg="white") Object_Button_plus.grid(row=6, column=0, sticky=EW) Object_Button_minus = Button(ObjectWindow, text="-", command=Funkce_znamenka.Object_set_minus, relief=GROOVE, bg="white") Object_Button_minus.grid(row=6, column=1, sticky=EW) Object_Button_power = Button(ObjectWindow, text="**", command=Funkce_znamenka.Object_set_power, relief=GROOVE, bg="white") Object_Button_power.grid(row=6, column=2, sticky=EW) Object_Button_cos = Button(ObjectWindow, text="cos", command=Funkce_goniometricke.Object_set_cos, relief=GROOVE, bg="white") Object_Button_cos.grid(row=8, column=1, sticky=EW) Object_Button_leftside = Button(ObjectWindow, text="(", command=Funkce_znamenka.Object_set_leftside, relief=GROOVE, bg="white") Object_Button_leftside.grid(row=8, column=2, sticky=EW) Object_Button_rightside = Button(ObjectWindow, text=")", command=Funkce_znamenka.Object_set_rightside, relief=GROOVE, bg="white") Object_Button_rightside.grid(row=9, column=2, sticky=EW) Object_Button_sin = Button(ObjectWindow, text="sin", command=Funkce_goniometricke.Object_set_sin, relief=GROOVE, bg="white") Object_Button_sin.grid(row=8, column=0, sticky=EW) Object_Button_tan = Button(ObjectWindow, text="tg", command=Funkce_goniometricke.Object_set_tan, relief=GROOVE, bg="white") Object_Button_tan.grid(row=9, column=0, sticky=EW) Object_Button_cotg = Button(ObjectWindow, text="cotg", command=Funkce_goniometricke.Object_set_cotg, relief=GROOVE, bg="white") Object_Button_cotg.grid(row=9, column=1, sticky=EW) Object_Button_Refresh = Button(ObjectWindow, text="Refresh", command=Funkce_vedlejsi.Action_Refresh, relief=GROOVE, bg="white") Object_Button_Refresh.grid(row=10, column=2, sticky=EW) Object_Button_Konec = Button(ObjectWindow, text="Konec", command=Funkce_vedlejsi.Action_Konec, relief=GROOVE, bg="white") Object_Button_Konec.grid(row=14, column=11, sticky=EW) Object_Button_multiply = Button(ObjectWindow, text="*", command=Funkce_znamenka.Object_set_multiply, relief=GROOVE, bg="white") Object_Button_multiply.grid(row=5, column=2, sticky=EW) Object_Button_Do_it = Button(ObjectWindow, text="=", command=Funkce_vedlejsi.Action_do_it, relief=GROOVE, fg="red",bg="white",) Object_Button_Do_it.grid(row=10, column=0, columnspan = 2, sticky=EW) Object_Button_kvad_rce = Button(ObjectWindow, text="Vypočítat", command=Funkce_vypocetni.function_kvad_rce, relief=GROOVE, fg="red",bg="white",) Object_Button_kvad_rce.grid(row=14, column=8, sticky=EW) Object_Button_graph_sinus = Button(ObjectWindow, text="Zobrazit sinus", command=Funkce_grafy.function_graph_sinus, relief=GROOVE, fg="red",bg="white",) Object_Button_graph_sinus.grid(row=2, column=11, sticky=EW) Object_Button_graph_cosinus = Button(ObjectWindow, text="Zobrazit cosinus", command=Funkce_grafy.function_graph_cosinus, relief=GROOVE, fg="red",bg="white",) Object_Button_graph_cosinus.grid(row=3, column=11, sticky=EW) Object_Button_graph_tangens = Button(ObjectWindow, text="Vizualizace tg", command=Funkce_grafy.function_graph_tangens, relief=GROOVE, fg="red",bg="white",) Object_Button_graph_tangens.grid(row=4, column=11, sticky=EW) Object_Button_graph_tangens = Button(ObjectWindow, text="Vizualizace arctg", command=Funkce_grafy.function_graph_arctg, relief=GROOVE, fg="red",bg="white",) Object_Button_graph_tangens.grid(row=5, column=11, sticky=EW) Label(text="Převodník DEC -> BIN").grid(row=11, column=0, columnspan=2, sticky=W) decimal = StringVar() binary = StringVar() decimal_entry = Entry(ObjectWindow, width = 16, textvariable = decimal) decimal_entry.grid(column = 1, row = 12, columnspan=2, sticky = W) Label(ObjectWindow, textvariable = binary).grid(column = 2, row = 15, sticky = W) Button(ObjectWindow, text = "Převést", command = Funkce_vypocetni.function_Dec_to_Bin, relief=GROOVE, fg="red",bg="white",).grid(column = 1, row = 14, sticky = EW) Label(ObjectWindow, justify=LEFT, text = 'Dekadicky:').grid(column = 0, row = 12, columnspan = 2, sticky = W) Label(ObjectWindow, justify=LEFT, text = 'Binárně:').grid(column = 0, row = 13, sticky = W) binresult=Label(ObjectWindow, text=" ", background="white", fg="red",relief=GROOVE) binresult.grid(row=13, column=1,columnspan = 3, sticky=W) Label(text="Součet a grafické zobrazení dvou vektorů:").grid(row=1, column=5, columnspan=10, sticky=W) Label(text="A [").grid(row=2, column=5, sticky=W) Label(text="B [").grid(row=3, column=5, sticky=W) Label(text=";").grid(row=2, column=7, sticky=W) Label(text=";").grid(row=3, column=7, sticky=W) Label(text="]").grid(row=2, column=9, sticky=W) Label(text="]").grid(row=3, column=9, sticky=W) bodAx=Entry(justify=CENTER) bodAx.config(width=20,fg="red",bg="white",font=20) bodAx.grid(row=2,column=6,padx="10",pady="10") bodAx.insert(999,"3") bodAy=Entry(justify=CENTER) bodAy.config(width=20,fg="red",bg="white",font=20) bodAy.grid(row=2,column=8,padx="10",pady="10") bodAy.insert(999,"2") bodBx=Entry(justify=CENTER) bodBx.config(width=20,fg="red",bg="white",font=20) bodBx.grid(row=3,column=6,padx="10",pady="10") bodBx.insert(999,"5") bodBy=Entry(justify=CENTER) bodBy.config(width=20,fg="red",bg="white",font=20, relief=SUNKEN) bodBy.grid(row=3,column=8,padx="10",pady="10") bodBy.insert(999,"1") soucet=Button(text="Vektorový součet",command=Funkce_vypocetni.function_soucet, fg="red",bg="white", relief=GROOVE) soucet.grid(row=4, column=6, sticky=EW) soucin=Button(text="Vektorový součin (skalární)",command=Funkce_vypocetni.function_soucin, fg="red",bg="white", relief=GROOVE) soucin.grid(row=4, column=8, sticky=EW) Label(text="Výpočet kořenů kvadratické rovnice:").grid(row=6, column=5, columnspan=10, sticky=W) kvad=Entry(justify=CENTER) kvad.config(width=20,fg="red",bg="white",font=20) kvad.grid(row=8,column=8,padx="10",pady="10") kvad.insert(999,"1") lin=Entry(justify=CENTER) lin.config(width=20,fg="red",bg="white",font=20) lin.grid(row=9,column=8,padx="10",pady="10") lin.insert(999,"4") absol=Entry(justify=CENTER) absol.config(width=20,fg="red",bg="white",font=20) absol.grid(row=10,column=8,padx="10",pady="10") absol.insert(999,"3") Label(text="Kvadratický člen:").grid(row=8, column=6, sticky=E) Label(text="Lineární člen:").grid(row=9, column=6, sticky=E) Label(text="Absolutní člen:").grid(row=10, column=6, sticky=E) Label(text="Kořen #1:").grid(row=11, column=6, sticky=E) Label(text="Kořen #2:").grid(row=12, column=6, sticky=E) kvadresult=Label(ObjectWindow, text=" ", background="white", fg="red",relief=GROOVE) kvadresult.grid(row=11, column=8, padx=2, pady=2, sticky=W) kvadresult2=Label(ObjectWindow, text=" ", background="white", fg="red",relief=GROOVE) kvadresult2.grid(row=12, column=8, padx=2, pady=2, sticky=W) Label(text="Zobrazení grafů funkcí na základě oboru hodnot:").grid(row=1, column=10, columnspan = 3, sticky=W) oborhodnotSIN=Entry(justify=CENTER) oborhodnotSIN.config(width=20,fg="red",bg="white",font=20) oborhodnotSIN.grid(row=2,column=10,padx="10",pady="10") oborhodnotSIN.insert(999,"2") oborhodnotCOS=Entry(justify=CENTER) oborhodnotCOS.config(width=20,fg="red",bg="white",font=20) oborhodnotCOS.grid(row=3,column=10,padx="10",pady="10") oborhodnotCOS.insert(999,"2") instance = GUI() ObjectWindow.mainloop()
<?php // common.php
$username = "root";
$password = "";
$host = "localhost";
$dbname = "pdo";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
die("Nepodařilo se připojit k databázi: " . $ex->getMessage());
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
header('Content-Type: text/html; charset=utf-8');
session_start();
<?php // login.php
require("common.php");
$submitted_username = '';
if(!empty($_POST))
{
$query = "
SELECT
id,
username,
password,
salt,
email
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$login_ok = false;
$row = $stmt->fetch();
if($row)
{
$check_password = hash('sha256', $_POST['password'] . $row['salt']);
for($round = 0; $round < 65536; $round++)
{
$check_password = hash('sha256', $check_password . $row['salt']);
}
if($check_password === $row['password'])
{
$login_ok = true;
}
}
if($login_ok)
{
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
header("Location: private.php");
die("Redirecting to: private.php");
}
else
{
print("Login Failed.");
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}
}
?>
<?php
header('Content-Type: text/html; charset=cp1250');
?>
<h1>Přihlášení</h1>
<form action="login.php" method="post">
Jméno:<br />
<input type="text" name="username" value="<?php echo $submitted_username; ?>" />
<br /><br />
Heslo::<br />
<input type="password" name="password" value="" />
<br /><br />
<input type="submit" value="Přihlásit" />
</form>
<a href="register.php">Registrace</a>
<?php // register.php
require("common.php");
if(!empty($_POST))
{
if(empty($_POST['username']))
{
die("Napište uživatelské jménno..");
}
if(empty($_POST['password']))
{
die("Napište heslo.");
}
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
die("Neplatný email.");
}
$query = "
SELECT
1
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Dotaz nebyl vykonán: " . $ex->getMessage());
}
$row = $stmt->fetch();
if($row)
{
die("Toto uživatelské jméno je již používáno.");
}
$query = "
SELECT
1
FROM users
WHERE
email = :email
";
$query_params = array(
':email' => $_POST['email']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Dotaz nebyl vykonán: " . $ex->getMessage());
}
$row = $stmt->fetch();
if($row)
{
die("Tato emailová adresa je již v databázi.");
}
$query = "
INSERT INTO users (
username,
password,
salt,
email
) VALUES (
:username,
:password,
:salt,
:email
)
";
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$password = hash('sha256', $_POST['password'] . $salt);
for($round = 0; $round < 65536; $round++)
{
$password = hash('sha256', $password . $salt);
}
$query_params = array(
':username' => $_POST['username'],
':password' => $password,
':salt' => $salt,
':email' => $_POST['email']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Dotaz nebyl vykonán: " . $ex->getMessage());
}
header("Location: login.php");
die("Redirecting to login.php");
}
?>
<?php
header('Content-Type: text/html; charset=cp1250');
?>
<h1>Registrace</h1>
<form action="register.php" method="post">
Jméno:<br />
<input type="text" name="username" value="" />
<br /><br />
E-Mail:<br />
<input type="text" name="email" value="" />
<br /><br />
Heslo:<br />
<input type="password" name="password" value="" />
<br /><br />
<input type="submit" value="Registrovat" />
</form>
<?php // logout.php
require("common.php");
unset($_SESSION['user']);
header("Location: login.php");
die("Redirecting to: login.php");
<?php // edit_account.php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
if(!empty($_POST))
{
if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
die("Špatná emailová adresa.");
}
if($_POST['email'] != $_SESSION['user']['email'])
{
$query = "
SELECT
1
FROM users
WHERE
email = :email
";
$query_params = array(
':email' => $_POST['email']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Dotaz nebyl vykonán: " . $ex->getMessage());
}
$row = $stmt->fetch();
if($row)
{
die("Tato emailová adresa je již používána.");
}
}
if(!empty($_POST['password']))
{
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
$password = hash('sha256', $_POST['password'] . $salt);
for($round = 0; $round < 65536; $round++)
{
$password = hash('sha256', $password . $salt);
}
}
else
{
$password = null;
$salt = null;
}
$query_params = array(
':email' => $_POST['email'],
':user_id' => $_SESSION['user']['id'],
);
if($password !== null)
{
$query_params[':password'] = $password;
$query_params[':salt'] = $salt;
}
$query = "
UPDATE users
SET
email = :email
";
if($password !== null)
{
$query .= "
, password = :password
, salt = :salt
";
}
$query .= "
WHERE
id = :user_id
";
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Dotaz nebyl vykonán: " . $ex->getMessage());
}
$_SESSION['user']['email'] = $_POST['email'];
header("Location: private.php");
die("Redirecting to private.php");
}
?>
<?php
header('Content-Type: text/html; charset=cp1250');
?>
<h1>Editovat účet</h1>
<form action="edit_account.php" method="post">
Jméno:<br />
<b><?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?></b>
<br /><br />
E-Mail:<br />
<input type="text" name="email" value="<?php echo htmlentities($_SESSION['user']['email'], ENT_QUOTES, 'UTF-8'); ?>" />
<br /><br />
Heslo:<br />
<input type="password" name="password" value="" /><br />
<i></i>
<br /><br />
<input type="submit" value="Aktualizovat" />
</form>
<?php // memberlist.php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
$query = "
SELECT
id,
username,
email
FROM users
";
try
{
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Dotaz nebyl zpracován: " . $ex->getMessage());
}
$rows = $stmt->fetchAll();
?>
<?php
header('Content-Type: text/html; charset=cp1250');
?>
<h1>Seznam</h1>
<table>
<tr>
<th>ID</th>
<th>Jméno</th>
<th>E-Mail</th>
</tr>
<?php foreach($rows as $row): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo htmlentities($row['username'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['email'], ENT_QUOTES, 'UTF-8'); ?></td>
</tr>
<?php endforeach; ?>
</table>
<a href="private.php">Zpět</a><br />
<?php // private.php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
?>
Ahoj <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>, toto je skrytý obsah!<br />
<?php
header('Content-Type: text/html; charset=cp1250');
?>
<a href="memberlist.php">Seznam uživatelů</a><br />
<a href="edit_account.php">Editovat účet</a><br />
<a href="#">Geolokace</a><br />
<a href="#">Formulář localstorage</a><br />
<a href="logout.php">Oshlásit se</a>
-----
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL,
`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` char(64) COLLATE utf8_unicode_ci NOT NULL,
`salt` char(16) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
INSERT INTO `users` (`id`, `username`, `password`, `salt`, `email`) VALUES
(1, 'kimi', '415fba3105beb41c321184b269e7e5ff0f36b931e0687fbcb4c9c026528bfea6', '593530d42b5773a0', 'patrik@email.cz'),
(2, 'admin', 'c4ca907b87f644240af26657db256806cfb398a52bc632c37e8c47098fed613c', '4a61515e7172a87b', 'admin@admin.com'),
(3, 'spse', 'b27a6e32055ade097438b8eac0efad60e1e557e7b8e1106afb1d1fe9aa6b0073', '72635b246038429a', 'spse@krizik.cz');
-----
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="cp1250">
<title>geolokace</title>
</head>
<html>
<body onload="getLocation()">
<p id="error"></p>
<p id="position"></p>
<p id="accuracy"></p>
<script type="text/javascript">
function showLocation(position) {
var accuracy = position.coords.accuracy;
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById("position").innerHTML = "<b>Aktuálnà poloha:</b> " + latitude + ", " + longitude;
document.getElementById("accuracy").innerHTML = "<b>Přesnost polohy:</b> " + accuracy + " m."
}
function errorHandler(error) {
switch (error.code) {
case 1:
document.getElementById("error").innerHTML = "Chyba: PĹ™Ăstup byl odepøen.";
break;
case 2:
document.getElementById("error").innerHTML = "Chyba: Poloha nenĂ k dispozici.";
break;
case 3:
document.getElementById("error").innerHTML = "Chyba: Vypršel časový limit.";
break;
default:
document.getElementById("error").innerHTML = "Chyba: " + error.message;
break;
}
}
function getLocation(){
if (navigator.geolocation) {
var options = {timeout:60000};
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
} else {
document.getElementById("error").innerHTML = "Podpora pro geolokaci nenà dostupná.";
}
}
</script>
<div ><div>Vyzkoušejte nový webhosting <a href="http://b.cz/">b.cz</a>. Nejkratší doména 2. řádu na českém trhu.</div></div></body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="windows-1250">
<script>
function ulozit()
{
if(typeof(Storage)!=="undefined"){
var jmeno = document.getElementById("FirstName").value;
var prijmeni = document.getElementById("LastName").value;
var heslo = document.getElementById("Password").value;
localStorage.FirstName = jmeno;
localStorage.LastName = prijmeni;
localStorage.Password = heslo;
document.getElementById("FirstName").value = localStorage.getItem("FirstName");
document.getElementById("zapsano").innerHTML="Data byla uložena do localstorage :)";
}else{
document.getElementById("chyba").innerHTML="Váš prohlížeč nepodporuje localstorage!";
}
}
function nacist(){
if (localStorage) {
document.getElementById('FirstName').value = localStorage.FirstName;
document.getElementById('LastName').value = localStorage.LastName;
document.getElementById('Password').value = localStorage.Password;
document.getElementById('status').innerHTML = '<p>Formulář byl načten z lokálního úložiště.</p>';
}
else{
alert('Váš prohlížeč bohužel nepodporuje místní úložiště');
}
}
</script>
<STYLE>
body {
font-family: "Trebuchet MS", "Verdana", sans-serif;
}
table {
border-color:#754F1D;
}
td {
padding: 4px 10px;
}
caption {
font-weight: bold;
color: black;
padding-bottom: 15px;
}
.pole {
background: rgb(51,204,204);
}
.data {
background: #F0E7DB;
}
.pozadi {
background: #F3D9B7
}
.sloupec {
text-align: center;
background: rgb(51,204,204);
}
tbody {
text-align: center;
}
</STYLE>
</head>
<body>
<table cellspacing="0" border="4" frame="void" rules="groups">
<caption align="top">Formulář s ukládáním dat do localstorage</caption>
<colgroup class="pole" >
<colgroup span="3" class="data" >
<col span="2">
<col class="pozadi" >
</colgroup>
<thead class="sloupec">
<tr>
<td></td>
<td>Formulář</td>
</tr>
</thead>
<tbody>
<tr>
<td>Jméno:</td>
<td><input type="text" id="FirstName" value=""></td>
</tr>
<tr>
<td>Příjmení:</td>
<td><input type="text" id="LastName" value=""><br></td>
<tr>
<td>Heslo:</td>
<td><input type="text" id="Password" value=""></td>
</tr>
<tr>
<td>Akce</td>
<td><p><button onclick="ulozit();" type="button">Zpracovat</button></p>
<p><button onclick="nacist();" type="button">Načíst</button></p></td>
</tr>
</tbody>
</table>
<div id="zapsano"></div>
<div id="chyba"></div>
<div id="status"></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>My first styled page</title>
<style type="text/css">
body {
padding-left: 11em;
font-family: Georgia, "Times New Roman",
Times, serif;
color: purple;
background-color: #d8da3d }
ul.navbar {
list-style-type: none;
padding: 0;
margin: 0;
position: absolute;
top: 2em;
left: 1em;
width: 9em }
h1 {
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif }
ul.navbar li {
background: white;
margin: 0.5em 0;
padding: 0.3em;
border-right: 1em solid black }
ul.navbar a {
text-decoration: none }
a:link {
color: blue }
a:visited {
color: purple }
address {
margin-top: 1em;
padding-top: 1em;
border-top: thin dotted }
</style>
</head>
<body>
<!-- Site navigation menu -->
<ul class="navbar">
<li><a href="#">menu#1</a>
<li><a href="#">menu#2</a>
<li><a href="#">menu#3</a>
<li><a href="#">menu#4</a>
</ul>
<!-- Main content -->
<h1>Nadpis</h1>
<p>Vitej
<p>obsah
<!-- Sign and date the page, it's only polite! -->
<address>footer</address>
</body>
</html>