dolibarr  13.0.2
holiday.php
1 <?php
2 /* Copyright (C) 2011-2019 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
4  * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
5  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("admin", "errors", "holiday"));
35 
36 if (!$user->admin) accessforbidden();
37 
38 $action = GETPOST('action', 'aZ09');
39 $value = GETPOST('value', 'alpha');
40 $label = GETPOST('label', 'alpha');
41 $scandir = GETPOST('scan_dir', 'alpha');
42 $type = 'contract';
43 
44 if (empty($conf->global->HOLIDAY_ADDON))
45 {
46  $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
47 }
48 
49 
50 /*
51  * Actions
52  */
53 
54 include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
55 
56 if ($action == 'updateMask')
57 {
58  $maskconst = GETPOST('maskconstholiday', 'alpha');
59  $maskvalue = GETPOST('maskholiday', 'alpha');
60  if ($maskconst) $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
61 
62  if (!($res > 0)) $error++;
63 
64  if (!$error)
65  {
66  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
67  } else {
68  setEventMessages($langs->trans("Error"), null, 'errors');
69  }
70 } elseif ($action == 'specimen') // For contract
71 {
72  $modele = GETPOST('module', 'alpha');
73 
74  $holiday = new Holiday($db);
75  $holiday->initAsSpecimen();
76 
77  // Search template files
78  $file = ''; $classname = ''; $filefound = 0;
79  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
80  foreach ($dirmodels as $reldir)
81  {
82  $file = dol_buildpath($reldir."core/modules/holiday/doc/pdf_".$modele.".modules.php", 0);
83  if (file_exists($file))
84  {
85  $filefound = 1;
86  $classname = "pdf_".$modele;
87  break;
88  }
89  }
90 
91  if ($filefound)
92  {
93  require_once $file;
94 
95  $module = new $classname($db);
96 
97  if ($module->write_file($holiday, $langs) > 0)
98  {
99  header("Location: ".DOL_URL_ROOT."/document.php?modulepart=holiday&file=SPECIMEN.pdf");
100  return;
101  } else {
102  setEventMessages($obj->error, $obj->errors, 'errors');
103  dol_syslog($obj->error, LOG_ERR);
104  }
105  } else {
106  setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
107  dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
108  }
109 }
110 
111 // Activate a model
112 elseif ($action == 'set')
113 {
114  $ret = addDocumentModel($value, $type, $label, $scandir);
115 } elseif ($action == 'del')
116 {
117  $ret = delDocumentModel($value, $type);
118  if ($ret > 0)
119  {
120  if ($conf->global->HOLIDAY_ADDON_PDF == "$value") dolibarr_del_const($db, 'HOLIDAY_ADDON_PDF', $conf->entity);
121  }
122 }
123 
124 // Set default model
125 elseif ($action == 'setdoc')
126 {
127  if (dolibarr_set_const($db, "HOLIDAY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity))
128  {
129  // La constante qui a ete lue en avant du nouveau set
130  // on passe donc par une variable pour avoir un affichage coherent
131  $conf->global->HOLIDAY_ADDON_PDF = $value;
132  }
133 
134  // On active le modele
135  $ret = delDocumentModel($value, $type);
136  if ($ret > 0)
137  {
138  $ret = addDocumentModel($value, $type, $label, $scandir);
139  }
140 } elseif ($action == 'setmod')
141 {
142  // TODO Verifier si module numerotation choisi peut etre active
143  // par appel methode canBeActivated
144 
145  dolibarr_set_const($db, "HOLIDAY_ADDON", $value, 'chaine', 0, '', $conf->entity);
146 } elseif ($action == 'set_other')
147 {
148  $freetext = GETPOST('HOLIDAY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
149  $res1 = dolibarr_set_const($db, "HOLIDAY_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
150 
151  $draft = GETPOST('HOLIDAY_DRAFT_WATERMARK', 'alpha');
152  $res2 = dolibarr_set_const($db, "HOLIDAY_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
153 
154  if (!$res1 > 0 || !$res2 > 0) $error++;
155 
156  if (!$error)
157  {
158  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
159  } else {
160  setEventMessages($langs->trans("Error"), null, 'errors');
161  }
162 }
163 
164 
165 /*
166  * View
167  */
168 
169 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
170 
171 llxHeader();
172 
173 $form = new Form($db);
174 
175 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
176 print load_fiche_titre($langs->trans("HolidaySetup"), $linkback, 'title_setup');
177 
179 
180 print dol_get_fiche_head($head, 'holiday', $langs->trans("Holidays"), -1, 'holiday');
181 
182 /*
183  * Holiday Numbering model
184  */
185 
186 print load_fiche_titre($langs->trans("HolidaysNumberingModules"), '', '');
187 
188 print '<div class="div-table-responsive-no-min">';
189 print '<table class="noborder centpercent">';
190 print '<tr class="liste_titre">';
191 print '<td width="100">'.$langs->trans("Name").'</td>';
192 print '<td>'.$langs->trans("Description").'</td>';
193 print '<td>'.$langs->trans("Example").'</td>';
194 print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
195 print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
196 print "</tr>\n";
197 
198 clearstatcache();
199 
200 foreach ($dirmodels as $reldir)
201 {
202  $dir = dol_buildpath($reldir."core/modules/holiday/");
203 
204  if (is_dir($dir))
205  {
206  $handle = opendir($dir);
207  if (is_resource($handle))
208  {
209  while (($file = readdir($handle)) !== false)
210  {
211  if (substr($file, 0, 12) == 'mod_holiday_' && substr($file, dol_strlen($file) - 3, 3) == 'php')
212  {
213  $file = substr($file, 0, dol_strlen($file) - 4);
214 
215  require_once $dir.$file.'.php';
216 
217  $module = new $file($db);
218 
219  // Show modules according to features level
220  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
221  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
222 
223  if ($module->isEnabled())
224  {
225  print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
226  print $module->info();
227  print '</td>';
228 
229  // Show example of numbering model
230  print '<td class="nowrap">';
231  $tmp = $module->getExample();
232  if (preg_match('/^Error/', $tmp)) {
233  $langs->load("errors");
234  print '<div class="error">'.$langs->trans($tmp).'</div>';
235  } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp);
236  else print $tmp;
237  print '</td>'."\n";
238 
239  print '<td class="center">';
240  if ($conf->global->HOLIDAY_ADDON == "$file")
241  {
242  print img_picto($langs->trans("Activated"), 'switch_on');
243  } else {
244  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;token='.newToken().'&amp;value='.urlencode($file).'">';
245  print img_picto($langs->trans("Disabled"), 'switch_off');
246  print '</a>';
247  }
248  print '</td>';
249 
250  $holiday = new Holiday($db);
251  $holiday->initAsSpecimen();
252 
253  // Info
254  $htmltooltip = '';
255  $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
256  $nextval = $module->getNextValue($mysoc, $holiday);
257  if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
258  $htmltooltip .= ''.$langs->trans("NextValue").': ';
259  if ($nextval) {
260  if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured')
261  $nextval = $langs->trans($nextval);
262  $htmltooltip .= $nextval.'<br>';
263  } else {
264  $htmltooltip .= $langs->trans($module->error).'<br>';
265  }
266  }
267 
268  print '<td class="center">';
269  print $form->textwithpicto('', $htmltooltip, 1, 0);
270  print '</td>';
271 
272  print '</tr>';
273  }
274  }
275  }
276  closedir($handle);
277  }
278  }
279 }
280 
281 print '</table>';
282 print '</div>';
283 
284 print '<br>';
285 
286 
287 if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
288  print dol_get_fiche_end();
289  // End of page
290  llxFooter();
291  $db->close();
292  exit;
293 }
294 
295 /*
296  * Documents models for Holidays
297  */
298 
299 print load_fiche_titre($langs->trans("TemplatePDFHolidays"), '', '');
300 
301 // Defined model definition table
302 $def = array();
303 $sql = "SELECT nom";
304 $sql .= " FROM ".MAIN_DB_PREFIX."document_model";
305 $sql .= " WHERE type = '".$db->escape($type)."'";
306 $sql .= " AND entity = ".$conf->entity;
307 $resql = $db->query($sql);
308 if ($resql)
309 {
310  $i = 0;
311  $num_rows = $db->num_rows($resql);
312  while ($i < $num_rows)
313  {
314  $array = $db->fetch_array($resql);
315  array_push($def, $array[0]);
316  $i++;
317  }
318 } else {
319  dol_print_error($db);
320 }
321 
322 
323 print '<div class="div-table-responsive-no-min">';
324 print '<table class="noborder centpercent">';
325 print '<tr class="liste_titre">';
326 print '<td>'.$langs->trans("Name").'</td>';
327 print '<td>'.$langs->trans("Description").'</td>';
328 print '<td align="center" width="60">'.$langs->trans("Status")."</td>\n";
329 print '<td align="center" width="60">'.$langs->trans("Default")."</td>\n";
330 print '<td align="center" width="80">'.$langs->trans("ShortInfo").'</td>';
331 print '<td align="center" width="80">'.$langs->trans("Preview").'</td>';
332 print "</tr>\n";
333 
334 clearstatcache();
335 
336 foreach ($dirmodels as $reldir)
337 {
338  foreach (array('', '/doc') as $valdir)
339  {
340  $realpath = $reldir."core/modules/holiday".$valdir;
341  $dir = dol_buildpath($realpath);
342 
343  if (is_dir($dir))
344  {
345  $handle = opendir($dir);
346  if (is_resource($handle))
347  {
348  while (($file = readdir($handle)) !== false)
349  {
350  $filelist[] = $file;
351  }
352  closedir($handle);
353  arsort($filelist);
354 
355  foreach ($filelist as $file)
356  {
357  if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file))
358  {
359  if (file_exists($dir.'/'.$file))
360  {
361  $name = substr($file, 4, dol_strlen($file) - 16);
362  $classname = substr($file, 0, dol_strlen($file) - 12);
363 
364  require_once $dir.'/'.$file;
365  $module = new $classname($db);
366 
367  $modulequalified = 1;
368  if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0;
369  if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0;
370 
371  if ($modulequalified)
372  {
373  print '<tr class="oddeven"><td width="100">';
374  print (empty($module->name) ? $name : $module->name);
375  print "</td><td>\n";
376  if (method_exists($module, 'info')) print $module->info($langs);
377  else print $module->description;
378  print '</td>';
379 
380  // Active
381  if (in_array($name, $def))
382  {
383  print '<td class="center">'."\n";
384  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
385  print img_picto($langs->trans("Enabled"), 'switch_on');
386  print '</a>';
387  print '</td>';
388  } else {
389  print '<td class="center">'."\n";
390  print '<a class="reposition" 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>';
391  print "</td>";
392  }
393 
394  // Default
395  print '<td class="center">';
396  if ($conf->global->HOLIDAY_ADDON_PDF == $name)
397  {
398  print img_picto($langs->trans("Default"), 'on');
399  } else {
400  print '<a class="reposition" 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>';
401  }
402  print '</td>';
403 
404  // Info
405  $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
406  $htmltooltip .= '<br>'.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown"));
407  if ($module->type == 'pdf')
408  {
409  $htmltooltip .= '<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
410  }
411  $htmltooltip .= '<br>'.$langs->trans("Path").': '.preg_replace('/^\//', '', $realpath).'/'.$file;
412 
413  $htmltooltip .= '<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
414  $htmltooltip .= '<br>'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1);
415  $htmltooltip .= '<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg, 1, 1);
416  $htmltooltip .= '<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg, 1, 1);
417  $htmltooltip .= '<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1);
418  $htmltooltip .= '<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark, 1, 1);
419 
420 
421  print '<td class="center">';
422  print $form->textwithpicto('', $htmltooltip, 1, 0);
423  print '</td>';
424 
425  // Preview
426  print '<td class="center">';
427  if ($module->type == 'pdf')
428  {
429  print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"), 'pdf').'</a>';
430  } else {
431  print img_object($langs->trans("PreviewNotAvailable"), 'generic');
432  }
433  print '</td>';
434 
435  print "</tr>\n";
436  }
437  }
438  }
439  }
440  }
441  }
442  }
443 }
444 
445 print '</table>';
446 print '</div>';
447 print "<br>";
448 
449 
450 /*
451  * Other options
452  */
453 
454 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
455 print '<input type="hidden" name="token" value="'.newToken().'">';
456 print '<input type="hidden" name="action" value="set_other">';
457 
458 print load_fiche_titre($langs->trans("OtherOptions"), '', '');
459 
460 print '<div class="div-table-responsive-no-min">';
461 print '<table class="noborder centpercent">';
462 print '<tr class="liste_titre">';
463 print '<td>'.$langs->trans("Parameter").'</td>';
464 print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
465 print "</tr>\n";
466 
467 $substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
468 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
469 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
470 foreach ($substitutionarray as $key => $val) $htmltext .= $key.'<br>';
471 $htmltext .= '</i>';
472 
473 print '<tr class="oddeven"><td colspan="2">';
474 print $form->textwithpicto($langs->trans("FreeLegalTextOnHolidays"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
475 print '<br>';
476 $variablename = 'HOLIDAY_FREE_TEXT';
477 if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
478 {
479  print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
480 } else {
481  include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
482  $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes');
483  print $doleditor->Create();
484 }
485 print '</td></tr>'."\n";
486 
487 //Use draft Watermark
488 
489 print '<tr class="oddeven"><td>';
490 print $form->textwithpicto($langs->trans("WatermarkOnDraftHolidayCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
491 print '</td><td>';
492 print '<input size="50" class="flat" type="text" name="HOLIDAY_DRAFT_WATERMARK" value="'.$conf->global->HOLIDAY_DRAFT_WATERMARK.'">';
493 print '</td></tr>'."\n";
494 
495 print '</table>';
496 print '</div>';
497 
498 
499 print '<div class="center">';
500 print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
501 print '</div>';
502 
503 print '</form>';
504 
505 
506 
507 print dol_get_fiche_end();
508 
509 // End of page
510 llxFooter();
511 $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
Class of the module paid holiday.
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
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
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 ...
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:643
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
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...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
print $_SERVER["PHP_SELF"] n
Edit parameters.
Definition: categories.php:101
Class to manage a WYSIWYG editor.
llxFooter()
Empty footer.
Definition: wrapper.php:59
holiday_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: holiday.lib.php:76
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.