-
Notifications
You must be signed in to change notification settings - Fork 1
/
do_holiday_aed.php
74 lines (70 loc) · 3.24 KB
/
do_holiday_aed.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
<?php /* $Id$ $URL$ */
if (!defined('W2P_BASE_DIR')) {
die('You should not access this file directly.');
}
require_once 'PEAR/Holidays.php';
require_once "holiday_functions.class.php";
$target = w2PgetParam($_POST, 'target', "");
$q = new w2p_Database_Query();
if($target=="calendar") {
$annual = w2PgetParam($_POST, 'holiday_annual', 0);
$description = w2PgetParam($_POST, 'holiday_description', "");
$newholidays = w2PgetParam($_POST, 'newholidays', "");
$newholidays = $newholidays ? explode(",", $newholidays) : array();
$holidays = array();
foreach($newholidays as $newholiday) {
list($id, $date, $name) = explode("-", $newholiday);
if ($id > 0) { // this holidays is blacklisted
$holiday = new CHoliday();
$holiday->loadFull($AppUI, $id);
$holiday->remove($AppUI, new w2p_Utilities_Date($date));
}
else {
$holidays[] = $date; // put the date in whitelist
}
}
$newholidaysranges = HolidayFunctions::makeHolidaysRecords($holidays, 0, HOLIDAY_TYPE_COMPANY_HOLIDAY, $annual, $description);
HolidayFunctions::storeRecords( $newholidaysranges, 0, HOLIDAY_TYPE_COMPANY_HOLIDAY, $annual, $description );
$newworkdays = w2PgetParam($_POST, 'newworkdays', "");
$newworkdays = $newworkdays ? explode(",", $newworkdays) : array();
$workdays = array();
foreach($newworkdays as $newworkday) {
list($id, $date, $name) = explode("-", $newworkday);
if ($id > 0) { // this holidays is in whitelist
$holiday = new CHoliday();
$holiday->loadFull($AppUI, $id);
$holiday->remove($AppUI, new w2p_Utilities_Date($date));
}
else {
$workdays[] = $date; // put the date in blacklist
}
}
$newworkdaysranges = HolidayFunctions::makeHolidaysRecords($workdays, 0, HOLIDAY_TYPE_COMPANY_WORKDAY);
HolidayFunctions::storeRecords( $newworkdaysranges, 0, HOLIDAY_TYPE_COMPANY_WORKDAY );
$AppUI->setMsg( "Public Holidays updated" );
}
if($target=="user") {
$user_id = w2PgetParam($_POST, 'user_id', $AppUI->user_id);
$description = w2PgetParam($_POST, 'holiday_description', "");
$newholidays = w2PgetParam($_POST, 'newholidays', "");
$newholidays = $newholidays ? explode(",", $newholidays) : array();
$holidays = array();
foreach($newholidays as $newholiday) {
list($id, $date, $name) = explode("-", $newholiday);
$holidays[] = $date; // put the date in whitelist
}
$newholidaysranges = HolidayFunctions::makeHolidaysRecords($holidays, $user_id, HOLIDAY_TYPE_USER_HOLIDAY, 0, $description);
HolidayFunctions::storeRecords( $newholidaysranges, $user_id, HOLIDAY_TYPE_USER_HOLIDAY, 0, $description );
$newworkdays = w2PgetParam($_POST, 'newworkdays', "");
$newworkdays = $newworkdays ? explode(",", $newworkdays) : array();
foreach($newworkdays as $newworkday) {
list($id, $date, $name) = explode("-", $newworkday);
if ($id > 0) { // this holidays is in whitelist of the user
$holiday = new CHoliday();
$holiday->loadFull($AppUI, $id);
$holiday->remove($AppUI, new w2p_Utilities_Date($date));
}
}
$AppUI->setMsg( "User Holidays updated" );
}
$AppUI->redirect();