dolibarr 24.0.0-beta
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-2025 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
45// Load translation files required by the page
46$langs->loadLangs(array("admin", "members", "mailmanspip"));
47
48if (!$user->admin) {
50}
51
52
53
54$action = GETPOST('action', 'aZ09');
55$testsubscribeemail = GETPOST("testsubscribeemail");
56$testunsubscribeemail = GETPOST("testunsubscribeemail");
57
58$error = 0;
59
60
61/*
62 * Actions
63 */
64
65// Action updated or added a constant
66if ($action == 'update' || $action == 'add') {
67 $tmparray = GETPOST('constname', 'array');
68 $tmpvalue = GETPOST('constvalue', 'array');
69 $tmpnote = GETPOST('constnote', 'array');
70 if (is_array($tmparray)) {
71 foreach ($tmparray as $key => $val) {
72 $constname = $tmparray[$key];
73 $constvalue = $tmpvalue[$key];
74 $constnote = $tmpnote[$key];
75 $res = dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, $constnote, $conf->entity);
76
77 if (!($res > 0)) {
78 $error++;
79 }
80 }
81 }
82
83 if (!$error) {
84 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
85 } else {
86 setEventMessages($langs->trans("Error"), null, 'errors');
87 }
88}
89
90// Action to activate a submodule of the 'adherent' module
91if ($action == 'set') {
92 $result = dolibarr_set_const($db, GETPOST("name", 'aZ09'), GETPOST("value"), '', 0, '', $conf->entity);
93 if ($result < 0) {
95 }
96}
97
98// Action to deactivate a submodule of the 'adherent' module
99if ($action == 'unset') {
100 $result = dolibarr_del_const($db, GETPOST("name", 'aZ09'), $conf->entity);
101 if ($result < 0) {
103 }
104}
105
106if (($action == 'testsubscribe' || $action == 'testunsubscribe') && getDolGlobalString('ADHERENT_USE_MAILMAN')) {
107 $email = GETPOST($action.'email');
108 if (!isValidEmail($email)) {
109 $langs->load("errors");
110 setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
111 } else {
112 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
113 $mailmanspip = new MailmanSpip($db);
114
115 $object = new stdClass();
116 $object->email = $email;
117 $object->pass = $email;
118 /*$object->element='member';
119 $object->type='Preferred Partners'; */
120
121 if ($action == 'testsubscribe') {
122 $result = $mailmanspip->add_to_mailman($object);
123 if ($result < 0) {
124 $error++;
125 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
126 } else {
127 setEventMessages($langs->trans("MailmanCreationSuccess"), null);
128 }
129 }
130 if ($action == 'testunsubscribe') {
131 $result = $mailmanspip->del_to_mailman($object);
132 if ($result < 0) {
133 $error++;
134 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
135 } else {
136 setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
137 }
138 }
139 }
140}
141
142
143/*
144 * View
145 */
146
147$help_url = '';
148
149llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url, '', 0, 0, '', '', '', 'mod-admin page-mailman');
150
151
152$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
153
154print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
155
156$head = mailmanspip_admin_prepare_head();
157
158if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
159 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
160 print '<input type="hidden" name="token" value="'.newToken().'">';
161 print '<input type="hidden" name="action" value="update">';
162
163 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
164
165 //$link=img_picto($langs->trans("Active"),'tick').' ';
166 $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">';
167 //$link.=$langs->trans("Disable");
168 $link .= img_picto($langs->trans("Activated"), 'switch_on');
169 $link .= '</a>';
170 // Edit the global variables
171 $constantes = array(
172 'ADHERENT_MAILMAN_ADMIN_PASSWORD',
173 'ADHERENT_MAILMAN_URL',
174 'ADHERENT_MAILMAN_UNSUB_URL',
175 'ADHERENT_MAILMAN_LISTS'
176 );
177
178 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
179
180 print '<br>';
181
182 // JQuery activity
183 print '<script type="text/javascript">
184 var i1=0;
185 var i2=0;
186 var i3=0;
187 jQuery(document).ready(function(){
188 jQuery("#exampleclick1").click(function(event){
189 if (i1 == 0) { jQuery("#example1").show(); i1=1; }
190 else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
191 });
192 jQuery("#exampleclick2").click(function(){
193 if (i2 == 0) { jQuery("#example2").show(); i2=1; }
194 else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
195 });
196 jQuery("#exampleclick3").click(function(){
197 if (i3 == 0) { jQuery("#example3").show(); i3=1; }
198 else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
199 });
200 });
201 </script>';
202
203 form_constantes($constantes, 2);
204
205 print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
206 print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
207
208 print dol_get_fiche_end();
209
210 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
211
212 print '</form>';
213} else {
214 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
215
216 $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">';
217 //$link.=img_$langs->trans("Activate")
218 $link .= img_picto($langs->trans("Disabled"), 'switch_off');
219 $link .= '</a>';
220 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
221
222 print dol_get_fiche_end();
223}
224
225
226if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
227 print '<form action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
228 print '<input type="hidden" name="token" value="'.newToken().'">';
229 print '<input type="hidden" name="action" value="testsubscribe">';
230
231 print $langs->trans("TestSubscribe").'<br>';
232 print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
233
234 print '</form>';
235
236 print '<form action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
237 print '<input type="hidden" name="token" value="'.newToken().'">';
238 print '<input type="hidden" name="action" value="testunsubscribe">';
239
240 print $langs->trans("TestUnSubscribe").'<br>';
241 print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
242
243 print '</form>';
244}
245
246// End of page
247llxFooter();
248$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
form_constantes($tableau, $strictw3c=2, $helptext='', $text='')
Show array with constants to edit.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage mailman and spip.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.