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