dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.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 <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php';
42
43// Load translation files required by the page
44$langs->loadLangs(array("admin", "holiday", "other"));
45
46if (!$user->admin) {
48}
49
50$action = GETPOST('action', 'aZ09');
51$value = GETPOST('value', 'alpha');
52$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
53
54$label = GETPOST('label', 'alpha');
55$scandir = GETPOST('scan_dir', 'alpha');
56$type = 'contract';
57
58if (!getDolGlobalString('HOLIDAY_ADDON')) {
59 $conf->global->HOLIDAY_ADDON = 'mod_holiday_madonna';
60}
61
62
63/*
64 * Actions
65 */
66$error = 0;
67
68include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
69
70if ($action == 'updateMask') {
71 $maskconst = GETPOST('maskconstholiday', 'aZ09');
72 $maskvalue = GETPOST('maskholiday', 'alpha');
73 $res = 0;
74 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
75 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
76 }
77
78 if (!($res > 0)) {
79 $error++;
80 }
81
82 if (!$error) {
83 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
84 } else {
85 setEventMessages($langs->trans("Error"), null, 'errors');
86 }
87} elseif ($action == 'specimen') { // For contract
88 $modele = GETPOST('module', 'alpha');
89
90 $holiday = new Holiday($db);
91 $holiday->initAsSpecimen();
92
93 // Search template files
94 $file = '';
95 $classname = '';
96 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
97 foreach ($dirmodels as $reldir) {
98 $file = dol_buildpath($reldir."core/modules/holiday/doc/pdf_".$modele.".modules.php", 0);
99 if (file_exists($file)) {
100 $classname = "pdf_".$modele;
101 break;
102 }
103 }
104
105 if ($classname !== '') {
106 require_once $file;
107
108 $module = new $classname($db);
109 '@phan-var-force ModelePDFHoliday $module';
110
111 if ($module->write_file($holiday, $langs) > 0) {
112 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=holiday&file=SPECIMEN.pdf");
113 return;
114 } else {
115 setEventMessages($module->error, $module->errors, 'errors');
116 dol_syslog($module->error, LOG_ERR);
117 }
118 } else {
119 $langs->load('errors');
120 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
121 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
122 }
123} elseif ($action == 'set') {
124 // Activate a model
125 $ret = addDocumentModel($value, $type, $label, $scandir);
126} elseif ($action == 'del') {
127 $ret = delDocumentModel($value, $type);
128 if ($ret > 0) {
129 if (getDolGlobalString('HOLIDAY_ADDON_PDF') == "$value") {
130 dolibarr_del_const($db, 'HOLIDAY_ADDON_PDF', $conf->entity);
131 }
132 }
133} elseif ($action == 'setdoc') {
134 // Set default model
135 if (dolibarr_set_const($db, "HOLIDAY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
136 // The constant that was read before the new set
137 // so we go through a variable to get a consistent display
138 $conf->global->HOLIDAY_ADDON_PDF = $value;
139 }
140
141 // On active le modele
142 $ret = delDocumentModel($value, $type);
143 if ($ret > 0) {
144 $ret = addDocumentModel($value, $type, $label, $scandir);
145 }
146} elseif ($action == 'setmod') {
147 // TODO Verifier si module numerotation choisi peut etre active
148 // par appel method canBeActivated
149
150 dolibarr_set_const($db, "HOLIDAY_ADDON", $value, 'chaine', 0, '', $conf->entity);
151} elseif ($action == 'set_other') {
152 $freetext = GETPOST('HOLIDAY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
153 $res1 = dolibarr_set_const($db, "HOLIDAY_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
154
155 $draft = GETPOST('HOLIDAY_DRAFT_WATERMARK', 'alpha');
156 $res2 = dolibarr_set_const($db, "HOLIDAY_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
157
158 if (!($res1 > 0) || !($res2 > 0)) {
159 $error++;
160 }
161
162 if (!$error) {
163 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
164 } else {
165 setEventMessages($langs->trans("Error"), null, 'errors');
166 }
167}
168
169
170/*
171 * View
172 */
173
174$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
175
176llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-admin page-holiday');
177
178$form = new Form($db);
179
180$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
181
182print load_fiche_titre($langs->trans("HolidaySetup"), $linkback, 'title_setup');
183
185
186print dol_get_fiche_head($head, 'holiday', $langs->trans("Holidays"), -1, 'holiday');
187
188/*
189 * Holiday Numbering model
190 */
191
192$holiday = new Holiday($db);
193$holiday->initAsSpecimen();
194
195printNumberingModuleList('holiday', 'mod_holiday_', 'HOLIDAY_ADDON', $langs->trans("HolidaysNumberingModules"), $holiday);
196
197print '<br>';
198
199
200/*
201 * Documents models for Holidays
202 */
203
204if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
205 printDocumentModelList($type, 'holiday', 'HOLIDAY_ADDON_PDF', $langs->trans("TemplatePDFHolidays"), array(
206 'Logo' => 'option_logo',
207 'PaymentMode' => 'option_modereg',
208 'PaymentConditions' => 'option_condreg',
209 'MultiLanguage' => 'option_multilang',
210 'WatermarkOnDraftOrders' => 'option_draft_watermark',
211 ));
212 print "<br>";
213}
214
215
216/*
217 * Type of leaves
218 */
219
220print load_fiche_titre($langs->trans("LeaveType"), '', '');
221
222print '<div class="urllink">';
223print img_picto('', 'url', 'class="pictofixedwidth"').' <a href="'.DOL_URL_ROOT.'/admin/dict.php?id=28&search_country_id='.($conf->entity).'">'.$langs->trans("ClickHereToGoToDictionary", $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Dictionary"), $langs->transnoentitiesnoconv("LeaveType")).'</a>';
224print '</div>';
225
226print '<br><br>';
227
228
229/*
230 * Type of leaves
231 */
232
233print load_fiche_titre($langs->trans("DictionaryPublicHolidays"), '', '');
234
235print '<div class="urllink">';
236print img_picto('', 'url', 'class="pictofixedwidth"').' <a href="'.DOL_URL_ROOT.'/admin/dict.php?id=32&search_country_id='.($conf->entity).'">'.$langs->trans("ClickHereToGoToDictionary", $langs->transnoentitiesnoconv("Setup"), $langs->transnoentitiesnoconv("Dictionary"), $langs->transnoentitiesnoconv("DictionaryPublicHolidays")).'</a>';
237print '</div>';
238
239print '<br><br>';
240
241
242/*
243 * Other options
244 */
245
246print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
247print '<input type="hidden" name="token" value="'.newToken().'">';
248print '<input type="hidden" name="action" value="set_other">';
249
250print load_fiche_titre($langs->trans("OtherOptions"), '', '');
251
252print '<div class="div-table-responsive-no-min">';
253print '<table class="noborder centpercent">';
254print '<tr class="liste_titre">';
255print '<td>'.$langs->trans("Parameter").'</td>';
256print '<td align="center" width="60"></td>';
257print "</tr>\n";
258
259// Set working days
260print '<tr class="oddeven">';
261print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Monday"))."</td>";
262print '<td class="center">';
263if ($conf->use_javascript_ajax) {
264 print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY', array(), null, 0);
265} else {
266 if (getDolGlobalString('MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY')) {
267 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
268 } else {
269 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_MONDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
270 }
271}
272print "</td>";
273print "</tr>";
274
275// Set working days
276print '<tr class="oddeven">';
277print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Friday"))."</td>";
278print '<td class="center">';
279if ($conf->use_javascript_ajax) {
280 print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY', array(), null, 0);
281} else {
282 if (getDolGlobalString('MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY')) {
283 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
284 } else {
285 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_FRIDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
286 }
287}
288print "</td>";
289print "</tr>";
290
291// Set working days
292print '<tr class="oddeven">';
293print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Saturday"))."</td>";
294print '<td class="center">';
295if ($conf->use_javascript_ajax) {
296 print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY', array(), null, 0, 0, 0, 2, 0, 1);
297} else {
298 if (getDolGlobalString('MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY')) {
299 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
300 } else {
301 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
302 }
303}
304print "</td>";
305print "</tr>";
306
307// Set working days
308print '<tr class="oddeven">';
309print "<td>".$langs->trans("XIsAUsualNonWorkingDay", $langs->transnoentitiesnoconv("Sunday"))."</td>";
310print '<td class="center">';
311if ($conf->use_javascript_ajax) {
312 print ajax_constantonoff('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY', array(), null, 0, 0, 0, 2, 0, 1);
313} else {
314 if (getDolGlobalString('MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY')) {
315 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
316 } else {
317 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
318 }
319}
320print "</td>";
321print "</tr>";
322
323// Set holiday decrease at the end of month
324print '<tr class="oddeven">';
325print "<td>".$langs->trans("ConsumeHolidaysAtTheEndOfTheMonthTheyAreTakenAt").' <span class="opacitymedium">('.$langs->trans("ConsumeHolidaysAtTheEndOfTheMonthTheyAreTakenAtBis").')</span></td>';
326print '<td class="center">';
327if ($conf->use_javascript_ajax) {
328 print ajax_constantonoff('HOLIDAY_DECREASE_AT_END_OF_MONTH', array(), null, 0, 0, 0, 2, 0, 1);
329} else {
330 if (getDolGlobalString('HOLIDAY_DECREASE_AT_END_OF_MONTH')) {
331 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&HOLIDAY_DECREASE_AT_END_OF_MONTH=1">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
332 } else {
333 print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_other&token='.newToken().'&HOLIDAY_DECREASE_AT_END_OF_MONTH=0">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
334 }
335}
336print "</td>";
337print "</tr>";
338
339if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
340 $substitutionarray = pdf_getSubstitutionArray($langs, array('objectamount'), null, 2);
341 $substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
342 $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
343 foreach ($substitutionarray as $key => $val) {
344 $htmltext .= $key.'<br>';
345 }
346 $htmltext .= '</i>';
347
348 print '<tr class="oddeven"><td colspan="2">';
349 print $form->textwithpicto($langs->trans("FreeLegalTextOnHolidays"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'tooltiphelp');
350 print '<br>';
351 $variablename = 'HOLIDAY_FREE_TEXT';
352 if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
353 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
354 } else {
355 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
356 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
357 print $doleditor->Create();
358 }
359 print '</td></tr>'."\n";
360
361 //Use draft Watermark
362
363 print '<tr class="oddeven"><td>';
364 print $form->textwithpicto($langs->trans("WatermarkOnDraftHolidayCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
365 print '</td><td>';
366 print '<input class="flat minwidth200" type="text" name="HOLIDAY_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('HOLIDAY_DRAFT_WATERMARK')).'">';
367 print '</td></tr>'."\n";
368}
369
370print '</table>';
371print '</div>';
372
373print $form->buttonsSaveCancel("Save", '');
374
375print '</form>';
376
377
378
379print dol_get_fiche_end();
380
381// End of page
382llxFooter();
383$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
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).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
Class of the module paid holiday.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
holiday_admin_prepare_head()
Return array head with list of tabs to view object information.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.