5 |
mathias |
1 |
<?php
|
|
|
2 |
/**
|
10 |
mathias |
3 |
* Formulaire de remarques assisté
|
|
|
4 |
* - envoie un email et écrit dans un fichier log
|
5 |
mathias |
5 |
*
|
10 |
mathias |
6 |
* Utilisation: http://www.tela-botanica.org/widget:reseau:remarques
|
7 |
mathias |
7 |
* Paramètres GET (optionnels):
|
10 |
mathias |
8 |
* pageSource : URL de la page depuis laquelle l'utilisateur a cliqué sur "nous contacter"
|
46 |
mathias |
9 |
* (exemple: http://www.tela-botanica.org/appli:cel)
|
|
|
10 |
* service : service à l'adresse duquel envoyer le rapport, par défaut webmestre,
|
54 |
mathias |
11 |
* limité aux clefs de la liste $this->servicesAutorises
|
46 |
mathias |
12 |
* (exemple: cel)
|
|
|
13 |
* email (DÉPRÉCIÉ) : adresse à laquelle envoyer le rapport, par défaut webmestre@tela-botanica.org,
|
54 |
mathias |
14 |
* limité aux valeurs de la liste $this->servicesAutorises
|
46 |
mathias |
15 |
* (exemple: cel_remarques@tela-botanica.org)
|
51 |
mathias |
16 |
* lang : langage (un squelette correspondant doit exister)
|
|
|
17 |
* (exemple: en)
|
7 |
mathias |
18 |
*
|
5 |
mathias |
19 |
* @author Mathias Chouet <mathias@tela-botanica.org>
|
|
|
20 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
21 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
22 |
* @version 0.1
|
|
|
23 |
* @copyright 2014, Tela Botanica (accueil@tela-botanica.org)
|
|
|
24 |
*/
|
10 |
mathias |
25 |
class Remarques extends WidgetCommun {
|
5 |
mathias |
26 |
|
|
|
27 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
28 |
|
7 |
mathias |
29 |
/**
|
46 |
mathias |
30 |
* service de destination par défaut, si un service ou une adresse non autorisés sont spécifiés,
|
|
|
31 |
* ou si aucun service ni adresse n'est spécifié
|
7 |
mathias |
32 |
*/
|
46 |
mathias |
33 |
const SERVICE_PAR_DEFAUT = 'webmestre';
|
7 |
mathias |
34 |
|
54 |
mathias |
35 |
/** liste des adresses de destination autorisées (à régler dans la config) */
|
|
|
36 |
protected $servicesAutorises;
|
5 |
mathias |
37 |
|
|
|
38 |
protected $cheminLog;
|
|
|
39 |
protected $pageSource;
|
46 |
mathias |
40 |
protected $serviceDestination;
|
5 |
mathias |
41 |
protected $emailDestination;
|
|
|
42 |
protected $action;
|
52 |
mathias |
43 |
protected $langue;
|
|
|
44 |
protected $langueDefaut;
|
5 |
mathias |
45 |
|
|
|
46 |
protected $description;
|
|
|
47 |
protected $gravite;
|
|
|
48 |
protected $navigateur;
|
|
|
49 |
protected $systeme;
|
|
|
50 |
protected $coordonnees;
|
|
|
51 |
|
103 |
killian |
52 |
protected $token;
|
|
|
53 |
|
5 |
mathias |
54 |
public function __construct($config, $parametres) {
|
|
|
55 |
parent::__construct($config, $parametres);
|
7 |
mathias |
56 |
|
54 |
mathias |
57 |
$this->servicesAutorises = $this->config['remarques-services'];
|
|
|
58 |
|
5 |
mathias |
59 |
$this->pageSource = 'inconnue';
|
46 |
mathias |
60 |
$this->serviceDestination = self::SERVICE_PAR_DEFAUT;
|
54 |
mathias |
61 |
$this->emailDestination = $this->servicesAutorises[self::SERVICE_PAR_DEFAUT];
|
5 |
mathias |
62 |
$this->action = null;
|
|
|
63 |
|
|
|
64 |
$this->description = null;
|
|
|
65 |
$this->gravite = null;
|
|
|
66 |
$this->navigateur = null;
|
|
|
67 |
$this->systeme = null;
|
|
|
68 |
$this->coordonnees = null;
|
103 |
killian |
69 |
$this->jeton = null;
|
5 |
mathias |
70 |
|
10 |
mathias |
71 |
$this->cheminLog = $this->config['remarques']['cheminFichierLog'];
|
52 |
mathias |
72 |
$this->langueDefaut = $this->config['remarques']['langueDefaut'];
|
103 |
killian |
73 |
|
|
|
74 |
session_start();
|
|
|
75 |
if (!isset($_SESSION['jeton'])) {
|
|
|
76 |
$_SESSION['jeton'] = bin2hex(openssl_random_pseudo_bytes(6));
|
|
|
77 |
}
|
5 |
mathias |
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Méthode appelée par défaut pour charger ce widget
|
|
|
82 |
*/
|
|
|
83 |
public function executer() {
|
|
|
84 |
$this->collecterParametres();
|
51 |
mathias |
85 |
$squelette = dirname(__FILE__) . self::DS . 'squelettes' . self::DS . 'remarques_' . $this->langue . '.tpl.php';
|
52 |
mathias |
86 |
if (! file_exists($squelette)) {
|
|
|
87 |
$squelette = dirname(__FILE__) . self::DS . 'squelettes' . self::DS . 'remarques_' . $this->langueDefaut . '.tpl.php';
|
|
|
88 |
}
|
5 |
mathias |
89 |
|
10 |
mathias |
90 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/remarques/squelettes/css/defaut.css');
|
|
|
91 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/remarques/squelettes/js/defaut.js');
|
46 |
mathias |
92 |
$widget['donnees']['service'] = $this->serviceDestination;
|
5 |
mathias |
93 |
$widget['donnees']['page'] = $this->pageSource;
|
|
|
94 |
$widget['donnees']['envoye'] = false;
|
103 |
killian |
95 |
$widget['donnees']['jeton'] = $_SESSION['jeton'];
|
5 |
mathias |
96 |
|
103 |
killian |
97 |
if ($this->action === 'envoyer' && $this->jeton === $_SESSION['jeton']) {
|
5 |
mathias |
98 |
$widget['donnees']['envoye'] = true;
|
|
|
99 |
// 1) entrée dans le log
|
|
|
100 |
try {
|
|
|
101 |
$this->log();
|
|
|
102 |
} catch (Exception $e) {
|
|
|
103 |
echo "Erreur lors de la création de l'entrée dans le fichier log<br/>";
|
|
|
104 |
}
|
|
|
105 |
// 2) email
|
|
|
106 |
try {
|
|
|
107 |
$this->email();
|
|
|
108 |
} catch (Exception $e) {
|
|
|
109 |
echo "Erreur lors de l'envoi de l'email<br/>";
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);
|
|
|
114 |
$this->envoyer($contenu);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
// paramètres du widget en GET et du formulaire en POST
|
|
|
118 |
protected function collecterParametres() {
|
|
|
119 |
if (isset($_GET['pageSource']) && $_GET['pageSource'] != '') {
|
|
|
120 |
$this->pageSource = $_GET['pageSource'];
|
|
|
121 |
}
|
51 |
mathias |
122 |
if (isset($_GET['lang']) && $_GET['lang'] != '') {
|
|
|
123 |
$this->langue = $_GET['lang'];
|
|
|
124 |
} else {
|
52 |
mathias |
125 |
$this->langue = $this->langueDefaut;
|
51 |
mathias |
126 |
}
|
54 |
mathias |
127 |
if (isset($_GET['service']) && in_array($_GET['service'], array_keys($this->servicesAutorises))) {
|
46 |
mathias |
128 |
$this->serviceDestination = $_GET['service'];
|
54 |
mathias |
129 |
$this->emailDestination = $this->servicesAutorises[$_GET['service']];
|
46 |
mathias |
130 |
} else {
|
|
|
131 |
// Rétrocompatibilité (déprécié)
|
54 |
mathias |
132 |
if (isset($_GET['email']) && in_array($_GET['email'], $this->servicesAutorises)) {
|
46 |
mathias |
133 |
$this->emailDestination = $_GET['email'];
|
54 |
mathias |
134 |
$this->serviceDestination = array_search($_GET['email'], $this->servicesAutorises);
|
46 |
mathias |
135 |
}
|
5 |
mathias |
136 |
}
|
|
|
137 |
if (isset($_POST['action']) && $_POST['action'] != '') {
|
|
|
138 |
$this->action = $_POST['action'];
|
|
|
139 |
}
|
|
|
140 |
// contenu du formulaire
|
|
|
141 |
if (isset($_POST['description']) && $_POST['description'] != '') {
|
12 |
mathias |
142 |
$this->description = stripslashes($_POST['description']);
|
5 |
mathias |
143 |
}
|
|
|
144 |
if (isset($_POST['gravite']) && $_POST['gravite'] != '') {
|
|
|
145 |
$this->gravite = $_POST['gravite'];
|
|
|
146 |
}
|
|
|
147 |
if (isset($_POST['navigateur']) && $_POST['navigateur'] != '') {
|
12 |
mathias |
148 |
$this->navigateur = stripslashes($_POST['navigateur']);
|
5 |
mathias |
149 |
}
|
|
|
150 |
if (isset($_POST['systeme']) && $_POST['systeme'] != '') {
|
12 |
mathias |
151 |
$this->systeme = stripslashes($_POST['systeme']);
|
5 |
mathias |
152 |
}
|
|
|
153 |
if (isset($_POST['coordonnees']) && $_POST['coordonnees'] != '') {
|
12 |
mathias |
154 |
$this->coordonnees = stripslashes($_POST['coordonnees']);
|
5 |
mathias |
155 |
}
|
103 |
killian |
156 |
$this->jeton = stripslashes($_POST['jeton'] ?? 'pasdejeton');
|
5 |
mathias |
157 |
}
|
|
|
158 |
|
|
|
159 |
// ajoute une entrée au log
|
|
|
160 |
protected function log() {
|
15 |
jpm |
161 |
$contenu = ''.
|
106 |
killian |
162 |
date("Y-m-d H:i:s") . "\n".
|
46 |
mathias |
163 |
"Pour: " . $this->serviceDestination . " <" . $this->emailDestination . ">\n".
|
15 |
jpm |
164 |
"Page: " . $this->pageSource . "\n".
|
|
|
165 |
"User agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n".
|
|
|
166 |
"Contributeur: " . $this->coordonnees . "\n".
|
|
|
167 |
"Gravité: " . $this->gravite . "\n".
|
|
|
168 |
"Navigateur: " . $this->navigateur . "\n".
|
|
|
169 |
"Système: " . $this->systeme . "\n".
|
|
|
170 |
"Description:\n " . str_replace("\n", "\n ", $this->description).
|
|
|
171 |
"\n\n-----------------------------------------------------------------------\n\n";
|
5 |
mathias |
172 |
|
|
|
173 |
file_put_contents($this->cheminLog, $contenu, FILE_APPEND);
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
// envoie un email
|
|
|
177 |
protected function email() {
|
15 |
jpm |
178 |
$contenu = ''.
|
106 |
killian |
179 |
date("Y-m-d H:i:s") . "\n".
|
46 |
mathias |
180 |
"Pour: " . $this->serviceDestination . " <" . $this->emailDestination . ">\n".
|
15 |
jpm |
181 |
"Page: " . $this->pageSource . "\n".
|
|
|
182 |
"User agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n".
|
|
|
183 |
"Contributeur: " . $this->coordonnees . "\n".
|
|
|
184 |
"Gravité: " . $this->gravite . "\n".
|
|
|
185 |
"Navigateur: " . $this->navigateur . "\n".
|
|
|
186 |
"Système: " . $this->systeme . "\n".
|
|
|
187 |
"Description:\n " . str_replace("\n", "\n ", $this->description);
|
5 |
mathias |
188 |
|
15 |
jpm |
189 |
$entetes = 'Content-Type: text/plain; charset="utf-8" '.
|
|
|
190 |
'Content-Transfer-Encoding: 8bit';
|
7 |
mathias |
191 |
|
15 |
jpm |
192 |
$sujet = substr($this->description, 0, 25).'... '.
|
|
|
193 |
'('.($this->coordonnees == '' ? 'inconnu' : $this->coordonnees).')';
|
5 |
mathias |
194 |
|
|
|
195 |
// mode charlot - mais y a rien dans le framework pour faire mieux
|
7 |
mathias |
196 |
mail($this->emailDestination, $sujet, $contenu, $entetes);
|
5 |
mathias |
197 |
}
|
|
|
198 |
}
|
|
|
199 |
?>
|