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