aboutsummaryrefslogtreecommitdiff
path: root/public/w/index.php
blob: f12e7f430fbc87ed44107d5f5288cf2f6358564e (plain)
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
<?php


// _____________________________________________________ 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.art.php');
require('../../class/class.app.php');
require('../../class/class.aff.php');
session();
if (!isset($_SESSION['level'])) {
    $level = 0;
} else {
    $level = $_SESSION['level'];
}
$app = new App($config);
$aff = new Aff($level);


// _____________________________________________________ A C T I O N __________________________________________________________________

if (isset($_POST['action'])) {
    switch ($_POST['action']) {

        case 'update':
            if ($app->exist($_GET['id'])) {
                $art = new Art($_POST);
                $app->update($art);
                header('Location: ?id=' . $art->id() . '&edit=1');
            }
            break;

        case 'login':
            $_SESSION['level'] = $app->login($_POST['pass']);
            header('Location: ?id=' . $_GET['id']);
            break;

        case 'logout':
            $_SESSION['level'] = $app->logout();
            header('Location: ?id=' . $_GET['id']);
            break;
    }

}




// _______________________________________________________ H E A D _____________________________________________________________
$titre = 'home';
if (isset($_GET['id'])) {
    $titre = $_GET['id'];
    if ($app->exist($_GET['id'])) {
        $art = $app->get($_GET['id']);
        $titre = $art->titre();
    }
}
$aff->head($titre);




// ______________________________________________________ B O D Y _______________________________________________________________ 


echo '<body>';
$aff->nav($app);

if (isset($_GET['id'])) {


    if ($app->exist($_GET['id'])) {

        $art = $app->get($_GET['id']);

        if (isset($_GET['edit']) and $_GET['edit'] == 1) {
            $aff->edit($art);
            $aff->aside($app->list());
        } else {
            $aff->lecture($art);

        }
    } 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 '<span class="alert"><h4>Cet article n\'existe pas encore</h4></span>';

            if ($level >= 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>';
            }

        }

    }
} else {
    echo "<h4>Bienvenue sur ce site.</h4>";
    $aff->home($app->list());
}
echo '</body>';



?>