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 24/** 25 * \file htdocs/admin/mailman.php 26 * \ingroup mailmanspip 27 * \brief Page to setup the module MailmanSpip (Mailman) 28 */ 29 30require '../main.inc.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php'; 33require_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 38if (!$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 52if ($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 } else { 69 setEventMessages($langs->trans("Error"), null, 'errors'); 70 } 71} 72 73// Action activation d'un sous module du module adherent 74if ($action == 'set') 75{ 76 $result = dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity); 77 if ($result < 0) 78 { 79 dol_print_error($db); 80 } 81} 82 83// Action desactivation d'un sous module du module adherent 84if ($action == 'unset') 85{ 86 $result = dolibarr_del_const($db, $_GET["name"], $conf->entity); 87 if ($result < 0) 88 { 89 dol_print_error($db); 90 } 91} 92 93if (($action == 'testsubscribe' || $action == 'testunsubscribe') && !empty($conf->global->ADHERENT_USE_MAILMAN)) 94{ 95 $email = GETPOST($action.'email'); 96 if (!isValidEmail($email)) 97 { 98 $langs->load("errors"); 99 setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors'); 100 } else { 101 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php'; 102 $mailmanspip = new MailmanSpip($db); 103 104 $object = new stdClass(); 105 $object->email = $email; 106 $object->pass = $email; 107 /*$object->element='member'; 108 $object->type='Preferred Partners'; */ 109 110 if ($action == 'testsubscribe') 111 { 112 $result = $mailmanspip->add_to_mailman($object); 113 if ($result < 0) 114 { 115 $error++; 116 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors'); 117 } else { 118 setEventMessages($langs->trans("MailmanCreationSuccess"), null); 119 } 120 } 121 if ($action == 'testunsubscribe') 122 { 123 $result = $mailmanspip->del_to_mailman($object); 124 if ($result < 0) 125 { 126 $error++; 127 setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors'); 128 } else { 129 setEventMessages($langs->trans("MailmanDeletionSuccess"), null); 130 } 131 } 132 } 133} 134 135 136/* 137 * View 138 */ 139 140$help_url = ''; 141 142llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url); 143 144 145$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 146print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup'); 147 148$head = mailmanspip_admin_prepare_head(); 149 150if (!empty($conf->global->ADHERENT_USE_MAILMAN)) 151{ 152 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; 153 print '<input type="hidden" name="token" value="'.newToken().'">'; 154 print '<input type="hidden" name="action" value="update">'; 155 156 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user'); 157 158 //$link=img_picto($langs->trans("Active"),'tick').' '; 159 $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&token='.newToken().'&value=0&name=ADHERENT_USE_MAILMAN">'; 160 //$link.=$langs->trans("Disable"); 161 $link .= img_picto($langs->trans("Activated"), 'switch_on'); 162 $link .= '</a>'; 163 // Edition des varibales globales 164 $constantes = array( 165 'ADHERENT_MAILMAN_ADMINPW', 166 'ADHERENT_MAILMAN_URL', 167 'ADHERENT_MAILMAN_UNSUB_URL', 168 'ADHERENT_MAILMAN_LISTS' 169 ); 170 171 print load_fiche_titre($langs->trans('MailmanTitle'), $link, ''); 172 173 print '<br>'; 174 175 // JQuery activity 176 print '<script type="text/javascript"> 177 var i1=0; 178 var i2=0; 179 var i3=0; 180 jQuery(document).ready(function(){ 181 jQuery("#exampleclick1").click(function(event){ 182 if (i1 == 0) { jQuery("#example1").show(); i1=1; } 183 else if (i1 == 1) { jQuery("#example1").hide(); i1=0; } 184 }); 185 jQuery("#exampleclick2").click(function(){ 186 if (i2 == 0) { jQuery("#example2").show(); i2=1; } 187 else if (i2 == 1) { jQuery("#example2").hide(); i2=0; } 188 }); 189 jQuery("#exampleclick3").click(function(){ 190 if (i3 == 0) { jQuery("#example3").show(); i3=1; } 191 else if (i3 == 1) { jQuery("#example3").hide(); i3=0; } 192 }); 193 }); 194 </script>'; 195 196 form_constantes($constantes, 2); 197 198 print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>'; 199 print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>'; 200 201 print dol_get_fiche_end(); 202 203 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>'; 204 205 print '</form>'; 206} else { 207 print dol_get_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user'); 208 209 $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value=1&name=ADHERENT_USE_MAILMAN">'; 210 //$link.=img_$langs->trans("Activate") 211 $link .= img_picto($langs->trans("Disabled"), 'switch_off'); 212 $link .= '</a>'; 213 print load_fiche_titre($langs->trans('MailmanTitle'), $link, ''); 214 215 print dol_get_fiche_end(); 216} 217 218 219if (!empty($conf->global->ADHERENT_USE_MAILMAN)) 220{ 221 print '<form action="'.$_SERVER["PHP_SELF"].'">'; 222 print '<input type="hidden" name="token" value="'.newToken().'">'; 223 print '<input type="hidden" name="action" value="testsubscribe">'; 224 225 print $langs->trans("TestSubscribe").'<br>'; 226 print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>'; 227 228 print '</form>'; 229 230 print '<form action="'.$_SERVER["PHP_SELF"].'">'; 231 print '<input type="hidden" name="token" value="'.newToken().'">'; 232 print '<input type="hidden" name="action" value="testunsubscribe">'; 233 234 print $langs->trans("TestUnSubscribe").'<br>'; 235 print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>'; 236 237 print '</form>'; 238} 239 240// End of page 241llxFooter(); 242$db->close(); 243