dolibarr 24.0.0-beta
website.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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
30// Load Dolibarr environment
31require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
46
47// Load translation files required by the page
48$langs->loadLangs(array("admin", "donations"));
49
50$action = GETPOST('action', 'aZ09');
51
52// Hook to be used by external payment modules (ie Payzen, ...)
53$hookmanager->initHooks(array('newpayment'));
54
55if (!$user->admin) {
57}
58
59$error = 0;
60
61
62/*
63 * Actions
64 */
65
66if ($action == 'setDONATION_ENABLE_PUBLIC') {
67 if (GETPOST('value')) {
68 dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 1, 'chaine', 0, '', $conf->entity);
69 } else {
70 dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 0, 'chaine', 0, '', $conf->entity);
71 }
72}
73
74if ($action == 'update') {
75 $public = GETPOST('DONATION_ENABLE_PUBLIC');
76
77 $minamount = GETPOST('DONATION_MIN_AMOUNT');
78 $publiccounters = GETPOST('DONATION_COUNTERS_ARE_PUBLIC');
79 $payonline = GETPOST('DONATION_NEWFORM_PAYONLINE');
80
81 $res = dolibarr_set_const($db, "DONATION_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity);
82 $res = dolibarr_set_const($db, "DONATION_MIN_AMOUNT", $minamount, 'chaine', 0, '', $conf->entity);
83 $res = dolibarr_set_const($db, "DONATION_COUNTERS_ARE_PUBLIC", $publiccounters, 'chaine', 0, '', $conf->entity);
84 $res = dolibarr_set_const($db, "DONATION_NEWFORM_PAYONLINE", $payonline, 'chaine', 0, '', $conf->entity);
85
86 if (!($res > 0)) {
87 $error++;
88 }
89
90 if (!$error) {
91 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
92 } else {
93 setEventMessages($langs->trans("Error"), null, 'errors');
94 }
95}
96
97
98/*
99 * View
100 */
101
102$form = new Form($db);
103
104$title = $langs->trans("DonationsSetup");
105$help_url = 'EN:Module_Donation|FR:Module_Don';
106
107llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-don page-admin_website');
108
109
110$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
111print load_fiche_titre($title, $linkback, 'title_setup');
112
114
115
116
117print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
118print '<input type="hidden" name="action" value="update">';
119print '<input type="hidden" name="token" value="'.newToken().'">';
120
121print dol_get_fiche_head($head, 'website', $langs->trans("Donations"), -1, 'payment');
122
123if ($conf->use_javascript_ajax) {
124 print "\n".'<script type="text/javascript">';
125 print 'jQuery(document).ready(function () {
126 function initfields()
127 {
128 if (jQuery("#DONATION_ENABLE_PUBLIC").val()==\'0\') {
129 jQuery("#trforcetype, #tramount, #tredit, #trpayment").hide();
130 }
131 if (jQuery("#DONATION_ENABLE_PUBLIC").val()==\'1\') {
132 jQuery("#trforcetype, #tramount, #tredit, #trpayment").show();
133 }
134 }
135 initfields();
136 jQuery("#DONATION_ENABLE_PUBLIC").change(function() { initfields(); });
137 })';
138 print '</script>'."\n";
139}
140
141
142print '<span class="opacitymedium">'.$langs->trans("BlankDonationFormDesc").'</span><br><br>';
143
144$param = '';
145
146$enabledisablehtml = $langs->trans("EnablePublicDonationForm").' ';
147if (!getDolGlobalString('DONATION_ENABLE_PUBLIC')) {
148 // Button off, click to enable
149 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setDONATION_ENABLE_PUBLIC&token='.newToken().'&value=1'.$param.'">';
150 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
151 $enabledisablehtml .= '</a>';
152} else {
153 // Button on, click to disable
154 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setDONATION_ENABLE_PUBLIC&token='.newToken().'&value=0'.$param.'">';
155 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
156 $enabledisablehtml .= '</a>';
157}
158print $enabledisablehtml;
159print '<input type="hidden" id="DONATION_ENABLE_PUBLIC" name="DONATION_ENABLE_PUBLIC" value="'.(!getDolGlobalString('DONATION_ENABLE_PUBLIC') ? 0 : 1).'">';
160
161print '<br><br>';
162
163
164if (getDolGlobalString('DONATION_ENABLE_PUBLIC')) {
165 print '<br>';
166 print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('BlankDonationForm').'</span><br>';
167 if (isModEnabled('multicompany')) {
168 $entity_qr = '?entity='.((int) $conf->entity);
169 } else {
170 $entity_qr = '';
171 }
172
173 // Define $urlwithroot
174 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
175 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
176
177 print '<div class="urllink">';
178 print '<input type="text" id="publicurldonation" class="quatrevingtpercentminusx" value="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">';
179 print '<a target="_blank" rel="noopener noreferrer" href="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
180 print '</div>';
181 print ajax_autoselect('publicurldonation');
182
183 print '<br><br>';
184
185 print '<div class="div-table-responsive-no-min">';
186 print '<table class="noborder centpercent">';
187
188 print '<tr class="liste_titre">';
189 print '<td>'.$langs->trans("Parameter").'</td>';
190 print '<td>'.$langs->trans("Value").'</td>';
191 print "</tr>\n";
192
193 // Min amount
194 print '<tr class="oddeven" id="tredit"><td>';
195 print $langs->trans("MinimumAmountDonation");
196 print '</td><td>';
197 print '<input type="text" class="right width50" id="DONATION_MIN_AMOUNT" name="DONATION_MIN_AMOUNT" value="'.getDolGlobalString('DONATION_MIN_AMOUNT').'">';
198 print "</td></tr>\n";
199
200 // Show counter of validated donations publicly
201 print '<tr class="oddeven" id="tredit"><td>';
202 print $langs->trans("donationCountersArePublic");
203 print '</td><td>';
204 print $form->selectyesno("DONATION_COUNTERS_ARE_PUBLIC", getDolGlobalInt('DONATION_COUNTERS_ARE_PUBLIC'), 1, false, 0, 1);
205 print "</td></tr>\n";
206
207 // Jump to an online payment page
208 print '<tr class="oddeven" id="trpayment"><td>';
209 print $langs->trans("DONATION_NEWFORM_PAYONLINE");
210 print '</td><td>';
211
212 // Initialize $validpaymentmethod
213 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
214 $validpaymentmethod = getValidOnlinePaymentMethods('', 1);
215
216 // Define $listofval using the $validpaymentmethod
217 $listofval = array();
218 $listofval['-1'] = array('label' => $langs->trans('No'));
219 $listofval['all'] = array('label' => $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')', 'data-html' => $langs->trans('Yes').' &nbsp; <span class="opacitymedium">('.$langs->trans("VisitorCanChooseItsPaymentMode").')</span>');
220 foreach ($validpaymentmethod as $key => $val) {
221 if (is_array($val)) {
222 $listofval[$key] = $val;
223 } else {
224 $listofval[$key] = array('label' => $key, 'status' => 'valid');
225 }
226 }
227
228 print $form->selectarray("DONATION_NEWFORM_PAYONLINE", $listofval, getDolGlobalString('DONATION_NEWFORM_PAYONLINE'), 0);
229 print "</td></tr>\n";
230
231 print '</table>';
232 print '</div>';
233
234 print '<div class="center">';
235 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
236 print '</div>';
237}
238
239
240print dol_get_fiche_end();
241
242print '</form>';
243
244// End of page
245llxFooter();
246$db->close();
global $dolibarr_main_url_root
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
donation_admin_prepare_head()
Prepare array with list of admin tabs.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.