-
Notifications
You must be signed in to change notification settings - Fork 4
/
edit_holidays.php
116 lines (104 loc) · 5.31 KB
/
edit_holidays.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
<?php
// edit_holidays.php - Reset holiday entitlements
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
$permission = 22; // Administrate
require ('core.php');
require (APPLICATION_LIBPATH.'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH.'auth.inc.php');
$title = $strEditHolidayEntitlement;
switch ($_REQUEST['action'])
{
case 'save':
$max_carryover = cleanvar($_REQUEST['max_carryover']);
$archivedate = strtotime($_REQUEST['archivedate']);
if ($archivedate < 1000) $archivedate = $now;
$default_entitlement = cleanvar($_REQUEST['default_entitlement']);
$sql = "SELECT * FROM `{$dbUsers}` WHERE status >= 1";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
while ($users = mysql_fetch_object($result))
{
$fieldname="user{$users->id}";
if ($_REQUEST[$fieldname] == 'yes')
{
$orig_entitlement = user_holiday_entitlement($users->id);
$used_holidays = user_count_holidays($users->id, 1, $archivedate);
$remaining_holidays = $orig_entitlement - $used_holidays;
if ($remaining_holidays < $max_carryover) $carryover = $remaining_holidays;
else $carryover = $max_carryover;
$new_entitlement = $default_entitlement + $carryover;
// Archive previous holiday
$hsql = "UPDATE `{$dbHolidays}` SET approved = approved+10 ";
$hsql .= "WHERE approved < 10 AND userid={$users->id} ";
$hsql .= "AND date < FROM_UNIXTIME($archivedate)";
mysql_query($hsql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
// Update Holiday Entitlement
$usql = "UPDATE `{$dbUsers}` SET holiday_entitlement = ";
$usql .= "$new_entitlement WHERE id={$users->id} LIMIT 1";
mysql_query($usql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
}
}
header("Location: edit_holidays.php");
exit;
break;
case 'form':
default:
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo "<h2>{$title}</h2>";
$sql = "SELECT * FROM `{$dbUsers}` WHERE status >= 1 ORDER BY realname ASC";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
echo "<form name='editholidays' action='{$_SERVER['PHP_SELF']}?action=save' method='post'>";
echo "<p>{$strResetHolidayEntitlementCarryOverNDaysOfUnusedHoliday}</p>";
echo "<div align='center'><label>{$strDefaultNewEntitlement}: ";
echo "<input type='text' name='default_entitlement' value='{$CONFIG['default_entitlement']}' size='4' /></label>, ";
echo sprintf($strMaxCarryOverXDays, "<input type='text' name='max_carryover' value='5' size='4' />");
$str = "<input type='text' id='archivedate' name='archivedate' size='10' value='".date('Y-m-d')."' />";
echo "<br />".sprintf($strArchiveDaysBookedPriorToX, $str)."\n ";
echo date_picker('editholidays.archivedate');
echo "</div>";
echo "<table align='center'>";
echo "<tr><th></th>";
echo colheader('realname', $strName, FALSE);
echo colheader('entitlement', $strEntitlement, FALSE);
echo colheader('holidaysused', $strUsed, FALSE);
echo colheader('holidaysremaining', sprintf($strRemaining, ''), FALSE);
//echo colheader('resetdate', "Reset Date", FALSE); // FIXME i18n
//echo colheader('newentitlement', $strNewEntitlement, FALSE);
echo "</tr>";
while ($users = mysql_fetch_object($result))
{
// define class for table row shading
if ($shade == 'shade1') $shade = "shade2";
else $shade = "shade1";
echo "<tr class='$shade'>";
echo "<td><input type='checkbox' name='user{$users->id}' value='yes' /></td>";
echo "<td><a href='holidays.php?user={$users->id}'>{$users->realname}</a> ({$users->username})</td>";
$entitlement = $users->holiday_entitlement;
$used_holidays = user_count_holidays($users->id, HOL_HOLIDAY, $users->holiday_resetdate);
$remaining_holidays = $entitlement - $used_holidays;
echo "<td style='text-align: right;'>{$entitlement}</td>";
echo "<td style='text-align: right;'>{$used_holidays}</td>";
echo "<td style='text-align: right;'>{$remaining_holidays}</td>";
//echo "<td style='text-align: right;'>{$users->holiday_resetdate}</td>";
//echo "<td style='text-align: right;'><input type='text' size='4' maxlength='5' value='{$newentitlement}' /></td>";
echo "</tr>";
}
echo "</table>";
echo "<p>";
echo "<input type='hidden' name='action' value='save' />";
echo "<input type='submit' name='submit' value='{$strSave}' /></p>";
echo "</form>";
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
break;
}
?>