-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathholiday_settings.php
428 lines (410 loc) · 19.7 KB
/
holiday_settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<?php /* $Id$ $URL$ */
require_once 'PEAR/Holidays.php';
require_once $AppUI->getLibraryClass("PEAR/Date");
require_once "holiday_functions.class.php";
$drivers_alloc = Date_Holidays::getInstalledDrivers();
$drivers_available = array(-1 => $AppUI->_("None"));
for($i=0;$drivers_alloc[$i];$i++){
$drivers_available[$i]=$drivers_alloc[$i]['title'];
}
$filters_alloc = Date_Holidays::getInstalledFilters();
$filters_available = array(-1 => $AppUI->_("None"));
for($i=0;$filters_alloc[$i];$i++){
list ($country, $whitelist) = explode("_", $filters_alloc[$i]['title']);
if ($whitelist) {
$filters_available[$i]=$AppUI->_($country). " >> " . $AppUI->_($whitelist);
}
}
// Query database settings
$q = new w2p_Database_Query();
$q->addTable("holiday_settings");
$q->addQuery("holiday_manual, holiday_auto, holiday_driver, holiday_filter");
extract($q->loadHash());
// establish the focus 'date'
$date = w2PgetParam($_GET, 'date', null);
if (!$date) {
$date = new w2p_Utilities_Date();
} else {
$date = new w2p_Utilities_Date($date);
}
$date->setDay(1);
$date->setMonth(1);
$date->setTime(0, 0, 0);
$year = $date->getYear();
$prev_year = $date->format(FMT_TIMESTAMP_DATE);
$prev_year = (int)($prev_year - 10000);
$next_year = $date->format(FMT_TIMESTAMP_DATE);
$next_year = (int)($next_year + 10000);
$start = $date->duplicate();
$end = $date->duplicate();
$end->setMonth(12);
$end->setDay(31);
$end->setTime(23, 59, 59);
$holidays = array();
$holidaysList = HolidayFunctions::getDefaultCalendarHolidaysForDatespan($start, $end);
foreach($holidaysList as $holiday) {
$id = 0;
$type = $holiday['type'];
$description = $holiday['description'] ? $holiday['description'] : "";
$name = $holiday['name'] ? $holiday['name'] : "";
$odate = $holiday['startDate'];
$oend = $holiday['endDate'];
$cdate = clone $odate;
while (!$cdate->after(clone $oend)) {
$holidays[$odate->format(FMT_TIMESTAMP_DATE)] = array($id, $type, $description, $name);
$odate = $odate->getNextDay();
$cdate = clone $odate;
}
}
$holidaysList = HolidayFunctions::getWhitelistForDatespan($start, $end);
foreach($holidaysList as $holiday) {
$id = $holiday['id'];
$type = $holiday['type'];
$description = $holiday['description'] ? $holiday['description'] : "";
$odate = $holiday['startDate'];
$oend = $holiday['endDate'];
$cdate = clone $odate;
while (!$cdate->after(clone $oend)) {
$holidays[$odate->format(FMT_TIMESTAMP_DATE)] = array($id, $type, $description, "");
$odate = $odate->getNextDay();
$cdate = clone $odate;
}
}
$holidaysList = HolidayFunctions::getBlacklistForDatespan($start, $end);
foreach($holidaysList as $holiday) {
$id = $holiday['id'];
$type = $holiday['type'];
$description = $holiday['description'] ? $holiday['description'] : "";
$odate = $holiday['startDate'];
$oend = $holiday['endDate'];
$cdate = clone $odate;
while (!$cdate->after(clone $oend)) {
$holidays[$odate->format(FMT_TIMESTAMP_DATE)] = array($id, $type, $description, "");
$odate = $odate->getNextDay();
$cdate = clone $odate;
}
}
$cal_working_days = explode(",",w2PgetConfig("cal_working_days"));
setlocale(LC_ALL, 'C');
$wk = Date_Calc::getCalendarWeek(null, null, null, '%w%A', 0);
?>
<style type="text/css">
@import "modules/holiday/style/common.css";
@import "modules/holiday/style/<?php echo $AppUI->getPref('UISTYLE'); ?>/styles.css";
</style>
<script type="text/javascript">
var workdays = [];
var holidays = [];
function addToWorkdays(date) {
for (i in workdays) {
if (workdays[i] == date) {
return false;
}
}
workdays.push(date);
return true;
}
function removeFromWorkdays(date) {
for (i in workdays) {
if (workdays[i] == date) {
workdays.splice(i, 1);
return true;
}
}
return false;
}
function addToHolidays(date) {
for (i in holidays) {
if (holidays[i] == date) {
return false;
}
}
holidays.push(date);
return true;
}
function removeFromHolidays(date) {
for (i in holidays) {
if (holidays[i] == date) {
holidays.splice(i, 1);
return true;
}
}
return false;
}
function getPublicHolidaysOptions(form) {
var nCompanyWorkday = 0;
var nCalendarWorkday = 0;
var ok = true;
$("li.ui-selected").each(function() {
if ($(this).hasClass("ui-company-workday")) {
nCompanyWorkday++;
}
else if ($(this).hasClass("ui-calendar-workday")) {
nCalendarWorkday++;
}
else {
ok = false;
}
});
if (!ok) {
alert("<?php echo $AppUI->_('Some of these days are already public holidays. Ctrl-click to unselect them and try again !', UI_OUTPUT_JS); ?>");
}
else if (nCompanyWorkday == 0 && nCalendarWorkday == 0) {
alert("<?php echo $AppUI->_('Please, select a day !', UI_OUTPUT_JS); ?>");
}
else if (nCalendarWorkday == 0) {
submitPublicHolidays(form);
}
else {
$('#holiday-choices-help').hide();
$('#holiday-choices-buttons').hide();
$('#holiday-choices-options').show();
}
}
function cancelPublicHolidays() {
$('#holiday-choices-help').show();
$('#holiday-choices-buttons').show();
$('#holiday-choices-options').hide();
}
function submitPublicHolidays(form) {
$("li.ui-selected").each(function() {
var date = $(this).attr('id');
$(this).removeClass("ui-selected");
if ($(this).hasClass("ui-calendar-workday")) {
if (!removeFromWorkdays(date)) addToHolidays(date);
$(this).removeClass("ui-calendar-workday").addClass("ui-calendar-holiday");
}
else if ($(this).hasClass("ui-company-workday")) {
if (!removeFromWorkdays(date)) addToHolidays(date);
$(this).removeClass("ui-company-workday").addClass("ui-company-holiday");
}
});
$('input:hidden[name=newholidays]').val(holidays.join(","));
$('input:hidden[name=newworkdays]').val(workdays.join(","));
$('#loadingMessage').show();
form.submit();
}
function getWorkingDaysOptions(form) {
var nCompanyHoliday = 0;
var nCalendarHoliday = 0;
var ok = true;
$("li.ui-selected").each(function() {
if ($(this).hasClass("ui-company-holiday")) {
nCompanyHoliday++;
}
else if ($(this).hasClass("ui-calendar-holiday")) {
nCalendarHoliday++;
}
else {
ok = false;
}
});
if (!ok) {
alert("<?php echo $AppUI->_('Some of these days are already working days. Ctrl-click to unselect them and try again !', UI_OUTPUT_JS); ?>");
}
else if (nCompanyHoliday == 0 && nCalendarHoliday == 0) {
alert("<?php echo $AppUI->_('Please, select a day !', UI_OUTPUT_JS); ?>");
}
else {
submitWorkingDays(form);
}
}
function submitWorkingDays(form) {
$("li.ui-selected").each(function() {
var date = $(this).attr('id');
$(this).removeClass("ui-selected");
if ($(this).hasClass("ui-calendar-holiday")) {
if (!removeFromHolidays(date)) addToWorkdays(date);
$(this).removeClass("ui-calendar-holiday").addClass("ui-calendar-workday");
}
else if ($(this).hasClass("ui-company-holiday")) {
if (!removeFromHolidays(date)) addToWorkdays(date);
$(this).removeClass("ui-company-holiday").addClass("ui-company-workday");
}
});
$('input:hidden[name=newholidays]').val(holidays.join(","));
$('input:hidden[name=newworkdays]').val(workdays.join(","));
$('#loadingMessage').show();
form.submit();
}
function submitOptions(form) {
var workingdays = [];
$("input:checked[name=cal_working_day]").each(function() {
workingdays.push($(this).val());
});
$('input:hidden[name=cal_working_days]').val(workingdays.join(","));
$('#loadingMessage').show();
form.submit();
}
$.getScript ("modules/holiday/lib/ui-selectable/jquery.ui.core.js", function () {
$.getScript ("modules/holiday/lib/ui-selectable/jquery.ui.widget.js", function () {
$.getScript ("modules/holiday/lib/ui-selectable/jquery.ui.mouse.js", function () {
$.getScript ("modules/holiday/lib/ui-selectable/jquery-ui-1.8.7.custom.js", function () {
$.getScript ("modules/holiday/lib/ui-selectable/jquery.ui.selectable.js", function () {
$(document).ready(function() {
$( "ol.selectable" ).selectable( { filter: '.ui-selectable' });
});
});
});
});
});
});
</script>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<td>
<form id="editholidaysettings" name="editholidaysettings" method="post" accept-charset="utf-8">
<input type="hidden" name="dosql" value="do_holiday_settings_aed" />
<input type="hidden" name="cal_working_days" value="" />
<div id="holiday-options">
<fieldset>
<legend><?php echo $AppUI->_('Calendar Options'); ?></legend>
<div class="settings">
<ul>
<li><?php echo $AppUI->_( 'Standard calendar' )."  ".arraySelect( $drivers_available,"holiday_driver",null,$holiday_driver); ?></li>
<li><?php echo $AppUI->_( 'Standard calendar filter' )."  ".arraySelect( $filters_available,"holiday_filter",null,$holiday_filter); ?></li>
<li><?php echo $AppUI->_( 'Enable standard calendar' );?><input type="checkbox" value="1" name="holiday_auto"<?php echo $holiday_auto ? 'checked="checked"' : ""; ?> /></li>
<li><?php echo $AppUI->_( 'Enable manual working days and public holidays' );?><input type="checkbox" value="1" name="holiday_manual"<?php echo $holiday_manual ? 'checked="checked"' : ""; ?> /></li>
</ul>
</div><br />
<div class="settings">
<ul>
<li><?php echo $AppUI->_( 'cal_working_days_title' ); ?> : </li>
<?php foreach ($wk as $day) {
$dow = substr($day, 0, 1);
$checked = in_array($dow, $cal_working_days) ? ' checked="checked"' : '';
?>
<li><input type="checkbox" name="cal_working_day" value="<?php echo $dow; ?>"<?php echo $checked; ?>><?php echo $AppUI->_(substr($day, 1));?></input></li>
<?php } ?>
<li><?php echo $AppUI->_('Working times');?> : <input type="text" class="cal_day" name="cal_day_start" size="5" value="<?php echo w2PgetConfig("cal_day_start"); ?>" /></li>
<li><?php echo $AppUI->_('to');?> <input type="text" class="cal_day" name="cal_day_end" size="5" value="<?php echo w2PgetConfig("cal_day_end"); ?>" /></li>
<li><input class="button" type="button" name="btnFuseAction" value="<?php echo $AppUI->_('save'); ?>" onClick="submitOptions(this.form);" /></li>
</ul>
</div>
</fieldset>
</div>
</form>
<form id="editholiday" name="editholiday" method="post" accept-charset="utf-8">
<input type="hidden" name="dosql" value="do_holiday_aed" />
<input type="hidden" name="target" value="calendar">
<input type="hidden" name="newholidays" value=""/>
<input type="hidden" name="newworkdays" value=""/>
<div>
<div id="holiday-calendar">
<table width="100%" cellspacing="0" cellpadding="4">
<tr>
<td colspan="20" valign="top">
<table border="0" cellspacing="1" cellpadding="2" width="100%" class="motitle">
<tr>
<td>
<a href="<?php echo '?m=holiday&date=' . $prev_year; ?>"><img src="<?php echo w2PfindImage('prev.gif'); ?>" width="16" height="16" alt="pre" title="pre" border="0"></a>
</td>
<th width="100%" align="center">
<?php echo $year; ?>
</th>
<td>
<a href="<?php echo '?m=holiday&date=' . $next_year; ?>"><img src="<?php echo w2PfindImage('next.gif'); ?>" width="16" height="16" alt="next" title="next" border="0"></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php $wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY); for ($m = 1; $m <= 12; $m++) {
$monthname = Date_Calc::getMonthFullname($m);
$cal = Date_Calc::getCalendarMonth($m, $year, '%Y%m%d%w', LOCALE_FIRST_DAY); //TODO : too long ?>
<div class="holiday-calendar-month">
<span class="holiday-calendar-monthname"><?php echo $AppUI->_($monthname, UI_CASE_UPPERFIRST).' '; ?></span>
<ol class="selectable">
<?php
foreach ($wk as $day) { ?>
<li class="ui-dayname"><?php $d = $AppUI->_($day); echo strtoupper($d{0}); ?></li>
<?php }
$n = 0;
foreach ($cal as $week) {
foreach ($week as $day) {
$month = intval(substr($day, 4, 2));
$d = intval(substr($day, 6, 2));
$dow = intval(substr($day, 8, 1));
$day = substr($day, 0, 8);
if ($m == $month) {
if (isset($holidays[$day])) {
$id = $holidays[$day][0];
$type = $holidays[$day][1];
$description = $holidays[$day][2];
$name = $holidays[$day][3];
switch ($type) {
case HOLIDAY_TYPE_COMPANY_WORKDAY : ?>
<li id="<?php echo $id.'-'.$day.'-'.$name; ?>" class="ui-company-workday ui-selectable" title="<?php echo $description; ?>"><?php echo $d; ?></li>
<?php break;
case HOLIDAY_TYPE_COMPANY_HOLIDAY : ?>
<li id="<?php echo $id.'-'.$day.'-'.$name; ?>" class="ui-company-holiday ui-selectable" title="<?php echo $description; ?>"><?php echo $d; ?></li>
<?php break;
case HOLIDAY_TYPE_CALENDAR_HOLIDAY : ?>
<li id="<?php echo $id.'-'.$day.'-'.$name; ?>" class="ui-calendar-holiday ui-selectable" title="<?php echo $description; ?>"><?php echo $d; ?></li>
<?php break;
} } elseif (in_array($dow, $cal_working_days)) { ?>
<li id="<?php echo '0-'.$day.'-'; ?>" class="ui-calendar-workday ui-selectable"><?php echo $d; ?></li>
<?php } else { ?>
<li id="<?php echo '0-'.$day.'-'; ?>" class="ui-weekend ui-unselectable"><?php echo $d; ?></li>
<?php } } else { ?>
<li class="ui-unselectable"></li>
<?php }
$n++;
}
}
while ($n < 42) { ?>
<li class="ui-unselectable"></li>
<?php $n++; }
?>
</ol>
</div>
<?php
}
?>
</div>
<div id="holiday-choices">
<fieldset>
<legend><?php echo $AppUI->_( 'Adding pubic holidays/working days' ); ?></legend>
<div id="holiday-choices-help">
<?php echo $AppUI->_('Days selection help'); ?>
<br /><br />
</div>
<div id="holiday-choices-options" style="display: none;">
<?php echo $AppUI->_('Enter a description for these new holidays'); ?>
<input type="text" name="holiday_description" /><br />
<?php echo $AppUI->_( 'For all years' );?><input type="checkbox" value="1" name="holiday_annual" checked="checked" /><br />
<?php echo $AppUI->_('then click'); ?>
<input class="button" type="button" name="addNewHolidays" onclick="submitPublicHolidays(this.form);" value="<?php echo $AppUI->_( 'Ok' ); ?>" />
<?php echo $AppUI->_('or'); ?>
<input class="button" type="button" name="addNewHolidays" onclick="cancelPublicHolidays();" value="<?php echo $AppUI->_( 'Cancel' ); ?>" />
</div>
<div id="holiday-choices-buttons">
<input class="button" type="button" name="addNewHolidays" onclick="getPublicHolidaysOptions(this.form);" value="<?php echo $AppUI->_( 'Add to public holidays' ); ?>" /><br />
<input class="button" type="button" name="addNewWorkdays" onclick="getWorkingDaysOptions(this.form);" value="<?php echo $AppUI->_( 'Add to working days' ); ?>" /><br />
</div>
</fieldset>
</div>
<div id="holiday-key">
<fieldset>
<legend><?php echo $AppUI->_( 'Key' ); ?></legend>
<div class="selectable">
<?php echo $AppUI->_('Calendar Workday'); ?>
<span class="ui-calendar-workday"> </span>
<?php echo $AppUI->_('Company Workday'); ?>
<span class="ui-company-workday"> </span>
<?php echo $AppUI->_('Calendar holiday'); ?>
<span class="ui-calendar-holiday"> </span>
<?php echo $AppUI->_('Company holiday'); ?>
<span class="ui-company-holiday"> </span>
<?php echo $AppUI->_('Selected days'); ?>
<span class="ui-selected"> </span>
</div>
</fieldset>
</div>
</div>
</form>
</td>
</tr>
</table>
<?php setlocale(LC_ALL, $AppUI->user_lang); ?>