dolibarr  16.0.5
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  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("admin", "members", "mailmanspip"));
37 
38 if (!$user->admin) {
40 }
41 
42 
43 $type = array('yesno', 'texte', 'chaine');
44 
45 $action = GETPOST('action', 'aZ09');
46 $testsubscribeemail = GETPOST("testsubscribeemail");
47 $testunsubscribeemail = GETPOST("testunsubscribeemail");
48 
49 $error = 0;
50 
51 
52 /*
53  * Actions
54  */
55 
56 // Action updated or added a constant
57 if ($action == 'update' || $action == 'add') {
58  $tmparray = GETPOST('constname', 'array');
59  if (is_array($tmparray)) {
60  foreach ($tmparray as $key => $val) {
61  $constname = $tmparray[$key];
62  $constvalue = $tmparray[$key];
63  $consttype = $tmparray[$key];
64  $constnote = $tmparray[$key];
65  $res = dolibarr_set_const($db, $constname, $constvalue, $type[$consttype], 0, $constnote, $conf->entity);
66 
67  if (!($res > 0)) {
68  $error++;
69  }
70  }
71  }
72 
73  if (!$error) {
74  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
75  } else {
76  setEventMessages($langs->trans("Error"), null, 'errors');
77  }
78 }
79 
80 // Action activation d'un sous module du module adherent
81 if ($action == 'set') {
82  $result = dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity);
83  if ($result < 0) {
84  dol_print_error($db);
85  }
86 }
87 
88 // Action desactivation d'un sous module du module adherent
89 if ($action == 'unset') {
90  $result = dolibarr_del_const($db, $_GET["name"], $conf->entity);
91  if ($result < 0) {
92  dol_print_error($db);
93  }
94 }
95 
96 if (($action == 'testsubscribe' || $action == 'testunsubscribe') && !empty($conf->global->ADHERENT_USE_MAILMAN)) {
97  $email = GETPOST($action.'email');
98  if (!isValidEmail($email)) {
99  $langs->load("errors");
100  setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
101  } else {
102  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
103  $mailmanspip = new MailmanSpip($db);
104 
105  $object = new stdClass();
106  $object->email = $email;
107  $object->pass = $email;
108  /*$object->element='member';
109  $object->type='Preferred Partners'; */
110 
111  if ($action == 'testsubscribe') {
112  $result = $mailmanspip->add_to_mailman($object);
113  if ($result < 0) {
114  $error++;
115  setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
116  } else {
117  setEventMessages($langs->trans("MailmanCreationSuccess"), null);
118  }
119  }
120  if ($action == 'testunsubscribe') {
121  $result = $mailmanspip->del_to_mailman($object);
122  if ($result < 0) {
123  $error++;
124  setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
125  } else {
126  setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
127  }
128  }
129  }
130 }
131 
132 
133 /*
134  * View
135  */
136 
137 $help_url = '';
138 
139 llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url);
140 
141 
142 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
143 print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
144 
145 $head = mailmanspip_admin_prepare_head();
146 
147 if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
148  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
149  print '<input type="hidden" name="token" value="'.newToken().'">';
150  print '<input type="hidden" name="action" value="update">';
151 
152  print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
153 
154  //$link=img_picto($langs->trans("Active"),'tick').' ';
155  $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">';
156  //$link.=$langs->trans("Disable");
157  $link .= img_picto($langs->trans("Activated"), 'switch_on');
158  $link .= '</a>';
159  // Edition des varibales globales
160  $constantes = array(
161  'ADHERENT_MAILMAN_ADMINPW',
162  'ADHERENT_MAILMAN_URL',
163  'ADHERENT_MAILMAN_UNSUB_URL',
164  'ADHERENT_MAILMAN_LISTS'
165  );
166 
167  print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
168 
169  print '<br>';
170 
171  // JQuery activity
172  print '<script type="text/javascript">
173  var i1=0;
174  var i2=0;
175  var i3=0;
176  jQuery(document).ready(function(){
177  jQuery("#exampleclick1").click(function(event){
178  if (i1 == 0) { jQuery("#example1").show(); i1=1; }
179  else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
180  });
181  jQuery("#exampleclick2").click(function(){
182  if (i2 == 0) { jQuery("#example2").show(); i2=1; }
183  else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
184  });
185  jQuery("#exampleclick3").click(function(){
186  if (i3 == 0) { jQuery("#example3").show(); i3=1; }
187  else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
188  });
189  });
190  </script>';
191 
192  form_constantes($constantes, 2);
193 
194  print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
195  print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
196 
197  print dol_get_fiche_end();
198 
199  print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
200 
201  print '</form>';
202 } else {
203  print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
204 
205  $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">';
206  //$link.=img_$langs->trans("Activate")
207  $link .= img_picto($langs->trans("Disabled"), 'switch_off');
208  $link .= '</a>';
209  print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
210 
211  print dol_get_fiche_end();
212 }
213 
214 
215 if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
216  print '<form action="'.$_SERVER["PHP_SELF"].'">';
217  print '<input type="hidden" name="token" value="'.newToken().'">';
218  print '<input type="hidden" name="action" value="testsubscribe">';
219 
220  print $langs->trans("TestSubscribe").'<br>';
221  print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
222 
223  print '</form>';
224 
225  print '<form action="'.$_SERVER["PHP_SELF"].'">';
226  print '<input type="hidden" name="token" value="'.newToken().'">';
227  print '<input type="hidden" name="action" value="testunsubscribe">';
228 
229  print $langs->trans("TestUnSubscribe").'<br>';
230  print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
231 
232  print '</form>';
233 }
234 
235 // End of page
236 llxFooter();
237 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
dolibarr_del_const
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:552
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
MailmanSpip
Class to manage mailman and spip.
Definition: mailmanspip.class.php:40
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
isValidEmail
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
Definition: functions.lib.php:3681
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
form_constantes
form_constantes($tableau, $strictw3c=0, $helptext='', $text='Value')
Show array with constants to edit.
Definition: admin.lib.php:1619
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59