dolibarr 21.0.0-alpha
mailman.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array("admin", "members", "mailmanspip"));
39
40if (!$user->admin) {
42}
43
44
45
46$action = GETPOST('action', 'aZ09');
47$testsubscribeemail = GETPOST("testsubscribeemail");
48$testunsubscribeemail = GETPOST("testunsubscribeemail");
49
50$error = 0;
51
52
53/*
54 * Actions
55 */
56
57// Action updated or added a constant
58if ($action == 'update' || $action == 'add') {
59 $tmparray = GETPOST('constname', 'array');
60 $tmpvalue = GETPOST('constvalue', 'array');
61 $tmpnote = GETPOST('constnote', 'array');
62 if (is_array($tmparray)) {
63 foreach ($tmparray as $key => $val) {
64 $constname = $tmparray[$key];
65 $constvalue = $tmpvalue[$key];
66 $constnote = $tmpnote[$key];
67 $res = dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, $constnote, $conf->entity);
68
69 if (!($res > 0)) {
70 $error++;
71 }
72 }
73 }
74
75 if (!$error) {
76 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
77 } else {
78 setEventMessages($langs->trans("Error"), null, 'errors');
79 }
80}
81
82// Action to activate a submodule of the 'adherent' module
83if ($action == 'set') {
84 $result = dolibarr_set_const($db, GETPOST("name", 'aZ09'), GETPOST("value"), '', 0, '', $conf->entity);
85 if ($result < 0) {
86 dol_print_error($db);
87 }
88}
89
90// Action to deactivate a submodule of the 'adherent' module
91if ($action == 'unset') {
92 $result = dolibarr_del_const($db, GETPOST("name", 'aZ09'), $conf->entity);
93 if ($result < 0) {
94 dol_print_error($db);
95 }
96}
97
98if (($action == 'testsubscribe' || $action == 'testunsubscribe') && getDolGlobalString('ADHERENT_USE_MAILMAN')) {
99 $email = GETPOST($action.'email');
100 if (!isValidEmail($email)) {
101 $langs->load("errors");
102 setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
103 } else {
104 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
105 $mailmanspip = new MailmanSpip($db);
106
107 $object = new stdClass();
108 $object->email = $email;
109 $object->pass = $email;
110 /*$object->element='member';
111 $object->type='Preferred Partners'; */
112
113 if ($action == 'testsubscribe') {
114 $result = $mailmanspip->add_to_mailman($object);
115 if ($result < 0) {
116 $error++;
117 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
118 } else {
119 setEventMessages($langs->trans("MailmanCreationSuccess"), null);
120 }
121 }
122 if ($action == 'testunsubscribe') {
123 $result = $mailmanspip->del_to_mailman($object);
124 if ($result < 0) {
125 $error++;
126 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
127 } else {
128 setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
129 }
130 }
131 }
132}
133
134
135/*
136 * View
137 */
138
139$help_url = '';
140
141llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url, '', 0, 0, '', '', '', 'mod-admin page-mailman');
142
143
144$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
145print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
146
147$head = mailmanspip_admin_prepare_head();
148
149if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
150 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
151 print '<input type="hidden" name="token" value="'.newToken().'">';
152 print '<input type="hidden" name="action" value="update">';
153
154 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
155
156 //$link=img_picto($langs->trans("Active"),'tick').' ';
157 $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">';
158 //$link.=$langs->trans("Disable");
159 $link .= img_picto($langs->trans("Activated"), 'switch_on');
160 $link .= '</a>';
161 // Edit the global variables
162 $constantes = array(
163 'ADHERENT_MAILMAN_ADMIN_PASSWORD',
164 'ADHERENT_MAILMAN_URL',
165 'ADHERENT_MAILMAN_UNSUB_URL',
166 'ADHERENT_MAILMAN_LISTS'
167 );
168
169 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
170
171 print '<br>';
172
173 // JQuery activity
174 print '<script type="text/javascript">
175 var i1=0;
176 var i2=0;
177 var i3=0;
178 jQuery(document).ready(function(){
179 jQuery("#exampleclick1").click(function(event){
180 if (i1 == 0) { jQuery("#example1").show(); i1=1; }
181 else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
182 });
183 jQuery("#exampleclick2").click(function(){
184 if (i2 == 0) { jQuery("#example2").show(); i2=1; }
185 else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
186 });
187 jQuery("#exampleclick3").click(function(){
188 if (i3 == 0) { jQuery("#example3").show(); i3=1; }
189 else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
190 });
191 });
192 </script>';
193
194 form_constantes($constantes, 2);
195
196 print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
197 print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
198
199 print dol_get_fiche_end();
200
201 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
202
203 print '</form>';
204} else {
205 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
206
207 $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">';
208 //$link.=img_$langs->trans("Activate")
209 $link .= img_picto($langs->trans("Disabled"), 'switch_off');
210 $link .= '</a>';
211 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
212
213 print dol_get_fiche_end();
214}
215
216
217if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
218 print '<form action="'.$_SERVER["PHP_SELF"].'">';
219 print '<input type="hidden" name="token" value="'.newToken().'">';
220 print '<input type="hidden" name="action" value="testsubscribe">';
221
222 print $langs->trans("TestSubscribe").'<br>';
223 print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
224
225 print '</form>';
226
227 print '<form action="'.$_SERVER["PHP_SELF"].'">';
228 print '<input type="hidden" name="token" value="'.newToken().'">';
229 print '<input type="hidden" name="action" value="testunsubscribe">';
230
231 print $langs->trans("TestUnSubscribe").'<br>';
232 print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
233
234 print '</form>';
235}
236
237// End of page
238llxFooter();
239$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
form_constantes($tableau, $strictw3c=2, $helptext='', $text='Value')
Show array with constants to edit.
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage mailman and spip.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.