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