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