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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<?php
class App
{
private $bdd;
private $admin;
private $secure;
public function __construct($config)
{
$this->admin = $config['admin'];
$this->secure = $config['secure'];
try {
$this->bdd = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'] . ';charset=utf8', $config['user'], $config['password']);
} catch (Exeption $e) {
die('Erreur : ' . $e->getMessage());
}
}
public function add(Art $art)
{
if ($this->exist($art->id())) {
echo '<h4>cet id existe deja</h4>';
} else {
$now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
$q = $this->bdd->prepare('INSERT INTO art(id, titre, soustitre, intro, tag, datecreation, datemodif, css, html, secure, couleurtext, couleurbkg, couleurlien, couleurlienblank) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien, :couleurlienblank)');
$q->bindValue(':id', $art->id());
$q->bindValue(':titre', $art->titre());
$q->bindValue(':soustitre', $art->soustitre());
$q->bindValue(':intro', $art->intro());
$q->bindValue(':tag', $art->tag('string'));
$q->bindValue(':datecreation', $now->format('Y-m-d H:i:s'));
$q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
$q->bindValue(':css', $art->css());
$q->bindValue(':html', $art->html('md'));
$q->bindValue(':secure', $art->secure());
$q->bindValue(':couleurtext', $art->couleurtext());
$q->bindValue(':couleurbkg', $art->couleurbkg());
$q->bindValue(':couleurlien', $art->couleurlien());
$q->bindValue(':couleurlienblank', $art->couleurlienblank());
$q->execute();
}
}
public function delete(Art $art)
{
$req = $this->bdd->prepare('DELETE FROM art WHERE id = :id ');
$req->execute(array('id' => $art->id()));
$req->closeCursor();
}
public function get($id)
{
$req = $this->bdd->prepare('SELECT * FROM art WHERE id = :id ');
$req->execute(array('id' => $id));
$donnees = $req->fetch(PDO::FETCH_ASSOC);
return new Art($donnees);
$req->closeCursor();
}
public function getlister()
{
$list = [];
$req = $this->bdd->query('SELECT * FROM art ORDER BY id');
while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
$list[] = new Art($donnees);
}
return $list;
}
public function lister()
{
$req = $this->bdd->query('SELECT * FROM art ORDER BY id');
$donnees = $req->fetchAll(PDO::FETCH_ASSOC);
return $donnees;
$req->closeCursor();
}
public function count()
{
return $this->bdd->query(' SELECT COUNT(*) FROM art ')->fetchColumn();
}
public function exist($id)
{
$req = $this->bdd->prepare(' SELECT COUNT(*) FROM art WHERE id = :id ');
$req->execute(array('id' => $id));
$donnees = $req->fetch(PDO::FETCH_ASSOC);
return (bool)$donnees['COUNT(*)'];
}
public function update(Art $art)
{
$now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
$q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien, couleurlienblank = :couleurlienblank WHERE id = :id');
$q->bindValue(':id', $art->id());
$q->bindValue(':titre', $art->titre());
$q->bindValue(':soustitre', $art->soustitre());
$q->bindValue(':intro', $art->intro());
$q->bindValue(':tag', $art->tag('string'));
$q->bindValue(':datecreation', $art->datecreation('string'));
$q->bindValue(':datemodif', $now->format('Y-m-d H:i:s'));
$q->bindValue(':css', $art->css());
$q->bindValue(':html', $art->html('md'));
$q->bindValue(':secure', $art->secure());
$q->bindValue(':couleurtext', $art->couleurtext());
$q->bindValue(':couleurbkg', $art->couleurbkg());
$q->bindValue(':couleurlien', $art->couleurlien());
$q->bindValue(':couleurlienblank', $art->couleurlienblank());
$q->execute();
}
//_________________________________________________________ S E S ________________________________________________________
public function login($pass)
{
if (strip_tags($pass) == $this->admin) {
var_dump($this->admin);
return $level = 2;
} elseif (strip_tags($pass) == $this->secure) {
return $level = 1;
}
}
public function logout()
{
return $level = 0;
}
}
?>
|