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