mailman.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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@capnetworks.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. $langs->load("admin");
  33. $langs->load("members");
  34. $langs->load("mailmanspip");
  35. if (! $user->admin) accessforbidden();
  36. $type=array('yesno','texte','chaine');
  37. $action = GETPOST('action','aZ09');
  38. $testsubscribeemail = GETPOST("testsubscribeemail");
  39. $testunsubscribeemail = GETPOST("testunsubscribeemail");
  40. /*
  41. * Actions
  42. */
  43. // Action mise a jour ou ajout d'une constante
  44. if ($action == 'update' || $action == 'add')
  45. {
  46. foreach($_POST['constname'] as $key => $val)
  47. {
  48. $constname=$_POST["constname"][$key];
  49. $constvalue=$_POST["constvalue"][$key];
  50. $consttype=$_POST["consttype"][$key];
  51. $constnote=$_POST["constnote"][$key];
  52. $res=dolibarr_set_const($db,$constname,$constvalue,$type[$consttype],0,$constnote,$conf->entity);
  53. if (! $res > 0) $error++;
  54. }
  55. if (! $error)
  56. {
  57. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  58. }
  59. else
  60. {
  61. setEventMessages($langs->trans("Error"), null, 'errors');
  62. }
  63. }
  64. // Action activation d'un sous module du module adherent
  65. if ($action == 'set')
  66. {
  67. $result=dolibarr_set_const($db, $_GET["name"], $_GET["value"], '', 0, '', $conf->entity);
  68. if ($result < 0)
  69. {
  70. dol_print_error($db);
  71. }
  72. }
  73. // Action desactivation d'un sous module du module adherent
  74. if ($action == 'unset')
  75. {
  76. $result=dolibarr_del_const($db, $_GET["name"], $conf->entity);
  77. if ($result < 0)
  78. {
  79. dol_print_error($db);
  80. }
  81. }
  82. if (($action == 'testsubscribe' || $action == 'testunsubscribe') && ! empty($conf->global->ADHERENT_USE_MAILMAN))
  83. {
  84. $email=GETPOST($action.'email');
  85. if (! isValidEmail($email))
  86. {
  87. $langs->load("errors");
  88. setEventMessages($langs->trans("ErrorBadEMail",$email), null, 'errors');
  89. }
  90. else
  91. {
  92. include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
  93. $mailmanspip=new MailmanSpip($db);
  94. $object=new stdClass();
  95. $object->email=$email;
  96. $object->pass=$email;
  97. /*$object->element='member';
  98. $object->type='Preferred Partners'; */
  99. if ($action == 'testsubscribe')
  100. {
  101. $result=$mailmanspip->add_to_mailman($object);
  102. if ($result < 0)
  103. {
  104. $error++;
  105. setEventMessages($mailmanspip->error,$mailmanspip->errors,'errors');
  106. }
  107. else
  108. {
  109. setEventMessages($langs->trans("MailmanCreationSuccess"), null);
  110. }
  111. }
  112. if ($action == 'testunsubscribe')
  113. {
  114. $result=$mailmanspip->del_to_mailman($object);
  115. if ($result < 0)
  116. {
  117. $error++;
  118. setEventMessages($mailmanspip->error,$mailmanspip->errors,'errors');
  119. }
  120. else
  121. {
  122. setEventMessages($langs->trans("MailmanDeletionSuccess"), null);
  123. }
  124. }
  125. }
  126. }
  127. /*
  128. * View
  129. */
  130. $help_url='';
  131. llxHeader('',$langs->trans("MailmanSpipSetup"),$help_url);
  132. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  133. print load_fiche_titre($langs->trans("MailmanSpipSetup"),$linkback,'title_setup');
  134. $head = mailmanspip_admin_prepare_head();
  135. $var=true;
  136. if (! empty($conf->global->ADHERENT_USE_MAILMAN))
  137. {
  138. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  139. dol_fiche_head($head, 'mailman', $langs->trans("Setup"), 0, 'user');
  140. //$link=img_picto($langs->trans("Active"),'tick').' ';
  141. $link='<a 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="action" value="testsubscribe">';
  195. print $langs->trans("TestSubscribe").'<br>';
  196. print $langs->trans("EMail").' <input type="email" class="flat" name="testsubscribeemail" value="'.GETPOST('testsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  197. print '</form>';
  198. print '<form action="'.$_SERVER["PHP_SELF"].'">';
  199. print '<input type="hidden" name="action" value="testunsubscribe">';
  200. print $langs->trans("TestUnSubscribe").'<br>';
  201. print $langs->trans("EMail").' <input type="email" class="flat" name="testunsubscribeemail" value="'.GETPOST('testunsubscribeemail').'"> <input class="button" type="submit" value="'.$langs->trans("Test").'"><br>';
  202. print '</form>';
  203. }
  204. llxFooter();
  205. $db->close();