From 8065ab134d45a064140b00243b233f67a3fb4caa Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Thu, 13 Apr 2023 17:39:50 +0200 Subject: [PATCH] mail func added, post route added, more css --- css/projects.css | 4 +++- index.php | 9 +++++--- libraries/console.php | 9 ++++++++ libraries/mail.php | 31 ++++++++++++++++++++++++++++ libraries/router.php | 15 ++++++++------ pages/contact/contact.php | 43 +++++++++++++++++++++++++++++++++++++-- 6 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 libraries/console.php create mode 100644 libraries/mail.php diff --git a/css/projects.css b/css/projects.css index 87605d7..45fae89 100644 --- a/css/projects.css +++ b/css/projects.css @@ -18,6 +18,8 @@ .card { display: flex; border: 1px solid red; + border-radius: 15px; + box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px; width: min(40rem, calc(100% - 1rem)); } @@ -40,7 +42,7 @@ .technologies { display: flex; gap: 1rem; - margin-right: auto; + flex-wrap: wrap; } .technologies span { diff --git a/index.php b/index.php index f438086..52c71d9 100644 --- a/index.php +++ b/index.php @@ -3,6 +3,7 @@ session_start(); $prod = false; require_once("./libraries/router.php"); +require_once("./libraries/console.php"); // Display Errors ini_set('display_startup_errors', 1); @@ -70,9 +71,11 @@ if($prod) { ?>
route('/', 'home'); - $R->route('/home', 'home'); - $R->route('/domu', 'home'); + $R->route('GET', '/', 'home'); + $R->route('GET', '/home', 'home'); + $R->route('GET', '/domu', 'home'); + + $R->route('POST', '/contact/send', 'contact'); $R = null; ?> diff --git a/libraries/console.php b/libraries/console.php new file mode 100644 index 0000000..8948e28 --- /dev/null +++ b/libraries/console.php @@ -0,0 +1,9 @@ +console.log('Debug Objects: " . $output . "' );"; +} diff --git a/libraries/mail.php b/libraries/mail.php new file mode 100644 index 0000000..3eab640 --- /dev/null +++ b/libraries/mail.php @@ -0,0 +1,31 @@ +from = $from; + $this->to = $to; + $this->subject = $subject; + $this->headers = $headers; + } + + public function send() { + // odeslání e-mailu + $headers = 'From: noreply@fofrweb.com' . "\r\n" . + 'Reply-To: support@fofrweb.com' . "\r\n" . + 'X-Mailer: PHP/' . phpversion(); + $this->headers = $headers; + + if (gettype($this->message) == 'string') { + if(mail($this->to, $this->subject, $this->message, $this->headers)) { + return 0; + } else { + return 1; + } + } + } +} diff --git a/libraries/router.php b/libraries/router.php index 460f731..a7c5a22 100644 --- a/libraries/router.php +++ b/libraries/router.php @@ -2,12 +2,15 @@ class Router { public $returned = false; - function route($url, $filename) { - if($_SERVER['REQUEST_METHOD'] == 'GET') { - if ($_SERVER['REQUEST_URI'] == $url) { - require_once("./pages/$filename/$filename.php"); - $this->returned = true; - return; + function route($method, $url, $filename) { + $methods = ['GET', 'POST']; + if(in_array($method, $methods)) { + if($_SERVER['REQUEST_METHOD'] == $method) { + if ($_SERVER['REQUEST_URI'] == $url) { + require_once("./pages/$filename/$filename.php"); + $this->returned = true; + return; + } } } } diff --git a/pages/contact/contact.php b/pages/contact/contact.php index 8256b3d..9dce6f9 100644 --- a/pages/contact/contact.php +++ b/pages/contact/contact.php @@ -1,7 +1,7 @@

Kontaktujte mě

-
+ @@ -11,6 +11,45 @@ - +
+ + +send()) { + header('Location: /?sent=true'); + } else { + echo "

Něco se nepovedlo, zkuste to znovu... :(

"; + echo "Zpět"; + } +}