dolibarr  19.0.0-dev
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 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("admin", "members", "mailmanspip"));
38 
39 if (!$user->admin) {
41 }
42 
43 
44 $type = array('yesno', 'texte', 'chaine');
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
58 if ($action == 'update' || $action == 'add') {
59  $tmparray = GETPOST('constname', 'array');
60  if (is_array($tmparray)) {
61  foreach ($tmparray as $key => $val) {
62  $constname = $tmparray[$key];
63  $constvalue = $tmparray[$key];
64  $consttype = $tmparray[$key];
65  $constnote = $tmparray[$key];
66  $res = dolibarr_set_const($db, $constname, $constvalue, $type[$consttype], 0, $constnote, $conf->entity);
67 
68  if (!($res > 0)) {
69  $error++;
70  }
71  }
72  }
73 
74  if (!$error) {
75  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
76  } else {
77  setEventMessages($langs->trans("Error"), null, 'errors');
78  }
79 }
80 
81 // Action activation d'un sous module du module adherent
82 if ($action == 'set') {
83  $result = dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity);
84  if ($result < 0) {
85  dol_print_error($db);
86  }
87 }
88 
89 // Action desactivation d'un sous module du module adherent
90 if ($action == 'unset') {
91  $result = dolibarr_del_const($db, $_GET["name"], $conf->entity);
92  if ($result < 0) {
93  dol_print_error($db);
94  }
95 }
96 
97 if (($action == 'testsubscribe' || $action == 'testunsubscribe') && !empty($conf->global->ADHERENT_USE_MAILMAN)) {
98  $email = GETPOST($action.'email');
99  if (!isValidEmail($email)) {
100  $langs->load("errors");
101  setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
102  } else {
103  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
104  $mailmanspip = new MailmanSpip($db);
105 
106  $object = new stdClass();
107  $object->email = $email;
108  $object->pass = $email;
109  /*$object->element='member';
110  $object->type='Preferred Partners'; */
111 
112  if ($action == 'testsubscribe') {
113  $result = $mailmanspip->add_to_mailman($object);
114  if ($result < 0) {
115  $error++;
116  setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
117  } else {
118  setEventMessages($langs->trans("MailmanCreationSuccess"), null);
119  }
120  }
121  if ($action == 'testunsubscribe') {
122  $result = $mailmanspip->del_to_mailman($object);
123  if ($result < 0) {
124  $error++;
125  setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
126  } else {
127  setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
128  }
129  }
130  }
131 }
132 
133 
134 /*
135  * View
136  */
137 
138 $help_url = '';
139 
140 llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url);
141 
142 
143 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
144 print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
145 
146 $head = mailmanspip_admin_prepare_head();
147 
148 if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
149  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
150  print '<input type="hidden" name="token" value="'.newToken().'">';
151  print '<input type="hidden" name="action" value="update">';
152 
153  print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
154 
155  //$link=img_picto($langs->trans("Active"),'tick').' ';
156  $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">';
157  //$link.=$langs->trans("Disable");
158  $link .= img_picto($langs->trans("Activated"), 'switch_on');
159  $link .= '</a>';
160  // Edition des varibales globales
161  $constantes = array(
162  'ADHERENT_MAILMAN_ADMIN_PASSWORD',
163  'ADHERENT_MAILMAN_URL',
164  'ADHERENT_MAILMAN_UNSUB_URL',
165  'ADHERENT_MAILMAN_LISTS'
166  );
167 
168  print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
169 
170  print '<br>';
171 
172  // JQuery activity
173  print '<script type="text/javascript">
174  var i1=0;
175  var i2=0;
176  var i3=0;
177  jQuery(document).ready(function(){
178  jQuery("#exampleclick1").click(function(event){
179  if (i1 == 0) { jQuery("#example1").show(); i1=1; }
180  else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
181  });
182  jQuery("#exampleclick2").click(function(){
183  if (i2 == 0) { jQuery("#example2").show(); i2=1; }
184  else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
185  });
186  jQuery("#exampleclick3").click(function(){
187  if (i3 == 0) { jQuery("#example3").show(); i3=1; }
188  else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
189  });
190  });
191  </script>';
192 
193  form_constantes($constantes, 2);
194 
195  print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
196  print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
197 
198  print dol_get_fiche_end();
199 
200  print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
201 
202  print '</form>';
203 } else {
204  print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
205 
206  $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">';
207  //$link.=img_$langs->trans("Activate")
208  $link .= img_picto($langs->trans("Disabled"), 'switch_off');
209  $link .= '</a>';
210  print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
211 
212  print dol_get_fiche_end();
213 }
214 
215 
216 if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
217  print '<form action="'.$_SERVER["PHP_SELF"].'">';
218  print '<input type="hidden" name="token" value="'.newToken().'">';
219  print '<input type="hidden" name="action" value="testsubscribe">';
220 
221  print $langs->trans("TestSubscribe").'<br>';
222  print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
223 
224  print '</form>';
225 
226  print '<form action="'.$_SERVER["PHP_SELF"].'">';
227  print '<input type="hidden" name="token" value="'.newToken().'">';
228  print '<input type="hidden" name="action" value="testunsubscribe">';
229 
230  print $langs->trans("TestUnSubscribe").'<br>';
231  print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input type="submit" class="button" value="'.$langs->trans("Test").'"><br>';
232 
233  print '</form>';
234 }
235 
236 // End of page
237 llxFooter();
238 $db->close();
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:118
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:638
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:562
form_constantes($tableau, $strictw3c=0, $helptext='', $text='Value')
Show array with constants to edit.
Definition: admin.lib.php:1662
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage mailman and spip.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.