1 | <?php |
---|
2 | function formulaires_clevermail_list_edit_charger_dist($lst_id = -1) { |
---|
3 | // Ces define sont mis ici car dans clevermail_options.php, il etait impossible de surcharger avec un plugin ayant : |
---|
4 | // <utilise id="clevermail" version="[2.5.0;]" /> |
---|
5 | // Pour proposer une URL complète (true) ou juste le chemin du squelette (false) à la création d'une nouvelle lettre |
---|
6 | @define("_CLEVERMAIL_DISTANT", true); |
---|
7 | @define("_CLEVERMAIL_NOUVEAUTES_HTML", 'clevermail_nouveautes_html'); |
---|
8 | // _CLEVERMAIL_NOUVEAUTES_HTML_OPTION est facultatif. Il permet de completer l'url amorcee avec _CLEVERMAIL_NOUVEAUTES_HTML. |
---|
9 | // define("_CLEVERMAIL_NOUVEAUTES_HTML_OPTION", 'cat=mot&sujet=1&pied=1&entete=1'); |
---|
10 | @define("_CLEVERMAIL_NOUVEAUTES_TEXT", 'clevermail_nouveautes_text'); |
---|
11 | // _CLEVERMAIL_NOUVEAUTES_TEXT_OPTION est facultatif. Il permet de completer l'url amorcee avec _CLEVERMAIL_NOUVEAUTES_TEXT. |
---|
12 | // define("_CLEVERMAIL_NOUVEAUTES_TEXT_OPTION", 'cat=mot&sujet=1&pied=1&entete=1'); |
---|
13 | if ($valeurs = sql_fetsel('*', 'spip_cm_lists', 'lst_id='.intval($lst_id))) { |
---|
14 | $valeurs['lst_auto_week_days'] = explode(',', $valeurs['lst_auto_week_days']); |
---|
15 | } else { |
---|
16 | $cm_mail_admin = sql_getfetsel('set_value', 'spip_cm_settings', 'set_name="CM_MAIL_ADMIN"'); |
---|
17 | if (defined('_CLEVERMAIL_NOUVEAUTES_HTML_OPTION')) { |
---|
18 | if (_CLEVERMAIL_DISTANT) { |
---|
19 | $url_html = generer_url_public(_CLEVERMAIL_NOUVEAUTES_HTML,_CLEVERMAIL_NOUVEAUTES_HTML_OPTION); |
---|
20 | } else { |
---|
21 | $url_html = _CLEVERMAIL_NOUVEAUTES_HTML; |
---|
22 | } |
---|
23 | } else { |
---|
24 | if (_CLEVERMAIL_DISTANT) { |
---|
25 | $url_html = generer_url_public(_CLEVERMAIL_NOUVEAUTES_HTML); |
---|
26 | } else { |
---|
27 | $url_html = _CLEVERMAIL_NOUVEAUTES_HTML; |
---|
28 | } |
---|
29 | } |
---|
30 | if (defined('_CLEVERMAIL_NOUVEAUTES_TEXT_OPTION')) { |
---|
31 | if (_CLEVERMAIL_DISTANT) { |
---|
32 | $url_text = generer_url_public(_CLEVERMAIL_NOUVEAUTES_TEXT,_CLEVERMAIL_NOUVEAUTES_TEXT_OPTION); |
---|
33 | } else { |
---|
34 | $url_text = _CLEVERMAIL_NOUVEAUTES_TEXT; |
---|
35 | } |
---|
36 | } else { |
---|
37 | if (_CLEVERMAIL_DISTANT) { |
---|
38 | $url_text = generer_url_public(_CLEVERMAIL_NOUVEAUTES_TEXT); |
---|
39 | } else { |
---|
40 | $url_text = _CLEVERMAIL_NOUVEAUTES_TEXT; |
---|
41 | } |
---|
42 | } |
---|
43 | $valeurs = array( |
---|
44 | 'lst_id' => -1, |
---|
45 | 'lst_name' => '', |
---|
46 | 'lst_comment' => '', |
---|
47 | 'lst_moderation' => 'closed', |
---|
48 | 'lst_moderator_email' => $cm_mail_admin, |
---|
49 | 'lst_subscribe_subject' => _T('clevermail:confirmation_votre_inscription'), |
---|
50 | 'lst_subscribe_text' => _T('clevermail:confirmation_votre_inscription_text'), |
---|
51 | 'lst_subject' => '', |
---|
52 | 'lst_unsubscribe_subject' => _T('clevermail:confirmation_votre_desinscription'), |
---|
53 | 'lst_unsubscribe_text' => _T('clevermail:confirmation_votre_desinscription_text'), |
---|
54 | 'lst_subject_tag' => 1, |
---|
55 | //'lst_url_html' => $GLOBALS['meta']['adresse_site'].'/?page=clevermail_nouveautes_html', |
---|
56 | 'lst_url_html' => $url_html, |
---|
57 | //'lst_url_text' => $GLOBALS['meta']['adresse_site'].'/?page=clevermail_nouveautes_text', |
---|
58 | 'lst_url_text' => $url_text, |
---|
59 | 'lst_auto_mode' => 'none', |
---|
60 | 'lst_auto_hour' => 8, |
---|
61 | 'lst_auto_week_days' => array(1), |
---|
62 | 'lst_auto_month_day' => 1, |
---|
63 | 'lst_auto_subscribers' => '', |
---|
64 | 'lst_auto_subscribers_mode' => 0 |
---|
65 | ); |
---|
66 | } |
---|
67 | return $valeurs; |
---|
68 | } |
---|
69 | |
---|
70 | function formulaires_clevermail_list_edit_verifier_dist($lst_id = -1) { |
---|
71 | $erreurs = array(); |
---|
72 | foreach(array('lst_name', 'lst_moderator_email', 'lst_url_html', 'lst_url_text') as $obligatoire) { |
---|
73 | if (!_request($obligatoire)) { |
---|
74 | $erreurs[$obligatoire] = _T('clevermail:ce_champ_est_obligatoire'); |
---|
75 | } |
---|
76 | } |
---|
77 | $nb = sql_countsel("spip_cm_lists", "lst_id != ".intval(_request('lst_id'))." AND lst_name = ".sql_quote(_request('lst_name'))); |
---|
78 | if ($nb > 0) { |
---|
79 | $erreurs['lst_name'] = _T('clevermail:lettre_meme_nom'); |
---|
80 | } |
---|
81 | include_spip('inc/filtres'); |
---|
82 | if (_request('lst_moderator_email') && !email_valide(_request('lst_moderator_email'))) { |
---|
83 | $erreurs['lst_moderator_email'] = _T('clevermail:cette_adresse_email_n_est_pas_valide'); |
---|
84 | } |
---|
85 | if (_request('lst_auto_mode') && _request('lst_auto_mode') != 'none') { |
---|
86 | if (in_array(_request('lst_auto_mode'), array('day', 'week', 'month'))) { |
---|
87 | if (_request('lst_auto_hour') && (intval(_request('lst_auto_hour')) < 0 || intval(_request('lst_auto_hour')) > 23)) { |
---|
88 | $erreurs['lst_auto_hour'] = _T('clevermail:auto_erreur_cette_heure_existe_pas'); |
---|
89 | } |
---|
90 | switch(_request('lst_auto_mode')) { |
---|
91 | case 'day': |
---|
92 | break; |
---|
93 | case 'week': |
---|
94 | if (!_request('lst_auto_week_days') || count(_request('lst_auto_week_days')) == 0) { |
---|
95 | $erreurs['lst_auto_week_days'] = _T('clevermail:auto_erreur_choisir_un_jour_minimum'); |
---|
96 | } elseif (min(_request('lst_auto_week_days')) < 0 || max(_request('lst_auto_week_days')) > 6) { |
---|
97 | $erreurs['lst_auto_week_days'] = _T('clevermail:auto_erreur_ce_jour_semaine_existe_pas'); |
---|
98 | } |
---|
99 | break; |
---|
100 | case 'month': |
---|
101 | if (_request('lst_auto_month_day') && (intval(_request('lst_auto_month_day')) < 0 || intval(_request('lst_auto_month_day')) > 31)) { |
---|
102 | $erreurs['lst_auto_month_day'] = _T('clevermail:auto_erreur_ce_jour_mois_existe_pas'); |
---|
103 | } elseif (intval(_request('lst_auto_month_day')) > 28) { |
---|
104 | $erreurs['lst_auto_month_day'] = _T('clevermail:auto_erreur_ce_jour_mois_pas_possible'); |
---|
105 | } |
---|
106 | break; |
---|
107 | } |
---|
108 | } else { |
---|
109 | $erreurs['lst_auto_mode'] = _T('clevermail:auto_erreur_ce_mode_automatisation_existe_pas'); |
---|
110 | } |
---|
111 | } |
---|
112 | if (_request('lst_auto_subscribers') != '') { |
---|
113 | include_spip('inc/distant'); |
---|
114 | if ($adresses = recuperer_page(_request('lst_auto_subscribers'))) { |
---|
115 | include_spip('inc/clevermail_abonnes'); |
---|
116 | if (!clevermail_verification_adresses_email($adresses)) { |
---|
117 | $erreurs['lst_auto_subscribers'] = _T('clevermail:le_format_des_adresses_email_ne_semble_pas_bon'); |
---|
118 | } |
---|
119 | } else { |
---|
120 | $erreurs['lst_auto_subscribers'] = _T('clevermail:fichier_adresses_distant_impossible_telecharger'); |
---|
121 | } |
---|
122 | } |
---|
123 | if (count($erreurs)) { |
---|
124 | $erreurs['message_erreur'] = _T('clevermail:veuillez_corriger_votre_saisie'); |
---|
125 | } |
---|
126 | return $erreurs; |
---|
127 | } |
---|
128 | |
---|
129 | function formulaires_clevermail_list_edit_traiter_dist($lst_id = -1) { |
---|
130 | $champs = array( |
---|
131 | 'lst_name' => _request('lst_name'), |
---|
132 | 'lst_comment' => _request('lst_comment'), |
---|
133 | 'lst_moderation' => _request('lst_moderation'), |
---|
134 | 'lst_moderator_email' => _request('lst_moderator_email'), |
---|
135 | 'lst_subscribe_subject' => _request('lst_subscribe_subject'), |
---|
136 | 'lst_subscribe_text' => _request('lst_subscribe_text'), |
---|
137 | 'lst_subject' => _request('lst_subject'), |
---|
138 | 'lst_unsubscribe_subject' => _request('lst_unsubscribe_subject'), |
---|
139 | 'lst_unsubscribe_text' => _request('lst_unsubscribe_text'), |
---|
140 | 'lst_subject_tag' => _request('lst_subject_tag'), |
---|
141 | 'lst_url_html' => _request('lst_url_html'), |
---|
142 | 'lst_url_text' => _request('lst_url_text'), |
---|
143 | 'lst_auto_mode' => _request('lst_auto_mode'), |
---|
144 | 'lst_auto_hour' => intval(_request('lst_auto_hour')), |
---|
145 | 'lst_auto_week_days' => implode(',', _request('lst_auto_week_days')), |
---|
146 | 'lst_auto_month_day' => intval(_request('lst_auto_month_day')), |
---|
147 | 'lst_auto_subscribers' => _request('lst_auto_subscribers'), |
---|
148 | 'lst_auto_subscribers_mode' => intval(_request('lst_auto_subscribers_mode')) |
---|
149 | ); |
---|
150 | |
---|
151 | // Handle checkbox value |
---|
152 | if (isset($list['lst_subject_tag']) && ($list['lst_subject_tag'] == 'on' || $list['lst_subject_tag'] == 1)) { |
---|
153 | $champs['lst_subject_tag'] = 1; |
---|
154 | } |
---|
155 | |
---|
156 | if (_request('lst_id') == -1) { |
---|
157 | sql_insertq('spip_cm_lists', $champs); |
---|
158 | // XXX : log en chaîne de langue |
---|
159 | spip_log('Nouvelle liste « '._request('lst_name').' »', 'clevermail'); |
---|
160 | } else { |
---|
161 | sql_updateq('spip_cm_lists', $champs, "lst_id = ".intval(_request('lst_id'))); |
---|
162 | // XXX : log en chaîne de langue |
---|
163 | spip_log('Modification de la liste « '._request('lst_name').' » (id = '._request('lst_id').')', 'clevermail'); |
---|
164 | } |
---|
165 | |
---|
166 | return array('message_ok' => 'ok', 'redirect' => generer_url_ecrire('clevermail_lists')); |
---|
167 | } |
---|
168 | ?> |
---|