Completed
Push — master ( a12fc9...cb80e3 )
by Paul
03:43
created

absences_saveVacation::addVacationRight()   D

Complexity

Conditions 20
Paths 192

Size

Total Lines 78
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 33
nc 192
nop 5
dl 0
loc 78
rs 4.7705
c 0
b 0
f 0

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
26
27
include_once dirname(__FILE__)."/functions.php";
28
include_once $GLOBALS['babInstallPath']."utilit/afincl.php";
29
include_once $GLOBALS['babInstallPath']."utilit/mailincl.php";
30
include_once dirname(__FILE__)."/utilit/vacincl.php";
31
require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
32
require_once dirname(__FILE__).'/utilit/agent.class.php';
33
require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
34
35
36
37
/**
38
 * 
39
 */
40
function bab_isEntryEditable($id)
41
{
42
	if ($id == 0) {
43
		// request creation
44
		return true;
45
		}
46
47
	$agent = absences_Agent::getCurrentUser();
48
	
49
	require_once dirname(__FILE__).'/utilit/entry.class.php';
50
	$entry = absences_Entry::getById($id);
51
	
52
	
53
	if ($agent->isManager()) {
54
		// le gestionnaire peut tout modifier
55
		return (int) $entry->id_user;
56
	}
57
	
58
	
59
	if ($entry->canModify()) {
60
	    return (int) $entry->id_user;
61
	}
62
	
63
	return false;
64
}
65
66
67
68
/**
69
 * Test if the current logged in user can create a vacation request in the name of $id_user
70
 * @param unknown_type $id_user
71
 * 
72
 * @return bool
73
 */
74
function bab_vacRequestCreate($id_user) {
75
	global $babBody;
76
	
77
	
78
	$target_agent = absences_Agent::getFromIdUser($id_user);
79
80
81
	if (!$target_agent->isInPersonnel()) {
82
		$babBody->addError(sprintf(absences_translate("The user %s is not registered in the personnel members"), $target_agent->getName()));
83
		return false;
84
	}
85
		
86
	if (!$target_agent->haveRights()) {
87
		$babBody->addError(absences_translate("No accessibles vacations rights"));
88
		return false;
89
	}
90
91
	if ($id_user == bab_getUserId()) {
92
		return true;
93
		}
94
	else
95
		{
96
		$current_agent = absences_Agent::getCurrentUser();
97
		if($current_agent->isManager())
98
			{
99
			return true;
100
			}
101
102
		if (absences_getVacationOption('chart_superiors_create_request') && absences_IsUserUnderSuperior($id_user)) {
103
			return true;
104
			}
105
		}
106
107
	$babBody->addError(sprintf(absences_translate("Access denied for %s"), $target_agent->getName()));
108
	return false;
109
	}
110
111
	
