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
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/ocapi.php"; |
26
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/urlincl.php"; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Tester si l'utilisateur en cours est un superieur de l'utilisateur passe en parametre ou si c'est la meme personne |
30
|
|
|
* @param int $id_user |
31
|
|
|
* |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
function absences_IsUserUnderSuperior($id_user) |
35
|
|
|
{ |
36
|
|
|
if ($id_user == bab_getUserId()) |
37
|
|
|
{ |
38
|
|
|
return true; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
42
|
|
|
|
43
|
|
|
$testedAgent = absences_Agent::getFromIdUser($id_user); |
44
|
|
|
$currentAgent = absences_Agent::getCurrentUser(); |
45
|
|
|
|
46
|
|
|
return $currentAgent->isSuperiorOf($testedAgent); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
class absences_notifyOnRequestChangeCls |
57
|
|
|
{ |
58
|
|
|
function __construct(absences_Entry $entry, $msg) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$this->message = $msg; |
|
|
|
|
61
|
|
|
$this->fromuser = absences_translate("User"); |
|
|
|
|
62
|
|
|
$this->from = absences_translate("from"); |
|
|
|
|
63
|
|
|
$this->until = absences_translate("until"); |
|
|
|
|
64
|
|
|
$this->quantitytxt = absences_translate("Quantity"); |
|
|
|
|
65
|
|
|
$this->commenttxt = absences_translate("Comment"); |
|
|
|
|
66
|
|
|
$this->username = bab_toHtml($entry->getUserName()); |
|
|
|
|
67
|
|
|
$this->begindate = bab_longDate(bab_mktime($entry->date_begin)); |
|
|
|
|
68
|
|
|
$this->enddate = bab_longDate(bab_mktime($entry->date_end)); |
|
|
|
|
69
|
|
|
$this->comment = bab_toHtml($entry->comment); |
|
|
|
|
70
|
|
|
$this->quantity = bab_toHtml(absences_vacEntryQuantity($entry->id)); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Notifier le demandeur si la demande de conges est modifiee ou supprime |
79
|
|
|
* @param array | Iterator $entries |
80
|
|
|
* @param int $id_user Recipient |
81
|
|
|
* @param bool $delete |
82
|
|
|
*/ |
83
|
|
|
function absences_notifyOnRequestChange($entries, $id_user, $delete = false) |
84
|
|
|
{ |
85
|
|
|
global $BAB_SESS_USER, $BAB_SESS_EMAIL; |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
$mail = bab_mail(); |
89
|
|
|
if( $mail == false ) |
90
|
|
|
return; |
91
|
|
|
|
92
|
|
|
$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user)); |
93
|
|
|
|
94
|
|
|
$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER); |
95
|
|
|
|
96
|
|
|
$msg = $delete ? absences_translate("Vacation request has been deleted") : absences_translate("Vacation request has been modified"); |
97
|
|
|
$mail->mailSubject($msg); |
98
|
|
|
|
99
|
|
|
$message = ''; |
100
|
|
|
$messagetxt = ''; |
101
|
|
|
|
102
|
|
View Code Duplication |
foreach($entries as $entry) |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$tempb = new absences_notifyOnRequestChangeCls($entry, $msg); |
105
|
|
|
$message .= $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newvacation")); |
|
|
|
|
106
|
|
|
$messagetxt .= bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newvacationtxt"); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$mail->mailBody($message, "html"); |
110
|
|
|
$mail->mailAltBody($messagetxt); |
111
|
|
|
|
112
|
|
|
$mail->send(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Notification for the manager when a request is deleted/modified |
118
|
|
|
* |
119
|
|
|
* |
120
|
|
|
*/ |
121
|
|
|
class absences_notifyManagers |
122
|
|
|
{ |
123
|
|
|
private $res; |
124
|
|
|
|
125
|
|
|
public function __construct(Array $row, $msg) |
126
|
|
|
{ |
127
|
|
|
global $babDB; |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
$this->message = $msg; |
|
|
|
|
131
|
|
|
$this->fromuser = absences_translate("User"); |
|
|
|
|
132
|
|
|
$this->from = absences_translate("from"); |
|
|
|
|
133
|
|
|
$this->until = absences_translate("until"); |
|
|
|
|
134
|
|
|
$this->username = bab_toHtml(bab_getUserName($row['id_user'])); |
|
|
|
|
135
|
|
|
$this->begindate = bab_longDate(bab_mktime($row['date_begin'])); |
|
|
|
|
136
|
|
|
$this->enddate = bab_longDate(bab_mktime($row['date_end'])); |
|
|
|
|
137
|
|
|
$this->res = $babDB->db_query("select |
138
|
|
|
r.description, |
139
|
|
|
e.quantity, |
140
|
|
|
r.quantity_unit, |
141
|
|
|
rg.name rgroup_name |
142
|
|
|
from |
143
|
|
|
absences_entries_elem e, |
144
|
|
|
absences_rights r |
145
|
|
|
LEFT JOIN absences_rgroup rg ON rg.id=r.id_rgroup |
146
|
|
|
where |
147
|
|
|
e.id_right=r.id |
148
|
|
|
AND e.id_entry =".$babDB->quote($row['id']) |
149
|
|
|
); |
150
|
|
|
$this->comment = bab_toHtml($row['comment']); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
public function getnextelem() |
155
|
|
|
{ |
156
|
|
|
global $babDB; |
157
|
|
|
|
158
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->res)) |
159
|
|
|
{ |
160
|
|
|
$this->description = bab_toHtml($arr['description']); |
|
|
|
|
161
|
|
|
$this->descriptiontxt = $arr['description']; |
|
|
|
|
162
|
|
|
$this->quantity = bab_toHtml(absences_quantity($arr['quantity'], $arr['quantity_unit'])); |
|
|
|
|
163
|
|
|
$this->rgroup_name = bab_toHtml($arr['rgroup_name']); |
|
|
|
|
164
|
|
|
return true; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
return false; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public static function send($id, $delete = false) |
172
|
|
|
{ |
173
|
|
|
|
174
|
|
|
$mail = bab_mail(); |
175
|
|
|
if( $mail == false ) |
176
|
|
|
{ |
177
|
|
|
return; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
$notify = (bool) absences_getVacationOption('email_manager_ondelete'); |
181
|
|
|
if (!$notify) |
182
|
|
|
{ |
183
|
|
|
return; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
global $babDB, $BAB_SESS_EMAIL, $BAB_SESS_USER; |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
$row = $babDB->db_fetch_array($babDB->db_query("select * from ".ABSENCES_ENTRIES_TBL." where id='".$babDB->db_escape_string($id)."'")); |
191
|
|
|
|
192
|
|
|
if (!$row) |
193
|
|
|
{ |
194
|
|
|
return; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER); |
198
|
|
|
|
199
|
|
|
require_once $GLOBALS['babInstallPath'].'admin/acl.php'; |
200
|
|
|
$managers = aclGetAccessUsers('absences_managers_groups', 1); |
201
|
|
|
foreach ($managers as $m) |
202
|
|
|
{ |
203
|
|
|
$mail->mailTo($m['email'], $m['name']); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
$msg = $delete ? absences_translate("Vacation request has been deleted") : absences_translate("Vacation request has been modified"); |
207
|
|
|
$mail->mailSubject($msg); |
208
|
|
|
|
209
|
|
|
$tempb = new absences_notifyManagers($row, $msg); |
210
|
|
|
$message = $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "vacmanager")); |
|
|
|
|
211
|
|
|
$mail->mailBody($message, "html"); |
212
|
|
|
|
213
|
|
|
$message = bab_printTemplate($tempb,"mailinfo.html", absences_addon()->getRelativePath()."vacmanagertxt"); |
|
|
|
|
214
|
|
|
$mail->mailAltBody($message); |
215
|
|
|
|
216
|
|
|
$mail->send(); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
|
222
|
|
|
|
223
|
|
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
|
227
|
|
|
|
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get list of right for a user |
231
|
|
|
* |
232
|
|
|
* @param string|false $begin ISO datetime |
233
|
|
|
* @param string|false $end ISO datetime |
234
|
|
|
* @param int|false $id_user |
235
|
|
|
* @param 1|0 $rfrom test active flag on right if user is not manager |
|
|
|
|
236
|
|
|
* |
237
|
|
|
* @return array |
238
|
|
|
*/ |
239
|
|
|
function absences_getRightsOnPeriod($begin = false, $end = false, $id_user = false, $rfrom = 0) |
240
|
|
|
{ |
241
|
|
|
require_once dirname(__FILE__).'/agent_right.class.php'; |
242
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
243
|
|
|
|
244
|
|
|
$return = array(); |
245
|
|
|
$begin = $begin ? bab_mktime( $begin ) : $begin; |
246
|
|
|
$end = $end ? bab_mktime( $end ) : $end; |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
if (!$id_user) { |
|
|
|
|
250
|
|
|
$id_user = $GLOBALS['BAB_SESS_USERID']; |
251
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$agent = absences_Agent::getFromIdUser($id_user); |
255
|
|
|
|
256
|
|
|
$res = new absences_AgentRightUserIterator(); |
257
|
|
|
$res->setAgent($agent); |
258
|
|
|
|
259
|
|
|
if( $rfrom == 1 ) |
260
|
|
|
{ |
261
|
|
|
$acclevel = absences_vacationsAccess(); |
262
|
|
|
if( isset($acclevel['manager']) && $acclevel['manager']) |
263
|
|
|
{ |
264
|
|
|
$res->showInactive(); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
if ($begin && $end) |
269
|
|
|
{ |
270
|
|
|
$res->setRequestPeriod($begin, $end); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
|
275
|
|
|
foreach ($res as $agentRight ) |
276
|
|
|
{ |
277
|
|
|
|
278
|
|
|
/*@var $agentRight absences_AgentRight */ |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
$right = $agentRight->getRight(); |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
$return[$right->id] = array( |
285
|
|
|
'id' => $right->id, |
286
|
|
|
'date_begin' => $right->date_begin, |
287
|
|
|
'date_end' => $right->date_end, |
288
|
|
|
'date_begin_valid' => $right->date_begin_valid, // disponibilite en fonction de la date de saisie |
289
|
|
|
'date_end_valid' => $right->date_end_valid, |
290
|
|
|
'quantity' => $right->quantity, |
291
|
|
|
'quantity_unit' => $right->quantity_unit, |
292
|
|
|
'description' => $right->description, |
293
|
|
|
'cbalance' => $right->cbalance, |
294
|
|
|
'quantity_available' => $agentRight->getAvailableQuantity(), |
295
|
|
|
'used' => $agentRight->getConfirmedQuantity(), |
296
|
|
|
'waiting' => $agentRight->getWaitingQuantity(), |
297
|
|
|
'no_distribution' => $right->no_distribution, |
298
|
|
|
'id_rgroup' => $right->id_rgroup, |
299
|
|
|
'rgroup' => $right->getRgroupLabel(), |
300
|
|
|
'agentRight' => $agentRight, |
301
|
|
|
'sortkey' => $right->id_rgroup > 0 ? $right->getRgroupSortkey() : $right->getSortKey() |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
return $return; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Rights list for on user, grouped by right groups |
311
|
|
|
* @param int $id_user |
312
|
|
|
* @param int $rfrom |
313
|
|
|
*/ |
314
|
|
|
function absences_getRightsByGroupOnPeriod($id_user, $rfrom = 0) { |
315
|
|
|
|
316
|
|
|
require_once dirname(__FILE__).'/agent_right.class.php'; |
317
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
318
|
|
|
|
319
|
|
|
if (!$id_user) { |
320
|
|
|
$id_user = $GLOBALS['BAB_SESS_USERID']; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
$agent = absences_Agent::getFromIdUser($id_user); |
324
|
|
|
|
325
|
|
|
// creer les droits de report eventuels avant d'afficher la liste des droits |
326
|
|
|
$agent->createReports(); |
327
|
|
|
|
328
|
|
|
$res = $agent->getAgentRightUserIterator(); |
329
|
|
|
|
330
|
|
|
if( $rfrom == 1 ) |
331
|
|
|
{ |
332
|
|
|
$current_Agent = absences_Agent::getCurrentUser(); |
333
|
|
|
if($current_Agent->isManager()) |
334
|
|
|
{ |
335
|
|
|
$res->showInactive(); |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
$rights = array(); |
340
|
|
|
foreach($res as $agentRight) { |
341
|
|
|
|
342
|
|
|
/*@var $agentRight absences_AgentRight */ |
343
|
|
|
|
344
|
|
|
$right = $agentRight->getRight(); |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
if (empty($right->id_rgroup) || null === $right->getRgroupLabel()) { |
348
|
|
|
$id = 'r'.$right->id; |
349
|
|
|
$description = $right->description; |
350
|
|
|
$type = $right->getType(); |
351
|
|
|
$sortkey = (int) $right->sortkey; |
352
|
|
|
} else { |
353
|
|
|
$id = 'g'.$right->id_rgroup; |
354
|
|
|
$description = $right->getRgroupLabel(); |
355
|
|
|
$type = null; |
356
|
|
|
$sortkey = $right->getRgroupSortkey(); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
if (isset($rights[$id])) { |
360
|
|
|
$quantity = $rights[$id]['quantity'] + $right->quantity; |
361
|
|
|
$quantity_available = $rights[$id]['quantity_available'] + $agentRight->getAvailableQuantity(); |
362
|
|
|
$used = $rights[$id]['used'] + $agentRight->getConfirmedQuantity(); |
363
|
|
|
$waiting = $rights[$id]['waiting'] + $agentRight->getWaitingQuantity(); |
364
|
|
|
$previsional = $rights[$id]['previsional'] + $agentRight->getPrevisionalQuantity(); |
365
|
|
|
} else { |
366
|
|
|
$quantity = $right->quantity; |
367
|
|
|
$quantity_available = $agentRight->getAvailableQuantity(); |
368
|
|
|
$used = $agentRight->getConfirmedQuantity(); |
369
|
|
|
$waiting = $agentRight->getWaitingQuantity(); |
370
|
|
|
$previsional = $agentRight->getPrevisionalQuantity(); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$rights[$id] = array( |
374
|
|
|
'description' => $description, |
375
|
|
|
'quantity' => $quantity, |
376
|
|
|
'quantity_unit' => $right->quantity_unit, |
377
|
|
|
'quantity_available' => $quantity_available, |
378
|
|
|
'used' => $used, |
379
|
|
|
'waiting' => $waiting, |
380
|
|
|
'previsional' => $previsional, |
381
|
|
|
'type' => $type, |
382
|
|
|
'sortkey' => $sortkey |
383
|
|
|
); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
bab_Sort::asort($rights, 'sortkey'); |
387
|
|
|
|
388
|
|
|
return $rights; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
|
392
|
|
|
|
393
|
|
|
|
394
|
|
|
class absences_Paginate |
395
|
|
|
{ |
396
|
|
|
/** |
397
|
|
|
* |
398
|
|
|
* @var int |
399
|
|
|
*/ |
400
|
|
|
public $pos; |
401
|
|
|
|
402
|
|
|
public $topurl = ""; |
403
|
|
|
public $bottomurl = ""; |
404
|
|
|
public $nexturl = ""; |
405
|
|
|
public $prevurl = ""; |
406
|
|
|
|
407
|
|
|
public $t_position = ''; |
408
|
|
|
|
409
|
|
|
public $display_pagination = false; |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
protected function paginate($total, $max) |
413
|
|
|
{ |
414
|
|
|
$this->t_first_page = absences_translate('First page'); |
|
|
|
|
415
|
|
|
$this->t_previous_page = absences_translate('Previous page'); |
|
|
|
|
416
|
|
|
$this->t_next_page = absences_translate('Next page'); |
|
|
|
|
417
|
|
|
$this->t_last_page = absences_translate('Last page'); |
|
|
|
|
418
|
|
|
|
419
|
|
|
|
420
|
|
|
$this->pos = (int) bab_rp('pos', 0); |
421
|
|
|
|
422
|
|
|
if( $total > $max ) |
423
|
|
|
{ |
424
|
|
|
$this->display_pagination = true; |
425
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php'; |
426
|
|
|
|
427
|
|
|
$tmpurl = bab_url::get_request_gp(); |
428
|
|
|
|
429
|
|
|
$page_number = 1 + ($this->pos / $max); |
430
|
|
|
$page_total = 1 + ($total / $max); |
431
|
|
|
$this->t_position = sprintf(absences_translate("Page %d/%d"), $page_number,$page_total); |
432
|
|
|
|
433
|
|
|
if( $this->pos > 0) |
434
|
|
|
{ |
435
|
|
|
$tmpurl->pos = 0; |
436
|
|
|
$this->topurl = bab_toHtml($tmpurl->toString()); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
$next = $this->pos - $max; |
440
|
|
|
if( $next >= 0) |
441
|
|
|
{ |
442
|
|
|
$tmpurl->pos = $next; |
443
|
|
|
$this->prevurl = bab_toHtml($tmpurl->toString()); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
$next = $this->pos + $max; |
447
|
|
|
if( $next < $total) |
448
|
|
|
{ |
449
|
|
|
$tmpurl->pos = $next; |
450
|
|
|
$this->nexturl = bab_toHtml($tmpurl->toString()); |
451
|
|
|
|
452
|
|
|
if( $next + $max < $total) |
453
|
|
|
{ |
454
|
|
|
$bottom = $total - $max; |
455
|
|
|
} |
456
|
|
|
else |
457
|
|
|
{ |
458
|
|
|
$bottom = $next; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
$tmpurl->pos = $bottom; |
462
|
|
|
$this->bottomurl = bab_toHtml($tmpurl->toString()); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
|
470
|
|
|
|
471
|
|
|
|
472
|
|
|
|
473
|
|
|
abstract class absences_MovementList extends absences_Paginate |
474
|
|
|
{ |
475
|
|
|
const MAX = 20; |
476
|
|
|
|
477
|
|
|
public $altbg = true; |
478
|
|
|
|
479
|
|
|
public $t_date; |
480
|
|
|
public $date; |
481
|
|
|
|
482
|
|
|
public $t_author; |
483
|
|
|
public $author; |
484
|
|
|
|
485
|
|
|
public $t_message; |
486
|
|
|
public $message; |
487
|
|
|
|
488
|
|
|
public $t_comment; |
489
|
|
|
public $comment; |
490
|
|
|
|
491
|
|
|
protected $res; |
492
|
|
|
|
493
|
|
|
public function __construct() |
494
|
|
|
{ |
495
|
|
|
$this->t_date = absences_translate('Date'); |
496
|
|
|
$this->t_author = absences_translate('Author'); |
497
|
|
|
$this->t_request = absences_translate('Object'); |
|
|
|
|
498
|
|
|
$this->t_message = absences_translate('Message'); |
499
|
|
|
$this->t_comment = absences_translate('Regularization or approval comment by the author'); |
500
|
|
|
|
501
|
|
|
bab_functionality::includeOriginal('Icons'); |
|
|
|
|
502
|
|
|
} |
503
|
|
|
|
504
|
|
View Code Duplication |
public function getnext() |
|
|
|
|
505
|
|
|
{ |
506
|
|
|
if (($this->res->key() - $this->pos) >= self::MAX) |
507
|
|
|
{ |
508
|
|
|
return false; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
if ($this->res->valid()) |
512
|
|
|
{ |
513
|
|
|
$W = bab_Widgets(); |
514
|
|
|
$movement = $this->res->current(); |
515
|
|
|
/*@var $movement absences_Movement */ |
516
|
|
|
|
517
|
|
|
$this->altbg = !$this->altbg; |
518
|
|
|
|
519
|
|
|
$this->author = bab_toHtml(bab_getUserName($movement->id_author)); |
520
|
|
|
$this->date = bab_toHtml(bab_shortDate(bab_mktime($movement->createdOn))); |
521
|
|
|
if ($request = $movement->getRequest()) |
522
|
|
|
{ |
523
|
|
|
$this->request = $request->getManagerFrame()->addClass(Func_Icons::ICON_LEFT_16)->display($W->HtmlCanvas()); |
|
|
|
|
524
|
|
|
} else { |
525
|
|
|
$this->request = ''; |
|
|
|
|
526
|
|
|
} |
527
|
|
|
$this->message = bab_toHtml($movement->message); |
528
|
|
|
$this->comment = bab_toHtml($movement->comment); |
529
|
|
|
|
530
|
|
|
$this->res->next(); |
531
|
|
|
return true; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
return false; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
View Code Duplication |
public function getHtml() |
|
|
|
|
538
|
|
|
{ |
539
|
|
|
$babBody = bab_getInstance('babBody'); |
540
|
|
|
|
541
|
|
|
if ($this->res->count() === 0) |
542
|
|
|
{ |
543
|
|
|
$babBody->addError(absences_translate('There are no records yet')); |
544
|
|
|
return ''; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
return bab_printTemplate($this, absences_addon()->getRelativePath()."agent.html", "movement"); |
|
|
|
|
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
|
552
|
|
|
|
553
|
|
|
|
554
|
|
|
|
555
|
|
|
class absences_listVacationRequestsCls extends absences_Paginate |
556
|
|
|
{ |
557
|
|
|
public $altbg = true; |
558
|
|
|
public $cardframe; |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* |
562
|
|
|
* @var int |
563
|
|
|
*/ |
564
|
|
|
public $folder; |
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* |
568
|
|
|
* @var absences_EntryIterator |
569
|
|
|
*/ |
570
|
|
|
private $folderIterator; |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* @var array |
574
|
|
|
*/ |
575
|
|
|
private $users; |
576
|
|
|
|
577
|
|
|
public $res; |
578
|
|
|
public $total; |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* 1 si les demandes sont modifiee par une autre personne que l'auteur |
582
|
|
|
* @var int |
583
|
|
|
*/ |
584
|
|
|
public $rfrom = 0; |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Entitee de l'organigramme |
588
|
|
|
* @var int |
589
|
|
|
*/ |
590
|
|
|
public $ide = null; |
591
|
|
|
|
592
|
|
|
|
593
|
|
|
public function __construct($id_user, $display_username) |
594
|
|
|
{ |
595
|
|
|
require_once dirname(__FILE__).'/request.class.php'; |
596
|
|
|
|
597
|
|
|
|
598
|
|
|
$this->uncheckall = absences_translate("Uncheck all"); |
|
|
|
|
599
|
|
|
$this->checkall = absences_translate("Check all"); |
|
|
|
|
600
|
|
|
$this->nametxt = absences_translate("Fullname"); |
|
|
|
|
601
|
|
|
$this->begindatetxt = absences_translate("Begin date"); |
|
|
|
|
602
|
|
|
$this->enddatetxt = absences_translate("End date"); |
|
|
|
|
603
|
|
|
$this->quantitytxt = absences_translate("Quantity"); |
|
|
|
|
604
|
|
|
$this->statustxt = absences_translate("Status"); |
|
|
|
|
605
|
|
|
$this->calendar = absences_translate("My planning"); |
|
|
|
|
606
|
|
|
$this->t_entity_planning = absences_translate("Department planning"); |
|
|
|
|
607
|
|
|
$this->myrights = absences_translate("My rights"); |
|
|
|
|
608
|
|
|
$this->t_edit = absences_translate("Modification"); |
|
|
|
|
609
|
|
|
$this->t_submit_previsional = absences_translate("Submit for approval"); |
|
|
|
|
610
|
|
|
|
611
|
|
|
$this->t_first_page = absences_translate("First page"); |
|
|
|
|
612
|
|
|
$this->t_previous_page = absences_translate("Previous page"); |
|
|
|
|
613
|
|
|
$this->t_next_page = absences_translate("Next page"); |
|
|
|
|
614
|
|
|
$this->t_last_page = absences_translate("Last page"); |
|
|
|
|
615
|
|
|
|
616
|
|
|
$this->details = absences_translate("View details"); |
|
|
|
|
617
|
|
|
$this->t_delete = absences_translate("Delete"); |
|
|
|
|
618
|
|
|
|
619
|
|
|
$this->display_username = $display_username; |
|
|
|
|
620
|
|
|
|
621
|
|
|
|
622
|
|
|
|
623
|
|
|
if (!is_array($id_user)) |
624
|
|
|
$this->users = array($id_user); |
625
|
|
|
else |
626
|
|
|
$this->users = $id_user; |
627
|
|
|
|
628
|
|
|
$this->calurl = bab_toHtml(absences_addon()->getUrl()."planning&idx=cal&idu=".implode(',', $this->users)."&popup=1"); |
|
|
|
|
629
|
|
|
$this->personal = ($id_user == bab_getUserId()); |
|
|
|
|
630
|
|
|
|
631
|
|
|
if ($this->personal) |
632
|
|
|
{ |
633
|
|
|
$agent = absences_Agent::getCurrentUser(); |
634
|
|
|
$entity = $agent->getMainEntity(); |
635
|
|
|
$this->entity_planning = $agent->canViewMainEntityPlanning(); |
|
|
|
|
636
|
|
|
$this->entity_calurl = bab_toHtml(absences_addon()->getUrl()."planning&idx=entity_cal&ide=".$entity['id']."&popup=1&emptylines=1"); |
|
|
|
|
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
$this->myrightsurl = bab_toHtml(absences_addon()->getUrl()."vacuser&idx=myrights"); |
|
|
|
|
640
|
|
|
|
641
|
|
|
|
642
|
|
|
$this->res = new absences_RequestIterator($this->users); |
643
|
|
|
$this->res->one_per_folder = true; |
644
|
|
|
$this->total = $this->res->count(); |
645
|
|
|
|
646
|
|
|
$this->paginate($this->total, ABSENCES_MAX_REQUESTS_LIST); |
647
|
|
|
|
648
|
|
|
$this->res->rewind(); |
649
|
|
|
$this->res->seek($this->pos); |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
|
653
|
|
|
public function getnext() |
654
|
|
|
{ |
655
|
|
|
|
656
|
|
|
if (($this->res->key() - $this->pos) >= ABSENCES_MAX_REQUESTS_LIST) |
657
|
|
|
{ |
658
|
|
|
return false; |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
|
662
|
|
|
if ($this->res->valid()) |
663
|
|
|
{ |
664
|
|
|
$this->altbg = !$this->altbg; |
665
|
|
|
$request = $this->res->current(); |
666
|
|
|
if (isset($request->folder) && $request->folder > 0) |
|
|
|
|
667
|
|
|
{ |
668
|
|
|
$this->folder = $request->folder; |
|
|
|
|
669
|
|
|
$this->folderIterator = new absences_EntryIterator; |
670
|
|
|
$this->folderIterator->orderby = 'date_begin ASC'; |
671
|
|
|
$this->folderIterator->folder = $this->folder; |
672
|
|
|
$this->folderIterator->id_entry_folder = $request->id; |
673
|
|
|
$this->folderIterator->users = $this->users; |
674
|
|
|
} else { |
675
|
|
|
$this->folder = null; |
676
|
|
|
$this->folderIterator = null; |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
$this->cardframe = $request->getCardFrame($this->display_username, $this->rfrom, $this->ide)->display(bab_Widgets()->HtmlCanvas()); |
680
|
|
|
|
681
|
|
|
$this->res->next(); |
682
|
|
|
return true; |
683
|
|
|
} |
684
|
|
|
return false; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
|
688
|
|
|
|
689
|
|
|
public function getnextfolded() |
690
|
|
|
{ |
691
|
|
|
if (isset($this->folderIterator) && $this->folderIterator->valid()) |
692
|
|
|
{ |
693
|
|
|
$request = $this->folderIterator->current(); |
694
|
|
|
$this->cardframe = $request->getCardFrame($this->display_username, $this->rfrom, $this->ide)->display(bab_Widgets()->HtmlCanvas()); |
695
|
|
|
$this->folderIterator->next(); |
696
|
|
|
return true; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
return false; |
700
|
|
|
} |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* Liste des demandes |
706
|
|
|
* |
707
|
|
|
* @param array | int $id_user |
708
|
|
|
* @param bool $display_username |
709
|
|
|
* @param int $rfrom si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue |
710
|
|
|
* @param int $ide id entite de l'organigramme >0 si gestionnaire delegue seulement |
711
|
|
|
*/ |
712
|
|
|
function absences_listVacationRequests($id_user, $display_username = false, $rfrom = 0, $ide = null) |
713
|
|
|
{ |
714
|
|
|
$babBody = bab_getInstance('babBody'); |
715
|
|
|
/*@var $babBody babBody */ |
716
|
|
|
|
717
|
|
|
if (empty($id_user)) { |
718
|
|
|
$babBody->msgerror = absences_translate("ERROR: No members"); |
719
|
|
|
return; |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
$temp = new absences_listVacationRequestsCls($id_user, $display_username); |
723
|
|
|
$temp->rfrom = $rfrom; |
724
|
|
|
$temp->ide = $ide; |
725
|
|
|
|
726
|
|
|
if (0 === $temp->total) |
727
|
|
|
{ |
728
|
|
|
$babBody->addMessage(absences_translate('You have no ongoing requests')); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
|
732
|
|
|
$babBody->addStyleSheet(absences_addon()->getRelativePath().'vacation.css'); |
|
|
|
|
733
|
|
|
$babBody->babecho(bab_printTemplate($temp, absences_addon()->getRelativePath()."vacuser.html", "vrequestslist")); |
|
|
|
|
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
|
737
|
|
|
|
738
|
|
|
|
739
|
|
|
|
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* |
743
|
|
|
* @param int $id ID user |
744
|
|
|
*/ |
745
|
|
|
function absences_listRightsByUser($id) |
746
|
|
|
{ |
747
|
|
|
global $babBody; |
748
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
749
|
|
|
|
750
|
|
|
$temp = new absences_AgentRightsList($id); |
751
|
|
|
$html = bab_printTemplate($temp, absences_addon()->getRelativePath()."vacadm.html", "rlistbyuser"); |
|
|
|
|
752
|
|
|
|
753
|
|
|
if (1 === (int) bab_rp('popup', 0)) |
754
|
|
|
{ |
755
|
|
|
$babBody->babPopup($html); |
756
|
|
|
} else { |
757
|
|
|
$babBody->babEcho($html); |
758
|
|
|
} |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
|
762
|
|
|
|
763
|
|
|
|
764
|
|
|
|
765
|
|
|
|
766
|
|
|
|
767
|
|
|
|
768
|
|
|
|
769
|
|
|
|
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* Mise a jour de la liste des droits d'un utilisateur |
773
|
|
|
* |
774
|
|
|
* @param int $userid |
775
|
|
|
* @param array $quantity |
776
|
|
|
* |
777
|
|
|
* @return boolean |
778
|
|
|
*/ |
779
|
|
|
function absences_updateVacationRightByUser($userid, $quantity, $comment) |
780
|
|
|
{ |
781
|
|
|
require_once dirname(__FILE__).'/changes.class.php'; |
782
|
|
|
|
783
|
|
|
$agent = absences_Agent::getFromIdUser($userid); |
784
|
|
|
foreach($agent->getAgentRightManagerIterator() as $agentRight) |
785
|
|
|
{ |
786
|
|
|
$right = $agentRight->getRight(); |
787
|
|
|
$changes = new absences_Changes(); |
788
|
|
|
|
789
|
|
|
if (!isset($quantity[$right->id])) |
790
|
|
|
{ |
791
|
|
|
continue; |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
$agentRightQuantity = $agentRight->getQuantityFromInput($quantity[$right->id]); |
795
|
|
|
if (!isset($agentRightQuantity)) |
796
|
|
|
{ |
797
|
|
|
continue; |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
|
801
|
|
|
$old_quantity = absences_quantity($agentRight->getQuantity(), $right->quantity_unit); |
802
|
|
|
$new_quantity = absences_quantity($agentRightQuantity, $right->quantity_unit); |
803
|
|
|
|
804
|
|
|
$changes->setQuantity($old_quantity, $new_quantity); |
805
|
|
|
$agentRight->quantity = $agentRightQuantity; |
806
|
|
|
$agentRight->save(); |
807
|
|
|
|
808
|
|
|
$agentRight->addAgentMovement($agent, $changes, $comment); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
return true; |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
|
815
|
|
|
|
816
|
|
|
|
817
|
|
|
|
818
|
|
|
|
819
|
|
|
|
820
|
|
|
|
821
|
|
|
|
822
|
|
|
|
823
|
|
|
class absences_rlistbyuserUnloadCls |
824
|
|
|
{ |
825
|
|
|
public $message; |
826
|
|
|
public $close; |
827
|
|
|
|
828
|
|
|
public function __construct($msg) |
829
|
|
|
{ |
830
|
|
|
$this->message = $msg; |
831
|
|
|
$this->close = absences_translate("Close"); |
832
|
|
|
} |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
|
836
|
|
|
|
837
|
|
|
|
838
|
|
|
|
839
|
|
|
function absences_rlistbyuserUnload($msg) |
840
|
|
|
{ |
841
|
|
|
$temp = new absences_rlistbyuserUnloadCls($msg); |
842
|
|
|
global $babBody; |
843
|
|
|
$babBody->babPopup(bab_printTemplate($temp, absences_addon()->getRelativePath()."vacadm.html", "rlistbyuserunload")); |
|
|
|
|
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
|
847
|
|
|
|
848
|
|
|
|
849
|
|
|
|
850
|
|
|
|
851
|
|
|
|
852
|
|
|
|
853
|
|
|
|
854
|
|
|
|
855
|
|
|
|
856
|
|
|
|
857
|
|
|
|
858
|
|
|
|
859
|
|
|
|
860
|
|
|
|
861
|
|
|
|
862
|
|
|
|
863
|
|
|
function absences_addVacationPersonnel($idp = false) |
864
|
|
|
{ |
865
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
866
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
867
|
|
|
|
868
|
|
|
|
869
|
|
|
$temp = new absences_AgentEdit($idp); |
870
|
|
|
$temp->printhtml(); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
|
874
|
|
|
|
875
|
|
|
|
876
|
|
|
|
877
|
|
|
|
878
|
|
|
|
879
|
|
|
/** |
880
|
|
|
* |
881
|
|
|
* @param int $ide |
882
|
|
|
* @return boolean |
883
|
|
|
*/ |
884
|
|
|
function absences_isAccessibleEntityAsSuperior($ide) { |
885
|
|
|
|
886
|
|
|
$ide = (int) $ide; |
887
|
|
|
|
888
|
|
|
$id_oc = absences_getVacationOption('id_chart'); |
889
|
|
|
|
890
|
|
|
|
891
|
|
|
$userentities = & bab_OCGetUserEntities($GLOBALS['BAB_SESS_USERID'], $id_oc); |
892
|
|
|
absences_addCoManagerEntities($userentities, $GLOBALS['BAB_SESS_USERID']); |
893
|
|
|
$userentities['superior']; |
894
|
|
|
|
895
|
|
|
foreach($userentities['superior'] as $arr) { |
896
|
|
|
if ($ide === (int) $arr['id']) { |
897
|
|
|
return true; |
898
|
|
|
} |
899
|
|
|
} |
900
|
|
|
|
901
|
|
|
return false; |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
|
905
|
|
|
/** |
906
|
|
|
* |
907
|
|
|
* @param int $ide |
908
|
|
|
* @return boolean |
909
|
|
|
*/ |
910
|
|
|
function absences_isAccessibleEntityAsCoManager($ide) { |
911
|
|
|
|
912
|
|
|
global $babDB; |
913
|
|
|
|
914
|
|
|
list($n) = $babDB->db_fetch_array($babDB->db_query(' |
915
|
|
|
SELECT COUNT(*) FROM '.ABSENCES_COMANAGER_TBL.' |
916
|
|
|
WHERE |
917
|
|
|
id_user='.$babDB->quote($GLOBALS['BAB_SESS_USERID']).' |
918
|
|
|
AND id_entity='.$babDB->quote($ide).' |
919
|
|
|
')); |
920
|
|
|
|
921
|
|
|
if ($n > 0) { |
922
|
|
|
return true; |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
return false; |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* Relancer les demande en attente sur le nouveau shema d'aprobation |
931
|
|
|
* n'est plus utilise pour le moment car la modification de l'utilisateur est bloque si il reste des demandes en attente en cours |
932
|
|
|
* |
933
|
|
|
* @param int $userid |
934
|
|
|
* @param int $idsa |
935
|
|
|
*/ |
936
|
|
|
function absences_updateVacationUser($userid, $idsa) |
937
|
|
|
{ |
938
|
|
|
global $babDB; |
939
|
|
|
|
940
|
|
|
$res = $babDB->db_query("select * from ".ABSENCES_ENTRIES_TBL." where id_user=".$babDB->quote($userid)." and status=''"); |
941
|
|
|
while( $row = $babDB->db_fetch_array($res)) { |
942
|
|
|
if( $row['idfai'] != 0 ) { |
943
|
|
|
deleteFlowInstance($row['idfai']); |
944
|
|
|
} |
945
|
|
|
$idfai = makeFlowInstance($idsa, "vac-".$row['id']); |
946
|
|
|
setFlowInstanceOwner($idfai, $row['id_user']); |
|
|
|
|
947
|
|
|
$babDB->db_query("UPDATE ".ABSENCES_ENTRIES_TBL." SET idfai=".$babDB->quote($idfai)." where id=".$babDB->quote($row['id']).""); |
948
|
|
|
$nfusers = getWaitingApproversFlowInstance($idfai, true); |
|
|
|
|
949
|
|
|
absences_notifyVacationApprovers($row['id'], $nfusers); |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
|
954
|
|
|
|
955
|
|
|
/** |
956
|
|
|
* Mise a jour du changement de regime |
957
|
|
|
*/ |
958
|
|
|
function absences_updateUserColl() |
959
|
|
|
{ |
960
|
|
|
global $babDB; |
961
|
|
|
|
962
|
|
|
if (empty($_POST['idp'])) |
963
|
|
|
{ |
964
|
|
|
return false; |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
$agent = absences_Agent::getFromIdUser($_POST['idp']); |
968
|
|
|
|
969
|
|
|
$users_rights = array(); |
970
|
|
|
$worked_ids = array(); |
971
|
|
|
|
972
|
|
|
$old_collection = $agent->getCollection(); |
973
|
|
|
$new_collection = absences_Collection::getById($_POST['idcol']); |
974
|
|
|
|
975
|
|
|
|
976
|
|
|
$res = $babDB->db_query("SELECT |
977
|
|
|
ur.id, |
978
|
|
|
ur.id_right, |
979
|
|
|
cr.id in_collection |
980
|
|
|
FROM ".ABSENCES_USERS_RIGHTS_TBL." ur |
981
|
|
|
LEFT JOIN |
982
|
|
|
absences_coll_rights cr ON ur.id_right=cr.id_right AND cr.id_coll=".$babDB->quote($old_collection->id)." |
983
|
|
|
WHERE |
984
|
|
|
id_user=".$babDB->quote($_POST['idp'])." |
985
|
|
|
"); |
986
|
|
|
|
987
|
|
|
|
988
|
|
|
$in_old_collection =array(); |
989
|
|
|
while($arr = $babDB->db_fetch_array($res)) |
990
|
|
|
{ |
991
|
|
|
$users_rights[$arr['id_right']] = $arr['id']; |
992
|
|
|
if (isset($arr['in_collection'])) { |
993
|
|
|
$in_old_collection[$arr['id_right']] = $arr['id_right']; |
994
|
|
|
} |
995
|
|
|
} |
996
|
|
|
|
997
|
|
|
$old_rights = $agent->getAgentRightManagerIterator(); |
998
|
|
|
$used = array(); |
999
|
|
|
foreach($old_rights as $r) |
1000
|
|
|
{ |
1001
|
|
|
/*@var $r absences_AgentRight */ |
1002
|
|
|
$used[$r->id_right] = $r->getConfirmedQuantity(); |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
$prefix = 'right_'; |
1006
|
|
|
$post_rights = array(); |
1007
|
|
|
|
1008
|
|
|
/* control */ |
1009
|
|
|
|
1010
|
|
|
foreach($_POST as $field => $value) |
1011
|
|
|
{ |
1012
|
|
|
if (mb_substr($field,0,mb_strlen($prefix)) == $prefix) |
1013
|
|
|
{ |
1014
|
|
|
$value = (float) str_replace(',', '.', $value); |
1015
|
|
|
|
1016
|
|
|
list(,$id_right) = explode('_',$field); |
1017
|
|
|
if (isset($used[$id_right])) |
1018
|
|
|
{ |
1019
|
|
|
$value += $used[$id_right]; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
$right = new absences_Right($id_right); |
1023
|
|
|
|
1024
|
|
|
if (((int) round(100*$right->quantity)) === ((int) round(100*$value))) |
1025
|
|
|
{ |
1026
|
|
|
// the value in the input is the default right value |
1027
|
|
|
$value = ''; |
1028
|
|
|
|
1029
|
|
|
} else if ($value < 0) |
1030
|
|
|
{ |
1031
|
|
|
if ($right->cbalance == 'N') |
1032
|
|
|
{ |
1033
|
|
|
$GLOBALS['babBody']->addError(sprintf(absences_translate("Negative balance are not allowed on right %s"), $right->description)); |
1034
|
|
|
return false; |
1035
|
|
|
|
1036
|
|
|
} |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
|
1040
|
|
|
$post_rights[$id_right] = $value; |
1041
|
|
|
} |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
/* RECORD */ |
1045
|
|
|
|
1046
|
|
|
foreach($post_rights as $id_right => $user_quantity) |
1047
|
|
|
{ |
1048
|
|
|
|
1049
|
|
|
$renewal = isset($_POST['renewal'][$id_right]) ? '1' : '0'; |
1050
|
|
|
|
1051
|
|
|
if (isset($users_rights[$id_right])) |
1052
|
|
|
{ |
1053
|
|
|
$babDB->db_query("UPDATE |
1054
|
|
|
".ABSENCES_USERS_RIGHTS_TBL." |
1055
|
|
|
SET |
1056
|
|
|
quantity='".$babDB->db_escape_string($user_quantity)."', |
1057
|
|
|
renewal=".$babDB->quote($renewal)." |
1058
|
|
|
WHERE id='".$babDB->db_escape_string($users_rights[$id_right])."' |
1059
|
|
|
"); |
1060
|
|
|
$worked_ids[] = $users_rights[$id_right]; |
1061
|
|
|
} |
1062
|
|
View Code Duplication |
else |
|
|
|
|
1063
|
|
|
{ |
1064
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_USERS_RIGHTS_TBL." |
1065
|
|
|
(id_user,id_right,quantity, renewal) |
1066
|
|
|
VALUES |
1067
|
|
|
( |
1068
|
|
|
'".$babDB->db_escape_string($_POST['idp'])."', |
1069
|
|
|
'".$babDB->db_escape_string($id_right)."', |
1070
|
|
|
'".$babDB->db_escape_string($user_quantity)."', |
1071
|
|
|
".$babDB->quote($renewal)." |
1072
|
|
|
)"); |
1073
|
|
|
$worked_ids[] = $babDB->db_insert_id(); |
1074
|
|
|
} |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
|
1078
|
|
|
if (count($worked_ids) > 0) |
1079
|
|
|
{ |
1080
|
|
|
// on supprime les liens avec les droits de l'ancien regime |
1081
|
|
|
// il ne faut pas supprimer les droits qui etait en rouge dans la liste |
1082
|
|
|
|
1083
|
|
|
$babDB->db_query(" |
1084
|
|
|
DELETE FROM ".ABSENCES_USERS_RIGHTS_TBL." |
1085
|
|
|
WHERE id NOT IN(".$babDB->quote($worked_ids).") |
1086
|
|
|
AND id_user= '".$babDB->db_escape_string($_POST['idp'])."' |
1087
|
|
|
AND id_right IN(".$babDB->quote($in_old_collection).") |
1088
|
|
|
"); |
1089
|
|
|
} |
1090
|
|
|
|
1091
|
|
|
|
1092
|
|
|
|
1093
|
|
|
|
1094
|
|
|
|
1095
|
|
|
if ($old_collection->id != $new_collection->id) |
1096
|
|
|
{ |
1097
|
|
|
$babDB->db_query("UPDATE ".ABSENCES_PERSONNEL_TBL." SET id_coll='".$babDB->db_escape_string($_POST['idcol'])."' WHERE id_user='".$babDB->db_escape_string($_POST['idp'])."'"); |
1098
|
|
|
|
1099
|
|
|
$agent->addMovement(sprintf(absences_translate('The collection has been modified from %s to %s'), $old_collection->name, $new_collection->name)); |
1100
|
|
|
} |
1101
|
|
|
return true; |
1102
|
|
|
} |
1103
|
|
|
|
1104
|
|
|
|
1105
|
|
|
function absences_changeucol($id_user,$newcol) |
1106
|
|
|
{ |
1107
|
|
|
global $babBody; |
1108
|
|
|
|
1109
|
|
|
class tempa |
1110
|
|
|
{ |
1111
|
|
|
var $altbg = true; |
1112
|
|
|
|
1113
|
|
|
function tempa($id_user,$newcol) |
|
|
|
|
1114
|
|
|
{ |
1115
|
|
|
$this->t_oldcol = absences_translate("Old collection"); |
|
|
|
|
1116
|
|
|
$this->t_newcol = absences_translate("New collection"); |
|
|
|
|
1117
|
|
|
$this->t_record = absences_translate("Record"); |
|
|
|
|
1118
|
|
|
$this->t_quantity = absences_translate("Quantity"); |
|
|
|
|
1119
|
|
|
$this->t_nbdays = absences_translate("Day(s)"); |
|
|
|
|
1120
|
|
|
$this->t_right = absences_translate("Rights"); |
|
|
|
|
1121
|
|
|
$this->t_balance = absences_translate("Balance"); |
|
|
|
|
1122
|
|
|
$this->t_balance_title = absences_translate("User remaining quantity (waiting request ignored)"); |
|
|
|
|
1123
|
|
|
$this->t_new_balance_title = absences_translate("User remaining quantity on new right, the new user rights will equal to balance+consumed (waiting request ignored)"); |
|
|
|
|
1124
|
|
|
$this->t_confirmed = absences_translate("Consumed"); |
|
|
|
|
1125
|
|
|
$this->t_waiting = absences_translate("Waiting"); |
|
|
|
|
1126
|
|
|
$this->t_right_user_title = absences_translate("Default quantity in the vacation right and specific user quantity (tooltip on bold)"); |
|
|
|
|
1127
|
|
|
$this->t_right_title = absences_translate("Default quantity in the vacation right"); |
|
|
|
|
1128
|
|
|
$this->t_user_modified = absences_translate("A specific user quantity exists"); |
|
|
|
|
1129
|
|
|
$this->t_renewal = absences_translate('Renewal'); |
|
|
|
|
1130
|
|
|
$this->t_renewal_title = absences_translate('Include this right in the next yearly renewal'); |
|
|
|
|
1131
|
|
|
|
1132
|
|
|
global $babDB; |
1133
|
|
|
$this->tg = bab_rp('tg'); |
|
|
|
|
1134
|
|
|
$this->ide = bab_rp('ide', false); |
|
|
|
|
1135
|
|
|
|
1136
|
|
|
$agent = absences_Agent::getFromIdUser($id_user); |
1137
|
|
|
$old_rights = $agent->getAgentRightManagerIterator(); |
1138
|
|
|
|
1139
|
|
|
$this->id_user = $id_user; |
|
|
|
|
1140
|
|
|
$this->id_coll = $newcol; |
|
|
|
|
1141
|
|
|
|
1142
|
|
|
$newCollection = absences_Collection::getById($newcol); |
1143
|
|
|
|
1144
|
|
|
$oldCollection = $agent->getCollection(); |
1145
|
|
|
$this->oldcol = ''; |
|
|
|
|
1146
|
|
|
|
1147
|
|
|
if (isset($oldCollection) && $oldCollection->getRow()) { |
1148
|
|
|
$this->oldcol = bab_toHtml($oldCollection->name); |
|
|
|
|
1149
|
|
|
} |
1150
|
|
|
|
1151
|
|
|
$this->newcol = bab_toHtml($newCollection->name); |
|
|
|
|
1152
|
|
|
|
1153
|
|
|
|
1154
|
|
|
$req = "SELECT cr.id_right _id_right, ur.* FROM |
1155
|
|
|
|
1156
|
|
|
absences_coll_rights cr |
1157
|
|
|
LEFT JOIN absences_users_rights ur ON ur.id_right = cr.id_right |
1158
|
|
|
AND ur.id_user = ".$babDB->quote($id_user)." |
1159
|
|
|
WHERE |
1160
|
|
|
cr.id_coll='".$babDB->db_escape_string($newcol)."' |
1161
|
|
|
"; |
1162
|
|
|
|
1163
|
|
|
$res = $babDB->db_query($req); |
1164
|
|
|
|
1165
|
|
|
$new_rights = array(); |
1166
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) |
1167
|
|
|
{ |
1168
|
|
|
|
1169
|
|
|
if (isset($arr['id'])) |
1170
|
|
|
{ |
1171
|
|
|
$row = $arr; |
1172
|
|
|
unset($row['_id_right']); |
1173
|
|
|
$collRight = new absences_AgentRight; |
1174
|
|
|
$collRight->setRow($arr); |
1175
|
|
|
} else { |
1176
|
|
|
$collRight = new absences_Right($arr['_id_right']); |
1177
|
|
|
|
1178
|
|
|
if (!$collRight->getRow()) |
1179
|
|
|
{ |
1180
|
|
|
bab_debug(sprintf('Failed to load right for id_right=%d', $arr['_id_right']), DBG_ERROR); |
1181
|
|
|
continue; |
1182
|
|
|
} |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
$new_rights[] = $collRight; |
1186
|
|
|
} |
1187
|
|
|
|
1188
|
|
|
$this->totaldays = 0; |
|
|
|
|
1189
|
|
|
|
1190
|
|
|
$this->rights = array(); |
|
|
|
|
1191
|
|
|
|
1192
|
|
|
foreach ($old_rights as $agentRight) |
1193
|
|
|
{ |
1194
|
|
|
$right = $agentRight->getRight(); |
1195
|
|
|
|
1196
|
|
View Code Duplication |
if (!$right->getRow()) { |
|
|
|
|
1197
|
|
|
bab_debug(sprintf('Failed to load right for agentRight %d, id_right=%d', $agentRight->id, $agentRight->id_right), DBG_ERROR); |
1198
|
|
|
continue; |
1199
|
|
|
} |
1200
|
|
|
|
1201
|
|
|
// ignorer les droits avec un solde a zero et qui sont |
1202
|
|
|
|
1203
|
|
|
if (!$right->isAccessibleByValidityPeriod() && 0 === (int) round(100 * $agentRight->getAvailableQuantity())) { |
1204
|
|
|
continue; |
1205
|
|
|
} |
1206
|
|
|
|
1207
|
|
|
|
1208
|
|
|
$this->rights[$right->id] = array( |
1209
|
|
|
'quantity_unit' => $right->quantity_unit, |
1210
|
|
|
'description' => $right->description, |
1211
|
|
|
'quantity_old' => $right->quantity, |
1212
|
|
|
'user_quantity_old' => $agentRight->quantity, |
1213
|
|
|
'quantity_available' => $agentRight->getAvailableQuantity(), |
1214
|
|
|
'confirmed' => (float) $agentRight->getConfirmedQuantity(), |
1215
|
|
|
'waiting' => (float) $agentRight->getWaitingQuantity() |
1216
|
|
|
); |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
foreach ($new_rights as $collRight) |
1220
|
|
|
{ |
1221
|
|
|
|
1222
|
|
|
|
1223
|
|
|
if ($collRight instanceof absences_AgentRight) |
1224
|
|
|
{ |
1225
|
|
|
$right = $collRight->getRight(); |
1226
|
|
|
$agentRight = $collRight; |
1227
|
|
|
$user_quantity_new = $agentRight->quantity; |
1228
|
|
|
$quantity_available = $agentRight->getAvailableQuantity(); |
1229
|
|
|
$confirmed = (float) $agentRight->getConfirmedQuantity(); |
1230
|
|
|
$waiting = (float) $agentRight->getWaitingQuantity(); |
1231
|
|
|
|
1232
|
|
|
} else { |
1233
|
|
|
$right = $collRight; |
1234
|
|
|
|
1235
|
|
|
$user_quantity_new = $right->quantity; |
1236
|
|
|
$quantity_available = null; |
1237
|
|
|
$confirmed = null; |
1238
|
|
|
$waiting = null; |
1239
|
|
|
} |
1240
|
|
|
|
1241
|
|
View Code Duplication |
if (!$right->getRow()) |
|
|
|
|
1242
|
|
|
{ |
1243
|
|
|
bab_debug(sprintf('Failed to load right for agentRight %d, id_right=%d', $agentRight->id, $agentRight->id_right), DBG_ERROR); |
|
|
|
|
1244
|
|
|
continue; |
1245
|
|
|
} |
1246
|
|
|
|
1247
|
|
|
if (!isset($this->rights[$right->id])) |
1248
|
|
|
{ |
1249
|
|
|
|
1250
|
|
|
|
1251
|
|
|
|
1252
|
|
|
$this->rights[$right->id] = array( |
1253
|
|
|
'quantity_unit' => $right->quantity_unit, |
1254
|
|
|
'description' => $right->description, |
1255
|
|
|
'quantity_new' => $right->quantity, |
1256
|
|
|
'user_quantity_new' => $user_quantity_new, |
1257
|
|
|
'quantity_available' => $quantity_available, |
1258
|
|
|
'confirmed' => $confirmed, |
1259
|
|
|
'waiting' => $waiting |
1260
|
|
|
); |
1261
|
|
|
|
1262
|
|
|
} |
1263
|
|
|
else |
1264
|
|
|
{ |
1265
|
|
|
$this->rights[$right->id]['quantity_new'] = $right->quantity; |
1266
|
|
|
$this->rights[$right->id]['confirmed'] = $confirmed; |
1267
|
|
|
$this->rights[$right->id]['waiting'] = $waiting; |
1268
|
|
|
} |
1269
|
|
|
} |
1270
|
|
|
} |
1271
|
|
|
|
1272
|
|
|
|
1273
|
|
|
private function createQuantityProperty($right, $name) |
1274
|
|
|
{ |
1275
|
|
|
|
1276
|
|
|
|
1277
|
|
|
if (!isset($right[$name]) || '' === $right[$name]) { |
1278
|
|
|
$this->right[$name] = ''; |
|
|
|
|
1279
|
|
|
} else { |
1280
|
|
|
$this->right[$name] = bab_toHtml(absences_quantity($right[$name], $right['quantity_unit'])); |
|
|
|
|
1281
|
|
|
} |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
function getnext() |
|
|
|
|
1285
|
|
|
{ |
1286
|
|
|
if (list($this->id,$right) = each($this->rights)) |
1287
|
|
|
{ |
1288
|
|
|
$this->altbg = !$this->altbg; |
1289
|
|
|
$default = (isset($right['quantity_new']) && $right['quantity_available'] > $right['quantity_new']) || !is_numeric($right['quantity_available']) ? $right['quantity_new'] : $right['quantity_available']; |
1290
|
|
|
|
1291
|
|
|
$newrightvalue = isset($_POST['right_'.$this->id]) ? $_POST['right_'.$this->id] : $default; |
|
|
|
|
1292
|
|
|
$this->newrightvalue = bab_toHtml(absences_editQuantity($newrightvalue, $right['quantity_unit'])); |
|
|
|
|
1293
|
|
|
|
1294
|
|
|
$this->createQuantityProperty($right, 'quantity_new'); |
1295
|
|
|
$this->createQuantityProperty($right, 'quantity_old'); |
1296
|
|
|
|
1297
|
|
|
$this->createQuantityProperty($right, 'user_quantity_new'); |
1298
|
|
|
$this->createQuantityProperty($right, 'user_quantity_old'); |
1299
|
|
|
|
1300
|
|
|
$this->createQuantityProperty($right, 'confirmed'); |
1301
|
|
|
$this->createQuantityProperty($right, 'waiting'); |
1302
|
|
|
|
1303
|
|
|
$this->createQuantityProperty($right, 'quantity_available'); |
1304
|
|
|
|
1305
|
|
|
|
1306
|
|
|
$this->right['description'] = bab_toHtml($right['description']); |
|
|
|
|
1307
|
|
|
//$this->right['quantity_available'] = bab_toHtml(absences_quantity($right['quantity_available'], $right['quantity_unit'])); |
1308
|
|
|
|
1309
|
|
|
$this->renewal = isset($right['quantity_new']); |
|
|
|
|
1310
|
|
|
|
1311
|
|
|
return true; |
1312
|
|
|
} |
1313
|
|
|
else |
1314
|
|
|
{ |
1315
|
|
|
return false; |
1316
|
|
|
} |
1317
|
|
|
} |
1318
|
|
|
|
1319
|
|
|
|
1320
|
|
|
|
1321
|
|
|
} |
1322
|
|
|
|
1323
|
|
|
|
1324
|
|
|
$tempa = new tempa($id_user,$newcol); |
1325
|
|
|
$babBody->babecho( bab_printTemplate($tempa, absences_addon()->getRelativePath()."vacadm.html", "changeucol")); |
|
|
|
|
1326
|
|
|
|
1327
|
|
|
} |
1328
|
|
|
|
1329
|
|
|
|
1330
|
|
|
function absences_getWfName($id_approb) |
1331
|
|
|
{ |
1332
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
1333
|
|
|
if (!$id_approb) |
1334
|
|
|
{ |
1335
|
|
|
return absences_translate('None'); |
1336
|
|
|
} |
1337
|
|
|
|
1338
|
|
|
|
1339
|
|
|
$arr = bab_WFGetApprobationInfos($id_approb); |
1340
|
|
|
|
1341
|
|
|
return $arr['name']; |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
|
1345
|
|
|
|
1346
|
|
|
|
1347
|
|
|
|
1348
|
|
|
|
1349
|
|
|
|
1350
|
|
|
|
1351
|
|
|
/** |
1352
|
|
|
* Set parameter for agent (create or modify) |
1353
|
|
|
* if the agent does not exists, il will be created |
1354
|
|
|
* |
1355
|
|
|
* @param int $iduser |
1356
|
|
|
* @param int $id_collection |
1357
|
|
|
* @param int $idsa Approval scheme |
1358
|
|
|
* @param int $id_sa_cet Optionnal approval scheme for time saving account |
1359
|
|
|
* @param int $id_sa_recover Optionnal approval scheme for work period recovery |
1360
|
|
|
* |
1361
|
|
|
* @throws Exception |
1362
|
|
|
* |
1363
|
|
|
* @return bool |
1364
|
|
|
*/ |
1365
|
|
|
function absences_setAgentInfos($iduser, $id_collection, $idsa, $id_sa_cet = 0, $id_sa_recover = 0, $emails = null, $id_organization = null) |
1366
|
|
|
{ |
1367
|
|
|
global $babDB; |
1368
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
1369
|
|
|
|
1370
|
|
|
if( empty($iduser) ) |
1371
|
|
|
{ |
1372
|
|
|
throw new Exception(absences_translate("You must specify a user")); |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
if( empty($idsa) ) |
1376
|
|
|
{ |
1377
|
|
|
throw new Exception(absences_translate("You must specify approbation schema")); |
1378
|
|
|
} |
1379
|
|
|
|
1380
|
|
|
if( !empty($iduser)) |
1381
|
|
|
{ |
1382
|
|
|
$agent = absences_Agent::getFromIdUser($iduser); |
1383
|
|
|
if( $agent->exists() ) |
1384
|
|
|
{ |
1385
|
|
|
|
1386
|
|
|
$query = "UPDATE ".ABSENCES_PERSONNEL_TBL." SET |
1387
|
|
|
|
1388
|
|
|
id_sa='".$babDB->db_escape_string($idsa)."', |
1389
|
|
|
id_sa_cet=".$babDB->quote($id_sa_cet).", |
1390
|
|
|
id_sa_recover=".$babDB->quote($id_sa_recover).""; |
1391
|
|
|
|
1392
|
|
|
if (null !== $id_collection) { |
1393
|
|
|
$query .= ", id_coll=".$babDB->quote($id_collection); |
1394
|
|
|
} |
1395
|
|
|
|
1396
|
|
|
if (null !== $emails) { |
1397
|
|
|
$query .= ", emails=".$babDB->quote($emails); |
1398
|
|
|
} |
1399
|
|
|
|
1400
|
|
|
if (null !== $id_organization) { |
1401
|
|
|
$query .= ", id_organization=".$babDB->quote($id_organization); |
1402
|
|
|
} |
1403
|
|
|
|
1404
|
|
|
|
1405
|
|
|
$babDB->db_query($query." WHERE id_user='".$babDB->db_escape_string($iduser)."'"); |
1406
|
|
|
|
1407
|
|
|
if( $agent->id_sa != $idsa ) |
1408
|
|
|
{ |
1409
|
|
|
$old = bab_WFGetApprobationInfos($agent->id_sa); |
1410
|
|
|
$new = bab_WFGetApprobationInfos($idsa); |
1411
|
|
|
$agent->addMovement(sprintf(absences_translate('The approbation shema has been modified from %s to %s'), $old['name'], $new['name'])); |
1412
|
|
|
} |
1413
|
|
|
|
1414
|
|
View Code Duplication |
if( $agent->id_sa_cet != $id_sa_cet ) |
|
|
|
|
1415
|
|
|
{ |
1416
|
|
|
$agent->addMovement(sprintf(absences_translate('The approbation shema for time saving account has been modified from %s to %s'), |
1417
|
|
|
absences_getWfName($agent->id_sa_cet), absences_getWfName($id_sa_cet))); |
1418
|
|
|
} |
1419
|
|
|
|
1420
|
|
View Code Duplication |
if( $agent->id_sa_recover != $id_sa_recover ) |
|
|
|
|
1421
|
|
|
{ |
1422
|
|
|
$agent->addMovement(sprintf(absences_translate('The approbation shema for work period recovery has been modified from %s to %s'), |
1423
|
|
|
absences_getWfName($agent->id_sa_recover), absences_getWfName($id_sa_recover))); |
1424
|
|
|
} |
1425
|
|
|
|
1426
|
|
|
|
1427
|
|
|
} |
1428
|
|
|
else |
1429
|
|
|
{ |
1430
|
|
|
if( empty($id_collection) ) |
1431
|
|
|
{ |
1432
|
|
|
throw new Exception(absences_translate("You must specify a vacation collection")); |
1433
|
|
|
} |
1434
|
|
|
|
1435
|
|
|
|
1436
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_PERSONNEL_TBL." |
1437
|
|
|
( |
1438
|
|
|
id_user, |
1439
|
|
|
id_coll, |
1440
|
|
|
id_sa, |
1441
|
|
|
id_sa_cet, |
1442
|
|
|
id_sa_recover, |
1443
|
|
|
emails, |
1444
|
|
|
id_organization |
1445
|
|
|
) VALUES ( |
1446
|
|
|
'".$babDB->db_escape_string($iduser)."', |
1447
|
|
|
".$babDB->quote($id_collection).", |
1448
|
|
|
'".$babDB->db_escape_string((string) $idsa)."', |
1449
|
|
|
'".$babDB->db_escape_string((string) $id_sa_cet)."', |
1450
|
|
|
'".$babDB->db_escape_string((string) $id_sa_recover)."', |
1451
|
|
|
".$babDB->quote((string) $emails).", |
1452
|
|
|
".$babDB->quote((string) $id_organization)." |
1453
|
|
|
)"); |
1454
|
|
|
|
1455
|
|
|
$agent->addMovement(absences_translate('New personnel member created')); |
1456
|
|
|
} |
1457
|
|
|
} |
1458
|
|
|
|
1459
|
|
|
|
1460
|
|
|
return true; |
1461
|
|
|
} |
1462
|
|
|
|
1463
|
|
|
|
1464
|
|
|
|
1465
|
|
|
/** |
1466
|
|
|
* Set rights associations according to collection |
1467
|
|
|
* |
1468
|
|
|
* @param int $id_user |
1469
|
|
|
* @param int $id_collection |
1470
|
|
|
* |
1471
|
|
|
* |
1472
|
|
|
*/ |
1473
|
|
|
function absences_setCollectionRights($id_user, $id_collection) |
1474
|
|
|
{ |
1475
|
|
|
require_once dirname(__FILE__).'/vacfixedincl.php'; |
1476
|
|
|
global $babDB; |
1477
|
|
|
|
1478
|
|
|
// create default user rights |
1479
|
|
|
|
1480
|
|
|
$babDB->db_query("DELETE FROM ".ABSENCES_USERS_RIGHTS_TBL." WHERE id_user='".$babDB->db_escape_string($id_user)."'"); |
1481
|
|
|
|
1482
|
|
|
$res = $babDB->db_query("SELECT |
1483
|
|
|
cr.id_right |
1484
|
|
|
FROM |
1485
|
|
|
absences_coll_rights cr |
1486
|
|
|
WHERE |
1487
|
|
|
cr.id_coll='".$babDB->db_escape_string($id_collection)."' |
1488
|
|
|
"); |
1489
|
|
|
|
1490
|
|
|
while($r = $babDB->db_fetch_array($res)) |
1491
|
|
|
{ |
1492
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_USERS_RIGHTS_TBL." ( id_user, id_right ) VALUES ('".$babDB->db_escape_string($id_user)."','".$babDB->db_escape_string($r['id_right'])."')"); |
1493
|
|
|
} |
1494
|
|
|
|
1495
|
|
|
|
1496
|
|
|
// update fixed vacation right |
1497
|
|
|
$messages = ''; |
1498
|
|
|
absences_updateFixedRightsOnUser($id_user, $messages); |
|
|
|
|
1499
|
|
|
} |
1500
|
|
|
|
1501
|
|
|
|
1502
|
|
|
|
1503
|
|
|
|
1504
|
|
|
/** |
1505
|
|
|
* mise a jour d'un utilisateur, utiliser par le gestionnaire et le gestionnaire delegue |
1506
|
|
|
* return false : retour au formulaire de modification de l'agent |
1507
|
|
|
* return true : continuer vers l'ecran de modification du regime |
1508
|
|
|
* return null : retour a la liste des agents |
1509
|
|
|
* |
1510
|
|
|
* |
1511
|
|
|
* @return bool | null |
1512
|
|
|
*/ |
1513
|
|
|
function absences_updateVacationPersonnel($id_user) |
1514
|
|
|
{ |
1515
|
|
|
global $babBody; |
1516
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
1517
|
|
|
|
1518
|
|
|
$agent = absences_Agent::getFromIdUser($id_user); |
1519
|
|
|
|
1520
|
|
|
try { |
1521
|
|
|
// T8246: on ne modifie pas le regime, l'utilisateur est redirige vers la page du changement de regime |
1522
|
|
|
absences_setAgentInfos($id_user, null, bab_rp('idsa'), bab_rp('id_sa_cet'), bab_rp('id_sa_recover'), bab_rp('emails'), bab_rp('id_organization')); |
1523
|
|
|
|
1524
|
|
|
} catch (Exception $e) |
1525
|
|
|
{ |
1526
|
|
|
$babBody->addError($e->getMessage()); |
1527
|
|
|
return false; |
1528
|
|
|
} |
1529
|
|
|
|
1530
|
|
|
|
1531
|
|
|
// mise a jour des profiles de rythmes de travail |
1532
|
|
|
|
1533
|
|
|
if (isset($_POST['profiles'])) { |
1534
|
|
|
require_once dirname(__FILE__).'/workschedules.php'; |
1535
|
|
|
|
1536
|
|
|
try { |
1537
|
|
|
absences_setProfiles($id_user, bab_pp('profiles')); |
1538
|
|
|
} catch (bab_SaveErrorException $e) { |
1539
|
|
|
$babBody->addError($e->getMessage()); |
1540
|
|
|
return false; |
1541
|
|
|
} |
1542
|
|
|
} |
1543
|
|
|
|
1544
|
|
|
|
1545
|
|
|
|
1546
|
|
|
if ((int) $agent->id_coll === (int) bab_rp('idcol')) { |
1547
|
|
|
// le regime n'a pas ete modifie, rediriger vers la liste des agents |
1548
|
|
|
|
1549
|
|
|
return null; |
1550
|
|
|
} |
1551
|
|
|
|
1552
|
|
|
return true; // vers la modification du regime; |
1553
|
|
|
} |
1554
|
|
|
|
1555
|
|
|
|
1556
|
|
|
|
1557
|
|
|
|
1558
|
|
|
|
1559
|
|
|
function absences_saveVacationPersonnel($userid, $idcol, $idsa, $id_sa_cet, $id_sa_recover, $emails, &$messages) |
|
|
|
|
1560
|
|
|
{ |
1561
|
|
|
global $babBody; |
1562
|
|
|
absences_setAgentInfos($userid, $idcol, $idsa, $id_sa_cet, $id_sa_recover, $emails); |
1563
|
|
|
absences_setCollectionRights($userid, $idcol); |
1564
|
|
|
|
1565
|
|
|
|
1566
|
|
|
// update user menu |
1567
|
|
|
bab_siteMap::clear($userid); |
1568
|
|
|
|
1569
|
|
|
return true; |
1570
|
|
|
} |
1571
|
|
|
|
1572
|
|
|
|
1573
|
|
|
class absences_notifyOnVacationChangeCls |
1574
|
|
|
{ |
1575
|
|
|
|
1576
|
|
|
public function __construct($quantity, $date_begin, $date_end, $msg) |
1577
|
|
|
{ |
1578
|
|
|
$this->message = $msg; |
|
|
|
|
1579
|
|
|
$this->from = absences_translate("from"); |
|
|
|
|
1580
|
|
|
$this->until = absences_translate("until"); |
|
|
|
|
1581
|
|
|
$this->quantitytxt = absences_translate("Quantity"); |
|
|
|
|
1582
|
|
|
$this->begindate = bab_strftime(bab_mktime($date_begin)); |
|
|
|
|
1583
|
|
|
$this->enddate = bab_strftime(bab_mktime($date_end)); |
|
|
|
|
1584
|
|
|
$this->quantity = $quantity; |
|
|
|
|
1585
|
|
|
} |
1586
|
|
|
} |
1587
|
|
|
|
1588
|
|
|
|
1589
|
|
|
/** |
1590
|
|
|
* Notify on vacation change |
1591
|
|
|
* @param int $idusers |
1592
|
|
|
* @param int $quantity |
1593
|
|
|
* @param string $date_begin 0000-00-00 00:00:00 |
1594
|
|
|
* @param string $date_end 0000-00-00 00:00:00 |
1595
|
|
|
* @param string $what |
1596
|
|
|
* |
1597
|
|
|
* @return bool |
1598
|
|
|
*/ |
1599
|
|
|
function absences_notifyOnVacationChange($idusers, $quantity, $date_begin, $date_end, $what) |
1600
|
|
|
{ |
1601
|
|
|
global $babBody, $BAB_SESS_USER, $BAB_SESS_EMAIL; |
1602
|
|
|
|
1603
|
|
|
if (empty($quantity) || empty($date_begin)) { |
1604
|
|
|
return false; |
1605
|
|
|
} |
1606
|
|
|
|
1607
|
|
|
|
1608
|
|
|
$cntusers = count($idusers); |
1609
|
|
|
|
1610
|
|
|
if( $cntusers > 0 ) |
1611
|
|
|
{ |
1612
|
|
|
$mail = bab_mail(); |
1613
|
|
|
if( $mail == false ) |
1614
|
|
|
return false; |
1615
|
|
|
|
1616
|
|
|
$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER); |
1617
|
|
|
switch($what) |
1618
|
|
|
{ |
1619
|
|
|
case ABSENCES_FIX_UPDATE: $msg = absences_translate("Vacation has been updated"); break; |
1620
|
|
|
case ABSENCES_FIX_DELETE: $msg = absences_translate("Vacation has been deleted"); break; |
1621
|
|
|
default: $msg = absences_translate("Vacation has been scheduled"); break; |
1622
|
|
|
} |
1623
|
|
|
|
1624
|
|
|
$mail->mailSubject($msg); |
1625
|
|
|
|
1626
|
|
|
$tempb = new absences_notifyOnVacationChangeCls($quantity, $date_begin, $date_end, $msg); |
1627
|
|
|
$message = $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newfixvacation")); |
|
|
|
|
1628
|
|
|
$mail->mailBody($message, "html"); |
1629
|
|
|
|
1630
|
|
|
$message = bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newfixvacationtxt"); |
|
|
|
|
1631
|
|
|
$mail->mailAltBody($message); |
1632
|
|
|
|
1633
|
|
|
for( $i=0; $i < $cntusers; $i++) |
1634
|
|
|
{ |
1635
|
|
|
$mail->clearTo(); |
1636
|
|
|
$mail->mailTo(bab_getUserEmail($idusers[$i]), bab_getUserName($idusers[$i])); |
1637
|
|
|
$mail->send(); |
1638
|
|
|
} |
1639
|
|
|
} |
1640
|
|
|
|
1641
|
|
|
return true; |
1642
|
|
|
} |
1643
|
|
|
|
1644
|
|
|
|
1645
|
|
|
function absences_isPlanningAccessValid() |
1646
|
|
|
{ |
1647
|
|
|
if (bab_isAccessValid('absences_public_planning_groups', 1)) { |
1648
|
|
|
return true; |
1649
|
|
|
} |
1650
|
|
|
|
1651
|
|
|
if (bab_getUserIdObjects('absences_custom_planning_groups')) { |
1652
|
|
|
return true; |
1653
|
|
|
} |
1654
|
|
|
|
1655
|
|
|
global $babDB; |
1656
|
|
|
$id_oc = absences_getVacationOption('id_chart'); |
1657
|
|
|
|
1658
|
|
|
$res = $babDB->db_query("SELECT p.id_user |
1659
|
|
|
FROM ".ABSENCES_PLANNING_TBL." p, bab_oc_entities e |
1660
|
|
|
WHERE p.id_user=".$babDB->quote($GLOBALS['BAB_SESS_USERID'])." |
1661
|
|
|
AND p.id_entity=e.id AND e.id_oc=".$babDB->quote($id_oc)); |
1662
|
|
|
return ($babDB->db_num_rows($res) > 0); |
1663
|
|
|
} |
1664
|
|
|
|
1665
|
|
|
|
1666
|
|
|
/** |
1667
|
|
|
* |
1668
|
|
|
* @param string $field |
1669
|
|
|
*/ |
1670
|
|
|
function absences_getVacationOption($field) { |
1671
|
|
|
global $babDB; |
1672
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/ocapi.php'; |
1673
|
|
|
|
1674
|
|
|
static $arr = null; |
1675
|
|
|
|
1676
|
|
|
if (null == $arr) { |
1677
|
|
|
$res = $babDB->db_query("SELECT * FROM ".ABSENCES_OPTIONS_TBL); |
1678
|
|
|
if (0 < $babDB->db_num_rows($res)) { |
1679
|
|
|
$arr = $babDB->db_fetch_assoc($res); |
1680
|
|
|
} else { |
1681
|
|
|
$arr = array( |
1682
|
|
|
|
1683
|
|
|
'chart_superiors_create_request' => 0, |
1684
|
|
|
'chart_superiors_set_rights' => 0, |
1685
|
|
|
'allow_mismatch' => 0, |
1686
|
|
|
'workperiod_recover_request' => 0, |
1687
|
|
|
'display_personal_history' => 0, |
1688
|
|
|
'modify_confirmed' => 0, |
1689
|
|
|
'modify_waiting' => 1, |
1690
|
|
|
'email_manager_ondelete' => 1, |
1691
|
|
|
'approb_email_defer' => 0, |
1692
|
|
|
'entity_planning' => 0, |
1693
|
|
|
'entity_planning_display_types' => 0, |
1694
|
|
|
'approb_alert' => 7, |
1695
|
|
|
'auto_approval' => 1, |
1696
|
|
|
'auto_confirm' => 0, |
1697
|
|
|
'sync_server' => 0, |
1698
|
|
|
'sync_url' => '', |
1699
|
|
|
'sync_nickname' => '', |
1700
|
|
|
'sync_password' => '', |
1701
|
|
|
'id_chart' => bab_OCgetPrimaryOcId(), |
1702
|
|
|
'user_add_email' => 0, |
1703
|
|
|
'end_recup' => 365, |
1704
|
|
|
'delay_recovery' => 0, |
1705
|
|
|
'maintenance' => 0, |
1706
|
|
|
'archivage_day' => 1, |
1707
|
|
|
'archivage_month' => 1, |
1708
|
|
|
// 'public_calendar' => 0, |
1709
|
|
|
'appliquant_email' => 1, |
1710
|
|
|
'organization_sync' => 0 |
1711
|
|
|
); |
1712
|
|
|
} |
1713
|
|
|
} |
1714
|
|
|
|
1715
|
|
|
return $arr[$field]; |
1716
|
|
|
} |
1717
|
|
|
|
1718
|
|
|
|
1719
|
|
|
|
1720
|
|
|
|
1721
|
|
|
|
1722
|
|
|
|
1723
|
|
|
/** |
1724
|
|
|
* Set vacation events into object |
1725
|
|
|
* |
1726
|
|
|
* @todo process queries with null dates |
1727
|
|
|
* |
1728
|
|
|
* @param bab_UserPeriods $user_periods query result set |
1729
|
|
|
* @param array $id_users |
1730
|
|
|
*/ |
1731
|
|
|
function absences_setVacationPeriods(bab_UserPeriods $user_periods, $id_users) { |
1732
|
|
|
global $babDB; |
1733
|
|
|
|
1734
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/nwdaysincl.php'; |
1735
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
1736
|
|
|
require_once dirname(__FILE__).'/entry.class.php'; |
1737
|
|
|
|
1738
|
|
|
$begin = $user_periods->begin; |
1739
|
|
|
$end = $user_periods->end; |
1740
|
|
|
|
1741
|
|
|
|
1742
|
|
|
|
1743
|
|
|
$query = " |
1744
|
|
|
SELECT |
1745
|
|
|
e.*, |
1746
|
|
|
c.calendar_backend |
1747
|
|
|
from |
1748
|
|
|
".ABSENCES_ENTRIES_TBL." e |
1749
|
|
|
LEFT JOIN ".BAB_CAL_USER_OPTIONS_TBL." c ON e.id_user=c.id_user |
1750
|
|
|
WHERE |
1751
|
|
|
e.id_user IN(".$babDB->quote($id_users).") |
1752
|
|
|
AND e.status!='N' |
1753
|
|
|
"; |
1754
|
|
|
|
1755
|
|
|
if (null !== $begin) |
1756
|
|
|
{ |
1757
|
|
|
$query .= " AND date_end > ".$babDB->quote($begin->getIsoDateTime())." "; |
1758
|
|
|
} |
1759
|
|
|
|
1760
|
|
|
if (null !== $end) |
1761
|
|
|
{ |
1762
|
|
|
$query .= " AND date_begin < ".$babDB->quote($end->getIsoDateTime())." "; |
1763
|
|
|
} |
1764
|
|
|
|
1765
|
|
|
$res = $babDB->db_query($query); |
1766
|
|
|
|
1767
|
|
|
// find begin and end |
1768
|
|
|
|
1769
|
|
|
$date_end = null; |
1770
|
|
|
$date_begin = null; |
1771
|
|
|
|
1772
|
|
|
while ($row = $babDB->db_fetch_assoc($res)) |
1773
|
|
|
{ |
1774
|
|
|
if (null === $date_end || $row['date_end'] > $date_end) |
1775
|
|
|
{ |
1776
|
|
|
$date_end = $row['date_end']; |
1777
|
|
|
} |
1778
|
|
|
|
1779
|
|
|
if (null === $date_begin || $row['date_begin'] < $date_begin) |
1780
|
|
|
{ |
1781
|
|
|
$date_begin = $row['date_begin']; |
1782
|
|
|
} |
1783
|
|
|
} |
1784
|
|
|
|
1785
|
|
|
if ($babDB->db_num_rows($res)) |
1786
|
|
|
{ |
1787
|
|
|
$babDB->db_data_seek($res, 0); |
1788
|
|
|
} |
1789
|
|
|
|
1790
|
|
|
|
1791
|
|
|
$begin = BAB_DateTime::fromIsoDateTime($date_begin); |
|
|
|
|
1792
|
|
|
$end = BAB_DateTime::fromIsoDateTime($date_end); |
|
|
|
|
1793
|
|
|
|
1794
|
|
|
$collections = array(); |
1795
|
|
|
|
1796
|
|
|
while( $row = $babDB->db_fetch_assoc($res)) |
1797
|
|
|
{ |
1798
|
|
|
$backend = bab_functionality::get('CalendarBackend/'.$row['calendar_backend']); |
1799
|
|
|
|
1800
|
|
|
if (!$backend) |
1801
|
|
|
{ |
1802
|
|
|
continue; |
1803
|
|
|
} |
1804
|
|
|
|
1805
|
|
|
|
1806
|
|
|
if (!isset($collections[$row['id_user']])) |
1807
|
|
|
{ |
1808
|
|
|
$id_user = (int) $row['id_user']; |
1809
|
|
|
$calendar = $backend->Personalcalendar($id_user); |
1810
|
|
|
|
1811
|
|
|
if ($calendar) |
1812
|
|
|
{ |
1813
|
|
|
$collections[$row['id_user']] = $backend->VacationPeriodCollection($calendar); |
1814
|
|
|
} else { |
1815
|
|
|
$collections[$row['id_user']] = null; |
1816
|
|
|
} |
1817
|
|
|
|
1818
|
|
|
} |
1819
|
|
|
|
1820
|
|
|
|
1821
|
|
|
if (isset($collections[$row['id_user']])) |
1822
|
|
|
{ |
1823
|
|
|
$entry = new absences_Entry(); |
1824
|
|
|
$entry->setRow($row); |
1825
|
|
|
|
1826
|
|
|
$p = new bab_CalendarPeriod; |
1827
|
|
|
absences_setPeriodProperties($p, $entry); |
1828
|
|
|
$collections[$row['id_user']]->addPeriod($p); |
1829
|
|
|
$p->setProperty('UID', 'VAC'.$row['id']); |
1830
|
|
|
$user_periods->addPeriod($p); |
1831
|
|
|
} |
1832
|
|
|
|
1833
|
|
|
} |
1834
|
|
|
} |
1835
|
|
|
|
1836
|
|
|
|
1837
|
|
|
|
1838
|
|
|
|
1839
|
|
|
|
1840
|
|
|
/** |
1841
|
|
|
* Search for a vacation request in ovidentia database and update the corresponding calendar period if the period is found using the user calendar backend |
1842
|
|
|
* @param int $id_request |
1843
|
|
|
* @param BAB_DateTime $begin old begin date |
1844
|
|
|
* @param BAB_DateTime $end old end date |
1845
|
|
|
* @return unknown_type |
1846
|
|
|
*/ |
1847
|
|
|
function absences_updatePeriod($id_request, BAB_DateTime $begin, BAB_DateTime $end) |
1848
|
|
|
{ |
1849
|
|
|
require_once dirname(__FILE__).'/entry.class.php'; |
1850
|
|
|
|
1851
|
|
|
$entry = absences_Entry::getById($id_request); |
1852
|
|
|
|
1853
|
|
|
if (!$entry->getRow()) { |
1854
|
|
|
throw new Exception(sprintf('Absence request with id %s does not exists', $id_request)); |
1855
|
|
|
} |
1856
|
|
|
|
1857
|
|
|
|
1858
|
|
|
$period = absences_getPeriod($id_request, $entry->id_user, $begin, $end); |
1859
|
|
|
if (null === $period) |
1860
|
|
|
{ |
1861
|
|
|
bab_debug('no period found in backend'); |
1862
|
|
|
return null; |
1863
|
|
|
} |
1864
|
|
|
|
1865
|
|
|
absences_setPeriodProperties($period, $entry); |
1866
|
|
|
|
1867
|
|
|
$period->save(); |
1868
|
|
|
} |
1869
|
|
|
|
1870
|
|
|
|
1871
|
|
|
/** |
1872
|
|
|
* Create a new vacation request into calendar backend |
1873
|
|
|
* @param $id_request |
1874
|
|
|
* @return unknown_type |
1875
|
|
|
*/ |
1876
|
|
|
function absences_createPeriod($id_request) |
1877
|
|
|
{ |
1878
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/calincl.php'; |
1879
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php'; |
1880
|
|
|
require_once dirname(__FILE__).'/entry.class.php'; |
1881
|
|
|
|
1882
|
|
|
$entry = absences_Entry::getById($id_request); |
1883
|
|
|
|
1884
|
|
|
|
1885
|
|
|
$icalendars = bab_getICalendars($entry->id_user); |
1886
|
|
|
|
1887
|
|
|
$calendar = $icalendars->getPersonalCalendar(); |
1888
|
|
|
|
1889
|
|
|
if (!$calendar) |
1890
|
|
|
{ |
1891
|
|
|
// do not create the vacation period if no personal calendar |
1892
|
|
|
return; |
1893
|
|
|
} |
1894
|
|
|
|
1895
|
|
|
$backend = $calendar->getBackend(); |
1896
|
|
|
|
1897
|
|
|
if ($backend instanceof Func_CalendarBackend_Ovi) |
1898
|
|
|
{ |
1899
|
|
|
// do not create the vacation period if the calendar backend is ovidentia because the calendar api will get the original vacation period |
1900
|
|
|
return; |
1901
|
|
|
} |
1902
|
|
|
|
1903
|
|
|
$date_begin = BAB_DateTime::fromIsoDateTime($entry->date_begin); |
1904
|
|
|
$date_end = BAB_DateTime::fromIsoDateTime($entry->date_end); |
1905
|
|
|
|
1906
|
|
|
$period = $backend->CalendarPeriod($date_begin->getTimeStamp(), $date_end->getTimeStamp()); |
1907
|
|
|
$collection = $backend->CalendarEventCollection($calendar); |
1908
|
|
|
$collection->addPeriod($period); |
1909
|
|
|
|
1910
|
|
|
absences_setPeriodProperties($period, $entry); |
1911
|
|
|
|
1912
|
|
|
$period->save(); |
1913
|
|
|
} |
1914
|
|
|
|
1915
|
|
|
|
1916
|
|
|
/** |
1917
|
|
|
* Gestion des types/couleurs sur le planning |
1918
|
|
|
* |
1919
|
|
|
*/ |
1920
|
|
|
class absences_EntryColors |
1921
|
|
|
{ |
1922
|
|
|
|
1923
|
|
|
private $stack = array(); |
1924
|
|
|
|
1925
|
|
|
|
1926
|
|
|
private $freeHalfDays = array(); |
1927
|
|
|
|
1928
|
|
|
/** |
1929
|
|
|
* |
1930
|
|
|
* @var int |
1931
|
|
|
*/ |
1932
|
|
|
private $maxHalfDays = 0; |
1933
|
|
|
|
1934
|
|
|
|
1935
|
|
|
/** |
1936
|
|
|
* Push and shift into a stack |
1937
|
|
|
* @param int $id_entry |
1938
|
|
|
* @param string $searchkey |
1939
|
|
|
* @param mixed $push |
1940
|
|
|
* |
1941
|
|
|
* $push = array( |
1942
|
|
|
* type, color |
1943
|
|
|
* ) |
1944
|
|
|
*/ |
1945
|
|
|
private function typeColorStack($id_entry, $searchkey, $push = false) { |
1946
|
|
|
|
1947
|
|
|
if (!isset($this->stack[$id_entry][$searchkey])) { |
1948
|
|
|
$this->stack[$id_entry][$searchkey] = array(); |
1949
|
|
|
} |
1950
|
|
|
|
1951
|
|
|
if (false === $push) { |
1952
|
|
|
return array_shift($this->stack[$id_entry][$searchkey]); |
1953
|
|
|
} |
1954
|
|
|
|
1955
|
|
|
array_push($this->stack[$id_entry][$searchkey], $push); |
1956
|
|
|
} |
1957
|
|
|
|
1958
|
|
|
|
1959
|
|
|
|
1960
|
|
|
/** |
1961
|
|
|
* |
1962
|
|
|
* @param int $id_entry |
1963
|
|
|
* @param int $id_user |
1964
|
|
|
* @param BAB_DateTime $date_begin Event start date |
1965
|
|
|
* @param BAB_DateTime $date_begin Event end date |
1966
|
|
|
* @param BAB_DateTime $search_begin colors start date / premier jour du mois |
1967
|
|
|
* |
1968
|
|
|
* @return array |
1969
|
|
|
*/ |
1970
|
|
|
public function get($id_entry, $id_user, BAB_DateTime $date_begin, BAB_DateTime $date_end, BAB_DateTime $search_begin) |
1971
|
|
|
{ |
1972
|
|
|
$searchkey = $search_begin->getIsoDate(); |
1973
|
|
|
|
1974
|
|
|
if (!isset($this->stack[$id_entry][$searchkey])) { |
1975
|
|
|
$this->setMaxHalfDays($date_begin, $date_end); |
1976
|
|
|
$this->getFreeHalfDays($id_user, $date_begin, $date_end); |
1977
|
|
|
$this->set($id_entry, $id_user, $date_begin, $search_begin); |
1978
|
|
|
} |
1979
|
|
|
|
1980
|
|
|
return $this->typeColorStack($id_entry, $searchkey); |
1981
|
|
|
} |
1982
|
|
|
|
1983
|
|
|
|
1984
|
|
|
|
1985
|
|
|
private function setMaxHalfDays(BAB_DateTime $date_begin, BAB_DateTime $date_end) |
1986
|
|
|
{ |
1987
|
|
|
$nbdays = BAB_DateTime::dateDiffIso($date_begin->getIsoDate(), $date_end->getIsoDate()); |
1988
|
|
|
|
1989
|
|
|
$this->maxHalfDays = (2* $nbdays); |
|
|
|
|
1990
|
|
|
} |
1991
|
|
|
|
1992
|
|
|
|
1993
|
|
|
|
1994
|
|
|
/** |
1995
|
|
|
* Set colors of entry into stack |
1996
|
|
|
* @param int $id_entry |
1997
|
|
|
* @param int $id_user |
1998
|
|
|
* @param BAB_DateTime $date_begin Debut de l'evenement |
1999
|
|
|
* @param BAB_DateTime $search_begin Debut de la zone de recherche, premier jour du mois |
2000
|
|
|
*/ |
2001
|
|
|
private function set($id_entry, $id_user, BAB_DateTime $date_begin, BAB_DateTime $search_begin) |
2002
|
|
|
{ |
2003
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/workinghoursincl.php'; |
2004
|
|
|
global $babDB; |
2005
|
|
|
|
2006
|
|
|
$req = "SELECT |
2007
|
|
|
e.quantity, |
2008
|
|
|
t.name type, |
2009
|
|
|
t.color |
2010
|
|
|
FROM |
2011
|
|
|
".ABSENCES_ENTRIES_ELEM_TBL." e, |
2012
|
|
|
".ABSENCES_RIGHTS_TBL." r, |
2013
|
|
|
".ABSENCES_TYPES_TBL." t |
2014
|
|
|
WHERE |
2015
|
|
|
e.id_entry=".$babDB->quote($id_entry)." |
2016
|
|
|
AND r.id=e.id_right |
2017
|
|
|
AND t.id=r.id_type |
2018
|
|
|
|
2019
|
|
|
ORDER BY e.date_begin"; |
2020
|
|
|
|
2021
|
|
|
$res2 = $babDB->db_query($req); |
2022
|
|
|
|
2023
|
|
|
$type_day = $date_begin->cloneDate(); |
2024
|
|
|
$type_day_end = $date_begin->cloneDate(); |
2025
|
|
|
$ignore = array(); |
2026
|
|
|
|
2027
|
|
|
|
2028
|
|
|
while ($arr = $babDB->db_fetch_assoc($res2)) |
2029
|
|
|
{ |
2030
|
|
|
|
2031
|
|
|
|
2032
|
|
|
for($d = 0; $d < $arr['quantity']; $d += 0.5) { |
2033
|
|
|
|
2034
|
|
|
// si le demi-jour est ferie ou non travaille , repousser la zone de couleur d'un demi-jour |
2035
|
|
|
while (!$this->isFree($type_day_end) && count($ignore) < $this->maxHalfDays) { |
2036
|
|
|
|
2037
|
|
|
$key = date('Ymda', $type_day_end->getTimeStamp()); |
2038
|
|
|
|
2039
|
|
|
$ignore[$key] = 1; |
2040
|
|
|
$type_day_end->add(12, BAB_DATETIME_HOUR); |
2041
|
|
|
} |
2042
|
|
|
|
2043
|
|
|
$type_day_end->add(12, BAB_DATETIME_HOUR); |
2044
|
|
|
|
2045
|
|
|
} |
2046
|
|
|
|
2047
|
|
|
|
2048
|
|
|
while ($type_day->getTimeStamp() < $type_day_end->getTimeStamp() ) { |
2049
|
|
|
|
2050
|
|
|
$key = date('Ymda', $type_day->getTimeStamp()); |
2051
|
|
|
|
2052
|
|
|
if ($type_day->getTimeStamp() >= $date_begin->getTimeStamp() |
2053
|
|
|
&& $search_begin->getTimeStamp() <= $type_day->getTimeStamp() |
2054
|
|
|
&& !isset($ignore[$key])) { |
2055
|
|
|
|
2056
|
|
|
$this->typeColorStack( |
2057
|
|
|
$id_entry, |
2058
|
|
|
$search_begin->getIsoDate(), |
2059
|
|
|
array( |
2060
|
|
|
'id_type' => $arr['type'], |
2061
|
|
|
'color' => $arr['color'] |
2062
|
|
|
) |
2063
|
|
|
); |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
|
|
$type_day->add(12, BAB_DATETIME_HOUR); |
2067
|
|
|
} |
2068
|
|
|
} |
2069
|
|
|
|
2070
|
|
|
} |
2071
|
|
|
|
2072
|
|
|
/** |
2073
|
|
|
* Indexer les jours travailles par demie-journee sur la periode de la demande |
2074
|
|
|
* |
2075
|
|
|
* @param int $id_user |
2076
|
|
|
* @param BAB_DateTime $date_begin debut demande |
2077
|
|
|
* @param BAB_DateTime $date_begin fin demande |
2078
|
|
|
*/ |
2079
|
|
|
private function getFreeHalfDays($id_user, BAB_DateTime $date_begin, BAB_DateTime $date_end) |
2080
|
|
|
{ |
2081
|
|
|
|
2082
|
|
|
$arr = absences_getHalfDaysIndex($id_user, $date_begin, $date_end, true); |
2083
|
|
|
|
2084
|
|
|
$this->freeHalfDays = $arr[2]; |
2085
|
|
|
} |
2086
|
|
|
|
2087
|
|
|
|
2088
|
|
|
/** |
2089
|
|
|
* Test if half day is free |
2090
|
|
|
* @param BAB_DateTime $date |
2091
|
|
|
* @return bool |
2092
|
|
|
*/ |
2093
|
|
|
private function isFree(BAB_DateTime $date) |
2094
|
|
|
{ |
2095
|
|
|
$key = date('Ymda', $date->getTimeStamp()); |
2096
|
|
|
|
2097
|
|
|
return isset($this->freeHalfDays[$key]); |
2098
|
|
|
} |
2099
|
|
|
} |
2100
|
|
|
|
2101
|
|
|
|
2102
|
|
|
|
2103
|
|
|
/** |
2104
|
|
|
* Update the period properties with vacation entry informations |
2105
|
|
|
* |
2106
|
|
|
* @param bab_CalendarPeriod $p |
2107
|
|
|
* @param absences_Entry $entry |
2108
|
|
|
* |
2109
|
|
|
* |
2110
|
|
|
* @return unknown_type |
2111
|
|
|
*/ |
2112
|
|
|
function absences_setPeriodProperties(bab_CalendarPeriod $p, absences_Entry $entry) |
2113
|
|
|
{ |
2114
|
|
|
global $babDB; |
2115
|
|
|
|
2116
|
|
|
$date_begin = BAB_DateTime::fromIsoDateTime($entry->date_begin); |
2117
|
|
|
$date_end = BAB_DateTime::fromIsoDateTime($entry->date_end); |
2118
|
|
|
$p->setDates($date_begin, $date_end); |
2119
|
|
|
|
2120
|
|
|
|
2121
|
|
|
list(, $category, $color) = $babDB->db_fetch_row($babDB->db_query(" |
2122
|
|
|
|
2123
|
|
|
SELECT |
2124
|
|
|
cat.id, |
2125
|
|
|
cat.name, |
2126
|
|
|
cat.bgcolor |
2127
|
|
|
FROM |
2128
|
|
|
".ABSENCES_COLLECTIONS_TBL." vct, |
2129
|
|
|
".ABSENCES_PERSONNEL_TBL." vpt, |
2130
|
|
|
".ABSENCES_ENTRIES_TBL." vet, |
2131
|
|
|
".BAB_CAL_CATEGORIES_TBL." cat |
2132
|
|
|
WHERE |
2133
|
|
|
vpt.id_coll=vct.id |
2134
|
|
|
AND vet.id_user=vpt.id_user |
2135
|
|
|
AND vet.id=".$babDB->quote($entry->id)." |
2136
|
|
|
AND cat.id = vct.id_cat |
2137
|
|
|
")); |
2138
|
|
|
|
2139
|
|
|
|
2140
|
|
|
if (!$entry->isPrevisonal()) |
2141
|
|
|
{ |
2142
|
|
|
if ('' === $entry->status) { |
2143
|
|
|
$p->setProperty('SUMMARY' , absences_translate("Waiting vacation")); |
2144
|
|
|
} else { |
2145
|
|
|
$p->setProperty('SUMMARY' , absences_translate("Vacation")); |
2146
|
|
|
} |
2147
|
|
|
} else { |
2148
|
|
|
$p->setProperty('SUMMARY' , absences_translate("Previsonal vacation")); |
2149
|
|
|
} |
2150
|
|
|
$p->setProperty('CATEGORIES' , $category); |
2151
|
|
|
$p->setProperty('X-CTO-COLOR' , $color); |
2152
|
|
|
$p->setProperty('X-CTO-VACATION' , $entry->id); |
2153
|
|
|
|
2154
|
|
|
if ($entry->comment) |
2155
|
|
|
{ |
2156
|
|
|
$p->setProperty('COMMENT' , $entry->comment); |
2157
|
|
|
} |
2158
|
|
|
|
2159
|
|
|
$description = ''; |
2160
|
|
|
$descriptiontxt = ''; |
2161
|
|
|
|
2162
|
|
|
if ('' === $entry->status) { |
2163
|
|
|
$description .= '<p>'.absences_translate("Waiting to be validated").'</p>'; |
2164
|
|
|
$descriptiontxt .= absences_translate("Waiting to be validated")."\n"; |
2165
|
|
|
} |
2166
|
|
|
|
2167
|
|
|
|
2168
|
|
|
|
2169
|
|
|
$ventilation = $entry->getElementsIterator(); |
2170
|
|
|
|
2171
|
|
|
$label = (1 === $ventilation->count()) ? absences_translate('Vacations type') : absences_translate('Vacations types'); |
2172
|
|
|
|
2173
|
|
|
$description .= '<table class="bab_cal_vacation_types" cellspacing="0">'; |
2174
|
|
|
$description .= '<thead><tr><td colspan="3">'.bab_toHtml($label).'</td></tr></thead>'; |
2175
|
|
|
$description .= '<tbody>'; |
2176
|
|
|
|
2177
|
|
|
|
2178
|
|
|
|
2179
|
|
|
|
2180
|
|
|
foreach($ventilation as $element) { |
2181
|
|
|
|
2182
|
|
|
/*@var $element absences_EntryElem */ |
2183
|
|
|
|
2184
|
|
|
$days = rtrim($element->quantity,'0.'); |
2185
|
|
|
$right = $element->getRight(); |
2186
|
|
|
$type = $right->getType(); |
2187
|
|
|
|
2188
|
|
|
$description .= sprintf( |
2189
|
|
|
'<tr><td style="background:#%s"> </td><td>%s</td><td>%s</td></tr>', |
2190
|
|
|
$type->color, |
2191
|
|
|
$days, |
2192
|
|
|
$type->name |
2193
|
|
|
); |
2194
|
|
|
|
2195
|
|
|
$descriptiontxt .= $days.' '.$type->name."\n"; |
2196
|
|
|
} |
2197
|
|
|
$description .= '</tbody></table>'; |
2198
|
|
|
|
2199
|
|
|
$data = array( |
2200
|
|
|
'id' => $entry->id, |
2201
|
|
|
'description' => $description, |
2202
|
|
|
'description_format' => 'html', |
2203
|
|
|
'id_user' => $entry->id_user, |
2204
|
|
|
'date_begin' => $entry->date_begin, // dans le planning les periodes sont decoupees par tranches de 12H, on utilise ces dates pour retrouver la periode initiale de la demande |
2205
|
|
|
'date_end' => $entry->date_end |
2206
|
|
|
); |
2207
|
|
|
|
2208
|
|
|
$p->setData($data); |
2209
|
|
|
|
2210
|
|
|
$p->setProperty('DESCRIPTION', $descriptiontxt); |
2211
|
|
|
|
2212
|
|
|
$p->setProperty('TRANSP','OPAQUE'); |
2213
|
|
|
} |
2214
|
|
|
|
2215
|
|
|
|
2216
|
|
|
|
2217
|
|
|
|
2218
|
|
|
|
2219
|
|
|
|
2220
|
|
|
|
2221
|
|
|
|
2222
|
|
|
/** |
2223
|
|
|
* Clear calendar data |
2224
|
|
|
* On non-working days changes by admin |
2225
|
|
|
* On working hours changes by admin |
2226
|
|
|
*/ |
2227
|
|
|
function absences_clearCalendars() { |
2228
|
|
|
global $babDB; |
2229
|
|
|
$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL.""); |
2230
|
|
|
} |
2231
|
|
|
|
2232
|
|
|
|
2233
|
|
|
/** |
2234
|
|
|
* Clear calendar data for user |
2235
|
|
|
*/ |
2236
|
|
|
function absences_clearUserCalendar($id_user = NULL) { |
2237
|
|
|
if (NULL === $id_user) { |
2238
|
|
|
$id_user = $GLOBALS['BAB_SESS_USERID']; |
2239
|
|
|
} |
2240
|
|
|
global $babDB; |
2241
|
|
|
$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL." WHERE id_user=".$babDB->quote($id_user)); |
2242
|
|
|
} |
2243
|
|
|
|
2244
|
|
|
|
2245
|
|
|
|
2246
|
|
|
|
2247
|
|
|
|
2248
|
|
|
|
2249
|
|
|
/** |
2250
|
|
|
* si type2 est prioritaire, return true |
2251
|
|
|
*/ |
2252
|
|
|
function absences_compare($type1, $type2, $vacation_is_free) { |
2253
|
|
|
|
2254
|
|
|
if ($vacation_is_free) { |
2255
|
|
|
|
2256
|
|
|
$order = array( |
2257
|
|
|
'bab_VacationPeriodCollection' => 1, |
2258
|
|
|
'bab_NonWorkingPeriodCollection' => 2, |
2259
|
|
|
'bab_WorkingPeriodCollection' => 3, |
2260
|
|
|
'bab_NonWorkingDaysCollection' => 6 |
2261
|
|
|
); |
2262
|
|
|
|
2263
|
|
|
} else { |
2264
|
|
|
|
2265
|
|
|
$order = array( |
2266
|
|
|
|
2267
|
|
|
'bab_NonWorkingPeriodCollection' => 1, |
2268
|
|
|
'bab_WorkingPeriodCollection' => 2, |
2269
|
|
|
'bab_VacationPeriodCollection' => 5, |
2270
|
|
|
'bab_NonWorkingDaysCollection' => 6 |
2271
|
|
|
); |
2272
|
|
|
|
2273
|
|
|
} |
2274
|
|
|
|
2275
|
|
|
|
2276
|
|
|
if (!isset($order[$type1])) |
2277
|
|
|
{ |
2278
|
|
|
throw new Exception(sprintf('The vacation calendar request has received the collection %s from a calendar backend, the backends must not return events of non requested collections', $type1)); |
2279
|
|
|
} |
2280
|
|
|
|
2281
|
|
|
if (!isset($order[$type2])) |
2282
|
|
|
{ |
2283
|
|
|
throw new Exception(sprintf('The vacation calendar request has received the collection %s from a calendar backend, the backends must not return events of non requested collections', $type2)); |
2284
|
|
|
} |
2285
|
|
|
|
2286
|
|
|
|
2287
|
|
|
if ($order[$type2] > $order[$type1]) { |
2288
|
|
|
return true; |
2289
|
|
|
} |
2290
|
|
|
|
2291
|
|
|
return false; |
2292
|
|
|
} |
2293
|
|
|
|
2294
|
|
|
function absences_is_free($collection) { |
2295
|
|
|
|
2296
|
|
|
|
2297
|
|
|
switch(true) { |
2298
|
|
|
case $collection instanceof bab_WorkingPeriodCollection: |
2299
|
|
|
return true; |
2300
|
|
|
|
2301
|
|
|
case $collection instanceof bab_NonWorkingPeriodCollection: |
2302
|
|
|
case $collection instanceof bab_VacationPeriodCollection: |
2303
|
|
|
case $collection instanceof bab_NonWorkingDaysCollection: |
2304
|
|
|
return false; |
2305
|
|
|
} |
2306
|
|
|
} |
2307
|
|
|
|
2308
|
|
|
|
2309
|
|
|
|
2310
|
|
|
|
2311
|
|
|
|
2312
|
|
|
|
2313
|
|
|
|
2314
|
|
|
/** |
2315
|
|
|
* Return arrays with periods for each half-day beetween two dates |
2316
|
|
|
* |
2317
|
|
|
* @param int $id_user |
2318
|
|
|
* @param BAB_dateTime $dateb |
2319
|
|
|
* @param BAB_dateTime $datee |
2320
|
|
|
* @param boolean $vacation_is_free |
2321
|
|
|
* @return array |
2322
|
|
|
* 0 : working periods for each half-day |
2323
|
|
|
* 1 : only the main period for each half day |
2324
|
|
|
* 2 : free-busy status for each half day |
2325
|
|
|
* 3 : periods indexed by type |
2326
|
|
|
* |
2327
|
|
|
*/ |
2328
|
|
|
function absences_getHalfDaysIndex($id_user, BAB_DateTime $dateb, BAB_DateTime $datee, $vacation_is_free = false) { |
2329
|
|
|
|
2330
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/utilit.php"; |
2331
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/workinghoursincl.php"; |
2332
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/calincl.php"; |
2333
|
|
|
|
2334
|
|
|
$obj = new bab_UserPeriods( |
2335
|
|
|
$dateb, |
2336
|
|
|
$datee |
2337
|
|
|
); |
2338
|
|
|
|
2339
|
|
|
$factory = bab_getInstance('bab_PeriodCriteriaFactory'); |
2340
|
|
|
/* @var $factory bab_PeriodCriteriaFactory */ |
2341
|
|
|
|
2342
|
|
|
$criteria = $factory->Collection( |
2343
|
|
|
array( |
2344
|
|
|
'bab_NonWorkingDaysCollection', |
2345
|
|
|
'bab_NonWorkingPeriodCollection', |
2346
|
|
|
'bab_WorkingPeriodCollection', |
2347
|
|
|
'bab_VacationPeriodCollection' |
2348
|
|
|
) |
2349
|
|
|
); |
2350
|
|
|
|
2351
|
|
|
$icalendars = bab_getICalendars($id_user); |
2352
|
|
|
|
2353
|
|
|
$calendar = $icalendars->getPersonalCalendar(); |
2354
|
|
|
|
2355
|
|
|
|
2356
|
|
|
if (!isset($calendar)) |
2357
|
|
|
{ |
2358
|
|
|
// the user personal calendar is not accessible |
2359
|
|
|
// create an instance only for vacations |
2360
|
|
|
|
2361
|
|
|
$calendar = bab_functionality::get('CalendarBackend')->PersonalCalendar($id_user); |
|
|
|
|
2362
|
|
|
} |
2363
|
|
|
|
2364
|
|
|
|
2365
|
|
|
$criteria = $criteria->_AND_($factory->Calendar($calendar)); |
2366
|
|
|
|
2367
|
|
|
$obj->createPeriods($criteria); |
2368
|
|
|
$obj->orderBoundaries(); |
2369
|
|
|
|
2370
|
|
|
// working periods for each half-day |
2371
|
|
|
$index_working = array(); |
2372
|
|
|
|
2373
|
|
|
// only the main period for each half day |
2374
|
|
|
$index_reduced = array(); |
2375
|
|
|
|
2376
|
|
|
// free-busy status for each half day |
2377
|
|
|
$is_free = array(); |
2378
|
|
|
|
2379
|
|
|
// periods indexed by type |
2380
|
|
|
$stack = array(); |
2381
|
|
|
|
2382
|
|
|
foreach($obj as $pe) { |
2383
|
|
|
|
2384
|
|
|
/*@var $pe bab_CalendarPeriod */ |
2385
|
|
|
|
2386
|
|
|
// bab_debug($pe->toHtml(), DBG_TRACE, $dateb->getIsoDateTime().' '.$datee->getIsoDateTime()); |
2387
|
|
|
|
2388
|
|
|
$group = $pe->split(12 * 3600); |
2389
|
|
|
foreach($group as $p) { |
2390
|
|
|
|
2391
|
|
|
/*@var $p bab_CalendarPeriod */ |
2392
|
|
|
if ($p->ts_begin < $datee->getTimeStamp() && $p->ts_end > $dateb->getTimeStamp()) { |
2393
|
|
|
$key = date('Ymda',$p->ts_begin); |
2394
|
|
|
$collection = $p->getCollection(); |
2395
|
|
|
$type = get_class($collection); |
2396
|
|
|
|
2397
|
|
|
$stack[$key][$type] = $p; |
2398
|
|
|
|
2399
|
|
|
if (!isset($index_reduced[$key]) || absences_compare(get_class($index_reduced[$key]->getCollection()), $type, $vacation_is_free)) { |
2400
|
|
|
|
2401
|
|
|
// overwrite reduced index if absences_compare return true |
2402
|
|
|
|
2403
|
|
|
$index_reduced[$key] = $p; |
2404
|
|
|
|
2405
|
|
|
// and reset the free-busy status with the new period |
2406
|
|
|
|
2407
|
|
|
if (absences_is_free($collection)) { |
2408
|
|
|
$is_free[$key] = 1; |
2409
|
|
|
} elseif (isset($is_free[$key])) { |
2410
|
|
|
unset($is_free[$key]); |
2411
|
|
|
} |
2412
|
|
|
} |
2413
|
|
|
|
2414
|
|
|
|
2415
|
|
|
if ($p->getCollection() instanceof bab_WorkingPeriodCollection) |
2416
|
|
|
{ |
2417
|
|
|
if (!isset($index_working[$key])) |
2418
|
|
|
{ |
2419
|
|
|
$index_working[$key] = array(); |
2420
|
|
|
} |
2421
|
|
|
|
2422
|
|
|
$index_working[$key][] = $p; |
2423
|
|
|
} |
2424
|
|
|
|
2425
|
|
|
// ajust period according to selection |
2426
|
|
|
|
2427
|
|
|
if ($p->ts_begin < $dateb->getTimeStamp()) |
2428
|
|
|
{ |
2429
|
|
|
$p->setBeginDate($dateb); |
2430
|
|
|
} |
2431
|
|
|
|
2432
|
|
|
if ($p->ts_end > $datee->getTimeStamp()) |
2433
|
|
|
{ |
2434
|
|
|
$p->setEndDate($datee); |
2435
|
|
|
} |
2436
|
|
|
} |
2437
|
|
|
} |
2438
|
|
|
} |
2439
|
|
|
|
2440
|
|
|
|
2441
|
|
|
return array($index_working, $index_reduced, $is_free, $stack); |
2442
|
|
|
} |
2443
|
|
|
|
2444
|
|
|
|
2445
|
|
|
|
2446
|
|
|
|
2447
|
|
|
function absences_group_insert($query, $exec = false) { |
2448
|
|
|
static $values = array(); |
2449
|
|
|
if ($query) { |
2450
|
|
|
$values[] = $query; |
2451
|
|
|
} |
2452
|
|
|
|
2453
|
|
|
if (300 <= count($values) || (0 < count($values) && $exec)) { |
2454
|
|
|
|
2455
|
|
|
$GLOBALS['babDB']->db_query(" |
2456
|
|
|
INSERT INTO ".ABSENCES_CALENDAR_TBL." |
2457
|
|
|
(id_user, monthkey, cal_date, ampm, period_type, id_entry, color, title) |
2458
|
|
|
VALUES |
2459
|
|
|
".implode(',',$values)." |
2460
|
|
|
"); |
2461
|
|
|
$values = array(); |
2462
|
|
|
} |
2463
|
|
|
} |
2464
|
|
|
|
2465
|
|
|
|
2466
|
|
|
|
2467
|
|
|
|
2468
|
|
|
|
2469
|
|
|
|
2470
|
|
|
|
2471
|
|
|
/** |
2472
|
|
|
* Update planning for the given user |
2473
|
|
|
* and the given period |
2474
|
|
|
* @param int $id_user |
2475
|
|
|
* @param int $year |
2476
|
|
|
* @param int $month |
2477
|
|
|
*/ |
2478
|
|
|
function absences_updateCalendar($id_user, $year, $month) { |
2479
|
|
|
|
2480
|
|
|
global $babDB; |
2481
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/workinghoursincl.php"; |
2482
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/dateTime.php"; |
2483
|
|
|
|
2484
|
|
|
|
2485
|
|
|
$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL." WHERE monthkey=".$babDB->quote($month.$year).' AND id_user='.$babDB->quote($id_user)); |
2486
|
|
|
|
2487
|
|
|
$dateb = new BAB_DateTime($year, $month, 1); |
2488
|
|
|
$datee = $dateb->cloneDate(); |
2489
|
|
|
$datee->add(1, BAB_DATETIME_MONTH); |
2490
|
|
|
|
2491
|
|
|
list(, $index_reduced, , $stack) = absences_getHalfDaysIndex($id_user, $dateb, $datee); |
2492
|
|
|
$previous = NULL; |
2493
|
|
|
|
2494
|
|
|
foreach($index_reduced as $key => $p) { |
2495
|
|
|
|
2496
|
|
|
$title = $p->getProperty('SUMMARY'); |
2497
|
|
|
$ampm = 'pm' === date('a',$p->ts_begin) ? 1 : 0; |
2498
|
|
|
$data = $p->getData(); |
2499
|
|
|
$id_entry = 0; |
2500
|
|
|
$color = ''; |
2501
|
|
|
|
2502
|
|
|
$collection = $p->getCollection(); |
2503
|
|
|
|
2504
|
|
|
switch(true) { |
2505
|
|
|
case $collection instanceof bab_WorkingPeriodCollection: |
2506
|
|
|
$type = BAB_PERIOD_WORKING; |
2507
|
|
|
break; |
2508
|
|
|
|
2509
|
|
|
case $collection instanceof bab_NonWorkingPeriodCollection: |
2510
|
|
|
$type = BAB_PERIOD_NONWORKING; |
2511
|
|
|
break; |
2512
|
|
|
|
2513
|
|
|
case $collection instanceof bab_VacationPeriodCollection: |
2514
|
|
|
$type = BAB_PERIOD_VACATION; |
2515
|
|
|
break; |
2516
|
|
|
|
2517
|
|
|
case $collection instanceof bab_NonWorkingDaysCollection: |
2518
|
|
|
$type = BAB_PERIOD_NWDAY; |
2519
|
|
|
if (version_compare(bab_getDbVersion(), '8.1.0', '<')) |
2520
|
|
|
{ |
2521
|
|
|
$title = $p->getProperty('DESCRIPTION'); |
2522
|
|
|
} |
2523
|
|
|
break; |
2524
|
|
|
|
2525
|
|
|
} |
2526
|
|
|
|
2527
|
|
|
|
2528
|
|
|
|
2529
|
|
|
|
2530
|
|
|
if ($p->getCollection() instanceof bab_VacationPeriodCollection) { |
2531
|
|
|
if (isset($stack[$key]['bab_WorkingPeriodCollection'])) { |
2532
|
|
|
$id_entry = $data['id']; |
2533
|
|
|
|
2534
|
|
|
$C = bab_getInstance('absences_EntryColors'); |
2535
|
|
|
/*@var $C absences_EntryColors */ |
2536
|
|
|
|
2537
|
|
|
$arr = $C->get($id_entry, $id_user, BAB_DateTime::fromIsoDateTime($data['date_begin']), BAB_DateTime::fromIsoDateTime($data['date_end']), $dateb); |
2538
|
|
|
$color = $arr['color']; |
2539
|
|
|
} else { |
2540
|
|
|
$type = BAB_PERIOD_NONWORKING; |
2541
|
|
|
} |
2542
|
|
|
} |
2543
|
|
|
|
2544
|
|
|
|
2545
|
|
|
$key = $id_user.$month.$year.$id_entry.$color.$type; |
|
|
|
|
2546
|
|
|
|
2547
|
|
|
if ($key !== $previous) { |
2548
|
|
|
|
2549
|
|
|
$previous = $key; |
2550
|
|
|
absences_group_insert("( |
2551
|
|
|
".$babDB->quote($id_user).", |
2552
|
|
|
".$babDB->quote($month.$year).", |
2553
|
|
|
".$babDB->quote(date('Y-m-d',$p->ts_begin)).", |
2554
|
|
|
".$babDB->quote($ampm).", |
2555
|
|
|
".$babDB->quote($type).", |
2556
|
|
|
".$babDB->quote($id_entry).", |
2557
|
|
|
".$babDB->quote($color).", |
2558
|
|
|
".$babDB->quote($title)." |
2559
|
|
|
)"); |
2560
|
|
|
|
2561
|
|
|
} |
2562
|
|
|
} |
2563
|
|
|
|
2564
|
|
|
absences_group_insert('',true); |
2565
|
|
|
} |
2566
|
|
|
|
2567
|
|
|
|
2568
|
|
|
|
2569
|
|
|
/** |
2570
|
|
|
* Date printout for periods |
2571
|
|
|
* @param int $timestamp |
2572
|
|
|
* @return string |
2573
|
|
|
*/ |
2574
|
|
|
function absences_longDate($timestamp) { |
2575
|
|
|
if (empty($timestamp)) { |
2576
|
|
|
return ''; |
2577
|
|
|
} |
2578
|
|
|
|
2579
|
|
|
return bab_longDate($timestamp, true); |
2580
|
|
|
} |
2581
|
|
|
|
2582
|
|
|
function absences_shortDate($timestamp) { |
2583
|
|
|
if (empty($timestamp)) { |
2584
|
|
|
return ''; |
2585
|
|
|
} |
2586
|
|
|
|
2587
|
|
|
return bab_shortDate($timestamp, true); |
2588
|
|
|
} |
2589
|
|
|
|
2590
|
|
|
|
2591
|
|
|
class absences_RequestDelete |
2592
|
|
|
{ |
2593
|
|
|
public static function direct(absences_Request $request, $folder) |
2594
|
|
|
{ |
2595
|
|
|
if ($folder) |
2596
|
|
|
{ |
2597
|
|
|
$allDeleted = true; |
2598
|
|
|
$I = $request->getFolderEntriesIterator(); |
|
|
|
|
2599
|
|
|
absences_notifyOnRequestChange($I, $request->id_user, true); |
2600
|
|
|
|
2601
|
|
|
foreach($I as $folder_entry) |
2602
|
|
|
{ |
2603
|
|
|
/*@var $folder_entry absences_Entry */ |
2604
|
|
|
absences_notifyManagers::send($folder_entry->id, true); |
2605
|
|
|
if (!$folder_entry->delete()) { |
2606
|
|
|
$allDeleted = false; |
2607
|
|
|
} |
2608
|
|
|
} |
2609
|
|
|
|
2610
|
|
|
|
2611
|
|
|
|
2612
|
|
|
|
2613
|
|
|
} else { |
2614
|
|
|
|
2615
|
|
|
absences_notifyManagers::send($request->id, true); |
2616
|
|
|
absences_notifyOnRequestChange(array($request), $request->id_user, true); |
2617
|
|
|
$allDeleted = $request->delete(); |
|
|
|
|
2618
|
|
|
} |
2619
|
|
|
|
2620
|
|
|
return $allDeleted; |
2621
|
|
|
} |
2622
|
|
|
|
2623
|
|
|
public static function withApproval(absences_Request $request, $folder) |
2624
|
|
|
{ |
2625
|
|
|
if ($folder) |
2626
|
|
|
{ |
2627
|
|
|
|
2628
|
|
|
$I = $request->getFolderEntriesIterator(); |
|
|
|
|
2629
|
|
|
|
2630
|
|
|
foreach($I as $folder_entry) |
2631
|
|
|
{ |
2632
|
|
|
/*@var $folder_entry absences_Entry */ |
2633
|
|
|
$folder_entry->todelete = 1; |
2634
|
|
|
$folder_entry->createApprobationInstance(); |
2635
|
|
|
} |
2636
|
|
|
|
2637
|
|
|
|
2638
|
|
|
} else { |
2639
|
|
|
|
2640
|
|
|
$request->todelete = 1; |
2641
|
|
|
$request->createApprobationInstance(); |
2642
|
|
|
} |
2643
|
|
|
|
2644
|
|
|
return true; |
2645
|
|
|
} |
2646
|
|
|
} |
2647
|
|
|
|
2648
|
|
|
|
2649
|
|
|
/** |
2650
|
|
|
* Delete vacation request |
2651
|
|
|
* notify user if vacation not elapsed |
2652
|
|
|
* delete approbation instance |
2653
|
|
|
* Update calendar |
2654
|
|
|
* @param int $id_request |
2655
|
|
|
* @param int $folder |
2656
|
|
|
* @param int $rfrom 1 if the delete request is created by a manager from back office (need to be secured) |
2657
|
|
|
* @return bool |
2658
|
|
|
*/ |
2659
|
|
|
function absences_delete_request($id_request, $folder = 0, $rfrom = 0) |
2660
|
|
|
{ |
2661
|
|
|
require_once dirname(__FILE__).'/entry.class.php'; |
2662
|
|
|
|
2663
|
|
|
$agent = absences_Agent::getCurrentUser(); |
2664
|
|
|
|
2665
|
|
|
if (!$agent->isManager()) { |
2666
|
|
|
$rfrom = 0; |
2667
|
|
|
} |
2668
|
|
|
|
2669
|
|
|
$request = absences_Entry::getById($id_request); |
2670
|
|
|
|
2671
|
|
|
if (!$request->getRow()) |
2672
|
|
|
{ |
2673
|
|
|
throw new Exception(absences_translate('This request does not exists')); |
2674
|
|
|
} |
2675
|
|
|
|
2676
|
|
|
if ('Y' === $request->status && 0 === $rfrom) { |
2677
|
|
|
return absences_RequestDelete::withApproval($request, $folder); |
2678
|
|
|
} |
2679
|
|
|
|
2680
|
|
|
return absences_RequestDelete::direct($request, $folder); |
2681
|
|
|
} |
2682
|
|
|
|
2683
|
|
|
|
2684
|
|
|
|
2685
|
|
|
/** |
2686
|
|
|
* Try to get a period from the calendar API from the request |
2687
|
|
|
* The calendar backend can contain a period duplicated into the calendarEventCollection with need to be updated or deleted |
2688
|
|
|
* This function can work without access to the personal calendar of the user |
2689
|
|
|
* |
2690
|
|
|
* @param int $id_request |
2691
|
|
|
* @param int $id_user search the period in this user personal calendar |
2692
|
|
|
* @param BAB_DateTime $begin request search begin date (should be the request begin date) |
2693
|
|
|
* @param BAB_DateTime $end request search end date (should be the request end date) |
2694
|
|
|
* |
2695
|
|
|
* @return bab_CalendarPeriod | null |
2696
|
|
|
*/ |
2697
|
|
|
function absences_getPeriod($id_request, $id_user, BAB_DateTime $begin, BAB_DateTime $end) |
2698
|
|
|
{ |
2699
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/calincl.php'; |
2700
|
|
|
|
2701
|
|
|
$icalendars = bab_getICalendars($id_user); |
2702
|
|
|
|
2703
|
|
|
$calendar = $icalendars->getPersonalCalendar(); |
2704
|
|
|
|
2705
|
|
|
if (!$calendar) |
2706
|
|
|
{ |
2707
|
|
|
return null; |
2708
|
|
|
} |
2709
|
|
|
|
2710
|
|
|
$backend = $calendar->getBackend(); |
2711
|
|
|
|
2712
|
|
|
$factory = $backend->Criteria(); |
2713
|
|
|
$criteria = $factory->Calendar($calendar); |
2714
|
|
|
$criteria = $criteria->_AND_($factory->Collection('bab_CalendarEventCollection')); |
2715
|
|
|
$criteria = $criteria->_AND_($factory->Begin($begin)); |
2716
|
|
|
$criteria = $criteria->_AND_($factory->End($end)); |
2717
|
|
|
$criteria = $criteria->_AND_($factory->Property('X-CTO-VACATION', $id_request)); |
2718
|
|
|
|
2719
|
|
|
$periods = $backend->selectPeriods($criteria); |
2720
|
|
|
|
2721
|
|
|
foreach($periods as $period) |
2722
|
|
|
{ |
2723
|
|
|
return $period; |
2724
|
|
|
} |
2725
|
|
|
|
2726
|
|
|
return null; |
2727
|
|
|
} |
2728
|
|
|
|
2729
|
|
|
|
2730
|
|
|
|
2731
|
|
|
|
2732
|
|
|
|
2733
|
|
|
|
2734
|
|
|
|
2735
|
|
View Code Duplication |
function absences_deleteVacationRequest($id, $manager_view = false) |
|
|
|
|
2736
|
|
|
{ |
2737
|
|
|
global $babBody; |
2738
|
|
|
require_once dirname(__FILE__).'/deleterequest.ui.php'; |
2739
|
|
|
|
2740
|
|
|
$babBody->setTitle(absences_translate("Delete vacation request")); |
2741
|
|
|
|
2742
|
|
|
$temp = new absences_deleteVacationRequestCls($id, $manager_view); |
2743
|
|
|
$babBody->babecho(bab_printTemplate($temp, absences_addon()->getRelativePath()."request.html", "delete_entry")); |
|
|
|
|
2744
|
|
|
} |
2745
|
|
|
|
2746
|
|
|
|
2747
|
|
|
|
2748
|
|
View Code Duplication |
function absences_deleteCetDepositRequest($id, $manager_view = false) |
|
|
|
|
2749
|
|
|
{ |
2750
|
|
|
global $babBody; |
2751
|
|
|
require_once dirname(__FILE__).'/deleterequest.ui.php'; |
2752
|
|
|
|
2753
|
|
|
$babBody->setTitle(absences_translate("Delete a time saving account deposit")); |
2754
|
|
|
|
2755
|
|
|
$temp = new absences_deleteCetDepositRequestCls($id, $manager_view); |
2756
|
|
|
$babBody->babecho(bab_printTemplate($temp, absences_addon()->getRelativePath()."request.html", "delete_cetdeposit")); |
|
|
|
|
2757
|
|
|
} |
2758
|
|
|
|
2759
|
|
|
|
2760
|
|
|
|
2761
|
|
View Code Duplication |
function absences_deleteWpRecoveryRequest($id, $manager_view = false) |
|
|
|
|
2762
|
|
|
{ |
2763
|
|
|
global $babBody; |
2764
|
|
|
require_once dirname(__FILE__).'/deleterequest.ui.php'; |
2765
|
|
|
|
2766
|
|
|
$babBody->setTitle(absences_translate("Delete a work period recover request")); |
2767
|
|
|
|
2768
|
|
|
$temp = new absences_deleteWpRecoveryRequestCls($id, $manager_view); |
2769
|
|
|
$babBody->babecho(bab_printTemplate($temp, absences_addon()->getRelativePath()."request.html", "delete_wprecovery")); |
|
|
|
|
2770
|
|
|
} |
2771
|
|
|
|
2772
|
|
|
|
2773
|
|
|
|
2774
|
|
|
|
2775
|
|
|
|
2776
|
|
|
|
2777
|
|
|
function absences_addCoManagerEntities(&$entities, $id_user) { |
2778
|
|
|
global $babDB; |
2779
|
|
|
$res = $babDB->db_query("SELECT id_entity FROM ".ABSENCES_COMANAGER_TBL." WHERE id_user=".$babDB->quote($id_user)); |
2780
|
|
|
|
2781
|
|
|
if (0 == $babDB->db_num_rows($res)) { |
2782
|
|
|
return; |
2783
|
|
|
} |
2784
|
|
|
|
2785
|
|
|
if (!isset($entities['superior'])) { |
2786
|
|
|
$entities['superior'] = array(); |
2787
|
|
|
} |
2788
|
|
|
|
2789
|
|
|
if (!function_exists('absences_is_superior')) { |
2790
|
|
|
function absences_is_superior($entities, $ide) { |
2791
|
|
|
foreach($entities['superior'] as $e) { |
2792
|
|
|
if ($ide == $e['id']) { |
2793
|
|
|
return true; |
2794
|
|
|
} |
2795
|
|
|
} |
2796
|
|
|
return false; |
2797
|
|
|
} |
2798
|
|
|
} |
2799
|
|
|
|
2800
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) { |
2801
|
|
|
$e = bab_OCGetEntity($arr['id_entity']); |
2802
|
|
|
$e['id'] = $arr['id_entity']; |
2803
|
|
|
$e['comanager'] = 1; |
2804
|
|
|
if (!absences_is_superior($entities, $arr['id_entity'])) { |
2805
|
|
|
$entities['superior'][] = $e; |
2806
|
|
|
} |
2807
|
|
|
} |
2808
|
|
|
} |
2809
|
|
|
|
2810
|
|
|
|
2811
|
|
|
|
2812
|
|
|
|
2813
|
|
|
|
2814
|
|
|
/** |
2815
|
|
|
* Get the list of available hours for a user |
2816
|
|
|
* if the id_user parameter is null, return hours list based on site parameters |
2817
|
|
|
* |
2818
|
|
|
* @param int $id_user |
2819
|
|
|
* |
2820
|
|
|
* @return array |
2821
|
|
|
*/ |
2822
|
|
|
function absences_hoursList($id_user = null) |
2823
|
|
|
{ |
2824
|
|
|
global $babDB, $babBody; |
2825
|
|
|
|
2826
|
|
|
$elapstime = null; |
2827
|
|
|
|
2828
|
|
|
if (null === $id_user) |
2829
|
|
|
{ |
2830
|
|
|
$elapstime = (int) $babBody->babsite['elapstime']; |
2831
|
|
|
} else { |
2832
|
|
|
|
2833
|
|
|
$res = $babDB->db_query("SELECT elapstime FROM bab_cal_user_options WHERE id_user=".$babDB->quote($id_user)); |
2834
|
|
|
if ($arr = $babDB->db_fetch_assoc($res)) |
2835
|
|
|
{ |
2836
|
|
|
$elapstime = (int) $arr['elapstime']; |
2837
|
|
|
} |
2838
|
|
|
} |
2839
|
|
|
|
2840
|
|
|
if (!isset($elapstime) || $elapstime === 0) |
2841
|
|
|
{ |
2842
|
|
|
$elapstime = 5; |
2843
|
|
|
} |
2844
|
|
|
|
2845
|
|
|
$list = array(); |
2846
|
|
|
$min = 0; |
2847
|
|
|
$hour = 0; |
2848
|
|
|
for ($i = 0; $i < 1440; $i += $elapstime) |
2849
|
|
|
{ |
2850
|
|
|
$min += $elapstime; |
2851
|
|
|
|
2852
|
|
|
if ($min >= 60) |
2853
|
|
|
{ |
2854
|
|
|
$hour++; |
2855
|
|
|
$min = 0; |
2856
|
|
|
} |
2857
|
|
|
|
2858
|
|
|
if (24 === $hour) |
2859
|
|
|
{ |
2860
|
|
|
break; |
2861
|
|
|
} |
2862
|
|
|
|
2863
|
|
|
$list[sprintf('%02d:%02d:00', $hour, $min)] = sprintf('%02d:%02d', $hour, $min); |
2864
|
|
|
} |
2865
|
|
|
|
2866
|
|
|
// add fixed hours |
2867
|
|
|
|
2868
|
|
|
$list['00:00:00'] = '00:00'; |
2869
|
|
|
$list['11:59:59'] = '11:59'; |
2870
|
|
|
$list['12:00:00'] = '12:00'; |
2871
|
|
|
$list['23:59:59'] = '23:59'; |
2872
|
|
|
|
2873
|
|
|
ksort($list); |
2874
|
|
|
|
2875
|
|
|
return $list; |
2876
|
|
|
|
2877
|
|
|
} |
2878
|
|
|
|
2879
|
|
|
/** |
2880
|
|
|
* Display a vacation right quantity in a text input |
2881
|
|
|
* @param float $quantity numeric |
2882
|
|
|
* @return string |
2883
|
|
|
*/ |
2884
|
|
|
function absences_editQuantity($quantity, $unit = 'H') |
2885
|
|
|
{ |
2886
|
|
|
switch($unit) |
2887
|
|
|
{ |
2888
|
|
|
case 'D': |
2889
|
|
|
$quantity = (string) round($quantity, 2); |
2890
|
|
|
break; |
2891
|
|
|
|
2892
|
|
|
case 'H': |
2893
|
|
|
$quantity = (string) round($quantity, 2); |
2894
|
|
|
break; |
2895
|
|
|
} |
2896
|
|
|
|
2897
|
|
|
if (false !== mb_strpos($quantity, '.')) |
2898
|
|
|
{ |
2899
|
|
|
$quantity = rtrim($quantity, '0'); |
2900
|
|
|
} |
2901
|
|
|
|
2902
|
|
|
$quantity = rtrim($quantity, '.'); |
2903
|
|
|
|
2904
|
|
|
if ('' === $quantity) { |
2905
|
|
|
$quantity = '0'; |
2906
|
|
|
} |
2907
|
|
|
|
2908
|
|
|
$quantity = str_replace('.', ',', $quantity); |
2909
|
|
|
|
2910
|
|
|
return $quantity; |
2911
|
|
|
} |
2912
|
|
|
|
2913
|
|
|
|
2914
|
3 |
|
|
2915
|
3 |
|
|
2916
|
3 |
|
|
2917
|
|
|
|
2918
|
|
|
|
2919
|
|
|
|
2920
|
|
|
/** |
2921
|
|
|
* Display a vacation right quantity |
2922
|
|
|
* @param string|float $quantity numeric |
2923
|
|
|
* @param string $unit D | H |
2924
|
|
|
*/ |
2925
|
|
|
function absences_quantity($quantity, $unit) |
2926
|
|
|
{ |
2927
|
|
|
|
2928
|
|
|
|
2929
|
|
|
switch($unit) { |
2930
|
|
|
case 'D': |
2931
|
|
|
$unit = absences_translate('day', 'days', floor($quantity)); |
2932
|
|
|
break; |
2933
|
|
|
case 'H': |
2934
|
|
|
$unit = absences_translate('hour', 'hours', floor($quantity)); |
2935
|
|
|
|
2936
|
|
|
// convertire en heures, minutes plustot que d'afficher des heures a virgules |
2937
|
|
|
|
2938
|
3 |
|
$minutes = round(($quantity - floor($quantity)) * 60); |
2939
|
3 |
|
if (0 != $minutes) { |
2940
|
|
|
$quantity = floor($quantity); |
2941
|
|
|
|
2942
|
|
|
if (0 == $quantity) |
2943
|
3 |
|
{ |
2944
|
|
|
return $minutes.' '.absences_translate('minutes'); |
2945
|
3 |
|
} |
2946
|
|
|
|
2947
|
|
|
return $quantity.' '.$unit.' '.$minutes.' '.absences_translate('min'); |
2948
|
|
|
} |
2949
|
3 |
|
|
2950
|
|
|
break; |
2951
|
3 |
|
} |
2952
|
|
|
|
2953
|
|
|
|
2954
|
|
|
if (false !== mb_strpos($quantity, '.')) |
2955
|
|
|
{ |
2956
|
|
|
$quantity = rtrim($quantity, '0'); |
2957
|
|
|
} |
2958
|
|
|
|
2959
|
|
|
$quantity = rtrim($quantity, '.'); |
2960
|
|
|
|
2961
|
|
|
if ('' === $quantity) { |
2962
|
|
|
$quantity = '0'; |
2963
|
|
|
} |
2964
|
|
|
|
2965
|
|
|
$quantity = str_replace('.', ',', $quantity); |
2966
|
|
|
|
2967
|
|
|
return $quantity.' '.$unit; |
2968
|
|
|
} |
2969
|
|
|
|
2970
|
|
|
|
2971
|
|
|
|
2972
|
|
|
|
2973
|
|
|
/** |
2974
|
|
|
* Display a period as a string |
2975
|
|
|
* @param string $begin ISO datetime |
2976
|
|
|
* @param string $end ISO datetime |
2977
|
|
|
*/ |
2978
|
|
|
function absences_DateTimePeriod($begin, $end, $funcname = 'bab_shortDate') |
2979
|
|
|
{ |
2980
|
|
|
$begin_day = mb_substr($begin, 0, 10); |
2981
|
|
|
$end_day = mb_substr($end, 0, 10); |
2982
|
|
|
|
2983
|
|
|
if ($begin_day === $end_day) |
2984
|
|
|
{ |
2985
|
|
|
$begin_hour = mb_substr($begin, 11, 5); |
2986
|
|
|
$end_hour = mb_substr($end, 11, 5); |
2987
|
|
|
|
2988
|
|
|
return sprintf(absences_translate('The %s from %s to %s'), $funcname(bab_mktime($begin), false), $begin_hour, $end_hour); |
2989
|
|
|
} |
2990
|
|
|
|
2991
|
|
|
return sprintf(absences_translate('From %s to %s'), $funcname(bab_mktime($begin)), $funcname(bab_mktime($end))); |
2992
|
|
|
} |
2993
|
|
|
|
2994
|
|
|
|
2995
|
|
|
|
2996
|
|
|
/** |
2997
|
|
|
* Get displayable quantity for one vacation entry |
2998
|
|
|
* @param int $id_entry |
2999
|
|
|
* @return string |
3000
|
|
|
*/ |
3001
|
|
View Code Duplication |
function absences_vacEntryQuantity($id_entry) |
|
|
|
|
3002
|
|
|
{ |
3003
|
|
|
global $babDB; |
3004
|
|
|
|
3005
|
|
|
$res = $babDB->db_query(" |
3006
|
|
|
SELECT |
3007
|
|
|
SUM(e.quantity) quantity, |
3008
|
|
|
r.quantity_unit |
3009
|
|
|
FROM |
3010
|
|
|
absences_entries_elem e, |
3011
|
|
|
absences_rights r |
3012
|
|
|
WHERE |
3013
|
|
|
e.id_entry =".$babDB->quote($id_entry)." |
3014
|
|
|
AND r.id = e.id_right |
3015
|
|
|
GROUP BY r.quantity_unit |
3016
|
|
|
ORDER BY r.quantity_unit DESC |
3017
|
|
|
" |
3018
|
|
|
); |
3019
|
|
|
|
3020
|
|
|
$list = array(); |
3021
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) |
3022
|
|
|
{ |
3023
|
|
|
$list[] = absences_quantity($arr['quantity'], $arr['quantity_unit']); |
3024
|
|
|
} |
3025
|
|
|
|
3026
|
|
|
return implode(', ', $list); |
3027
|
|
|
} |
3028
|
|
|
|
3029
|
|
|
|
3030
|
|
|
|
3031
|
|
|
|
3032
|
|
|
/** |
3033
|
|
|
* get a list of approvers with same requests to approve |
3034
|
|
|
* @param int $notified Filter by notified status, default value output the unnotified requests |
3035
|
|
|
* @return array |
3036
|
|
|
*/ |
3037
|
|
|
function absences_getRequestsApprovers($notified = 0) |
3038
|
|
|
{ |
3039
|
|
|
require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
3040
|
|
|
require_once dirname(__FILE__).'/request.class.php'; |
3041
|
|
|
|
3042
|
|
|
|
3043
|
|
|
$waitingRequests = new absences_RequestIterator; |
3044
|
|
|
if (isset($notified)) { |
3045
|
|
|
$waitingRequests->appr_notified = $notified; |
3046
|
|
|
} |
3047
|
|
|
$waitingRequests->idfai_set = true; |
3048
|
|
|
|
3049
|
|
|
$by_approver = array(); |
3050
|
|
|
|
3051
|
|
|
foreach($waitingRequests as $request) |
3052
|
|
|
{ |
3053
|
|
|
/*@var $request absences_Request */ |
3054
|
|
|
|
3055
|
|
|
$arr = bab_WFGetWaitingApproversInstance($request->idfai); |
3056
|
|
|
|
3057
|
|
|
foreach($arr as $id_approver) |
3058
|
|
|
{ |
3059
|
|
|
if (!isset($by_approver[$id_approver])) |
3060
|
|
|
{ |
3061
|
|
|
$by_approver[$id_approver] = array(); |
3062
|
|
|
} |
3063
|
|
|
|
3064
|
|
|
$by_approver[$id_approver][get_class($request).'.'.$request->id] = $request; |
3065
|
|
|
} |
3066
|
|
|
} |
3067
|
|
|
|
3068
|
|
|
// sort by similar request lists |
3069
|
|
|
$by_email = array(); |
3070
|
|
|
foreach($by_approver as $id_approver => $arr) |
3071
|
|
|
{ |
3072
|
|
|
ksort($arr); |
3073
|
|
|
$keys = array_keys($arr); |
3074
|
|
|
$mailkey = implode(',', $keys); |
3075
|
|
|
|
3076
|
|
|
if (!isset($by_email[$mailkey])) |
3077
|
|
|
{ |
3078
|
|
|
$by_email[$mailkey] = array( |
3079
|
|
|
'approvers' => array(), |
3080
|
|
|
'requests' => array() |
3081
|
|
|
); |
3082
|
|
|
} |
3083
|
|
|
|
3084
|
|
|
$by_email[$mailkey]['approvers'][$id_approver] = $id_approver; |
3085
|
|
|
$by_email[$mailkey]['requests'] += $arr; |
3086
|
|
|
} |
3087
|
|
|
|
3088
|
|
|
return $by_email; |
3089
|
|
|
} |
3090
|
|
|
|
3091
|
|
|
|
3092
|
|
|
|
3093
|
|
|
/** |
3094
|
|
|
* formulaire de recherche pour les liste des demandes gestionnaire |
3095
|
|
|
*/ |
3096
|
|
|
class absences_getRequestSearchForm |
3097
|
|
|
{ |
3098
|
|
|
public function getForm(Array $statarr = null) |
3099
|
|
|
{ |
3100
|
|
|
bab_functionality::includeOriginal('Icons'); |
|
|
|
|
3101
|
|
|
$W = bab_Widgets(); |
3102
|
|
|
$form = $W->Form(null, $W->FlowLayout()->setSpacing(1, 'em', 3,'em')); |
3103
|
|
|
$form->setSelfPageHiddenFields()->setReadOnly(); |
3104
|
|
|
|
3105
|
|
|
$form->addClass('absences-filterform'); |
3106
|
|
|
$form->addClass('widget-bordered'); |
3107
|
|
|
$form->addClass('BabLoginMenuBackground'); |
3108
|
|
|
$form->addClass('widget-centered'); |
3109
|
|
|
$form->addClass(Func_Icons::ICON_LEFT_16); |
3110
|
|
|
$form->colon(); |
3111
|
|
|
|
3112
|
|
|
$form->setCanvasOptions($form->Options()->width(97,'%')); |
|
|
|
|
3113
|
|
|
|
3114
|
|
|
if (isset($statarr)) { |
3115
|
|
|
|
3116
|
|
|
$options = array('' => '') + $statarr; |
3117
|
|
|
|
3118
|
|
|
$form->addItem( |
3119
|
|
|
$W->LabelledWidget( |
3120
|
|
|
absences_translate('Status'), |
3121
|
|
|
$W->Select() |
3122
|
|
|
->setOptions($options), |
3123
|
|
|
'idstatus' |
3124
|
|
|
) |
3125
|
|
|
); |
3126
|
|
|
} |
3127
|
|
|
|
3128
|
|
|
$form->addItem( |
3129
|
|
|
$W->LabelledWidget( |
3130
|
|
|
absences_translate('User'), |
3131
|
|
|
$W->UserPicker(), |
3132
|
|
|
'userid' |
3133
|
|
|
) |
3134
|
|
|
); |
3135
|
|
|
|
3136
|
|
|
|
3137
|
|
|
if ($org = $this->organization()) { |
3138
|
|
|
$form->addItem($org); |
3139
|
|
|
} |
3140
|
|
|
|
3141
|
|
|
$form->addItem( |
3142
|
|
|
$W->LabelledWidget( |
3143
|
|
|
absences_translate('Date'), |
3144
|
|
|
$W->PeriodPicker()->setNames('dateb', 'datee') |
3145
|
|
|
) |
3146
|
|
|
); |
3147
|
|
|
|
3148
|
|
|
$values = array( |
3149
|
|
|
'idstatus' => $this->param('idstatus'), |
3150
|
|
|
'userid' => (int) $this->param('userid'), |
3151
|
|
|
'organization' => (int) $this->param('organization'), |
3152
|
|
|
'dateb' => $this->param('dateb'), |
3153
|
|
|
'datee' => $this->param('datee'), |
3154
|
|
|
'vpos' => (int) $this->param('vpos', 0) |
3155
|
|
|
); |
3156
|
|
|
|
3157
|
|
|
$form->setValues($values); |
3158
|
|
|
$form->addItem($W->SubmitButton()->setLabel(absences_translate('Search'))); |
3159
|
|
|
|
3160
|
|
|
return $form; |
3161
|
|
|
} |
3162
|
|
|
|
3163
|
|
|
|
3164
|
|
|
/** |
3165
|
|
|
* |
3166
|
|
|
*/ |
3167
|
|
View Code Duplication |
protected function organization() |
|
|
|
|
3168
|
|
|
{ |
3169
|
|
|
require_once dirname(__FILE__).'/organization.class.php'; |
3170
|
|
|
|
3171
|
|
|
$W = bab_Widgets(); |
3172
|
|
|
$select = $W->Select(); |
3173
|
|
|
$select->addOption('', ''); |
3174
|
|
|
|
3175
|
|
|
$collections = new absences_OrganizationIterator(); |
3176
|
|
|
|
3177
|
|
|
if (0 === $collections->count()) { |
3178
|
|
|
return null; |
3179
|
|
|
} |
3180
|
|
|
|
3181
|
|
|
|
3182
|
|
|
foreach($collections as $collection) { |
3183
|
|
|
$select->addOption($collection->id, $collection->name); |
3184
|
|
|
} |
3185
|
|
|
|
3186
|
|
|
return $W->LabelledWidget( |
3187
|
|
|
absences_translate('Organization'), |
3188
|
|
|
$select, |
3189
|
|
|
'organization' |
3190
|
|
|
); |
3191
|
|
|
|
3192
|
|
|
} |
3193
|
|
|
|
3194
|
|
|
|
3195
|
|
|
|
3196
|
|
|
public function getHtmlForm(Array $statarr = null) |
3197
|
|
|
{ |
3198
|
|
|
$W = bab_Widgets(); |
3199
|
|
|
$form = $this->getForm($statarr); |
3200
|
|
|
|
3201
|
|
|
return $form->display($W->HtmlCanvas()); |
3202
|
|
|
} |
3203
|
|
|
|
3204
|
|
|
|
3205
|
|
View Code Duplication |
public function param($name, $default = '') |
|
|
|
|
3206
|
|
|
{ |
3207
|
|
|
if (isset($_REQUEST[$name])) |
3208
|
|
|
{ |
3209
|
|
|
$_SESSION['babVacation'][$name] = $_REQUEST[$name]; |
3210
|
|
|
return $_REQUEST[$name]; |
3211
|
|
|
} |
3212
|
|
|
|
3213
|
|
|
if (isset($_SESSION['babVacation'][$name])) |
3214
|
|
|
{ |
3215
|
|
|
return $_SESSION['babVacation'][$name]; |
3216
|
|
|
} |
3217
|
|
|
|
3218
|
|
|
return $default; |
3219
|
10 |
|
} |
3220
|
10 |
|
} |
3221
|
|
|
|
3222
|
10 |
|
|
3223
|
10 |
|
|
3224
|
|
|
/** |
3225
|
10 |
|
* Compare 2 vacation right quantities |
3226
|
|
|
* Soit un float php soit une chaine de mysql float, pour les saisie utilisateur remplacer , par . avant d'appeller la fonction |
3227
|
|
|
* |
3228
|
|
|
* @param float | string $qt1 |
3229
|
|
|
* @param float | string $qt2 |
3230
|
|
|
* |
3231
|
|
|
* @return bool |
3232
|
|
|
*/ |
3233
|
|
|
function absences_cq($qt1, $qt2) |
3234
|
|
|
{ |
3235
|
|
|
$qt1 = (float) $qt1; |
3236
|
|
|
$qt2 = (float) $qt2; |
3237
|
|
|
|
3238
|
|
|
$v1 = (int) round(100*$qt1); |
3239
|
|
|
$v2 = (int) round(100*$qt2); |
3240
|
|
|
|
3241
|
|
|
return ($v1 === $v2); |
3242
|
|
|
} |
3243
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.