mailman.php 7.8 KB

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