1
|
|
|
<?php |
2
|
|
|
/************************************************************************ |
3
|
|
|
* OVIDENTIA http://www.ovidentia.org * |
4
|
|
|
************************************************************************ |
5
|
|
|
* Copyright (c) 2003 by CANTICO ( http://www.cantico.fr ) * |
6
|
|
|
* * |
7
|
|
|
* This file is part of Ovidentia. * |
8
|
|
|
* * |
9
|
|
|
* Ovidentia is free software; you can redistribute it and/or modify * |
10
|
|
|
* it under the terms of the GNU General Public License as published by * |
11
|
|
|
* the Free Software Foundation; either version 2, or (at your option) * |
12
|
|
|
* any later version. * |
13
|
|
|
* * |
14
|
|
|
* This program is distributed in the hope that it will be useful, but * |
15
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
17
|
|
|
* See the GNU General Public License for more details. * |
18
|
|
|
* * |
19
|
|
|
* You should have received a copy of the GNU General Public License * |
20
|
|
|
* along with this program; if not, write to the Free Software * |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,* |
22
|
|
|
* USA. * |
23
|
|
|
************************************************************************/ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class absences_PeriodFrame |
27
|
|
|
{ |
28
|
|
|
public $isfixed = false; |
29
|
|
|
|
30
|
|
|
public $altbg = true; |
31
|
|
|
|
32
|
|
|
public $datebegin; |
33
|
|
|
public $datebegintxt; |
34
|
|
|
|
35
|
|
|
public $dateend; |
36
|
|
|
public $dateendtxt; |
37
|
|
|
|
38
|
|
|
public $vactype; |
39
|
|
|
public $addvac; |
40
|
|
|
public $save_previsional; |
41
|
|
|
public $remark; |
42
|
|
|
public $nbdaystxt; |
43
|
|
|
public $invaliddate; |
44
|
|
|
public $invaliddate2; |
45
|
|
|
public $invalidentry; |
46
|
|
|
public $invalidentry1; |
47
|
|
|
public $invalidentry3; |
48
|
|
|
public $totaltxt; |
49
|
|
|
public $balancetxt; |
50
|
|
|
public $calendar; |
51
|
|
|
public $t_total; |
52
|
|
|
public $t_available; |
53
|
|
|
public $t_waiting; |
54
|
|
|
public $t_period_nbdays; |
55
|
|
|
public $t_view_rights; |
56
|
|
|
public $t_recurring; |
57
|
|
|
|
58
|
|
|
public $totalval; |
59
|
|
|
public $maxallowed; |
60
|
|
|
public $id; |
61
|
|
|
public $id_user; |
62
|
|
|
public $ide; |
63
|
|
|
|
64
|
|
|
public $year; |
65
|
|
|
public $month; |
66
|
|
|
public $rfrom; |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function __construct($id_user, $id) |
71
|
|
|
{ |
72
|
|
|
require_once dirname(__FILE__).'/entry.class.php'; |
73
|
|
|
global $babBody, $babDB; |
74
|
|
|
$this->datebegin = $GLOBALS['babUrlScript']."?tg=month&callback=dateBegin&ymin=0&ymax=2"; |
75
|
|
|
$this->datebegintxt = absences_translate("Begin date"); |
76
|
|
|
$this->dateend = $GLOBALS['babUrlScript']."?tg=month&callback=dateEnd&ymin=0&ymax=2"; |
77
|
|
|
$this->dateendtxt = absences_translate("End date"); |
78
|
|
|
$this->vactype = absences_translate("Vacation type"); |
79
|
|
View Code Duplication |
if ($id) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$this->addvac = absences_translate("Edit vacation request"); |
82
|
|
|
$this->save_previsional = absences_translate("Save previsional request"); |
83
|
|
|
} else { |
84
|
|
|
$this->addvac = absences_translate("Request vacation"); |
85
|
|
|
$this->save_previsional = absences_translate("Create previsional request"); |
86
|
|
|
} |
87
|
|
|
$this->remark = absences_translate("Remarks"); |
88
|
|
|
$this->nbdaystxt = absences_translate("Quantity"); |
89
|
|
|
$this->invaliddate = absences_translate("ERROR: End date must be older"); |
90
|
|
|
$this->invaliddate = str_replace("'", "\'", $this->invaliddate); |
91
|
|
|
$this->invaliddate = str_replace('"', "'+String.fromCharCode(34)+'",$this->invaliddate); |
92
|
|
|
$this->invaliddate2 = absences_translate("Total days does'nt fit between dates"); |
93
|
|
|
$this->invaliddate2 = str_replace("'", "\'", $this->invaliddate2); |
94
|
|
|
$this->invaliddate2 = str_replace('"', "'+String.fromCharCode(34)+'",$this->invaliddate2); |
95
|
|
|
$this->invalidentry = absences_translate("Invalid entry! Only numbers are accepted or . !"); |
96
|
|
|
$this->invalidentry = str_replace("'", "\'", $this->invalidentry); |
97
|
|
|
$this->invalidentry = str_replace('"', "'+String.fromCharCode(34)+'",$this->invalidentry); |
98
|
|
|
$this->invalidentry1 = absences_translate("Invalid entry"); |
99
|
|
|
$this->invalidentry3 = absences_translate("The number of days exceed the total allowed"); |
100
|
|
|
$this->totaltxt = absences_translate("Total"); |
101
|
|
|
$this->balancetxt = absences_translate("Balance"); |
102
|
|
|
$this->calendar = absences_translate("Planning"); |
103
|
|
|
$this->t_total = absences_translate("Total"); |
104
|
|
|
$this->t_available = absences_translate("Available"); |
105
|
|
|
$this->t_waiting = absences_translate("Waiting"); |
106
|
|
|
$this->t_period_nbdays = absences_translate("Period days"); |
107
|
|
|
$this->t_view_rights = absences_translate("View rights details"); |
108
|
|
|
$this->t_recurring = absences_translate("Do a recuring request"); |
109
|
|
|
$this->t_previsional = absences_translate("Previsional"); |
|
|
|
|
110
|
|
|
$this->t_previsional_available = absences_translate("Prev. bal."); |
|
|
|
|
111
|
|
|
|
112
|
|
|
$this->totalval = 0; |
113
|
|
|
$this->maxallowed = 0; |
114
|
|
|
$this->id = $id; |
115
|
|
|
$this->id_user = $id_user; |
116
|
|
|
$this->ide = bab_rp('ide'); |
117
|
|
|
|
118
|
|
|
$this->year = isset($_REQUEST['year']) ? $_REQUEST['year'] : date('Y'); |
119
|
|
|
$this->month = isset($_REQUEST['month']) ? $_REQUEST['month'] : date('n'); |
120
|
|
|
$this->rfrom = isset($_REQUEST['rfrom']) ? $_REQUEST['rfrom'] : 0; |
121
|
|
|
|
122
|
|
|
if (!empty($this->id) && !isset($_POST['daybegin'])) |
123
|
|
|
{ |
124
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/dateTime.php"; |
125
|
|
|
|
126
|
|
|
$entry = absences_Entry::getById($this->id); |
127
|
|
|
$arr = $entry->getRow(); |
128
|
|
|
|
129
|
|
|
$date_begin = BAB_DateTime::fromIsoDateTime($arr['date_begin']); |
130
|
|
|
$date_end = BAB_DateTime::fromIsoDateTime($arr['date_end']); |
131
|
|
|
|
132
|
|
|
$this->yearbegin = $date_begin->getYear(); |
|
|
|
|
133
|
|
|
$this->monthbegin = $date_begin->getMonth(); |
|
|
|
|
134
|
|
|
$this->daybegin = $date_begin->getDayOfMonth(); |
|
|
|
|
135
|
|
|
|
136
|
|
|
$this->yearend = $date_end->getYear(); |
|
|
|
|
137
|
|
|
$this->monthend = $date_end->getMonth(); |
|
|
|
|
138
|
|
|
$this->dayend = $date_end->getDayOfMonth(); |
|
|
|
|
139
|
|
|
|
140
|
|
|
$this->hourbegin = date('H:i:s', $date_begin->getTimeStamp()); |
|
|
|
|
141
|
|
|
$this->halfdaybegin = 'am' === date('a', $date_begin->getTimeStamp()) ? 0 : 1; |
|
|
|
|
142
|
|
|
$this->hourend = date('H:i:s', $date_end->getTimeStamp()); |
|
|
|
|
143
|
|
|
$this->halfdayend = 'am' === date('a', $date_end->getTimeStamp()) ? 0 : 1; |
|
|
|
|
144
|
|
|
} |
145
|
|
|
elseif (isset($_POST['daybegin'])) |
146
|
|
|
{ |
147
|
|
|
$this->daybegin = $_POST['daybegin']; |
148
|
|
|
$this->dayend = $_POST['dayend']; |
149
|
|
|
$this->monthbegin = $_POST['monthbegin']; |
150
|
|
|
$this->monthend = $_POST['monthend']; |
151
|
|
|
$this->yearbegin = $this->year + $_POST['yearbegin'] - 1; |
152
|
|
|
$this->yearend = $this->year + $_POST['yearend'] - 1; |
153
|
|
|
$this->halfdaybegin = 0; |
|
|
|
|
154
|
|
|
$this->halfdayend = 1; |
|
|
|
|
155
|
|
|
$this->hourbegin = $_POST['hourbegin']; |
156
|
|
|
$this->hourend = $_POST['hourend']; |
157
|
|
|
} |
158
|
|
|
else |
159
|
|
|
{ |
160
|
|
|
$this->daybegin = date("j"); |
161
|
|
|
$this->dayend = date("j"); |
162
|
|
|
$this->monthbegin = date("n"); |
163
|
|
|
$this->monthend = date("n"); |
164
|
|
|
$this->yearbegin = $this->year; |
165
|
|
|
$this->yearend = $this->year; |
166
|
|
|
$this->halfdaybegin = 0; |
|
|
|
|
167
|
|
|
$this->halfdayend = 1; |
|
|
|
|
168
|
|
|
$this->hourbegin = '00:00:00'; |
169
|
|
|
$this->hourend = '23:59:59'; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$this->halfdaysel = $this->halfdaybegin; |
|
|
|
|
173
|
|
|
|
174
|
|
|
$this->calurl = absences_addon()->getUrl()."planning&idx=cal&idu=".$id_user; |
|
|
|
|
175
|
|
|
|
176
|
|
|
$this->rights = absences_getRightsByGroupOnPeriod($id_user, $this->rfrom); |
|
|
|
|
177
|
|
|
$this->total_available = array('D' => 0, 'H' => 0); |
|
|
|
|
178
|
|
|
$this->total_waiting = array('D' => 0, 'H' => 0); |
|
|
|
|
179
|
|
|
$this->total_previsional = array('D' => 0, 'H' => 0); |
|
|
|
|
180
|
|
|
$this->total_prevavail = array('D' => 0, 'H' => 0); |
|
|
|
|
181
|
|
|
|
182
|
|
|
$this->dayType = array( |
|
|
|
|
183
|
|
|
absences_translate("Morning"), |
184
|
|
|
absences_translate("Afternoon") |
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
$this->hours = absences_hoursList($GLOBALS['BAB_SESS_USERID']); |
|
|
|
|
188
|
|
|
|
189
|
|
|
|
190
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/workinghoursincl.php'; |
191
|
|
|
$jSON = array(); |
192
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 0), $jSON); |
193
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 1), $jSON); |
194
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 2), $jSON); |
195
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 3), $jSON); |
196
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 4), $jSON); |
197
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 5), $jSON); |
198
|
|
|
$this->addWorkingPeriod(bab_getWHours($GLOBALS['BAB_SESS_USERID'], 6), $jSON); |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
$this->json_working_hours = '['.implode(',', $jSON).']'; |
|
|
|
|
202
|
|
|
|
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* reduce working periods for planning |
207
|
|
|
*/ |
208
|
|
|
private function addWorkingPeriod($whours, &$jSON) |
209
|
|
|
{ |
210
|
|
|
if (empty($whours)) |
211
|
|
|
{ |
212
|
|
|
return; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
foreach($whours as $k => $period) |
216
|
|
|
{ |
217
|
|
|
if ($period['startHour'] < '11:59:59' && $period['endHour'] > '12:00:00') |
218
|
|
|
{ |
219
|
|
|
$whours[$k]['endHour'] = '11:59:59'; |
220
|
|
|
$whours[] = array( |
221
|
|
|
'startHour' => '12:00:00', |
222
|
|
|
'endHour' => $period['endHour'], |
223
|
|
|
'weekDay' => $period['weekDay'] |
224
|
|
|
); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
foreach($whours as $period) |
230
|
|
|
{ |
231
|
|
|
$jSON[] = '{ |
232
|
|
|
weekDay:'.$period['weekDay'].', |
233
|
|
|
startHour:\''.$period['startHour'].'\', |
234
|
|
|
endHour:\''.$period['endHour'].'\' |
235
|
|
|
}'; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
|
241
|
|
|
function getnextday() |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
static $i = 1; |
244
|
|
|
|
245
|
|
|
if( $i <= date("t")) |
246
|
|
|
{ |
247
|
|
|
$this->dayid = $i; |
|
|
|
|
248
|
|
|
$i++; |
249
|
|
|
return true; |
250
|
|
|
} |
251
|
|
|
else |
252
|
|
|
{ |
253
|
|
|
$i = 1; |
254
|
|
|
return false; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
function getnextmonth() |
|
|
|
|
260
|
|
|
{ |
261
|
|
|
static $i = 1; |
262
|
|
|
|
263
|
|
|
if( $i < 13) |
264
|
|
|
{ |
265
|
|
|
$this->monthid = $i; |
|
|
|
|
266
|
|
|
$this->monthname = bab_DateStrings::getMonth($i); |
|
|
|
|
267
|
|
|
$i++; |
268
|
|
|
return true; |
269
|
|
|
} |
270
|
|
|
else |
271
|
|
|
{ |
272
|
|
|
$i = 1; |
273
|
|
|
return false; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
} |
277
|
|
|
function getnextyear() |
|
|
|
|
278
|
|
|
{ |
279
|
|
|
static $i = 0; |
280
|
|
|
if( $i < 3) |
281
|
|
|
{ |
282
|
|
|
$this->yearid = $i+1; |
|
|
|
|
283
|
|
|
$this->yearidval = $this->year + $i; |
|
|
|
|
284
|
|
|
$i++; |
285
|
|
|
return true; |
286
|
|
|
} |
287
|
|
|
else |
288
|
|
|
{ |
289
|
|
|
$i = 0; |
290
|
|
|
return false; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
} |
294
|
|
|
function getnexthour() |
|
|
|
|
295
|
|
|
{ |
296
|
|
|
if (list($key, $value) = each($this->hours)) |
297
|
|
|
{ |
298
|
|
|
$this->value = bab_toHtml($key); |
|
|
|
|
299
|
|
|
$this->option = bab_toHtml($value); |
|
|
|
|
300
|
|
|
return true; |
301
|
|
|
} |
302
|
|
|
reset($this->hours); |
303
|
|
|
return false; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
function getnextright() |
|
|
|
|
307
|
|
|
{ |
308
|
|
|
if ($this->right = & current($this->rights)) |
|
|
|
|
309
|
|
|
{ |
310
|
|
|
next($this->rights); |
|
|
|
|
311
|
|
|
$this->altbg = !$this->altbg; |
312
|
|
|
$this->right['quantity_available'] = $this->right['quantity_available'] - $this->right['waiting']; |
|
|
|
|
313
|
|
|
$this->right['previsional_available'] = $this->right['quantity_available'] - $this->right['previsional']; |
314
|
|
|
|
315
|
|
|
$this->total_available[$this->right['quantity_unit']] += $this->right['quantity_available']; |
316
|
|
|
$this->total_waiting[$this->right['quantity_unit']] += $this->right['waiting']; |
317
|
|
|
$this->total_previsional[$this->right['quantity_unit']] += $this->right['previsional']; |
318
|
|
|
$this->total_prevavail[$this->right['quantity_unit']] += $this->right['previsional_available']; |
319
|
|
|
|
320
|
|
|
$this->right['quantity_available'] = bab_toHtml(absences_quantity($this->right['quantity_available'], $this->right['quantity_unit'])); |
321
|
|
|
$this->right['previsional_available'] = bab_toHtml(absences_quantity($this->right['previsional_available'], $this->right['quantity_unit'])); |
322
|
|
|
$this->right['waiting'] = bab_toHtml(absences_quantity($this->right['waiting'], $this->right['quantity_unit'])); |
323
|
|
|
$this->right['previsional'] = bab_toHtml(absences_quantity($this->right['previsional'], $this->right['quantity_unit'])); |
324
|
|
|
|
325
|
|
|
if (isset($this->right['type'])) |
326
|
|
|
{ |
327
|
|
|
$this->color = bab_toHtml($this->right['type']->color); |
|
|
|
|
328
|
|
|
$this->type = bab_toHtml($this->right['type']->name); |
|
|
|
|
329
|
|
|
} else { |
330
|
|
|
$this->color = null; |
331
|
|
|
$this->type = null; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
return true; |
335
|
|
|
} |
336
|
|
|
else |
337
|
|
|
return false; |
338
|
|
|
|
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
private function getDisplay($arr) |
342
|
|
|
{ |
343
|
|
|
$list = array(); |
344
|
|
|
foreach($arr as $quantity_unit => $quantity) { |
345
|
|
|
if ($quantity) { |
346
|
|
|
$list[] = absences_quantity($quantity, $quantity_unit); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
return implode(', ', $list); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
public function gettotal() |
354
|
|
|
{ |
355
|
|
|
static $call = null; |
356
|
|
|
|
357
|
|
|
if (isset($call)) { |
358
|
|
|
return false; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
$call = true; |
362
|
|
|
|
363
|
|
|
$this->total_available = bab_toHtml($this->getDisplay($this->total_available)); |
364
|
|
|
$this->total_waiting = bab_toHtml($this->getDisplay($this->total_waiting)); |
365
|
|
|
$this->total_previsional = bab_toHtml($this->getDisplay($this->total_previsional)); |
366
|
|
|
$this->total_prevavail = bab_toHtml($this->getDisplay($this->total_prevavail)); |
367
|
|
|
|
368
|
|
|
return true; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.