mailman.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. * \file htdocs/admin/mailman.php
  25. * \ingroup mailmanspip
  26. * \brief Page to setup the module MailmanSpip (Mailman)
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/mailmanspip.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("admin", "members", "mailmanspip"));
  34. if (!$user->admin) accessforbidden();
  35. $type = array('yesno', 'texte', 'chaine');
  36. $action = GETPOST('action', 'aZ09');
  37. $testsubscribeemail = GETPOST("testsubscribeemail");
  38. $testunsubscribeemail = GETPOST("testunsubscribeemail");
  39. /*
  40. * Actions
  41. */
  42. // Action updated or added a constant
  43. if ($action == 'update' || $action == 'add')
  44. {
  45. foreach ($_POST['constname'] as $key => $val)
  46. {
  47. $constname = $_POST["constname"][$key];
  48. $constvalue = $_POST["constvalue"][$key];
  49. $consttype = $_POST["consttype"][$key];
  50. $constnote = $_POST["constnote"][$key];
  51. $res = dolibarr_set_const($db, $constname, $constvalue, $type[$consttype], 0, $constnote, $conf->entity);
  52. if (!$res > 0) $error++;
  53. }
  54. if (!$error)
  55. {
  56. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  57. }
  58. else
  59. {
  60. setEventMessages($langs->trans("Error"), null, 'errors');
  61. }
  62. }
  63. // Action activation d'un sous module du module adherent
  64. if ($action == 'set')
  65. {
  66. $result = dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity);
  67. if ($result < 0)
  68. {
  69. dol_print_error($db);
  70. }
  71. }
  72. // Action desactivation d'un sous module du module adherent
  73. if ($action == 'unset')
  74. {
  75. $result = dolibarr_del_const($db, $_GET["name"], $conf->entity);
  76. if ($result < 0)
  77. {
  78. dol_print_error($db);
  79. }
  80. }
  81. if (($action == 'testsubscribe' || $action == 'testunsubscribe') && !empty($conf->global->ADHERENT_USE_MAILMAN))
  82. {
  83. $email = GETPOST($action.'email');
  84. if (!isValidEmail($email))
  85. {
  86. $langs->load("errors");
  87. setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
  88. }
  89. else
  90. {
  91. include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
  92. $mailmanspip = new MailmanSpip($db);
  93. $object = new stdClass();
  94. $object->email = $email;
  95. $object->pass = $email;
  96. /*$object->element='member';
  97. $object->type='Preferred Partners'; */
  98. if ($action == 'testsubscribe')
  99. {
  100. $result = $mailmanspip->add_to_mailman($object);
  101. if ($result < 0)
  102. {
  103. $error++;
  104. setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
  105. }
  106. else
  107. {
  108. setEventMessages($langs->trans("MailmanCreationSuccess"), null);
  109. }
  110. }
  111. if ($action == 'testunsubscribe')
  112. {
  113. $result = $mailmanspip->del_to_mailman($object);
  114. if ($result < 0)
  115. {
  116. $error++;
  117. setEventMessages($mailmanspip->error, $mailmanspip->errors, 'errors');
  118. }
  119. else
  120. {
  121. setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
  122. }
  123. }
  124. }
  125. }
  126. /*
  127. * View
  128. */
  129. $help_url = '';
  130. llxHeader('', $langs->trans("MailmanSpipSetup"), $help_url);
  131. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  132. print load_fiche_titre($langs->trans("MailmanSpipSetup"), $linkback, 'title_setup');
  133. $head = mailmanspip_admin_prepare_head();
  134. if (!empty($conf->global->ADHERENT_USE_MAILMAN))
  135. {
  136. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  137. print '<input type="hidden" name="token" value="'.newToken().'">';
  138. print '<input type="hidden" name="action" value="update">';
  139. dol_fiche_head($head, 'mailman', $langs->trans("Setup"), -1, 'user');
  140. //$link=img_picto($langs->trans("Active"),'tick').' ';
  141. $link = '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=unset&value=0&name=ADHERENT_USE_MAILMAN">';
  142. //$link.=$langs->trans("Disable");
  143. $link .= img_picto($langs->trans("Activated"), 'switch_on');
  144. $link .= '</a>';
  145. // Edition des varibales globales
  146. $constantes = array(
  147. 'ADHERENT_MAILMAN_ADMINPW',
  148. 'ADHERENT_MAILMAN_URL',
  149. 'ADHERENT_MAILMAN_UNSUB_URL',
  150. 'ADHERENT_MAILMAN_LISTS'
  151. );
  152. print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
  153. print '<br>';
  154. // JQuery activity
  155. print '<script type="text/javascript">
  156. var i1=0;
  157. var i2=0;
  158. var i3=0;
  159. jQuery(document).ready(function(){
  160. jQuery("#exampleclick1").click(function(event){
  161. if (i1 == 0) { jQuery("#example1").show(); i1=1; }
  162. else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
  163. });
  164. jQuery("#exampleclick2").click(function(){
  165. if (i2 == 0) { jQuery("#example2").show(); i2=1; }
  166. else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
  167. });
  168. jQuery("#exampleclick3").click(function(){
  169. if (i3 == 0) { jQuery("#example3").show(); i3=1; }
  170. else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
  171. });
  172. });
  173. </script>';
  174. form_constantes($constantes, 2);
  175. print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
  176. print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
  177. dol_fiche_end();
  178. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
  179. print '</form>';
  180. }
  181. else
  182. {
  183. dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
  184. $link = '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value=1&name=ADHERENT_USE_MAILMAN">';
  185. //$link.=img_$langs->trans("Activate")
  186. $link .= img_picto($langs->trans("Disabled"), 'switch_off');
  187. $link .= '</a>';
  188. print load_fiche_titre($langs->trans('MailmanTitle'), $link, '');
  189. dol_fiche_end();
  190. }
  191. if (!empty($conf->global->ADHERENT_USE_MAILMAN))
  192. {
  193. print '<form action="'.$_SERVER["PHP_SELF"].'">';
  194. print '<input type="hidden" name="token" value="'.newToken().'">';
  195. print '<input type="hidden" name="action" value="testsubscribe">';
  196. print $langs->trans("TestSubscribe").'<br>';
  197. print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  198. print '</form>';
  199. print '<form action="'.$_SERVER["PHP_SELF"].'">';
  200. print '<input type="hidden" name="token" value="'.newToken().'">';
  201. print '<input type="hidden" name="action" value="testunsubscribe">';
  202. print $langs->trans("TestUnSubscribe").'<br>';
  203. print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  204. print '</form>';
  205. }
  206. // End of page
  207. llxFooter();
  208. $db->close();