112
function absences_recurringVacation($begin, $end, $id)
113
{
114
	global $babBody;
115
	class temp
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type temp has been defined more than once; this definition is ignored, only the first definition in programs/vacadm.php (L38-118) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
116
	{
117
		/**
118
		 * 
119
		 * @var Func_CalendarBackend
120
		 */
121
		private $calendarBackend;
122
		
123
		/**
124
		 * 
125
		 * @var array
126
		 */
127
		private $rrule;
128
		
129
		
130
		public $begin;
131
		public $end;
132
		public $id;
133
		public $duration;
134
		public $id_user;
135
		public $rfrom;
136
		
137
		public $datebegintxt;
138
		public $dateendtxt;
139
		public $t_loaddates;
140
		public $t_daily;
141
		public $t_weekly;
142
		public $t_monthly;
143
		public $t_all_the;
144
		public $t_years;
145
		public $t_months;
146
		public $t_weeks;
147
		public $t_days;
148
		public $repeat_dateendtxt;
149
		public $t_sun;
150
		public $t_mon;
151
		public $t_tue;
152
		public $t_wen;
153
		public $t_thu;
154
		public $t_fri;
155
		public $t_sat;
156
		public $calendar;
157
		public $addvac;
158
		public $t_vacation_request;
159
			
160
		public $calurl;
161
		public $datebegin;
162
		public $dateend;
163
		public $username;
164
		public $nbdays;
165
		public $end_day;
166
		public $end_month;
167
		public $end_year;
168
		public $curyear;
169
		public $ymin;
170
		public $ymax;
171
		public $yearmin;
172
		public $repeat;
173
		public $repeat_n_1;
174
		public $repeat_n_2;
175
		public $repeat_n_3;
176
		public $repeat_wd_checked;
177
		
178
	
179
		public function __construct($begin, $end, $id)
180
		{
181
			global $babBody;
182
			
183
			$this->begin = $begin;
0 ignored issues
show
Bug introduced by
The property begin 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...
184
			$this->end = $end;
0 ignored issues
show
Bug introduced by
The property end 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...
185
			$this->id = $id;
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...
186
			$this->duration = bab_mktime($this->end) - bab_mktime($this->begin);
0 ignored issues
show
Bug introduced by
The property duration 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...
187
			
188
			$this->id_user = bab_pp('id_user');
0 ignored issues
show
Bug introduced by
The property id_user does not seem to exist. Did you mean iduser?

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...
189
			$this->rfrom = bab_pp('rfrom', 0);
0 ignored issues
show
Bug introduced by
The property rfrom 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...
190
			
191
			$this->datebegintxt = absences_translate("Begin date");
0 ignored issues
show
Bug introduced by
The property datebegintxt does not seem to exist. Did you mean begintxt?

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...
192
			$this->dateendtxt = absences_translate("End date");
0 ignored issues
show
Bug introduced by
The property dateendtxt does not seem to exist. Did you mean endtxt?

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...
193
			$this->t_loaddates = absences_translate("Load dates");
0 ignored issues
show
Bug introduced by
The property t_loaddates 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...
194
			$this->t_daily = absences_translate("Daily");
0 ignored issues
show
Bug introduced by
The property t_daily 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...
195
			$this->t_weekly = absences_translate("Weekly");
0 ignored issues
show
Bug introduced by
The property t_weekly 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...
196
			$this->t_monthly = absences_translate("Monthly");
0 ignored issues
show
Bug introduced by
The property t_monthly 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...
197
			$this->t_all_the = absences_translate("Every");
0 ignored issues
show
Bug introduced by
The property t_all_the 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...
198
			$this->t_years = absences_translate("years");
0 ignored issues
show
Bug introduced by
The property t_years 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...
199
			$this->t_months = absences_translate("months");
0 ignored issues
show
Bug introduced by
The property t_months 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...
200
			$this->t_weeks = absences_translate("weeks");
0 ignored issues
show
Bug introduced by
The property t_weeks 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...
201
			$this->t_days = absences_translate("days");
202
			$this->repeat_dateendtxt = absences_translate("Periodicity end date");
0 ignored issues
show
Bug introduced by
The property repeat_dateendtxt does not seem to exist. Did you mean endtxt?

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...
203
			$this->t_sun = mb_substr(absences_translate("Sunday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_sun 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...
204
			$this->t_mon = mb_substr(absences_translate("Monday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_mon 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...
205
			$this->t_tue = mb_substr(absences_translate("Tuesday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_tue 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...
206
			$this->t_wen = mb_substr(absences_translate("Wednesday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_wen 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...
207
			$this->t_thu = mb_substr(absences_translate("Thursday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_thu 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...
208
			$this->t_fri = mb_substr(absences_translate("Friday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_fri 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...
209
			$this->t_sat = mb_substr(absences_translate("Saturday"),0,3);
0 ignored issues
show
Bug introduced by
The property t_sat 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...
210
			$this->calendar = absences_translate("Planning");
0 ignored issues
show
Bug introduced by
The property calendar does not seem to exist. Did you mean t_calendar?

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...
211
			$this->addvac = absences_translate('Confirm the period selection');
212
			$this->t_vacation_request = absences_translate('Create a vacation request on the following periods:');
0 ignored issues
show
Bug introduced by
The property t_vacation_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...
213
			
214
			$this->calurl = bab_toHtml(absences_addon()->getUrl()."planning&idx=cal&idu=".$this->id_user."&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...
Bug introduced by
The property id_user does not seem to exist. Did you mean iduser?

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...
215
			
216
			$this->datebegin = absences_longDate(bab_mktime($begin));
0 ignored issues
show
Bug introduced by
The property datebegin 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...
217
			$end_timestamp = bab_mktime($end);
218
			$this->dateend = absences_longDate($end_timestamp);
0 ignored issues
show
Bug introduced by
The property dateend 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...
219
			
220
221
			$this->username = bab_toHtml(bab_getUserName($this->id_user));
0 ignored issues
show
Bug introduced by
The property id_user does not seem to exist. Did you mean iduser?

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...
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...
222
			
223
			$this->nbdays = 31;
0 ignored issues
show
Bug introduced by
The property nbdays does not seem to exist. Did you mean nbdaystxt?

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...
224
			$this->end_day = bab_pp('repeat_dayend', date('d', $end_timestamp));
0 ignored issues
show
Bug introduced by
The property end_day 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...
225
			$this->end_month = bab_pp('repeat_monthend', date('m', $end_timestamp));
0 ignored issues
show
Bug introduced by
The property end_month 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...
226
			$this->end_year = bab_pp('repeat_yearend', date('Y', $end_timestamp));
0 ignored issues
show
Bug introduced by
The property end_year 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...
227
			
228
			
229
			$this->curyear = date('Y');
0 ignored issues
show
Bug introduced by
The property curyear 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...
230
			
231
			$this->ymin = 2;
0 ignored issues
show
Bug introduced by
The property ymin 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...
232
			$this->ymax = 5;
0 ignored issues
show
Bug introduced by
The property ymax 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...
233
			$this->yearmin = $this->curyear - $this->ymin;
0 ignored issues
show
Bug introduced by
The property yearmin 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...
234
			
235
			
236
			$this->repeat = (int) bab_pp('repeat', 1);
0 ignored issues
show
Bug introduced by
The property repeat 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...
237
			$this->repeat_n_1 = bab_pp('repeat_n_1');
0 ignored issues
show
Bug introduced by
The property repeat_n_1 does not seem to exist. Did you mean repeat?

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...
238
			$this->repeat_n_2 = bab_pp('repeat_n_2');
0 ignored issues
show
Bug introduced by
The property repeat_n_2 does not seem to exist. Did you mean repeat?

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...
239
			$this->repeat_n_3 = bab_pp('repeat_n_3');
0 ignored issues
show
Bug introduced by
The property repeat_n_3 does not seem to exist. Did you mean repeat?

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...
240
			
241
			$weekdays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
242
			$repeat_wd = (array) bab_pp('repeat_wd', array());
243
			$repeat_wd = array_flip($repeat_wd);
244
			$this->repeat_wd_checked = array();
0 ignored issues
show
Bug introduced by
The property repeat_wd_checked does not seem to exist. Did you mean repeat?

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...
245
			
246
			foreach($weekdays as $wd)
247
			{
248
				$this->repeat_wd_checked[$wd] = isset($repeat_wd[$wd]) ? 'checked="checked"' : '';
0 ignored issues
show
Bug introduced by
The property repeat_wd_checked does not seem to exist. Did you mean repeat?

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...
249
			}
250
			
251
			if (isset($_POST['loaddates']))
252
			{
253
				$backendName = bab_getICalendars($this->id_user)->calendar_backend;
0 ignored issues
show
Bug introduced by
The property id_user does not seem to exist. Did you mean iduser?

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...
254
				if (!$backendName)
255
				{
256
					$backendName = 'Ovi';
257
				}
258
				
259
				$this->calendarBackend = bab_functionality::get('CalendarBackend/'.$backendName);
0 ignored issues
show
Bug introduced by
The property calendarBackend 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...
260
				
261
				try {
262
					$this->rrule = $this->loaddates();
0 ignored issues
show
Bug introduced by
The property rrule 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...
Bug introduced by
The method loaddates() does not seem to exist on object<temp>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
263
					$this->dates_loaded = true;
0 ignored issues
show
Bug introduced by
The property dates_loaded 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...
264
				} catch (ErrorException $e)
265
				{
266
					$babBody->addError($e->getMessage());
267
				}
268
				
269
			}
270
		}
271
		
272
		/**
273
		 * Get an array with posted rules
274
		 * @return array
275
		 */
276
		private function getPostedRecurringParameters()
277
		{
278
			$args = array();
279
			
280
281
			$args['until'] = array(
282
					'year'	=> (int) $_POST['repeat_yearend'],
283
					'month'	=> (int) $_POST['repeat_monthend'],
284
					'day'	=> (int) $_POST['repeat_dayend']
285
			);
286
		
287
			$_POST['repeat'] = isset($_POST['repeat']) ? $_POST['repeat'] : '';
288
			switch ($_POST['repeat']) {
289
		
290
				case ABSENCES_RECUR_WEEKLY:
291
					$args['rrule'] = ABSENCES_RECUR_WEEKLY;
292
					if( empty($_POST['repeat_n_2']))
293
					{
294
						$_POST['repeat_n_2'] = 1;
295
					}
296
		
297
					$args['nweeks'] = (int) $_POST['repeat_n_2'];
298
		
299
					if( isset($_POST['repeat_wd']) )
300
					{
301
						$args['rdays'] = $_POST['repeat_wd'];
302
					}
303
		
304
					break;
305
		
306
				case ABSENCES_RECUR_MONTHLY: 
307
					$args['rrule'] = ABSENCES_RECUR_MONTHLY;
308
					if( empty($_POST['repeat_n_3']))
309
					{
310
						$_POST['repeat_n_3'] = 1;
311
					}
312
		
313
					$args['nmonths'] = (int) $_POST['repeat_n_3'];
314
					break;
315
		
316
				case ABSENCES_RECUR_YEARLY:
317
					$args['rrule'] = ABSENCES_RECUR_YEARLY;
318
					if( empty($_POST['repeat_n_4']))
319
					{
320
						$_POST['repeat_n_4'] = 1;
321
					}
322
					$args['nyears'] = (int) $_POST['repeat_n_4'];
323
					break;
324
		
325
				case ABSENCES_RECUR_DAILY:
326
				default:
327
					$args['rrule'] = ABSENCES_RECUR_DAILY;
328
					if( empty($_POST['repeat_n_1']))
329
					{
330
						$_POST['repeat_n_1'] = 1;
331
					}
332
		
333
					$args['ndays'] = (int) $_POST['repeat_n_1'];
334
					break;
335
			}
336
			
337
			
338
			
339
			return $args;
340
		}
341
		
342
		
343
		/**
344
		 * Convert posted data to a standard RRULE icaldendar property
345
		 * @throws ErrorException
346
		 */
347
		private function getRRule()
348
		{
349
			$args = $this->getPostedRecurringParameters();
0 ignored issues
show
Bug introduced by
The method getPostedRecurringParameters() does not seem to exist on object<temp>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
350
			
351
			if(!isset($args['rrule']) ) {
352
				return null;
353
			}
354
355
			$duration = $this->duration;
356
			$rrule = array();
357
		
358
			switch( $args['rrule'] )
359
			{
360
				case ABSENCES_RECUR_WEEKLY:
361
					if( $duration > 24 * 3600 * 7 * $args['nweeks']) {
362
						throw new ErrorException(absences_translate("The duration of the event must be shorter than how frequently it occurs"));
363
					}
364
		
365
					$rrule[]= 'INTERVAL='.$args['nweeks'];
366
		
367
					if( !isset($args['rdays']) ) {
368
						// no week day specified, reapeat event every week
369
						$rrule[]= 'FREQ=WEEKLY';
370
					}
371
					else {
372
						$rrule[]= 'FREQ=WEEKLY';
373
						// BYDAY : add list of weekday    = "SU" / "MO" / "TU" / "WE" / "TH" / "FR" / "SA"
374
						$rrule[] = 'BYDAY='.implode(',', $args['rdays']);
375
					}
376
		
377
					break;
378
		
379
		
380 View Code Duplication
				case ABSENCES_RECUR_MONTHLY:
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...
381
					if( $duration > 24*3600*28*$args['nmonths']) {
382
						throw new ErrorException(absences_translate("The duration of the event must be shorter than how frequently it occurs"));
383
					}
384
		
385
					$rrule[]= 'INTERVAL='.$args['nmonths'];
386
					$rrule[]= 'FREQ=MONTHLY';
387
					break;
388
		
389 View Code Duplication
				case ABSENCES_RECUR_YEARLY: /* yearly */
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...
390
		
391
					if( $duration > 24*3600*365*$args['nyears']) {
392
						throw new ErrorException(absences_translate("The duration of the event must be shorter than how frequently it occurs"));
393
					}
394
					$rrule[]= 'INTERVAL='.$args['nyears'];
395
					$rrule[]= 'FREQ=YEARLY';
396
					break;
397
		
398 View Code Duplication
				case ABSENCES_RECUR_DAILY: /* daily */
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...
399
					if( $duration > 24*3600*$args['ndays'] ) {
400
						throw new ErrorException(absences_translate("The duration of the event must be shorter than how frequently it occurs"));
401
					}
402
					$rrule[]= 'INTERVAL='.$args['ndays'];
403
					$rrule[]= 'FREQ=DAILY';
404
					break;
405
			}
406
		
407
		
408
			
409
			if (isset($args['until'])) {
410
			
411
				$until = self::getDateTime($args['until']);
0 ignored issues
show
Bug introduced by
The method getDateTime() does not seem to exist on object<temp>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
412
				$until->add(1, BAB_DATETIME_DAY);
413
			
414
				if( $until->getTimeStamp() < bab_mktime($this->end)) {
415
					throw new ErrorException(absences_translate("Repeat date must be older than end date"));
416
				}
417
			
418
			
419
				$rrule[] = 'UNTIL='.$until->getICal(true);
420
			}
421
			
422
			return implode(';',$rrule);
423
		}
424
		
425
		
426
		/**
427
		 * Get dateTime object from date as array with keys
428
		 * <ul>
429
		 *	<li>year</li>
430
		 *	<li>month<li>
431
		 *	<li>day</li>
432
		 *	<li>hours (optional)</li>
433
		 *	<li>minutes (optional)</li>
434
		 * <ul>
435
		 *
436
		 *
437
		 * @param	array	$arr
438
		 *
439
		 * @param	int		$default_ts default timestamp value to use if values of date are not set
440
		 *
441
		 * @return 	BAB_DateTime
442
		 */
443
		public static function getDateTime($arr, $default_ts = null) {
444
		
445
		
446
			if (!isset($default_ts) && (!isset($arr['year']) || !isset($arr['month']) || !isset($arr['day']))) {
447
				return null;
448
			}
449
		
450
			if (!isset($arr['year'])) {
451
				$arr['year'] = date('Y', $default_ts);
452
			}
453
		
454
			if (!isset($arr['month'])) {
455
				$arr['month'] = date('m', $default_ts);
456
			}
457
		
458
			if (!isset($arr['day'])) {
459
				$arr['day'] = date('d', $default_ts);
460
			}
461
		
462
			if (!isset($arr['hours'])) {
463
				$arr['hours'] = 0;
464
			}
465
		
466
			if (!isset($arr['minutes'])) {
467
				$arr['minutes'] = 0;
468
			}
469
		
470
			return new BAB_DateTime($arr['year'], $arr['month'], $arr['day'], $arr['hours'],$arr['minutes']);
471
		}
472
		
473
		
474
		/**
475
		 * @return RRule
476
		 */
477
		private function loaddates()
478
		{
479
			if (null === $rrule = $this->getRRule())
0 ignored issues
show
Bug introduced by
The method getRRule() does not seem to exist on object<temp>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
480
			{
481
				return null;
482
			}
483
			
484
			$arr = array();
485
			
486
			
487
			require_once dirname(__FILE__).'/utilit/RRule.php';
488
			
489
			$o = new RRule(new iCalDate(bab_mktime($this->begin)), $rrule);
490
			
491
			
492
			while($date = $o->GetNext())
493
			{
494
				$begin = BAB_DateTime::fromIsoDateTime($date->Render());
495
				$end = clone $begin;
496
				$end->add($this->duration, BAB_DATETIME_SECOND);
497
				
498
				// do not add the unavailable periods
499
				
500
				$hd_index = absences_getHalfDaysIndex($this->id_user, $begin, $end);
0 ignored issues
show
Bug introduced by
The property id_user does not seem to exist. Did you mean iduser?

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...
501
				
502
				if (count($hd_index[2]) > 0) // free half day on the requested period
503
				{
504
					$arr[$begin->getTimeStamp()] = array($begin, $end);
505
				}
506
			}
507
			
508
			ksort($arr);
509
			
510
			return $arr;
511
		}
512
		
513
		
514
		public function getnextday()
515
		{
516
			static $i = 1;
517
			if( $i <= $this->nbdays)
0 ignored issues
show
Bug introduced by
The property nbdays does not seem to exist. Did you mean nbdaystxt?

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...
518
			{
519
				$this->dayid = $i;
520
				if($this->end_day == $i)
521
				{
522
					$this->selected = "selected";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
523
				}
524
				else
525
					$this->selected = "";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
526
		
527
				$i++;
528
				return true;
529
			}
530
			else
531
			{
532
				$i = 1;
533
				return false;
534
			}
535
		
536
		}
537
		
538
		public function getnextmonth()
539
		{
540
			static $i = 1;
541
		
542
			if( $i < 13)
543
			{
544
				$this->monthid = $i;
545
				$this->monthname = bab_toHtml(bab_DateStrings::getMonth($i));
546
				if($this->end_month == $i)
547
				{
548
					$this->selected = "selected";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
549
				}
550
				else
551
					$this->selected = "";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
552
		
553
				$i++;
554
				return true;
555
			}
556
			else
557
			{
558
				$i = 1;
559
				return false;
560
			}
561
		
562
		}
563
		
564
		public function getnextyear()
565
		{
566
			static $i = 0;
567
			if( $i < $this->ymin + $this->ymax + 1)
568
			{
569
				$this->yearidval = ($this->yearmin + $i);
570
				$this->yearid = $this->yearidval;
0 ignored issues
show
Bug introduced by
The property yearid does not seem to exist. Did you mean yearidval?

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...
571
				if($this->end_year == $this->yearidval)
572
				{
573
					$this->selected = "selected";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
574
				}
575
				else
576
					$this->selected = "";
0 ignored issues
show
Bug introduced by
The property selected does not seem to exist. Did you mean yselected?

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...
577
				$i++;
578
				return true;
579
			}
580
			else
581
			{
582
				$i = 0;
583
				return false;
584
			}
585
		
586
		}
587
		
588
	
589
		/**
590
		 * list periods computed from posted recurring parameters
591
		 */
592
		public function getnextperiod()
593
		{
594
			if (isset($this->rrule) && list(,$arr) = each($this->rrule))
595
			{
596
				$begin = $arr[0];
597
				$end = $arr[1];
598
				
599
				$this->p_begin = $begin->getIsoDateTime();
0 ignored issues
show
Bug introduced by
The property p_begin 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->p_end = $end->getIsoDateTime();
0 ignored issues
show
Bug introduced by
The property p_end 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...
601
				
602
				$this->period = sprintf(absences_translate('from %s to %s'), $begin->shortFormat(), $end->shortFormat());
0 ignored issues
show
Bug introduced by
The property period 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->checked = (isset($_POST['loaddates']) || isset($_POST['period'][$this->p_begin]));
0 ignored issues
show
Bug introduced by
The property checked 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
				return true;
605
			}
606
			return false;
607
		}
608
	
609
	}
610
	
611
	$temp = new temp($begin,$end, $id);
0 ignored issues
show
Bug introduced by
The call to temp::temp() misses some required arguments starting with $description.
Loading history...
612
	$babBody->babecho(	bab_printTemplate($temp, absences_addon()->getRelativePath()."vacuser.html", "recurring"));
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...
613
}
614
	
615
	
616
617
618
619
class absences_RequestVacation
620
{
621
622
	public $recurring;
623
	
624
	
625
	/**
626
	 * @var array
627
	 */
628
	public $rights;
629
	
630
	/**
631
	 * @var array
632
	 */
633
	public $right;
634
	
635
	public $id;
636
	public $id_user;
637
	public $ide;
638
	public $username;
639
	
640
	public $datebegintxt;
641
	public $dateendtxt;
642
	public $vactype;
643
	public $addvac;
644
	public $save_previsional;
645
	public $remark;
646
	public $nbdaystxt;
647
	public $invaliddate;
648
	public $invaliddate2;
649
	public $invalidentry;
650
	public $invalidentry1;
651
	public $invalidentry2;
652
	public $invalidentry3;
653
	public $totaltxt;
654
	public $balancetxt;
655
	public $previsionalbalancetxt;
656
	public $calendar;
657
	public $total_days;
658
	public $total_hours;
659
	public $maxallowed;
660
	public $t_days;
661
	public $t_alert_nomatch;
662
	public $t_confirm_nomatch;
663
	public $t_or;
664
	public $t_recurring;
665
	public $t_recurring_help;
666
	public $t_previsional;
667
	public $t_no_approval;
668
	public $t_force_approval;
669
	public $allow_mismatch;
670
671
672
	public function __construct($begin, $end, $id)
673
	{
674
		global $babBody, $babDB;
675
		require_once dirname(__FILE__).'/utilit/entry.class.php';
676
677
		$begin = $this->formatInputDate($begin);
678
		$end = $this->formatInputDate($end);
679
680
681
		if ($end < date('Y-m-d H:i:s') && !$id)
682
		{
683
			$babBody->addMessage(absences_translate('Warning, the request is in the past, do you really want to create a request at this date?'));
684
		}
685
686
		$this->recurring = (!empty($_POST['period']) && is_array($_POST['period']));
687
		$nb_request = $this->recurring ? count($_POST['period']) : 1;
688
689
		$this->datebegintxt = absences_translate("Begin date");
690
		$this->dateendtxt = absences_translate("End date");
691
		$this->vactype = absences_translate("Vacation type");
692 View Code Duplication
		if ($id)
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...
693
		{
694
			$this->addvac = absences_translate("Edit vacation request");
695
			$this->save_previsional = absences_translate("Edit previsional request");
696
		} else {
697
			$this->addvac = absences_translate("Send vacation request");
698
			$this->save_previsional = absences_translate("Save previsional request");
699
		}
700
		$this->remark = absences_translate("Description:");
701
		$this->nbdaystxt = absences_translate("Quantity");
702
		$this->invaliddate = bab_toHtml(absences_translate("ERROR: End date must be older"), BAB_HTML_JS);
703
		$this->invaliddate2 = bab_toHtml(absences_translate("Total number of days does not fit between dates"), BAB_HTML_JS);
704
		$this->invalidentry = bab_toHtml(absences_translate("Invalid entry!  Only numbers are accepted or . !"), BAB_HTML_JS);
705
		$this->invalidentry1 = absences_translate("Invalid entry");
706
		$this->invalidentry2 = absences_translate("Days must be multiple of 0.5");
707
		$this->invalidentry3 = absences_translate("The number of days exceed the total allowed");
708
		$this->totaltxt = absences_translate("Total:");
709
		$this->balancetxt = absences_translate("Balance");
710
		$this->previsionalbalancetxt = absences_translate("Previsional balance");
711
		$this->calendar = absences_translate("Planning");
712
		$this->total_days = 0;
713
		$this->total_hours = 0;
714
		$this->maxallowed = 0;
715
		$this->id = $id;
716
		$this->id_user = $_POST['id_user'];
717
		$this->ide = bab_pp('ide');
718
		$this->username = bab_toHtml(bab_getUserName($this->id_user));
719
		$this->t_days = absences_translate("working days");
720
		$this->t_alert_nomatch = bab_toHtml(absences_translate("Total number of affected days does not match the period."),BAB_HTML_JS);
721
		$this->t_confirm_nomatch = bab_toHtml(absences_translate("Total number of affected days does not match the period, do you really want to submit your request with this mismatch?"),BAB_HTML_JS);
722
		$this->t_or = absences_translate('Or');
723
		$this->t_recurring = absences_translate('All periods:');
724
		$this->t_recurring_help = absences_translate('The allocation is made on a single period, the other will be reserved with the same configuration');
725
		$this->t_previsional = absences_translate('Previsional request (will not be sent to approval)', 'Previsional requests (will not be sent to approval)', $nb_request);
726
		$this->t_no_approval = absences_translate('This right do not require approval');
727
        $this->t_force_approval = absences_translate('Launch the approval process on this request');
728
729
		$this->allow_mismatch = absences_getVacationOption('allow_mismatch');
730
731
        
732
733
		if (empty($this->id))
734
		{
735
736
			// create a new entry (not saved)
737
			$entry = new absences_Entry();
738
			$entry->setRow(array(
739
					'id_user' 	 => $this->id_user,
740
					'date_begin' => $begin,
741
					'date_end'	 => $end
742
			));
743
744
			$this->previsional = true;
0 ignored issues
show
Bug introduced by
The property previsional does not seem to exist. Did you mean save_previsional?

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...
745
			$this->previsional_checked = isset($_POST['previsional']);
0 ignored issues
show
Bug introduced by
The property previsional_checked 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...
746
747
			$this->upd_recurring = false;
0 ignored issues
show
Bug introduced by
The property upd_recurring does not seem to exist. Did you mean recurring?

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...
748
749
		} else {
750
			$entry = absences_Entry::getById($this->id);
751
			$dates_modified = ($entry->date_begin !== $begin || $entry->date_end !== $end);
752
753
			$entry->date_begin = $begin;
754
			$entry->date_end = $end;
755
			if ($this->previsional = $entry->isPrevisonal())
0 ignored issues
show
Bug introduced by
The property previsional does not seem to exist. Did you mean save_previsional?

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...
756
			{
757
				$this->previsional_checked = true;
758
			}
759
760
			if ($entry->folder && !$dates_modified)
761
			{
762
				$this->t_upd_recurring = absences_translate('Update description and rights for all periods with same total quantity in the recurring request');
0 ignored issues
show
Bug introduced by
The property t_upd_recurring does not seem to exist. Did you mean recurring?

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...
763
				$this->upd_recurring = true;
0 ignored issues
show
Bug introduced by
The property upd_recurring does not seem to exist. Did you mean recurring?

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...
764
			} else {
765
				$this->upd_recurring = false;
0 ignored issues
show
Bug introduced by
The property upd_recurring does not seem to exist. Did you mean recurring?

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...
766
			}
767
		}
768
769
770
		$days = $entry->getDurationDays();
771
		$hours = $entry->getDurationHours();
772
773
774
775
		$this->period_nbdays = $days;
0 ignored issues
show
Bug introduced by
The property period_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...
776
		$this->period_nbhours = $hours;
0 ignored issues
show
Bug introduced by
The property period_nbhours 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...
777
778
		/**
779
		 * nombre de jours non utilises restant, initialisation
780
		 */
781
		$this->last_days = $days;
0 ignored issues
show
Bug introduced by
The property last_days does not seem to exist. Did you mean t_days?

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...
782
783
		/**
784
		 * nombre d'heures non utilises restantes, initialisation
785
		 */
786
		$this->last_hours = $hours;
0 ignored issues
show
Bug introduced by
The property last_hours 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...
787
788
789
		$this->t_days = absences_translate("Day(s)");
790
791
792
793
		$this->begin		= $entry->date_begin;
0 ignored issues
show
Bug introduced by
The property begin 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...
794
		$this->end			= $entry->date_end;
0 ignored issues
show
Bug introduced by
The property end 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...
795
796
		$this->rfrom = isset($_POST['rfrom'])? $_POST['rfrom'] : 0;
0 ignored issues
show
Bug introduced by
The property rfrom 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...
797
		$this->rights = array();
798
		$rights = absences_getRightsOnPeriod($this->begin, $this->end, $this->id_user, $this->rfrom);
799
800
		$this->contain_hours_rights = false;
0 ignored issues
show
Bug introduced by
The property contain_hours_rights 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...
801
802
		$this->no_approval_message = false;
0 ignored issues
show
Bug introduced by
The property no_approval_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...
803
		$one_approval = false;
804
805
806
		foreach($rights as $right) {
807
			$id		= empty($right['id_rgroup']) ? 'r'.$right['id'] : 'g'.$right['id_rgroup'];
808
809
			if ('H' === $right['quantity_unit'])
810
			{
811
				$this->contain_hours_rights = true;
0 ignored issues
show
Bug introduced by
The property contain_hours_rights 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...
812
			}
813
814
			if (isset($this->rights[$id])) {
815
				$this->rights[$id]['rights'][$right['id']] = array(
816
					'description'			=> $right['description'],
817
					'quantity_available'	=> $right['quantity_available'] - $right['waiting'],
818
			        'previsional_available'	=> $right['quantity_available'] - $right['agentRight']->getPrevisionalQuantity() - $right['waiting'],
819
			        'sortkey'               => $this->getOptionSortKey($right)
820
				);
821
				continue;
822
823
			} elseif(!empty($right['id_rgroup'])) {
824
			    
825
			    // les droits avec regroupement sont ajoutes dans ['rights']
826
			    
827
			    
828
				$right['rights'] = array(
829
					$right['id'] => array(
830
						'description' 			=> $right['description'],
831
						'quantity_available'	=> $right['quantity_available'] - $right['waiting'],
832
				        'previsional_available'	=> $right['quantity_available'] - $right['agentRight']->getPrevisionalQuantity() - $right['waiting'],
833
				        'sortkey'               => $this->getOptionSortKey($right)
834
					)
835
				);
836
			}
837
838
			$this->rights[$id] = $right;
839
840
			$agentRight = $right['agentRight'];
841
			if (0 === (int) $agentRight->getRight()->require_approval) {
842
				$this->no_approval_message = true;
843
			} else {
844
			    $one_approval = true;
845
			}
846
			
847
			
848
		}
849
		
850
		
851
		$author = absences_Agent::getCurrentUser();
852
		$this->manager_propose_approval = ($author->isManager() && $one_approval && $this->rfrom);
0 ignored issues
show
Bug introduced by
The property manager_propose_approval 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...
853
		
854
		
855
		if (empty($this->rights)) {
856
			$babBody->addError(absences_translate('No rights accessibles on this period'));
857
		}
858
859
860
		bab_Sort::asort($this->rights, 'sortkey');
861
862
863
		$s_days = sprintf('<strong>%s</strong>', absences_editQuantity($days, 'D'));
864
		$s_hours = sprintf('<strong>%s</strong>', absences_editQuantity($hours, 'H'));
865
866
		$r_days = sprintf('<strong>%s</strong>', absences_editQuantity($nb_request*$days, 'D'));
867
		$r_hours = sprintf('<strong>%s</strong>', absences_editQuantity($nb_request*$hours, 'H'));
868
869
870
		if ($this->contain_hours_rights)
0 ignored issues
show
Bug introduced by
The property contain_hours_rights 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...
871
		{
872
			$this->period_infos = sprintf(absences_translate('The period contain %s day(s) or %s hour(s)', 'Each period contain %s day(s) or %s hour(s)', $nb_request), $s_days, $s_hours);
0 ignored issues
show
Bug introduced by
The property period_infos 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...
873
			$this->recurring_total = sprintf(absences_translate('Total in all periods: %s day(s) or %s hour(s)'), $r_days, $r_hours);
0 ignored issues
show
Bug introduced by
The property recurring_total does not seem to exist. Did you mean recurring?

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...
874
		} else {
875
			$this->period_infos = sprintf(absences_translate('The period contain %s day(s)', 'Each period contain %s day(s)', $nb_request), $s_days);
876
			$this->recurring_total = sprintf(absences_translate('All periods contains %s day(s)'), $r_days);
0 ignored issues
show
Bug introduced by
The property recurring_total does not seem to exist. Did you mean recurring?

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...
877
		}
878
879
880
881
		if (!empty($this->id))
882
		{
883
			$res = $babDB->db_query("SELECT id_right, quantity FROM ".ABSENCES_ENTRIES_ELEM_TBL." WHERE id_entry='".$babDB->db_escape_string($this->id)."'");
884
			while ($arr = $babDB->db_fetch_array($res))
885
			{
886
				$this->current['r'.$arr['id_right']] = $arr['quantity'];
0 ignored issues
show
Bug introduced by
The property current 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...
887
			}
888
		}
889
890
		$this->recorded = array();
0 ignored issues
show
Bug introduced by
The property recorded 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...
891
		if (!empty($this->id))
892
		{
893
			$res = $babDB->db_query("
894
					SELECT
895
					e.id_right,
896
					r.id_rgroup,
897
					e.quantity
898
					FROM
899
					".ABSENCES_ENTRIES_ELEM_TBL." e,
900
					".ABSENCES_RIGHTS_TBL." r
901
902
					WHERE
903
					e.id_entry='".$babDB->db_escape_string($this->id)."'
904
					AND e.id_right = r.id
905
					");
906
			while($arr = $babDB->db_fetch_array($res))
907
			{
908
				if (empty($arr['id_rgroup'])) {
909
					$this->recorded['r'.$arr['id_right']] = $arr['quantity'];
910
				} else {
911
					$this->recorded['g'.$arr['id_rgroup']] = $arr['quantity'];
912
				}
913
			}
914
915
			list($this->remarks) = $babDB->db_fetch_array($babDB->db_query("SELECT comment FROM ".ABSENCES_ENTRIES_TBL." WHERE id=".$babDB->quote($this->id)));
0 ignored issues
show
Bug introduced by
The property remarks does not seem to exist. Did you mean remark?

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...
916
		}
917
		else
918
		{
919
			$this->remarks = isset($_POST['remarks']) ? stripslashes($_POST['remarks']) : '';
0 ignored issues
show
Bug introduced by
The property remarks does not seem to exist. Did you mean remark?

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...
920
		}
921
922
		$this->datebegin = absences_longDate(bab_mktime($begin));
0 ignored issues
show
Bug introduced by
The property datebegin does not seem to exist. Did you mean datebegintxt?

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...
923
		$this->dateend = absences_longDate(bab_mktime($end));
0 ignored issues
show
Bug introduced by
The property dateend does not seem to exist. Did you mean dateendtxt?

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...
924
925
926
		$this->calurl = absences_addon()->getUrl()."planning&idx=cal&idu=".$this->id_user."&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...
927
928
	}
929
	
930
	
931
	private function getOptionSortKey(Array $right)
932
	{
933
	    // T8618 ordonner en fonction de la date de fin de validite
934
	     
935
	    $sortkey = $right['date_end_valid'];
936
	    if ('0000-00-00' === $sortkey) {
937
	        $sortkey = $right['date_end'];
938
	    }
939
	    
940
	    $sortkey .= ' '.$right['description'];
941
	    
942
	    return $sortkey;
943
	}
944
	
945
946
947
	/**
948
	 * Correct errors in the DATETIME format
949
	 * @param string $str
950
	 * @return string
951
	 */
952
	private function formatInputDate($str)
953
	{
954
	    $m = null;
955
		preg_match('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', $str, $m);
956
		return sprintf('%04d-%02d-%02d %02d:%02d:%02d', $m[1], $m[2], $m[3], $m[4], $m[5], $m[6]);
957
	}
958
959
960
961
	/**
962
	 * Convert days to hours
963
	 * @param float $days
964
	 * @return float
965
	 */
966 View Code Duplication
	private function daysToHours($days)
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...
967
	{
968
		if (0 == $this->period_nbdays)
969
		{
970
			return 0;
971
		}
972
973
		$ratio = $this->period_nbhours / $this->period_nbdays;
974
		return round(($ratio * $days), 2);
975
	}
976
977
	/**
978
	 * Convert hours to days
979
	 * @param float $hours
980
	 * @return float
981
	 */
982 View Code Duplication
	private function hoursToDays($hours)
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...
983
	{
984
		if (0 == $this->period_nbhours)
985
		{
986
			return 0;
987
		}
988
989
		$ratio = $this->period_nbdays / $this->period_nbhours;
990
		return round(($ratio * $hours), 2);
991
	}
992
993
	/**
994
	 *
995
	 * @param string 	$unit		D | H
996
	 * @param float		$set
997
	 *
998
	 * @return float | null
999
	 */
1000
	private function last($unit = null, $set = null)
1001
	{
1002
		if (null === $set)
1003
		{
1004
			switch($unit)
1005
			{
1006
				case 'D':
1007
					return $this->last_days;
0 ignored issues
show
Bug introduced by
The property last_days does not seem to exist. Did you mean t_days?

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...
1008
1009
				case 'H':
1010
					return $this->last_hours;
1011
			}
1012
		}
1013
		else
1014
		{
1015
			switch($unit)
1016
			{
1017
				case 'D':
1018
					$this->last_days = $set;
0 ignored issues
show
Bug introduced by
The property last_days does not seem to exist. Did you mean t_days?

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...
1019
					$this->last_hours = $this->daysToHours($set);
1020
					break;
1021
1022
				case 'H':
1023
					$this->last_days = $this->hoursToDays($set);
0 ignored issues
show
Bug introduced by
The property last_days does not seem to exist. Did you mean t_days?

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...
1024
					$this->last_hours = $set;
1025
					break;
1026
			}
1027
		}
1028
1029
	}
1030
1031
1032
	public function getnextright()
1033
	{
1034
1035
		if (list($id,$this->right) = each($this->rights))
1036
		{
1037
		    // ordonner les listes deroulantes
1038
		    
1039
	        if (!empty($this->right['rights'])) {
1040
	            bab_Sort::asort($this->rights[$id]['rights'], 'sortkey', bab_Sort::CASE_INSENSITIVE);
1041
	        }
1042
		    
1043
1044
	        $agentRight = $this->right['agentRight'];
1045
	        /*@var $agentRight absences_AgentRight */
1046
1047
			$this->id_rgroup = $this->right['id_rgroup'];
0 ignored issues
show
Bug introduced by
The property id_rgroup 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...
1048
			$this->rgroup = bab_toHtml($this->right['rgroup']);
0 ignored issues
show
Bug introduced by
The property rgroup does not seem to exist. Did you mean id_rgroup?

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...
1049
1050
			$this->right['description'] = bab_toHtml($this->right['description']);
1051
			$this->right['current_quantity'] = 
1052
			$this->right['quantity_available'] = $this->right['quantity_available'] - $this->right['waiting'];
1053
			$this->right['previsional_available'] = $this->right['quantity_available'] - $agentRight->getPrevisionalQuantity();
1054
			
1055
			$this->current_quantity = '';
0 ignored issues
show
Bug introduced by
The property current_quantity does not seem to exist. Did you mean current?

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...
1056
			if (isset($this->current[$id])) {
1057
			    $this->current_quantity = bab_toHtml($this->current[$id]);
0 ignored issues
show
Bug introduced by
The property current_quantity does not seem to exist. Did you mean current?

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...
1058
			}
1059
			$this->quantity_available = bab_toHtml(absences_quantity($this->right['quantity_available'], $this->right['quantity_unit']));
0 ignored issues
show
Bug introduced by
The property quantity_available 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...
1060
			$this->previsional_quantity_available = bab_toHtml(absences_quantity($this->right['previsional_available'], $this->right['quantity_unit']));
0 ignored issues
show
Bug introduced by
The property previsional_quantity_available does not seem to exist. Did you mean quantity_available?

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...
1061
1062
			
1063
			$right = $agentRight->getRight();
1064
1065
			$this->no_approval = !((bool) $right->require_approval);
0 ignored issues
show
Bug introduced by
The property no_approval does not seem to exist. Did you mean t_no_approval?

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...
1066
1067
1068 View Code Duplication
			switch($this->right['quantity_unit'])
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...
1069
			{
1070
				case 'D':
1071
					$this->unit = absences_translate('day(s)');
0 ignored issues
show
Bug introduced by
The property unit 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...
1072
					break;
1073
1074
				case 'H':
1075
					$this->unit = absences_translate('hour(s)');
1076
					break;
1077
			}
1078
1079
1080
			$float_quantity = 0.0;
1081
1082
1083
			if (isset($_POST['nbdays'][$id]))
1084
			{
1085
				$float_quantity = (float) str_replace(',', '.', $_POST['quantity'][$id]);
1086
				$this->quantity = $_POST['quantity'][$id];
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1087
			}
1088
			elseif( count($this->recorded) > 0) {
1089
				if (isset($this->recorded[$id])) {
1090
					$float_quantity = (float) $this->recorded[$id];
1091
					$this->quantity = absences_editQuantity($this->recorded[$id], $this->right['quantity_unit']);
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1092
				}
1093
				else {
1094
					$this->quantity = '0';
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1095
					$float_quantity = 0.0;
1096
				}
1097
			}
1098
			elseif (0 == $this->right['no_distribution'] && $this->last($this->right['quantity_unit']) > 0 && $this->right['quantity_available'] > 0)
1099
			{
1100
1101
				$last = $this->last($this->right['quantity_unit']);
1102
1103
1104
				if ($last >= $this->right['quantity_available'])
1105
				{
1106
					$float_quantity = $this->right['quantity_available'];
1107
					$this->quantity = absences_editQuantity($this->right['quantity_available'], $this->right['quantity_unit']);
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1108
1109
					$last -= $this->right['quantity_available'];
1110
					$this->last($this->right['quantity_unit'], $last);
1111
				}
1112
				elseif ($this->right['quantity_available'] > 0)
1113
				{
1114
					$float_quantity = $last;
1115
					$this->quantity = absences_editQuantity($last, $this->right['quantity_unit']);
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1116
					$this->last($this->right['quantity_unit'], 0);
1117
				}
1118
1119
			}
1120
			else
1121
			{
1122
				$float_quantity = 0.0;
1123
				$this->quantity = '0';
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1124
1125
			}
1126
1127
1128
1129
1130
			switch($this->right['quantity_unit'])
1131
			{
1132
				case 'D':
1133
					$this->total_days += $float_quantity;
1134
					$this->total_hours += $this->daysToHours($this->quantity);
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1135
					break;
1136
				case 'H':
1137
					$this->total_hours += $float_quantity;
1138
					$this->total_days += $this->hoursToDays($this->quantity);
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean quantity_available?

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...
1139
					break;
1140
			}
1141
1142
1143
1144
			return true;
1145
		}
1146
		else
1147
			return false;
1148
1149
	}
1150
1151
1152
	public function getnextrgroupright() {
1153
		if (list($id, $arr) = each($this->right['rights'])) {
1154
			$this->id_right = bab_toHtml($id);
0 ignored issues
show
Bug introduced by
The property id_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...
1155
			$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...
1156
1157
			$recorded = isset($this->current['r'.$id]) ? $this->current['r'.$id] : 0;
1158
			$this->current_quantity = bab_toHtml($recorded);
0 ignored issues
show
Bug introduced by
The property current_quantity does not seem to exist. Did you mean current?

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...
1159
			$this->quantity_available = bab_toHtml($arr['quantity_available']);
1160
			$this->previsional_available = bab_toHtml($arr['previsional_available']);
0 ignored issues
show
Bug introduced by
The property previsional_available 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...
1161
			$this->selected = isset($this->current['r'.$id]);
0 ignored issues
show
Bug introduced by
The property selected 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...
1162
			return true;
1163
		}
1164
		return false;
1165
	}
1166
1167
	public function getnextrecurring() {
1168
		if (list($begin, $end) = each($_POST['period'])) {
1169
			$this->period = bab_toHtml(sprintf(absences_translate('from %s to %s'), bab_shortDate(bab_mktime($begin)), bab_shortDate(bab_mktime($end))));
0 ignored issues
show
Bug introduced by
The property period does not seem to exist. Did you mean period_nbdays?

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...
1170
			$this->p_begin = bab_toHtml($begin);
0 ignored issues
show
Bug introduced by
The property p_begin 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...
1171
			$this->p_end = bab_toHtml($end);
0 ignored issues
show
Bug introduced by
The property p_end 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...
1172
			return true;
1173
		}
1174
		return false;
1175
	}
1176
1177
}
1178
1179
1180
1181
1182
1183
function requestVacation($begin,$end, $id, $rfrom, $ide)
1184
	{
1185
	global $babBody;
1186
	
1187
	if ($id)
1188
	{
1189
		$babBody->setTitle(absences_translate("Edit vacation request"));
1190
	} else
1191
	{
1192
		$babBody->setTitle(absences_translate("Request vacation"));
1193
	}
1194
	
1195
	
1196
	if( !bab_isEntryEditable($id) )
1197
	{
1198
		return false;
1199
	}
1200
	
1201
	if (absences_lockedForMainteance())
1202
	{
1203
		$babBody->addError(absences_getMaintenanceMessage());
1204
		return false;
1205
	}
1206
	
1207
	$agent = absences_Agent::getCurrentUser();
1208
	
1209
	if ($id)
1210
	{
1211
		if ($rfrom)
1212
		{
1213
			if ($ide && $agent->isEntityManagerOf($ide))
1214
			{
1215
				// modification d'une demande par un gestionnaire delegue
1216
				$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
1217
				$babBody->addItemMenu("entity_members", absences_translate("Entity requests"), absences_addon()->getUrl()."vacchart&idx=entity_requests&ide=".$ide);
1218
				$babBody->addItemMenu("vunew", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=vunew&id=".$id."&rfrom=1&ide=".$ide);
1219
				
1220 View Code Duplication
			} elseif (!$ide && $agent->isManager()) {
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...
1221
				// modification d'une demande par un gestionnaire
1222
				$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
1223
				$babBody->addItemMenu("lper", absences_translate("Requests"), absences_addon()->getUrl()."vacadmb&idx=lreq");
1224
				$babBody->addItemMenu("vunew", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=vunew&id=".$id."&rfrom=1");
1225
			}
1226 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...
1227
			// modification d'une demande par un agent
1228
			$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
1229
			$babBody->addItemMenu("vunew", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=vunew&id=".$id);
1230
		}
1231
	} else {
1232
		
1233
		if ($rfrom)
1234
		{
1235
			if ($ide && $agent->isEntityManagerOf($ide))
1236
			{
1237
				// creation d'une demande par un gestionnaire delegue
1238
				$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
1239
				$babBody->addItemMenu("entity_members", absences_translate("Entity requests"), absences_addon()->getUrl()."vacchart&idx=entity_requests&ide=".$ide);
1240
				$babBody->addItemMenu("vunew", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=vunew&rfrom=1&ide=".$ide);
1241
		
1242 View Code Duplication
			} elseif (!$ide && $agent->isManager()) {
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...
1243
				// creation d'une demande par un gestionnaire
1244
				$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
1245
				$babBody->addItemMenu("lper", absences_translate("Requests"), absences_addon()->getUrl()."vacadmb&idx=lreq");
1246
				$babBody->addItemMenu("vunew", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=vunew&rfrom=1");
1247
			}
1248 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...
1249
			// creation d'une demande par un agent
1250
			$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
1251
			$babBody->addItemMenu("vunew", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=vunew");
1252
		}
1253
		
1254
	}
1255
	
1256
1257
	$temp = new absences_RequestVacation($begin,$end, $id);
1258
	$babBody->babecho(	bab_printTemplate($temp, absences_addon()->getRelativePath()."vacuser.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...
1259
	}
1260
1261
1262
1263
function period($id_user, $id = 0)
1264
	{
1265
	    require_once dirname(__FILE__).'/utilit/period.ui.php';
1266
	    
1267
		$temp = new absences_PeriodFrame($id_user, $id);
1268
		$GLOBALS['babBody']->babecho(bab_printTemplate($temp,  absences_addon()->getRelativePath()."vacuser.html", "period"));
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...
1269
	}
1270
1271
1272
1273
1274
function viewrights($id_user)
1275
	{
1276
	class temp
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type temp has been defined more than once; this definition is ignored, only the first definition in programs/vacadm.php (L38-118) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
1277
		{
1278
1279
		var $altbg = true;
1280
1281
		function temp($id_user) {
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...
1282
			$this->rights = absences_getRightsByGroupOnPeriod($id_user);
0 ignored issues
show
Bug introduced by
The property rights does not seem to exist. Did you mean t_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...
1283
			$this->total = 0;
0 ignored issues
show
Bug introduced by
The property total 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...
1284
			$this->total_waiting = 0;
0 ignored issues
show
Bug introduced by
The property total_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...
1285
			$this->t_avariable_days = absences_translate("Avariable days");
0 ignored issues
show
Bug introduced by
The property t_avariable_days 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...
1286
			$this->t_waiting_days = absences_translate("Waiting days");
0 ignored issues
show
Bug introduced by
The property t_waiting_days 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...
1287
			$this->t_period_nbdays = absences_translate("Period days");
0 ignored issues
show
Bug introduced by
The property t_period_nbdays does not seem to exist. Did you mean period?

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...
1288
			$this->t_total = absences_translate("Total");
0 ignored issues
show
Bug introduced by
The property t_total 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...
1289
1290
			$this->t_available = absences_translate("Available");
0 ignored issues
show
Bug introduced by
The property t_available 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...
1291
			$this->t_waiting = absences_translate("Waiting");
0 ignored issues
show
Bug introduced by
The property t_waiting does not seem to exist. Did you mean t_waiting_days?

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...
1292
1293
			$this->total = array('D' => 0, 'H' => 0);
1294
			$this->total_waiting = array('D' => 0, 'H' => 0);
1295
		}
1296
1297
		function getnextright()
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...
1298
			{
1299
			if ($right = & current($this->rights))
0 ignored issues
show
Bug introduced by
The property rights does not seem to exist. Did you mean t_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...
1300
				{
1301
				$this->altbg = !$this->altbg;
1302
				next($this->rights);
0 ignored issues
show
Bug introduced by
The property rights does not seem to exist. Did you mean t_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...
1303
				$quantity_available = $right['quantity_available'] - $right['waiting'];
1304
				$this->description = bab_toHtml($right['description']);
1305
1306
				$this->quantity_available = array('D' => 0, 'H' => 0);
0 ignored issues
show
Bug introduced by
The property quantity_available does not seem to exist. Did you mean quantity?

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...
1307
				$this->waiting = array('D' => 0, 'H' => 0);
0 ignored issues
show
Bug introduced by
The property waiting does not seem to exist. Did you mean total_waiting?

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...
1308
1309
				$this->quantity_available[$right['quantity_unit']] = $quantity_available;
0 ignored issues
show
Bug introduced by
The property quantity_available does not seem to exist. Did you mean quantity?

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...
1310
				$this->waiting[$right['quantity_unit']] = $right['waiting'];
0 ignored issues
show
Bug introduced by
The property waiting does not seem to exist. Did you mean total_waiting?

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...
1311
1312
				$this->total[$right['quantity_unit']] += $this->quantity_available[$right['quantity_unit']];
0 ignored issues
show
Bug introduced by
The property quantity_available does not seem to exist. Did you mean quantity?

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...
1313
				$this->total_waiting[$right['quantity_unit']] += $this->waiting[$right['quantity_unit']];
0 ignored issues
show
Bug introduced by
The property waiting does not seem to exist. Did you mean total_waiting?

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...
1314
				return true;
1315
				}
1316
			else
1317
				return false;
1318
1319
			}
1320
1321
		}
1322
		$temp = new temp($id_user);
0 ignored issues
show
Bug introduced by
The call to temp::temp() misses some required arguments starting with $what.
Loading history...
1323
		
1324
		global $babBody;
1325
		
1326
		$html = bab_printTemplate($temp,  absences_addon()->getRelativePath()."vacuser.html", "viewrights");
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...
1327
		
1328
		if (1 === (int) bab_rp('popup'))
1329
		{
1330
		    $babBody->babPopup($html);
1331
		} else {
1332
		    $babBody->babEcho($html);
1333
		}
1334
	}
1335
1336
1337
1338
function vedUnload()
1339
	{
1340
	class temp
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type temp has been defined more than once; this definition is ignored, only the first definition in programs/vacadm.php (L38-118) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
1341
		{
1342
		var $message;
1343
		var $close;
1344
		var $redirecturl;
1345
1346
		function temp()
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...
1347
			{
1348
			$this->message = absences_translate("Vacation entry has been updated");
1349
			$this->close = absences_translate("Close");
0 ignored issues
show
Bug introduced by
The property close 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...
1350
			$this->redirecturl = absences_addon()->getUrl()."vacuser&idx=lval";
0 ignored issues
show
Bug introduced by
The property redirecturl 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...
1351
			}
1352
		}
1353
1354
	$temp = new temp();
0 ignored issues
show
Bug introduced by
The call to temp::temp() misses some required arguments starting with $vtid.
Loading history...
1355
	global $babBody;
1356
	$babBody->babPopup(bab_printTemplate($temp, absences_addon()->getRelativePath()."vacuser.html", "vedunload"));
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...
1357
	}
1358
1359
1360
1361
class absences_saveVacation
1362
{
1363
1364
1365
	/**
1366
	 * Test la quantite dispo sur un droit
1367
	 * 
1368
	 *
1369
	 * @param	array	&$nbdays	list of rights to save in request, rows are added on each valid calls
1370
	 * @param	Array	$arr		vacation rights properties
1371
	 * @param	float	$quantity	requested quantity in form
1372
	 * @param	int		$id_request	if this is a request modification
1373
	 * 
1374
	 * @throws Exception
1375
	 * 
1376
	 * @return bool
1377
	 */
1378
	private static function addVacationRight(&$nbdays, Array $arr, $quantity, $id_request, &$used_in_previous_periods)
1379
	{
1380
		$quantity = str_replace(',','.', $quantity);
1381
		$available = ($arr['quantity_available'] - $arr['waiting']);
1382
		
1383
		if (!isset($used_in_previous_periods[$arr['id']]))
1384
		{
1385
			$used_in_previous_periods[$arr['id']] = 0;
1386
		}
1387
1388
		if (!empty($id_request)) {
1389
			
1390
			$entry = absences_Entry::getById($id_request);
1391
			
1392
			if (!$entry->isPrevisonal()) {
1393
    			$element = $entry->getElement($arr['id']);
1394
    			
1395
    			if (isset($element)) {
1396
        			// quantity in current request is unavailable, add it to $available (waiting or confirmed)
1397
        			$available += $element->quantity;
1398
    			}
1399
			}
1400
		}
1401
1402
		
1403
		if ('' === $quantity) {
1404
			$quantity = 0;
1405
		}
1406
		
1407
1408
		if(!is_numeric($quantity) || $quantity < 0 ) {
1409
			throw new Exception(sprintf(absences_translate("You must specify a correct number days on right %s"), $arr['description']));
1410
		}
1411
1412
		if (!empty($quantity) && $arr['cbalance'] != 'Y' && ($available - $quantity - $used_in_previous_periods[$arr['id']]) < 0) {
1413
			throw new Exception(sprintf(absences_translate("You can't take more than %s on the right %s"), absences_quantity($available, $arr['quantity_unit']), $arr['description']));
1414
		}
1415
		
1416
		
1417
		// si le droit est un compte epargne temps, verifier les conditions d'utilisations speciales
1418
		if (!empty($quantity))
1419
		{
1420
			$agentRight = $arr['agentRight'];
1421
			/*@var $agentRight absences_agentRight */
1422
			$right = $agentRight->getRight();
1423
			
1424
			if (absences_Right::CET === $right->getKind() && ($cet = $right->getRightCet()))
1425
			{
1426
				if (0 !== (int) round(10*$cet->min_use)) // 0 = min_use disabled
1427
				{
1428
					// -1 = force using all available
1429
					
1430
					$min_use = (float) $cet->min_use;
1431
					
1432
					if ($min_use < 0 && $quantity < $available)
1433
					{
1434
						throw new Exception(sprintf(absences_translate("The quantity available in %s must be used all in one request"), $arr['description']));
1435
					}
1436
					
1437
					
1438
					if ($min_use > 0 && ((int) round(10*$quantity)) < ((int) round(10*$min_use)))
1439
					{
1440
						throw new Exception(sprintf(absences_translate("The minimal quantity usable in one request for the right %s is %s"), $arr['description'], absences_quantity($min_use, 'D')));
1441
					}
1442
				}
1443
			}
1444
		}
1445
		
1446
1447
		if( $quantity > 0 ) {
1448
			$nbdays['id'][] = (int) $arr['id'];
1449
			$nbdays['val'][] = $quantity;
1450
			$nbdays['total'][$arr['quantity_unit']] += $quantity;
1451
			$used_in_previous_periods[$arr['id']] += $quantity;
1452
		}
1453
1454
		return true;
1455
	}
1456
	
1457
	
1458
	/**
1459
	 * requests in same folder and with same quantity and with same status
1460
	 * @param absences_Entry $entry
1461
	 * @return array
1462
	 */
1463
	private static function selectFolderSimilarRequests($entry)
1464
	{
1465
		require_once dirname(__FILE__).'/utilit/entry.class.php';
1466
		global $babDB;
1467
		
1468
		$res = $babDB->db_query('SELECT
1469
				e.* 
1470
			FROM
1471
				absences_entries e 
1472
			WHERE e.folder='.$babDB->quote($entry->folder).'
1473
				AND e.status='.$babDB->quote($entry->status).'
1474
				AND e.id<>'.$babDB->quote($entry->id).' 
1475
		');
1476
		
1477
		$return = array();
1478
		while($arr = $babDB->db_fetch_assoc($res))
1479
		{
1480
			$e = new absences_Entry();
1481
			$e->setRow($arr);
1482
			
1483
			if ($e->getTotalDays() == $entry->getTotalDays())
1484
			{
1485
				$return[] = $e;
1486
			}
1487
		}
1488
		
1489
		return $return;
1490
	}
1491
	
1492
	
1493
	/**
1494
	 * Save posted data
1495
	 */
1496
	public static function save()
1497
	{
1498
		global $babBody;
1499
		
1500
		if (absences_lockedForMainteance())
1501
		{
1502
			return false;
1503
		}
1504
		
1505
		
1506
		$id_request		= (int) $_POST['id'];
1507
		$id_user		= (int) $_POST['id_user'];
1508
		$rfrom			= $_POST['rfrom'];
1509
		
1510
		if( $rfrom == 1 )
1511
		{
1512
			$agent = absences_Agent::getCurrentUser();
1513
			if( !$agent->isManager())
1514
			{
1515
				$rfrom = 0;
1516
			}
1517
		}
1518
		
1519
		
1520
		
1521
		if (isset($_POST['period']) && is_array($_POST['period']))
1522
		{
1523
			// recurring request
1524
			
1525
			$period_list = $_POST['period'];
1526
			$folder = count($period_list) > 1 ? time() : 0;
1527
			$period_list_id = array();
1528
			
1529
		} else if (isset($_POST['upd_recurring']) && $id_request > 0) 
1530
		{
1531
1532
			// update recurring request
1533
1534
			require_once dirname(__FILE__).'/utilit/entry.class.php';
1535
			$entry = absences_Entry::getById($id_request);
1536
			
1537
			$folder = (int) $entry->folder;
1538
			
1539
			$period_list = array(
1540
					$_POST['begin'] => $_POST['end']
1541
			);
1542
			
1543
			$period_list_id = array(
1544
					$_POST['begin'] => $id_request
1545
			);
1546
			
1547
			$list = self::selectFolderSimilarRequests($entry);
1548
			
1549
			foreach($list as $e)
1550
			{
1551
				$period_list[$e->date_begin] = $e->date_end;
1552
				$period_list_id[$e->date_begin] = $e->id;
1553
			}
1554
			
1555
			
1556
			
1557
	    } else {
1558
		
1559
			$period_list = array(
1560
				$_POST['begin'] => $_POST['end']
1561
			);
1562
			
1563
			$period_list_id = array(
1564
				$_POST['begin'] => $id_request
1565
			);
1566
			
1567
			$folder = 0;
1568
		}
1569
		
1570
		/**
1571
		 * Les droits utilises pour les tests sont les droits affiches a l'ecran
1572
		 * dans une demande repetitive, c'est la premiere periode qui est utilise pour les tests d'affichage
1573
		 */
1574
		$rights = absences_getRightsOnPeriod(key($period_list), reset($period_list), $id_user, $rfrom);
1575
		
1576
		// test phase
1577
		
1578
		$used_in_previous_periods = array();
1579
		
1580
		
1581
		$nbdays = null;
1582
		
1583
		
1584
		foreach($period_list as $begin => $end)
1585
		{
1586
			$id_request = isset($period_list_id[$begin]) ? $period_list_id[$begin] : 0;
1587
			
1588
			
1589
			try {
1590
			    // la repartition des jours sur les droits
1591
			    $_nbdays = self::testRightsQuantity($id_request, $rights, $used_in_previous_periods);
1592
			    if (!isset($nbdays)) {
1593
			        $nbdays = $_nbdays;
1594
			    }
1595
			    
1596
			} catch (Exception $e)
1597
			{
1598
			    $babBody->addError($e->getMessage());
1599
			    return false;
1600
			}
1601
			
1602
			
1603
			// verifier que le droit est dispo sur la periode
1604
			// utile pour les demandes repetitives
1605
			if (!test_periodValidity($id_request, $id_user, bab_mktime($begin), bab_mktime($end))) {
1606
				return false;
1607
			}
1608
1609
			try {
1610
				self::testRightsAvailability($rights, $nbdays, $begin, $end);
1611
			} catch (Exception $e)
1612
			{
1613
				$babBody->addError($e->getMessage());
1614
				return false;
1615
			}
1616
		}
1617
		
1618
		
1619
		if (!isset($nbdays)) {
1620
		    throw new Exception('missing quantity');
1621
		}
1622
		
1623
		
1624
		
1625
		// save phase
1626
		$saved = false;
1627
		foreach ($period_list as $begin => $end) {
1628
			$id_request = isset($period_list_id[$begin]) ? $period_list_id[$begin] : 0;
1629
			
1630
			if (self::savePeriod($id_request, $begin, $end, $id_user, $rfrom, $nbdays, $folder)) {
1631
				$saved = true;
1632
			}
1633
		}
1634
		
1635
		
1636
		if ($saved && !isset($_POST['previsional']))
1637
		{
1638
			$defer = (bool) absences_getVacationOption('approb_email_defer');
1639
			if (!$defer) {
1640
			    require_once dirname(__FILE__).'/utilit/request.notify.php';
1641
				absences_notifyRequestApprovers();
1642
			}
1643
		}
1644
1645
		return true;
1646
	}
1647
	
1648
	
1649
	
1650
	
1651
	
1652
	
1653
	
1654
	/**
1655
	 * Test des soldes 
1656
	 * retourne la liste des droit qui devons etre inseres ou false si la demande n'est pas autorise
1657
	 * 
1658
	 * @throws Exception
1659
	 * 
1660
	 * @return array | false
1661
	 */
1662
	private static function testRightsQuantity($id_request, $rights, &$used_in_previous_periods)
1663
	{
1664
		
1665
		
1666
		$rgroups = array();
1667
		$nbdays = array(
1668
			'id' => array(),
1669
			'val' => array(),
1670
		    'total' => array(
1671
		        'D' => 0,
1672
		        'H' => 0
1673
		    )
1674
		);
1675
		
1676
		// regular vacation rights
1677
		foreach($rights as &$arr)
1678
		{
1679
			if( isset($_POST['quantity'][$arr['id']]))
1680
			{
1681
				$quantity = $_POST['quantity'][$arr['id']];
1682
				if (!self::addVacationRight($nbdays, $arr, $quantity, $id_request, $used_in_previous_periods))
1683
				{
1684
					return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by absences_saveVacation::testRightsQuantity of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1685
				}
1686
			}
1687
		
1688
			if ($arr['id_rgroup'] > 0) {
1689
				$rgroups[$arr['id']] = $arr['id_rgroup'];
1690
			}
1691
		}
1692
		
1693
		// right groups
1694
		
1695
		if (isset($_POST['rgroup_right'])) {
1696
			foreach($_POST['rgroup_right'] as $id_rgroup => $id_right) {
1697
				if (isset($rgroups[$id_right]) && $rgroups[$id_right] == $id_rgroup) {
1698
					$quantity = $_POST['rgroup_value'][$id_rgroup];
1699
1700
					if (!self::addVacationRight($nbdays, $rights[$id_right], $quantity, $id_request, $used_in_previous_periods))
1701
					{
1702
						return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by absences_saveVacation::testRightsQuantity of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1703
					}
1704
				}
1705
			}
1706
		}
1707
		
1708
		if (empty($nbdays['val']))
1709
		{
1710
			throw new Exception(absences_translate("Empty requests are not allowed"));
1711
		}
1712
		
1713
		
1714
		$days = 0.0;
1715
		$hours = 0.0;
0 ignored issues
show
Unused Code introduced by
$hours 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...
1716
		
1717 View Code Duplication
		if (isset($_POST['total']['D'])) {
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...
1718
		    $days = (float) str_replace(',', '.', $_POST['total']['D']);
1719
		}
1720
		
1721 View Code Duplication
		if (isset($_POST['total']['H'])) {
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...
1722
		    $hours = (float) str_replace(',', '.', $_POST['total']['H']);
0 ignored issues
show
Unused Code introduced by
$hours 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...
1723
		}
1724
		
1725
		
1726
1727
		
1728 View Code Duplication
		if ($nbdays['total']['D'] > 0 && !absences_cq($nbdays['total']['D'], $days)) {
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...
1729
		    throw new Exception(absences_translate("Quantities must match total days"));
1730
		}
1731
		
1732 View Code Duplication
		if ($nbdays['total']['H'] > 0 && !absences_cq($nbdays['total']['H'], $days)) {
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...
1733
		    throw new Exception(absences_translate("Quantities must match total hours"));
1734
		}
1735
		
1736
		return $nbdays;
1737
	}
1738
	
1739
	
1740
	
1741
	/**
1742
	 * Tester pour une periode si les droits avec une quantite saisie est disponibe
1743
	 * 
1744
	 * @param array $rights			Array from absences_getRightsOnPeriod
1745
	 * @param array $nbdays
1746
	 * @param string $begin			ISO datetime
1747
	 * @param string $end			ISO datetime
1748
	 * 
1749
	 * @throws Exception
1750
	 * 
1751
	 * @return bool
1752
	 */
1753
	private static function testRightsAvailability(Array $rights, Array $nbdays, $begin, $end)
1754
	{
1755
		$begin_ts = bab_mktime($begin);
1756
		$end_ts = bab_mktime($end);
1757
		
1758
		
1759
		foreach($nbdays['id'] as $k => $id_right)
1760
		{
1761
			if (isset($nbdays['val'][$k]) && !empty($nbdays['val'][$k]))
1762
			{
1763
				$agentRight = $rights[$id_right]['agentRight'];
1764
				
1765
1766
				
1767
				if (!$agentRight->isAccessibleOnPeriod($begin_ts, $end_ts))
1768
				{
1769
					throw new Exception(sprintf(
1770
							absences_translate('The right "%s" is not accessible %s, in a recurring request, all periods must be inside the used right validity period'), 
1771
							$rights[$id_right]['description'], 
1772
							mb_strtolower(absences_DateTimePeriod($begin, $end))
1773
					));
1774
				}
1775
				
1776
				if (!$agentRight->isAccessibleOnDelay($begin_ts))
1777
				{
1778
					$right = $agentRight->getRight();
1779
					$rightRule = $right->getRightRule();
1780
					
1781
					throw new Exception(sprintf(
1782
							absences_translate('The right "%s" is not accessible in the next %s days'), 
1783
							$right[$id_right]['description'], 
1784
							$rightRule->delay_before
1785
					));
1786
				}
1787
			}
1788
		}
1789
		
1790
		return true;
1791
	}
1792
	
1793
	
1794
	
1795
	private static function getPeriodSpanOnEdit($old_date_begin, $old_date_end, BAB_DateTime $date_begin, BAB_DateTime $date_end)
1796
	{
1797
	    $old_date_begin_obj = BAB_DateTime::fromIsoDateTime($old_date_begin);
1798
	    $old_date_end_obj = BAB_DateTime::fromIsoDateTime($old_date_end);
1799
	    
1800
	    $old_date_begin = $old_date_begin_obj->getTimeStamp();
1801
	    $old_date_end = $old_date_end_obj->getTimeStamp();
1802
	    
1803
	    $new_date_begin = $date_begin->getTimeStamp();
1804
	    $new_date_end = $date_end->getTimeStamp();
1805
	    
1806
	    $period_begin	= $old_date_begin 	< $new_date_begin 	? $old_date_begin 	: $new_date_begin;
1807
	    $period_end 	= $old_date_end 	> $new_date_end 	? $old_date_end 	: $new_date_end;
1808
	    
1809
	    return array($period_begin, $period_end);
1810
	}
1811
	
1812
	
1813
	
1814
	/**
1815
	 * Save in calendar
1816
	 * 
1817
	 * 
1818
	 * @param int $id_request
1819
	 * @param BAB_DateTime | null $old_date_begin_obj
1820
	 * @param BAB_DateTime | null $old_date_end_obj
1821
	 */
1822
	private static function saveInCalendar($id_request, $id, $old_date_begin_obj, $old_date_end_obj)
1823
	{
1824
	    if (empty($id_request)) {
1825
	        // event creation
1826
	        absences_createPeriod($id);
1827
	    
1828
	    } else {
1829
	        // event modification
1830
	        absences_updatePeriod($id, $old_date_begin_obj, $old_date_end_obj);
1831
	    }
1832
	}
1833
1834
1835
	/**
1836
	 * 
1837
	 * @param string   $begin		ISO datetime
1838
	 * @param string   $end		    ISO datetime
1839
	 * @param int      $id_user     Request owner
1840
	 * @param int      $rfrom       rfrom=1 if modification from a manager and from the back-office
1841
	 * @return boolean
1842
	 */
1843
	private static function savePeriod($id_request, $begin, $end, $id_user, $rfrom, $nbdays, $folder = 0)
1844
	{
1845
		require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
1846
		require_once dirname(__FILE__).'/utilit/entry.class.php';
1847
		require_once dirname(__FILE__).'/utilit/entry_elem.class.php';
1848
		global $babBody;
1849
1850
1851
		
1852
		$remarks		= $_POST['remarks'];
1853
		
1854
		
1855
		$date_begin = BAB_DateTime::fromIsoDateTime($begin);
1856
		$date_end	= BAB_DateTime::fromIsoDateTime($end);
1857
		$status = isset($_POST['previsional']) ? 'P' : 'Y';
1858
		
1859
		
1860
1861
1862
		if (empty($id_request)) {
1863
			// event creation
1864
			
1865
			$entry = new absences_Entry;
1866
			$entry->id_user = $id_user;
1867
			$entry->createdBy = bab_getUserId();
1868
			$entry->date_begin = $begin;
1869
			$entry->date_end = $end;
1870
			$entry->comment = $remarks;
1871
			$entry->createdOn = date('Y-m-d H:i:s');
1872
			$entry->idfai = 0;
1873
			$entry->status = $status;
1874
			$entry->folder = $folder;
1875
			    
1876
			$entry->save();
1877
			
1878
			$id = $entry->id;
1879
1880
			$period_begin = bab_mktime($begin);
1881
			$period_end = bab_mktime($end);
1882
			
1883
			$old_date_begin_obj = null;
1884
			$old_date_end_obj = null;
1885
1886
1887
		}
1888
		else {
1889
			// event modification
1890
1891
			$entry = absences_Entry::getById($id_request);
1892
1893
			$old_date_begin = $entry->date_begin;
1894
			$old_date_end = $entry->date_end;
1895
1896
			if ($entry->idfai > 0) {
1897
				deleteFlowInstance($entry->idfai);
1898
			}
1899
				
1900
			$entry->date_begin = $date_begin->getIsoDateTime();
1901
			$entry->date_end = $date_end->getIsoDateTime();
1902
			$entry->comment = $remarks;
1903
			$entry->idfai = 0;
1904
			$entry->status = $status;
1905
			
1906
			$entry->save();
1907
			
1908
			$entry->loadElements();
1909
1910
			$id = $id_request;
1911
1912
			
1913
            list($period_begin, $period_end) = self::getPeriodSpanOnEdit($old_date_begin, $old_date_end, $date_begin, $date_end);
1914
            
1915
            $old_date_begin_obj = BAB_DateTime::fromIsoDateTime($old_date_begin);
1916
            $old_date_end_obj = BAB_DateTime::fromIsoDateTime($old_date_end);
1917
		}
1918
1919
1920
		// insert rights
1921
		
1922
	   $saved_rights = array();
1923
1924
		if (isset($nbdays['id'])) {
1925
		  $count = count($nbdays['id']);
1926
		  for( $i = 0; $i < $count; $i++) {
1927
			   
1928
		      $id_right = $nbdays['id'][$i];
1929
		      $saved_rights[$id_right] = $id_right;
1930
		      
1931
    			$elem = $entry->getElement($id_right);
1932
    			if (!isset($elem)) {
1933
    			     $elem = new absences_EntryElem();
1934
    			     $elem->setEntry($entry);
1935
    			     $entry->addElement($elem);
1936
    			}
1937
    			
1938
    			$elem->id_right = $id_right;
1939
    			$elem->date_begin = '0000-00-00 00:00:00';
1940
    			$elem->date_end = '0000-00-00 00:00:00';
1941
    			$elem->quantity = $nbdays['val'][$i];
1942
			}
1943
		}
1944
		
1945
		// remove elements set to zero
1946
		foreach($entry->getElements() as $element) {
1947
		    if (!isset($saved_rights[$element->id_right])) {
1948
		        $element->delete();
1949
		    }
1950
		}
1951
		
1952
		$entry->setElementsDates();
1953
		$entry->saveElements();
1954
		$entry->createPlannedPeriods();
1955
		$entry->savePlannedPeriods();
1956
		
1957
1958
		// set period into calendar backend if necessary
1959
		try {
1960
            self::saveInCalendar($id_request, $id, $old_date_begin_obj, $old_date_end_obj);
1961
		} catch (Exception $e) {
1962
		    // ex: caldav is not accessible
1963
		    
1964
		    /*@var $babBody babBody */
1965
		    $babBody->addNextPageError(sprintf(absences_translate('Failed to save event in calendar: %s'), $e->getMessage()));
0 ignored issues
show
Documentation introduced by
sprintf(absences_transla...%s'), $e->getMessage()) is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1966
		}
1967
1968
1969
		include_once $GLOBALS['babInstallPath']."utilit/eventperiod.php";
1970
		$event = new bab_eventPeriodModified($period_begin, $period_end, $id_user);
1971
		$event->types = BAB_PERIOD_VACATION;
1972
		bab_fireEvent($event);
1973
		
1974
		
1975
		
1976
1977
		if (!isset($_POST['previsional']))
1978
		{
1979
		    $author = absences_Agent::getCurrentUser();
1980
		    $approbCreated = false;
1981
		    $startApproval = true;
1982
		    
1983
		    if ($author->isManager()) {
1984
		        if (isset($_POST['force_approval'])) { // checkbox does not exists if manager create his own request
1985
		            $startApproval = (bool) bab_pp('force_approval');
1986
		        }
1987
		    }
1988
		    
1989
		    
1990
		    if ($startApproval) {
1991
    			// create approbation
1992
    			if (self::createInstance($entry, !empty($id_request))) {
1993
    			    $approbCreated = true;
1994
    			}
1995
		    } else {
1996
		        self::addNoApprovalMovment($entry, !empty($id_request));
1997
		    }
1998
		    
1999
		    if (!$approbCreated)
2000
		    {
2001
		        // ex : retirer des RTT en fonction des arret maladie, l'absences maladie est cree par le gestionnaire sans approbation
2002
		        $entry->applyDynamicRight();
2003
		        
2004
		        // notify owner and other emails about the confirmed vacation request
2005
		        $entry->notifyOwner();
2006
		    }
2007
			
2008
			if (!empty($id_request))
2009
			{
2010
				// notification de modification
2011
				$entry = absences_Entry::getById($id);
2012
				absences_notifyOnRequestChange(array($entry), $entry->id_user);
2013
				absences_notifyManagers::send($id);
2014
			}
2015
		}
2016
		
2017
		
2018
2019
		return true;
2020
	}
2021
2022
	
2023
	
2024
	public static function submitRequest($id)
2025
	{
2026
	    require_once dirname(__FILE__).'/utilit/entry.class.php';
2027
	    global $babBody;
2028
	    
2029
	    $entry = absences_Entry::getById($id);
2030
	    
2031
	    try {
2032
	        $entry->checkAvailable();
2033
	    } catch(Exception $e) {
2034
	        $babBody->addNextPageError($e->getMessage());
2035
	        return false;
2036
	    }
2037
	    
2038
	    if (!self::createInstance($entry)) {
2039
	        // ex : retirer des RTT en fonction des arret maladie, l'absences maladie est cree par le gestionnaire sans approbation
2040
	        $entry->applyDynamicRight();
2041
	        
2042
	        // notify owner and other emails about the confirmed vacation request
2043
	        $entry->notifyOwner();
2044
	    }
2045
	}	
2046
	
2047
	
2048
	protected static function addNoApprovalMovment($entry, $modify)
2049
	{
2050
	    if ($modify)
2051
	    {
2052
	        $text = absences_translate('The %s has been modified without approval');
2053
	    } else {
2054
	        $text = absences_translate('The %s has been created without approval');
2055
	    }
2056
	    
2057
	    $entry->addMovement(sprintf($text, $entry->getTitle()));
2058
	}
2059
	
2060
	
2061
	/**
2062
	 * Create approbation instance, set status in waiting state
2063
	 * @param 	absences_Entry 	$entry
2064
	 * @param	bool	        $modify
2065
	 * 
2066
	 * @return bool
2067
	 */
2068
	public static function createInstance(absences_Entry $entry, $modify = false)
2069
	{
2070
		require_once dirname(__FILE__).'/utilit/request.notify.php';
2071
		global $babBody;
2072
		
2073
		
2074
		
2075
		if (!$entry->requireApproval())
2076
		{
2077
2078
		    self::addNoApprovalMovment($entry, $modify);
2079
			return false;
2080
		} else {
2081
		    
2082
		    
2083
		    if ($modify)
2084
		    {
2085
		        $text = absences_translate('The %s has been modified');
2086
		    } else {
2087
		        $text = absences_translate('The %s has been created');
2088
		    }
2089
		    
2090
		    $entry->addMovement(sprintf($text, $entry->getTitle()));
2091
		}
2092
		
2093
		
2094
		if (!$entry->createApprobationInstance()) {
2095
		    // impossible de crer une instance, 
2096
		    // l'utilisateur peut etre en auto-approbation ou le schema ne retourne aucun approbateur
2097
    		$entry->status = 'Y';
2098
    		$entry->onConfirm();
2099
    		$entry->save();
2100
    		return false;
2101
		}
2102
		
2103
		
2104
		
2105
		return true;
2106
	}
2107
	
2108
	
2109
	
2110 View Code Duplication
	public static function gotoList()
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...
2111
	{
2112
		require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
2113
		
2114
		$url = bab_url::get_request('tg');
2115
		$url->idx = 'lvreq';
2116
		$url->location();
2117
	}
2118
2119
}
2120
2121
2122
2123
2124
2125
2126
2127
2128
/**
2129
 * Test period validity
2130
 * verifie qu'il n'y a pas de chevauchements de periodes
2131
 * 
2132
 * @param int $id_entry
2133
 * @param int $id_user
2134
 * @param int $begin
2135
 * @param int $end
2136
 * @return boolean
2137
 */
2138
function test_periodValidity($id_entry,$id_user,$begin,$end)
2139
{
2140
	global $babBody, $babDB;
2141
	
2142
	if( $begin >= $end)
2143
		{
2144
		$babBody->msgerror = absences_translate("ERROR: End date must be older")." !";
2145
		return false;
2146
		}
2147
		
2148
2149
	$date_begin = date('Y-m-d H:i:s',$begin);
2150
	$date_end = date('Y-m-d H:i:s',$end);
2151
2152
	$req = "SELECT
2153
				COUNT(*)
2154
		FROM ".ABSENCES_ENTRIES_TBL."
2155
			WHERE
2156
			id_user='".$babDB->db_escape_string($id_user)."'
2157
			AND date_begin < '".$babDB->db_escape_string($date_end)."'  
2158
			AND date_end > '".$babDB->db_escape_string($date_begin)."' 
2159
			AND id <> '".$babDB->db_escape_string($id_entry)."'
2160
			AND status<>'N'";
2161
2162
	$res = $babDB->db_query($req);
2163
	list($n) = $babDB->db_fetch_array($res);
2164
2165
	if ($n > 0) {
2166
		$babBody->msgerror = absences_translate("ERROR: a request is already defined on this period");
2167
		return false;
2168
	}
2169
2170
	return true;
2171
}
2172
2173
/**
2174
 * Test period validaity from posted first step
2175
 * @return boolean
2176
 */
2177
function test_period()
2178
{
2179
global $babBody;
2180
include_once $GLOBALS['babInstallPath']."utilit/dateTime.php";
2181
2182
if (!isset($_POST['daybegin']) ||
2183
	!isset($_POST['monthbegin']) ||
2184
	!isset($_POST['yearbegin']) ||
2185
	!isset($_POST['hourbegin']) ||
2186
	!isset($_POST['dayend']) ||
2187
	!isset($_POST['monthend']) ||
2188
	!isset($_POST['yearend']) ||
2189
	!isset($_POST['hourend']) ||
2190
	!isset($_POST['id_user'])
2191
	)
2192
	{
2193
	$babBody->msgerror = absences_translate("Error");
2194
	return false;
2195
	}
2196
2197
	$yearbegin = $_POST['year'] + $_POST['yearbegin'] - 1;
2198
	$yearend = $_POST['year'] + $_POST['yearend'] - 1;
2199
2200
	$begin	= BAB_DateTime::fromIsoDateTime($yearbegin.'-'.$_POST['monthbegin'].'-'.$_POST['daybegin'].' '.$_POST['hourbegin']);
2201
	$end	= BAB_DateTime::fromIsoDateTime($yearend.'-'.$_POST['monthend'].'-'.$_POST['dayend'].' '.$_POST['hourend']);
2202
2203
	$id_entry = isset($_POST['id']) ? $_POST['id'] : 0;
2204
2205
return test_periodValidity($id_entry, $_POST['id_user'], $begin->getTimeStamp(), $end->getTimeStamp());
2206
}
2207
2208
2209
2210
2211
/**
2212
 * Get posted date from the first step edit form or from the hidden field
2213
 *
2214
 */
2215
class absences_PostedDate
2216
{
2217
	/**
2218
	 * @return string ISO datetime
2219
	 */
2220
	public static function begin()
2221
	{
2222
		if (isset($_POST['daybegin']))
2223
		{
2224
			$yearbegin = $_POST['year'] + $_POST['yearbegin'] -1;
2225
			return $yearbegin.'-'.$_POST['monthbegin'].'-'.$_POST['daybegin'].' '.$_POST['hourbegin'];
2226
		}
2227
		
2228
		if (isset($_POST['begin']))
2229
		{
2230
			return $_POST['begin'];
2231
		}
2232
		
2233
		if (isset($_POST['period']))
2234
		{
2235
			return key($_POST['period']);
2236
		}
2237
	}
2238
	
2239
	/**
2240
	 * @return string ISO datetime
2241
	 */
2242
	public static function end()
2243
	{
2244
		if (isset($_POST['dayend']))
2245
		{
2246
			
2247
			$yearend = $_POST['year'] + $_POST['yearend'] -1;
2248
			return $yearend.'-'.$_POST['monthend'].'-'.$_POST['dayend'].' '.$_POST['hourend'];
2249
		}
2250
		
2251
		if (isset($_POST['end']))
2252
		{
2253
			return $_POST['end'];
2254
		}
2255
		
2256
		if (isset($_POST['period']))
2257
		{
2258
			return reset($_POST['period']);
2259
		}
2260
	}
2261
}
2262
2263
2264
2265
2266 View Code Duplication
function absences_workperiodGotoList()
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...
2267
{
2268
    $agent = absences_Agent::getCurrentUser();
2269
    
2270
    if (!empty($_POST['workperiod']['id_user'])) {
2271
        
2272
        
2273
        if ($agent->isManager()) {
2274
            $url = new bab_url(absences_addon()->getUrl().'vacadmwd');
2275
            $url->location();
2276
            return;
2277
        }
2278
        
2279
        //TODO: liste des demandes de l'entite si gestionnaire delegue
2280
    }
2281
    
2282
    $url = bab_url::get_request('tg');
2283
    $url->idx = 'lvreq';
2284
    $url->location();
2285
}
2286
2287
2288
2289
2290
/**
2291
 * Save form
2292
 * @param array 							$workperiod
2293
 * @param absences_WorkperiodRecoverRequest	$workperiodRecover
2294
 * @throws Exception
2295
 */
2296
function absences_saveWorkperiodRecoverRequest(Array $workperiod, absences_WorkperiodRecoverRequest $workperiodRecover = null)
2297
{
2298
	$babBody = bab_getInstance('babBody');
2299
	/* @var $babBody babBody */
2300
	
2301
	if (absences_lockedForMainteance())
2302
	{
2303
		return false;
2304
	}
2305
	
2306
	
2307
	if (!absences_WorkperiodRecoverRequest::checkForm($workperiod, $workperiodRecover))
2308
	{
2309
		return false;
2310
	}
2311
	
2312
	
2313
	
2314
	
2315
	
2316
	$type = absences_WorkperiodType::getFromId($workperiod['id_type']);
2317
	
2318
	if (!$type->getRow())
2319
	{
2320
		throw new Exception(absences_translate('This type does not exits'));
2321
	}
2322
	
2323
	$agent = absences_Agent::getCurrentUser();
2324
	
2325
	if (!isset($workperiodRecover))
2326
	{
2327
		$workperiodRecover = new absences_WorkperiodRecoverRequest();
2328
		
2329
		if (!empty($workperiod['id_user'])) {
2330
    		$spoofed = absences_Agent::getFromIdUser($workperiod['id_user']);
2331
    		if (!$agent->isManager() && !$agent->isSuperiorOf($spoofed)) {
2332
    		    throw new Exception(absences_translate('This type does not exits'));
2333
    		}
2334
    		
2335
    		$workperiodRecover->id_user = $spoofed->getIdUser();
2336
    		
2337
		} else {
2338
		    $workperiodRecover->id_user = bab_getUserId();
2339
		}
2340
	}
2341
	
2342
	$workperiodRecover->date_begin = absences_dateTimeForm($workperiod['datebegin'], $workperiod['hourbegin']);
2343
	$workperiodRecover->date_end = absences_dateTimeForm($workperiod['dateend'], $workperiod['hourend']);
2344
	$workperiodRecover->id_type = $type->id;
2345
	$workperiodRecover->comment = $workperiod['comment'];
2346
	$workperiodRecover->quantity = $type->quantity;
0 ignored issues
show
Documentation introduced by
The property quantity does not exist on object<absences_WorkperiodType>. 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...
2347
	$workperiodRecover->quantity_unit = $type->quantity_unit;
0 ignored issues
show
Documentation introduced by
The property quantity_unit does not exist on object<absences_WorkperiodType>. 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...
2348
	$workperiodRecover->status = 'Y';
2349
	$workperiodRecover->id_right = 0;
2350
	$workperiodRecover->save();
2351
	
2352
2353
	if ($workperiodRecover->createApprobationInstance())
2354
	{
2355
		$babBody->addNextPageMessage(absences_translate('Your workperiod recovery request has been sent for approval'));
0 ignored issues
show
Documentation introduced by
absences_translate('Your...een sent for approval') is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2356
	} else {
2357
		$babBody->addNextPageMessage(absences_translate('Your workperiod recovery request has been saved without approval'));
0 ignored issues
show
Documentation introduced by
absences_translate('Your...aved without approval') is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2358
	}
2359
	
2360
	$defer = (bool) absences_getVacationOption('approb_email_defer');
2361
	
2362
	if (!$defer)
2363
	{
2364
		require_once dirname(__FILE__).'/utilit/request.notify.php';
2365
		absences_notifyRequestApprovers();
2366
	}
2367
2368
	
2369
	absences_workperiodGotoList();
2370
}
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
/**
2382
 * Display form
2383
 */
2384
function absences_createWorkperiodRecoverRequest()
2385
{
2386
	require_once dirname(__FILE__).'/utilit/workperiod_recover_request.class.php';
2387
	require_once dirname(__FILE__).'/utilit/workperiod_recover_request.ui.php';
2388
	
2389
	
2390
	$babBody = bab_getBody();
2391
	
2392
	
2393
	
2394
	$agent = absences_Agent::getCurrentUser();
2395
	
2396
	if ($id_user = (int) bab_rp('id_user')) {
2397
	    $spoofed = absences_Agent::getFromIdUser($id_user);
2398
	    if (!$agent->isManager() && !$agent->isSuperiorOf($spoofed)) {
2399
	        return $babBody->addError('Spoofing failed workperiod recover request creation, you must be superior of the spoofed agent');
2400
	    }
2401
	    
2402
	    $agent = $spoofed;
2403
	}
2404
	
2405
	
2406
	
2407
	$request = null;
2408
	$id = bab_rp('id', null);
2409
	if (isset($id))
2410
	{
2411
		$request = absences_WorkperiodRecoverRequest::getById($id);
2412
		if (!$request->canModify())
2413
		{
2414
			return;
2415
		}
2416
	} else if (!$agent->canCreateWorkperiodRecoverRequest()) {
2417
		return $babBody->addError('Agent not allowed to create workperiod recover requests');
2418
	}
2419
	
2420
	
2421
	if (!isset($request) && $id_user) {
2422
	    $request = new absences_WorkperiodRecoverRequest();
2423
	    $request->id_user = $id_user;
2424
	}
2425
	
2426
	
2427
	$W = bab_Widgets();
2428
	$page = $W->BabPage();
2429
	
2430 View Code Duplication
	if (isset($_POST['workperiod']))
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...
2431
	{
2432
		if ( isset($_POST['workperiod']['cancel']) )
2433
		{
2434
			absences_workperiodGotoList();
2435
		}
2436
	
2437
	
2438
		if( isset($_POST['workperiod']['save'] ))
2439
		{
2440
			try {
2441
				absences_saveWorkperiodRecoverRequest($_POST['workperiod'], $request);
2442
				
2443
			} catch (Exception $e)
2444
			{
2445
				$page->addError($e->getMessage());
2446
			}
2447
		}
2448
	}
2449
	
2450
	
2451
	$page->setTitle(absences_translate('Create a working days report entitling recovery'));
2452
	
2453 View Code Duplication
	if (absences_lockedForMainteance())
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...
2454
	{
2455
		$page->addError(absences_getMaintenanceMessage());
2456
		
2457
	} else {
2458
	
2459
		$editor = new absences_WorkperiodRecoverRequestEditor($request, isset($spoofed), false);
2460
		$page->addItem($editor);
2461
		
2462
	}
2463
	
2464
	$page->displayHtml();
2465
}
2466
2467
2468
2469
2470 View Code Duplication
function absences_cetGotoList()
0 ignored issues
show
Best Practice introduced by
The function absences_cetGotoList() has been defined more than once; this definition is ignored, only the first definition in programs/vacadmcet.php (L152-159) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
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...
2471
{
2472
    $agent = absences_Agent::getCurrentUser();
2473
2474
    if (!empty($_POST['cet']['id_user'])) {
2475
2476
2477
        if ($agent->isManager()) {
2478
            $url = new bab_url(absences_addon()->getUrl().'vacadmcet');
2479
            $url->location();
2480
            return;
2481
        }
2482
2483
        //TODO: liste des demandes de l'entite si gestionnaire delegue
2484
    }
2485
2486
    $url = bab_url::get_request('tg');
2487
    $url->idx = 'lvreq';
2488
    $url->location();
2489
}
2490
2491
2492
/**
2493
 * Save a CET request
2494
 * 
2495
 * 
2496
 * @param array 					 $cet					posted form
2497
 * @param absences_CetDepositRequest $cet_deposit_request	Current request to modify or null for new request
2498
 */
2499
function absences_saveCetDepositRequest(Array $cet, absences_CetDepositRequest $cet_deposit_request = null)
2500
{
2501
	require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php';
2502
	require_once dirname(__FILE__).'/utilit/agent_right.class.php';
2503
	
2504
	$babBody = bab_getInstance('babBody');
2505
	/* @var $babBody babBody */
2506
	
2507
	
2508
	if (absences_lockedForMainteance())
2509
	{
2510
		return false;
2511
	}
2512
	
2513
2514
	$quantity = (float) str_replace(',', '.', $cet['quantity']);
2515
	$agent_right = absences_AgentRight::getById((int) $cet['id_agent_right_source']);
2516
	
2517
	
2518
	$agent = $agent_right->getAgent();
2519
	
2520
	if (!isset($cet['id_user']) && bab_getUserId() !== $agent->getIdUser())
2521
	{
2522
		throw new Exception('Not accessible agentRight');
2523
	}
2524
	
2525
	if (isset($cet['id_user']))
2526
	{
2527
	    $currentUser = absences_Agent::getCurrentUser();
2528
	    if (!$currentUser->isManager() && !$currentUser->isSuperiorOf($agent)) {
2529
	        throw new Exception(absences_translate('Access denied to this account'));
2530
	    }
2531
	}
2532
	
2533
	
2534
	$AgentCet = $agent->Cet();
2535
	if (!$AgentCet->testDepositQuantity($agent_right, $quantity))
2536
	{
2537
		return false;
2538
	}
2539
	
2540
	
2541
	
2542
	if (!isset($cet_deposit_request))
2543
	{
2544
		// create the request
2545
		$cet_deposit_request = new absences_CetDepositRequest();
2546
	}
2547
	
2548
	$cet_deposit_request->id_user 				= $agent->getIdUser();
2549
	$cet_deposit_request->id_agent_right_cet 	= $AgentCet->getDepositAgentRight()->id;
2550
	$cet_deposit_request->id_agent_right_source = $agent_right->id;
2551
	$cet_deposit_request->quantity				= $quantity;
2552
	$cet_deposit_request->idfai					= 0;
2553
	$cet_deposit_request->comment				= $cet['comment'];
2554
	$cet_deposit_request->status				= 'Y';
2555
	
2556
	$cet_deposit_request->save();
2557
	
2558
2559
	if ($cet_deposit_request->createApprobationInstance())
2560
	{
2561
		$babBody->addNextPageMessage(absences_translate('Your time saving account deposit has been sent for approval'));
0 ignored issues
show
Documentation introduced by
absences_translate('Your...een sent for approval') is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2562
	} else {
2563
		$babBody->addNextPageMessage(absences_translate('Your time saving account deposit has been saved without approval'));
0 ignored issues
show
Documentation introduced by
absences_translate('Your...aved without approval') is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2564
	}
2565
	
2566
	
2567
	$defer = (bool) absences_getVacationOption('approb_email_defer');
2568
	
2569
	if (!$defer)
2570
	{
2571
		require_once dirname(__FILE__).'/utilit/request.notify.php';
2572
		absences_notifyRequestApprovers();
2573
	}
2574
	
2575
	absences_cetGotoList();
2576
}
2577
2578
2579
2580
function absences_createCetDepositRequest()
2581
{
2582
	require_once dirname(__FILE__).'/utilit/cet_deposit_request.class.php';
2583
	require_once dirname(__FILE__).'/utilit/cet_deposit_request.ui.php';
2584
	
2585
	$agent = absences_Agent::getCurrentUser();
0 ignored issues
show
Unused Code introduced by
$agent 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...
2586
	
2587
	$id = bab_rp('id', null);
2588
	$request = null;
2589
	
2590
	$W = bab_Widgets();
2591
	$page = $W->BabPage();
2592
	
2593
	if (isset($id))
2594
	{
2595
		$request = absences_CetDepositRequest::getById($id);
2596
		if (!$request->canModify())
2597
		{
2598
		    $page->addError(absences_translate('This request is not modifiable'));
2599
		    $page->displayHtml();
2600
			return;
2601
		}
2602
	} elseif (bab_rp('id_user')) {
2603
	    
2604
	    $request = new absences_CetDepositRequest();
2605
	    $request->id_user = bab_rp('id_user');
2606
	    $request->status = '';
2607
	    $request->quantity = 0;
2608
	    
2609
	    $agent = absences_Agent::getFromIdUser($request->id_user);
2610
	    
2611
	    if (!$agent->Cet()->canAdd()) {
2612
	        $page->addError(sprintf(absences_translate('%s is not allowed to use time saving account'), $agent->getName()));
2613
	        $page->displayHtml();
2614
	        return;
2615
	    }
2616
	}
2617
	
2618
	
2619
	
2620
	
2621
	
2622
	
2623
2624
	
2625 View Code Duplication
	if (isset($_POST['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...
2626
	{
2627
		if ( isset($_POST['cet']['cancel']) )
2628
		{
2629
			absences_cetGotoList();
2630
		}
2631
	
2632
	
2633
		if( isset($_POST['cet']['save'] ))
2634
		{
2635
			try {
2636
				absences_saveCetDepositRequest($_POST['cet'], $request);
2637
			} catch (Exception $e)
2638
			{
2639
				$page->addError($e->getMessage());
2640
			}
2641
		}
2642
	}
2643
	
2644
	if (isset($request) && $request->id)
2645
	{
2646
		$page->setTitle(absences_translate('Edit the time saving account deposit'));
2647
	} else {
2648
		$page->setTitle(absences_translate('Request a deposit in my time saving account'));
2649
	}
2650
2651 View Code Duplication
	if (absences_lockedForMainteance())
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...
2652
	{
2653
		$page->addError(absences_getMaintenanceMessage());
2654
2655
	} else {
2656
	
2657
		$editor = new absences_CetDepositRequestEditor($request, isset($_REQUEST['id_user']));
2658
		$page->addItem($editor);
2659
	}
2660
	
2661
	$page->displayHtml();
2662
}
2663
2664
2665
2666
2667
2668
2669
2670
/**
2671
 * Display a menu to create vacation request, CET request, workingdays recovery request
2672
 * @return string
2673
 */
2674
function absences_requestMenu()
2675
{
2676
	$toolbar = absences_getToolbar();
2677
	$agent = absences_Agent::getCurrentUser();
2678
	$addon = absences_addon();
2679
	
2680
	$sImgPath = $GLOBALS['babInstallPath'] . 'skins/ovidentia/images/Puces/';
2681
	
2682
	
2683
	
2684
	$toolbar->addToolbarItem(
2685
			new BAB_ToolbarItem(absences_translate('Request a vacation'), $addon->getUrl().'vacuser&idx=period',
2686
					$sImgPath . 'edit_add.png', '', '', '')
2687
	);
2688
	
2689 View Code Duplication
	if ($agent->canCreateWorkperiodRecoverRequest()) {
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...
2690
		$toolbar->addToolbarItem(
2691
				new BAB_ToolbarItem(absences_translate("Recovery request"), $addon->getUrl().'vacuser&idx=workperiod',
2692
						$sImgPath . 'edit_add.png', '', '', '')
2693
		);
2694
	}
2695
	
2696 View Code Duplication
	if ($agent->Cet()->canAdd()) {
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...
2697
		$toolbar->addToolbarItem(
2698
				new BAB_ToolbarItem(absences_translate("Deposit on my time saving account"), $addon->getUrl().'vacuser&idx=cet',
2699
						$sImgPath . 'edit_add.png', '', '', '')
2700
		);
2701
	}
2702
	
2703
	return $toolbar->printTemplate();
2704
}
2705
2706
2707
2708
function absences_personalMovements()
2709
{
2710
	require_once dirname(__FILE__).'/utilit/agent.class.php';
2711
	require_once dirname(__FILE__).'/utilit/agent.ui.php';
2712
	
2713
	$babBody = bab_getBody();
2714
	$agent = absences_Agent::getCurrentUser();
2715
	
2716
	
2717
	$list = new absences_AgentMovementList($agent);
2718
	
2719
	$babBody->setTitle(absences_translate('My history'));
2720
	
2721
	$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
2722
	$babBody->addItemMenu("movement", absences_translate("History"), absences_addon()->getUrl()."vacuser&idx=movement");
2723
	
2724
	if (absences_getVacationOption('user_add_email'))
2725
	{
2726
		$babBody->addItemMenu("options", absences_translate("Options"), absences_addon()->getUrl()."vacuser&idx=options");
2727
	}
2728
2729
	$babBody->babEcho($list->getHtml());
2730
}
2731
2732
2733
2734
2735
/**
2736
 * 
2737
 */
2738
function absences_personalOptions()
2739
{
2740
	global $babBody;
2741
	
2742
	require_once dirname(__FILE__).'/utilit/agent.class.php';
2743
	require_once dirname(__FILE__).'/utilit/agent.ui.php';
2744
	require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
2745
	
2746
	$agent = absences_Agent::getCurrentUser();
2747
	
2748
	
2749
	
2750
	
2751
	
2752
	$W = bab_Widgets();
2753
	$page = $W->BabPage();
2754
	
2755
	
2756
	if ($options = bab_pp('options'))
2757
	{
2758
		$emails = $options['emails'];
2759
		$agent->setEmails($emails);
2760
		
2761
		$babBody->addNextPageMessage(absences_translate('The emails were saved'));
2762
		
2763
		$url = bab_url::get_request('tg', 'idx');
2764
		$url->location();
2765
	}
2766
	
2767
	
2768
	
2769
	$page->setTitle(absences_translate('My options'));
2770
	
2771
	$page->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
2772
	
2773
	if (absences_getVacationOption('display_personal_history'))
2774
	{
2775
		$page->addItemMenu("movement", absences_translate("History"), absences_addon()->getUrl()."vacuser&idx=movement");
2776
	}
2777
	
2778
	$page->addItemMenu("options", absences_translate("Options"), absences_addon()->getUrl()."vacuser&idx=options");
2779
	
2780
	
2781
	$editor = new absences_PersonalOptionsEditor;
2782
	$page->addItem($editor);
2783
	
2784
	
2785
	$page->displayHtml();
2786
}
2787
2788
2789
2790
2791
2792
2793
function absences_personalRights_addRightInTable(Widget_TableView $table, $row, absences_Right $right, absences_AgentRight $agentRight)
2794
{
2795
    $W = bab_Widgets();
2796
    $type = $right->getType();
2797
    
2798
    $icon = $W->Frame();
2799
    $icon->setCanvasOptions($icon->Options()->width(10,'px')->height(10,'px')->backgroundColor('#'.$type->color));
2800
    $icon->setTitle($type->name);
2801
2802
    $col = 0;
2803
    
2804
    $table->addItem($W->HBoxItems($icon,$W->Label($right->description))
2805
        ->setHorizontalSpacing(.8,'em')->setVerticalAlign('middle')									, $row, $col++);
2806
    $table->addItem($W->Label(absences_quantity($agentRight->getQuantity(), $right->quantity_unit))				, $row, $col++);
2807
    $table->addItem($W->Label(absences_quantity($agentRight->getConfirmedQuantity(), $right->quantity_unit))	, $row, $col++);
2808
    $table->addItem($W->Label(absences_quantity($agentRight->getWaitingQuantity(), $right->quantity_unit))		, $row, $col++);
2809
    $balance = $agentRight->getQuantity() - $agentRight->getConfirmedQuantity() - $agentRight->getWaitingQuantity();
2810
    $table->addItem($W->Label(absences_quantity($balance, $right->quantity_unit))								, $row, $col++);
2811
    $previsional = $agentRight->getPrevisionalQuantity();
2812
    $table->addItem($W->Label(absences_quantity($previsional, $right->quantity_unit))		                    , $row, $col++);
2813
    $table->addItem($W->Label(absences_quantity($balance - $previsional, $right->quantity_unit))		        , $row, $col++);
2814
    $table->addItem($W->Label(bab_shortDate(bab_mktime($right->date_begin), false))								, $row, $col++);
2815
    $table->addItem($W->Label(bab_shortDate(bab_mktime($right->date_end), false))								, $row, $col++);
2816
}
2817
2818
2819
2820
function absences_personalRights()
2821
{
2822
	$W = bab_Widgets();
2823
	$agent = absences_Agent::getCurrentUser();
2824
	
2825
	if (!$agent->exists())
2826
	{
2827
		return;
2828
	}
2829
	
2830
	$page = $W->BabPage()->setEmbedded(false);
2831
	$page->setTitle(absences_translate('My vacations rights'));
2832
	
2833
	$table = $W->BabTableView();
2834
	
2835
	$row = 0;
2836
	$col = 0;
2837
	$table->addHeadRow(0);
2838
	
2839
	$table->addItem($W->Label(absences_translate('Description'))	, $row, $col++);
2840
	$table->addItem($W->Label(absences_translate('Rights'))			, $row, $col++);
2841
	$table->addItem($W->Label(absences_translate('Consumed'))		, $row, $col++);
2842
	$table->addItem($W->Label(absences_translate('Waiting'))		, $row, $col++);
2843
	$table->addItem($W->Label(absences_translate('Balance'))		, $row, $col++);
2844
	$table->addItem($W->Label(absences_translate('Previsional'))	, $row, $col++);
2845
	$table->addItem($W->Label(absences_translate('Previ. Bal.'))	, $row, $col++);
2846
	$table->addItem($W->Label(absences_translate('Begin date'))		, $row, $col++);
2847
	$table->addItem($W->Label(absences_translate('End date'))		, $row, $col++);
2848
	$row++;	
2849
	
2850
	$I = $agent->getAgentRightUserIterator();
2851
	
2852
	$rows = array();
2853
	
2854
	foreach($I as $agentRight)
2855
	{
2856
		
2857
	    $right = $agentRight->getRight();
2858
		$rgroup = $right->getRgroupLabel();
2859
2860
2861
		if ($rgroup)
2862
		{
2863
			if (!isset($rows['rgroup'.$right->id_rgroup])) {
2864
    			$rows['rgroup'.$right->id_rgroup] = array(
2865
    			    'sortkey' => $right->getRgroupSortkey(),
2866
    			    'rgroup' => array()
2867
    			);
2868
			}
2869
			
2870
			$rows['rgroup'.$right->id_rgroup]['rgroup'][] = $agentRight;
2871
			continue;
2872
		}
2873
		
2874
		$rows['right'.$right->id] = array(
2875
		    'sortkey' => $right->sortkey,
2876
		    'agentRight' => $agentRight
2877
		);		
2878
	}
2879
	
2880
	bab_Sort::asort($rows, 'sortkey');
2881
	
2882
	foreach($rows as $arr_row) {
2883
	    
2884
	    if (isset($arr_row['rgroup'])) {
2885
	        $rgroup = reset($arr_row['rgroup'])->getRight()->getRgroupLabel();
2886
	        $table->addItem($W->Label($rgroup)->addClass('widget-strong'), $row, 0, -1, 9);
2887
	        $row++;
2888
	        
2889
	        foreach($arr_row['rgroup'] as $agentRight) {
2890
	            $right = $agentRight->getRight();
2891
	            $right->description = bab_nbsp().bab_nbsp().bab_nbsp().bab_nbsp().$right->description;
2892
	            absences_personalRights_addRightInTable($table, $row, $right, $agentRight);
2893
	            $row++;
2894
	        }
2895
	        
2896
	        continue;
2897
	    }
2898
	    
2899
	    
2900
	    $agentRight = $arr_row['agentRight'];
2901
	    $right = $agentRight->getRight();
2902
	    
2903
	    absences_personalRights_addRightInTable($table, $row, $right, $agentRight);
2904
	    $row++;
2905
	}
2906
	
2907
	
2908
	
2909
	
2910
	$page->addItem($table);
2911
	$print = $W->Link($W->Icon(absences_translate('Print'), Func_Icons::ACTIONS_DOCUMENT_PRINT), 'javascript:window.print()');
2912
	$page->addItem($W->Frame()->addClass(Func_Icons::ICON_LEFT_16)->addClass('widget-align-center')->addItem($print));
2913
	
2914
	$page->displayHtml();
2915
}
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
/**
2926
 * @param string $date
2927
 * @return array
2928
 */
2929
function absences_getDayWorkingHours($date)
2930
{
2931
    require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
2932
    
2933
    $id_user = bab_gp('id_user');
2934
    $agent = absences_Agent::getFromIdUser(bab_getUserId());
2935
    
2936
    if ($id_user != $agent->getIdUser() && !absences_IsUserUnderSuperior($id_user) && !$agent->isManager()) {
2937
        throw new Exception('Access denied');
2938
    }
2939
    
2940
    $wh = bab_functionality::get('WorkingHours');
2941
    /* @var $wh Func_WorkingHours */
2942
    
2943
    $begin = BAB_DateTime::fromIsoDateTime(bab_gp('date').' 00:00:00');
2944
    $end = clone $begin;
2945
    $end->add(1, BAB_DATETIME_DAY);
2946
    
2947
    return $wh->selectPeriods($id_user, $begin, $end);
2948
}
2949
2950
2951
2952
2953
2954
2955
2956
2957
/**
2958
 * Create or edit a request period 
2959
 * first step of a vacation request
2960
 */
2961
function absences_requestPeriod()
2962
{
2963
	include_once dirname(__FILE__)."/utilit/planningincl.php";
2964
	global $babBody;
2965
	$agent = absences_Agent::getCurrentUser();
2966
	
2967
	
2968
	
2969
	
2970
	
2971
	
2972
	if (!empty($_REQUEST['id']))
2973
	{
2974
		// request modification
2975
		
2976
		
2977 View Code Duplication
		if (bab_rp('rfrom'))
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...
2978
		{
2979
			if ($agent->isManager() && !bab_rp('ide'))
2980
			{
2981
				// request modification from a manager
2982
			
2983
				$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
2984
				$babBody->addItemMenu("lper", absences_translate("Requests"), absences_addon()->getUrl()."vacadmb&idx=lreq");
2985
				$babBody->addItemMenu("period", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=period");
2986
			}
2987
			
2988
			if ($agent->isEntityManager() && bab_rp('ide'))
2989
			{
2990
				// request modification from a delegated manager
2991
			
2992
				$babBody->addItemMenu("entities", absences_translate("Delegated management"), absences_addon()->getUrl()."vacchart&idx=entities");
2993
				$babBody->addItemMenu("entity_members", absences_translate("Entity requests"), absences_addon()->getUrl()."vacchart&idx=entity_requests&ide=".bab_rp('ide'));
2994
				$babBody->addItemMenu("period", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=period&ide=".bab_rp('ide'));
2995
			}
2996
			
2997
			
2998
		} else {
2999
			
3000
			// request modification from agent
3001
		
3002
			$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3003
			$babBody->addItemMenu("period", absences_translate("Edit"), absences_addon()->getUrl()."vacuser&idx=period&id=".bab_rp('id'));
3004
			
3005
			if( $agent->isManager())
3006
			{
3007
				$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3008
			}
3009
			if ($agent->isEntityManager())
3010
			{
3011
				$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3012
			}
3013
		
3014
		
3015
		}
3016
		
3017
		
3018
		$babBody->setTitle(absences_translate("Edit vacation request"));
3019
		
3020
		if (absences_lockedForMainteance())
3021
		{
3022
			$babBody->addError(absences_getMaintenanceMessage());
3023
			return false;
3024
		}
3025
		
3026
		
3027
		$id_user = bab_isEntryEditable($_REQUEST['id']);
3028
		if (!$id_user)
3029
		{
3030
			$babBody->addError(absences_translate("Access denied, this request is not modifiable"));
3031
			return false;
3032
		}
3033 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...
3034
		{
3035
			absences_viewVacationCalendar(array($id_user), true, true, bab_rp('nbmonth', 12), false);
3036
			period($id_user, $_REQUEST['id']);
3037
			return true;
3038
		}
3039
	}
3040
	else
3041
	{
3042
		
3043
		// request creation
3044
		
3045
		if (isset($_GET['idu']) && is_numeric($_GET['idu'])) {
3046
			$id_user = $_GET['idu']; // deprecated?
3047
		}
3048 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...
3049
			$id_user = bab_rp('id_user', bab_getUserId());
3050
			
3051
			if (bab_rp('rfrom'))
3052
			{
3053
			
3054
				if ($agent->isManager() && !bab_rp('ide'))
3055
				{
3056
					// request creation from a manager
3057
					
3058
					$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
3059
					$babBody->addItemMenu("lper", absences_translate("Personnel"), absences_addon()->getUrl()."vacadm&idx=lper");
3060
					$babBody->addItemMenu("period", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=period");
3061
				}
3062
				
3063
				if ($agent->isEntityManager() && bab_rp('ide'))
3064
				{
3065
					// request creation from a delegated manager
3066
					
3067
					$babBody->addItemMenu("entities", absences_translate("Delegated management"), absences_addon()->getUrl()."vacchart&idx=entities");
3068
					$babBody->addItemMenu("entity_members", absences_translate("Entity members"), absences_addon()->getUrl()."vacchart&idx=entity_members&ide=".bab_rp('ide'));
3069
					$babBody->addItemMenu("period", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=period");
3070
				}
3071
			
3072
			} else {
3073
				
3074
				// request creation from agent
3075
				
3076
				$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3077
				$babBody->addItemMenu("period", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=period");
3078
				
3079
				
3080
				if( $agent->isManager())
3081
				{
3082
					$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3083
				}
3084
				if ($agent->isEntityManager())
3085
				{
3086
					$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3087
				}
3088
				
3089
			}
3090
		}
3091
		
3092
		
3093
		if ($id_user == bab_getUserId())
3094
		{
3095
			$babBody->setTitle(absences_translate("Request vacation"));
3096
		} else {
3097
			$babBody->setTitle(absences_translate("Request vacation for another user")); // rfrom=1
3098
		}
3099
		
3100
		if (absences_lockedForMainteance())
3101
		{
3102
			$babBody->addError(absences_getMaintenanceMessage());
3103
			return false;
3104
		}
3105
		
3106
	
3107 View Code Duplication
		if (bab_vacRequestCreate($id_user)) {
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...
3108
			absences_viewVacationCalendar(array($id_user), true, true, bab_rp('nbmonth', 12), false);
3109
			period($id_user);
3110
			return true;
3111
		}
3112
	}
3113
	
3114
	$babBody->addError(absences_translate("Access denied, no access to create a request"));
3115
	return false;
3116
}
3117
3118
3119
3120
3121
3122
/* main */
3123
bab_requireCredential();
3124
$agent = absences_Agent::getCurrentUser();
3125
$idx = bab_rp('idx', "lvreq");
3126
3127
3128 View Code Duplication
if(!$agent->isInPersonnel() && !$agent->isEntityManager() && !$agent->isManager())
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...
3129
	{
3130
	$babBody->msgerror = absences_translate("Access denied");
3131
	return;
3132
	}
3133
3134
3135
3136
if (isset($_POST['action']))
3137
{
3138
switch ($_POST['action'])
3139
	{
3140
	case 'period':
3141
		if (!test_period()) {
3142
			$idx = 'period';
3143
		}
3144
		break;
3145
3146
	case 'vacation_request':
3147
		
3148
		$id = bab_pp('id');
3149
		
3150
		if (bab_isEntryEditable($id))
3151
		{
3152
		if(!absences_saveVacation::save()) {
3153
			$idx = "vunew";
3154
			}
3155
		elseif ($_POST['id_user'] == bab_getUserId())
3156
			{
3157
			// demande pour moi meme, retour a la liste de mes demandes
3158
			header("Location: ". absences_addon()->getUrl()."vacuser&idx=lvreq");
3159
			exit;
3160
			}
3161 View Code Duplication
		elseif ($id)
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...
3162
			{
3163
			// modification d'une demande, retour liste des demandes	
3164
			if (bab_pp('ide')) {
3165
				header("Location: ". absences_addon()->getUrl().'vacchart&idx=entity_requests&ide='.bab_pp('ide'));
3166
				exit;
3167
			}
3168
3169
			header("Location: ". absences_addon()->getUrl()."vacadmb&idx=lreq");
3170
			exit;
3171
			}
3172 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...
3173
			{
3174
			// creation d'une demande, retour a la liste des agents
3175
			if (bab_pp('ide')) {
3176
				header("Location: ". absences_addon()->getUrl().'vacchart&idx=entity_members&ide='.bab_pp('ide'));
3177
				exit;
3178
			}
3179
			
3180
			header("Location: ". absences_addon()->getUrl()."vacadm&idx=lper");
3181
			exit;
3182
			}
3183
		}
3184
		break;
3185
3186
	case 'delete_request':
3187
		
3188
		if ($id_entry = bab_pp('id_entry'))
3189
		{
3190
			$id_user = bab_isEntryEditable($id_entry);
3191
			if ($id_user || $agent->isManager())
3192
			{
3193
				if (absences_delete_request(bab_pp('id_entry'), bab_pp('folder', 0), (int) bab_pp('rfrom', 0)))
3194
				{
3195
					header("Location: ". bab_pp('url'));
3196
					exit;
3197
				} else {
3198
					$babBody->addError(absences_translate('Failed to delete the vacation request'));
3199
				}
3200
			}
3201
		}
3202
		
3203
		
3204 View Code Duplication
		if ($id_deposit = bab_pp('id_deposit'))
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...
3205
		{
3206
			require_once dirname(__FILE__).'/utilit/cet_deposit_request.class.php';
3207
			$deposit = absences_CetDepositRequest::getById($id_deposit);
3208
			if ($deposit->canDelete())
3209
			{
3210
				$deposit->delete();
3211
				$url = new bab_url(bab_pp('url'));
3212
				$url->location();
3213
			}
3214
		}
3215
		
3216
		
3217 View Code Duplication
		if ($id_recovery = bab_pp('id_recovery'))
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...
3218
		{
3219
			require_once dirname(__FILE__).'/utilit/workperiod_recover_request.class.php';
3220
			$recovery = absences_WorkperiodRecoverRequest::getById($id_recovery);
3221
			if ($recovery->canDelete())
3222
			{
3223
				$recovery->delete();
3224
				$url = new bab_url(bab_pp('url'));
3225
				$url->location();
3226
			}
3227
		}
3228
		
3229
		break;
3230
	}
3231
}
3232
3233
3234
3235
3236
3237
switch($idx)
3238
	{
3239
3240
	case "unload":
3241
		vedUnload();
3242
		exit;
3243
		break;
3244
3245 View Code Duplication
	case "morve":
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...
3246
		require_once dirname(__FILE__).'/utilit/request.ui.php';
3247
		$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3248
		$babBody->addItemMenu("morve", absences_translate("View request"), absences_addon()->getUrl()."vacuser&idx=lvreq&id=".bab_rp('id'));
3249
		absences_viewVacationRequestDetail(bab_rp('id'));
3250
		break;
3251
		
3252 View Code Duplication
	case 'view_cet_deposit':
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...
3253
		require_once dirname(__FILE__).'/utilit/request.ui.php';
3254
		$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3255
		$babBody->addItemMenu("view_cet_deposit", absences_translate("View request"), absences_addon()->getUrl()."vacuser&idx=view_cet_deposit&id=".bab_rp('id'));
3256
		absences_viewCetDepositDetail(bab_rp('id'));
3257
		break;
3258
3259 View Code Duplication
	case 'view_wp_recovery':
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...
3260
		require_once dirname(__FILE__).'/utilit/request.ui.php';
3261
		$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3262
		$babBody->addItemMenu("view_wp_recovery", absences_translate("View request"), absences_addon()->getUrl()."vacuser&idx=view_wp_recovery&id=".bab_rp('id'));
3263
		absences_viewWpRecoveryDetail(bab_rp('id'));
3264
		break;
3265
		
3266
	case "period":
3267
		// demande, premiere etape
3268
		absences_requestPeriod();
3269
		break;
3270
		
3271
		
3272
	case 'recurring':
3273
		if( bab_isEntryEditable($_POST['id']) )
3274
		{
3275
			absences_recurringVacation(absences_PostedDate::begin(), absences_PostedDate::end(), $_POST['id']);
3276
			
3277
			$babBody->addItemMenu("recurring", absences_translate("Request"), absences_addon()->getUrl()."vacuser&idx=vunew");
3278
			$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3279
		}
3280
		if($agent->isManager())
3281
			$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3282
		if ($agent->isEntityManager())
3283
			$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3284
		break;
3285
3286
	case "vunew":
3287
		// demande, deuxieme etape
3288
		requestVacation(absences_PostedDate::begin(), absences_PostedDate::end(), $_POST['id'], bab_pp('rfrom'), bab_pp('ide'));
3289
		break;
3290
3291
	case 'delete':
3292
		
3293
		$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3294
		
3295
		if ($id_entry = bab_rp('id_entry'))
3296
		{
3297
			$babBody->addItemMenu("delete", absences_translate("Delete request"), absences_addon()->getUrl()."vacuser&idx=delete&id_entry=".$id_entry);
3298
			absences_deleteVacationRequest($id_entry);
3299
		}
3300
		
3301
		if ($id_cetdeposit = bab_rp('id_cetdeposit'))
3302
		{
3303
			$babBody->addItemMenu("delete", absences_translate("Delete request"), absences_addon()->getUrl()."vacuser&idx=delete&id_cetdeposit=".$id_cetdeposit);
3304
			absences_deleteCetDepositRequest($id_cetdeposit);
3305
		}
3306
		
3307
		if ($id_recovery = bab_rp('id_recovery'))
3308
		{
3309
			$babBody->addItemMenu("delete", absences_translate("Delete request"), absences_addon()->getUrl()."vacuser&idx=delete&id_recovery=".$id_recovery);
3310
			absences_deleteWpRecoveryRequest($id_recovery);
3311
		}
3312
		
3313
		break;
3314
3315
	case 'viewrights':
3316
		if (absences_IsUserUnderSuperior($_GET['id_user']) || $agent->isManager()) {
3317
			$babBody->setTitle(absences_translate("Balance").' : '.bab_getUserName($_GET['id_user']));
3318
3319
			if (isset($_GET['ide'])) {
3320
				$babBody->addItemMenu("entity_members", absences_translate("Entity members"), absences_addon()->getUrl()."vacchart&idx=entity_members&ide=".$_GET['ide']);
3321
			}
3322
3323
			$babBody->addItemMenu("viewrights", absences_translate("Balance"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3324
			viewrights($_GET['id_user']);
3325
		} else {
3326
			$babBody->msgerror = absences_translate("Access denied");
3327
		}
3328
		break;
3329
3330
		
3331
	case 'subprev':
3332
		$id_entry = (int) bab_rp('id_entry');
3333
		if ($id_entry && bab_isEntryEditable($id_entry))
3334
		{
3335
			absences_saveVacation::submitRequest($id_entry);
3336
			absences_saveVacation::gotoList();
3337
		} else {
3338
			$babBody->msgerror = absences_translate("Access denied to request modification");
3339
		}
3340
			
3341
		break;
3342
		
3343 View Code Duplication
	case 'workperiod':
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...
3344
		absences_createWorkperiodRecoverRequest();
3345
		
3346
		
3347
		if (!bab_rp('id_user')) {
3348
		  $babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3349
		}
3350
		
3351
		$babBody->addItemMenu("workperiod", absences_translate("Working day"), absences_addon()->getUrl()."vacuser&idx=workperiod");
3352
		
3353
		if( $agent->isManager())
3354
			$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3355
		
3356
		if ($agent->isEntityManager())
3357
			$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3358
		break;
3359
		
3360 View Code Duplication
	case '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...
3361
		absences_createCetDepositRequest();
3362
		
3363
		if (!bab_rp('id_user')) {
3364
		    $babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3365
		}
3366
		
3367
		$babBody->addItemMenu("cet", absences_translate("Time saving account"), absences_addon()->getUrl()."vacuser&idx=cet");
3368
		
3369
		if( $agent->isManager())
3370
			$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3371
		
3372
		if ($agent->isEntityManager())
3373
			$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3374
		break;
3375
		
3376
	case 'movement':
3377
		
3378
		absences_personalMovements();
3379
		break;
3380
		
3381
	case 'options':
3382
		absences_personalOptions();
3383
		break;
3384
		
3385
	case 'myrights':
3386
		absences_personalRights();
3387
		die();
3388
		break;
3389
		
3390
		
3391
	case 'workinghours':
3392
	    require_once $GLOBALS['babInstallPath'].'utilit/json.php';
3393
	    echo bab_json_encode(absences_getDayWorkingHours(bab_gp('date')));
3394
	    die();
3395
3396
	case 'clear':
3397
		$babDB->db_query("TRUNCATE ".ABSENCES_CALENDAR_TBL);
3398
3399
	case "lvreq":
3400
	default:
3401
		$babBody->title = absences_translate("My already filed requests");
3402
		if( $agent->isInPersonnel() )
3403
		{
3404
			$babBody->babEcho(absences_requestMenu());
3405
			absences_listVacationRequests(bab_getUserId(), false);
3406
			$babBody->addItemMenu("lvreq", absences_translate("Requests"), absences_addon()->getUrl()."vacuser&idx=lvreq");
3407
			if (absences_getVacationOption('display_personal_history'))
3408
			{
3409
				$babBody->addItemMenu("movement", absences_translate("History"), absences_addon()->getUrl()."vacuser&idx=movement");
3410
			}
3411
			
3412
			if (absences_getVacationOption('user_add_email'))
3413
			{
3414
				$babBody->addItemMenu("options", absences_translate("Options"), absences_addon()->getUrl()."vacuser&idx=options");
3415
			}
3416
			
3417
		} else {
3418
			
3419 View Code Duplication
			if ($agent->isManager() && 'lvreq' === $idx)
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...
3420
			{
3421
				// manager only
3422
				$url = new bab_url;
3423
				$url->tg = 'addon/absences/vacadm';
3424
				$url->location();
3425
			}
3426
			
3427 View Code Duplication
			if ($agent->isEntityManager() && 'lvreq' === $idx)
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...
3428
			{
3429
				// delegated manager only
3430
				$url = new bab_url;
3431
				$url->tg = 'addon/absences/vacchart';
3432
				$url->location();
3433
			}
3434
		}
3435
			
3436
		if( $agent->isManager())
3437
		{
3438
			$babBody->addItemMenu("list", absences_translate("Management"), absences_addon()->getUrl()."vacadm");
3439
		}
3440
3441
		if ($agent->isEntityManager())
3442
		{
3443
			$babBody->addItemMenu("entities", absences_translate("Delegate management"), absences_addon()->getUrl()."vacchart&idx=entities");
3444
		}
3445
		break;
3446
	}
3447
3448
if ( absences_isPlanningAccessValid())
3449
{
3450
	$babBody->addItemMenu("planning", absences_translate("Plannings"), absences_addon()->getUrl()."planning&idx=userlist");
3451
}
3452
3453
3454
3455
3456
$babBody->setCurrentItemMenu($idx);
3457
bab_siteMap::setPosition('absences','User');
3458
3459