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