diff options
Diffstat (limited to 'public/w/index.php')
-rw-r--r-- | public/w/index.php | 166 |
1 files changed, 123 insertions, 43 deletions
diff --git a/public/w/index.php b/public/w/index.php index 9a40e9f..3f572b3 100644 --- a/public/w/index.php +++ b/public/w/index.php @@ -3,32 +3,120 @@ // _____________________________________________________ R E Q U I R E ________________________________________________________________ - - -$config = require('../../config.php'); require('../../vendor/autoload.php'); use Michelf\Markdown; use Michelf\MarkdownExtra; - require('../../fn/fn.php'); +require('../../class/class.w.config.php'); require('../../class/class.w.art.php'); require('../../class/class.w.app.php'); require('../../class/class.w.aff.php'); require('../../class/class.w.media.php'); +require('../../class/class.w.record.php'); + +// ________________________________________________________ I N S T A L _________________________________________________ + +$app = new App(); +$aff = new Aff(); + + +$config = $app->readconfig(); +if (!$config) { + $message = 'config_file_error'; + echo $message; + if (isset($_POST['config']) && $_POST['config'] == 'create') { + $config = $app->createconfig($_POST); + $app->savejson($config->tojson()); + header('Location: ./'); + + } else { + $aff->configform(); + } + exit; +} + + +// _________________________________________________________ S E S ___________________________________________________________ + session(); if (!isset($_SESSION['level'])) { - $level = 0; + $session = 0; } else { - $level = $_SESSION['level']; + $session = $_SESSION['level']; +} + +$app->setsession($session); + +//var_dump($config); +//var_dump($app); + + + +// _________________________________________________________ N A V _______________________________________________ + +if (isset($_GET['id'])) { + $app->setbdd($config); } -$app = new App($config); -$aff = new Aff($level); // _____________________________________________________ A C T I O N __________________________________________________________________ + +if (isset($_POST['action'])) { + switch ($_POST['action']) { + + case 'login': + $_SESSION['level'] = $app->login($_POST['pass'], $config); + if (isset($_GET['id'])) { + header('Location: ?id=' . $_GET['id']); + } else { + header('Location: ./'); + } + break; + + case 'logout': + $_SESSION['level'] = $app->logout(); + if (isset($_GET['id'])) { + header('Location: ?id=' . $_GET['id']); + } else { + header('Location: ./'); + } + break; + + case 'addmedia': + $message = $app->addmedia($_FILES, 2 ** 24, $_POST['id']); + header('Location: ./?aff=media&message=' . $message); + break; + + case 'addcss': + $message = $app->addcss($_FILES, 2 ** 24, $_POST['id']); + header('Location: ./?aff=admin&message=' . $message); + break; + + case 'changecss': + $config->setcssread($_POST['lecturecss']); + $app->savejson($config->tojson()); + header('Location: ./?aff=admin'); + break; + + case 'editconfig': + $config->hydrate($_POST); + $app->savejson($config->tojson()); + header('Location: ./?aff=admin'); + + break; + + + } +} + + +// _____________________________________________________ D A T A B A S E __________________________________________________________________ + if (isset($_POST['action'])) { + $app->setbdd($config); + switch ($_POST['action']) { case 'update': @@ -71,46 +159,22 @@ if (isset($_POST['action'])) { } break; - - case 'login': - $_SESSION['level'] = $app->login($_POST['pass']); - if (isset($_GET['id'])) { - header('Location: ?id=' . $_GET['id']); - } else { - header('Location: ./'); - } - break; - - case 'logout': - $_SESSION['level'] = $app->logout(); - if (isset($_GET['id'])) { - header('Location: ?id=' . $_GET['id']); - } else { - header('Location: ./'); - } - break; - - case 'addmedia': - $message = $app->addmedia($_FILES, 2 ** 10, $_POST['id']); - header('Location: ./?aff=media&message='.$message); - break; - } } - - // _______________________________________________________ H E A D _____________________________________________________________ if (isset($_GET['id'])) { + $app->setbdd($config); if ($app->exist($_GET['id'])) { $art = $app->get($_GET['id']); if (isset($_GET['edit']) && $_GET['edit'] == 1) { - $aff->arthead($art, '✏'); + $aff->arthead($art, $config->cssread(), 1); + } else { + $aff->arthead($art, $config->cssread(), 0); } - $aff->arthead($art, ''); } else { $aff->head($_GET['id'], 'w'); @@ -146,15 +210,17 @@ echo '<body>'; $aff->nav($app); if (isset($_GET['id'])) { + $app->setbdd($config); + if ($app->exist($_GET['id'])) { $art = $app->get($_GET['id']); - if (isset($_GET['edit']) and $_GET['edit'] == 1 and $aff->session() == 2) { - $aff->edit($art, $app->getlister(['id', 'titre'], 'id')); + if (isset($_GET['edit']) and $_GET['edit'] == 1 and $app->session() >= $app::EDITOR) { + $aff->edit($art, $app, $app->getlister(['id', 'titre'], 'id')); $aff->copy($art, $app->getlister(['id', 'titre'], 'id')); - $aff->aside($app->lister()); + $aff->aside($app); } else { $aff->lecture($art, $app); @@ -170,7 +236,7 @@ if (isset($_GET['id'])) { } else { echo '<span class="alert"><h4>Cet article n\'existe pas encore</h4></span>'; - if ($level >= 2) { + if ($aff->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>'; } @@ -184,11 +250,17 @@ if (isset($_GET['id'])) { } elseif (isset($_GET['lien'])) { echo '<h4>' . $_GET['lien'] . '</h4>'; $aff->lien($app->getlister(['id', 'titre', 'intro', 'lien'], 'id'), $_GET['lien']); - -} elseif (isset($_GET['aff'])) { +} elseif (isset($_GET['aff']) && $app->session() == $app::ADMIN) { if ($_GET['aff'] == 'admin') { + echo '<section>'; echo '<h1>Admin</h1>'; + + $aff->admincss($config, $app->csslist()); + $aff->admindb($config); + + echo '</section>'; } elseif ($_GET['aff'] == 'media') { + echo '<h1>Media</h1>'; echo '<section>'; $aff->addmedia(); @@ -198,11 +270,19 @@ if (isset($_GET['id'])) { } elseif ($_GET['aff'] == 'record') { echo '<h1>Record</h1>'; + echo '<section>'; + + $aff->recordlist($app); + + echo '</section>'; + } else { header('Location: ./'); } } else { + $app->setbdd($config); + if (isset($_GET['tri'])) { $tri = strip_tags($_GET['tri']); } else { @@ -213,7 +293,7 @@ if (isset($_GET['id'])) { } else { $desc = 'ASC'; } - $aff->home2table($app->getlister(['id', 'titre', 'intro', 'lien', 'datecreation', 'datemodif'], $tri, $desc)); + $aff->home2table($app, $app->getlister(['id', 'titre', 'intro', 'lien', 'datecreation', 'datemodif'], $tri, $desc)); } |