* Copyright (C) 2006-2015 Laurent Destailleur * Copyright (C) 2006-2012 Regis Houssin * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2024 Alexandre Spangaro * Copyright (C) 2024 Frédéric France * Copyright (C) 2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/don/admin/website.php * \ingroup don * \brief File of main public page for donation module */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user * * @var string $dolibarr_main_url_root */ // Load translation files required by the page $langs->loadLangs(array("admin", "donations")); $action = GETPOST('action', 'aZ09'); // Hook to be used by external payment modules (ie Payzen, ...) $hookmanager = new HookManager($db); $hookmanager->initHooks(array('newpayment')); if (!$user->admin) { accessforbidden(); } $error = 0; /* * Actions */ if ($action == 'setDONATION_ENABLE_PUBLIC') { if (GETPOST('value')) { dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 1, 'chaine', 0, '', $conf->entity); } else { dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 0, 'chaine', 0, '', $conf->entity); } } if ($action == 'update') { $public = GETPOST('DONATION_ENABLE_PUBLIC'); $minamount = GETPOST('DONATION_MIN_AMOUNT'); $publiccounters = GETPOST('DONATION_COUNTERS_ARE_PUBLIC'); $payonline = GETPOST('DONATION_NEWFORM_PAYONLINE'); $res = dolibarr_set_const($db, "DONATION_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "DONATION_MIN_AMOUNT", $minamount, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "DONATION_COUNTERS_ARE_PUBLIC", $publiccounters, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "DONATION_NEWFORM_PAYONLINE", $payonline, 'chaine', 0, '', $conf->entity); if (!($res > 0)) { $error++; } if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("Error"), null, 'errors'); } } /* * View */ $form = new Form($db); $title = $langs->trans("DonationsSetup"); $help_url = 'EN:Module_Donation|FR:Module_Don'; llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-don page-admin_website'); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title, $linkback, 'title_setup'); $head = donation_admin_prepare_head(); print '
'; print ''; print ''; print dol_get_fiche_head($head, 'website', $langs->trans("Donations"), -1, 'user'); if ($conf->use_javascript_ajax) { print "\n".''."\n"; } print ''.$langs->trans("BlankDonationFormDesc").'

'; $param = ''; $enabledisablehtml = $langs->trans("EnablePublicDonationForm").' '; if (!getDolGlobalString('DONATION_ENABLE_PUBLIC')) { // Button off, click to enable $enabledisablehtml .= ''; $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off'); $enabledisablehtml .= ''; } else { // Button on, click to disable $enabledisablehtml .= ''; $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on'); $enabledisablehtml .= ''; } print $enabledisablehtml; print ''; print '

'; if (getDolGlobalString('DONATION_ENABLE_PUBLIC')) { print '
'; print img_picto('', 'globe').' '.$langs->trans('BlankDonationForm').'
'; if (isModEnabled('multicompany')) { $entity_qr = '?entity='.((int) $conf->entity); } else { $entity_qr = ''; } // Define $urlwithroot $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file print ''; print ajax_autoselect('publicurldonation'); print '

'; print '
'; print ''; print ''; print ''; print ''; print "\n"; // Min amount print '\n"; // Show counter of validated donations publicly print '\n"; // Jump to an online payment page print '\n"; print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; print $langs->trans("MinimumAmountDonation"); print ''; print ''; print "
'; print $langs->trans("donationCountersArePublic"); print ''; print $form->selectyesno("DONATION_COUNTERS_ARE_PUBLIC", getDolGlobalInt('DONATION_COUNTERS_ARE_PUBLIC'), 1, false, 0, 1); print "
'; print $langs->trans("DONATION_NEWFORM_PAYONLINE"); print ''; // Initialize $validpaymentmethod // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods() $validpaymentmethod = getValidOnlinePaymentMethods('', 1); // Define $listofval using the $validpaymentmethod $listofval = array(); $listofval['-1'] = array('label' => $langs->trans('No')); $listofval['all'] = array('label' => $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')', 'data-html' => $langs->trans('Yes').'   ('.$langs->trans("VisitorCanChooseItsPaymentMode").')'); foreach ($validpaymentmethod as $key => $val) { if (is_array($val)) { $listofval[$key] = $val; } else { $listofval[$key] = array('label' => $key, 'status' => 'valid'); } } print $form->selectarray("DONATION_NEWFORM_PAYONLINE", $listofval, getDolGlobalString('DONATION_NEWFORM_PAYONLINE'), 0); print "
'; print '
'; print '
'; print ''; print '
'; } print dol_get_fiche_end(); print '
'; // End of page llxFooter(); $db->close();