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"
|
7 |
mathias |
9 |
* (exemple: http://www.tela-botanica.org/appli:cel)
|
|
|
10 |
* email : adresse à laquelle envoyer le rapport, par défaut webmestre@tela-botanica.org, limité à la liste self::$emailsAutorises
|
|
|
11 |
* (exemple: cel_remarques@tela-botanica.org)
|
|
|
12 |
*
|
5 |
mathias |
13 |
* @author Mathias Chouet <mathias@tela-botanica.org>
|
|
|
14 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
15 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
16 |
* @version 0.1
|
|
|
17 |
* @copyright 2014, Tela Botanica (accueil@tela-botanica.org)
|
|
|
18 |
*/
|
10 |
mathias |
19 |
class Remarques extends WidgetCommun {
|
5 |
mathias |
20 |
|
|
|
21 |
const DS = DIRECTORY_SEPARATOR;
|
|
|
22 |
|
7 |
mathias |
23 |
/**
|
|
|
24 |
* adresse de destination par défaut, si une adresse non autorisée est spécifiée,
|
|
|
25 |
* ou si aucune adresse n'est spécifiée
|
|
|
26 |
*/
|
|
|
27 |
const EMAIL_PAR_DEFAUT = 'webmestre@tela-botanica.org';
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* liste des adresses de destination autorisées
|
|
|
31 |
*/
|
5 |
mathias |
32 |
private static $emailsAutorises = array(
|
|
|
33 |
'eflore_remarques@tela-botanica.org',
|
|
|
34 |
'pictoflora_remarques@tela-botanica.org',
|
|
|
35 |
'identiplante_remarques@tela-botanica.org',
|
|
|
36 |
'cel_remarques@tela-botanica.org',
|
|
|
37 |
'coel_remarques@tela-botanica.org',
|
|
|
38 |
'webmestre@tela-botanica.org',
|
|
|
39 |
'mathias@tela-botanica.org'
|
|
|
40 |
);
|
|
|
41 |
|
|
|
42 |
protected $cheminLog;
|
|
|
43 |
protected $pageSource;
|
|
|
44 |
protected $emailDestination;
|
|
|
45 |
protected $action;
|
|
|
46 |
|
|
|
47 |
protected $description;
|
|
|
48 |
protected $gravite;
|
|
|
49 |
protected $navigateur;
|
|
|
50 |
protected $systeme;
|
|
|
51 |
protected $coordonnees;
|
|
|
52 |
|
|
|
53 |
public function __construct($config, $parametres) {
|
|
|
54 |
parent::__construct($config, $parametres);
|
7 |
mathias |
55 |
|
5 |
mathias |
56 |
$this->pageSource = 'inconnue';
|
7 |
mathias |
57 |
$this->emailDestination = self::EMAIL_PAR_DEFAUT;
|
5 |
mathias |
58 |
$this->action = null;
|
|
|
59 |
|
|
|
60 |
$this->description = null;
|
|
|
61 |
$this->gravite = null;
|
|
|
62 |
$this->navigateur = null;
|
|
|
63 |
$this->systeme = null;
|
|
|
64 |
$this->coordonnees = null;
|
|
|
65 |
|
10 |
mathias |
66 |
$this->cheminLog = $this->config['remarques']['cheminFichierLog'];
|
5 |
mathias |
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Méthode appelée par défaut pour charger ce widget
|
|
|
71 |
*/
|
|
|
72 |
public function executer() {
|
|
|
73 |
$this->collecterParametres();
|
10 |
mathias |
74 |
$squelette = dirname(__FILE__) . self::DS . 'squelettes' . self::DS . 'remarques.tpl.php';
|
5 |
mathias |
75 |
|
10 |
mathias |
76 |
$widget['donnees']['url_css'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/remarques/squelettes/css/defaut.css');
|
|
|
77 |
$widget['donnees']['url_js'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], 'modules/remarques/squelettes/js/defaut.js');
|
5 |
mathias |
78 |
$widget['donnees']['email'] = $this->emailDestination;
|
|
|
79 |
$widget['donnees']['page'] = $this->pageSource;
|
|
|
80 |
$widget['donnees']['envoye'] = false;
|
|
|
81 |
|
|
|
82 |
if ($this->action === 'envoyer') {
|
|
|
83 |
$widget['donnees']['envoye'] = true;
|
|
|
84 |
// 1) entrée dans le log
|
|
|
85 |
try {
|
|
|
86 |
$this->log();
|
|
|
87 |
} catch (Exception $e) {
|
|
|
88 |
echo "Erreur lors de la création de l'entrée dans le fichier log<br/>";
|
|
|
89 |
}
|
|
|
90 |
// 2) email
|
|
|
91 |
try {
|
|
|
92 |
$this->email();
|
|
|
93 |
} catch (Exception $e) {
|
|
|
94 |
echo "Erreur lors de l'envoi de l'email<br/>";
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
$contenu = $this->traiterSquelettePhp($squelette, $widget['donnees']);
|
|
|
99 |
$this->envoyer($contenu);
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
// paramètres du widget en GET et du formulaire en POST
|
|
|
103 |
protected function collecterParametres() {
|
|
|
104 |
if (isset($_GET['pageSource']) && $_GET['pageSource'] != '') {
|
|
|
105 |
$this->pageSource = $_GET['pageSource'];
|
|
|
106 |
}
|
|
|
107 |
if (isset($_GET['email']) && in_array($_GET['email'], self::$emailsAutorises)) {
|
|
|
108 |
$this->emailDestination = $_GET['email'];
|
|
|
109 |
}
|
|
|
110 |
if (isset($_POST['action']) && $_POST['action'] != '') {
|
|
|
111 |
$this->action = $_POST['action'];
|
|
|
112 |
}
|
|
|
113 |
// contenu du formulaire
|
|
|
114 |
if (isset($_POST['description']) && $_POST['description'] != '') {
|
12 |
mathias |
115 |
$this->description = stripslashes($_POST['description']);
|
5 |
mathias |
116 |
}
|
|
|
117 |
if (isset($_POST['gravite']) && $_POST['gravite'] != '') {
|
|
|
118 |
$this->gravite = $_POST['gravite'];
|
|
|
119 |
}
|
|
|
120 |
if (isset($_POST['navigateur']) && $_POST['navigateur'] != '') {
|
12 |
mathias |
121 |
$this->navigateur = stripslashes($_POST['navigateur']);
|
5 |
mathias |
122 |
}
|
|
|
123 |
if (isset($_POST['systeme']) && $_POST['systeme'] != '') {
|
12 |
mathias |
124 |
$this->systeme = stripslashes($_POST['systeme']);
|
5 |
mathias |
125 |
}
|
|
|
126 |
if (isset($_POST['coordonnees']) && $_POST['coordonnees'] != '') {
|
12 |
mathias |
127 |
$this->coordonnees = stripslashes($_POST['coordonnees']);
|
5 |
mathias |
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// ajoute une entrée au log
|
|
|
132 |
protected function log() {
|
15 |
jpm |
133 |
$contenu = ''.
|
|
|
134 |
date("Y-m-d h:i:s") . "\n".
|
|
|
135 |
"Pour: " . $this->emailDestination . "\n".
|
|
|
136 |
"Page: " . $this->pageSource . "\n".
|
|
|
137 |
"User agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n".
|
|
|
138 |
"Contributeur: " . $this->coordonnees . "\n".
|
|
|
139 |
"Gravité: " . $this->gravite . "\n".
|
|
|
140 |
"Navigateur: " . $this->navigateur . "\n".
|
|
|
141 |
"Système: " . $this->systeme . "\n".
|
|
|
142 |
"Description:\n " . str_replace("\n", "\n ", $this->description).
|
|
|
143 |
"\n\n-----------------------------------------------------------------------\n\n";
|
5 |
mathias |
144 |
|
|
|
145 |
file_put_contents($this->cheminLog, $contenu, FILE_APPEND);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
// envoie un email
|
|
|
149 |
protected function email() {
|
15 |
jpm |
150 |
$contenu = ''.
|
|
|
151 |
date("Y-m-d h:i:s") . "\n".
|
|
|
152 |
"Pour: " . $this->emailDestination . "\n".
|
|
|
153 |
"Page: " . $this->pageSource . "\n".
|
|
|
154 |
"User agent: " . $_SERVER['HTTP_USER_AGENT'] . "\n".
|
|
|
155 |
"Contributeur: " . $this->coordonnees . "\n".
|
|
|
156 |
"Gravité: " . $this->gravite . "\n".
|
|
|
157 |
"Navigateur: " . $this->navigateur . "\n".
|
|
|
158 |
"Système: " . $this->systeme . "\n".
|
|
|
159 |
"Description:\n " . str_replace("\n", "\n ", $this->description);
|
5 |
mathias |
160 |
|
15 |
jpm |
161 |
$entetes = 'Content-Type: text/plain; charset="utf-8" '.
|
|
|
162 |
'Content-Transfer-Encoding: 8bit';
|
7 |
mathias |
163 |
|
15 |
jpm |
164 |
$sujet = substr($this->description, 0, 25).'... '.
|
|
|
165 |
'('.($this->coordonnees == '' ? 'inconnu' : $this->coordonnees).')';
|
5 |
mathias |
166 |
|
|
|
167 |
// mode charlot - mais y a rien dans le framework pour faire mieux
|
7 |
mathias |
168 |
mail($this->emailDestination, $sujet, $contenu, $entetes);
|
5 |
mathias |
169 |
}
|
|
|
170 |
}
|
|
|
171 |
?>
|