dolibarr 21.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 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) {
94 dol_print_error($db);
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) {
102 dol_print_error($db);
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="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
153print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
154
155$head = mailmanspip_admin_prepare_head();
156
157if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
158 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
159 print '<input type="hidden" name="token" value="'.newToken().'">';
160 print '<input type="hidden" name="action" value="update">';
161
162 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
163
164 //$link=img_picto($langs->trans("Active"),'tick').' ';
165 $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">';
166 //$link.=$langs->trans("Disable");
167 $link .= img_picto($langs->trans("Activated"), 'switch_on');
168 $link .= '</a>';
169 // Edit the global variables
170 $constantes = array(
171 'ADHERENT_MAILMAN_ADMIN_PASSWORD',
172 'ADHERENT_MAILMAN_URL',
173 'ADHERENT_MAILMAN_UNSUB_URL',
174 'ADHERENT_MAILMAN_LISTS'
175 );
176
177 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
178
179 print '<br>';
180
181 // JQuery activity
182 print '<script type="text/javascript">
183 var i1=0;
184 var i2=0;
185 var i3=0;
186 jQuery(document).ready(function(){
187 jQuery("#exampleclick1").click(function(event){
188 if (i1 == 0) { jQuery("#example1").show(); i1=1; }
189 else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
190 });
191 jQuery("#exampleclick2").click(function(){
192 if (i2 == 0) { jQuery("#example2").show(); i2=1; }
193 else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
194 });
195 jQuery("#exampleclick3").click(function(){
196 if (i3 == 0) { jQuery("#example3").show(); i3=1; }
197 else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
198 });
199 });
200 </script>';
201
202 form_constantes($constantes, 2);
203
204 print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
205 print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
206
207 print dol_get_fiche_end();
208
209 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
210
211 print '</form>';
212} else {
213 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
214
215 $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">';
216 //$link.=img_$langs->trans("Activate")
217 $link .= img_picto($langs->trans("Disabled"), 'switch_off');
218 $link .= '</a>';
219 print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
220
221 print dol_get_fiche_end();
222}
223
224
225if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
226 print '<form action="'.$_SERVER["PHP_SELF"].'">';
227 print '<input type="hidden" name="token" value="'.newToken().'">';
228 print '<input type="hidden" name="action" value="testsubscribe">';
229
230 print $langs->trans("TestSubscribe").'<br>';
231 print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
232
233 print '</form>';
234
235 print '<form action="'.$_SERVER["PHP_SELF"].'">';
236 print '<input type="hidden" name="token" value="'.newToken().'">';
237 print '<input type="hidden" name="action" value="testunsubscribe">';
238
239 print $langs->trans("TestUnSubscribe").'<br>';
240 print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
241
242 print '</form>';
243}
244
245// End of page
246llxFooter();
247$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.