5 |
david |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
if (!defined("_ECRIRE_INC_VERSION")) return; #securite
|
|
|
4 |
|
|
|
5 |
//
|
|
|
6 |
// Formulaire de signature d'une petition
|
|
|
7 |
//
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
// Contexte necessaire lors de la compilation
|
|
|
11 |
|
|
|
12 |
// Il *faut* demander petition, meme si on ne s'en sert pas dans l'affichage,
|
|
|
13 |
// car on doit obtenir la jointure avec sql_petitions pour verifier si
|
|
|
14 |
// une petition est attachee a l'article
|
|
|
15 |
global $balise_FORMULAIRE_SIGNATURE_collecte;
|
|
|
16 |
$balise_FORMULAIRE_SIGNATURE_collecte = array('id_article', 'petition');
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
// Verification des arguments (contexte + filtres)
|
|
|
20 |
function balise_FORMULAIRE_SIGNATURE_stat($args, $filtres) {
|
|
|
21 |
|
|
|
22 |
// pas d'id_article => erreur de squelette
|
|
|
23 |
if (!$args[0])
|
|
|
24 |
return erreur_squelette(
|
|
|
25 |
_T('zbug_champ_hors_motif',
|
|
|
26 |
array ('champ' => '#FORMULAIRE_SIGNATURE',
|
|
|
27 |
'motif' => 'ARTICLES')), '');
|
|
|
28 |
|
|
|
29 |
// article sans petition => pas de balise
|
|
|
30 |
else if (!$args[1])
|
|
|
31 |
return '';
|
|
|
32 |
|
|
|
33 |
else {
|
|
|
34 |
// aller chercher dans la base la petition associee
|
|
|
35 |
$s = spip_query("SELECT texte, site_obli, message
|
|
|
36 |
FROM spip_petitions WHERE id_article = ".intval($args[0]));
|
|
|
37 |
if ($r = spip_fetch_array($s)) {
|
|
|
38 |
$args[2] = $r['texte'];
|
|
|
39 |
// le signataire doit-il donner un site ?
|
|
|
40 |
$args[3] = ($r['site_obli'] == 'oui') ? '':' ';
|
|
|
41 |
// le signataire peut-il proposer un commentaire
|
|
|
42 |
$args[4] = ($r['message'] == 'oui') ? ' ':'';
|
|
|
43 |
}
|
|
|
44 |
return $args;
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
// Executer la balise
|
|
|
49 |
function balise_FORMULAIRE_SIGNATURE_dyn($id_article, $petition, $texte, $site_obli, $message) {
|
|
|
50 |
|
|
|
51 |
if (_request('var_confirm')) # _GET
|
|
|
52 |
return reponse_confirmation($id_article);
|
|
|
53 |
|
|
|
54 |
else if (_request('nom_email') AND _request('adresse_email')) # _POST
|
|
|
55 |
return reponse_signature($id_article,
|
|
|
56 |
_request('nom_email'), _request('adresse_email'),
|
|
|
57 |
_request('message'), _request('signature_nom_site'),
|
|
|
58 |
_request('signature_url_site'), _request('url_page')
|
|
|
59 |
);
|
|
|
60 |
|
|
|
61 |
else {
|
|
|
62 |
return array('formulaire_signature', $GLOBALS['delais'],
|
|
|
63 |
array(
|
|
|
64 |
'id_article' => $id_article,
|
|
|
65 |
'petition' => $petition,
|
|
|
66 |
'texte' => $texte,
|
|
|
67 |
'site_obli' => $site_obli,
|
|
|
68 |
'message' => $message,
|
|
|
69 |
'self' => $GLOBALS["clean_link"]->getUrl()
|
|
|
70 |
));
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
// Retour a l'ecran du lien de confirmation d'une signature de petition.
|
|
|
76 |
// Si var_confirm est non vide, c'est l'appel en debut de inc-public
|
|
|
77 |
// pour vider le cache au demarrage afin que la nouvelle signature apparaisse.
|
|
|
78 |
// Sinon, c'est l'execution du formulaire et on retourne le message
|
|
|
79 |
// de confirmation ou d'erreur construit lors de l'appel par inc-public.
|
|
|
80 |
|
|
|
81 |
function reponse_confirmation($id_article, $var_confirm = '') {
|
|
|
82 |
static $confirm = '';
|
|
|
83 |
|
|
|
84 |
if (!$var_confirm) return $confirm;
|
|
|
85 |
include_local(_FILE_CONNECT);
|
|
|
86 |
if ($GLOBALS['db_ok']) {
|
|
|
87 |
include_ecrire("inc_texte.php3");
|
|
|
88 |
include_ecrire("inc_filtres.php3");
|
|
|
89 |
|
|
|
90 |
// Eviter les doublons
|
|
|
91 |
$lock = "petition $id_article $var_confirm";
|
|
|
92 |
if (!spip_get_lock($lock, 5)) {
|
|
|
93 |
$confirm= _T('form_pet_probleme_technique');
|
|
|
94 |
}
|
|
|
95 |
else {
|
|
|
96 |
$query_sign = "SELECT * FROM spip_signatures WHERE statut='".addslashes($var_confirm)."'";
|
|
|
97 |
$result_sign = spip_query($query_sign);
|
|
|
98 |
if (spip_num_rows($result_sign) > 0) {
|
|
|
99 |
while($row = spip_fetch_array($result_sign)) {
|
|
|
100 |
$id_signature = $row['id_signature'];
|
|
|
101 |
$id_article = $row['id_article'];
|
|
|
102 |
$date_time = $row['date_time'];
|
|
|
103 |
$nom_email = $row['nom_email'];
|
|
|
104 |
$adresse_email = $row['ad_email'];
|
|
|
105 |
$nom_site = $row['nom_site'];
|
|
|
106 |
$url_site = $row['url_site'];
|
|
|
107 |
$message = $row['message'];
|
|
|
108 |
$statut = $row['statut'];
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
$query_petition = "SELECT * FROM spip_petitions WHERE id_article=$id_article";
|
|
|
112 |
$result_petition = spip_query($query_petition);
|
|
|
113 |
|
|
|
114 |
while ($row = spip_fetch_array($result_petition)) {
|
|
|
115 |
$id_article = $row['id_article'];
|
|
|
116 |
$email_unique = $row['email_unique'];
|
|
|
117 |
$site_obli = $row['site_obli'];
|
|
|
118 |
$site_unique = $row['site_unique'];
|
|
|
119 |
$message_petition = $row['message'];
|
|
|
120 |
$texte_petition = $row['texte'];
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
if ($email_unique == "oui") {
|
|
|
124 |
$email = addslashes($adresse_email);
|
|
|
125 |
$query = "SELECT * FROM spip_signatures WHERE id_article=$id_article AND ad_email='$email' AND statut='publie'";
|
|
|
126 |
$result = spip_query($query);
|
|
|
127 |
if (spip_num_rows($result) > 0) {
|
|
|
128 |
$confirm= (_T('form_pet_deja_signe'));
|
|
|
129 |
$refus = "oui";
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
if ($site_unique == "oui") {
|
|
|
134 |
$site = addslashes($url_site);
|
|
|
135 |
$query = "SELECT * FROM spip_signatures WHERE id_article=$id_article AND url_site='$site' AND statut='publie'";
|
|
|
136 |
$result = spip_query($query);
|
|
|
137 |
if (spip_num_rows($result) > 0) {
|
|
|
138 |
$confirm= (_T('form_pet_deja_enregistre'));
|
|
|
139 |
$refus = "oui";
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
if ($refus == "oui") {
|
|
|
144 |
$confirm= (_T('form_deja_inscrit'));
|
|
|
145 |
}
|
|
|
146 |
else {
|
|
|
147 |
$query = "UPDATE spip_signatures
|
|
|
148 |
SET statut='publie', date_time=NOW()
|
|
|
149 |
WHERE id_signature='$id_signature'";
|
|
|
150 |
$result = spip_query($query);
|
|
|
151 |
// invalider les pages ayant des boucles signatures
|
|
|
152 |
include_ecrire('inc_invalideur.php3');
|
|
|
153 |
include_ecrire('inc_meta.php3');
|
|
|
154 |
suivre_invalideur("id='varia/pet$id_article'");
|
|
|
155 |
|
|
|
156 |
$confirm= (_T('form_pet_signature_validee'));
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
else {
|
|
|
160 |
$confirm= (_T('form_pet_aucune_signature'));
|
|
|
161 |
}
|
|
|
162 |
spip_release_lock($lock);
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
else {
|
|
|
166 |
$confirm= _T('form_pet_probleme_technique');
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
//
|
|
|
171 |
// Retour a l'ecran de la signature d'une petition
|
|
|
172 |
//
|
|
|
173 |
|
|
|
174 |
function reponse_signature($id_article, $nom_email, $adresse_email, $message, $nom_site, $url_site, $url_page) {
|
|
|
175 |
|
|
|
176 |
if ($GLOBALS['db_ok']) {
|
|
|
177 |
include_ecrire("inc_texte.php3");
|
|
|
178 |
include_ecrire("inc_filtres.php3");
|
|
|
179 |
include_ecrire("inc_mail.php3");
|
|
|
180 |
|
|
|
181 |
// Eviter les doublons
|
|
|
182 |
$lock = "petition $id_article $adresse_email";
|
|
|
183 |
if (!spip_get_lock($lock, 5)) {
|
|
|
184 |
return _T('form_pet_probleme_technique');
|
|
|
185 |
} else {
|
|
|
186 |
$query_petition = "SELECT * FROM spip_petitions WHERE id_article=$id_article";
|
|
|
187 |
$result_petition = spip_query($query_petition);
|
|
|
188 |
|
|
|
189 |
while ($row = spip_fetch_array($result_petition)) {
|
|
|
190 |
$id_article = $row['id_article'];
|
|
|
191 |
$email_unique = $row['email_unique'];
|
|
|
192 |
$site_obli = $row['site_obli'];
|
|
|
193 |
$site_unique = $row['site_unique'];
|
|
|
194 |
$message_petition = $row['message'];
|
|
|
195 |
$texte_petition = $row['texte'];
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
if (strlen($nom_email) < 2) {
|
|
|
199 |
return _T('form_indiquer_nom');
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
if ($adresse_email == _T('info_mail_fournisseur')) {
|
|
|
203 |
return _T('form_indiquer_email');
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
if ($email_unique == "oui") {
|
|
|
207 |
$email = addslashes($adresse_email);
|
|
|
208 |
$query = "SELECT * FROM spip_signatures WHERE id_article=$id_article AND ad_email='$email' AND statut='publie'";
|
|
|
209 |
$result = spip_query($query);
|
|
|
210 |
if (spip_num_rows($result) > 0) {
|
|
|
211 |
return _T('form_pet_deja_signe');
|
|
|
212 |
}
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
if (!email_valide($adresse_email)) {
|
|
|
216 |
return _T('form_email_non_valide');
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
if ($site_obli == "oui") {
|
|
|
220 |
if (!$nom_site) {
|
|
|
221 |
return _T('form_indiquer_nom_site');
|
|
|
222 |
}
|
|
|
223 |
include_ecrire("inc_sites.php3");
|
|
|
224 |
|
|
|
225 |
if (!recuperer_page($url_site)) {
|
|
|
226 |
return _T('form_pet_url_invalide');
|
|
|
227 |
}
|
|
|
228 |
}
|
|
|
229 |
if ($site_unique == "oui") {
|
|
|
230 |
$site = addslashes($url_site);
|
|
|
231 |
$query = "SELECT * FROM spip_signatures WHERE id_article=$id_article AND url_site='$site' AND (statut='publie' OR statut='poubelle')";
|
|
|
232 |
$result = spip_query($query);
|
|
|
233 |
if (spip_num_rows($result) > 0) {
|
|
|
234 |
return _T('form_pet_site_deja_enregistre');
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
$passw = test_pass();
|
|
|
239 |
|
|
|
240 |
if ($refus == "oui") {
|
|
|
241 |
return _T('form_pet_signature_pasprise');
|
|
|
242 |
}
|
|
|
243 |
else {
|
|
|
244 |
$query_site = "SELECT titre FROM spip_articles WHERE id_article=$id_article";
|
|
|
245 |
$result_site = spip_query($query_site);
|
|
|
246 |
while ($row = spip_fetch_array($result_site)) {
|
|
|
247 |
$titre = $row['titre'];
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
$link = new Link($url_page);
|
|
|
251 |
$link->addVar('var_confirm', $passw);
|
|
|
252 |
$url = $link->getUrl("sp$id_article");
|
|
|
253 |
|
|
|
254 |
$messagex = _T('form_pet_mail_confirmation', array('titre' => $titre, 'nom_email' => $nom_email, 'nom_site' => $nom_site, 'url_site' => $url_site, 'url' => $url));
|
|
|
255 |
|
|
|
256 |
if (envoyer_mail($adresse_email, _T('form_pet_confirmation')." ".$titre, $messagex)) {
|
|
|
257 |
|
|
|
258 |
$nom_email = addslashes($nom_email);
|
|
|
259 |
$adresse_email = addslashes($adresse_email);
|
|
|
260 |
$nom_site = addslashes($nom_site);
|
|
|
261 |
$url_site = addslashes($url_site);
|
|
|
262 |
$message = addslashes($message);
|
|
|
263 |
|
|
|
264 |
spip_query("INSERT INTO spip_signatures (id_article, date_time, nom_email, ad_email, nom_site, url_site, message, statut) VALUES ($id_article, NOW(), '$nom_email', '$adresse_email', '$nom_site', '$url_site', '$message', '$passw')");
|
|
|
265 |
return _T('form_pet_envoi_mail_confirmation');
|
|
|
266 |
}
|
|
|
267 |
else {
|
|
|
268 |
return _T('form_pet_probleme_technique');
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
spip_release_lock($lock);
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
else {
|
|
|
275 |
return _T('form_pet_probleme_technique');
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
function test_pass() {
|
|
|
282 |
include_ecrire("inc_acces.php3");
|
|
|
283 |
for (;;) {
|
|
|
284 |
$passw = creer_pass_aleatoire();
|
|
|
285 |
$query = "SELECT statut FROM spip_signatures WHERE statut='$passw'";
|
|
|
286 |
$result = spip_query($query);
|
|
|
287 |
if (!spip_num_rows($result)) break;
|
|
|
288 |
}
|
|
|
289 |
return $passw;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
?>
|