generated from teknasyon-bootcamp/homework5
-
Notifications
You must be signed in to change notification settings - Fork 4
/
post-create.php
79 lines (64 loc) · 2.1 KB
/
post-create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require "vendor/autoload.php";
$config = require "config.php";
$engine = $config['engine'];
$host = $config['host'];
$user = $config['user'];
$pass = $config['password'];
$log_type = $config['logging'];
$log_file_dir = __DIR__."/storage/logs/logs.log";
use App\DB\Engine\Mysql;
use App\DB\Engine\MongoDB;
use App\Db\Database;
use App\Logger\Driver\Database as LoggerDatabase;
use App\Logger\Driver\File;
use App\Logger\Logger;
use App\Logger\LoggableInterface;
if ($engine == "mysql") {
$driver = new Mysql($host, $user, $pass, "book_app");
} elseif ($engine =="mongodb") {
$driver = new MongoDB("", "", "", "", "", []);
}
if($log_type =="file"){
$logger = new Logger(new File($log_file_dir));
}else{
$logger = new Logger(new LoggerDatabase($driver));
}
try{
$db = new Database();
$db->setDriver($driver);
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
if (isset($_GET['post'])){
$post = $_GET['post'];
$book_id = $_GET['id'];
try{
$is_created = $db->create("posts",[["post"=>$post, "bookId" => $book_id]]);
}catch (Exception $e){
$logger->log($e, LoggableInterface::ERROR);
}
}
?>
<?php include "_shared/header.php";?>
<?php
if(isset($is_created)){
echo "<p class='text-center alert-success'>Post başarıyla oluşturuldu</p>";
echo "<br>";
echo "<div class='d-flex justify-content-center'><a href='http://localhost/homework5-hw5_grup3/index.php' class='btn btn-primary mt-5'>Anasayfaya geri dön</a></div>";
}
?>
<div class="container">
<h1>Kitap İçin Post Oluştur</h1>
<form action='post-create.php' method='GET'>
<div class='form-group'>
<div >
<input type="hidden" name="id" value='<?=$_GET['id']??'' ?>'>
<label for='post'>Post</label>
<textarea name="post" rows="10" cols="100" style="resize: none" class='form-control'></textarea>
</div>
<button class = 'btn btn-primary mt-3'>Gönder</button>
</div>
</form>
</div>
<?php include "_shared/footer.php";?>