Completed
Push — master ( a182e4...7f1093 )
by Paul
04:26
created

vacincl.php ➔ absences_updateUserColl()   F

Complexity

Conditions 15
Paths 649

Size

Total Lines 118
Code Lines 54

Duplication

Lines 13
Ratio 11.02 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 15
eloc 54
c 1
b 1
f 0
nc 649
nop 0
dl 13
loc 118
rs 2.4166
ccs 0
cts 73
cp 0
crap 240

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
59
	{
60
		global $babDB;
61
		$this->message = $msg;
0 ignored issues
show
Bug introduced by
The property message does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
62
		$this->fromuser = absences_translate("User");
0 ignored issues
show
Bug introduced by
The property fromuser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
		$this->from = absences_translate("from");
0 ignored issues
show
Bug introduced by
The property from does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
64
		$this->until = absences_translate("until");
0 ignored issues
show
Bug introduced by
The property until does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
65
		$this->quantitytxt = absences_translate("Quantity");
0 ignored issues
show
Bug introduced by
The property quantitytxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
		$this->commenttxt = absences_translate("Comment");
0 ignored issues
show
Bug introduced by
The property commenttxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
67
		$this->username = bab_toHtml($entry->getUserName());
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
68
		$this->begindate = bab_longDate(bab_mktime($entry->date_begin));
0 ignored issues
show
Bug introduced by
The property begindate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
		$this->enddate = bab_longDate(bab_mktime($entry->date_end));
0 ignored issues
show
Bug introduced by
The property enddate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
		$this->comment = bab_toHtml($entry->comment);
0 ignored issues
show
Bug introduced by
The property comment does not seem to exist. Did you mean commenttxt?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
71
		$this->quantity = bab_toHtml(absences_vacEntryQuantity($entry->id));
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantitytxt?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
72
	}
73
}
74
75
76
77
78
/**
79
 * Notifier le demandeur si la demande de conges est modifiee ou supprime
80
 * @param array | Iterator 	$entries
81
 * @param int				$id_user		Recipient
82
 * @param bool 	$delete
83
 */
84
function absences_notifyOnRequestChange($entries, $id_user, $delete = false)
85
{
86
	global $babBody, $babDB, $BAB_SESS_USER, $BAB_SESS_EMAIL;
87
88
89
	$mail = bab_mail();
90
	if( $mail == false )
91
		return;
92
93
	$mail->mailTo(bab_getUserEmail($id_user), bab_getUserName($id_user));
94
95
	$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER);
96
97
	$msg = $delete ? absences_translate("Vacation request has been deleted") : absences_translate("Vacation request has been modified");
98
	$mail->mailSubject($msg);
99
100
	$message = '';
101
	$messagetxt = '';
102
103 View Code Duplication
	foreach($entries as $entry)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
	{
105
		$tempb = new absences_notifyOnRequestChangeCls($entry, $msg);
106
		$message .= $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newvacation"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
107
		$messagetxt .= bab_printTemplate($tempb,  absences_addon()->getRelativePath()."mailinfo.html", "newvacationtxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
108
	}
109
110
	$mail->mailBody($message, "html");
111
	$mail->mailAltBody($messagetxt);
112
113
	$mail->send();
114
}
115
116
117
/**
118
 * Notification for the manager when a request is deleted/modified
119
 *
120
 *
121
 */
122
class absences_notifyManagers
123
{
124
	private $res;
125
126
	public function __construct(Array $row, $msg)
127
	{
128
		global $babDB;
129
130
131
		$this->message = $msg;
0 ignored issues
show
Bug introduced by
The property message does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
132
		$this->fromuser = absences_translate("User");
0 ignored issues
show
Bug introduced by
The property fromuser does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
133
		$this->from = absences_translate("from");
0 ignored issues
show
Bug introduced by
The property from does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
134
		$this->until = absences_translate("until");
0 ignored issues
show
Bug introduced by
The property until does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
135
		$this->username = bab_toHtml(bab_getUserName($row['id_user']));
0 ignored issues
show
Bug introduced by
The property username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
136
		$this->begindate = bab_longDate(bab_mktime($row['date_begin']));
0 ignored issues
show
Bug introduced by
The property begindate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
137
		$this->enddate = bab_longDate(bab_mktime($row['date_end']));
0 ignored issues
show
Bug introduced by
The property enddate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
138
		$this->res = $babDB->db_query("select
139
				r.description,
140
				e.quantity,
141
				r.quantity_unit,
142
				rg.name rgroup_name
143
				from
144
				absences_entries_elem e,
145
				absences_rights r
146
				LEFT JOIN absences_rgroup rg ON rg.id=r.id_rgroup
147
				where
148
				e.id_right=r.id
149
				AND e.id_entry =".$babDB->quote($row['id'])
150
		);
151
		$this->comment = bab_toHtml($row['comment']);
0 ignored issues
show
Bug introduced by
The property comment does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
152
	}
153
154
155
	public function getnextelem()
156
	{
157
		global $babDB;
158
159
		if ($arr = $babDB->db_fetch_assoc($this->res))
160
		{
161
			$this->description = bab_toHtml($arr['description']);
0 ignored issues
show
Bug introduced by
The property description does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
162
			$this->descriptiontxt = $arr['description'];
0 ignored issues
show
Bug introduced by
The property descriptiontxt does not seem to exist. Did you mean description?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
163
			$this->quantity = bab_toHtml(absences_quantity($arr['quantity'], $arr['quantity_unit']));
0 ignored issues
show
Bug introduced by
The property quantity does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
164
			$this->rgroup_name = bab_toHtml($arr['rgroup_name']);
0 ignored issues
show
Bug introduced by
The property rgroup_name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
165
			return true;
166
		}
167
168
		return false;
169
	}
170
171
172
	public static function send($id, $delete = false)
173
	{
174
175
		$mail = bab_mail();
176
		if( $mail == false )
177
		{
178
			return;
179
		}
180
181
		$notify = (bool) absences_getVacationOption('email_manager_ondelete');
182
		if (!$notify)
183
		{
184
			return;
185
		}
186
187
188
		global $babDB, $BAB_SESS_EMAIL, $BAB_SESS_USER;
189
190
191
		$row = $babDB->db_fetch_array($babDB->db_query("select * from ".ABSENCES_ENTRIES_TBL." where id='".$babDB->db_escape_string($id)."'"));
192
193
		if (!$row)
194
		{
195
			return;
196
		}
197
198
		$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER);
199
200
		require_once $GLOBALS['babInstallPath'].'admin/acl.php';
201
		$managers = aclGetAccessUsers('absences_managers_groups', 1);
202
		foreach ($managers as $m)
203
		{
204
			$mail->mailTo($m['email'], $m['name']);
205
		}
206
207
		$msg = $delete ? absences_translate("Vacation request has been deleted") : absences_translate("Vacation request has been modified");
208
		$mail->mailSubject($msg);
209
210
		$tempb = new absences_notifyManagers($row, $msg);
211
		$message = $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "vacmanager"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
212
		$mail->mailBody($message, "html");
213
214
		$message = bab_printTemplate($tempb,"mailinfo.html",  absences_addon()->getRelativePath()."vacmanagertxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
215
		$mail->mailAltBody($message);
216
217
		$mail->send();
218
	}
219
}
220
221
222
223
224
225
226
227
228
229
230
/**
231
 * Get list of right for a user
232
 *
233
 * @param	string|false	$begin		ISO datetime
234
 * @param	string|false	$end		ISO datetime
235
 * @param	int|false		$id_user
236
 * @param	1|0				$rfrom		test active flag on right if user is not manager
0 ignored issues
show
Documentation introduced by
The doc-type 1|0 could not be parsed: Unknown type name "1" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
237
 *
238
 * @return array
239
 */
240
function absences_getRightsOnPeriod($begin = false, $end = false, $id_user = false, $rfrom = 0)
241
{
242
	require_once dirname(__FILE__).'/agent_right.class.php';
243
	require_once dirname(__FILE__).'/agent.class.php';
244
245
	$return = array();
246
	$begin = $begin ? bab_mktime( $begin ) : $begin;
247
	$end = $end ? bab_mktime( $end ) : $end;
248
249
250
	if (!$id_user)  {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id_user of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
251
		$id_user = $GLOBALS['BAB_SESS_USERID'];
252
253
	}
254
255
	$agent = absences_Agent::getFromIdUser($id_user);
256
257
	$res = new absences_AgentRightUserIterator();
258
	$res->setAgent($agent);
259
260
	if( $rfrom == 1 )
261
	{
262
		$acclevel = absences_vacationsAccess();
263
		if( isset($acclevel['manager']) && $acclevel['manager'])
264
		{
265
			$res->showInactive();
266
		}
267
	}
268
269
	if ($begin && $end)
270
	{
271
		$res->setRequestPeriod($begin, $end);
272
	}
273
274
275
276
	foreach ($res as $agentRight )
277
	{
278
279
		/*@var $agentRight absences_AgentRight */
280
281
282
		$right = $agentRight->getRight();
283
284
285
		$return[$right->id] = array(
286
				'id'					=> $right->id,
287
				'date_begin'			=> $right->date_begin,
288
				'date_end'				=> $right->date_end,
289
		        'date_begin_valid'      => $right->date_begin_valid, // disponibilite en fonction de la date de saisie
290
		        'date_end_valid'        => $right->date_end_valid,
291
				'quantity'				=> $right->quantity,
292
				'quantity_unit'			=> $right->quantity_unit,
293
				'description'			=> $right->description,
294
				'cbalance'				=> $right->cbalance,
295
				'quantity_available'	=> $agentRight->getAvailableQuantity(),
296
				'used'					=> $agentRight->getConfirmedQuantity(),
297
				'waiting'				=> $agentRight->getWaitingQuantity(),
298
				'no_distribution'		=> $right->no_distribution,
299
				'id_rgroup'				=> $right->id_rgroup,
300
				'rgroup'				=> $right->getRgroupLabel(),
301
				'agentRight'			=> $agentRight,
302
				'sortkey'				=> $right->id_rgroup > 0 ? $right->getRgroupSortkey() : $right->getSortKey()
303
		);
304
	}
305
306
307
	return $return;
308
}
309
310
/**
311
 * Rights list for on user, grouped by right groups
312
 * @param int $id_user
313
 * @param int $rfrom
314
 */
