mailman.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. /**
  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. dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
  138. //$link=img_picto($langs->trans("Active"),'tick').' ';
  139. $link='<a href="'.$_SERVER["PHP_SELF"].'?action=unset&value=0&name=ADHERENT_USE_MAILMAN">';
  140. //$link.=$langs->trans("Disable");
  141. $link.=img_picto($langs->trans("Activated"),'switch_on');
  142. $link.='</a>';
  143. // Edition des varibales globales
  144. $constantes=array(
  145. 'ADHERENT_MAILMAN_ADMINPW',
  146. 'ADHERENT_MAILMAN_URL',
  147. 'ADHERENT_MAILMAN_UNSUB_URL',
  148. 'ADHERENT_MAILMAN_LISTS'
  149. );
  150. print load_fiche_titre($langs->trans('MailmanTitle'), $link,'');
  151. print '<br>';
  152. // JQuery activity
  153. print '<script type="text/javascript">
  154. var i1=0;
  155. var i2=0;
  156. var i3=0;
  157. jQuery(document).ready(function(){
  158. jQuery("#exampleclick1").click(function(event){
  159. if (i1 == 0) { jQuery("#example1").show(); i1=1; }
  160. else if (i1 == 1) { jQuery("#example1").hide(); i1=0; }
  161. });
  162. jQuery("#exampleclick2").click(function(){
  163. if (i2 == 0) { jQuery("#example2").show(); i2=1; }
  164. else if (i2 == 1) { jQuery("#example2").hide(); i2=0; }
  165. });
  166. jQuery("#exampleclick3").click(function(){
  167. if (i3 == 0) { jQuery("#example3").show(); i3=1; }
  168. else if (i3 == 1) { jQuery("#example3").hide(); i3=0; }
  169. });
  170. });
  171. </script>';
  172. form_constantes($constantes,2);
  173. print '*'.$langs->trans("FollowingConstantsWillBeSubstituted").'<br>';
  174. print '%LISTE%, %MAILMAN_ADMINPW%, %EMAIL% <br>';
  175. dol_fiche_end();
  176. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Update").'" name="update"></div>';
  177. print '</form>';
  178. }
  179. else
  180. {
  181. dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
  182. $link='<a href="'.$_SERVER["PHP_SELF"].'?action=set&value=1&name=ADHERENT_USE_MAILMAN">';
  183. //$link.=img_$langs->trans("Activate")
  184. $link.=img_picto($langs->trans("Disabled"),'switch_off');
  185. $link.='</a>';
  186. print load_fiche_titre($langs->trans('MailmanTitle'), $link,'');
  187. dol_fiche_end();
  188. }
  189. if (! empty($conf->global->ADHERENT_USE_MAILMAN))
  190. {
  191. print '<form action="'.$_SERVER["PHP_SELF"].'">';
  192. print '<input type="hidden" name="action" value="testsubscribe">';
  193. print $langs->trans("TestSubscribe").'<br>';
  194. print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  195. print '</form>';
  196. print '<form action="'.$_SERVER["PHP_SELF"].'">';
  197. print '<input type="hidden" name="action" value="testunsubscribe">';
  198. print $langs->trans("TestUnSubscribe").'<br>';
  199. print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  200. print '</form>';
  201. }
  202. // End of page
  203. llxFooter();
  204. $db->close();