1
|
|
|
<?php |
2
|
|
|
namespace core; |
3
|
|
|
|
4
|
|
|
use core\database\Database; |
5
|
|
|
|
6
|
|
|
class App { |
7
|
|
|
private static $database; |
8
|
|
|
private static $nav; |
9
|
|
|
private static $erreur; |
10
|
|
|
|
11
|
|
|
private static $title; |
12
|
|
|
private static $description; |
13
|
|
|
|
14
|
|
|
private static $values = []; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------// |
18
|
|
|
public function __construct() { |
19
|
|
|
|
20
|
|
|
} |
21
|
|
|
//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------// |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
26
|
|
|
public static function getErreur() { |
27
|
|
|
return self::$erreur; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array |
32
|
|
|
* get array of all values wich will be used in the page |
33
|
|
|
*/ |
34
|
|
|
public static function getValues() { |
35
|
|
|
return self::$values; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return Database |
40
|
|
|
* renvoi une instance de la classe Database |
41
|
|
|
*/ |
42
|
|
|
public static function getDb() { |
43
|
|
|
if (self::$database == null) { |
44
|
|
|
self::$database = new Database(DB_TYPE, DB_NAME, DB_USER, DB_PASS, DB_HOST); |
45
|
|
|
} |
46
|
|
|
return self::$database; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param null $no_module |
51
|
|
|
* @return Navigation |
52
|
|
|
* renvoi une instancde de la class navigation |
53
|
|
|
*/ |
54
|
|
|
public static function getNav($no_module = null) { |
55
|
|
|
if (self::$nav == null) { |
56
|
|
|
self::$nav = new Navigation($no_module); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return self::$nav; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return mixed |
64
|
|
|
* function tu get the title of the page |
65
|
|
|
*/ |
66
|
|
|
public static function getTitle() { |
67
|
|
|
return self::$title; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return mixed |
72
|
|
|
* function to get description of the page |
73
|
|
|
*/ |
74
|
|
|
public static function getDescription() { |
75
|
|
|
return self::$description; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $url |
80
|
|
|
* fonction qui permet de supprmer un dossier avec toute son abrorescence en fonction d'une URL |
81
|
|
|
*/ |
82
|
|
|
public static function supprimerDossier($url) { |
83
|
|
|
if (is_dir($url)) { |
84
|
|
|
$objects = scandir($url); |
85
|
|
|
foreach ($objects as $object) { |
86
|
|
|
if ($object != "." && $object != "..") { |
87
|
|
|
if (filetype($url."/".$object) == "dir") App::supprimerDossier($url."/".$object); else unlink($url."/".$object); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
reset($objects); |
91
|
|
|
rmdir($url); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param $from |
97
|
|
|
* @param $to |
98
|
|
|
* @param $sujet |
99
|
|
|
* @param $message |
100
|
|
|
*/ |
101
|
|
|
public static function envoyerMail($from, $to, $sujet, $message) { |
102
|
|
|
$mail = new \Nette\Mail\Message(); |
103
|
|
|
$mail->setFrom($from) |
104
|
|
|
->addTo($to) |
105
|
|
|
->setSubject($sujet) |
106
|
|
|
->setHtmlBody($message); |
107
|
|
|
|
108
|
|
|
if (SMTP_HOST != "") { |
109
|
|
|
$mailer = new \Nette\Mail\SmtpMailer([ |
110
|
|
|
'host' => SMTP_HOST, |
111
|
|
|
'username' => SMTP_USER, |
112
|
|
|
'password' => SMTP_PASS, |
113
|
|
|
'secure' => SMTP_SECURE, |
114
|
|
|
'port' => SMTP_PORT |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
else { |
118
|
|
|
$mailer = new \Nette\Mail\SmtpMailer(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$mailer->send($mail); |
122
|
|
|
} |
123
|
|
|
//-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
|
127
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
128
|
|
|
/** |
129
|
|
|
* @param $values |
130
|
|
|
* can set values while keep older infos |
131
|
|
|
*/ |
132
|
|
|
public static function setValues($values) { |
133
|
|
|
self::$values = array_merge(self::$values, $values); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param $title |
138
|
|
|
* function to set title of the page |
139
|
|
|
*/ |
140
|
|
|
public static function setTitle($title) { |
141
|
|
|
self::$title = $title; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @param $description |
146
|
|
|
* function to set description of the page |
147
|
|
|
*/ |
148
|
|
|
public static function setDescription($description) { |
149
|
|
|
self::$description = $description; |
150
|
|
|
} |
151
|
|
|
//-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
152
|
|
|
} |