315
function absences_getRightsByGroupOnPeriod($id_user, $rfrom = 0) {
316
317
	require_once dirname(__FILE__).'/agent_right.class.php';
318
	require_once dirname(__FILE__).'/agent.class.php';
319
320
	if (!$id_user)  {
321
		$id_user = $GLOBALS['BAB_SESS_USERID'];
322
	}
323
324
	$agent = absences_Agent::getFromIdUser($id_user);
325
326
	// creer les droits de report eventuels avant d'afficher la liste des droits
327
	$agent->createReports();
328
329
	$res = $agent->getAgentRightUserIterator();
330
331
	if( $rfrom == 1 )
332
	{
333
		$current_Agent = absences_Agent::getCurrentUser();
334
		if($current_Agent->isManager())
335
		{
336
			$res->showInactive();
337
		}
338
	}
339
340
	$rights = array();
341
	foreach($res as $agentRight) {
342
343
		/*@var $agentRight absences_AgentRight */
344
345
		$right = $agentRight->getRight();
346
347
348
		if (empty($right->id_rgroup) || null === $right->getRgroupLabel()) {
349
			$id				= 'r'.$right->id;
350
			$description	= $right->description;
351
			$type 			= $right->getType();
352
			$sortkey		= (int) $right->sortkey;
353
		} else {
354
			$id 			= 'g'.$right->id_rgroup;
355
			$description	= $right->getRgroupLabel();
356
			$type 			= null;
357
			$sortkey		= $right->getRgroupSortkey();
358
		}
359
360
		if (isset($rights[$id])) {
361
			$quantity			= $rights[$id]['quantity'] + $right->quantity;
362
			$quantity_available	= $rights[$id]['quantity_available'] + $agentRight->getAvailableQuantity();
363
			$used				= $rights[$id]['used'] + $agentRight->getConfirmedQuantity();
364
			$waiting			= $rights[$id]['waiting'] + $agentRight->getWaitingQuantity();
365
			$previsional        = $rights[$id]['previsional'] + $agentRight->getPrevisionalQuantity();
366
		} else {
367
			$quantity			= $right->quantity;
368
			$quantity_available	= $agentRight->getAvailableQuantity();
369
			$used				= $agentRight->getConfirmedQuantity();
370
			$waiting			= $agentRight->getWaitingQuantity();
371
			$previsional        = $agentRight->getPrevisionalQuantity();
372
		}
373
374
		$rights[$id] = array(
375
				'description'			=> $description,
376
				'quantity'				=> $quantity,
377
				'quantity_unit'			=> $right->quantity_unit,
378
				'quantity_available'	=> $quantity_available,
379
				'used'					=> $used,
380
				'waiting'				=> $waiting,
381
		        'previsional'           => $previsional,
382
				'type'					=> $type,
383
				'sortkey'				=> $sortkey
384
		);
385
	}
386
387
	bab_Sort::asort($rights, 'sortkey');
388
389
	return $rights;
390
}
391
392
393
394
395
class absences_Paginate
396
{
397
	/**
398
	 *
399
	 * @var int
400
	 */
401
	public $pos;
402
403
	public $topurl 		= "";
404
	public $bottomurl 	= "";
405
	public $nexturl 	= "";
406
	public $prevurl 	= "";
407
408
	public $t_position 	= '';
409
	
410
	public $display_pagination = false;
411
412
413
	protected function paginate($total, $max)
414
	{
415
		$this->t_first_page = absences_translate('First page');
0 ignored issues
show
Bug introduced by
The property t_first_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
416
		$this->t_previous_page = absences_translate('Previous page');
0 ignored issues
show
Bug introduced by
The property t_previous_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
417
		$this->t_next_page = absences_translate('Next page');
0 ignored issues
show
Bug introduced by
The property t_next_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
418
		$this->t_last_page = absences_translate('Last page');
0 ignored issues
show
Bug introduced by
The property t_last_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
419
420
421
		$this->pos = (int) bab_rp('pos', 0);
422
423
		if( $total > $max )
424
		{
425
		    $this->display_pagination = true;
426
			require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
427
				
428
			$tmpurl = bab_url::get_request_gp();
429
430
			$page_number = 1 + ($this->pos / $max);
431
			$page_total = 1 + ($total / $max);
432
			$this->t_position = sprintf(absences_translate("Page %d/%d"), $page_number,$page_total);
433
434
			if( $this->pos > 0)
435
			{
436
				$tmpurl->pos = 0;
437
				$this->topurl = bab_toHtml($tmpurl->toString());
438
			}
439
440
			$next = $this->pos - $max;
441
			if( $next >= 0)
442
			{
443
				$tmpurl->pos = $next;
444
				$this->prevurl = bab_toHtml($tmpurl->toString());
445
			}
446
447
			$next = $this->pos + $max;
448
			if( $next < $total)
449
			{
450
				$tmpurl->pos = $next;
451
				$this->nexturl =  bab_toHtml($tmpurl->toString());
452
453
				if( $next + $max < $total)
454
				{
455
					$bottom = $total - $max;
456
				}
457
				else
458
				{
459
					$bottom = $next;
460
				}
461
462
				$tmpurl->pos = $bottom;
463
				$this->bottomurl =  bab_toHtml($tmpurl->toString());
464
			}
465
		}
466
467
	}
468
}
469
470
471
472
473
474
abstract class absences_MovementList extends absences_Paginate
475
{
476
    const MAX = 20;
477
478
    public $altbg = true;
479
480
    public $t_date;
481
    public $date;
482
483
    public $t_author;
484
    public $author;
485
486
    public $t_message;
487
    public $message;
488
489
    public $t_comment;
490
    public $comment;
491
492
    protected $res;
493
494
    public function __construct()
495
    {
496
        $this->t_date = absences_translate('Date');
497
        $this->t_author = absences_translate('Author');
498
        $this->t_request = absences_translate('Object');
0 ignored issues
show
Bug introduced by
The property t_request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
499
        $this->t_message = absences_translate('Message');
500
        $this->t_comment = absences_translate('Regularization or approval comment by the author');
501
502
        bab_functionality::includeOriginal('Icons');
503
    }
504
505 View Code Duplication
    public function getnext()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
506
    {
507
        if (($this->res->key() - $this->pos) >= self::MAX)
508
        {
509
            return false;
510
        }
511
512
        if ($this->res->valid())
513
        {
514
            $W = bab_Widgets();
515
            $movement = $this->res->current();
516
            /*@var $movement absences_Movement */
517
             
518
            $this->altbg = !$this->altbg;
519
520
            $this->author = bab_toHtml(bab_getUserName($movement->id_author));
521
            $this->date = bab_toHtml(bab_shortDate(bab_mktime($movement->createdOn)));
522
            if ($request = $movement->getRequest())
523
            {
524
                $this->request = $request->getManagerFrame()->addClass(Func_Icons::ICON_LEFT_16)->display($W->HtmlCanvas());
0 ignored issues
show
Bug introduced by
The property request does not seem to exist. Did you mean t_request?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
525
            } else {
526
                $this->request = '';
0 ignored issues
show
Bug introduced by
The property request does not seem to exist. Did you mean t_request?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
527
            }
528
            $this->message = bab_toHtml($movement->message);
529
            $this->comment = bab_toHtml($movement->comment);
530
             
531
            $this->res->next();
532
            return true;
533
        }
534
535
        return false;
536
    }
537
538 View Code Duplication
    public function getHtml()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
539
    {
540
        $babBody = bab_getInstance('babBody');
541
542
        if ($this->res->count() === 0)
543
        {
544
            $babBody->addError(absences_translate('There are no records yet'));
545
            return '';
546
        }
547
548
        return bab_printTemplate($this, absences_addon()->getRelativePath()."agent.html", "movement");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
549
    }
550
}
551
552
553
554
555
556
class absences_listVacationRequestsCls extends absences_Paginate
557
{
558
	public $altbg = true;
559
	public $cardframe;
560
561
	/**
562
	 *
563
	 * @var int
564
	 */
565
	public $folder;
566
567
	/**
568
	 *
569
	 * @var absences_EntryIterator
570
	 */
571
	private $folderIterator;
572
573
	/**
574
	 * @var array
575
	 */
576
	private $users;
577
578
	public $res;
579
	public $total;
580
581
	/**
582
	 * 1 si les demandes sont modifiee par une autre personne que l'auteur
583
	 * @var int
584
	 */
585
	public $rfrom = 0;
586
587
	/**
588
	 * Entitee de l'organigramme
589
	 * @var int
590
	 */
591
	public $ide = null;
592
593
594
	public function __construct($id_user, $display_username)
595
	{
596
		require_once dirname(__FILE__).'/request.class.php';
597
598
599
		$this->uncheckall = absences_translate("Uncheck all");
0 ignored issues
show
Bug introduced by
The property uncheckall does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
600
		$this->checkall = absences_translate("Check all");
0 ignored issues
show
Bug introduced by
The property checkall does not seem to exist. Did you mean uncheckall?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
601
		$this->nametxt = absences_translate("Fullname");
0 ignored issues
show
Bug introduced by
The property nametxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
602
		$this->begindatetxt = absences_translate("Begin date");
0 ignored issues
show
Bug introduced by
The property begindatetxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
603
		$this->enddatetxt = absences_translate("End date");
0 ignored issues
show
Bug introduced by
The property enddatetxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
604
		$this->quantitytxt = absences_translate("Quantity");
0 ignored issues
show
Bug introduced by
The property quantitytxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
605
		$this->statustxt = absences_translate("Status");
0 ignored issues
show
Bug introduced by
The property statustxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
606
		$this->calendar = absences_translate("My planning");
0 ignored issues
show
Bug introduced by
The property calendar does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
607
		$this->t_entity_planning = absences_translate("Department planning");
0 ignored issues
show
Bug introduced by
The property t_entity_planning does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
608
		$this->myrights = absences_translate("My rights");
0 ignored issues
show
Bug introduced by
The property myrights does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
609
		$this->t_edit = absences_translate("Modification");
0 ignored issues
show
Bug introduced by
The property t_edit does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
610
		$this->t_submit_previsional = absences_translate("Submit for approval");
0 ignored issues
show
Bug introduced by
The property t_submit_previsional does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
611
612
		$this->t_first_page = absences_translate("First page");
0 ignored issues
show
Bug introduced by
The property t_first_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
613
		$this->t_previous_page = absences_translate("Previous page");
0 ignored issues
show
Bug introduced by
The property t_previous_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
614
		$this->t_next_page = absences_translate("Next page");
0 ignored issues
show
Bug introduced by
The property t_next_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
615
		$this->t_last_page = absences_translate("Last page");
0 ignored issues
show
Bug introduced by
The property t_last_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
616
617
		$this->details = absences_translate("View details");
0 ignored issues
show
Bug introduced by
The property details does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
618
		$this->t_delete = absences_translate("Delete");
0 ignored issues
show
Bug introduced by
The property t_delete does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
619
620
		$this->display_username = $display_username;
0 ignored issues
show
Bug introduced by
The property display_username does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
621
622
623
624
		if (!is_array($id_user))
625
			$this->users = array($id_user);
626
		else
627
			$this->users = $id_user;
628
629
		$this->calurl = bab_toHtml(absences_addon()->getUrl()."planning&idx=cal&idu=".implode(',', $this->users)."&popup=1");
0 ignored issues
show
Bug introduced by
The property calurl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
630
		$this->personal = ($id_user == bab_getUserId());
0 ignored issues
show
Bug introduced by
The property personal does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
631
632
		if ($this->personal)
633
		{
634
			$agent = absences_Agent::getCurrentUser();
635
			$entity = $agent->getMainEntity();
636
			$this->entity_planning = $agent->canViewMainEntityPlanning();
0 ignored issues
show
Bug introduced by
The property entity_planning does not seem to exist. Did you mean t_entity_planning?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
637
			$this->entity_calurl = bab_toHtml(absences_addon()->getUrl()."planning&idx=entity_cal&ide=".$entity['id']."&popup=1&emptylines=1");
0 ignored issues
show
Bug introduced by
The property entity_calurl does not seem to exist. Did you mean calurl?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
638
		}
639
640
		$this->myrightsurl = bab_toHtml(absences_addon()->getUrl()."vacuser&idx=myrights");
0 ignored issues
show
Bug introduced by
The property myrightsurl does not seem to exist. Did you mean myrights?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
641
642
643
		$this->res = new absences_RequestIterator($this->users);
644
		$this->res->one_per_folder = true;
645
		$this->total = $this->res->count();
646
647
		$this->paginate($this->total, ABSENCES_MAX_REQUESTS_LIST);
648
649
		$this->res->rewind();
650
		$this->res->seek($this->pos);
651
	}
652
653
654
	public function getnext()
655
	{
656
657
		if (($this->res->key() - $this->pos) >= ABSENCES_MAX_REQUESTS_LIST)
658
		{
659
			return false;
660
		}
661
662
663
		if ($this->res->valid())
664
		{
665
			$this->altbg = !$this->altbg;
666
			$request = $this->res->current();
667
			if (isset($request->folder) && $request->folder > 0)
0 ignored issues
show
Documentation introduced by
The property folder does not exist on object<absences_Request>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
668
			{
669
				$this->folder = $request->folder;
0 ignored issues
show
Documentation introduced by
The property folder does not exist on object<absences_Request>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
670
				$this->folderIterator = new absences_EntryIterator;
671
				$this->folderIterator->orderby = 'date_begin ASC';
672
				$this->folderIterator->folder = $this->folder;
673
				$this->folderIterator->id_entry_folder = $request->id;
674
				$this->folderIterator->users = $this->users;
675
			} else {
676
				$this->folder = null;
677
				$this->folderIterator = null;
678
			}
679
				
680
			$this->cardframe = $request->getCardFrame($this->display_username, $this->rfrom, $this->ide)->display(bab_Widgets()->HtmlCanvas());
681
682
			$this->res->next();
683
			return true;
684
		}
685
		return false;
686
	}
687
688
689
690
	public function getnextfolded()
691
	{
692
		if (isset($this->folderIterator) && $this->folderIterator->valid())
693
		{
694
			$request = $this->folderIterator->current();
695
			$this->cardframe = $request->getCardFrame($this->display_username, $this->rfrom, $this->ide)->display(bab_Widgets()->HtmlCanvas());
696
			$this->folderIterator->next();
697
			return true;
698
		}
699
700
		return false;
701
	}
702
}
703
704
705
/**
706
 * Liste des demandes
707
 *
708
 * @param array | int 	$id_user
709
 * @param bool 			$display_username
710
 * @param int			$rfrom				si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue
711
 * @param int			$ide				id entite de l'organigramme >0 si gestionnaire delegue seulement
712
 */
