dolibarr 25.0.0-alpha
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 '<div class="info">'.$langs->trans("BlankDonationFormDesc").'</div>';
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}
158
159print '<div class="neutral">';
160print $enabledisablehtml;
161print '<input type="hidden" id="DONATION_ENABLE_PUBLIC" name="DONATION_ENABLE_PUBLIC" value="'.(!getDolGlobalString('DONATION_ENABLE_PUBLIC') ? 0 : 1).'">';
162print '</div>';
163
164print '<br>';
165
166
167if (getDolGlobalString('DONATION_ENABLE_PUBLIC')) {
168 print '<br>';
169 print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('BlankDonationForm').'</span><br>';
170 if (isModEnabled('multicompany')) {
171 $entity_qr = '?entity='.((int) $conf->entity);
172 } else {
173 $entity_qr = '';
174 }
175
176 // Define $urlwithroot
177 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
178 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
179
180 print '<div class="urllink">';
181 print '<input type="text" id="publicurldonation" class="quatrevingtpercentminusx" value="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">';
182 print '<a target="_blank" rel="noopener noreferrer" href="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
183 print '</div>';
184 print ajax_autoselect('publicurldonation');
185
186 print '<br><br>';
187
188 print '<div class="div-table-responsive-no-min">';
189 print '<table class="noborder centpercent">';
190
191 print '<tr class="liste_titre">';
192 print '<td>'.$langs->trans("Parameter").'</td>';
193 print '<td>'.$langs->trans("Value").'</td>';
194 print "</tr>\n";
195
196 // Min amount
197 print '<tr class="oddeven" id="tredit"><td>';
198 print $langs->trans("MinimumAmountDonation");
199 print '</td><td>';
200 print '<input type="text" class="right width50" id="DONATION_MIN_AMOUNT" name="DONATION_MIN_AMOUNT" value="'.getDolGlobalString('DONATION_MIN_AMOUNT').'">';
201 print "</td></tr>\n";
202
203 // Show counter of validated donations publicly
204 print '<tr class="oddeven" id="tredit"><td>';
205 print $langs->trans("donationCountersArePublic");
206 print '</td><td>';
207 print $form->selectyesno("DONATION_COUNTERS_ARE_PUBLIC", getDolGlobalInt('DONATION_COUNTERS_ARE_PUBLIC'), 1, false, 0, 1);
208 print "</td></tr>\n";
209
210 // Jump to an online payment page
211 print '<tr class="oddeven" id="trpayment"><td>';
212 print $langs->trans("DONATION_NEWFORM_PAYONLINE");
213 print '</td><td>';
214
215 // Initialize $validpaymentmethod
216 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
217 $validpaymentmethod = getValidOnlinePaymentMethods('', 1);
218
219 // Define $listofval using the $validpaymentmethod
220 $listofval = array();
221 $listofval['-1'] = array('label' => $langs->trans('No'));
222 $listofval['all'] = array('label' => $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')', 'data-html' => $langs->trans('Yes').' &nbsp; <span class="opacitymedium">('.$langs->trans("VisitorCanChooseItsPaymentMode").')</span>');
223 foreach ($validpaymentmethod as $key => $val) {
224 if (is_array($val)) {
225 $listofval[$key] = $val;
226 } else {
227 $listofval[$key] = array('label' => $key, 'status' => 'valid');
228 }
229 }
230
231 print $form->selectarray("DONATION_NEWFORM_PAYONLINE", $listofval, getDolGlobalString('DONATION_NEWFORM_PAYONLINE'), 0);
232 print "</td></tr>\n";
233
234 print '</table>';
235 print '</div>';
236
237 print '<div class="center">';
238 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
239 print '</div>';
240}
241
242
243print dol_get_fiche_end();
244
245print '</form>';
246
247// End of page
248llxFooter();
249$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:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.