aboutsummaryrefslogtreecommitdiff
path: root/public/w/index.php
blob: 38a4132195406c0d16ca6c02ad8997901d9c289f (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
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
147
<?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 'delete':
            if ($app->exist($_GET['id'])) {
                $art = new Art($_POST);
                $app->delete($art);
                header('Location: ?id=' . $art->id());
            }
            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;

    }

}




// _______________________________________________________ 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->lister());
        } else {
            $aff->lecture($art, $app);

        }
    } else {
        if (isset($_POST['action'])) {
            if ($_POST['action'] == 'new') {
                $art = new Art($_GET);
                $art->reset();
                $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>';
            }

        }

    }
} elseif (isset($_GET['tag'])) {
    echo '<h4>' . $_GET['tag'] . '</h4>';
    $aff->tag($app->getlister(['id', 'titre', 'intro', 'tag'], 'id'), $_GET['tag']);

} elseif (isset($_GET['lien'])) {
    echo '<h4>' . $_GET['lien'] . '</h4>';
    $aff->lien($app->getlister(['id', 'titre', 'intro', 'lien'], 'id'), $_GET['lien']);

} else {
    if (isset($_GET['tri'])) {
        $tri = strip_tags($_GET['tri']);
    } else {
        $tri = 'id';
    }
    $aff->search();
    $aff->home2table($app->getlister(['id', 'titre', 'intro', 'lien'], $tri));
}
echo '</body>';



?>