dolibarr 23.0.3
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-2017 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-2025 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.'/don/class/don.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
43if (isModEnabled('accounting')) {
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
45}
46
47// Load translation files required by the page
48$langs->loadLangs(array('admin', 'donations', 'accountancy', 'other'));
49
50if (!$user->admin) {
52}
53
54$action = GETPOST('action', 'aZ09');
55$value = GETPOST('value');
56$label = GETPOST('label', 'alpha');
57$scandir = GETPOST('scan_dir', 'alpha');
58
59$type = 'donation';
60
61
62/*
63 * Action
64 */
65$error = 0;
66
67if ($action == 'specimen') {
68 $modele = GETPOST('module', 'alpha');
69
70 $don = new Don($db);
71 $don->initAsSpecimen();
72
73 // Search template files
74 $dir = DOL_DOCUMENT_ROOT."/core/modules/dons/";
75 $file = $modele.".modules.php";
76 if ($modele !== '' && file_exists($dir.$file)) {
77 require_once $dir.$file;
78
79 $classname = (string) $modele;
80 $obj = new $classname($db);
81 '@phan-var-force ModeleDon $obj';
84 if ($obj->write_file($don, $langs) > 0) {
85 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
86 return;
87 } else {
88 setEventMessages($obj->error, $obj->errors, 'errors');
89 dol_syslog($obj->error, LOG_ERR);
90 }
91 } else {
92 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
93 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
94 }
95} elseif ($action == 'setdoc') {
96 // Set default model
97 if (dolibarr_set_const($db, "DON_ADDON_MODEL", $value, 'chaine', 0, '', $conf->entity)) {
98 // The constant that was read before the new set
99 // So we go through a variable for a coherent display
100 $conf->global->DON_ADDON_MODEL = $value;
101 }
102
103 // It enables the model
104 $ret = delDocumentModel($value, $type);
105 if ($ret > 0) {
106 $ret = addDocumentModel($value, $type, $label, $scandir);
107 }
108} elseif ($action == 'set') {
109 // Activate a model
110 $ret = addDocumentModel($value, $type, $label, $scandir);
111} elseif ($action == 'del') {
112 $ret = delDocumentModel($value, $type);
113 if ($ret > 0) {
114 if (getDolGlobalString('DON_ADDON_MODEL') == "$value") {
115 dolibarr_del_const($db, 'DON_ADDON_MODEL', $conf->entity);
116 }
117 }
118}
119
120// Options
121if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') {
122 $account = GETPOST('DONATION_ACCOUNTINGACCOUNT', 'alpha');
123
124 $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT", $account, 'chaine', 0, '', $conf->entity);
125
126 if (!($res > 0)) {
127 $error++;
128 }
129
130 if (!$error) {
131 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
132 $action = ''; // To avoid to execute next actions
133 } else {
134 setEventMessages($langs->trans("Error"), null, 'errors');
135 $action = ''; // To avoid to execute next actions
136 }
137}
138
139if ($action == 'set_DONATION_MESSAGE') {
140 $freemessage = GETPOST('DONATION_MESSAGE', 'restricthtml'); // No alpha here, we want exact string
141
142 $res = dolibarr_set_const($db, "DONATION_MESSAGE", $freemessage, 'chaine', 0, '', $conf->entity);
143
144 if (!($res > 0)) {
145 $error++;
146 }
147
148 if (!$error) {
149 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
150 $action = ''; // To avoid to execute next actions
151 } else {
152 setEventMessages($langs->trans("Error"), null, 'errors');
153 $action = ''; // To avoid to execute next actions
154 }
155}
156
157// Other cases
158$reg = array();
159if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
160 $code = $reg[1];
161 if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
162 header("Location: ".$_SERVER["PHP_SELF"]);
163 exit;
164 } else {
165 dol_print_error($db);
166 }
167}
168
169if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
170 $code = $reg[1];
171 if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
172 header("Location: ".$_SERVER["PHP_SELF"]);
173 exit;
174 } else {
175 dol_print_error($db);
176 }
177}
178
179/*
180 * View
181 */
182
183$dir = "../../core/modules/dons/";
184$form = new Form($db);
185if (isModEnabled('accounting')) {
186 $formaccounting = new FormAccounting($db);
187}
188
189$help_url = '';
190llxHeader('', $langs->trans("DonationsSetup"), $help_url, '', 0, 0, '', '', '', 'mod-donation page-admin');
191
192$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>';
193print load_fiche_titre($langs->trans("DonationsSetup"), $linkback, 'title_setup');
194
196
197print dol_get_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment');
198
199
200// Document templates
201print load_fiche_titre($langs->trans("DonationsModels"), '', '');
202
203// Defined the template definition table
204$type = 'donation';
205$def = array();
206$sql = "SELECT nom";
207$sql .= " FROM ".MAIN_DB_PREFIX."document_model";
208$sql .= " WHERE type = '".$db->escape($type)."'";
209$resql = $db->query($sql);
210if ($resql) {
211 $i = 0;
212 $num_rows = $db->num_rows($resql);
213 while ($i < $num_rows) {
214 $array = $db->fetch_array($resql);
215 if (is_array($array)) {
216 array_push($def, $array[0]);
217 }
218 $i++;
219 }
220} else {
221 dol_print_error($db);
222}
223
224print '<table class="noborder centpercent">';
225print '<tr class="liste_titre">';
226print '<td>'.$langs->trans("Name").'</td>';
227print '<td>'.$langs->trans("Description").'</td>';
228print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
229print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
230print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
231print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
232print "</tr>\n";
233
234clearstatcache();
235
236$handle = opendir($dir);
237
238if (is_resource($handle)) {
239 while (($file = readdir($handle)) !== false) {
240 if (preg_match('/\.modules\.php$/i', $file)) {
241 $name = substr($file, 0, dol_strlen($file) - 12);
242 $classname = substr($file, 0, dol_strlen($file) - 12);
243
244 require_once $dir.'/'.$file;
245 $module = new $classname($db);
246 '@phan-var-force ModeleDon $module';
249 // Show modules according to features level
250 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
251 continue;
252 }
253 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
254 continue;
255 }
256
257 if ($module->isEnabled()) {
258 print '<tr class="oddeven"><td width=\"100\">';
259 echo $module->name;
260 print '</td>';
261 print '<td>';
262 print $module->description;
263 print '</td>';
264
265 // Active
266 if (in_array($name, $def)) {
267 if (getDolGlobalString('DON_ADDON_MODEL') == $name) {
268 print "<td class=\"center\">\n";
269 print img_picto($langs->trans("Enabled"), 'switch_on');
270 print '</td>';
271 } else {
272 print "<td class=\"center\">\n";
273 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>';
274 print '</td>';
275 }
276 } else {
277 print "<td class=\"center\">\n";
278 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>';
279 print "</td>";
280 }
281
282 // Default
283 if (getDolGlobalString('DON_ADDON_MODEL') == "$name") {
284 print "<td class=\"center\">";
285 print img_picto($langs->trans("Default"), 'on');
286 print '</td>';
287 } else {
288 print "<td class=\"center\">";
289 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>';
290 print '</td>';
291 }
292
293 // Info
294 $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
295 $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
296 if ($module->type == 'pdf') {
297 $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
298 }
299 $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
300 $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
301 $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
302 print '<td class="center">';
303 print $form->textwithpicto('', $htmltooltip, -1, 'info');
304 print '</td>';
305
306 // Preview
307 print '<td class="center">';
308 print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"), 'generic').'</a>';
309 print '</td>';
310
311 print "</tr>\n";
312 }
313 }
314 }
315 closedir($handle);
316}
317
318print '</table><br>';
319
320/*
321 * Params
322 */
323print load_fiche_titre($langs->trans("Options"), '', '');
324
325print '<table class="noborder centpercent">';
326print '<tr class="liste_titre">';
327print '<td>'.$langs->trans("Parameters").'</td>';
328print '<td width="60" class="center">'.$langs->trans("Value")."</td>\n";
329print '<td></td>';
330print "</tr>\n";
331
332if (isModEnabled("societe")) {
333 print '<tr class="oddeven">';
334 print '<td colspan="2">';
335 print $langs->trans("DonationUseThirdparties");
336 print '</td>';
337 print '<td class="center">';
338 if ($conf->use_javascript_ajax) {
339 print ajax_constantonoff('DONATION_USE_THIRDPARTIES');
340 } else {
341 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
342 print $form->selectarray("DONATION_USE_THIRDPARTIES", $arrval, getDolGlobalString('DONATION_USE_THIRDPARTIES'));
343 }
344 print "</td>\n";
345 print "</tr>\n";
346}
347
348print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
349print '<input type="hidden" name="token" value="'.newToken().'" />';
350print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
351
352print '<tr class="oddeven">';
353print '<td>';
354$label = $langs->trans("AccountAccounting");
355print '<label for="DONATION_ACCOUNTINGACCOUNT">'.$label.'</label></td>';
356print '<td class="center">';
357if (isModEnabled('accounting')) {
359 print $formaccounting->select_account(getDolGlobalString('DONATION_ACCOUNTINGACCOUNT'), 'DONATION_ACCOUNTINGACCOUNT', 1, array(), 1, 1);
360} else {
361 print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="' . getDolGlobalString('DONATION_ACCOUNTINGACCOUNT').'">';
362}
363print '</td><td class="center">';
364print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
365print "</td></tr>\n";
366print '</form>';
367
368print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
369print '<input type="hidden" name="token" value="'.newToken().'" />';
370print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
371
372print '<tr class="oddeven"><td colspan="2">';
373print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
374print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">' . getDolGlobalString('DONATION_MESSAGE').'</textarea>';
375print '</td><td class="center">';
376print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
377print "</td></tr>\n";
378
379print "</table>\n";
380print '</form>';
381
382/*
383 * French only parameters
384 */
385if (preg_match('/fr/i', $mysoc->country_code)) {
386 print '<br>';
387 print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
388
389 print '<table class="noborder centpercent">';
390 print '<tr class="liste_titre">';
391 print '<td>'.$langs->trans("Parameters").'</td>'."\n";
392 print '<td class="center">'.$langs->trans("Status").'</td>'."\n";
393 print "</tr>\n";
394
395 print '<tr class="oddeven">';
396 print '<td width="80%">'.$langs->trans("DONATION_ART200").'</td>';
397 print '<td class="center">';
398 if ($conf->use_javascript_ajax) {
399 print ajax_constantonoff('DONATION_ART200');
400 } else {
401 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
402 print $form->selectarray("DONATION_ART200", $arrval, getDolGlobalString('DONATION_ART200'));
403 }
404 print '</td></tr>';
405
406 print '<tr class="oddeven">';
407 print '<td width="80%">'.$langs->trans("DONATION_ART238").'</td>';
408 print '<td class="center">';
409 if ($conf->use_javascript_ajax) {
410 print ajax_constantonoff('DONATION_ART238');
411 } else {
412 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
413 print $form->selectarray("DONATION_ART238", $arrval, getDolGlobalString('DONATION_ART238'));
414 }
415 print '</td></tr>';
416
417 print '<tr class="oddeven">';
418 print '<td width="80%">'.$langs->trans("DONATION_ART978").'</td>';
419 print '<td class="center">';
420 if ($conf->use_javascript_ajax) {
421 print ajax_constantonoff('DONATION_ART978');
422 } else {
423 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
424 print $form->selectarray("DONATION_ART978", $arrval, getDolGlobalString('DONATION_ART978'));
425 }
426 print '</td></tr>';
427 print "</table>\n";
428}
429
430llxFooter();
431
432$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
Class to manage donations.
Definition don.class.php:41
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
global $mysoc
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
img_info($titlealt='default')
Show info logo.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.