1 | <?php |
---|
2 | include_spip('inc/forms'); |
---|
3 | |
---|
4 | function generer_mail_ecard_formulaire($id_form, $id_reponse, $id_article){ |
---|
5 | $texte = ""; |
---|
6 | $res = spip_query("SELECT titre,texte FROM spip_articles WHERE id_article=".spip_abstract_quote($id_article)); |
---|
7 | if ($row = spip_fetch_array($res)){ |
---|
8 | $titre = $row['titre']; |
---|
9 | $texte = liens_absolus(propre($row['texte'])); |
---|
10 | } |
---|
11 | $texte .= "<br />\n<a href='".url_absolue(generer_url_article($id_article))."'>Retrouvez cette e-card en ligne</a><br/>\n"; |
---|
12 | |
---|
13 | $query = "SELECT * FROM spip_forms WHERE id_form=$id_form"; |
---|
14 | $result = spip_query($query); |
---|
15 | if ($row = spip_fetch_array($result)) { |
---|
16 | $champconfirm = $row['champconfirm']; |
---|
17 | //$email = unserialize($row['email']); |
---|
18 | |
---|
19 | $email_dest = $email['defaut']; |
---|
20 | $mailconfirm = ""; |
---|
21 | |
---|
22 | $form_summary = ''; |
---|
23 | $structure = unserialize($row['structure']); |
---|
24 | // Ici on parcourt les valeurs entrees pour les champs demandes |
---|
25 | foreach ($structure as $index => $t) { |
---|
26 | $type = $t['type']; |
---|
27 | $code = $t['code']; |
---|
28 | $type_ext = $t['type_ext']; |
---|
29 | |
---|
30 | if (!in_array($type,array('separateur','textestatique'))){ |
---|
31 | if ($code != $champconfirm) // on ne remet pas l'email du destinataire dans le mail |
---|
32 | $form_summary .= "<strong>".$t['nom'] . "</strong> : "; |
---|
33 | |
---|
34 | $query2 = "SELECT * FROM spip_reponses_champs WHERE id_reponse='$id_reponse' AND champ='$code'"; |
---|
35 | $result2 = spip_query($query2); |
---|
36 | $reponses = ''; |
---|
37 | while ($row2 = spip_fetch_array($result2)) { |
---|
38 | if ($email['route']==$code && isset($email[$row2['valeur']])) |
---|
39 | $email_dest = $email[$row2['valeur']]; |
---|
40 | if ($code == $champconfirm) |
---|
41 | $mailconfirm = $row2['valeur']; |
---|
42 | |
---|
43 | $reponses .= Forms_traduit_reponse($type, $code,$type_ext,$row2['valeur']).", "; |
---|
44 | } |
---|
45 | if ($code != $champconfirm) // on ne remet pas l'email du destinataire dans le mail |
---|
46 | if (strlen($reponses) > 2) |
---|
47 | $form_summary .= substr($reponses,0,strlen($reponses)-2); |
---|
48 | $form_summary .= "<br />\n"; |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | include_spip('inc/charset'); |
---|
53 | $trans_tbl = get_html_translation_table (HTML_ENTITIES); |
---|
54 | $trans_tbl = array_flip ($trans_tbl); |
---|
55 | if ($mailconfirm !== '') { |
---|
56 | $head="From: ecard@".$_SERVER["HTTP_HOST"]."\n"; |
---|
57 | $head .= "Content-type : text/html\n"; |
---|
58 | |
---|
59 | $message = ""; |
---|
60 | $message .= $texte . "<br />\n" . $form_summary; |
---|
61 | $sujet = $titre; |
---|
62 | $dest = $mailconfirm; |
---|
63 | |
---|
64 | // mettre le texte dans un charset acceptable |
---|
65 | $mess_iso = unicode2charset(charset2unicode($message),'iso-8859-1'); |
---|
66 | // regler les entites si il en reste |
---|
67 | $mess_iso = strtr($mess_iso, $trans_tbl); |
---|
68 | |
---|
69 | mail($dest, $sujet, $mess_iso, $head); |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | ?> |
---|