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
|
|
|
require_once dirname(__FILE__).'/vacincl.php'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get period index from database |
34
|
|
|
* |
35
|
|
|
* @param int $id_user |
36
|
|
|
* @param int $month |
37
|
|
|
* @param int $year |
38
|
|
|
* @param string $dateb ISO date |
39
|
|
|
* @param string $datee ISO date |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
function absences_getPeriodIndex($id_user, $month, $year, $dateb, $datee) |
44
|
|
|
{ |
45
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/settings.class.php'; |
46
|
|
|
global $babDB; |
47
|
|
|
|
48
|
|
|
$req = " |
49
|
|
|
SELECT |
50
|
|
|
c.id_user, |
51
|
|
|
c.cal_date, |
52
|
|
|
c.ampm, |
53
|
|
|
c.period_type, |
54
|
|
|
c.id_entry, |
55
|
|
|
c.color, |
56
|
|
|
c.title, |
57
|
|
|
e.status |
58
|
|
|
FROM |
59
|
|
|
".ABSENCES_CALENDAR_TBL." c |
60
|
|
|
LEFT JOIN ".ABSENCES_ENTRIES_TBL." e ON e.id = c.id_entry |
61
|
|
|
WHERE |
62
|
|
|
monthkey=".$babDB->quote($month.$year)." |
63
|
|
|
AND c.id_user=".$babDB->quote($id_user)." |
64
|
|
|
ORDER BY c.cal_date, c.ampm |
65
|
|
|
"; |
66
|
|
|
$res = $babDB->db_query($req); |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
if (0 === $babDB->db_num_rows($res)) |
70
|
|
|
{ |
71
|
|
|
// cache not found |
72
|
|
|
|
73
|
|
|
absences_updateCalendar($id_user, $year, $month); |
74
|
|
|
$res = $babDB->db_query($req); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$periodIndex = array(); |
79
|
|
|
|
80
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) { |
81
|
|
|
/* |
82
|
|
|
if ('0000-00-00' !== $dateb && $dateb > $arr['cal_date']) { |
83
|
|
|
continue; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ('0000-00-00' !== $datee && $datee < $arr['cal_date']) { |
87
|
|
|
continue; |
88
|
|
|
} |
89
|
|
|
*/ |
90
|
|
|
$arr['period_type'] = (int) $arr['period_type']; |
91
|
|
|
$arr['ampm'] = (int) $arr['ampm']; |
92
|
|
|
$arr['id_user'] = (int) $arr['id_user']; |
93
|
|
|
|
94
|
|
|
$key = 'd.'.$arr['cal_date']; |
95
|
|
|
$key .= $arr['ampm'] ? '.1' : '.0'; |
96
|
|
|
$periodIndex[$key] = $arr; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
return $periodIndex; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
|
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* |
109
|
|
|
*/ |
110
|
|
View Code Duplication |
function absences_getEntites() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
$id_chart = absences_getVacationOption('id_chart'); |
113
|
|
|
$org = new bab_OrgChartUtil($id_chart); |
114
|
|
|
if (!$org->isAccessValid()) { |
115
|
|
|
return array(); |
116
|
|
|
} |
117
|
|
|
return bab_OCGetEntities($id_chart); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
* @param int $ide |
123
|
|
|
*/ |
124
|
|
View Code Duplication |
function absences_getChildsEntities($ide) |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
$id_chart = absences_getVacationOption('id_chart'); |
127
|
|
|
$org = new bab_OrgChartUtil($id_chart); |
128
|
|
|
if (!$org->isAccessValid()) { |
129
|
|
|
return array(); |
130
|
|
|
} |
131
|
|
|
return bab_OCGetChildsEntities($ide, $id_chart); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
class absences_viewVacationCalendarCls |
138
|
|
|
{ |
139
|
|
|
var $entries = array(); |
140
|
|
|
var $fullname; |
141
|
|
|
var $vacwaitingtxt; |
142
|
|
|
var $vacapprovedtxt; |
143
|
|
|
var $print; |
144
|
|
|
var $close; |
145
|
|
|
var $emptylines = true; |
146
|
|
|
|
147
|
|
|
public $display_types; |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
public $public = false; |
151
|
|
|
public $total = null; |
152
|
|
|
|
153
|
|
|
public $loadmore = null; |
154
|
|
|
public $loadall = false; |
155
|
|
|
|
156
|
|
|
public $nbmonth; |
157
|
|
|
|
158
|
|
|
public $limit; |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* |
163
|
|
|
* @param array $users Users displayed by default |
164
|
|
|
* @param bool $period Allow period selection (vacation request creation first step) |
165
|
|
|
* @param bool $display_types Display types color and legend on planning |
166
|
|
|
* @param int $nbmonth Number of month to load |
167
|
|
|
* @param bool $dispusers Display user names column |
168
|
|
|
*/ |
169
|
|
|
public function __construct($users, $period, $display_types, $nbmonth, $dispusers, $shiftmonth = 0, $legend = true) |
170
|
|
|
{ |
171
|
|
|
global $babBody; |
172
|
|
|
|
173
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/dateTime.php"; |
174
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/urlincl.php"; |
175
|
|
|
|
176
|
|
|
$month = isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : (date("n") + $shiftmonth); |
177
|
|
|
$year = isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : date("Y"); |
178
|
|
|
|
179
|
|
|
global $babDB; |
180
|
|
|
$this->month = $month; |
|
|
|
|
181
|
|
|
$this->year = $year; |
|
|
|
|
182
|
|
|
|
183
|
|
|
$this->dispusers = $dispusers; |
|
|
|
|
184
|
|
|
$this->display_types = $display_types; |
185
|
|
|
$this->display_legend = $legend; |
|
|
|
|
186
|
|
|
|
187
|
|
|
$this->userNameArr = array(); |
|
|
|
|
188
|
|
|
|
189
|
|
|
foreach ($users as $uid) |
190
|
|
|
{ |
191
|
|
|
$uid = (int) $uid; |
192
|
|
|
$this->userNameArr[$uid] = bab_getUserName($uid); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
bab_sort::natcasesort($this->userNameArr); |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
$this->idusers = array_keys($this->userNameArr); |
|
|
|
|
199
|
|
|
$this->nbusers = count($this->idusers); |
|
|
|
|
200
|
|
|
$this->firstuser = bab_toHtml(current($this->userNameArr)); |
|
|
|
|
201
|
|
|
$this->display_firstuser = 1 === $this->nbusers; |
|
|
|
|
202
|
|
|
|
203
|
|
|
$this->period = $period; |
|
|
|
|
204
|
|
|
$this->vacwaitingtxt = absences_translate("Waiting vacation request"); |
205
|
|
|
$this->vacapprovedtxt = absences_translate("Approved vacation request"); |
206
|
|
|
$this->t_selected = absences_translate("Selected period"); |
|
|
|
|
207
|
|
|
$this->print = absences_translate("Print"); |
208
|
|
|
$this->close = absences_translate("Close"); |
209
|
|
|
$this->t_noresult = absences_translate("No results found for this search query"); |
|
|
|
|
210
|
|
|
|
211
|
|
|
$this->t_previousmonth = absences_translate("Previous month"); |
|
|
|
|
212
|
|
|
$this->t_previousyear = absences_translate("Previous year"); |
|
|
|
|
213
|
|
|
$this->t_nextmonth = absences_translate("Next month"); |
|
|
|
|
214
|
|
|
$this->t_nextyear = absences_translate("Next year"); |
|
|
|
|
215
|
|
|
|
216
|
|
|
$this->t_nonworking = absences_translate("Non-working day"); |
|
|
|
|
217
|
|
|
$this->t_weekend = absences_translate("Week-end"); |
|
|
|
|
218
|
|
|
$this->t_rotate = absences_translate("Print in landscape"); |
|
|
|
|
219
|
|
|
$this->t_non_used = $this->display_types ? absences_translate("Non-used days") : absences_translate("Absences"); |
|
|
|
|
220
|
|
|
$this->t_waiting = absences_translate("Waiting vacation request"); |
|
|
|
|
221
|
|
|
$this->t_previsional = absences_translate("Previsional vacation request"); |
|
|
|
|
222
|
|
|
$this->t_waiting_vac = absences_translate("Waiting vacation request"); |
|
|
|
|
223
|
|
|
$this->t_legend = absences_translate("Legend"); |
|
|
|
|
224
|
|
|
|
225
|
|
|
$this->id_request = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0; |
|
|
|
|
226
|
|
|
|
227
|
|
|
$this->nbmonth = $nbmonth; |
228
|
|
|
|
229
|
|
|
$this->limit = absences_getSearchLimit($nbmonth); |
230
|
|
|
|
231
|
|
|
$urltmp = bab_url::get_request_gp(); |
232
|
|
|
$urltmp->search = null; // the search button, disabled for navigation |
233
|
|
|
$this->nwd_color = 'yellow'; // default color for non working days if no categories |
|
|
|
|
234
|
|
|
|
235
|
|
|
if( $GLOBALS['babBody']->babsite['id_calendar_cat'] != 0) |
236
|
|
|
{ |
237
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/calapi.php"; |
238
|
|
|
$idcat = bab_calGetCategories($GLOBALS['babBody']->babsite['id_calendar_cat']); |
239
|
|
|
if( isset($idcat[0]['color'])) |
240
|
|
|
{ |
241
|
|
|
$this->nwd_color = $idcat[0]['color']; |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
if (!empty($_REQUEST['popup'])) |
246
|
|
|
{ |
247
|
|
|
$this->popup = true; |
|
|
|
|
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if (!isset($_REQUEST['ide'])) |
251
|
|
|
{ |
252
|
|
|
$urltmp->idu = implode(',',$this->idusers); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
$switchurl = clone $urltmp; |
256
|
|
|
|
257
|
|
|
if (1 == $this->nbmonth) { |
258
|
|
|
|
259
|
|
|
$switchurl->nbmonth = 12; |
260
|
|
|
$this->switchurl = $switchurl->toString(); |
|
|
|
|
261
|
|
|
$this->switchlabel = absences_translate("Year view"); |
|
|
|
|
262
|
|
|
|
263
|
|
|
|
264
|
|
|
|
265
|
|
|
$this->prevmonthclass = 'prev1'; |
|
|
|
|
266
|
|
|
$this->prevyearclass = 'prev2'; |
|
|
|
|
267
|
|
|
|
268
|
|
|
$this->nextmonthclass = 'next1'; |
|
|
|
|
269
|
|
|
$this->nextyearclass = 'next2'; |
|
|
|
|
270
|
|
|
|
271
|
|
|
} else { |
272
|
|
|
$switchurl->nbmonth = 1; |
273
|
|
|
$this->switchurl = $switchurl->toString(); |
274
|
|
|
$this->switchlabel = absences_translate("Month view"); |
275
|
|
|
|
276
|
|
|
$this->prevmonthclass = 'prev2'; |
277
|
|
|
$this->prevyearclass = 'prev1'; |
278
|
|
|
|
279
|
|
|
$this->nextmonthclass = 'next2'; |
280
|
|
|
$this->nextyearclass = 'next1'; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
$urltmp->nbmonth = $this->nbmonth; |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
$previousmonth = clone $urltmp; |
287
|
|
|
$previousmonth->month = date("n", mktime( 0,0,0, $month-1, 1, $year)); |
288
|
|
|
$previousmonth->year = date("Y", mktime( 0,0,0, $month-1, 1, $year)); |
289
|
|
|
$this->previousmonth = $previousmonth->toString(); |
|
|
|
|
290
|
|
|
|
291
|
|
|
$nextmonth = clone $urltmp; |
292
|
|
|
$nextmonth->month = date("n", mktime( 0,0,0, $month+1, 1, $year)); |
293
|
|
|
$nextmonth->year = date("Y", mktime( 0,0,0, $month+1, 1, $year)); |
294
|
|
|
$this->nextmonth = $nextmonth->toString(); |
|
|
|
|
295
|
|
|
|
296
|
|
|
$previousyear = clone $urltmp; |
297
|
|
|
$previousyear->month = date("n", mktime( 0,0,0, $month, 1, $year-1)); |
298
|
|
|
$previousyear->year = date("Y", mktime( 0,0,0, $month, 1, $year-1)); |
299
|
|
|
$this->previousyear = $previousyear->toString(); |
|
|
|
|
300
|
|
|
|
301
|
|
|
$nextyear = clone $urltmp; |
302
|
|
|
$nextyear->month = date("n", mktime( 0,0,0, $month, 1, $year+1)); |
303
|
|
|
$nextyear->year = date("Y", mktime( 0,0,0, $month, 1, $year+1)); |
304
|
|
|
$this->nextyear = $nextyear->toString(); |
|
|
|
|
305
|
|
|
|
306
|
|
|
$dateb = new BAB_DateTime($year, $month, 1); |
307
|
|
|
$datee = $dateb->cloneDate(); |
308
|
|
|
$datee->add($this->nbmonth, BAB_DATETIME_MONTH); |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
|
312
|
|
|
$this->yearname = $this->getTitle($dateb, $datee); |
|
|
|
|
313
|
|
|
|
314
|
|
|
|
315
|
|
|
|
316
|
|
|
|
317
|
|
|
|
318
|
|
|
|
319
|
|
|
|
320
|
|
|
if ($this->display_types) |
321
|
|
|
{ |
322
|
|
|
$this->restypes = $babDB->db_query(" |
|
|
|
|
323
|
|
|
|
324
|
|
|
SELECT |
325
|
|
|
t.* |
326
|
|
|
FROM |
327
|
|
|
".ABSENCES_TYPES_TBL." t, |
328
|
|
|
absences_rights r, |
329
|
|
|
absences_users_rights ur, |
330
|
|
|
".ABSENCES_PERSONNEL_TBL." p |
331
|
|
|
WHERE |
332
|
|
|
p.id_user IN(".$babDB->quote($this->idusers).") |
333
|
|
|
AND p.id_user=ur.id_user |
334
|
|
|
AND ur.id_right=r.id |
335
|
|
|
AND r.id_type=t.id |
336
|
|
|
GROUP BY |
337
|
|
|
t.id |
338
|
|
|
"); |
339
|
|
|
|
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
|
343
|
|
|
// filtre par service |
344
|
|
|
|
345
|
|
|
$W = bab_Widgets(); |
346
|
|
|
$departments = $W->Multiselect(); |
347
|
|
|
$departments->setName('departments')->setValue(bab_rp('departments')); |
348
|
|
|
|
349
|
|
|
$entities = absences_getEntites(); |
350
|
|
|
foreach($entities as $e) { |
351
|
|
|
$departments->addOption($e['id'], $e['name']); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
$this->departments = ''; |
|
|
|
|
355
|
|
|
|
356
|
|
|
if (count($entities) > 0) { |
357
|
|
|
$this->departments = $departments->display($W->HtmlCanvas()); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
|
361
|
|
|
// filtre recherche par date |
362
|
|
|
|
363
|
|
|
$this->datefilter = $this->getDateFilter()->display($W->HtmlCanvas()); |
|
|
|
|
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
|
367
|
|
|
|
368
|
|
|
private function getDateFilter() |
369
|
|
|
{ |
370
|
|
|
$W = bab_Widgets(); |
371
|
|
|
|
372
|
|
|
switch (bab_rp('searchtype')) { |
373
|
|
View Code Duplication |
case '2': |
|
|
|
|
374
|
|
|
$dateb = bab_rp('dateb'); |
375
|
|
|
$datee = bab_rp('datee'); |
376
|
|
|
$_date = null; |
377
|
|
|
break; |
378
|
|
|
|
379
|
|
|
default: |
380
|
|
View Code Duplication |
case '1': |
|
|
|
|
381
|
|
|
$dateb = null; |
382
|
|
|
$datee = null; |
383
|
|
|
$_date = bab_rp('date'); |
384
|
|
|
break; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
$periodpicker = $W->PeriodPicker()->setNames('dateb', 'datee')->setValues($dateb, $datee); |
388
|
|
|
|
389
|
|
|
$period = $W->LabelledWidget( |
390
|
|
|
absences_translate('Date'), |
391
|
|
|
$periodpicker |
392
|
|
|
); |
393
|
|
|
|
394
|
|
|
$picker = $W->DatePicker() |
395
|
|
|
->setValue($_date) |
396
|
|
|
->addClass('absences-search-by-date'); |
397
|
|
|
|
398
|
|
|
if (method_exists($picker, 'setDefaultDate')) { |
399
|
|
|
$picker->setDefaultDate($this->year.'-'.$this->month.'-01'); |
400
|
|
|
$periodpicker->setDefaultDate($this->year.'-'.$this->month.'-01'); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
$date = $W->LabelledWidget( |
404
|
|
|
absences_translate('Date'), |
405
|
|
|
$picker, |
406
|
|
|
'date' |
407
|
|
|
); |
408
|
|
|
|
409
|
|
|
$begin = $picker->getISODate($dateb); |
410
|
|
|
$end = $picker->getISODate($datee); |
411
|
|
|
$d = $picker->getISODate($_date); |
412
|
|
|
|
413
|
|
|
if ('0000-00-00' !== $d) { |
414
|
|
|
$begin = $d; |
415
|
|
|
$end = $d; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
if ('0000-00-00' !== $begin && '0000-00-00' !== $end) { |
419
|
|
|
$picker->setMetadata('dateb', $begin); |
420
|
|
|
$picker->setMetadata('datee', $end); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
|
424
|
|
|
$frame = $W->Frame(null , $W->HBoxItems()); |
425
|
|
|
|
426
|
|
|
|
427
|
|
|
$frame->addItem( |
428
|
|
|
$W->LabelledWidget( |
429
|
|
|
absences_translate('Search by date'), |
430
|
|
|
$W->Select() |
|
|
|
|
431
|
|
|
->setAssociatedDisplayable($date, array('1')) |
432
|
|
|
->setAssociatedDisplayable($period, array('2')) |
433
|
|
|
->addOption('1', absences_translate("Absences on a date")) |
434
|
|
|
->addOption('2', absences_translate("Absences in a period")) |
435
|
|
|
->setValue(bab_rp('searchtype', 1)), |
436
|
|
|
'searchtype' |
437
|
|
|
) |
438
|
|
|
); |
439
|
|
|
|
440
|
|
|
|
441
|
|
|
$frame->addItem($period); |
442
|
|
|
$frame->addItem($date); |
443
|
|
|
|
444
|
|
|
return $frame; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @param BAB_DateTime $dateb |
450
|
|
|
* @param BAB_DateTime $datee |
451
|
|
|
* |
452
|
|
|
* @return string |
453
|
|
|
*/ |
454
|
|
|
private function getTitle(BAB_DateTime $dateb, BAB_DateTime $datee) |
455
|
|
|
{ |
456
|
|
|
$months = bab_DateStrings::getMonths(); |
457
|
|
|
$duration = (int) round(($datee->getTimeStamp() - $dateb->getTimeStamp()) / 86400); |
458
|
|
|
|
459
|
|
|
if ($duration > 33) { |
460
|
|
|
|
461
|
|
|
$end = $datee->cloneDate(); |
462
|
|
|
$end->less(1, BAB_DATETIME_DAY); |
463
|
|
|
|
464
|
|
|
return $months[$dateb->getMonth()].' '.$dateb->getYear()."-".$months[$end->getMonth()].' '.$end->getYear(); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
return $months[$dateb->getMonth()].' '.$dateb->getYear(); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
|
471
|
|
|
|
472
|
|
|
|
473
|
|
|
public function getnexthidden() |
474
|
|
|
{ |
475
|
|
|
if (list($name, $value) = each($_GET)) |
476
|
|
|
{ |
477
|
|
|
if (is_array($value)) |
478
|
|
|
{ |
479
|
|
|
return true; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
$this->name = bab_toHtml($name); |
|
|
|
|
483
|
|
|
$this->value = bab_toHtml($value); |
|
|
|
|
484
|
|
|
return true; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
reset($_GET); |
488
|
|
|
return false; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
|
492
|
|
|
|
493
|
|
|
public function getdayname() |
494
|
|
|
{ |
495
|
|
|
static $i = 1; |
496
|
|
|
if( $i <= 31) |
497
|
|
|
{ |
498
|
|
|
$this->dayname = sprintf('%02d',$i); |
|
|
|
|
499
|
|
|
$i++; |
500
|
|
|
return true; |
501
|
|
|
} |
502
|
|
|
else |
503
|
|
|
return false; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* |
509
|
|
|
*/ |
510
|
|
|
public function getmonth() |
511
|
|
|
{ |
512
|
|
|
static $i = 0; |
513
|
|
|
if( $i < $this->nbmonth) |
514
|
|
|
{ |
515
|
|
|
|
516
|
|
|
$dateb = new BAB_DateTime($this->year, $this->month + $i, 1); |
517
|
|
|
|
518
|
|
|
$this->curyear = $dateb->getYear(); |
|
|
|
|
519
|
|
|
$this->curmonth = $dateb->getMonth(); |
|
|
|
|
520
|
|
|
$months = bab_DateStrings::getMonths(); |
521
|
|
|
$this->monthname = bab_toHtml($months[$this->curmonth]); |
|
|
|
|
522
|
|
|
$this->totaldays = date("t", $dateb->getTimeStamp()); |
|
|
|
|
523
|
|
|
$this->previous_period = NULL; |
|
|
|
|
524
|
|
|
$i++; |
525
|
|
|
return true; |
526
|
|
|
} |
527
|
|
|
else |
528
|
|
|
return false; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
|
532
|
|
|
|
533
|
|
|
|
534
|
|
|
|
535
|
|
|
public function getnextuser() |
536
|
|
|
{ |
537
|
|
|
static $i = 0; |
538
|
|
|
|
539
|
|
|
$n = $this->nbusers; |
540
|
|
|
|
541
|
|
|
if ( $n == 0 ) |
542
|
|
|
$n = 1; |
543
|
|
|
|
544
|
|
|
$this->rowspan = $this->emptylines ? $this->nbusers : $n; |
|
|
|
|
545
|
|
|
|
546
|
|
|
if ($i < $n) |
547
|
|
|
{ |
548
|
|
|
$this->first = $i == 0 ; |
|
|
|
|
549
|
|
|
$this->id_user = $this->idusers[$i]; |
|
|
|
|
550
|
|
|
$this->username = bab_toHtml($this->userNameArr[$this->id_user]); |
|
|
|
|
551
|
|
|
try { |
552
|
|
|
$agent = absences_Agent::getCurrentUser(); |
553
|
|
|
if ($agent->isManager()) |
554
|
|
|
{ |
555
|
|
|
$this->userurl = bab_toHtml('?tg=addon/absences/vacadm&idx=modp&idp='.$this->idusers[$i]); |
|
|
|
|
556
|
|
|
} else { |
557
|
|
|
$this->userurl = false; |
558
|
|
|
} |
559
|
|
|
} catch(Exception $e) |
560
|
|
|
{ |
561
|
|
|
$this->userurl = false; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
|
565
|
|
|
$i++; |
566
|
|
|
return true; |
567
|
|
|
} |
568
|
|
|
else |
569
|
|
|
{ |
570
|
|
|
$i = 0; |
571
|
|
|
return false; |
572
|
|
|
} |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
|
576
|
|
|
/** |
577
|
|
|
* |
578
|
|
|
* @return boolean |
579
|
|
|
*/ |
580
|
|
|
public function getday() |
581
|
|
|
{ |
582
|
|
|
static $d = 1; |
583
|
|
|
static $total = 0; |
584
|
|
|
if( $d <= 31) |
585
|
|
|
{ |
586
|
|
|
$time = mktime(0, 0, 0, $this->curmonth, $d, $this->curyear); |
587
|
|
|
$this->day = bab_formatDate('%D', $time).' '.date('j', $time); |
|
|
|
|
588
|
|
|
$d++; |
589
|
|
|
return true; |
590
|
|
|
} |
591
|
|
|
else |
592
|
|
|
{ |
593
|
|
|
$d = 1; |
594
|
|
|
return false; |
595
|
|
|
} |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
public function getnexttype() |
599
|
|
|
{ |
600
|
|
|
|
601
|
|
|
if (!$this->display_types) { |
602
|
|
|
return false; |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
global $babDB; |
606
|
|
|
if ($this->arr = $babDB->db_fetch_array($this->restypes)) { |
607
|
|
|
$this->arr['name'] = bab_toHtml($this->arr['name']); |
|
|
|
|
608
|
|
|
$this->arr['description'] = bab_toHtml($this->arr['description']); |
609
|
|
|
return true; |
610
|
|
|
} |
611
|
|
|
else { |
612
|
|
|
return false; |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
|
617
|
|
|
public function entity($ide, $all = false) |
618
|
|
|
{ |
619
|
|
|
// permettre de charger les sous-entites fusionnes dans le meme planning |
620
|
|
|
|
621
|
|
|
$url = bab_url::get_request_gp(); |
622
|
|
|
$url->all = $all ? '0' : '1'; |
623
|
|
|
|
624
|
|
|
$this->mergedurl = false; |
|
|
|
|
625
|
|
|
|
626
|
|
|
if (bab_OCGetChildCount($ide)) { |
627
|
|
|
$this->mergedurl = bab_toHtml($url->toString()); |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
if ($all) { |
631
|
|
|
$this->t_merged = absences_translate('View the entity only'); |
|
|
|
|
632
|
|
|
} else { |
633
|
|
|
$this->t_merged = absences_translate('View users from all entities'); |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
|
638
|
|
|
public function publiccalendar($total) |
639
|
|
|
{ |
640
|
|
|
$this->display_firstuser = false; |
|
|
|
|
641
|
|
|
$this->public = true; |
642
|
|
|
$this->t_search_name = absences_translate('Search by name'); |
|
|
|
|
643
|
|
|
$this->t_search_entity = absences_translate('By entity'); |
|
|
|
|
644
|
|
|
$this->keyword = bab_rp('keyword'); |
|
|
|
|
645
|
|
|
$this->t_ok = absences_translate('Ok'); |
|
|
|
|
646
|
|
|
|
647
|
|
|
$this->total = $total; |
648
|
|
|
$this->t_total = sprintf(absences_translate('%d result found', '%d results found', $total), $total); |
|
|
|
|
649
|
|
|
|
650
|
|
|
|
651
|
|
|
// prepare button for first load |
652
|
|
|
|
653
|
|
|
$this->t_use_month_view = false; |
|
|
|
|
654
|
|
|
|
655
|
|
|
$this->t_loadall = absences_translate('View all results'); |
|
|
|
|
656
|
|
|
$this->t_viewBegin = absences_translate('View the first 30 only'); |
|
|
|
|
657
|
|
|
|
658
|
|
|
if ($total > $this->nbusers) |
659
|
|
|
{ |
660
|
|
|
$last = $total - $this->nbusers; |
661
|
|
|
|
662
|
|
|
if (1 < $this->nbmonth) |
663
|
|
|
{ |
664
|
|
|
$this->t_use_month_view = sprintf(absences_translate('The planning display only %d results from %d total results, use the month view to fetch next results'), $this->nbusers, $total); |
665
|
|
|
$this->loadmore = false; |
666
|
|
|
$this->loadall = false; |
667
|
|
|
} else { |
668
|
|
|
|
669
|
|
|
$this->loadall = false; |
670
|
|
|
$this->loadmore = $this->limit < $last ? $this->limit : $last; |
671
|
|
|
$this->t_loadmore = sprintf(absences_translate('Load the next %d results'), $this->loadmore); |
|
|
|
|
672
|
|
|
} |
673
|
|
|
} else { |
674
|
|
|
$this->loadmore = false; |
675
|
|
|
$this->loadall = false; |
676
|
|
|
} |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
|
680
|
|
|
public function getHtml() |
681
|
|
|
{ |
682
|
|
|
// dans les vielles versions d'ovidentia |
683
|
|
|
// l'access a l'api des organigramme renvoi un message d'erreur si on a pas les droits de lecture |
684
|
|
|
// dans le planning le bouton qui permet d'acceder au sous-entites a besoin de cette api |
685
|
|
|
// on supprime le message d'erreur pour eviter qui apparaisse sur le planning perso |
686
|
|
|
// dans le vielles versions d'ovidentia < 8.4.0 le bouton pour afficher les sous-entites dans le meme planning sera probablement inoperant |
687
|
|
|
// tant que l'organigramme n'est pas accessible en lecture |
688
|
|
|
|
689
|
|
|
$babBody = bab_getBody(); |
690
|
|
|
|
691
|
|
|
if ($babBody->msgerror === bab_translate('Error: Right insufficient')) { |
692
|
|
|
bab_debug($babBody->msgerror); |
693
|
|
|
$babBody->msgerror = null; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
return bab_printTemplate($this, absences_addon()->getRelativePath()."vacuser.html", "calendarbyuser"); |
|
|
|
|
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
|
700
|
|
|
|
701
|
|
|
public function printhtml() |
702
|
|
|
{ |
703
|
|
|
global $babBody; |
704
|
|
|
|
705
|
|
|
/*@var $babBody babBody */ |
706
|
|
|
|
707
|
|
|
$html = $this->getHtml(); |
708
|
|
|
|
709
|
|
|
/*@var $jquery Func_Jquery */ |
710
|
|
|
$jquery = bab_functionality::get('jquery'); |
711
|
|
|
$jquery->includeCore(); |
712
|
|
|
|
713
|
|
|
$babBody->addStyleSheet(absences_addon()->getStylePath().'vacation.css'); |
714
|
|
|
$babBody->addJavascriptFile(absences_addon()->getTemplatePath().'calendar.jquery.js', true); |
715
|
|
|
|
716
|
|
|
if (isset($_REQUEST['popup']) && $_REQUEST['popup'] == 1) { |
717
|
|
|
$babBody->babpopup($html); |
718
|
|
|
} |
719
|
|
|
else { |
720
|
|
|
$babBody->babecho($html); |
721
|
|
|
} |
722
|
|
|
} |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
|
726
|
|
|
|
727
|
|
|
|
728
|
|
|
|
729
|
|
|
|
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* Display a vacation calendar |
733
|
|
|
* @param array $users array of id_user to display |
734
|
|
|
* @param boolean $period allow period selection, first step of vacation request |
735
|
|
|
* @param boolean $display_types Display types color and legend on planning |
736
|
|
|
* @param int $nbmonth Number of month to display |
737
|
|
|
* @param bool $dispusers display a column with user names |
738
|
|
|
* @param int $total Total number of results in search |
739
|
|
|
*/ |
740
|
|
|
function absences_viewVacationCalendar($users, $period, $display_types, $nbmonth = 12, $dispusers = true, $total = null ) |
741
|
|
|
{ |
742
|
|
|
global $babBody; |
743
|
|
|
|
744
|
|
|
$temp = new absences_viewVacationCalendarCls($users, $period, $display_types, $nbmonth, $dispusers); |
745
|
|
|
|
746
|
|
|
if (count($users) == 0) |
747
|
|
|
{ |
748
|
|
|
$babBody->addError(absences_translate("ERROR: No members")); |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
if (bab_rp('idx') == 'entity_cal') |
752
|
|
|
{ |
753
|
|
|
$temp->entity(bab_rp('ide'), (bool) bab_rp('all', false)); |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
if (bab_rp('idx') == 'public') |
757
|
|
|
{ |
758
|
|
|
$temp->publiccalendar($total); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
$temp->printhtml(); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
|
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* Serach in active users to display the public calendar |
768
|
|
|
* @param string $keyword |
769
|
|
|
* @param array $departments |
770
|
|
|
* @param string $dateb |
771
|
|
|
* @param string $datee |
772
|
|
|
* @param string $date |
773
|
|
|
*/ |
774
|
|
|
function absences_publicCalendarUsers($keyword, $departments, $searchtype, $dateb, $datee, $date) |
775
|
|
|
{ |
776
|
|
|
global $babDB; |
777
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/userinfosincl.php'; |
778
|
|
|
|
779
|
|
|
|
780
|
|
|
$W = bab_Widgets(); |
781
|
|
|
$datePicker = $W->DatePicker(); |
782
|
|
|
|
783
|
|
|
switch($searchtype) { |
784
|
|
|
default: |
785
|
|
|
case 1: |
786
|
|
|
$dateb = '0000-00-00'; |
787
|
|
|
$datee = '0000-00-00'; |
788
|
|
|
$date = $datePicker->getISODate($date); |
789
|
|
|
break; |
790
|
|
|
|
791
|
|
|
case 2: |
792
|
|
|
$dateb = $datePicker->getISODate($dateb); |
793
|
|
|
$datee = $datePicker->getISODate($datee); |
794
|
|
|
$date = '0000-00-00'; |
795
|
|
|
break; |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
|
799
|
|
|
if ('0000-00-00' !== $date && false !== $date) { |
800
|
|
|
$dateb = $date; |
801
|
|
|
$datee = $date; |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
|
805
|
|
|
$query = 'SELECT |
806
|
|
|
u.id, |
807
|
|
|
u.lastname, |
808
|
|
|
u.firstname |
809
|
|
|
FROM |
810
|
|
|
bab_users u |
811
|
|
|
LEFT JOIN bab_oc_roles_users ru ON ru.id_user=u.id |
812
|
|
|
LEFT JOIN bab_oc_roles r ON r.id=ru.id_role, |
813
|
|
|
absences_personnel p |
814
|
|
|
|
815
|
|
|
WHERE |
816
|
|
|
p.id_user=u.id AND '.bab_userInfos::queryAllowedUsers('u'); |
817
|
|
|
|
818
|
|
|
|
819
|
|
|
if (isset($keyword)) |
820
|
|
|
{ |
821
|
|
|
$query .= ' AND (u.lastname LIKE \'%'.$babDB->db_escape_like($keyword).'%\' OR u.firstname LIKE \'%'.$babDB->db_escape_like($keyword).'%\')'; |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
if (isset($departments)) |
825
|
|
|
{ |
826
|
|
|
$query .= ' AND r.id_entity IN('.$babDB->quote($departments).')'; |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
if ('0000-00-00' !== $dateb && '0000-00-00' !== $datee && false !== $dateb && false !== $datee) { |
830
|
|
|
$subquery = 'SELECT id_user FROM absences_entries WHERE date_begin<'.$babDB->quote($datee.' 23:59:59').' AND date_end>'.$babDB->quote($dateb.' 00:00:00').' GROUP BY id_user'; |
831
|
|
|
$query .= ' AND u.id IN('.$subquery.')'; |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
|
835
|
|
|
$query .= 'GROUP BY u.id ORDER BY u.lastname, u.firstname'; |
836
|
|
|
|
837
|
|
|
$res = $babDB->db_query($query); |
838
|
|
|
|
839
|
|
|
return $res; |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
|
843
|
|
|
function absences_getSearchLimit($nbmonth) |
844
|
|
|
{ |
845
|
|
|
$initusers = (int) bab_rp('limit'); |
846
|
|
|
if (empty($initusers)) { |
847
|
|
|
// preload the 30 first users if limit not set |
848
|
|
|
$initusers = 1 === $nbmonth ? 30 : 10; |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
return $initusers; |
852
|
|
|
} |
853
|
|
|
|
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.