dolibarr 25.0.0-alpha
donation.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012-2015 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2013-2026 Philippe Grand <philippe.grand@atoo-net.com>
5 * Copyright (C) 2015-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
6 * Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
7 * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
30require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
44if (isModEnabled('accounting')) {
45 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
46}
47
48// Load translation files required by the page
49$langs->loadLangs(array('admin', 'donations', 'accountancy', 'other'));
50
51if (!$user->admin) {
53}
54
55$action = GETPOST('action', 'aZ09');
56$value = GETPOST('value');
57$label = GETPOST('label', 'alpha');
58$scandir = GETPOST('scan_dir', 'alpha');
59
60$type = 'donation';
61
62$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
63
64
65/*
66 * Action
67 */
68$error = 0;
69
70if ($action == 'specimen') {
71 $modele = GETPOST('module', 'alpha');
72
73 $don = new Don($db);
74 $don->initAsSpecimen();
75
76 // Search template files
77 $file = '';
78 if ($modele !== '') {
79 foreach ($dirmodels as $reldir) {
80 $file = dol_buildpath($reldir."core/modules/dons/".dol_sanitizeFileName($modele.".modules.php"), 0);
81 if (file_exists($file)) {
82 break;
83 }
84 $file = '';
85 }
86 }
87 if ($file !== '') {
88 require_once $file;
89
90 $classname = (string) $modele;
91 $obj = new $classname($db);
92 '@phan-var-force ModeleDon $obj';
95 if ($obj->write_file($don, $langs) > 0) {
96 // The specimen file is SPECIMEN.html or SPECIMEN.pdf according to the type of template
97 $specimenfile = empty($obj->result['fullpath']) ? 'SPECIMEN.html' : basename($obj->result['fullpath']);
98 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=".urlencode($specimenfile));
99 return;
100 } else {
101 setEventMessages($obj->error, $obj->errors, 'errors');
102 dol_syslog($obj->error, LOG_ERR);
103 }
104 } else {
105 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
106 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
107 }
108} elseif ($action == 'setdoc') {
109 // Set default model
110 if (dolibarr_set_const($db, "DON_ADDON_MODEL", $value, 'chaine', 0, '', $conf->entity)) {
111 // The constant that was read before the new set
112 // So we go through a variable for a coherent display
113 $conf->global->DON_ADDON_MODEL = $value;
114 }
115
116 // It enables the model
117 $ret = delDocumentModel($value, $type);
118 if ($ret > 0) {
119 $ret = addDocumentModel($value, $type, $label, $scandir);
120 }
121} elseif ($action == 'set') {
122 // Activate a model
123 $ret = addDocumentModel($value, $type, $label, $scandir);
124} elseif ($action == 'del') {
125 $ret = delDocumentModel($value, $type);
126 if ($ret > 0) {
127 if (getDolGlobalString('DON_ADDON_MODEL') == "$value") {
128 dolibarr_del_const($db, 'DON_ADDON_MODEL', $conf->entity);
129 }
130 }
131}
132
133// Options
134if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') {
135 $account = GETPOST('DONATION_ACCOUNTINGACCOUNT', 'alpha');
136
137 $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT", $account, 'chaine', 0, '', $conf->entity);
138
139 if (!($res > 0)) {
140 $error++;
141 }
142
143 if (!$error) {
144 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
145 $action = ''; // To avoid to execute next actions
146 } else {
147 setEventMessages($langs->trans("Error"), null, 'errors');
148 $action = ''; // To avoid to execute next actions
149 }
150}
151
152if ($action == 'set_DONATION_MESSAGE') {
153 $freemessage = GETPOST('DONATION_MESSAGE', 'restricthtml'); // No alpha here, we want exact string
154
155 $res = dolibarr_set_const($db, "DONATION_MESSAGE", $freemessage, 'chaine', 0, '', $conf->entity);
156
157 if (!($res > 0)) {
158 $error++;
159 }
160
161 if (!$error) {
162 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
163 $action = ''; // To avoid to execute next actions
164 } else {
165 setEventMessages($langs->trans("Error"), null, 'errors');
166 $action = ''; // To avoid to execute next actions
167 }
168}
169
170// Other cases
171$reg = array();
172if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
173 $code = $reg[1];
174 if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
175 header("Location: ".$_SERVER["PHP_SELF"]);
176 exit;
177 } else {
178 dol_print_error($db);
179 }
180}
181
182if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
183 $code = $reg[1];
184 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
185 header("Location: ".$_SERVER["PHP_SELF"]);
186 exit;
187 } else {
188 dol_print_error($db);
189 }
190}
191
192/*
193 * View
194 */
195
196$form = new Form($db);
197if (isModEnabled('accounting')) {
198 $formaccounting = new FormAccounting($db);
199} else {
200 $formaccounting = null;
201}
202
203$help_url = '';
204llxHeader('', $langs->trans("DonationsSetup"), $help_url, '', 0, 0, '', '', '', 'mod-donation page-admin');
205
206$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>';
207print load_fiche_titre($langs->trans("DonationsSetup"), $linkback, 'title_setup');
208
210
211print dol_get_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment');
212
213
214// Document templates
215print load_fiche_titre($langs->trans("DonationsModels"), '', '');
216
217// Defined the template definition table
218$type = 'donation';
219$def = array();
220$sql = "SELECT nom";
221$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
222$sql .= " WHERE type = '".$db->escape($type)."'";
223$resql = $db->query($sql);
224if ($resql) {
225 $i = 0;
226 $num_rows = $db->num_rows($resql);
227 while ($i < $num_rows) {
228 $array = $db->fetch_array($resql);
229 if (is_array($array)) {
230 array_push($def, $array[0]);
231 }
232 $i++;
233 }
234} else {
235 dol_print_error($db);
236}
237
238print '<table class="noborder centpercent">';
239print '<tr class="liste_titre">';
240print '<td>'.$langs->trans("Name").'</td>';
241print '<td>'.$langs->trans("Description").'</td>';
242print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
243print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
244print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
245print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
246print "</tr>\n";
247
248clearstatcache();
249
250// Templates can be provided by Dolibarr or by external modules (dir core/modules/dons/ of the module)
251$filelist = array();
252foreach ($dirmodels as $reldir) {
253 $dir = dol_buildpath($reldir."core/modules/dons/");
254 if (is_dir($dir)) {
255 foreach (dol_dir_list($dir, 'files', 0, '\.modules\.php$', '', 'name', SORT_ASC, 0, 1) as $tmpfile) {
256 if (!isset($filelist[$tmpfile['name']])) {
257 $filelist[$tmpfile['name']] = $tmpfile['fullname'];
258 }
259 }
260 }
261}
262
263if (count($filelist)) {
264 $arrayofmodels = array();
265
266 foreach ($filelist as $file => $fullpath) {
267 if (preg_match('/\.modules\.php$/i', $file)) {
268 $name = dol_substr($file, 0, dol_strlen($file) - 12);
269 $classname = dol_substr($file, 0, dol_strlen($file) - 12);
270
271 require_once $fullpath;
272 $module = new $classname($db);
273 '@phan-var-force ModeleDon $module';
276 // Show modules according to features level
277 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
278 continue;
279 }
280 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
281 continue;
282 }
283
284 if ($module->isEnabled()) {
285 $arrayofmodels[$name] = $module;
286 }
287 }
288 }
289
290 // Sort models by their position
291 $arrayofmodels = dol_sort_array($arrayofmodels, 'position');
292 '@phan-var-force array<string,ModeleDon> $arrayofmodels';
293
294 foreach ($arrayofmodels as $name => $module) {
295 print '<tr class="oddeven"><td width=\"100\">';
296 echo $module->name;
297 print '</td>';
298 print '<td>';
299 print $module->description;
300 print '</td>';
301
302 // Active
303 if (in_array($name, $def)) {
304 if (getDolGlobalString('DON_ADDON_MODEL') == $name) {
305 print "<td class=\"center\">\n";
306 print img_picto($langs->trans("Enabled"), 'switch_on');
307 print '</td>';
308 } else {
309 print "<td class=\"center\">\n";
310 print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"), 'switch_on').'</a>';
311 print '</td>';
312 }
313 } else {
314 print "<td class=\"center\">\n";
315 print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').'</a>';
316 print "</td>";
317 }
318
319 // Default
320 if (getDolGlobalString('DON_ADDON_MODEL') == "$name") {
321 print "<td class=\"center\">";
322 print img_picto($langs->trans("Default"), 'on');
323 print '</td>';
324 } else {
325 print "<td class=\"center\">";
326 print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&token='.newToken().'&value='.urlencode($name).'&scan_dir='.urlencode($module->scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
327 print '</td>';
328 }
329
330 // Info
331 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
332 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
333 if ($module->type == 'pdf') {
334 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
335 }
336 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
337 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
338 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
339 print '<td class="center">';
340 print $form->textwithpicto('', $htmltooltip, -1, 'info');
341 print '</td>';
342
343 // Preview
344 print '<td class="center">';
345 if ($module->type == 'pdf') {
346 // The PDF is sent as a download, a new window would stay empty
347 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($name).'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
348 } else {
349 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.urlencode($name).'" target="specimen">'.img_object($langs->trans("Preview"), 'generic').'</a>';
350 }
351 print '</td>';
352
353 print "</tr>\n";
354 }
355}
356
357print '</table><br>';
358
359/*
360 * Params
361 */
362print load_fiche_titre($langs->trans("Options"), '', '');
363
364print '<table class="noborder centpercent">';
365print '<tr class="liste_titre">';
366print '<td>'.$langs->trans("Parameters").'</td>';
367print '<td width="60" class="center">'.$langs->trans("Value")."</td>\n";
368print '<td></td>';
369print "</tr>\n";
370
371if (isModEnabled("societe")) {
372 print '<tr class="oddeven">';
373 print '<td colspan="2">';
374 print $langs->trans("DonationUseThirdparties");
375 print '</td>';
376 print '<td class="center">';
377 if ($conf->use_javascript_ajax) {
378 print ajax_constantonoff('DONATION_USE_THIRDPARTIES');
379 } else {
380 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
381 print $form->selectarray("DONATION_USE_THIRDPARTIES", $arrval, getDolGlobalString('DONATION_USE_THIRDPARTIES'));
382 }
383 print "</td>\n";
384 print "</tr>\n";
385}
386
387print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
388print '<input type="hidden" name="token" value="'.newToken().'" />';
389print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
390
391print '<tr class="oddeven">';
392print '<td>';
393$label = $langs->trans("AccountAccounting");
394print '<label for="DONATION_ACCOUNTINGACCOUNT">'.$label.'</label></td>';
395print '<td class="center">';
396if (isModEnabled('accounting') && is_object($formaccounting)) {
398 print $formaccounting->select_account(getDolGlobalString('DONATION_ACCOUNTINGACCOUNT'), 'DONATION_ACCOUNTINGACCOUNT', 1, array(), 1, 1);
399} else {
400 print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="' . getDolGlobalString('DONATION_ACCOUNTINGACCOUNT').'">';
401}
402print '</td><td class="center">';
403print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
404print "</td></tr>\n";
405print '</form>';
406
407print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
408print '<input type="hidden" name="token" value="'.newToken().'" />';
409print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
410
411print '<tr class="oddeven"><td colspan="2">';
412print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
413print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">' . getDolGlobalString('DONATION_MESSAGE').'</textarea>';
414print '</td><td class="center">';
415print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
416print "</td></tr>\n";
417
418print "</table>\n";
419print '</form>';
420
421/*
422 * French only parameters
423 */
424if (preg_match('/fr/i', $mysoc->country_code)) {
425 print '<br>';
426 print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
427
428 print '<table class="noborder centpercent">';
429 print '<tr class="liste_titre">';
430 print '<td>'.$langs->trans("Parameters").'</td>'."\n";
431 print '<td class="center">'.$langs->trans("Status").'</td>'."\n";
432 print "</tr>\n";
433
434 print '<tr class="oddeven">';
435 print '<td width="80%">'.$langs->trans("DONATION_ART200").'</td>';
436 print '<td class="center">';
437 if ($conf->use_javascript_ajax) {
438 print ajax_constantonoff('DONATION_ART200');
439 } else {
440 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
441 print $form->selectarray("DONATION_ART200", $arrval, getDolGlobalString('DONATION_ART200'));
442 }
443 print '</td></tr>';
444
445 print '<tr class="oddeven">';
446 print '<td width="80%">'.$langs->trans("DONATION_ART238").'</td>';
447 print '<td class="center">';
448 if ($conf->use_javascript_ajax) {
449 print ajax_constantonoff('DONATION_ART238');
450 } else {
451 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
452 print $form->selectarray("DONATION_ART238", $arrval, getDolGlobalString('DONATION_ART238'));
453 }
454 print '</td></tr>';
455
456 print '<tr class="oddeven">';
457 print '<td width="80%">'.$langs->trans("DONATION_ART978").'</td>';
458 print '<td class="center">';
459 if ($conf->use_javascript_ajax) {
460 print ajax_constantonoff('DONATION_ART978');
461 } else {
462 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
463 print $form->selectarray("DONATION_ART978", $arrval, getDolGlobalString('DONATION_ART978'));
464 }
465 print '</td></tr>';
466 print "</table>\n";
467}
468
469llxFooter();
470
471$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage donations.
Definition don.class.php:42
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
global $mysoc
donation_admin_prepare_head()
Prepare array with list of admin tabs.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
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.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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:542
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.