|
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 ["app" => 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) === true) { |
|
84
|
|
|
$files = array_diff(scandir($url), array('.', '..')); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($files as $file) { |
|
87
|
|
|
self::supprimerDossier(realpath($url).'/'.$file); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return rmdir($url); |
|
91
|
|
|
} |
|
92
|
|
|
else if (is_file($url) === true) { |
|
93
|
|
|
return unlink($url); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return false; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $from |
|
101
|
|
|
* @param $to |
|
102
|
|
|
* @param $sujet |
|
103
|
|
|
* @param $message |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function envoyerMail($from, $to, $sujet, $message) { |
|
106
|
|
|
$mail = new \Nette\Mail\Message(); |
|
107
|
|
|
$mail->setFrom($from) |
|
108
|
|
|
->addTo($to) |
|
109
|
|
|
->setSubject($sujet) |
|
110
|
|
|
->setHtmlBody($message); |
|
111
|
|
|
|
|
112
|
|
|
if (SMTP_HOST != "") { |
|
113
|
|
|
$mailer = new \Nette\Mail\SmtpMailer([ |
|
114
|
|
|
'host' => SMTP_HOST, |
|
115
|
|
|
'username' => SMTP_USER, |
|
116
|
|
|
'password' => SMTP_PASS, |
|
117
|
|
|
'secure' => SMTP_SECURE, |
|
118
|
|
|
'port' => SMTP_PORT |
|
119
|
|
|
]); |
|
120
|
|
|
} |
|
121
|
|
|
else { |
|
122
|
|
|
$mailer = new \Nette\Mail\SmtpMailer(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$mailer->send($mail); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return int |
|
130
|
|
|
*/ |
|
131
|
|
|
public static function getIdIdentite() { |
|
132
|
|
|
if (isset($_SESSION['idlogin'.CLEF_SITE])) { |
|
133
|
|
|
return $_SESSION['idlogin'.CLEF_SITE]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return 0; |
|
137
|
|
|
} |
|
138
|
|
|
//-------------------------- FIN GETTER ----------------------------------------------------------------------------// |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
143
|
|
|
/** |
|
144
|
|
|
* @param $values |
|
145
|
|
|
* can set values while keep older infos |
|
146
|
|
|
*/ |
|
147
|
|
|
public static function setValues($values) { |
|
148
|
|
|
self::$values = array_merge(self::$values, $values); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param $title |
|
153
|
|
|
* function to set title of the page |
|
154
|
|
|
*/ |
|
155
|
|
|
public static function setTitle($title) { |
|
156
|
|
|
self::$title = $title; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param $description |
|
161
|
|
|
* function to set description of the page |
|
162
|
|
|
*/ |
|
163
|
|
|
public static function setDescription($description) { |
|
164
|
|
|
self::$description = $description; |
|
165
|
|
|
} |
|
166
|
|
|
//-------------------------- FIN SETTER ----------------------------------------------------------------------------// |
|
167
|
|
|
} |