dolibarr  9.0.0
donation.php
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-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
6  * Copyright (C) 2015 Benoit Bruchard <benoitb21@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT . '/core/lib/donation.lib.php';
30 require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
32 if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('admin', 'donations', 'accountancy', 'other'));
36 
37 if (!$user->admin) accessforbidden();
38 
39 $typeconst=array('yesno','texte','chaine');
40 
41 $action = GETPOST('action','alpha');
42 $value = GETPOST('value');
43 $label = GETPOST('label','alpha');
44 $scandir = GETPOST('scan_dir','alpha');
45 
46 $type='donation';
47 
48 
49 /*
50  * Action
51  */
52 
53 if ($action == 'specimen')
54 {
55  $modele=GETPOST('module','alpha');
56 
57  $don = new Don($db);
58  $don->initAsSpecimen();
59 
60  // Search template files
61  $dir = DOL_DOCUMENT_ROOT . "/core/modules/dons/";
62  $file = $modele.".modules.php";
63  if (file_exists($dir.$file))
64  {
65  $classname = $modele;
66  require_once $dir.$file;
67 
68  $obj = new $classname($db);
69 
70  if ($obj->write_file($don,$langs) > 0)
71  {
72  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=donation&file=SPECIMEN.html");
73  return;
74  }
75  else
76  {
77  setEventMessages($obj->error, $obj->errors, 'errors');
78  dol_syslog($obj->error, LOG_ERR);
79  }
80  }
81  else
82  {
83  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
84  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
85  }
86 }
87 
88 // Set default model
89 else if ($action == 'setdoc')
90 {
91  if (dolibarr_set_const($db, "DON_ADDON_MODEL",$value,'chaine',0,'',$conf->entity))
92  {
93  // The constant that was read before the new set
94  // So we go through a variable for a coherent display
95  $conf->global->DON_ADDON_MODEL = $value;
96  }
97 
98  // It enables the model
99  $ret = delDocumentModel($value, $type);
100  if ($ret > 0)
101  {
102  $ret = addDocumentModel($value, $type, $label, $scandir);
103  }
104 }
105 
106 // Activate a model
107 else if ($action == 'set')
108 {
109  $ret = addDocumentModel($value, $type, $label, $scandir);
110 }
111 
112 else if ($action == 'del')
113 {
114  $ret = delDocumentModel($value, $type);
115  if ($ret > 0)
116  {
117  if ($conf->global->DON_ADDON_MODEL == "$value") dolibarr_del_const($db, 'DON_ADDON_MODEL',$conf->entity);
118  }
119 }
120 
121 // Options
122 if ($action == 'set_DONATION_ACCOUNTINGACCOUNT')
123 {
124  $account = GETPOST('DONATION_ACCOUNTINGACCOUNT','alpha');
125 
126  $res = dolibarr_set_const($db, "DONATION_ACCOUNTINGACCOUNT",$account,'chaine',0,'',$conf->entity);
127 
128  if (! $res > 0) $error++;
129 
130  if (! $error)
131  {
132  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
133  }
134  else
135  {
136  setEventMessages($langs->trans("Error"), null, 'errors');
137  }
138 }
139 
140 if ($action == 'set_DONATION_MESSAGE')
141 {
142  $freemessage = GETPOST('DONATION_MESSAGE','none'); // No alpha here, we want exact string
143 
144  $res = dolibarr_set_const($db, "DONATION_MESSAGE",$freemessage,'chaine',0,'',$conf->entity);
145 
146  if (! $res > 0) $error++;
147 
148  if (! $error)
149  {
150  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
151  }
152  else
153  {
154  setEventMessages($langs->trans("Error"), null, 'errors');
155  }
156 }
157 
158 // Activate an article
159 else if ($action == 'setart200') {
160  $setart200 = GETPOST('value', 'int');
161  $res = dolibarr_set_const($db, "DONATION_ART200", $setart200, 'yesno', 0, '', $conf->entity);
162  if (! $res > 0)
163  $error ++;
164 
165  if (! $error) {
166  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
167  } else {
168  setEventMessages($langs->trans("Error"), null, 'mesgs');
169  }
170 }
171 else if ($action == 'setart238') {
172  $setart238 = GETPOST('value', 'int');
173  $res = dolibarr_set_const($db, "DONATION_ART238", $setart238, 'yesno', 0, '', $conf->entity);
174  if (! $res > 0)
175  $error ++;
176 
177  if (! $error) {
178  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
179  } else {
180  setEventMessages($langs->trans("Error"), null, 'mesgs');
181  }
182 }
183 else if ($action == 'setart885') {
184  $setart885 = GETPOST('value', 'int');
185  $res = dolibarr_set_const($db, "DONATION_ART885", $setart885, 'yesno', 0, '', $conf->entity);
186  if (! $res > 0)
187  $error ++;
188 
189  if (! $error) {
190  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
191  } else {
192  setEventMessages($langs->trans("Error"), null, 'mesgs');
193  }
194 }
195 
196 /*
197  * View
198  */
199 
200 $dir = "../../core/modules/dons/";
201 $form=new Form($db);
202 if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
203 
204 llxHeader('',$langs->trans("DonationsSetup"),'DonConfiguration');
205 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
206 print load_fiche_titre($langs->trans("DonationsSetup"),$linkback,'title_setup');
207 
209 
210 dol_fiche_head($head, 'general', $langs->trans("Donations"), -1, 'payment');
211 
212 
213 // Document templates
214 print load_fiche_titre($langs->trans("DonationsModels"), '', '');
215 
216 // Defined the template definition table
217 $type='donation';
218 $def = array();
219 $sql = "SELECT nom";
220 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
221 $sql.= " WHERE type = '".$type."'";
222 $resql=$db->query($sql);
223 if ($resql)
224 {
225  $i = 0;
226  $num_rows=$db->num_rows($resql);
227  while ($i < $num_rows)
228  {
229  $array = $db->fetch_array($resql);
230  array_push($def, $array[0]);
231  $i++;
232  }
233 }
234 else
235 {
236  dol_print_error($db);
237 }
238 
239 print '<table class="noborder" width="100%">';
240 print '<tr class="liste_titre">';
241 print '<td>'.$langs->trans("Name").'</td>';
242 print '<td>'.$langs->trans("Description").'</td>';
243 print '<td align="center" width="60">'.$langs->trans("Activated").'</td>';
244 print '<td align="center" width="60">'.$langs->trans("Default").'</td>';
245 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
246 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
247 print "</tr>\n";
248 
249 clearstatcache();
250 
251 $handle=opendir($dir);
252 
253 if (is_resource($handle))
254 {
255  while (($file = readdir($handle))!==false)
256  {
257  if (preg_match('/\.modules\.php$/i',$file))
258  {
259  $name = substr($file, 0, dol_strlen($file) -12);
260  $classname = substr($file, 0, dol_strlen($file) -12);
261 
262  require_once $dir.'/'.$file;
263  $module=new $classname($db);
264 
265  // Show modules according to features level
266  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
267  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
268 
269  if ($module->isEnabled())
270  {
271  print '<tr class="oddeven"><td width=\"100\">';
272  echo $module->name;
273  print '</td>';
274  print '<td>';
275  print $module->description;
276  print '</td>';
277 
278  // Active
279  if (in_array($name, $def))
280  {
281  if ($conf->global->DON_ADDON_MODEL == $name)
282  {
283  print "<td align=\"center\">\n";
284  print img_picto($langs->trans("Enabled"),'switch_on');
285  print '</td>';
286  }
287  else
288  {
289  print "<td align=\"center\">\n";
290  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Enabled"),'switch_on').'</a>';
291  print '</td>';
292  }
293  }
294  else
295  {
296  print "<td align=\"center\">\n";
297  print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
298  print "</td>";
299  }
300 
301  // Default
302  if ($conf->global->DON_ADDON_MODEL == "$name")
303  {
304  print "<td align=\"center\">";
305  print img_picto($langs->trans("Default"),'on');
306  print '</td>';
307  }
308  else
309  {
310  print "<td align=\"center\">";
311  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
312  print '</td>';
313  }
314 
315  // Info
316  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
317  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
318  if ($module->type == 'pdf')
319  {
320  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
321  }
322  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
323  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
324  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
325  print '<td align="center">';
326  print $form->textwithpicto('',$htmltooltip,-1,0);
327  print '</td>';
328 
329  // Preview
330  print '<td align="center">';
331  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'" target="specimen">'.img_object($langs->trans("Preview"),'generic').'</a>';
332  print '</td>';
333 
334  print "</tr>\n";
335  }
336  }
337  }
338  closedir($handle);
339 }
340 
341 print '</table><br>';
342 
343 /*
344  * Params
345  */
346 print load_fiche_titre($langs->trans("Options"), '', '');
347 
348 print '<table class="noborder" width="100%">';
349 print '<tr class="liste_titre">';
350 print '<td>'.$langs->trans("Parameters").'</td>';
351 print '<td width="60" align="center">'.$langs->trans("Value")."</td>\n";
352 print '<td></td>';
353 print "</tr>\n";
354 
355 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
356 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
357 print '<input type="hidden" name="action" value="set_DONATION_ACCOUNTINGACCOUNT" />';
358 
359 print '<tr class="oddeven">';
360 
361 print '<td>';
362 $label = $langs->trans("AccountAccounting");
363 print '<label for="DONATION_ACCOUNTINGACCOUNT">' . $label . '</label></td>';
364 print '<td>';
365 if (! empty($conf->accounting->enabled))
366 {
367  print $formaccounting->select_account($conf->global->DONATION_ACCOUNTINGACCOUNT, 'DONATION_ACCOUNTINGACCOUNT', 1, '', 1, 1);
368 }
369 else
370 {
371  print '<input type="text" size="10" id="DONATION_ACCOUNTINGACCOUNT" name="DONATION_ACCOUNTINGACCOUNT" value="' . $conf->global->DONATION_ACCOUNTINGACCOUNT . '">';
372 }
373 print '</td><td align="right">';
374 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
375 print "</td></tr>\n";
376 print '</form>';
377 
378 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
379 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
380 print '<input type="hidden" name="action" value="set_DONATION_MESSAGE" />';
381 
382 print '<tr class="oddeven"><td colspan="2">';
383 print $langs->trans("FreeTextOnDonations").' '.img_info($langs->trans("AddCRIfTooLong")).'<br>';
384 print '<textarea name="DONATION_MESSAGE" class="flat" cols="80">'.$conf->global->DONATION_MESSAGE.'</textarea>';
385 print '</td><td align="right">';
386 print '<input type="submit" class="button" value="'.$langs->trans("Modify").'" />';
387 print "</td></tr>\n";
388 
389 print "</table>\n";
390 print '</form>';
391 
392 /*
393  * French params
394  */
395 if (preg_match('/fr/i',$conf->global->MAIN_INFO_SOCIETE_COUNTRY))
396 {
397  print '<br>';
398  print load_fiche_titre($langs->trans("FrenchOptions"), '', '');
399 
400  print '<table class="noborder" width="100%">';
401  print '<tr class="liste_titre">';
402  print '<td colspan="3">' . $langs->trans('Parameters') . '</td>';
403  print "</tr>\n";
404 
405  print '<tr class="oddeven">';
406  print '<td width="80%">' . $langs->trans("DONATION_ART200") . '</td>';
407  if (! empty($conf->global->DONATION_ART200)) {
408  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart200&value=0">';
409  print img_picto($langs->trans("Activated"), 'switch_on');
410  print '</a></td>';
411  } else {
412  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart200&value=1">';
413  print img_picto($langs->trans("Disabled"), 'switch_off');
414  print '</a></td>';
415  }
416  print '</tr>';
417 
418  print '<tr class="oddeven">';
419  print '<td width="80%">' . $langs->trans("DONATION_ART238") . '</td>';
420  if (! empty($conf->global->DONATION_ART238)) {
421  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart238&value=0">';
422  print img_picto($langs->trans("Activated"), 'switch_on');
423  print '</a></td>';
424  } else {
425  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart238&value=1">';
426  print img_picto($langs->trans("Disabled"), 'switch_off');
427  print '</a></td>';
428  }
429  print '</tr>';
430 
431  print '<tr class="oddeven">';
432  print '<td width="80%">' . $langs->trans("DONATION_ART885") . '</td>';
433  if (! empty($conf->global->DONATION_ART885)) {
434  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart885&value=0">';
435  print img_picto($langs->trans("Activated"), 'switch_on');
436  print '</a></td>';
437  } else {
438  print '<td align="center" colspan="2"><a href="' . $_SERVER['PHP_SELF'] . '?action=setart885&value=1">';
439  print img_picto($langs->trans("Disabled"), 'switch_off');
440  print '</a></td>';
441  }
442  print '</tr>';
443  print "</table>\n";
444 }
445 
446 llxFooter();
447 
448 $db->close();
delDocumentModel($name, $type)
Delete document model used by doc generator.
Definition: admin.lib.php:1643
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
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:510
img_info($titlealt='default')
Show info logo.
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
Definition: admin.lib.php:1609
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage donations.
Definition: don.class.php:35
Class to manage generation of HTML components for accounting management.
donation_admin_prepare_head()
Prepare array with list of admin tabs.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)