713
function absences_listVacationRequests($id_user, $display_username = false, $rfrom = 0, $ide = null)
714
{
715
	$babBody = bab_getInstance('babBody');
716
	/*@var $babBody babBody */
717
718
	if (empty($id_user)) {
719
		$babBody->msgerror = absences_translate("ERROR: No members");
720
		return;
721
	}
722
723
	$temp = new absences_listVacationRequestsCls($id_user, $display_username);
724
	$temp->rfrom = $rfrom;
725
	$temp->ide = $ide;
726
727
	if (0 === $temp->total)
728
	{
729
		$babBody->addMessage(absences_translate('You have no ongoing requests'));
730
	}
731
732
733
	$babBody->addStyleSheet(absences_addon()->getRelativePath().'vacation.css');
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
734
	$babBody->babecho(bab_printTemplate($temp,  absences_addon()->getRelativePath()."vacuser.html", "vrequestslist"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
735
}
736
737
738
739
740
741
742
/**
743
 *
744
 * @param int $id		ID user
745
 */
746
function absences_listRightsByUser($id)
747
{
748
	global $babBody;
749
	require_once dirname(__FILE__).'/agent.ui.php';
750
751
	$temp = new absences_AgentRightsList($id);
752
	$html = bab_printTemplate($temp,  absences_addon()->getRelativePath()."vacadm.html", "rlistbyuser");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
753
	
754
	if (1 === (int) bab_rp('popup', 0))
755
	{
756
	    $babBody->babPopup($html);
757
	} else {
758
	    $babBody->babEcho($html);
759
	}
760
}
761
762
763
764
765
766
767
768
769
770
771
772
/**
773
 * Mise a jour de la liste des droits d'un utilisateur
774
 *
775
 * @param	int		$userid
776
 * @param	array	$quantity
777
 *
778
 * @return 	boolean
779
 */
780
function absences_updateVacationRightByUser($userid, $quantity, $comment)
781
{
782
	global $babDB;
783
	require_once dirname(__FILE__).'/changes.class.php';
784
785
	$agent = absences_Agent::getFromIdUser($userid);
786
	foreach($agent->getAgentRightManagerIterator() as $agentRight)
787
	{
788
		$right = $agentRight->getRight();
789
		$changes = new absences_Changes();
790
791
		if (!isset($quantity[$right->id]))
792
		{
793
			continue;
794
		}
795
		
796
		$agentRightQuantity  = $agentRight->getQuantityFromInput($quantity[$right->id]);
797
		if (!isset($agentRightQuantity))
798
		{
799
		    continue;
800
		}
801
802
		
803
		$old_quantity = absences_quantity($agentRight->getQuantity(), $right->quantity_unit);
804
		$new_quantity = absences_quantity($agentRightQuantity, $right->quantity_unit);
805
806
		$changes->setQuantity($old_quantity, $new_quantity);
807
		$agentRight->quantity = $agentRightQuantity;
808
		$agentRight->save();
809
		
810
		$agentRight->addAgentMovement($agent, $changes, $comment);
811
	}
812
813
	return true;
814
}
815
816
817
818
819
820
821
822
823
824
825
class absences_rlistbyuserUnloadCls
826
{
827
    public $message;
828
    public $close;
829
830
    public function __construct($msg)
831
    {
832
        $this->message = $msg;
833
        $this->close = absences_translate("Close");
834
    }
835
}
836
837
838
839
840
841
function absences_rlistbyuserUnload($msg)
842
{
843
	$temp = new absences_rlistbyuserUnloadCls($msg);
844
	global $babBody;
845
	$babBody->babPopup(bab_printTemplate($temp, absences_addon()->getRelativePath()."vacadm.html", "rlistbyuserunload"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
846
}
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
function absences_addVacationPersonnel($idp = false)
866
{
867
	require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
868
    require_once dirname(__FILE__).'/agent.ui.php';
869
	
870
871
	$temp = new absences_AgentEdit($idp);
872
	$temp->printhtml();
873
}
874
875
876
877
878
879
880
881
/**
882
 *
883
 * @param	int		$ide
884
 * @return	boolean
885
 */
886
function absences_isAccessibleEntityAsSuperior($ide) {
887
888
	$ide = (int) $ide;
889
890
	$id_oc = absences_getVacationOption('id_chart');
891
892
893
	$userentities = & bab_OCGetUserEntities($GLOBALS['BAB_SESS_USERID'], $id_oc);
894
	absences_addCoManagerEntities($userentities, $GLOBALS['BAB_SESS_USERID']);
895
	$userentities['superior'];
896
897
	foreach($userentities['superior'] as $arr) {
898
		if ($ide === (int) $arr['id']) {
899
			return true;
900
		}
901
	}
902
903
	return false;
904
}
905
906
907
/**
908
 *
909
 * @param	int		$ide
910
 * @return	boolean
911
 */
912
function absences_isAccessibleEntityAsCoManager($ide) {
913
914
	global $babDB;
915
916
	list($n) = $babDB->db_fetch_array($babDB->db_query('
917
			SELECT COUNT(*) FROM '.ABSENCES_COMANAGER_TBL.'
918
			WHERE
919
			id_user='.$babDB->quote($GLOBALS['BAB_SESS_USERID']).'
920
			AND id_entity='.$babDB->quote($ide).'
921
			'));
922
923
	if ($n > 0) {
924
		return true;
925
	}
926
927
	return false;
928
}
929
930
931
/**
932
 * Relancer les demande en attente sur le nouveau shema d'aprobation
933
 * n'est plus utilise pour le moment car la modification de l'utilisateur est bloque si il reste des demandes en attente en cours
934
 *
935
 * @param int $userid
936
 * @param int $idsa
937
 */
938
function absences_updateVacationUser($userid, $idsa)
939
{
940
	global $babDB;
941
942
	$res = $babDB->db_query("select * from ".ABSENCES_ENTRIES_TBL." where id_user=".$babDB->quote($userid)." and status=''");
943
	while( $row = $babDB->db_fetch_array($res)) {
944
		if( $row['idfai'] != 0 ) {
945
			deleteFlowInstance($row['idfai']);
946
		}
947
		$idfai = makeFlowInstance($idsa, "vac-".$row['id']);
948
		setFlowInstanceOwner($idfai, $row['id_user']);
0 ignored issues
show
Bug introduced by
It seems like $idfai defined by makeFlowInstance($idsa, 'vac-' . $row['id']) on line 947 can also be of type boolean; however, setFlowInstanceOwner() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
949
		$babDB->db_query("UPDATE ".ABSENCES_ENTRIES_TBL." SET idfai=".$babDB->quote($idfai)." where id=".$babDB->quote($row['id'])."");
950
		$nfusers = getWaitingApproversFlowInstance($idfai, true);
0 ignored issues
show
Bug introduced by
It seems like $idfai defined by makeFlowInstance($idsa, 'vac-' . $row['id']) on line 947 can also be of type boolean; however, getWaitingApproversFlowInstance() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
951
		absences_notifyVacationApprovers($row['id'], $nfusers);
952
	}
953
}
954
955
956
957
/**
958
 * Mise a jour du changement de regime
959
 */
960
function absences_updateUserColl()
961
{
962
	global $babDB;
963
964
	if (empty($_POST['idp']))
965
	{
966
		return false;
967
	}
968
969
	$agent = absences_agent::getFromIdUser($_POST['idp']);
970
971
	$users_rights = array();
972
	$worked_ids = array();
973
974
975
976
	$res = $babDB->db_query("SELECT id,id_right FROM ".ABSENCES_USERS_RIGHTS_TBL." WHERE id_user='".$babDB->db_escape_string($_POST['idp'])."'");
977
	while($arr = $babDB->db_fetch_array($res))
978
	{
979
		$users_rights[$arr['id_right']] = $arr['id'];
980
	}
981
982
	$old_rights = $agent->getAgentRightManagerIterator();
983
	$used = array();
984
	foreach($old_rights as $r)
985
	{
986
		/*@var $r absences_AgentRight */
987
		$used[$r->id_right] = $r->getConfirmedQuantity();
988
	}
989
990
	$prefix = 'right_';
991
	$post_rights = array();
992
993
	/* control */
994
995
	foreach($_POST as $field => $value)
996
	{
997
		if (mb_substr($field,0,mb_strlen($prefix)) == $prefix)
998
		{
999
		    $value = (float) str_replace(',', '.', $value);
1000
		    
1001
			list(,$id_right) = explode('_',$field);
1002
			if (isset($used[$id_right]))
1003
			{
1004
				$value += $used[$id_right];
1005
			}
1006
1007
			$right = new absences_Right($id_right);
1008
				
1009
			if (((int) round(100*$right->quantity)) === ((int) round(100*$value)))
1010
			{
1011
				$value = '';
1012
1013
			} else if ($value < 0)
1014
			{
1015
				if ($right->cbalance == 'N')
1016
				{
1017
					$GLOBALS['babBody']->addError(sprintf(absences_translate("Negative balance are not allowed on right %s"), $right->description));
1018
					return false;
1019
1020
				}
1021
			}
1022
1023
1024
			$post_rights[$id_right] = $value;
1025
		}
1026
	}
1027
1028
	/* RECORD */
1029
1030
	foreach($post_rights as $id_right => $user_quantity)
1031
	{
1032
	    
1033
	    $renewal = isset($_POST['renewal'][$id_right]) ? '1' : '0';
1034
	    
1035
		if (isset($users_rights[$id_right]))
1036
		{
1037
			$babDB->db_query("UPDATE 
1038
			        ".ABSENCES_USERS_RIGHTS_TBL." 
1039
			        SET 
1040
			            quantity='".$babDB->db_escape_string($user_quantity)."', 
1041
			            renewal=".$babDB->quote($renewal)." 
1042
			    WHERE id='".$babDB->db_escape_string($users_rights[$id_right])."'
1043
			");
1044
			$worked_ids[] = $users_rights[$id_right];
1045
		}
1046 View Code Duplication
		else
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1047
		{
1048
			$babDB->db_query("INSERT INTO ".ABSENCES_USERS_RIGHTS_TBL." 
1049
			        (id_user,id_right,quantity, renewal) 
1050
			VALUES 
1051
			        (
1052
			            '".$babDB->db_escape_string($_POST['idp'])."', 
1053
			            '".$babDB->db_escape_string($id_right)."', 
1054
			            '".$babDB->db_escape_string($user_quantity)."',
1055
			            ".$babDB->quote($renewal)."
1056
			       )");
1057
			$worked_ids[] = $babDB->db_insert_id();
1058
		}
1059
	}
1060
1061
	if (count($worked_ids) > 0)
1062
	{
1063
		$babDB->db_query("DELETE FROM ".ABSENCES_USERS_RIGHTS_TBL." WHERE id NOT IN(".$babDB->quote($worked_ids).") AND id_user= '".$babDB->db_escape_string($_POST['idp'])."'");
1064
	}
1065
1066
1067
	$old_collection = $agent->getCollection();
1068
	$new_collection = absences_Collection::getById($_POST['idcol']);
1069
1070
	if ($old_collection->id != $new_collection->id)
1071
	{
1072
		$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'])."'");
1073
1074
		$agent->addMovement(sprintf(absences_translate('The collection has been modified from %s to %s'), $old_collection->name, $new_collection->name));
1075
	}
1076
	return true;
1077
}
1078
1079
1080
function absences_changeucol($id_user,$newcol)
1081
{
1082
	global $babBody;
1083
1084
	class tempa
1085
	{
1086
		var $altbg = true;
1087
1088
		function tempa($id_user,$newcol)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1089
		{
1090
			$this->t_oldcol = absences_translate("Old collection");
0 ignored issues
show
Bug introduced by
The property t_oldcol does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1091
			$this->t_newcol = absences_translate("New collection");
0 ignored issues
show
Bug introduced by
The property t_newcol does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1092
			$this->t_record = absences_translate("Record");
0 ignored issues
show
Bug introduced by
The property t_record does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1093
			$this->t_quantity = absences_translate("Quantity");
0 ignored issues
show
Bug introduced by
The property t_quantity does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1094
			$this->t_nbdays = absences_translate("Day(s)");
0 ignored issues
show
Bug introduced by
The property t_nbdays does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1095
			$this->t_right = absences_translate("Rights");
0 ignored issues
show
Bug introduced by
The property t_right does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1096
			$this->t_balance = absences_translate("Balance");
0 ignored issues
show
Bug introduced by
The property t_balance does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1097
			$this->t_balance_title = absences_translate("User remaining quantity (waiting request ignored)");
0 ignored issues
show
Bug introduced by
The property t_balance_title does not seem to exist. Did you mean t_balance?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1098
			$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)");
0 ignored issues
show
Bug introduced by
The property t_new_balance_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1099
			$this->t_confirmed = absences_translate("Consumed");
0 ignored issues
show
Bug introduced by
The property t_confirmed does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1100
			$this->t_waiting = absences_translate("Waiting");
0 ignored issues
show
Bug introduced by
The property t_waiting does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1101
			$this->t_right_user_title = absences_translate("Default quantity in the vacation right and specific user quantity (tooltip on bold)");
0 ignored issues
show
Bug introduced by
The property t_right_user_title does not seem to exist. Did you mean t_right?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1102
			$this->t_right_title = absences_translate("Default quantity in the vacation right");
0 ignored issues
show
Bug introduced by
The property t_right_title does not seem to exist. Did you mean t_right?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1103
			$this->t_user_modified = absences_translate("A specific user quantity exists");
0 ignored issues
show
Bug introduced by
The property t_user_modified does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1104
			$this->t_renewal = absences_translate('Renewal');
0 ignored issues
show
Bug introduced by
The property t_renewal does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1105
			$this->t_renewal_title = absences_translate('Include this right in the next yearly renewal');
0 ignored issues
show
Bug introduced by
The property t_renewal_title does not seem to exist. Did you mean t_renewal?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1106
1107
			global $babDB;
1108
			$this->tg = bab_rp('tg');
0 ignored issues
show
Bug introduced by
The property tg does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1109
			$this->ide = bab_rp('ide', false);
0 ignored issues
show
Bug introduced by
The property ide does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1110
1111
			$agent = absences_Agent::getFromIdUser($id_user);
1112
			$old_rights = $agent->getAgentRightManagerIterator();
1113
1114
			$this->id_user = $id_user;
0 ignored issues
show
Bug introduced by
The property id_user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1115
			$this->id_coll = $newcol;
0 ignored issues
show
Bug introduced by
The property id_coll does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1116
			
1117
			$newCollection = absences_Collection::getById($newcol);
1118
1119
			$this->oldcol = bab_toHtml($agent->getCollection()->name);
0 ignored issues
show
Bug introduced by
The property oldcol does not seem to exist. Did you mean t_oldcol?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1120
			$this->newcol = bab_toHtml($newCollection->name);
0 ignored issues
show
Bug introduced by
The property newcol does not seem to exist. Did you mean t_newcol?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1121
1122
			
1123
			$req = "SELECT cr.id_right _id_right, ur.* FROM
1124
				
1125
			absences_coll_rights cr
1126
			    LEFT JOIN absences_users_rights ur ON ur.id_right = cr.id_right
1127
			    AND ur.id_user = ".$babDB->quote($id_user)."
1128
			WHERE
1129
			    cr.id_coll='".$babDB->db_escape_string($newcol)."'
1130
			";
1131
				
1132
			$res = $babDB->db_query($req);
1133
				
1134
			$new_rights = array();
1135
			while ($arr = $babDB->db_fetch_assoc($res))
1136
			{
1137
					
1138
				if (isset($arr['id']))
1139
				{
1140
					$row = $arr;
1141
					unset($row['_id_right']);
1142
					$collRight = new absences_AgentRight;
1143
					$collRight->setRow($arr);
1144
				} else {
1145
					$collRight = new absences_Right($arr['_id_right']);
1146
						
1147
					if (!$collRight->getRow())
1148
					{
1149
						bab_debug(sprintf('Failed to load right for id_right=%d', $arr['_id_right']), DBG_ERROR);
1150
						continue;
1151
					}
1152
				}
1153
					
1154
				$new_rights[] = $collRight;
1155
			}
1156
				
1157
			$this->totaldays = 0;
0 ignored issues
show
Bug introduced by
The property totaldays does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1158
1159
			$this->rights = array();
0 ignored issues
show
Bug introduced by
The property rights does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1160
1161
			foreach ($old_rights as $agentRight)
1162
			{
1163
				$right = $agentRight->getRight();
1164
1165 View Code Duplication
				if (!$right->getRow()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1166
					bab_debug(sprintf('Failed to load right for agentRight %d, id_right=%d', $agentRight->id, $agentRight->id_right), DBG_ERROR);
1167
					continue;
1168
				}
1169
				
1170
				// ignorer les droits avec un solde a zero et qui sont 
1171
				
1172
				if (!$right->isAccessibleByValidityPeriod() && 0 === (int) round(100 * $agentRight->getAvailableQuantity())) {
1173
				    continue;
1174
				}
1175
				
1176
1177
				$this->rights[$right->id] = array(
1178
						'quantity_unit'			=> $right->quantity_unit,
1179
						'description' 			=> $right->description,
1180
						'quantity_old' 			=> $right->quantity,
1181
						'user_quantity_old' 	=> $agentRight->quantity,
1182
						'quantity_available' 	=> $agentRight->getAvailableQuantity(),
1183
						'confirmed'				=> (float) $agentRight->getConfirmedQuantity(),
1184
						'waiting'				=> (float) $agentRight->getWaitingQuantity()
1185
				);
1186
			}
1187
1188
			foreach ($new_rights as $collRight)
1189
			{
1190
					
1191
					
1192
				if ($collRight instanceof absences_AgentRight)
1193
				{
1194
					$right = $collRight->getRight();
1195
					$agentRight = $collRight;
1196
					$user_quantity_new = $agentRight->quantity;
1197
					$quantity_available = $agentRight->getAvailableQuantity();
1198
					$confirmed = (float) $agentRight->getConfirmedQuantity();
1199
					$waiting = (float) $agentRight->getWaitingQuantity();
1200
						
1201
				} else {
1202
					$right = $collRight;
1203
						
1204
					$user_quantity_new = $right->quantity;
1205
					$quantity_available = null;
1206
					$confirmed = null;
1207
					$waiting = null;
1208
				}
1209
1210 View Code Duplication
				if (!$right->getRow())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1211
				{
1212
					bab_debug(sprintf('Failed to load right for agentRight %d, id_right=%d', $agentRight->id, $agentRight->id_right), DBG_ERROR);
0 ignored issues
show
Bug introduced by
The variable $agentRight does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1213
					continue;
1214
				}
1215
					
1216
				if (!isset($this->rights[$right->id]))
1217
				{
1218
1219
						
1220
						
1221
					$this->rights[$right->id] = array(
1222
							'quantity_unit'			=> $right->quantity_unit,
1223
							'description' 			=> $right->description,
1224
							'quantity_new' 			=> $right->quantity,
1225
							'user_quantity_new' 	=> $user_quantity_new,
1226
							'quantity_available'	=> $quantity_available,
1227
							'confirmed'				=> $confirmed,
1228
							'waiting'				=> $waiting
1229
					);
1230
1231
				}
1232
				else
1233
				{
1234
					$this->rights[$right->id]['quantity_new'] = $right->quantity;
1235
					$this->rights[$right->id]['confirmed'] = $confirmed;
1236
					$this->rights[$right->id]['waiting'] = $waiting;
1237
				}
1238
			}
1239
		}
1240
			
1241
			
1242
		private function createQuantityProperty($right, $name)
1243
		{
1244
				
1245
				
1246
			if (!isset($right[$name]) || '' === $right[$name]) {
1247
				$this->right[$name] = '';
0 ignored issues
show
Bug introduced by
The property right does not seem to exist. Did you mean rights?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1248
			} else {
1249
				$this->right[$name] = bab_toHtml(absences_quantity($right[$name], $right['quantity_unit']));
0 ignored issues
show
Bug introduced by
The property right does not seem to exist. Did you mean rights?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1250
			}
1251
		}
1252
1253
		function getnext()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1254
		{
1255
			if (list($this->id,$right) = each($this->rights))
1256
			{
1257
				$this->altbg = !$this->altbg;
1258
				$default = (isset($right['quantity_new']) && $right['quantity_available'] > $right['quantity_new']) || !is_numeric($right['quantity_available']) ? $right['quantity_new'] : $right['quantity_available'];
1259
1260
				$newrightvalue = isset($_POST['right_'.$this->id]) ? $_POST['right_'.$this->id] : $default;
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1261
				$this->newrightvalue = bab_toHtml(absences_editQuantity($newrightvalue, $right['quantity_unit']));
0 ignored issues
show
Bug introduced by
The property newrightvalue does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1262
1263
				$this->createQuantityProperty($right, 'quantity_new');
1264
				$this->createQuantityProperty($right, 'quantity_old');
1265
1266
				$this->createQuantityProperty($right, 'user_quantity_new');
1267
				$this->createQuantityProperty($right, 'user_quantity_old');
1268
1269
				$this->createQuantityProperty($right, 'confirmed');
1270
				$this->createQuantityProperty($right, 'waiting');
1271
1272
				$this->createQuantityProperty($right, 'quantity_available');
1273
1274
1275
				$this->right['description'] = bab_toHtml($right['description']);
0 ignored issues
show
Bug introduced by
The property right does not seem to exist. Did you mean rights?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1276
				//$this->right['quantity_available'] = bab_toHtml(absences_quantity($right['quantity_available'], $right['quantity_unit']));
1277
1278
                $this->renewal = isset($right['quantity_new']);
0 ignored issues
show
Bug introduced by
The property renewal does not seem to exist. Did you mean t_renewal?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1279
                
1280
				return true;
1281
			}
1282
			else
1283
			{
1284
				return false;
1285
			}
1286
		}
1287
			
1288
1289
			
1290
	}
1291
1292
1293
	$tempa = new tempa($id_user,$newcol);
1294
	$babBody->babecho(	bab_printTemplate($tempa, absences_addon()->getRelativePath()."vacadm.html", "changeucol"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1295
1296
}
1297
1298
1299
function absences_getWfName($id_approb)
1300
{
1301
	require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
1302
	if (!$id_approb)
1303
	{
1304
		return absences_translate('None');
1305
	}
1306
1307
1308
	$arr = bab_WFGetApprobationInfos($id_approb);
1309
1310
	return $arr['name'];
1311
}
1312
1313
1314
1315
1316
1317
1318
1319
1320
/**
1321
 * Set parameter for agent (create or modify)
1322
 * if the agent does not exists, il will be created
1323
 *
1324
 * @param	int		$iduser
1325
 * @param	int		$id_collection
1326
 * @param	int		$idsa				Approval scheme
1327
 * @param	int		$id_sa_cet			Optionnal approval scheme for time saving account
1328
 * @param	int		$id_sa_recover		Optionnal approval scheme for work period recovery
1329
 *
1330
 * @throws Exception
1331
 *
1332
 * @return bool
1333
 */
1334
function absences_setAgentInfos($iduser, $id_collection, $idsa, $id_sa_cet = 0, $id_sa_recover = 0, $emails = null, $id_organization = null)
1335
{
1336
	global $babDB;
1337
	require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
1338
1339
	if( empty($iduser) )
1340
	{
1341
		throw new Exception(absences_translate("You must specify a user"));
1342
	}
1343
1344
	if( empty($idsa) )
1345
	{
1346
		throw new Exception(absences_translate("You must specify approbation schema"));
1347
	}
1348
1349
	if( !empty($iduser))
1350
	{
1351
		$agent = absences_Agent::getFromIdUser($iduser);
1352
		if( $agent->exists() )
1353
		{
1354
1355
			$query = "UPDATE ".ABSENCES_PERSONNEL_TBL." SET
1356
			
1357
			id_sa='".$babDB->db_escape_string($idsa)."',
1358
			id_sa_cet=".$babDB->quote($id_sa_cet).",
1359
			id_sa_recover=".$babDB->quote($id_sa_recover)."";
1360
			
1361
			if (null !== $id_collection) {
1362
			    $query .= ", id_coll=".$babDB->quote($id_collection);
1363
			}
1364
				
1365
			if (null !== $emails) {
1366
				$query .= ", emails=".$babDB->quote($emails);
1367
			}
1368
			
1369
			if (null !== $id_organization) {
1370
			    $query .= ", id_organization=".$babDB->quote($id_organization);
1371
			}
1372
				
1373
				
1374
			$babDB->db_query($query." WHERE id_user='".$babDB->db_escape_string($iduser)."'");
1375
1376
			if( $agent->id_sa != $idsa )
1377
			{
1378
				$old = bab_WFGetApprobationInfos($agent->id_sa);
1379
				$new = bab_WFGetApprobationInfos($idsa);
1380
				$agent->addMovement(sprintf(absences_translate('The approbation shema has been modified from %s to %s'), $old['name'], $new['name']));
1381
			}
1382
1383 View Code Duplication
			if( $agent->id_sa_cet != $id_sa_cet )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1384
			{
1385
				$agent->addMovement(sprintf(absences_translate('The approbation shema for time saving account has been modified from %s to %s'),
1386
						absences_getWfName($agent->id_sa_cet), absences_getWfName($id_sa_cet)));
1387
			}
1388
1389 View Code Duplication
			if( $agent->id_sa_recover != $id_sa_recover )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1390
			{
1391
				$agent->addMovement(sprintf(absences_translate('The approbation shema for work period recovery has been modified from %s to %s'),
1392
						absences_getWfName($agent->id_sa_recover), absences_getWfName($id_sa_recover)));
1393
			}
1394
1395
1396
		}
1397
		else
1398
		{
1399
		    if( empty($id_collection) )
1400
		    {
1401
		        throw new Exception(absences_translate("You must specify a vacation collection"));
1402
		    }
1403
		    
1404
		    
1405
			$babDB->db_query("INSERT INTO ".ABSENCES_PERSONNEL_TBL."
1406
					(
1407
					id_user,
1408
					id_coll,
1409
					id_sa,
1410
					id_sa_cet,
1411
					id_sa_recover,
1412
					emails,
1413
			        id_organization
1414
			) VALUES (
1415
					'".$babDB->db_escape_string($iduser)."',
1416
					".$babDB->quote($id_collection).",
1417
					'".$babDB->db_escape_string((string) $idsa)."',
1418
					'".$babDB->db_escape_string((string) $id_sa_cet)."',
1419
					'".$babDB->db_escape_string((string) $id_sa_recover)."',
1420
					".$babDB->quote((string) $emails).",
1421
			        ".$babDB->quote((string) $id_organization)."
1422
			)");
1423
1424
			$agent->addMovement(absences_translate('New personnel member created'));
1425
		}
1426
	}
1427
1428
1429
	return true;
1430
}
1431
1432
1433
1434
/**
1435
 * Set rights associations according to collection
1436
 *
1437
 * @param	int		$id_user
1438
 * @param	int		$id_collection
1439
 *
1440
 *
1441
 */
1442
function absences_setCollectionRights($id_user, $id_collection)
1443
{
1444
	require_once dirname(__FILE__).'/vacfixedincl.php';
1445
	global $babDB;
1446
1447
	// create default user rights
1448
1449
	$babDB->db_query("DELETE FROM ".ABSENCES_USERS_RIGHTS_TBL." WHERE id_user='".$babDB->db_escape_string($id_user)."'");
1450
1451
	$res = $babDB->db_query("SELECT
1452
			cr.id_right
1453
			FROM
1454
			absences_coll_rights cr
1455
			WHERE
1456
			cr.id_coll='".$babDB->db_escape_string($id_collection)."'
1457
			");
1458
1459
	while($r = $babDB->db_fetch_array($res))
1460
	{
1461
		$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'])."')");
1462
	}
1463
1464
1465
	// update fixed vacation right
1466
	absences_updateFixedRightsOnUser($id_user, $messages);
1467
}
1468
1469
1470
1471
1472
/**
1473
 * mise a jour d'un utilisateur, utiliser par le gestionnaire et le gestionnaire delegue
1474
 * return false : retour au formulaire de modification de l'agent
1475
 * return true : continuer vers l'ecran de modification du regime
1476
 * return null : retour a la liste des agents
1477
 * 
1478
 * 
1479
 * @return bool | null
1480
 */
1481
function absences_updateVacationPersonnel($id_user)
1482
{
1483
	global $babBody;
1484
    require_once dirname(__FILE__).'/agent.class.php';
1485
    
1486
    $agent = absences_Agent::getFromIdUser($id_user);
1487
1488
	try {
1489
	    // T8246: on ne modifie pas le regime, l'utilisateur est redirige vers la page du changement de regime
1490
		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'));
1491
1492
	} catch (Exception $e)
1493
	{
1494
		$babBody->addError($e->getMessage());
1495
		return false;
1496
	}
1497
	
1498
	
1499
	// mise a jour des profiles de rythmes de travail
1500
	
1501
	if (isset($_POST['profiles'])) {
1502
	    require_once dirname(__FILE__).'/workschedules.php';
1503
	    
1504
	    try {
1505
	       absences_setProfiles($id_user, bab_pp('profiles'));
1506
	    } catch (bab_SaveErrorException $e) {
1507
	        $babBody->addError($e->getMessage());
1508
	        return false;
1509
	    }
1510
	}
1511
	
1512
	
1513
	
1514
	if ((int) $agent->id_coll === (int) bab_rp('idcol')) {
1515
	    // le regime n'a pas ete modifie, rediriger vers la liste des agents
1516
	    
1517
	    return null;
1518
	}
1519
1520
	return true; // vers la modification du regime;
1521
}
1522
1523
1524
1525
1526
1527
function absences_saveVacationPersonnel($userid,  $idcol, $idsa, $id_sa_cet, $id_sa_recover, $emails, &$messages)
0 ignored issues
show
Unused Code introduced by
The parameter $messages is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1528
{
1529
	global $babBody, $babDB;
1530
	absences_setAgentInfos($userid,  $idcol, $idsa, $id_sa_cet, $id_sa_recover, $emails);
1531
	absences_setCollectionRights($userid, $idcol);
1532
1533
1534
	// update user menu
1535
	bab_sitemap::clear($userid);
1536
1537
	return true;
1538
}
1539
1540
1541
class absences_notifyOnVacationChangeCls
1542
{
1543
1544
	public function __construct($quantity, $date_begin,  $date_end, $msg)
1545
	{
1546
		global $babDB;
1547
		$this->message = $msg;
0 ignored issues
show
Bug introduced by
The property message does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1548
		$this->from = absences_translate("from");
0 ignored issues
show
Bug introduced by
The property from does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1549
		$this->until = absences_translate("until");
0 ignored issues
show
Bug introduced by
The property until does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1550
		$this->quantitytxt = absences_translate("Quantity");
0 ignored issues
show
Bug introduced by
The property quantitytxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1551
		$this->begindate = bab_strftime(bab_mktime($date_begin));
0 ignored issues
show
Bug introduced by
The property begindate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The function bab_strftime() has been deprecated.

This function has been deprecated.

Loading history...
1552
		$this->enddate = bab_strftime(bab_mktime($date_end));
0 ignored issues
show
Bug introduced by
The property enddate does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Deprecated Code introduced by
The function bab_strftime() has been deprecated.

This function has been deprecated.

Loading history...
1553
		$this->quantity = $quantity;
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantitytxt?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1554
	}
1555
}
1556
1557
1558
/**
1559
 * Notify on vacation change
1560
 * @param int		$idusers
1561
 * @param int		$quantity
1562
 * @param string	$date_begin		0000-00-00 00:00:00
1563
 * @param string	$date_end		0000-00-00 00:00:00
1564
 * @param string	$what
1565
 * 
1566
 * @return bool
1567
 */
1568
function absences_notifyOnVacationChange($idusers, $quantity, $date_begin, $date_end, $what)
1569
{
1570
	global $babBody, $babDB, $BAB_SESS_USER, $BAB_SESS_EMAIL;
1571
	
1572
	if (empty($quantity) || empty($date_begin)) {
1573
	    return false;
1574
	}
1575
1576
1577
	$cntusers = count($idusers);
1578
1579
	if( $cntusers > 0 )
1580
	{
1581
		$mail = bab_mail();
1582
		if( $mail == false )
1583
			return false;
1584
1585
		$mail->mailFrom($BAB_SESS_EMAIL, $BAB_SESS_USER);
1586
		switch($what)
1587
		{
1588
			case ABSENCES_FIX_UPDATE: $msg = absences_translate("Vacation has been updated");	break;
1589
			case ABSENCES_FIX_DELETE: $msg = absences_translate("Vacation has been deleted");	break;
1590
			default: $msg = absences_translate("Vacation has been scheduled");	break;
1591
		}
1592
1593
		$mail->mailSubject($msg);
1594
1595
		$tempb = new absences_notifyOnVacationChangeCls($quantity, $date_begin, $date_end, $msg);
1596
		$message = $mail->mailTemplate(bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newfixvacation"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1597
		$mail->mailBody($message, "html");
1598
1599
		$message = bab_printTemplate($tempb, absences_addon()->getRelativePath()."mailinfo.html", "newfixvacationtxt");
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
1600
		$mail->mailAltBody($message);
1601
1602
		for( $i=0; $i < $cntusers; $i++)
1603
		{
1604
			$mail->clearTo();
1605
			$mail->mailTo(bab_getUserEmail($idusers[$i]), bab_getUserName($idusers[$i]));
1606
			$mail->send();
1607
		}
1608
	}
1609
	
1610
	return true;
1611
}
1612
1613
1614
function absences_isPlanningAccessValid()
1615
{
1616
    if (bab_isAccessValid('absences_public_planning_groups', 1)) {
1617
        return true;
1618
    }
1619
    
1620
    if (bab_getUserIdObjects('absences_custom_planning_groups')) {
1621
        return true;
1622
    }
1623
    
1624
	global $babDB;
1625
	$id_oc = absences_getVacationOption('id_chart');
1626
	
1627
	$res = $babDB->db_query("SELECT p.id_user 
1628
	     FROM ".ABSENCES_PLANNING_TBL." p, bab_oc_entities e 
1629
	        WHERE p.id_user=".$babDB->quote($GLOBALS['BAB_SESS_USERID'])." 
1630
	        AND p.id_entity=e.id AND e.id_oc=".$babDB->quote($id_oc));
1631
	return  ($babDB->db_num_rows($res) > 0);
1632
}
1633
1634
1635
/**
1636
 *
1637
 * @param string $field
1638
 */
1639
function absences_getVacationOption($field) {
1640
	global $babDB;
1641
	require_once $GLOBALS['babInstallPath'].'utilit/ocapi.php';
1642
1643
	static $arr = null;
1644
1645
	if (null == $arr) {
1646
		$res = $babDB->db_query("SELECT * FROM ".ABSENCES_OPTIONS_TBL);
1647
		if (0 < $babDB->db_num_rows($res)) {
1648
			$arr = $babDB->db_fetch_assoc($res);
1649
		} else {
1650
			$arr = array(
1651
1652
					'chart_superiors_create_request' 	=> 0,
1653
					'chart_superiors_set_rights'		=> 0,
1654
					'allow_mismatch' 					=> 0,
1655
					'workperiod_recover_request'		=> 0,
1656
					'display_personal_history'			=> 0,
1657
			        'modify_confirmed'       			=> 0,
1658
			        'modify_waiting'       			    => 1,
1659
					'email_manager_ondelete'			=> 1,
1660
					'approb_email_defer'				=> 0,
1661
					'entity_planning'					=> 0,
1662
			        'entity_planning_display_types'		=> 0,
1663
					'approb_alert'						=> 7,
1664
			        'auto_approval'                     => 1,
1665
					'auto_confirm'						=> 0,
1666
					'sync_server'						=> 0,
1667
					'sync_url'							=> '',
1668
					'sync_nickname'						=> '',
1669
					'sync_password'						=> '',
1670
					'id_chart'							=> bab_OCgetPrimaryOcId(),
1671
					'user_add_email'					=> 0,
1672
					'end_recup'							=> 365,
1673
					'delay_recovery'					=> 0,
1674
					'maintenance'						=> 0,
1675
					'archivage_day'						=> 1,
1676
					'archivage_month'					=> 1,
1677
				//	'public_calendar'					=> 0,
1678
					'appliquant_email'					=> 1,
1679
					'organization_sync'					=> 0
1680
			);
1681
		}
1682
	}
1683
1684
	return $arr[$field];
1685
}
1686
1687
1688
1689
1690
1691
1692
/**
1693
 * Set vacation events into object
1694
 *
1695
 * @todo process queries with null dates
1696
 *
1697
 * @param bab_UserPeriods				$user_periods			query result set
1698
 * @param array							$id_users
1699
 */
1700
function absences_setVacationPeriods(bab_UserPeriods $user_periods, $id_users) {
1701
	global $babDB;
1702
1703
	require_once $GLOBALS['babInstallPath'].'utilit/nwdaysincl.php';
1704
	require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
1705
	require_once dirname(__FILE__).'/entry.class.php';
1706
1707
	$begin = $user_periods->begin;
1708
	$end = $user_periods->end;
1709
1710
1711
1712
	$query = "
1713
    	SELECT 
1714
    	   e.*, 
1715
    	   c.calendar_backend 
1716
    	from
1717
    	   ".ABSENCES_ENTRIES_TBL." e 
1718
    	       LEFT JOIN ".BAB_CAL_USER_OPTIONS_TBL." c ON e.id_user=c.id_user
1719
    	WHERE
1720
    	   e.id_user IN(".$babDB->quote($id_users).") 
1721
    	   AND e.status!='N'
1722
	";
1723
1724
	if (null !== $begin)
1725
	{
1726
		$query .= " AND date_end > ".$babDB->quote($begin->getIsoDateTime())." ";
1727
	}
1728
1729
	if (null !== $end)
1730
	{
1731
		$query .= " AND date_begin < ".$babDB->quote($end->getIsoDateTime())." ";
1732
	}
1733
1734
	$res = $babDB->db_query($query);
1735
1736
	// find begin and end
1737
1738
	$date_end = null;
1739
	$date_begin = null;
1740
1741
	while ($row = $babDB->db_fetch_assoc($res))
1742
	{
1743
		if (null === $date_end || $row['date_end'] > $date_end)
1744
		{
1745
			$date_end = $row['date_end'];
1746
		}
1747
1748
		if (null === $date_begin || $row['date_begin'] < $date_begin)
1749
		{
1750
			$date_begin = $row['date_begin'];
1751
		}
1752
	}
1753
1754
	if ($babDB->db_num_rows($res))
1755
	{
1756
		$babDB->db_data_seek($res, 0);
1757
	}
1758
1759
1760
	$begin 	= BAB_DateTime::fromIsoDateTime($date_begin);
0 ignored issues
show
Unused Code introduced by
$begin is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1761
	$end	= BAB_DateTime::fromIsoDateTime($date_end);
0 ignored issues
show
Unused Code introduced by
$end is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1762
1763
	$collections = array();
1764
1765
	while( $row = $babDB->db_fetch_assoc($res))
1766
	{
1767
		$backend = bab_functionality::get('CalendarBackend/'.$row['calendar_backend']);
1768
1769
		if (!$backend)
1770
		{
1771
			continue;
1772
		}
1773
1774
1775
		if (!isset($collections[$row['id_user']]))
1776
		{
1777
			$id_user = (int) $row['id_user'];
1778
			$calendar = $backend->Personalcalendar($id_user);
1779
1780
			if ($calendar)
1781
			{
1782
				$collections[$row['id_user']] = $backend->VacationPeriodCollection($calendar);
1783
			} else {
1784
				$collections[$row['id_user']] = null;
1785
			}
1786
1787
		}
1788
1789
1790
		if (isset($collections[$row['id_user']]))
1791
		{
1792
			$entry = new absences_Entry();
1793
			$entry->setRow($row);
1794
				
1795
			$p = new bab_calendarPeriod;
1796
			absences_setPeriodProperties($p, $entry);
1797
			$collections[$row['id_user']]->addPeriod($p);
1798
			$p->setProperty('UID', 'VAC'.$row['id']);
1799
			$user_periods->addPeriod($p);
1800
		}
1801
1802
	}
1803
}
1804
1805
1806
1807
1808
1809
/**
1810
 * Search for a vacation request in ovidentia database and update the corresponding calendar period if the period is found using the user calendar backend
1811
 * @param int			$id_request
1812
 * @param BAB_DateTime 	$begin			old begin date
1813
 * @param BAB_DateTime	$end			old end date
1814
 * @return unknown_type
1815
 */
1816
function absences_updatePeriod($id_request, BAB_DateTime $begin, BAB_DateTime $end)
1817
{
1818
	global $babDB;
1819
	require_once dirname(__FILE__).'/entry.class.php';
1820
1821
	$entry = absences_Entry::getById($id_request);
1822
	
1823
	if (!$entry->getRow()) {
1824
	    throw new Exception(sprintf('Absence request with id %s does not exists', $id_request));
1825
	}
1826
1827
1828
	$period = absences_getPeriod($id_request, $entry->id_user, $begin, $end);
1829
	if (null === $period)
1830
	{
1831
		bab_debug('no period found in backend');
1832
		return null;
1833
	}
1834
1835
	absences_setPeriodProperties($period, $entry);
1836
1837
	$period->save();
1838
}
1839
1840
1841
/**
1842
 * Create a new vacation request into calendar backend
1843
 * @param $id_request
1844
 * @return unknown_type
1845
 */
1846
function absences_createPeriod($id_request)
1847
{
1848
	global $babDB;
1849
	require_once $GLOBALS['babInstallPath'].'utilit/calincl.php';
1850
	require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
1851
	require_once dirname(__FILE__).'/entry.class.php';
1852
1853
	$entry = absences_Entry::getById($id_request);
1854
1855
1856
	$icalendars = bab_getICalendars($entry->id_user);
1857
1858
	$calendar = $icalendars->getPersonalCalendar();
1859
1860
	if (!$calendar)
1861
	{
1862
		// do not create the vacation period if no personal calendar
1863
		return;
1864
	}
1865
1866
	$backend = $calendar->getBackend();
1867
1868
	if ($backend instanceof Func_CalendarBackend_Ovi)
1869
	{
1870
		// do not create the vacation period if the calendar backend is ovidentia because the calendar api will get the original vacation period
1871
		return;
1872
	}
1873
1874
	$date_begin = BAB_DateTime::fromIsoDateTime($entry->date_begin);
1875
	$date_end	= BAB_DateTime::fromIsoDateTime($entry->date_end);
1876
1877
	$period = $backend->CalendarPeriod($date_begin->getTimeStamp(), $date_end->getTimeStamp());
1878
	$collection = $backend->CalendarEventCollection($calendar);
1879
	$collection->addPeriod($period);
1880
1881
	absences_setPeriodProperties($period, $entry);
1882
1883
	$period->save();
1884
}
1885
1886
1887
/**
1888
 * Gestion des types/couleurs sur le planning
1889
 *
1890
 */
1891
class absences_EntryColors
1892
{
1893
1894
	private $stack = array();
1895
1896
1897
	private $freeHalfDays = array();
1898
1899
	/**
1900
	 *
1901
	 * @var int
1902
	 */
1903
	private $maxHalfDays = 0;
1904
1905
1906
	/**
1907
	 * Push and shift into a stack
1908
	 * @param int		$id_entry
1909
	 * @param string 	$searchkey
1910
	 * @param mixed $push
1911
	 *
1912
	 * $push = array(
1913
	 *		type, color
1914
	 *	)
1915
	 */
1916
	private function typeColorStack($id_entry, $searchkey, $push = false) {
1917
1918
		if (!isset($this->stack[$id_entry][$searchkey])) {
1919
			$this->stack[$id_entry][$searchkey] = array();
1920
		}
1921
1922
		if (false === $push) {
1923
			return array_shift($this->stack[$id_entry][$searchkey]);
1924
		}
1925
1926
		array_push($this->stack[$id_entry][$searchkey], $push);
1927
	}
1928
1929
1930
1931
	/**
1932
	 *
1933
	 * @param int $id_entry
1934
	 * @param int $id_user
1935
	 * @param BAB_DateTime $date_begin		Event start date
1936
	 * @param BAB_DateTime $date_begin		Event end date
1937
	 * @param BAB_DateTime $search_begin	colors start date		/ premier jour du mois
1938
	 *
1939
	 * @return array
1940
	 */
1941
	public function get($id_entry, $id_user, BAB_DateTime $date_begin, BAB_DateTime $date_end, BAB_DateTime $search_begin)
1942
	{
1943
		$searchkey = $search_begin->getIsoDate();
1944
1945
		if (!isset($this->stack[$id_entry][$searchkey])) {
1946
			$this->setMaxHalfDays($date_begin, $date_end);
1947
			$this->getFreeHalfDays($id_user, $date_begin, $date_end);
1948
			$this->set($id_entry, $id_user, $date_begin, $search_begin);
1949
		}
1950
1951
		return $this->typeColorStack($id_entry, $searchkey);
1952
	}
1953
1954
1955
1956
	private function setMaxHalfDays(BAB_DateTime $date_begin, BAB_DateTime $date_end)
1957
	{
1958
		$nbdays = BAB_DateTime::dateDiffIso($date_begin->getIsoDate(), $date_end->getIsoDate());
1959
1960
		$this->maxHalfDays = (2* $nbdays);
0 ignored issues
show
Documentation Bug introduced by
It seems like 2 * $nbdays can also be of type double. However, the property $maxHalfDays is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
1961
	}
1962
1963
1964
1965
	/**
1966
	 * Set colors of entry into stack
1967
	 * @param 	int 			$id_entry
1968
	 * @param 	int 			$id_user
1969
	 * @param 	BAB_DateTime 	$date_begin		Debut de l'evenement
1970
	 * @param	BAB_DateTime	$search_begin	Debut de la zone de recherche, premier jour du mois
1971
	 */
1972
	private function set($id_entry, $id_user, BAB_DateTime $date_begin, BAB_DateTime $search_begin)
1973
	{
1974
		require_once $GLOBALS['babInstallPath'].'utilit/workinghoursincl.php';
1975
		global $babDB;
1976
1977
		$req = "SELECT
1978
        		e.quantity,
1979
        		t.name type,
1980
        		t.color
1981
    		FROM 
1982
		          ".ABSENCES_ENTRIES_ELEM_TBL." e,
1983
    		      ".ABSENCES_RIGHTS_TBL." r,
1984
    		      ".ABSENCES_TYPES_TBL." t
1985
    		WHERE
1986
    		  e.id_entry=".$babDB->quote($id_entry)."
1987
    		  AND r.id=e.id_right
1988
    		  AND t.id=r.id_type
1989
1990
	      ORDER BY e.date_begin";
1991
1992
		$res2 = $babDB->db_query($req);
1993
1994
		$type_day       = $date_begin->cloneDate();
1995
		$type_day_end   = $date_begin->cloneDate();
1996
		$ignore 		= array();
1997
1998
1999
		while ($arr = $babDB->db_fetch_assoc($res2))
2000
		{
2001
			
2002
				
2003
			for($d = 0; $d < $arr['quantity']; $d += 0.5) {
2004
2005
				// si le demi-jour est ferie ou non travaille , repousser la zone de couleur d'un demi-jour
2006
				while (!$this->isFree($type_day_end) && count($ignore) < $this->maxHalfDays) {
2007
					
2008
					$key = date('Ymda', $type_day_end->getTimeStamp());
2009
					
2010
					$ignore[$key] = 1;
2011
					$type_day_end->add(12, BAB_DATETIME_HOUR);
2012
				}
2013
2014
				$type_day_end->add(12, BAB_DATETIME_HOUR);
2015
2016
			}
2017
			
2018
2019
			while ($type_day->getTimeStamp() < $type_day_end->getTimeStamp() ) {
2020
				
2021
				$key = date('Ymda', $type_day->getTimeStamp());
2022
2023
				if ($type_day->getTimeStamp() >= $date_begin->getTimeStamp() 
2024
						&& $search_begin->getTimeStamp() <= $type_day->getTimeStamp() 
2025
						&& !isset($ignore[$key])) {
2026
2027
					$this->typeColorStack(
2028
							$id_entry,
2029
							$search_begin->getIsoDate(),
2030
							array(
2031
									'id_type'       => $arr['type'],
2032
									'color'         => $arr['color']
2033
							)
2034
					);
2035
				}
2036
2037
				$type_day->add(12, BAB_DATETIME_HOUR);
2038
			}
2039
		}
2040
2041
	}
2042
2043
	/**
2044
	 * Indexer les jours travailles par demie-journee sur la periode de la demande
2045
	 *
2046
	 * @param int			$id_user
2047
	 * @param BAB_DateTime 	$date_begin		debut demande
2048
	 * @param BAB_DateTime	$date_begin		fin demande
2049
	 */
2050
	private function getFreeHalfDays($id_user, BAB_DateTime $date_begin, BAB_DateTime $date_end)
2051
	{
2052
2053
		$arr = absences_getHalfDaysIndex($id_user, $date_begin, $date_end, true);
2054
2055
		$this->freeHalfDays = $arr[2];
2056
	}
2057
2058
	
2059
	/**
2060
	 * Test if half day is free
2061
	 * @param BAB_DateTime $date
2062
	 * @return bool
2063
	 */
2064
	private function isFree(BAB_DateTime $date)
2065
	{
2066
		$key = date('Ymda', $date->getTimeStamp());
2067
2068
		return isset($this->freeHalfDays[$key]);
2069
	}
2070
}
2071
2072
2073
2074
/**
2075
 * Update the period properties with vacation entry informations
2076
 *
2077
 * @param 	bab_CalendarPeriod	$p
2078
 * @param 	absences_Entry		$entry
2079
 *
2080
 *
2081
 * @return unknown_type
2082
 */
2083
function absences_setPeriodProperties(bab_CalendarPeriod $p, absences_Entry $entry)
2084
{
2085
	global $babDB;
2086
2087
	$date_begin = BAB_DateTime::fromIsoDateTime($entry->date_begin);
2088
	$date_end	= BAB_DateTime::fromIsoDateTime($entry->date_end);
2089
	$p->setDates($date_begin, $date_end);
2090
2091
2092
	list(, $category, $color) = $babDB->db_fetch_row($babDB->db_query("
2093
2094
			SELECT
2095
			cat.id,
2096
			cat.name,
2097
			cat.bgcolor
2098
			FROM
2099
			".ABSENCES_COLLECTIONS_TBL." vct,
2100
			".ABSENCES_PERSONNEL_TBL." vpt,
2101
			".ABSENCES_ENTRIES_TBL." vet,
2102
			".BAB_CAL_CATEGORIES_TBL." cat
2103
			WHERE
2104
			vpt.id_coll=vct.id
2105
			AND vet.id_user=vpt.id_user
2106
			AND vet.id=".$babDB->quote($entry->id)."
2107
			AND cat.id = vct.id_cat
2108
			"));
2109
2110
2111
	if (!$entry->isPrevisonal())
2112
	{
2113
	    if ('' === $entry->status) {
2114
	        $p->setProperty('SUMMARY'		, absences_translate("Waiting vacation"));
2115
	    } else {
2116
		  $p->setProperty('SUMMARY'			, absences_translate("Vacation"));
2117
	    }
2118
	} else {
2119
		$p->setProperty('SUMMARY'			, absences_translate("Previsonal vacation"));
2120
	}
2121
	$p->setProperty('CATEGORIES'		, $category);
2122
	$p->setProperty('X-CTO-COLOR'		, $color);
2123
	$p->setProperty('X-CTO-VACATION'	, $entry->id);
2124
2125
	if ($entry->comment)
2126
	{
2127
		$p->setProperty('COMMENT'		, $entry->comment);
2128
	}
2129
2130
	$description = '';
2131
	$descriptiontxt = '';
2132
2133
	if ('' === $entry->status) {
2134
		$description .= '<p>'.absences_translate("Waiting to be validated").'</p>';
2135
		$descriptiontxt .= absences_translate("Waiting to be validated")."\n";
2136
	}
2137
2138
2139
2140
	$ventilation = $entry->getElementsIterator();
2141
2142
	$label = (1 === $ventilation->count()) ? absences_translate('Vacations type') : absences_translate('Vacations types');
2143
2144
	$description .= '<table class="bab_cal_vacation_types" cellspacing="0">';
2145
	$description .= '<thead><tr><td colspan="3">'.bab_toHtml($label).'</td></tr></thead>';
2146
	$description .= '<tbody>';
2147
2148
2149
2150
2151
	foreach($ventilation as $element) {
2152
2153
		/*@var $element absences_EntryElem */
2154
2155
		$days = rtrim($element->quantity,'0.');
2156
		$right = $element->getRight();
2157
		$type = $right->getType();
2158
2159
		$description .= sprintf(
2160
				'<tr><td style="background:#%s">&nbsp; &nbsp;</td><td>%s</td><td>%s</td></tr>',
2161
				$type->color,
2162
				$days,
2163
				$type->name
2164
		);
2165
			
2166
		$descriptiontxt .= $days.' '.$type->name."\n";
2167
	}
2168
	$description .= '</tbody></table>';
2169
2170
	$data = array(
2171
			'id' => $entry->id,
2172
			'description' => $description,
2173
			'description_format' => 'html',
2174
			'id_user' => $entry->id_user,
2175
			'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
2176
			'date_end' => $entry->date_end
2177
	);
2178
2179
	$p->setData($data);
2180
2181
	$p->setProperty('DESCRIPTION', $descriptiontxt);
2182
2183
	$p->setProperty('TRANSP','OPAQUE');
2184
}
2185
2186
2187
2188
2189
2190
2191
2192
2193
/**
2194
 * Clear calendar data
2195
 * On non-working days changes by admin
2196
 * On working hours changes by admin
2197
 */
2198
function absences_clearCalendars() {
2199
	global $babDB;
2200
	$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL."");
2201
}
2202
2203
2204
/**
2205
 * Clear calendar data for user
2206
 */
2207
function absences_clearUserCalendar($id_user = NULL) {
2208
	if (NULL === $id_user) {
2209
		$id_user = $GLOBALS['BAB_SESS_USERID'];
2210
	}
2211
	global $babDB;
2212
	$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL." WHERE id_user=".$babDB->quote($id_user));
2213
}
2214
2215
2216
2217
2218
2219
2220
/**
2221
 * si type2 est prioritaire, return true
2222
 */
2223
function absences_compare($type1, $type2, $vacation_is_free) {
2224
2225
	if ($vacation_is_free) {
2226
2227
		$order = array(
2228
				'bab_VacationPeriodCollection'			=> 1,
2229
				'bab_NonWorkingPeriodCollection'		=> 2,
2230
				'bab_WorkingPeriodCollection' 			=> 3,
2231
				'bab_NonWorkingDaysCollection'			=> 6
2232
		);
2233
2234
	} else {
2235
2236
		$order = array(
2237
2238
				'bab_NonWorkingPeriodCollection'		=> 1,
2239
				'bab_WorkingPeriodCollection'			=> 2,
2240
				'bab_VacationPeriodCollection'			=> 5,
2241
				'bab_NonWorkingDaysCollection'			=> 6
2242
		);
2243
2244
	}
2245
2246
2247
	if (!isset($order[$type1]))
2248
	{
2249
		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));
2250
	}
2251
2252
	if (!isset($order[$type2]))
2253
	{
2254
		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));
2255
	}
2256
2257
2258
	if ($order[$type2] > $order[$type1]) {
2259
		return true;
2260
	}
2261
2262
	return false;
2263
}
2264
2265
function absences_is_free($collection) {
2266
2267
2268
	switch(true) {
2269
		case $collection instanceof bab_WorkingPeriodCollection:
2270
			return true;
2271
2272
		case $collection instanceof bab_NonWorkingPeriodCollection:
2273
		case $collection instanceof bab_VacationPeriodCollection:
2274
		case $collection instanceof bab_NonWorkingDaysCollection:
2275
			return false;
2276
	}
2277
}
2278
2279
2280
2281
2282
2283
2284
2285
/**
2286
 * Return arrays with periods for each half-day beetween two dates
2287
 *
2288
 * @param	int				$id_user
2289
 * @param	BAB_dateTime	$dateb
2290
 * @param	BAB_dateTime	$datee
2291
 * @param	boolean			$vacation_is_free
2292
 * @return array
2293
 * 				0 : working periods for each half-day
2294
 * 				1 : only the main period for each half day
2295
 * 				2 : free-busy status for each half day
2296
 * 				3 : periods indexed by type
2297
 *
2298
 */
2299
function absences_getHalfDaysIndex($id_user, BAB_dateTime $dateb, BAB_dateTime $datee, $vacation_is_free = false) {
2300
2301
	global $babDB;
2302
	include_once $GLOBALS['babInstallPath']."utilit/utilit.php";
2303
	include_once $GLOBALS['babInstallPath']."utilit/workinghoursincl.php";
2304
	include_once $GLOBALS['babInstallPath']."utilit/calincl.php";
2305
2306
	$obj = new bab_UserPeriods(
2307
			$dateb,
2308
			$datee
2309
	);
2310
2311
	$factory = bab_getInstance('bab_PeriodCriteriaFactory');
2312
	/* @var $factory bab_PeriodCriteriaFactory */
2313
2314
	$criteria = $factory->Collection(
2315
			array(
2316
					'bab_NonWorkingDaysCollection',
2317
					'bab_NonWorkingPeriodCollection',
2318
					'bab_WorkingPeriodCollection',
2319
					'bab_VacationPeriodCollection'
2320
			)
2321
	);
2322
2323
	$icalendars = bab_getICalendars($id_user);
2324
2325
	$calendar = $icalendars->getPersonalCalendar();
2326
2327
2328
	if (!isset($calendar))
2329
	{
2330
		// the user personal calendar is not accessible
2331
		// create an instance only for vacations
2332
2333
		$calendar = bab_functionality::get('CalendarBackend')->PersonalCalendar($id_user);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class bab_functionality as the method PersonalCalendar() does only exist in the following sub-classes of bab_functionality: Func_CalendarBackend, Func_CalendarBackend_Ovi. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
2334
	}
2335
2336
2337
	$criteria = $criteria->_AND_($factory->Calendar($calendar));
2338
2339
	$obj->createPeriods($criteria);
2340
	$obj->orderBoundaries();
2341
2342
	// working periods for each half-day
2343
	$index_working = array();
2344
2345
	// only the main period for each half day
2346
	$index_reduced = array();
2347
2348
	// free-busy status for each half day
2349
	$is_free = array();
2350
2351
	// periods indexed by type
2352
	$stack = array();
2353
2354
	foreach($obj as $pe) {
2355
2356
		/*@var $pe bab_CalendarPeriod */
2357
2358
		// bab_debug($pe->toHtml(), DBG_TRACE, $dateb->getIsoDateTime().' '.$datee->getIsoDateTime());
2359
2360
		$group = $pe->split(12 * 3600);
2361
		foreach($group as $p) {
2362
				
2363
			/*@var $p bab_CalendarPeriod */
2364
			if ($p->ts_begin < $datee->getTimeStamp() && $p->ts_end > $dateb->getTimeStamp()) {
2365
				$key = date('Ymda',$p->ts_begin);
2366
				$collection = $p->getCollection();
2367
				$type = get_class($collection);
2368
2369
				$stack[$key][$type] = $p;
2370
2371
				if (!isset($index_reduced[$key]) || absences_compare(get_class($index_reduced[$key]->getCollection()), $type, $vacation_is_free)) {
2372
						
2373
					// overwrite reduced index if absences_compare return true
2374
						
2375
					$index_reduced[$key] = $p;
2376
						
2377
					// and reset the free-busy status with the new period
2378
2379
					if (absences_is_free($collection)) {
2380
						$is_free[$key] = 1;
2381
					} elseif (isset($is_free[$key])) {
2382
						unset($is_free[$key]);
2383
					}
2384
				}
2385
2386
2387
				if ($p->getCollection() instanceof bab_WorkingPeriodCollection)
2388
				{
2389
					if (!isset($index_working[$key]))
2390
					{
2391
						$index_working[$key] = array();
2392
					}
2393
						
2394
					$index_working[$key][] = $p;
2395
				}
2396
2397
				// ajust period according to selection
2398
2399
				if ($p->ts_begin < $dateb->getTimeStamp())
2400
				{
2401
					$p->setBeginDate($dateb);
2402
				}
2403
2404
				if ($p->ts_end > $datee->getTimeStamp())
2405
				{
2406
					$p->setEndDate($datee);
2407
				}
2408
			}
2409
		}
2410
	}
2411
2412
2413
	return array($index_working, $index_reduced, $is_free, $stack);
2414
}
2415
2416
2417
2418
2419
function absences_group_insert($query, $exec = false) {
2420
	static $values = array();
2421
	if ($query) {
2422
		$values[] = $query;
2423
	}
2424
2425
	if (300 <= count($values) || (0 < count($values) && $exec)) {
2426
2427
		$GLOBALS['babDB']->db_query("
2428
				INSERT INTO ".ABSENCES_CALENDAR_TBL."
2429
				(id_user, monthkey, cal_date, ampm, period_type, id_entry, color, title)
2430
				VALUES
2431
				".implode(',',$values)."
2432
				");
2433
		$values = array();
2434
	}
2435
}
2436
2437
2438
2439
2440
2441
2442
2443
/**
2444
 * Update planning for the given user
2445
 * and the given period
2446
 * @param int		$id_user
2447
 * @param int		$year
2448
 * @param int		$month
2449
 */
2450
function absences_updateCalendar($id_user, $year, $month) {
2451
2452
	global $babDB;
2453
	include_once $GLOBALS['babInstallPath']."utilit/workinghoursincl.php";
2454
	include_once $GLOBALS['babInstallPath']."utilit/dateTime.php";
2455
2456
2457
	$babDB->db_query("DELETE FROM ".ABSENCES_CALENDAR_TBL." WHERE monthkey=".$babDB->quote($month.$year).' AND id_user='.$babDB->quote($id_user));
2458
2459
	$dateb = new BAB_dateTime($year, $month, 1);
2460
	$datee = $dateb->cloneDate();
2461
	$datee->add(1, BAB_DATETIME_MONTH);
2462
2463
	list(, $index_reduced, , $stack) = absences_getHalfDaysIndex($id_user, $dateb, $datee);
2464
	$previous = NULL;
2465
2466
	foreach($index_reduced as $key => $p) {
2467
2468
		$title		= $p->getProperty('SUMMARY');
2469
		$ampm		= 'pm' === date('a',$p->ts_begin) ? 1 : 0;
2470
		$data		= $p->getData();
2471
		$id_entry	= 0;
2472
		$color		= '';
2473
2474
		$collection = $p->getCollection();
2475
2476
		switch(true) {
2477
			case $collection instanceof bab_WorkingPeriodCollection:
2478
				$type = BAB_PERIOD_WORKING;
2479
				break;
2480
2481
			case $collection instanceof bab_NonWorkingPeriodCollection:
2482
				$type = BAB_PERIOD_NONWORKING;
2483
				break;
2484
2485
			case $collection instanceof bab_VacationPeriodCollection:
2486
				$type = BAB_PERIOD_VACATION;
2487
				break;
2488
2489
			case $collection instanceof bab_NonWorkingDaysCollection:
2490
				$type = BAB_PERIOD_NWDAY;
2491
				if (version_compare(bab_getDbVersion(), '8.1.0', '<'))
2492
				{
2493
					$title = $p->getProperty('DESCRIPTION');
2494
				}
2495
				break;
2496
					
2497
		}
2498
2499
2500
2501
2502
		if ($p->getCollection() instanceof bab_VacationPeriodCollection) {
2503
			if (isset($stack[$key]['bab_WorkingPeriodCollection'])) {
2504
				$id_entry = $data['id'];
2505
2506
				$C = bab_getInstance('absences_EntryColors');
2507
				/*@var $C absences_EntryColors */
2508
2509
				$arr = $C->get($id_entry, $id_user, BAB_DateTime::fromIsoDateTime($data['date_begin']), BAB_DateTime::fromIsoDateTime($data['date_end']), $dateb);
2510
				$color = $arr['color'];
2511
			} else {
2512
				$type = BAB_PERIOD_NONWORKING;
2513
			}
2514
		}
2515
2516
2517
		$key = $id_user.$month.$year.$id_entry.$color.$type;
0 ignored issues
show
Bug introduced by
The variable $type does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2518
2519
		if ($key !== $previous) {
2520
2521
			$previous = $key;
2522
			absences_group_insert("(
2523
					".$babDB->quote($id_user).",
2524
					".$babDB->quote($month.$year).",
2525
					".$babDB->quote(date('Y-m-d',$p->ts_begin)).",
2526
					".$babDB->quote($ampm).",
2527
					".$babDB->quote($type).",
2528
					".$babDB->quote($id_entry).",
2529
					".$babDB->quote($color).",
2530
					".$babDB->quote($title)."
2531
			)");
2532
2533
		}
2534
	}
2535
2536
	absences_group_insert('',true);
2537
}
2538
2539
2540
2541
/**
2542
 * Date printout for periods
2543
 * @param int $timestamp
2544
 * @return string
2545
 */
2546
function absences_longDate($timestamp) {
2547
	if (empty($timestamp)) {
2548
		return '';
2549
	}
2550
2551
	return bab_longDate($timestamp, true);
2552
}
2553
2554
function absences_shortDate($timestamp) {
2555
	if (empty($timestamp)) {
2556
		return '';
2557
	}
2558
2559
	return bab_shortDate($timestamp, true);
2560
}
2561
2562
2563
class absences_RequestDelete
2564
{
2565
    public static function direct(absences_Request $request, $folder)
2566
    {
2567
        if ($folder)
2568
        {
2569
            $allDeleted = true;
2570
            $I = $request->getFolderEntriesIterator();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class absences_Request as the method getFolderEntriesIterator() does only exist in the following sub-classes of absences_Request: absences_Entry. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
2571
            absences_notifyOnRequestChange($I, $request->id_user, true);
2572
        
2573
            foreach($I as $folder_entry)
2574
            {
2575
                /*@var $folder_entry absences_Entry */
2576
                absences_notifyManagers::send($folder_entry->id, true);
2577
                if (!$folder_entry->delete()) {
2578
                    $allDeleted = false;
2579
                }
2580
            }
2581
        
2582
        
2583
        
2584
        
2585
        } else {
2586
        
2587
            absences_notifyManagers::send($request->id, true);
2588
            absences_notifyOnRequestChange(array($request), $request->id_user, true);
2589
            $allDeleted = $request->delete();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $allDeleted is correct as $request->delete() (which targets absences_Request::delete()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
2590
        }
2591
        
2592
        return $allDeleted;
2593
    }
2594
    
2595
    public static function withApproval(absences_Request $request, $folder)
2596
    {
2597
        if ($folder)
2598
        {
2599
            
2600
            $I = $request->getFolderEntriesIterator();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class absences_Request as the method getFolderEntriesIterator() does only exist in the following sub-classes of absences_Request: absences_Entry. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
2601
        
2602
            foreach($I as $folder_entry)
2603
            {
2604
                /*@var $folder_entry absences_Entry */
2605
                $folder_entry->todelete = 1;
2606
                $folder_entry->createApprobationInstance();
2607
            }
2608
2609
        
2610
        } else {
2611
            
2612
            $request->todelete = 1;
2613
            $request->createApprobationInstance();
2614
        }
2615
        
2616
        return true;
2617
    }
2618
}
2619
2620
2621
/**
2622
 * Delete vacation request
2623
 * notify user if vacation not elapsed
2624
 * delete approbation instance
2625
 * Update calendar
2626
 * @param int $id_request
2627
 * @param int $folder
2628
 * @param int $rfrom            1 if the delete request is created by a manager from back office (need to be secured)
2629
 * @return bool
2630
 */
2631
function absences_delete_request($id_request, $folder = 0, $rfrom = 0)
2632
{
2633
	require_once dirname(__FILE__).'/entry.class.php';
2634
	
2635
	$agent = absences_Agent::getCurrentUser();
2636
	
2637
	if (!$agent->isManager()) {
2638
	    $rfrom = 0;
2639
	}
2640
2641
	$request = absences_Entry::getById($id_request);
2642
2643
	if (!$request->getRow())
2644
	{
2645
		throw new Exception(absences_translate('This request does not exists'));
2646
	}
2647
2648
	if ('Y' === $request->status && 0 === $rfrom) {
2649
	    return absences_RequestDelete::withApproval($request, $folder);
2650
	}
2651
2652
	return absences_RequestDelete::direct($request, $folder);
2653
}
2654
2655
2656
2657
/**
2658
 * Try to get a period from the calendar API from the request
2659
 * The calendar backend can contain a period duplicated into the calendarEventCollection with need to be updated or deleted
2660
 * This function can work without access to the personal calendar of the user
2661
 *
2662
 * @param	int				$id_request
2663
 * @param	int				$id_user		search the period in this user personal calendar
2664
 * @param	BAB_DateTime	$begin			request search begin date	(should be the request begin date)
2665
 * @param	BAB_DateTime	$end			request search end date		(should be the request end date)
2666
 *
2667
 * @return bab_CalendarPeriod | null
2668
 */
2669
function absences_getPeriod($id_request, $id_user, BAB_DateTime $begin, BAB_DateTime $end)
2670
{
2671
	require_once $GLOBALS['babInstallPath'].'utilit/calincl.php';
2672
	global $babDB;
2673
2674
	$icalendars = bab_getICalendars($id_user);
2675
2676
	$calendar = $icalendars->getPersonalCalendar();
2677
2678
	if (!$calendar)
2679
	{
2680
		return null;
2681
	}
2682
2683
	$backend = $calendar->getBackend();
2684
2685
	$factory = $backend->Criteria();
2686
	$criteria = $factory->Calendar($calendar);
2687
	$criteria = $criteria->_AND_($factory->Collection('bab_CalendarEventCollection'));
2688
	$criteria = $criteria->_AND_($factory->Begin($begin));
2689
	$criteria = $criteria->_AND_($factory->End($end));
2690
	$criteria = $criteria->_AND_($factory->Property('X-CTO-VACATION', $id_request));
2691
2692
	$periods = $backend->selectPeriods($criteria);
2693
2694
	foreach($periods as $period)
2695
	{
2696
		return $period;
2697
	}
2698
2699
	return null;
2700
}
2701
2702
2703
2704
2705
2706
2707
2708 View Code Duplication
function absences_deleteVacationRequest($id, $manager_view = false)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2709
{
2710
	global $babBody;
2711
	require_once dirname(__FILE__).'/deleterequest.ui.php';
2712
2713
	$babBody->setTitle(absences_translate("Delete vacation request"));
2714
2715
	$temp = new absences_deleteVacationRequestCls($id, $manager_view);
2716
	$babBody->babecho(bab_printTemplate($temp,  absences_addon()->getRelativePath()."request.html", "delete_entry"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
2717
}
2718
2719
2720
2721 View Code Duplication
function absences_deleteCetDepositRequest($id, $manager_view = false)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2722
{
2723
	global $babBody;
2724
	require_once dirname(__FILE__).'/deleterequest.ui.php';
2725
2726
	$babBody->setTitle(absences_translate("Delete a time saving account deposit"));
2727
2728
	$temp = new absences_deleteCetDepositRequestCls($id, $manager_view);
2729
	$babBody->babecho(bab_printTemplate($temp,  absences_addon()->getRelativePath()."request.html", "delete_cetdeposit"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
2730
}
2731
2732
2733
2734 View Code Duplication
function absences_deleteWpRecoveryRequest($id, $manager_view = false)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2735
{
2736
	global $babBody;
2737
	require_once dirname(__FILE__).'/deleterequest.ui.php';
2738
2739
	$babBody->setTitle(absences_translate("Delete a work period recover request"));
2740
2741
	$temp = new absences_deleteWpRecoveryRequestCls($id, $manager_view);
2742
	$babBody->babecho(bab_printTemplate($temp,  absences_addon()->getRelativePath()."request.html", "delete_wprecovery"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
2743
}
2744
2745
2746
2747
2748
2749
2750
function absences_addCoManagerEntities(&$entities, $id_user) {
2751
	global $babDB;
2752
	$res = $babDB->db_query("SELECT id_entity FROM ".ABSENCES_COMANAGER_TBL." WHERE id_user=".$babDB->quote($id_user));
2753
2754
	if (0 == $babDB->db_num_rows($res)) {
2755
		return;
2756
	}
2757
2758
	if (!isset($entities['superior'])) {
2759
		$entities['superior'] = array();
2760
	}
2761
2762
	if (!function_exists('absences_is_superior')) {
2763
		function absences_is_superior($entities, $ide) {
2764
			foreach($entities['superior'] as $e) {
2765
				if ($ide == $e['id']) {
2766
					return true;
2767
				}
2768
			}
2769
			return false;
2770
		}
2771
	}
2772
2773
	while ($arr = $babDB->db_fetch_assoc($res)) {
2774
		$e = bab_OCGetEntity($arr['id_entity']);
2775
		$e['id'] = $arr['id_entity'];
2776
		$e['comanager'] = 1;
2777
		if (!absences_is_superior($entities, $arr['id_entity'])) {
2778
			$entities['superior'][] = $e;
2779
		}
2780
	}
2781
}
2782
2783
2784
2785
2786
2787
/**
2788
 * Get the list of available hours for a user
2789
 * if the id_user parameter is null, return hours list based on site parameters
2790
 *
2791
 * @param	int		$id_user
2792
 *
2793
 * @return array
2794
 */
2795
function absences_hoursList($id_user = null)
2796
{
2797
	global $babDB, $babBody;
2798
2799
	$elapstime = null;
2800
2801
	if (null === $id_user)
2802
	{
2803
		$elapstime = (int) $babBody->babsite['elapstime'];
2804
	} else {
2805
2806
		$res = $babDB->db_query("SELECT elapstime FROM bab_cal_user_options WHERE id_user=".$babDB->quote($id_user));
2807
		if ($arr = $babDB->db_fetch_assoc($res))
2808
		{
2809
			$elapstime = (int) $arr['elapstime'];
2810
		}
2811
	}
2812
2813
	if (!isset($elapstime) || $elapstime === 0)
2814
	{
2815
		$elapstime = 5;
2816
	}
2817
2818
	$list = array();
2819
	$min = 0;
2820
	$hour = 0;
2821
	for ($i = 0; $i < 1440; $i += $elapstime)
2822
	{
2823
		$min += $elapstime;
2824
2825
		if ($min >= 60)
2826
		{
2827
			$hour++;
2828
			$min = 0;
2829
		}
2830
2831
		if (24 === $hour)
2832
		{
2833
			break;
2834
		}
2835
2836
		$list[sprintf('%02d:%02d:00', $hour, $min)] = sprintf('%02d:%02d', $hour, $min);
2837
	}
2838
2839
	// add fixed hours
2840
2841
	$list['00:00:00'] = '00:00';
2842
	$list['11:59:59'] = '11:59';
2843
	$list['12:00:00'] = '12:00';
2844
	$list['23:59:59'] = '23:59';
2845
2846
	ksort($list);
2847
2848
	return $list;
2849
2850
}
2851
2852
/**
2853
 * Display a vacation right quantity in a text input
2854
 * @param float	$quantity	numeric
2855
 * @return string
2856
 */
2857
function absences_editQuantity($quantity, $unit = 'H')
2858
{
2859
	switch($unit)
2860
	{
2861
		case 'D':
2862
			$quantity = (string) round($quantity, 2);
2863
			break;
2864
2865
		case 'H':
2866
			$quantity = (string) round($quantity, 2);
2867
			break;
2868
	}
2869
2870
	if (false !== mb_strpos($quantity, '.'))
2871
	{
2872
		$quantity = rtrim($quantity, '0');
2873
	}
2874
2875
	$quantity = rtrim($quantity, '.');
2876
2877
	if ('' === $quantity) {
2878
		$quantity = '0';
2879
	}
2880
2881
	$quantity = str_replace('.', ',', $quantity);
2882
2883
	return $quantity;
2884
}
2885
2886
2887
2888
2889
2890
2891
2892
2893
/**
2894
 * Display a vacation right quantity
2895
 * @param	string|float	$quantity		numeric
2896
 * @param	string			$unit			D | H
2897
 */
2898
function absences_quantity($quantity, $unit)
2899
{
2900
2901
2902
	switch($unit) {
2903 3
		case 'D':
2904 3
			$unit = absences_translate('day', 'days', floor($quantity));
2905 3
			break;
2906
		case 'H':
2907
			$unit = absences_translate('hour', 'hours', floor($quantity));
2908
2909
			// convertire en heures, minutes plustot que d'afficher des heures a virgules
2910
2911
			$minutes = round(($quantity - floor($quantity)) * 60);
2912
			if (0 != $minutes) {
2913
				$quantity = floor($quantity);
2914
2915
				if (0 == $quantity)
2916
				{
2917
					return $minutes.' '.absences_translate('minutes');
2918
				}
2919
2920
				return $quantity.' '.$unit.' '.$minutes.' '.absences_translate('min');
2921
			}
2922
2923
			break;
2924
	}
2925
2926
2927 3
	if (false !== mb_strpos($quantity, '.'))
2928 3
	{
2929
		$quantity = rtrim($quantity, '0');
2930
	}
2931
2932 3
	$quantity = rtrim($quantity, '.');
2933
2934 3
	if ('' === $quantity) {
2935
		$quantity = '0';
2936
	}
2937
2938 3
	$quantity = str_replace('.', ',', $quantity);
2939
2940 3
	return $quantity.' '.$unit;
2941
}
2942
2943
2944
2945
2946
/**
2947
 * Display a period as a string
2948
 * @param string $begin		ISO datetime
2949
 * @param string $end		ISO datetime
2950
 */
2951
function absences_DateTimePeriod($begin, $end, $funcname = 'bab_shortDate')
2952
{
2953
	$begin_day = mb_substr($begin, 0, 10);
2954
	$end_day = mb_substr($end, 0, 10);
2955
2956
	if ($begin_day === $end_day)
2957
	{
2958
		$begin_hour = mb_substr($begin, 11, 5);
2959
		$end_hour = mb_substr($end, 11, 5);
2960
2961
		return sprintf(absences_translate('The %s from %s to %s'), $funcname(bab_mktime($begin), false), $begin_hour, $end_hour);
2962
	}
2963
2964
	return sprintf(absences_translate('From %s to %s'), $funcname(bab_mktime($begin)), $funcname(bab_mktime($end)));
2965
}
2966
2967
2968
2969
/**
2970
 * Get displayable quantity for one vacation entry
2971
 * @param	int		$id_entry
2972
 * @return string
2973
 */
2974 View Code Duplication
function absences_vacEntryQuantity($id_entry)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2975
{
2976
	global $babDB;
2977
2978
	$res = $babDB->db_query("
2979
			SELECT
2980
			SUM(e.quantity) quantity,
2981
			r.quantity_unit
2982
			FROM
2983
			absences_entries_elem e,
2984
			absences_rights r
2985
			WHERE
2986
			e.id_entry =".$babDB->quote($id_entry)."
2987
			AND r.id = e.id_right
2988
			GROUP BY r.quantity_unit
2989
			ORDER BY r.quantity_unit DESC
2990
			"
2991
	);
2992
2993
	$list = array();
2994
	while ($arr = $babDB->db_fetch_assoc($res))
2995
	{
2996
		$list[] = absences_quantity($arr['quantity'], $arr['quantity_unit']);
2997
	}
2998
2999
	return implode(', ', $list);
3000
}
3001
3002
3003
3004
3005
/**
3006
 * get a list of approvers with same requests to approve
3007
 * @param int $notified Filter by notified status, default value output the unnotified requests
3008
 * @return array
3009
 */
3010
function absences_getRequestsApprovers($notified = 0)
3011
{
3012
	require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
3013
	require_once dirname(__FILE__).'/request.class.php';
3014
3015
3016
	$waitingRequests = new absences_RequestIterator;
3017
	if (isset($notified)) {
3018
	   $waitingRequests->appr_notified = $notified;
3019
	}
3020
	$waitingRequests->idfai_set = true;
3021
3022
	$by_approver = array();
3023
3024
	foreach($waitingRequests as $request)
3025
	{
3026
		/*@var $request absences_Request  */
3027
3028
		$arr = bab_WFGetWaitingApproversInstance($request->idfai);
3029
3030
		foreach($arr as $id_approver)
3031
		{
3032
			if (!isset($by_approver[$id_approver]))
3033
			{
3034
				$by_approver[$id_approver] = array();
3035
			}
3036
				
3037
			$by_approver[$id_approver][get_class($request).'.'.$request->id] = $request;
3038
		}
3039
	}
3040
3041
	// sort by similar request lists
3042
	$by_email = array();
3043
	foreach($by_approver as $id_approver => $arr)
3044
	{
3045
		ksort($arr);
3046
		$keys = array_keys($arr);
3047
		$mailkey = implode(',', $keys);
3048
3049
		if (!isset($by_email[$mailkey]))
3050
		{
3051
			$by_email[$mailkey] = array(
3052
					'approvers' => array(),
3053
					'requests' => array()
3054
			);
3055
		}
3056
		
3057
		$by_email[$mailkey]['approvers'][$id_approver] = $id_approver;
3058
		$by_email[$mailkey]['requests'] += $arr;
3059
	}
3060
3061
	return $by_email;
3062
}
3063
3064
3065
3066
/**
3067
 * formulaire de recherche pour les liste des demandes gestionnaire
3068
 */
3069
class absences_getRequestSearchForm
3070
{
3071
	public function getForm(Array $statarr = null)
3072
	{
3073
		bab_functionality::includeOriginal('Icons');
3074
		$W = bab_Widgets();
3075
		$form = $W->Form(null, $W->FlowLayout()->setSpacing(1, 'em', 3,'em'));
3076
		$form->setSelfPageHiddenFields()->setReadOnly();
3077
3078
		$form->addClass('absences-filterform');
3079
		$form->addClass('widget-bordered');
3080
		$form->addClass('BabLoginMenuBackground');
3081
		$form->addClass('widget-centered');
3082
		$form->addClass(Func_Icons::ICON_LEFT_16);
3083
		$form->colon();
3084
3085
		$form->setCanvasOptions($form->Options()->width(97,'%'));
3086
3087
		if (isset($statarr)) {
3088
		    
3089
		    $options = array('' => '') + $statarr;
3090
		    
3091
    		$form->addItem(
3092
    			$W->LabelledWidget(
3093
    				absences_translate('Status'),
3094
    				$W->Select()
3095
    				->setOptions($options),
3096
    				'idstatus'
3097
    			)
3098
    		);
3099
		}
3100
3101
		$form->addItem(
3102
			$W->LabelledWidget(
3103
				absences_translate('User'),
3104
				$W->UserPicker(),
3105
				'userid'
3106
			)
3107
		);
3108
		
3109
		
3110
		if ($org = $this->organization()) {
3111
		    $form->addItem($org);
3112
		}
3113
3114
		$form->addItem(
3115
			$W->LabelledWidget(
3116
				absences_translate('Date'),
3117
				$W->PeriodPicker()->setNames('dateb', 'datee')
3118
			)
3119
		);
3120
3121
		$values = array(
3122
			'idstatus'       => $this->param('idstatus'),
3123
			'userid'         => (int) $this->param('userid'),
3124
		    'organization'   => (int) $this->param('organization'),
3125
			'dateb'          => $this->param('dateb'),
3126
			'datee'          => $this->param('datee'),
3127
			'vpos'           => (int) $this->param('vpos', 0)
3128
		);
3129
3130
		$form->setValues($values);
3131
		$form->addItem($W->SubmitButton()->setLabel(absences_translate('Search')));
3132
3133
		return $form;
3134
	}
3135
	
3136
	
3137
	/**
3138
	 * 
3139
	 */
3140 View Code Duplication
	protected function organization()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3141
	{
3142
	    require_once dirname(__FILE__).'/organization.class.php';
3143
	    
3144
	    $W = bab_Widgets();
3145
	    $select = $W->Select();
3146
	    $select->addOption('', '');
3147
	    
3148
	    $collections = new absences_OrganizationIterator();
3149
	    
3150
	    if (0 === $collections->count()) {
3151
	        return null;
3152
	    }
3153
	    
3154
	    
3155
	    foreach($collections as $collection) {
3156
	        $select->addOption($collection->id, $collection->name);
3157
	    }
3158
	    
3159
	    return $W->LabelledWidget(
3160
            absences_translate('Organization'),
3161
            $select,
3162
            'organization'
3163
	    );
3164
	    
3165
	}
3166
	
3167
	
3168
	
3169
	public function getHtmlForm(Array $statarr = null)
3170
	{
3171
	    $W = bab_Widgets();
3172
	    $form = $this->getForm($statarr);
3173
	    
3174
	    return $form->display($W->HtmlCanvas());
3175
	}
3176
3177
3178 View Code Duplication
	public function param($name, $default = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
3179
	{
3180
		if (isset($_REQUEST[$name]))
3181
		{
3182
			$_SESSION['babVacation'][$name] = $_REQUEST[$name];
3183
			return $_REQUEST[$name];
3184
		}
3185
3186
		if (isset($_SESSION['babVacation'][$name]))
3187
		{
3188
			return $_SESSION['babVacation'][$name];
3189
		}
3190
3191
		return $default;
3192
	}
3193
}
3194
3195
3196
3197
/**
3198
 * Compare 2 vacation right quantities
3199
 * Soit un float php soit une chaine de mysql float, pour les saisie utilisateur remplacer , par . avant d'appeller la fonction
3200
 *
3201
 * @param	float | string	$qt1
3202
 * @param	float | string	$qt2
3203
 *
3204
 * @return bool
3205
 */
3206
function absences_cq($qt1, $qt2)
3207
{
3208 10
    $qt1 = (float) $qt1;
3209 10
    $qt2 = (float) $qt2;
3210
3211 10
    $v1 = (int) round(100*$qt1);
3212 10
    $v2 = (int) round(100*$qt2);
3213
3214 10
    return ($v1 === $v2);
3215
}
3216