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