website.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/adherents/admin/website.php
  22. * \ingroup member
  23. * \brief File of main public page for member module
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("admin", "members"));
  33. $action = GETPOST('action', 'aZ09');
  34. if (!$user->admin) {
  35. accessforbidden();
  36. }
  37. $error = 0;
  38. /*
  39. * Actions
  40. */
  41. if ($action == 'setMEMBER_ENABLE_PUBLIC') {
  42. if (GETPOST('value')) {
  43. dolibarr_set_const($db, 'MEMBER_ENABLE_PUBLIC', 1, 'chaine', 0, '', $conf->entity);
  44. } else {
  45. dolibarr_set_const($db, 'MEMBER_ENABLE_PUBLIC', 0, 'chaine', 0, '', $conf->entity);
  46. }
  47. }
  48. if ($action == 'update') {
  49. $public = GETPOST('MEMBER_ENABLE_PUBLIC');
  50. $amount = price2num(GETPOST('MEMBER_NEWFORM_AMOUNT'), 'MT', 2);
  51. $minamount = GETPOST('MEMBER_MIN_AMOUNT');
  52. $publiccounters = GETPOST('MEMBER_COUNTERS_ARE_PUBLIC');
  53. $showtable = GETPOST('MEMBER_SHOW_TABLE');
  54. $showvoteallowed = GETPOST('MEMBER_SHOW_VOTE_ALLOWED');
  55. $payonline = GETPOST('MEMBER_NEWFORM_PAYONLINE');
  56. $forcetype = GETPOST('MEMBER_NEWFORM_FORCETYPE', 'int');
  57. $forcemorphy = GETPOST('MEMBER_NEWFORM_FORCEMORPHY', 'aZ09');
  58. $res = dolibarr_set_const($db, "MEMBER_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity);
  59. $res = dolibarr_set_const($db, "MEMBER_NEWFORM_AMOUNT", $amount, 'chaine', 0, '', $conf->entity);
  60. $res = dolibarr_set_const($db, "MEMBER_MIN_AMOUNT", $minamount, 'chaine', 0, '', $conf->entity);
  61. $res = dolibarr_set_const($db, "MEMBER_COUNTERS_ARE_PUBLIC", $publiccounters, 'chaine', 0, '', $conf->entity);
  62. $res = dolibarr_set_const($db, "MEMBER_SKIP_TABLE", !$showtable, 'chaine', 0, '', $conf->entity); // Logic is reversed for retrocompatibility: "skip -> show"
  63. $res = dolibarr_set_const($db, "MEMBER_HIDE_VOTE_ALLOWED", !$showvoteallowed, 'chaine', 0, '', $conf->entity); // Logic is reversed for retrocompatibility: "hide -> show"
  64. $res = dolibarr_set_const($db, "MEMBER_NEWFORM_PAYONLINE", $payonline, 'chaine', 0, '', $conf->entity);
  65. if ($forcetype < 0) {
  66. $res = dolibarr_del_const($db, "MEMBER_NEWFORM_FORCETYPE", $conf->entity);
  67. } else {
  68. $res = dolibarr_set_const($db, "MEMBER_NEWFORM_FORCETYPE", $forcetype, 'chaine', 0, '', $conf->entity);
  69. }
  70. if ($forcemorphy == '-1') {
  71. $res = dolibarr_del_const($db, "MEMBER_NEWFORM_FORCEMORPHY", $conf->entity);
  72. } else {
  73. $res = dolibarr_set_const($db, "MEMBER_NEWFORM_FORCEMORPHY", $forcemorphy, 'chaine', 0, '', $conf->entity);
  74. }
  75. if (!($res > 0)) {
  76. $error++;
  77. }
  78. if (!$error) {
  79. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  80. } else {
  81. setEventMessages($langs->trans("Error"), null, 'errors');
  82. }
  83. }
  84. /*
  85. * View
  86. */
  87. $form = new Form($db);
  88. $title = $langs->trans("MembersSetup");
  89. $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
  90. llxHeader('', $title, $help_url);
  91. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  92. print load_fiche_titre($title, $linkback, 'title_setup');
  93. $head = member_admin_prepare_head();
  94. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  95. print '<input type="hidden" name="action" value="update">';
  96. print '<input type="hidden" name="token" value="'.newToken().'">';
  97. print dol_get_fiche_head($head, 'website', $langs->trans("Members"), -1, 'user');
  98. if ($conf->use_javascript_ajax) {
  99. print "\n".'<script type="text/javascript">';
  100. print 'jQuery(document).ready(function () {
  101. function initemail()
  102. {
  103. if (jQuery("#MEMBER_NEWFORM_PAYONLINE").val()==\'-1\')
  104. {
  105. jQuery("#tremail").hide();
  106. }
  107. else
  108. {
  109. jQuery("#tremail").show();
  110. }
  111. }
  112. function initfields()
  113. {
  114. if (jQuery("#MEMBER_ENABLE_PUBLIC").val()==\'0\')
  115. {
  116. jQuery("#trforcetype, #tramount, #tredit, #trpayment, #tremail").hide();
  117. }
  118. if (jQuery("#MEMBER_ENABLE_PUBLIC").val()==\'1\')
  119. {
  120. jQuery("#trforcetype, #tramount, #tredit, #trpayment").show();
  121. if (jQuery("#MEMBER_NEWFORM_PAYONLINE").val()==\'-1\') jQuery("#tremail").hide();
  122. else jQuery("#tremail").show();
  123. }
  124. }
  125. initfields();
  126. jQuery("#MEMBER_ENABLE_PUBLIC").change(function() { initfields(); });
  127. jQuery("#MEMBER_NEWFORM_PAYONLINE").change(function() { initemail(); });
  128. })';
  129. print '</script>'."\n";
  130. }
  131. print '<span class="opacitymedium">'.$langs->trans("BlankSubscriptionFormDesc").'</span><br><br>';
  132. $param = '';
  133. $enabledisablehtml = $langs->trans("EnablePublicSubscriptionForm").' ';
  134. if (empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
  135. // Button off, click to enable
  136. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMEMBER_ENABLE_PUBLIC&token='.newToken().'&value=1'.$param.'">';
  137. $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
  138. $enabledisablehtml .= '</a>';
  139. } else {
  140. // Button on, click to disable
  141. $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setMEMBER_ENABLE_PUBLIC&token='.newToken().'&value=0'.$param.'">';
  142. $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
  143. $enabledisablehtml .= '</a>';
  144. }
  145. print $enabledisablehtml;
  146. print '<input type="hidden" id="MEMBER_ENABLE_PUBLIC" name="MEMBER_ENABLE_PUBLIC" value="'.(empty($conf->global->MEMBER_ENABLE_PUBLIC) ? 0 : 1).'">';
  147. print '<br><br>';
  148. if (!empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
  149. print '<br>';
  150. //print $langs->trans('FollowingLinksArePublic').'<br>';
  151. print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('BlankSubscriptionForm').'</span><br>';
  152. if (isModEnabled('multicompany')) {
  153. $entity_qr = '?entity='.((int) $conf->entity);
  154. } else {
  155. $entity_qr = '';
  156. }
  157. // Define $urlwithroot
  158. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  159. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  160. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  161. print '<div class="urllink">';
  162. print '<input type="text" id="publicurlmember" class="quatrevingtpercentminusx" value="'.$urlwithroot.'/public/members/new.php'.$entity_qr.'">';
  163. print '<a target="_blank" rel="noopener noreferrer" href="'.$urlwithroot.'/public/members/new.php'.$entity_qr.'">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
  164. print '</div>';
  165. print ajax_autoselect('publicurlmember');
  166. print '<br>';
  167. print '<div class="div-table-responsive-no-min">';
  168. print '<table class="noborder centpercent">';
  169. print '<tr class="liste_titre">';
  170. print '<td>'.$langs->trans("Parameter").'</td>';
  171. print '<td>'.$langs->trans("Value").'</td>';
  172. print "</tr>\n";
  173. // Force Type
  174. $adht = new AdherentType($db);
  175. print '<tr class="oddeven drag" id="trforcetype"><td>';
  176. print $langs->trans("ForceMemberType");
  177. print '</td><td>';
  178. $listofval = array();
  179. $listofval += $adht->liste_array(1);
  180. $forcetype = empty($conf->global->MEMBER_NEWFORM_FORCETYPE) ? -1 : $conf->global->MEMBER_NEWFORM_FORCETYPE;
  181. print $form->selectarray("MEMBER_NEWFORM_FORCETYPE", $listofval, $forcetype, count($listofval) > 1 ? 1 : 0);
  182. print "</td></tr>\n";
  183. // Force nature of member (mor/phy)
  184. $morphys["phy"] = $langs->trans("Physical");
  185. $morphys["mor"] = $langs->trans("Moral");
  186. print '<tr class="oddeven drag" id="trforcenature"><td>';
  187. print $langs->trans("ForceMemberNature");
  188. print '</td><td>';
  189. $forcenature = empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY) ? 0 : $conf->global->MEMBER_NEWFORM_FORCEMORPHY;
  190. print $form->selectarray("MEMBER_NEWFORM_FORCEMORPHY", $morphys, $forcenature, 1);
  191. print "</td></tr>\n";
  192. // Amount
  193. print '<tr class="oddeven" id="tramount"><td>';
  194. print $langs->trans("DefaultAmount");
  195. print '</td><td>';
  196. print '<input type="text" class="right width50" id="MEMBER_NEWFORM_AMOUNT" name="MEMBER_NEWFORM_AMOUNT" value="'.(!empty($conf->global->MEMBER_NEWFORM_AMOUNT) ? $conf->global->MEMBER_NEWFORM_AMOUNT : '').'">';
  197. print "</td></tr>\n";
  198. // Min amount
  199. print '<tr class="oddeven" id="tredit"><td>';
  200. print $langs->trans("MinimumAmount");
  201. print '</td><td>';
  202. print '<input type="text" class="right width50" id="MEMBER_MIN_AMOUNT" name="MEMBER_MIN_AMOUNT" value="'.(!empty($conf->global->MEMBER_MIN_AMOUNT) ? $conf->global->MEMBER_MIN_AMOUNT : '').'">';
  203. print "</td></tr>\n";
  204. // SHow counter of validated members publicly
  205. print '<tr class="oddeven" id="tredit"><td>';
  206. print $langs->trans("MemberCountersArePublic");
  207. print '</td><td>';
  208. print $form->selectyesno("MEMBER_COUNTERS_ARE_PUBLIC", (!empty($conf->global->MEMBER_COUNTERS_ARE_PUBLIC) ? $conf->global->MEMBER_COUNTERS_ARE_PUBLIC : 0), 1);
  209. print "</td></tr>\n";
  210. // Show the table of all available membership types. If not, show a form (as the default was for Dolibarr <=16.0)
  211. $skiptable = (!empty($conf->global->MEMBER_SKIP_TABLE) ? $conf->global->MEMBER_SKIP_TABLE : 0);
  212. print '<tr class="oddeven" id="tredit"><td>';
  213. print $langs->trans("MembersShowMembershipTypesTable");
  214. print '</td><td>';
  215. print $form->selectyesno("MEMBER_SHOW_TABLE", !$skiptable, 1); // Reverse the logic "hide -> show" for retrocompatibility
  216. print "</td></tr>\n";
  217. // Show "vote allowed" setting for membership types
  218. $hidevoteallowed = (!empty($conf->global->MEMBER_HIDE_VOTE_ALLOWED) ? $conf->global->MEMBER_HIDE_VOTE_ALLOWED : 0);
  219. print '<tr class="oddeven" id="tredit"><td>';
  220. print $langs->trans("MembersShowVotesAllowed");
  221. print '</td><td>';
  222. print $form->selectyesno("MEMBER_SHOW_VOTE_ALLOWED", !$hidevoteallowed, 1); // Reverse the logic "hide -> show" for retrocompatibility
  223. print "</td></tr>\n";
  224. // Jump to an online payment page
  225. print '<tr class="oddeven" id="trpayment"><td>';
  226. print $langs->trans("MEMBER_NEWFORM_PAYONLINE");
  227. print '</td><td>';
  228. $listofval = array();
  229. $listofval['-1'] = $langs->trans('No');
  230. $listofval['all'] = $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')';
  231. if (isModEnabled('paybox')) {
  232. $listofval['paybox'] = 'Paybox';
  233. }
  234. if (isModEnabled('paypal')) {
  235. $listofval['paypal'] = 'PayPal';
  236. }
  237. if (isModEnabled('stripe')) {
  238. $listofval['stripe'] = 'Stripe';
  239. }
  240. print $form->selectarray("MEMBER_NEWFORM_PAYONLINE", $listofval, (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE) ? $conf->global->MEMBER_NEWFORM_PAYONLINE : ''), 0);
  241. print "</td></tr>\n";
  242. print '</table>';
  243. print '</div>';
  244. print '<div class="center">';
  245. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
  246. print '</div>';
  247. }
  248. print dol_get_fiche_end();
  249. print '</form>';
  250. // End of page
  251. llxFooter();
  252. $db->close();