dolibarr  19.0.0-dev
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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/donation.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
33 if (isModEnabled('accounting')) {
34  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
35 }
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('admin', 'donations', 'accountancy', 'other'));
39 
40 if (!$user->admin) {
42 }
43 
44 $action = GETPOST('action', 'aZ09');
45 $value = GETPOST('value');
46 $label = GETPOST('label', 'alpha');
47 $scandir = GETPOST('scan_dir', 'alpha');
48 
49 $type = 'donation';
50 
51 
52 /*
53  * Action
54  */
55 
56 if ($action == 'specimen') {
57  $modele = GETPOST('module', 'alpha');
58 
59  $don = new Don($db);
60  $don->initAsSpecimen();
61 
62  // Search template files
63  $dir = DOL_DOCUMENT_ROOT."/core/modules/dons/";
64  $file = $modele.".modules.php";
65  if (file_exists($dir.$file)) {
66  $classname = $modele;
67  require_once $dir.$file;
68 
69  $obj = new $classname($db);
70 
71  if ($obj->write_file($don, $langs) > 0) {
72  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
73  return;
74  } else {
75  setEventMessages($obj->error, $obj->errors, 'errors');
76  dol_syslog($obj->error, LOG_ERR);
77  }
78  } else {
79  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
80  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
81  }
82 } elseif ($action == 'setdoc') {
83  // Set default model
84  if (dolibarr_set_const($db, "DON_ADDON_MODEL", $value, 'chaine', 0, '', $conf->entity)) {
85  // The constant that was read before the new set
86  // So we go through a variable for a coherent display
87  $conf->global->DON_ADDON_MODEL = $value;
88  }
89 
90  // It enables the model
91  $ret = delDocumentModel($value, $type);
92  if ($ret > 0) {
93  $ret = addDocumentModel($value, $type, $label, $scandir);
94  }
95 } elseif ($action == 'set') {
96  // Activate a model
97  $ret = addDocumentModel($value, $type, $label, $scandir);
98 } elseif ($action == 'del') {
99  $ret = delDocumentModel($value, $type);
100  if ($ret > 0) {
101  if ($conf->global->DON_ADDON_MODEL == "$value") {
102  dolibarr_del_const($db, 'DON_ADDON_MODEL', $conf->entity);
103  }
104  }
105 }
106 
107 // Options
108 if ($action == 'set_DONATION_ACCOUNTINGACCOUNT') {
109  $account = GETPOST('DONATION_ACCOUNTINGACCOUNT', 'alpha');
110 
111  $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT", $account, 'chaine', 0, '', $conf->entity);
112 
113  if (!($res > 0)) {
114  $error++;
115  }
116 
117  if (!$error) {
118  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
119  $action = ''; // To avoid to execute next actions
120  } else {
121  setEventMessages($langs->trans("Error"), null, 'errors');
122  $action = ''; // To avoid to execute next actions
123  }
124 }
125 
126 if ($action == 'set_DONATION_MESSAGE') {
127  $freemessage = GETPOST('DONATION_MESSAGE', 'restricthtml'); // No alpha here, we want exact string
128 
129  $res = dolibarr_set_const($db, "DONATION_MESSAGE", $freemessage, 'chaine', 0, '', $conf->entity);
130 
131  if (!($res > 0)) {
132  $error++;
133  }
134 
135  if (!$error) {
136  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
137  $action = ''; // To avoid to execute next actions
138  } else {
139  setEventMessages($langs->trans("Error"), null, 'errors');
140  $action = ''; // To avoid to execute next actions
141  }
142 }
143 
144 // Other cases
145 $reg = array();
146 if (preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) {
147  $code = $reg[1];
148  if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) {
149  header("Location: ".$_SERVER["PHP_SELF"]);
150  exit;
151  } else {
152  dol_print_error($db);
153  }
154 }
155 
156 if (preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) {
157  $code = $reg[1];
158  if (dolibarr_del_const($db, $code, $conf->entity) > 0) {
159  header("Location: ".$_SERVER["PHP_SELF"]);
160  exit;
161  } else {
162  dol_print_error($db);
163  }
164 }
165 
166 /*
167  * View
168  */
169 
170 $dir = "../../core/modules/dons/";
171 $form = new Form($db);
172 if (isModEnabled('accounting')) {
173  $formaccounting = new FormAccounting($db);
174 }
175 
176 llxHeader('', $langs->trans("DonationsSetup"), 'DonConfiguration');
177 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
178 print load_fiche_titre($langs->trans("DonationsSetup"), $linkback, 'title_setup');
179 
181 
182 print dol_get_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment');
183 
184 
185 // Document templates
186 print load_fiche_titre($langs->trans("DonationsModels"), '', '');
187 
188 // Defined the template definition table
189 $type = 'donation';
190 $def = array();
191 $sql = "SELECT nom";
192 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
193 $sql .= " WHERE type = '".$db->escape($type)."'";
194 $resql = $db->query($sql);
195 if ($resql) {
196  $i = 0;
197  $num_rows = $db->num_rows($resql);
198  while ($i < $num_rows) {
199  $array = $db->fetch_array($resql);
200  array_push($def, $array[0]);
201  $i++;
202  }
203 } else {
204  dol_print_error($db);
205 }
206 
207 print '<table class="noborder centpercent">';
208 print '<tr class="liste_titre">';
209 print '<td>'.$langs->trans("Name").'</td>';
210 print '<td>'.$langs->trans("Description").'</td>';
211 print '<td class="center" width="60">'.$langs->trans("Activated").'</td>';
212 print '<td class="center" width="60">'.$langs->trans("Default").'</td>';
213 print '<td class="center" width="80">'.$langs->trans("ShortInfo").'</td>';
214 print '<td class="center" width="80">'.$langs->trans("Preview").'</td>';
215 print "</tr>\n";
216 
217 clearstatcache();
218 
219 $handle = opendir($dir);
220 
221 if (is_resource($handle)) {
222  while (($file = readdir($handle)) !== false) {
223  if (preg_match('/\.modules\.php$/i', $file)) {
224  $name = substr($file, 0, dol_strlen($file) - 12);
225  $classname = substr($file, 0, dol_strlen($file) - 12);
226 
227  require_once $dir.'/'.$file;
228  $module = new $classname($db);
229 
230  // Show modules according to features level
231  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) {
232  continue;
233  }
234  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) {
235  continue;
236  }
237 
238  if ($module->isEnabled()) {
239  print '<tr class="oddeven"><td width=\"100\">';
240  echo $module->name;
241  print '</td>';
242  print '<td>';
243  print $module->description;
244  print '</td>';
245 
246  // Active
247  if (in_array($name, $def)) {
248  if ($conf->global->DON_ADDON_MODEL == $name) {
249  print "<td class=\"center\">\n";
250  print img_picto($langs->trans("Enabled"), 'switch_on');
251  print '</td>';
252  } else {
253  print "<td class=\"center\">\n";
254  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>';
255  print '</td>';
256  }
257  } else {
258  print "<td class=\"center\">\n";
259  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>';
260  print "</td>";
261  }
262 
263  // Default
264  if ($conf->global->DON_ADDON_MODEL == "$name") {
265  print "<td class=\"center\">";
266  print img_picto($langs->trans("Default"), 'on');
267  print '</td>';
268  } else {
269  print "<td class=\"center\">";
270  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>';
271  print '</td>';
272  }
273 
274  // Info
275  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
276  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
277  if ($module->type == 'pdf') {
278  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
279  }
280  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
281  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
282  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
283  print '<td class="center">';
284  print $form->textwithpicto('', $htmltooltip, -1, 0);
285  print '</td>';
286 
287  // Preview
288  print '<td class="center">';
289  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"), 'generic').'</a>';
290  print '</td>';
291 
292  print "</tr>\n";
293  }
294  }
295  }
296  closedir($handle);
297 }
298 
299 print '</table><br>';
300 
301 /*
302  * Params
303  */
304 print load_fiche_titre($langs->trans("Options"), '', '');
305 
306 print '<table class="noborder centpercent">';
307 print '<tr class="liste_titre">';
308 print '<td>'.$langs->trans("Parameters").'</td>';
309 print '<td width="60" class="center">'.$langs->trans("Value")."</td>\n";
310 print '<td></td>';
311 print "</tr>\n";
312 
313 if (isModEnabled("societe")) {
314  print '<tr class="oddeven">';
315  print '<td colspan="2">';
316  print $langs->trans("DonationUseThirdparties");
317  print '</td>';
318  print '<td class="center">';
319  if ($conf->use_javascript_ajax) {
320  print ajax_constantonoff('DONATION_USE_THIRDPARTIES');
321  } else {
322  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
323  print $form->selectarray("DONATION_USE_THIRDPARTIES", $arrval, $conf->global->DONATION_USE_THIRDPARTIES);
324  }
325  print "</td>\n";
326  print "</tr>\n";
327 }
328 
329 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
330 print '<input type="hidden" name="token" value="'.newToken().'" />';
331 print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
332 
333 print '<tr class="oddeven">';
334 print '<td>';
335 $label = $langs->trans("AccountAccounting");
336 print '<label for="DONATION_ACCOUNTINGACCOUNT">'.$label.'</label></td>';
337 print '<td class="center">';
338 if (isModEnabled('accounting')) {
339  print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
340 } else {
341  print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="'.$conf->global->DONATION_ACCOUNTINGACCOUNT.'">';
342 }
343 print '</td><td class="center">';
344 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
345 print "</td></tr>\n";
346 print '</form>';
347 
348 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
349 print '<input type="hidden" name="token" value="'.newToken().'" />';
350 print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
351 
352 print '<tr class="oddeven"><td colspan="2">';
353 print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
354 print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">'.$conf->global->DONATION_MESSAGE.'</textarea>';
355 print '</td><td class="center">';
356 print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'" />';
357 print "</td></tr>\n";
358 
359 print "</table>\n";
360 print '</form>';
361 
362 /*
363  * French params
364  */
365 if (preg_match('/fr/i', $conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
366  print '<br>';
367  print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
368 
369  print '<table class="noborder centpercent">';
370  print '<tr class="liste_titre">';
371  print '<td>'.$langs->trans("Parameters").'</td>'."\n";
372  print '<td class="center">'.$langs->trans("Status").'</td>'."\n";
373  print "</tr>\n";
374 
375  print '<tr class="oddeven">';
376  print '<td width="80%">'.$langs->trans("DONATION_ART200").'</td>';
377  print '<td class="center">';
378  if ($conf->use_javascript_ajax) {
379  print ajax_constantonoff('DONATION_ART200');
380  } else {
381  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
382  print $form->selectarray("DONATION_ART200", $arrval, $conf->global->DONATION_ART200);
383  }
384  print '</td></tr>';
385 
386  print '<tr class="oddeven">';
387  print '<td width="80%">'.$langs->trans("DONATION_ART238").'</td>';
388  print '<td class="center">';
389  if ($conf->use_javascript_ajax) {
390  print ajax_constantonoff('DONATION_ART238');
391  } else {
392  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
393  print $form->selectarray("DONATION_ART238", $arrval, $conf->global->DONATION_ART238);
394  }
395  print '</td></tr>';
396 
397  print '<tr class="oddeven">';
398  print '<td width="80%">'.$langs->trans("DONATION_ART978").'</td>';
399  print '<td class="center">';
400  if ($conf->use_javascript_ajax) {
401  print ajax_constantonoff('DONATION_ART978');
402  } else {
403  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
404  print $form->selectarray("DONATION_ART978", $arrval, $conf->global->DONATION_ART978);
405  }
406  print '</td></tr>';
407  print "</table>\n";
408 }
409 
410 llxFooter();
411 
412 $db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1918
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).
Definition: admin.lib.php:638
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
Definition: admin.lib.php:562
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1949
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='inline-block')
On/off button for constant.
Definition: ajax.lib.php:630
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage donations.
Definition: don.class.php:40
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
donation_admin_prepare_head()
Prepare array with list of admin tabs.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.