aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-03-18 03:48:04 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-03-18 03:48:04 +0100
commit2060e198b1f9ac41deee93848417121fb1c066f5 (patch)
treeff3abf3f4af68cef081d19f3aa935079bdf25ad6
parent3650a038f0a6c99d52723e9567d5f173c4398c3a (diff)
downloadwcms-2060e198b1f9ac41deee93848417121fb1c066f5.tar.gz
wcms-2060e198b1f9ac41deee93848417121fb1c066f5.zip
classes fonctionnelles
-rw-r--r--class/class.app.php35
-rw-r--r--class/class.art.php342
-rw-r--r--fn/fn.php4
-rw-r--r--public/css/style.css15
-rw-r--r--public/rsc/css/style.css0
-rw-r--r--public/w/index.php117
6 files changed, 336 insertions, 177 deletions
diff --git a/class/class.app.php b/class/class.app.php
index d9867d3..ad62c25 100644
--- a/class/class.app.php
+++ b/class/class.app.php
@@ -1,4 +1,3 @@
-<h4>class.app</h4>
<?php
class App
{
@@ -23,7 +22,7 @@ class App
{
if ($this->exist($art->id())) {
- echo '<p>cet id existe deja</p>';
+ echo '<h4>cet id existe deja</h4>';
} else {
$now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
@@ -72,21 +71,36 @@ class App
$list = [];
$req = $this->bdd->query('SELECT * FROM art ORDER BY id');
- while ($donnees = $req->fetch(PDO::FETCH_ASSOC))
- {
- $list[] = new Art($donnees);
+ while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
+ $list[] = new Art($donnees);
}
return $list;
}
+ public function menu($session)
+ {
+ $req = $this->bdd->query('SELECT * FROM art ORDER BY id');
+ echo '<ul>';
+ while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) {
+ echo '<li><a href="?id=' . $donnees['id'] . '&display=1">' . $donnees['titre'] . '</a> - ' . $donnees['intro'];
+ if ($session >= 2) {
+ echo ' - <a href="?id=' . $donnees['id'] . '&edit=1">modifier</a></li>';
+ } else {
+ echo '</li>';
+ }
+ }
+ echo ' </ul> ';
+
+ }
+
public function count()
{
- return $this->bdd->query('SELECT COUNT(*) FROM art')->fetchColumn();
+ 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 = $this->bdd->prepare(' SELECT COUNT(*) FROM art WHERE id = :id ');
$req->execute(array('id' => $id));
$donnees = $req->fetch(PDO::FETCH_ASSOC);
@@ -98,17 +112,17 @@ class App
$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 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());
- $q->bindValue(':datecreation', $art->datecreation()->format('Y-m-d H:i:s'));
+ $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());
- $q->bindValue(':secure', $art->secure(), PDO::PARAM_INT);
+ $q->bindValue(':secure', $art->secure());
$q->bindValue(':couleurtext', $art->couleurtext());
$q->bindValue(':couleurbkg', $art->couleurbkg());
$q->bindValue(':couleurlien', $art->couleurlien());
@@ -116,6 +130,5 @@ class App
$q->execute();
}
-
}
?> \ No newline at end of file
diff --git a/class/class.art.php b/class/class.art.php
index ec085d8..bf2aeef 100644
--- a/class/class.art.php
+++ b/class/class.art.php
@@ -1,4 +1,3 @@
-<h4>class.art</h4>
<?php
class Art
@@ -21,9 +20,10 @@ class Art
private static $lenhtml = 65535;
private static $securemax = 2;
private static $lencouleur = 7;
+ private static $edit = 2;
- // _____________________________________________________ F U N ____________________________________________________
+// _____________________________________________________ F U N ____________________________________________________
public function __construct(array $donnees)
{
@@ -41,175 +41,273 @@ class Art
}
}
- // _____________________________________________________ G E T ____________________________________________________
-
- public function id()
+ public function default()
{
- return $this->id;
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+
+ $this->settitre($this->id());
+ $this->setsoustitre($this->id());
+ $this->setintro('resumé');
+ $this->settag('sans tag,');
+ $this->setdatecreation($now);
+ $this->setcss('display: inline;');
+ $this->sethtml('contenu');
+ $this->setsecure(2);
+ $this->setcouleurtext('#000000');
+ $this->setcouleurbkg('#FFFFFF');
+ $this->setcouleurlien('#000000');
}
- public function titre()
+ public function edit($session)
{
- return $this->titre;
- }
+ if ($session >= self::$edit) {
+
+ ?>
+ <article>
+ <form class="edit" action="?id=<?= $this->id() ?>" method="post">
+ <label for="titre">Titre :</label>
+ <input type="text" name="titre" id="titre" value="<?= $this->titre(); ?>">
+ <label for="soustitre">Sous-titre :</label>
+ <input type="text" name="soustitre" id="soustitre" value="<?= $this->soustitre(); ?>">
+ <label for="intro">Introduction :</label>
+ <input type="text" name="intro" id="intro" value="<?= $this->intro(); ?>">
+ <label for="tag">Tag(s) :</label>
+ <input type="text" name="tag" id="tag" value="<?= $this->tag(); ?>">
+ <label for="css">Styles CSS :</label>
+ <input type="text" name="css" id="css" value="<?= $this->css(); ?>">
+ <label for="secure">Niveau de sécuritée :</label>
+ <select name="secure" id="secure">
+ <option value="0" <?= $this->secure() == 0 ? 'selected' : '' ?>>0</option>
+ <option value="1" <?= $this->secure() == 1 ? 'selected' : '' ?>>1</option>
+ <option value="2" <?= $this->secure() == 2 ? 'selected' : '' ?>>2</option>
+ </select>
+ <label for="couleurtext">Couleur du texte :</label>
+ <input type="color" name="couleurtext" value="<?= $this->couleurtext() ?>" id="couleurtext">
+ <label for="couleurbkg">Couleur de l'arrière plan :</label>
+ <input type="color" name="couleurbkg" value="<?= $this->couleurbkg() ?>" id="couleurbkg">
+ <label for="couleurlien">Couleur des liens :</label>
+ <input type="color" name="couleurlien" value="<?= $this->couleurlien() ?>" id="couleurlien">
+ <label for="html">Contenu :</label>
+ <textarea name="html" id="html" ><?= $this->html(); ?></textarea>
+ <input type="hidden" name="datecreation" value="<?= $this->datecreation('string'); ?>">
+ <input type="hidden" name="id" value="<?= $this->id() ?>">
+ <input type="hidden" name="action" value="update">
+ <input type="submit" value="modifier">
+ </form>
+ </article>
+
+ <?php
- public function soustitre()
- {
- return $this->soustitre;
- }
+}
- public function intro()
- {
- return $this->intro;
- }
+}
- public function tag()
- {
- return $this->tag;
- }
+public function display($session)
+{
+ if ($session >= $this->secure()) {
- public function datecreation()
- {
+ ?>
+ <style>
+ article {
+ background: <?= $this->couleurbkg() ?>;
+ color: <?= $this->couleurtext() ?>;
+ }
+
+ a {
+ color: <?= $this->couleurlien() ?>;
+ }
+ <?= $this->css() ?>
+ </style>
+ <article>
+ <h1><?= $this->titre() ?></h1>
+ <h2><?= $this->soustitre() ?></h2>
+ <h3><?= $this->intro() ?></h3>
+ <p><?= $this->html() ?></p>
+ </article>
+ <?php
+
+}
+
+}
+
+ // _____________________________________________________ G E T ____________________________________________________
+
+public function id()
+{
+ return $this->id;
+}
+
+public function titre()
+{
+ return $this->titre;
+}
+
+public function soustitre()
+{
+ return $this->soustitre;
+}
+
+public function intro()
+{
+ return $this->intro;
+}
+
+public function tag()
+{
+ return $this->tag;
+}
+
+public function datecreation($option) {
+ if ($option == 'string') {
+ return $this->datecreation->format('Y-m-d H:i:s');
+ } elseif($option == 'date') {
return $this->datecreation;
}
+}
- public function datemodif()
- {
+
+public function datemodif($option) {
+ if ($option == 'string') {
+ return $this->datemodif->format('Y-m-d H:i:s');
+ } elseif($option == 'date') {
return $this->datemodif;
}
+}
- public function css()
- {
- return $this->css;
- }
+public function css()
+{
+ return $this->css;
+}
- public function html()
- {
- return $this->html;
- }
+public function html()
+{
+ return $this->html;
+}
- public function secure()
- {
- return $this->secure;
- }
+public function secure()
+{
+ return $this->secure;
+}
- public function couleurtext()
- {
- return $this->couleurtext;
- }
+public function couleurtext()
+{
+ return $this->couleurtext;
+}
- public function couleurbkg()
- {
- return $this->couleurbkg;
- }
+public function couleurbkg()
+{
+ return $this->couleurbkg;
+}
- public function couleurlien()
- {
- return $this->couleurlien;
- }
+public function couleurlien()
+{
+ return $this->couleurlien;
+}
- // _____________________________________________________ S E T ____________________________________________________
+ // _____________________________________________________ S E T ____________________________________________________
- public function setid($id)
- {
- if (strlen($id) < self::$len and is_string($id)) {
- $this->id = strip_tags(strtolower(str_replace(" ", "", $id)));
- }
+public function setid($id)
+{
+ if (strlen($id) < self::$len and is_string($id)) {
+ $this->id = strip_tags(strtolower(str_replace(" ", "", $id)));
}
+}
- public function settitre($titre)
- {
- if (strlen($titre) < self::$len and is_string($titre)) {
- $this->titre = strip_tags(trim($titre));
- }
+public function settitre($titre)
+{
+ if (strlen($titre) < self::$len and is_string($titre)) {
+ $this->titre = strip_tags(trim($titre));
}
+}
- public function setsoustitre($soustitre)
- {
- if (strlen($soustitre) < self::$len and is_string($soustitre)) {
- $this->soustitre = strip_tags(trim($soustitre));
- }
+public function setsoustitre($soustitre)
+{
+ if (strlen($soustitre) < self::$len and is_string($soustitre)) {
+ $this->soustitre = strip_tags(trim($soustitre));
}
+}
- public function setintro($intro)
- {
- if (strlen($intro) < self::$len and is_string($intro)) {
- $this->intro = strip_tags(trim($intro));
- }
+public function setintro($intro)
+{
+ if (strlen($intro) < self::$len and is_string($intro)) {
+ $this->intro = strip_tags(trim($intro));
}
+}
- public function settag($tag)
- {
- if (strlen($tag) < self::$len and is_string($tag)) {
- $this->tag = strip_tags(trim(strtolower($tag)));
- }
+public function settag($tag)
+{
+ if (strlen($tag) < self::$len and is_string($tag)) {
+ $this->tag = strip_tags(trim(strtolower($tag)));
}
+}
- public function setdatecreation($datecreation)
- {
- if ($datecreation instanceof DateTimeImmutable) {
- $this->datecreation = $datecreation;
- } else {
- $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris'));
- }
+public function setdatecreation($datecreation)
+{
+ if ($datecreation instanceof DateTimeImmutable) {
+ $this->datecreation = $datecreation;
+ } else {
+ $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris'));
}
+}
- public function setdatemodif($datemodif)
- {
- if ($datemodif instanceof DateTimeImmutable) {
- $this->datemodif = $datemodif;
- } else {
- $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris'));
- }
+public function setdatemodif($datemodif)
+{
+ if ($datemodif instanceof DateTimeImmutable) {
+ $this->datemodif = $datemodif;
+ } else {
+ $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris'));
}
+}
- public function setcss($css)
- {
- if (strlen($css) < self::$len and is_string($css)) {
- $this->css = strip_tags(trim(strtolower($css)));
- }
+public function setcss($css)
+{
+ if (strlen($css) < self::$len and is_string($css)) {
+ $this->css = strip_tags(trim(strtolower($css)));
}
+}
- public function sethtml($html)
- {
- if (strlen($html) < self::$lenhtml and is_string($html)) {
- $this->html = $html;
- }
+public function sethtml($html)
+{
+ if (strlen($html) < self::$lenhtml and is_string($html)) {
+ $this->html = $html;
}
+}
- public function setsecure($secure)
- {
- if ($secure >= 0 and $secure <= self::$securemax) {
- $this->secure = intval($secure);
- }
+public function setsecure($secure)
+{
+ if ($secure >= 0 and $secure <= self::$securemax) {
+ $this->secure = intval($secure);
}
+}
- public function setcouleurtext($couleurtext)
- {
- $couleurtext = strval($couleurtext);
- if (strlen($couleurtext) <= self::$lencouleur) {
- $this->couleurtext = strip_tags(trim($couleurtext));
- }
+public function setcouleurtext($couleurtext)
+{
+ $couleurtext = strval($couleurtext);
+ if (strlen($couleurtext) <= self::$lencouleur) {
+ $this->couleurtext = strip_tags(trim($couleurtext));
}
+}
- public function setcouleurbkg($couleurbkg)
- {
- $couleurbkg = strval($couleurbkg);
- if (strlen($couleurbkg) <= self::$lencouleur) {
- $this->couleurbkg = strip_tags(trim($couleurbkg));
- }
+public function setcouleurbkg($couleurbkg)
+{
+ $couleurbkg = strval($couleurbkg);
+ if (strlen($couleurbkg) <= self::$lencouleur) {
+ $this->couleurbkg = strip_tags(trim($couleurbkg));
}
+}
- public function setcouleurlien($couleurlien)
- {
- $couleurlien = strval($couleurlien);
- if (strlen($couleurlien) <= self::$lencouleur) {
- $this->couleurlien = strip_tags(trim($couleurlien));
- }
+public function setcouleurlien($couleurlien)
+{
+ $couleurlien = strval($couleurlien);
+ if (strlen($couleurlien) <= self::$lencouleur) {
+ $this->couleurlien = strip_tags(trim($couleurlien));
}
+}
}
+
+
?> \ No newline at end of file
diff --git a/fn/fn.php b/fn/fn.php
index cef8a1c..0da8ba4 100644
--- a/fn/fn.php
+++ b/fn/fn.php
@@ -1,5 +1,3 @@
-<h4>functions</h4>
-
<?php
function bddconnect($host, $bdname, $user, $password)
{
@@ -27,7 +25,7 @@ function head($title) {
?>
<head>
<meta charset="utf8" />
- <link href="" rel="stylesheet" />
+ <link href="/css/style.css" rel="stylesheet" />
<title><?= $title ?></title>
</head>
<?php
diff --git a/public/css/style.css b/public/css/style.css
new file mode 100644
index 0000000..ca04f38
--- /dev/null
+++ b/public/css/style.css
@@ -0,0 +1,15 @@
+body {background-color: #dcdcdceb;}
+
+input, textarea, select {
+ width: 90%;
+ padding-left: 15px;
+ padding-right: 15px;
+ margin: 5px;
+ margin-left: 5%;
+ margin-right: 5%;
+ height: 30px;
+ border-style: unset;
+}
+textarea {
+ height: 1000px;
+} \ No newline at end of file
diff --git a/public/rsc/css/style.css b/public/rsc/css/style.css
deleted file mode 100644
index e69de29..0000000
--- a/public/rsc/css/style.css
+++ /dev/null
diff --git a/public/w/index.php b/public/w/index.php
index 99d8cb6..41137d0 100644
--- a/public/w/index.php
+++ b/public/w/index.php
@@ -24,21 +24,21 @@ head('article');
// 'datemodif' => new DateTimeImmutable(null, timezone_open("Europe/Paris"))
// ]);
-$arraytest = ([
- 'id' => 'articlet2',
- 'titre' => 'titre',
- 'soustitre' => 'soustitre',
- 'intro' => 'intro',
- 'tag' => 'sans tag,',
- 'datecreation' => '2018-03-17 18:31:34',
- 'datemodif' => '2018-03-17 18:31:34',
- 'css' => 'display: inline:',
- 'html' => 'coucou les loulous',
- 'secure' => 0,
- 'couleurtext' => '#000000',
- 'couleurbkg' => '#ffffff',
- 'couleurlien' => '#2a3599'
-]);
+// $arraytest = ([
+// 'id' => 'articlet2',
+// 'titre' => 'titre',
+// 'soustitre' => 'soustitre',
+// 'intro' => 'intro',
+// 'tag' => 'sans tag,',
+// 'datecreation' => '2018-03-17 18:31:34',
+// 'datemodif' => '2018-03-17 18:31:34',
+// 'css' => 'display: inline:',
+// 'html' => 'coucou les loulous',
+// 'secure' => 0,
+// 'couleurtext' => '#000000',
+// 'couleurbkg' => '#ffffff',
+// 'couleurlien' => '#2a3599'
+// ]);
// $art = new Art($arreytest);
@@ -54,32 +54,67 @@ $arraytest = ([
// echo '<p>article exist :' . $app->exist('articlet') . '</p>';
// var_dump($app->exist('articlet'));
-
-
-echo '<pre>';
-$art = $app->get('articlet');
-
-var_dump($art);
-
-echo 'count : ' . $app->count();
-
- var_dump($app->exist('bouffffe'));
- var_dump($app->exist('bouffe'));
-
-
- $art2 = new Art($arraytest);
-
-// $app->add($art2);
-
-$app->update($art2);
-
-var_dump($app->getlist());
-
-echo '</pre>';
-
-
-
-
+$session = 2;
+
+
+if (isset($_GET['id'])) {
+
+ if ($session == 2) {
+ ?>
+ <nav>
+ <a href="?" >home</a>
+ <a href="?id=<?= $_GET['id'] ?>&display=1" target="_blank">display</a>
+ <a href="?id=<?= $_GET['id'] ?>&edit=1" >edit</a>
+ </nav>
+ <?php
+
+
+}
+
+if ($app->exist($_GET['id'])) {
+
+ if (isset($_POST['action']) and $_POST['action'] == 'update') {
+ $art = new Art($_POST);
+ var_dump($art);
+ $app->update($art);
+ header('Location: ?id=' . $art->id() . '&edit=1');
+
+ }
+
+ $art = $app->get($_GET['id']);
+
+
+
+ if (isset($_GET['display']) and $_GET['display'] == 1) {
+ $art->display($session);
+ }
+ if (isset($_GET['edit']) and $_GET['edit'] == 1) {
+ $art->edit($session);
+ }
+ } else {
+ if (isset($_POST['action'])) {
+ if ($_POST['action'] == 'new') {
+ $art = new Art($_GET);
+ $art->default();
+ var_dump($art);
+ $app->add($art);
+ header('Location: ?id=' . $_GET['id'] . '&edit=1');
+ }
+ } else {
+ echo '<h4>Cet article n\'éxiste pas encore</h4>';
+
+ if ($session >= 2) {
+ echo '<form action="?id=' . $_GET['id'] . '&edit=1" method="post"><input type="hidden" name="action" value="new"><input type="submit" value="créer"></form>';
+ }
+ echo '<a href="?info=erreur">retour maison</a>';
+
+ }
+
+ }
+} else {
+ echo "<h4>Bienvenue sur ce site.</h4>";
+ $app->menu($session);
+}