dolibarr 23.0.3
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 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 = new HookManager($db);
54$hookmanager->initHooks(array('newpayment'));
55
56if (!$user->admin) {
58}
59
60$error = 0;
61
62
63/*
64 * Actions
65 */
66
67if ($action == 'setDONATION_ENABLE_PUBLIC') {
68 if (GETPOST('value')) {
69 dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 1, 'chaine', 0, '', $conf->entity);
70 } else {
71 dolibarr_set_const($db, 'DONATION_ENABLE_PUBLIC', 0, 'chaine', 0, '', $conf->entity);
72 }
73}
74
75if ($action == 'update') {
76 $public = GETPOST('DONATION_ENABLE_PUBLIC');
77
78 $minamount = GETPOST('DONATION_MIN_AMOUNT');
79 $publiccounters = GETPOST('DONATION_COUNTERS_ARE_PUBLIC');
80 $payonline = GETPOST('DONATION_NEWFORM_PAYONLINE');
81
82 $res = dolibarr_set_const($db, "DONATION_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity);
83 $res = dolibarr_set_const($db, "DONATION_MIN_AMOUNT", $minamount, 'chaine', 0, '', $conf->entity);
84 $res = dolibarr_set_const($db, "DONATION_COUNTERS_ARE_PUBLIC", $publiccounters, 'chaine', 0, '', $conf->entity);
85 $res = dolibarr_set_const($db, "DONATION_NEWFORM_PAYONLINE", $payonline, 'chaine', 0, '', $conf->entity);
86
87 if (!($res > 0)) {
88 $error++;
89 }
90
91 if (!$error) {
92 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
93 } else {
94 setEventMessages($langs->trans("Error"), null, 'errors');
95 }
96}
97
98
99/*
100 * View
101 */
102
103$form = new Form($db);
104
105$title = $langs->trans("DonationsSetup");
106$help_url = 'EN:Module_Donation|FR:Module_Don';
107
108llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-don page-admin_website');
109
110
111$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>';
112print load_fiche_titre($title, $linkback, 'title_setup');
113
115
116
117
118print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
119print '<input type="hidden" name="action" value="update">';
120print '<input type="hidden" name="token" value="'.newToken().'">';
121
122print dol_get_fiche_head($head, 'website', $langs->trans("Donations"), -1, 'payment');
123
124if ($conf->use_javascript_ajax) {
125 print "\n".'<script type="text/javascript">';
126 print 'jQuery(document).ready(function () {
127 function initfields()
128 {
129 if (jQuery("#DONATION_ENABLE_PUBLIC").val()==\'0\') {
130 jQuery("#trforcetype, #tramount, #tredit, #trpayment").hide();
131 }
132 if (jQuery("#DONATION_ENABLE_PUBLIC").val()==\'1\') {
133 jQuery("#trforcetype, #tramount, #tredit, #trpayment").show();
134 }
135 }
136 initfields();
137 jQuery("#DONATION_ENABLE_PUBLIC").change(function() { initfields(); });
138 })';
139 print '</script>'."\n";
140}
141
142
143print '<span class="opacitymedium">'.$langs->trans("BlankDonationFormDesc").'</span><br><br>';
144
145$param = '';
146
147$enabledisablehtml = $langs->trans("EnablePublicDonationForm").' ';
148if (!getDolGlobalString('DONATION_ENABLE_PUBLIC')) {
149 // Button off, click to enable
150 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setDONATION_ENABLE_PUBLIC&token='.newToken().'&value=1'.$param.'">';
151 $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
152 $enabledisablehtml .= '</a>';
153} else {
154 // Button on, click to disable
155 $enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setDONATION_ENABLE_PUBLIC&token='.newToken().'&value=0'.$param.'">';
156 $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
157 $enabledisablehtml .= '</a>';
158}
159print $enabledisablehtml;
160print '<input type="hidden" id="DONATION_ENABLE_PUBLIC" name="DONATION_ENABLE_PUBLIC" value="'.(!getDolGlobalString('DONATION_ENABLE_PUBLIC') ? 0 : 1).'">';
161
162print '<br><br>';
163
164
165if (getDolGlobalString('DONATION_ENABLE_PUBLIC')) {
166 print '<br>';
167 print img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans('BlankDonationForm').'</span><br>';
168 if (isModEnabled('multicompany')) {
169 $entity_qr = '?entity='.((int) $conf->entity);
170 } else {
171 $entity_qr = '';
172 }
173
174 // Define $urlwithroot
175 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
176 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
177
178 print '<div class="urllink">';
179 print '<input type="text" id="publicurldonation" class="quatrevingtpercentminusx" value="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">';
180 print '<a target="_blank" rel="noopener noreferrer" href="'.$urlwithroot.'/public/donations/new.php'.$entity_qr.'">'.img_picto('', 'globe', 'class="paddingleft"').'</a>';
181 print '</div>';
182 print ajax_autoselect('publicurldonation');
183
184 print '<br><br>';
185
186 print '<div class="div-table-responsive-no-min">';
187 print '<table class="noborder centpercent">';
188
189 print '<tr class="liste_titre">';
190 print '<td>'.$langs->trans("Parameter").'</td>';
191 print '<td>'.$langs->trans("Value").'</td>';
192 print "</tr>\n";
193
194 // Min amount
195 print '<tr class="oddeven" id="tredit"><td>';
196 print $langs->trans("MinimumAmountDonation");
197 print '</td><td>';
198 print '<input type="text" class="right width50" id="DONATION_MIN_AMOUNT" name="DONATION_MIN_AMOUNT" value="'.getDolGlobalString('DONATION_MIN_AMOUNT').'">';
199 print "</td></tr>\n";
200
201 // Show counter of validated donations publicly
202 print '<tr class="oddeven" id="tredit"><td>';
203 print $langs->trans("donationCountersArePublic");
204 print '</td><td>';
205 print $form->selectyesno("DONATION_COUNTERS_ARE_PUBLIC", getDolGlobalInt('DONATION_COUNTERS_ARE_PUBLIC'), 1, false, 0, 1);
206 print "</td></tr>\n";
207
208 // Jump to an online payment page
209 print '<tr class="oddeven" id="trpayment"><td>';
210 print $langs->trans("DONATION_NEWFORM_PAYONLINE");
211 print '</td><td>';
212
213 // Initialize $validpaymentmethod
214 // The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
215 $validpaymentmethod = getValidOnlinePaymentMethods('', 1);
216
217 // Define $listofval using the $validpaymentmethod
218 $listofval = array();
219 $listofval['-1'] = array('label' => $langs->trans('No'));
220 $listofval['all'] = array('label' => $langs->trans('Yes').' ('.$langs->trans("VisitorCanChooseItsPaymentMode").')', 'data-html' => $langs->trans('Yes').' &nbsp; <span class="opacitymedium">('.$langs->trans("VisitorCanChooseItsPaymentMode").')</span>');
221 foreach ($validpaymentmethod as $key => $val) {
222 if (is_array($val)) {
223 $listofval[$key] = $val;
224 } else {
225 $listofval[$key] = array('label' => $key, 'status' => 'valid');
226 }
227 }
228
229 print $form->selectarray("DONATION_NEWFORM_PAYONLINE", $listofval, getDolGlobalString('DONATION_NEWFORM_PAYONLINE'), 0);
230 print "</td></tr>\n";
231
232 print '</table>';
233 print '</div>';
234
235 print '<div class="center">';
236 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'">';
237 print '</div>';
238}
239
240
241print dol_get_fiche_end();
242
243print '</form>';
244
245// End of page
246llxFooter();
247$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.
Class to manage hooks.
donation_admin_prepare_head()
Prepare array with list of admin tabs.
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.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
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)
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.