dolibarr  9.0.0
expensereport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
8  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
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 <http://www.gnu.org/licenses/>.
23  */
24 
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('admin', 'errors', 'trips', 'other'));
39 
40 if (! $user->admin) accessforbidden();
41 
42 $action = GETPOST('action','alpha');
43 $value = GETPOST('value','alpha');
44 $label = GETPOST('label','alpha');
45 $scandir = GETPOST('scan_dir','alpha');
46 $type='expensereport';
47 
48 
49 /*
50  * Actions
51  */
52 
53 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
54 
55 if ($action == 'updateMask')
56 {
57  $maskconst=GETPOST('maskconst','alpha');
58  $maskvalue=GETPOST('maskvalue','alpha');
59  if ($maskconst) $res = dolibarr_set_const($db,$maskconst,$maskvalue,'chaine',0,'',$conf->entity);
60 
61  if (! $res > 0) $error++;
62 
63  if (! $error)
64  {
65  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
66  }
67  else
68  {
69  setEventMessages($langs->trans("Error"), null, 'errors');
70  }
71 }
72 
73 else if ($action == 'specimen') // For fiche inter
74 {
75  $modele= GETPOST('module','alpha');
76 
77  $inter = new ExpenseReport($db);
78  $inter->initAsSpecimen();
79  $inter->status = 0; // Force statut draft to show watermark
80  $inter->fk_statut = 0; // Force statut draft to show watermark
81 
82  // Search template files
83  $file=''; $classname=''; $filefound=0;
84  $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
85  foreach($dirmodels as $reldir)
86  {
87  $file=dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php",0);
88  if (file_exists($file))
89  {
90  $filefound=1;
91  $classname = "pdf_".$modele;
92  break;
93  }
94  }
95 
96  if ($filefound)
97  {
98  require_once $file;
99 
100  $module = new $classname($db);
101 
102  if ($module->write_file($inter,$langs) > 0)
103  {
104  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
105  return;
106  }
107  else
108  {
109  setEventMessages($module->error, $module->errors,'errors');
110  dol_syslog($module->error, LOG_ERR);
111  }
112  }
113  else
114  {
115  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
116  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
117  }
118 }
119 
120 // Activate a model
121 else if ($action == 'set')
122 {
123  $ret = addDocumentModel($value, $type, $label, $scandir);
124  if ($ret > 0 && empty($conf->global->EXPENSEREPORT_ADDON_PDF))
125  {
126  dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value,'chaine',0,'',$conf->entity);
127  }
128 }
129 
130 else if ($action == 'del')
131 {
132  $ret = delDocumentModel($value, $type);
133  if ($ret > 0)
134  {
135  if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$value") dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF',$conf->entity);
136  }
137 }
138 
139 // Set default model
140 else if ($action == 'setdoc')
141 {
142  if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
143  {
144  // La constante qui a ete lue en avant du nouveau set
145  // on passe donc par une variable pour avoir un affichage coherent
146  $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
147  }
148 
149  // On active le modele
150  $ret = delDocumentModel($value, $type);
151  if ($ret > 0)
152  {
153  $ret = addDocumentModel($value, $type, $label, $scandir);
154  }
155 }
156 
157 else if ($action == 'setmod')
158 {
159  // TODO Verifier si module numerotation choisi peut etre active
160  // par appel methode canBeActivated
161 
162  dolibarr_set_const($db, "EXPENSEREPORT_ADDON",$value,'chaine',0,'',$conf->entity);
163 }
164 
165 else if ($action == 'setoptions')
166 {
167  $db->begin();
168 
169  $freetext= GETPOST('EXPENSEREPORT_FREE_TEXT','none'); // No alpha here, we want exact string
170  $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
171 
172  $draft= GETPOST('EXPENSEREPORT_DRAFT_WATERMARK','alpha');
173  $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK",trim($draft),'chaine',0,'',$conf->entity);
174 
175  if (! $res1 > 0 || ! $res2 > 0) $error++;
176 
177  if (! $error)
178  {
179  $db->commit();
180  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
181  }
182  else
183  {
184  $db->rollback();
185  setEventMessages($langs->trans("Error"), null, 'errors');
186  }
187 }
188 
189 
190 /*
191  * View
192  */
193 
194 $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
195 
196 llxHeader('',$langs->trans("ExpenseReportsSetup"));
197 
198 $form=new Form($db);
199 
200 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
201 print load_fiche_titre($langs->trans("ExpenseReportsSetup"),$linkback,'title_setup');
202 
203 
205 
206 dol_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');
207 
208 /*
209  * Expense report numbering model
210  */
211 
212 print load_fiche_titre($langs->trans("ExpenseReportNumberingModules"),'','');
213 
214 print '<table class="noborder" width="100%">';
215 print '<tr class="liste_titre">';
216 print '<td>'.$langs->trans("Name").'</td>';
217 print '<td>'.$langs->trans("Description").'</td>';
218 print '<td class="nowrap">'.$langs->trans("Example").'</td>';
219 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
220 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
221 print '</tr>'."\n";
222 
223 clearstatcache();
224 
225 foreach ($dirmodels as $reldir)
226 {
227  $dir = dol_buildpath($reldir."core/modules/expensereport/");
228 
229  if (is_dir($dir))
230  {
231  $handle = opendir($dir);
232  if (is_resource($handle))
233  {
234  while (($file = readdir($handle))!==false)
235  {
236  if (substr($file, 0, 18) == 'mod_expensereport_' && substr($file, dol_strlen($file)-3, 3) == 'php')
237  {
238  $file = substr($file, 0, dol_strlen($file)-4);
239 
240  require_once $dir.$file.'.php';
241 
242  $module = new $file($db);
243 
244  // Show modules according to features level
245  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
246  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
247 
248  if ($module->isEnabled())
249  {
250 
251  print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
252  print $module->info();
253  print '</td>';
254 
255  // Show example of numbering model
256  print '<td class="nowrap">';
257  $tmp=$module->getExample();
258  if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
259  elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
260  else print $tmp;
261  print '</td>'."\n";
262 
263  print '<td align="center">';
264  if ($conf->global->EXPENSEREPORT_ADDON == $file)
265  {
266  print img_picto($langs->trans("Activated"),'switch_on');
267  }
268  else
269  {
270  print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
271  print img_picto($langs->trans("Disabled"),'switch_off');
272  print '</a>';
273  }
274  print '</td>';
275 
276  $exp=new ExpenseReport($db);
277  $exp->initAsSpecimen();
278 
279  // Info
280  $htmltooltip='';
281  $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
282  $nextval=$module->getNextValue($exp);
283  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
284  $htmltooltip.=''.$langs->trans("NextValue").': ';
285  if ($nextval) {
286  if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
287  $nextval = $langs->trans($nextval);
288  $htmltooltip.=$nextval.'<br>';
289  } else {
290  $htmltooltip.=$langs->trans($module->error).'<br>';
291  }
292  }
293 
294  print '<td align="center">';
295  print $form->textwithpicto('',$htmltooltip,1,0);
296  print '</td>';
297 
298  print "</tr>\n";
299  }
300  }
301  }
302  closedir($handle);
303  }
304  }
305 }
306 print "</table><br>\n";
307 
308 /*
309  * Documents models for Interventions
310  */
311 
312 print load_fiche_titre($langs->trans("TemplatePDFExpenseReports"), '', '');
313 
314 // Defini tableau def des modeles
315 $type='expensereport';
316 $def = array();
317 $sql = "SELECT nom";
318 $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
319 $sql.= " WHERE type = '".$type."'";
320 $sql.= " AND entity = ".$conf->entity;
321 $resql=$db->query($sql);
322 if ($resql)
323 {
324  $i = 0;
325  $num_rows=$db->num_rows($resql);
326  while ($i < $num_rows)
327  {
328  $array = $db->fetch_array($resql);
329  array_push($def, $array[0]);
330  $i++;
331  }
332 }
333 else
334 {
335  dol_print_error($db);
336 }
337 
338 print '<table class="noborder" width="100%">';
339 print '<tr class="liste_titre">';
340 print '<td>'.$langs->trans("Name").'</td>';
341 print '<td>'.$langs->trans("Description").'</td>';
342 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
343 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
344 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
345 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
346 print "</tr>\n";
347 
348 clearstatcache();
349 
350 foreach ($dirmodels as $reldir)
351 {
352  $dir = dol_buildpath($reldir."core/modules/expensereport/doc");
353 
354  if (is_dir($dir))
355  {
356  $handle=opendir($dir);
357  if (is_resource($handle))
358  {
359  while (($file = readdir($handle))!==false)
360  {
361  $filelist[]=$file;
362  }
363  closedir($handle);
364  arsort($filelist);
365 
366  foreach($filelist as $file)
367  {
368  if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
369  {
370 
371  if (file_exists($dir.'/'.$file))
372  {
373 
374  $name = substr($file, 4, dol_strlen($file) -16);
375  $classname = substr($file, 0, dol_strlen($file) -12);
376 
377  require_once $dir.'/'.$file;
378  $module = new $classname($db);
379 
380  $modulequalified=1;
381  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0;
382  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0;
383 
384  if ($modulequalified)
385  {
386  print '<tr class="oddeven"><td width="100">';
387  print (empty($module->name)?$name:$module->name);
388  print "</td><td>\n";
389  if (method_exists($module,'info')) print $module->info($langs);
390  else print $module->description;
391  print '</td>';
392 
393  // Active
394  if (in_array($name, $def))
395  {
396  print "<td align=\"center\">\n";
397  print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
398  print img_picto($langs->trans("Enabled"),'switch_on');
399  print '</a>';
400  print "</td>";
401  }
402  else
403  {
404  print "<td align=\"center\">\n";
405  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>';
406  print "</td>";
407  }
408 
409  // Default
410  print "<td align=\"center\">";
411  if ($conf->global->EXPENSEREPORT_ADDON_PDF == "$name")
412  {
413  print img_picto($langs->trans("Default"),'on');
414  }
415  else
416  {
417  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>';
418  }
419  print '</td>';
420 
421  // Info
422  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
423  $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
424  $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
425  $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
426  $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
427  $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
428  $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
429  $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
430  $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
431  print '<td align="center">';
432  print $form->textwithpicto('',$htmltooltip,-1,0);
433  print '</td>';
434 
435  // Preview
436  print '<td align="center">';
437  if ($module->type == 'pdf')
438  {
439  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'intervention').'</a>';
440  }
441  else
442  {
443  print img_object($langs->trans("PreviewNotAvailable"),'generic');
444  }
445  print '</td>';
446 
447  print '</tr>';
448  }
449  }
450  }
451  }
452  }
453  }
454 }
455 
456 print '</table>';
457 
458 
459 print '<br>';
460 
461 
462 
463 /*
464  * Other options
465  */
466 
467 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
468 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
469 print '<input type="hidden" name="action" value="setoptions">';
470 
471 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
472 print '<table class="noborder" width="100%">';
473 print '<tr class="liste_titre">';
474 print '<td>'.$langs->trans("Parameter").'</td>';
475 print '<td align="center" width="60"></td>';
476 print "</tr>\n";
477 
478 $substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
479 $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
480 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
481 foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
482 $htmltext.='</i>';
483 
484 print '<tr class="oddeven"><td colspan="2">';
485 print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
486 $variablename='EXPENSEREPORT_FREE_TEXT';
487 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
488 {
489  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
490 }
491 else
492 {
493  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
494  $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
495  print $doleditor->Create();
496 }
497 print '</td></tr>'."\n";
498 
499 //Use draft Watermark
500 
501 print '<tr class="oddeven"><td colspan="2">';
502 print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
503 print '<input size="50" class="flat" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.$conf->global->EXPENSEREPORT_DRAFT_WATERMARK.'">';
504 print '</td></tr>'."\n";
505 
506 print '</table>';
507 
508 print '<div class="center">';
509 print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
510 print '</div>';
511 
512 print '</form>';
513 
514 dol_fiche_end();
515 
516 // End of page
517 llxFooter();
518 $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
expensereport_admin_prepare_head()
Return array head with list of tabs to view object informations.
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...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
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
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
Class to manage Trips and Expenses.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition: pdf.lib.php:623
Class to manage a WYSIWYG editor.
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)