dolibarr  9.0.0
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 <http://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) accessforbidden();
39 
40 
41 $type=array('yesno','texte','chaine');
42 
43 $action = GETPOST('action','aZ09');
44 $testsubscribeemail = GETPOST("testsubscribeemail");
45 $testunsubscribeemail = GETPOST("testunsubscribeemail");
46 
47 /*
48  * Actions
49  */
50 
51 // Action updated or added a constant
52 if ($action == 'update' || $action == 'add')
53 {
54  foreach($_POST['constname'] as $key => $val)
55  {
56  $constname=$_POST["constname"][$key];
57  $constvalue=$_POST["constvalue"][$key];
58  $consttype=$_POST["consttype"][$key];
59  $constnote=$_POST["constnote"][$key];
60  $res=dolibarr_set_const($db,$constname,$constvalue,$type[$consttype],0,$constnote,$conf->entity);
61 
62  if (! $res > 0) $error++;
63  }
64 
65  if (! $error)
66  {
67  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
68  }
69  else
70  {
71  setEventMessages($langs->trans("Error"), null, 'errors');
72  }
73 }
74 
75 // Action activation d'un sous module du module adherent
76 if ($action == 'set')
77 {
78  $result=dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity);
79  if ($result < 0)
80  {
81  dol_print_error($db);
82  }
83 }
84 
85 // Action desactivation d'un sous module du module adherent
86 if ($action == 'unset')
87 {
88  $result=dolibarr_del_const($db, $_GET["name"], $conf->entity);
89  if ($result < 0)
90  {
91  dol_print_error($db);
92  }
93 }
94 
95 if (($action == 'testsubscribe' || $action == 'testunsubscribe') && ! empty($conf->global->ADHERENT_USE_MAILMAN))
96 {
97  $email=GETPOST($action.'email');
98  if (! isValidEmail($email))
99  {
100  $langs->load("errors");
101  setEventMessages($langs->trans("ErrorBadEMail",$email), null, 'errors');
102  }
103  else
104  {
105  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
106  $mailmanspip=new MailmanSpip($db);
107 
108  $object=new stdClass();
109  $object->email=$email;
110  $object->pass=$email;
111  /*$object->element='member';
112  $object->type='Preferred Partners'; */
113 
114  if ($action == 'testsubscribe')
115  {
116  $result=$mailmanspip->add_to_mailman($object);
117  if ($result < 0)
118  {
119  $error++;
120  setEventMessages($mailmanspip->error,$mailmanspip->errors,'errors');
121  }
122  else
123  {
124  setEventMessages($langs->trans("MailmanCreationSuccess"), null);
125  }
126  }
127  if ($action == 'testunsubscribe')
128  {
129  $result=$mailmanspip->del_to_mailman($object);
130  if ($result < 0)
131  {
132  $error++;
133  setEventMessages($mailmanspip->error,$mailmanspip->errors,'errors');
134  }
135  else
136  {
137  setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
138  }
139  }
140  }
141 }
142 
143 
144 /*
145  * View
146  */
147 
148 $help_url='';
149 
150 llxHeader('',$langs->trans("MailmanSpipSetup"),$help_url);
151 
152 
153 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
154 print load_fiche_titre($langs->trans("MailmanSpipSetup"),$linkback,'title_setup');
155 
156 $head = mailmanspip_admin_prepare_head();
157 
158 if (! empty($conf->global->ADHERENT_USE_MAILMAN))
159 {
160  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
161 
162  dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
163 
164  //$link=img_picto($langs->trans("Active"),'tick').' ';
165  $link='<a href="'.$_SERVER["PHP_SELF"].'?action=unset&value=0&name=ADHERENT_USE_MAILMAN">';
166  //$link.=$langs->trans("Disable");
167  $link.=img_picto($langs->trans("Activated"),'switch_on');
168  $link.='</a>';
169  // Edition des varibales globales
170  $constantes=array(
171  'ADHERENT_MAILMAN_ADMINPW',
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  dol_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 }
213 else
214 {
215  dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
216 
217  $link='<a href="'.$_SERVER["PHP_SELF"].'?action=set&value=1&name=ADHERENT_USE_MAILMAN">';
218  //$link.=img_$langs->trans("Activate")
219  $link.=img_picto($langs->trans("Disabled"),'switch_off');
220  $link.='</a>';
221  print load_fiche_titre($langs->trans('MailmanTitle'), $link,'');
222 
223  dol_fiche_end();
224 }
225 
226 
227 if (! empty($conf->global->ADHERENT_USE_MAILMAN))
228 {
229  print '<form action="'.$_SERVER["PHP_SELF"].'">';
230  print '<input type="hidden" name="action" value="testsubscribe">';
231  print $langs->trans("TestSubscribe").'<br>';
232  print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
233  print '</form>';
234  print '<form action="'.$_SERVER["PHP_SELF"].'">';
235  print '<input type="hidden" name="action" value="testunsubscribe">';
236  print $langs->trans("TestUnSubscribe").'<br>';
237  print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
238  print '</form>';
239 }
240 
241 // End of page
242 llxFooter();
243 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
form_constantes($tableau, $strictw3c=0, $helptext='')
Show array with constants to edit.
Definition: admin.lib.php:1365
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage mailman and spip.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.