Completed
Push — master ( 0d2d5a...8b85c2 )
by Paul
03:29
created

absences_viewVacationCalendarCls   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 586
Duplicated Lines 1.71 %

Coupling/Cohesion

Components 5
Dependencies 8

Importance

Changes 13
Bugs 2 Features 1
Metric Value
c 13
b 2
f 1
dl 10
loc 586
rs 6.8539
wmc 54
lcom 5
cbo 8

13 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 195 14
C getDateFilter() 10 78 7
A getTitle() 0 15 2
A getnexthidden() 0 17 3
A getdayname() 0 12 2
A getmonth() 0 20 2
B getnextuser() 0 39 6
A getday() 0 17 2
A getnexttype() 0 17 3
A entity() 0 19 4
B publiccalendar() 0 40 4
A getHtml() 0 18 2
A printhtml() 0 22 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like absences_viewVacationCalendarCls often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use absences_viewVacationCalendarCls, and based on these observations, apply Extract Interface, too.

1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia is free software; you can redistribute it and/or modify    *
10
 * it under the terms of the GNU General Public License as published by *
11
 * the Free Software Foundation; either version 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  GNU General Public License for more details.				*
18
 *																		*
19
 * You should have received a copy of the GNU General Public License	*
20
 * along with this program; if not, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
26
require_once dirname(__FILE__).'/vacincl.php';
27
28
29
30
31
32
/**
33
 * Get period index from database
34
 *
35
 * @param	int		$id_user
36
 * @param	int		$month
37
 * @param	int		$year
38
 * @param   string  $dateb      ISO date
39
 * @param   string  $datee      ISO date
40
 *
41
 * @return array
42
 */
43
function absences_getPeriodIndex($id_user, $month, $year, $dateb, $datee)
44
{
45
	require_once $GLOBALS['babInstallPath'].'utilit/settings.class.php';
46
	global $babDB;
47
48
	$req = "
49
	SELECT 
50
		c.id_user,
51
		c.cal_date,
52
		c.ampm,
53
		c.period_type,
54
		c.id_entry,
55
		c.color,
56
		c.title,
57
		e.status 
58
	FROM
59
		".ABSENCES_CALENDAR_TBL." c
60
		LEFT JOIN ".ABSENCES_ENTRIES_TBL." e ON e.id = c.id_entry 
61
	WHERE
62
		monthkey=".$babDB->quote($month.$year)."
63
		AND c.id_user=".$babDB->quote($id_user)."
64
	ORDER BY c.cal_date, c.ampm 
65
	";
66
	$res = $babDB->db_query($req);
67
68
69
	if (0 === $babDB->db_num_rows($res))
70
	{
71
		// cache not found
72
73
		absences_updateCalendar($id_user, $year, $month);
74
		$res = $babDB->db_query($req);
75
	}
76
77
78
	$periodIndex = array();
79
	
80
	while ($arr = $babDB->db_fetch_assoc($res)) {
81
	    /*
82
	    if ('0000-00-00' !== $dateb && $dateb > $arr['cal_date']) {
83
	        continue;
84
	    }
85
	    
86
	    if ('0000-00-00' !== $datee && $datee < $arr['cal_date']) {
87
	        continue;
88
	    }
89
		*/
90
		$arr['period_type'] = (int) $arr['period_type'];
91
		$arr['ampm'] = (int) $arr['ampm'];
92
		$arr['id_user'] = (int) $arr['id_user'];
93
		
94
		$key = 'd.'.$arr['cal_date'];
95
		$key .= $arr['ampm'] ? '.1' : '.0';
96
		$periodIndex[$key] = $arr;
97
	}
98
99
100
	return $periodIndex;
101
}
102
103
104
105
106
107
/**
108
 * 
109
 */
110 View Code Duplication
function absences_getEntites()
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...
111
{
112
    $id_chart = absences_getVacationOption('id_chart');
113
    $org = new bab_OrgChartUtil($id_chart);
114
    if (!$org->isAccessValid()) {
115
        return array();
116
    }
117
    return bab_OCGetEntities($id_chart);
118
}
119
120
/**
121
 * 
122
 * @param int $ide
123
 */
124 View Code Duplication
function absences_getChildsEntities($ide)
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...
125
{
126
    $id_chart = absences_getVacationOption('id_chart');
127
    $org = new bab_OrgChartUtil($id_chart);
128
    if (!$org->isAccessValid()) {
129
        return array();
130
    }
131
    return bab_OCGetChildsEntities($ide, $id_chart);
132
}
133
134
135
136
137
class absences_viewVacationCalendarCls
138
{
139
	var $entries = array();
140
	var $fullname;
141
	var $vacwaitingtxt;
142
	var $vacapprovedtxt;
143
	var $print;
144
	var $close;
145
	var $emptylines = true;
146
147
	public $display_types;
148
	
149
	
150
	public $public = false;
151
	public $total = null;
152
	
153
	public $loadmore = null;
154
	public $loadall = false;
155
	
156
	public $nbmonth;
157
	
158
	public $limit;
159
160
161
	/**
162
	 * 
163
	 * @param array 	$users			Users displayed by default
164
	 * @param bool 		$period			Allow period selection (vacation request creation first step)
165
	 * @param bool 		$display_types	Display types color and legend on planning
166
	 * @param int		$nbmonth		Number of month to load
167
	 * @param bool		$dispusers		Display user names column
168
	 */
169
	public function __construct($users, $period, $display_types, $nbmonth, $dispusers, $shiftmonth = 0, $legend = true)
170
	{
171
		global $babBody;
172
173
		include_once $GLOBALS['babInstallPath']."utilit/dateTime.php";
174
		include_once $GLOBALS['babInstallPath']."utilit/urlincl.php";
175
176
		$month = isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : (date("n") + $shiftmonth);
177
		$year = isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : date("Y");
178
179
		global $babDB;
180
		$this->month = $month;
0 ignored issues
show
Bug introduced by
The property 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...
181
		$this->year = $year;
0 ignored issues
show
Bug introduced by
The property 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...
182
183
		$this->dispusers = $dispusers;
0 ignored issues
show
Bug introduced by
The property dispusers 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->display_types = $display_types;
185
		$this->display_legend = $legend;
0 ignored issues
show
Bug introduced by
The property display_legend 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
187
		$this->userNameArr = array();
0 ignored issues
show
Bug introduced by
The property userNameArr 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...
188
		
189
		foreach ($users as $uid)
190
		{
191
			$uid = (int) $uid;
192
			$this->userNameArr[$uid] = bab_getUserName($uid);
193
		}
194
195
		bab_sort::natcasesort($this->userNameArr);
196
197
198
		$this->idusers 		= array_keys($this->userNameArr);
0 ignored issues
show
Bug introduced by
The property idusers 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->nbusers 		= count($this->idusers);
0 ignored issues
show
Bug introduced by
The property nbusers 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->firstuser 	= bab_toHtml(current($this->userNameArr));
0 ignored issues
show
Bug introduced by
The property firstuser 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->display_firstuser = 1 === $this->nbusers;
0 ignored issues
show
Bug introduced by
The property display_firstuser does not seem to exist. Did you mean firstuser?

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...
202
203
		$this->period = $period;
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...
204
		$this->vacwaitingtxt = absences_translate("Waiting vacation request");
205
		$this->vacapprovedtxt = absences_translate("Approved vacation request");
206
		$this->t_selected = absences_translate("Selected period");
0 ignored issues
show
Bug introduced by
The property t_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...
207
		$this->print = absences_translate("Print");
208
		$this->close = absences_translate("Close");
209
		$this->t_noresult = absences_translate("No results found for this search query");
0 ignored issues
show
Bug introduced by
The property t_noresult 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
211
		$this->t_previousmonth = absences_translate("Previous month");
0 ignored issues
show
Bug introduced by
The property t_previousmonth 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...
212
		$this->t_previousyear = absences_translate("Previous year");
0 ignored issues
show
Bug introduced by
The property t_previousyear 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
		$this->t_nextmonth = absences_translate("Next month");
0 ignored issues
show
Bug introduced by
The property t_nextmonth 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...
214
		$this->t_nextyear = absences_translate("Next year");
0 ignored issues
show
Bug introduced by
The property t_nextyear 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...
215
216
		$this->t_nonworking = absences_translate("Non-working day");
0 ignored issues
show
Bug introduced by
The property t_nonworking 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
		$this->t_weekend = absences_translate("Week-end");
0 ignored issues
show
Bug introduced by
The property t_weekend 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...
218
		$this->t_rotate = absences_translate("Print in landscape");
0 ignored issues
show
Bug introduced by
The property t_rotate 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
		$this->t_non_used = $this->display_types ? absences_translate("Non-used days") : absences_translate("Absences");
0 ignored issues
show
Bug introduced by
The property t_non_used 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...
220
		$this->t_waiting = absences_translate("Waiting vacation request");
0 ignored issues
show
Bug introduced by
The property t_waiting does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
222
		$this->t_waiting_vac = absences_translate("Waiting vacation request");
0 ignored issues
show
Bug introduced by
The property t_waiting_vac does not seem to exist. Did you mean t_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...
223
		$this->t_legend = absences_translate("Legend");
0 ignored issues
show
Bug introduced by
The property t_legend 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...
224
225
		$this->id_request = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
0 ignored issues
show
Bug introduced by
The property id_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...
226
227
		$this->nbmonth = $nbmonth;
228
		
229
		$this->limit = absences_getSearchLimit($nbmonth);
230
231
		$urltmp = bab_url::get_request_gp();
232
		$this->nwd_color = 'yellow'; // default color for non working days if no categories
0 ignored issues
show
Bug introduced by
The property nwd_color 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
234
		if( $GLOBALS['babBody']->babsite['id_calendar_cat'] != 0)
235
		{
236
			include_once $GLOBALS['babInstallPath']."utilit/calapi.php";
237
			$idcat = bab_calGetCategories($GLOBALS['babBody']->babsite['id_calendar_cat']);
238
			if( isset($idcat[0]['color']))
239
			{
240
				$this->nwd_color = $idcat[0]['color'];
241
			}
242
		}
243
244
		if (!empty($_REQUEST['popup']))
245
		{
246
			$this->popup = true;
0 ignored issues
show
Bug introduced by
The property popup 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...
247
		}
248
249
		if (!isset($_REQUEST['ide']))
250
		{
251
			$urltmp->idu = implode(',',$this->idusers);
252
		}
253
254
		$switchurl = clone $urltmp;
255
256
		if (1 == $this->nbmonth) {
257
258
			$switchurl->nbmonth = 12;
259
			$this->switchurl = $switchurl->toString();
0 ignored issues
show
Bug introduced by
The property switchurl 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
			$this->switchlabel = absences_translate("Year view");
0 ignored issues
show
Bug introduced by
The property switchlabel 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...
261
			
262
			
263
			
264
			$this->prevmonthclass = 'prev1';
0 ignored issues
show
Bug introduced by
The property prevmonthclass 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...
265
			$this->prevyearclass = 'prev2';
0 ignored issues
show
Bug introduced by
The property prevyearclass 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...
266
			
267
			$this->nextmonthclass = 'next1';
0 ignored issues
show
Bug introduced by
The property nextmonthclass 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...
268
			$this->nextyearclass = 'next2';
0 ignored issues
show
Bug introduced by
The property nextyearclass 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...
269
			
270
		} else {
271
			$switchurl->nbmonth = 1;
272
			$this->switchurl = $switchurl->toString();
273
			$this->switchlabel = absences_translate("Month view");
274
			
275
			$this->prevmonthclass = 'prev2';
276
			$this->prevyearclass = 'prev1';
277
			
278
			$this->nextmonthclass = 'next2';
279
			$this->nextyearclass = 'next1';
280
		}
281
282
		$urltmp->nbmonth = $this->nbmonth;
283
284
285
		$previousmonth = clone $urltmp;
286
		$previousmonth->month = date("n", mktime( 0,0,0, $month-1, 1, $year));
287
		$previousmonth->year = date("Y", mktime( 0,0,0, $month-1, 1, $year));
288
		$this->previousmonth	= $previousmonth->toString();
0 ignored issues
show
Bug introduced by
The property previousmonth does not seem to exist. Did you mean t_previousmonth?

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...
289
290
		$nextmonth = clone $urltmp;
291
		$nextmonth->month = date("n", mktime( 0,0,0, $month+1, 1, $year));
292
		$nextmonth->year = date("Y", mktime( 0,0,0, $month+1, 1, $year));
293
		$this->nextmonth = $nextmonth->toString();
0 ignored issues
show
Bug introduced by
The property nextmonth does not seem to exist. Did you mean t_nextmonth?

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...
294
295
		$previousyear = clone $urltmp;
296
		$previousyear->month = date("n", mktime( 0,0,0, $month, 1, $year-1));
297
		$previousyear->year = date("Y", mktime( 0,0,0, $month, 1, $year-1));
298
		$this->previousyear = $previousyear->toString();
0 ignored issues
show
Bug introduced by
The property previousyear does not seem to exist. Did you mean t_previousyear?

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...
299
300
		$nextyear = clone $urltmp;
301
		$nextyear->month = date("n", mktime( 0,0,0, $month, 1, $year+1));
302
		$nextyear->year = date("Y", mktime( 0,0,0, $month, 1, $year+1));
303
		$this->nextyear = $nextyear->toString();
0 ignored issues
show
Bug introduced by
The property nextyear does not seem to exist. Did you mean t_nextyear?

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...
304
305
		$dateb = new BAB_DateTime($year, $month, 1);
306
		$datee = $dateb->cloneDate();
307
		$datee->add($this->nbmonth, BAB_DATETIME_MONTH);
308
		
309
		
310
311
		$this->yearname = $this->getTitle($dateb, $datee);
0 ignored issues
show
Bug introduced by
The property yearname 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...
312
		
313
		
314
315
316
317
318
319
		if ($this->display_types)
320
		{
321
			$this->restypes = $babDB->db_query("
0 ignored issues
show
Bug introduced by
The property restypes 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...
322
323
				SELECT
324
					t.*
325
					FROM
326
					".ABSENCES_TYPES_TBL." t,
327
					absences_rights r,
328
					absences_users_rights ur,
329
					".ABSENCES_PERSONNEL_TBL." p
330
				WHERE
331
					p.id_user IN(".$babDB->quote($this->idusers).")
332
					AND p.id_user=ur.id_user
333
					AND ur.id_right=r.id
334
					AND r.id_type=t.id
335
				GROUP BY
336
					t.id
337
					");
338
339
		}
340
		
341
		
342
		// filtre par service
343
		
344
		$W = bab_Widgets();
345
		$departments = $W->Multiselect();
346
		$departments->setName('departments')->setValue(bab_rp('departments'));
347
		
348
		$entities = absences_getEntites();
349
		foreach($entities as $e) {
350
		    $departments->addOption($e['id'], $e['name']);
351
		}
352
		
353
		$this->departments = '';
0 ignored issues
show
Bug introduced by
The property departments 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...
354
355
		if (count($entities) > 0) {
356
		    $this->departments = $departments->display($W->HtmlCanvas());
357
		}
358
		
359
		
360
		// filtre recherche par date
361
		
362
		$this->datefilter = $this->getDateFilter()->display($W->HtmlCanvas());
0 ignored issues
show
Bug introduced by
The property datefilter 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...
363
	}
364
	
365
	
366
	
367
	private function getDateFilter()
368
	{
369
	    $W = bab_Widgets();
370
	    
371
	    switch (bab_rp('searchtype')) {
372 View Code Duplication
	        case '2':
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...
373
    	       $dateb = bab_rp('dateb');
374
    	       $datee = bab_rp('datee');
375
    	       $_date = null;
376
    	       break;
377
    	      
378
	        default:
379 View Code Duplication
	        case '1':
0 ignored issues
show
Unused Code introduced by
case '1': $dateb = n..._rp('date'); break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
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...
380
	           $dateb = null;
381
	           $datee = null;
382
	           $_date = bab_rp('date');
383
	           break;
384
	    }
385
	    
386
	    $periodpicker = $W->PeriodPicker()->setNames('dateb', 'datee')->setValues($dateb, $datee);
387
	    
388
	    $period = $W->LabelledWidget(
389
	        absences_translate('Date'),
390
	        $periodpicker
391
	    );
392
	    
393
	    $picker = $W->DatePicker()
394
    	    ->setValue($_date)
395
    	    ->addClass('absences-search-by-date');
396
	    
397
    	if (method_exists($picker, 'setDefaultDate')) {
398
    	    $picker->setDefaultDate($this->year.'-'.$this->month.'-01');
399
    	    $periodpicker->setDefaultDate($this->year.'-'.$this->month.'-01');
400
    	}
401
	    
402
	    $date = $W->LabelledWidget(
403
	            absences_translate('Date'),
404
	            $picker,
405
	            'date'
406
	    );
407
	    
408
	    $begin = $picker->getISODate($dateb);
409
	    $end = $picker->getISODate($datee);
410
	    $d = $picker->getISODate($_date);
411
	    
412
	    if ('0000-00-00' !== $d) {
413
	        $begin = $d;
414
	        $end = $d;
415
	    }
416
	    
417
	    if ('0000-00-00' !== $begin && '0000-00-00' !== $end) {
418
	        $picker->setMetadata('dateb', $begin);
419
	        $picker->setMetadata('datee', $end);
420
	    }
421
	    
422
	    
423
	    $frame = $W->Frame(null , $W->HBoxItems());
424
	    
425
	    
426
	    $frame->addItem(
427
	            $W->LabelledWidget(
428
	                    absences_translate('Search by date'),
429
	                    $W->Select()
430
	                    ->setAssociatedDisplayable($date, array('1'))
431
	                    ->setAssociatedDisplayable($period, array('2'))
432
	                    ->addOption('1', absences_translate("Absences on a date"))
433
	                    ->addOption('2', absences_translate("Absences in a period"))
434
	                    ->setValue(bab_rp('searchtype', 1)),
435
	                    'searchtype'
436
	            )
437
	    );
438
	    
439
	    
440
	    $frame->addItem($period);
441
	    $frame->addItem($date);
442
	    
443
	    return $frame;
444
	}
445
	
446
	
447
	/**
448
	 * @param BAB_DateTime $dateb
449
	 * @param BAB_DateTime $datee
450
	 * 
451
	 * @return string
452
	 */
453
	private function getTitle(BAB_DateTime $dateb, BAB_DateTime $datee)
454
	{
455
	    $months = bab_DateStrings::getMonths();
456
	    $duration = (int) round(($datee->getTimeStamp() - $dateb->getTimeStamp()) / 86400);
457
458
	    if ($duration > 33) {
459
	        
460
	        $end = $datee->cloneDate();
461
	        $end->less(1, BAB_DATETIME_DAY);
462
	        
463
	        return $months[$dateb->getMonth()].' '.$dateb->getYear()."-".$months[$end->getMonth()].' '.$end->getYear();
464
	    }
465
	    
466
	    return $months[$dateb->getMonth()].' '.$dateb->getYear();
467
	}
468
	
469
	
470
	
471
	
472
	public function getnexthidden()
473
	{
474
		if (list($name, $value) = each($_GET))
475
		{
476
			if (is_array($value))
477
			{
478
				return true;
479
			}
480
			
481
			$this->name = bab_toHtml($name);
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
482
			$this->value = bab_toHtml($value);
0 ignored issues
show
Bug introduced by
The property value 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...
483
			return true;
484
		}
485
		
486
		reset($_GET);
487
		return false;
488
	}
489
	
490
	
491
492
	public function getdayname()
493
	{
494
		static $i = 1;
495
		if( $i <= 31)
496
		{
497
			$this->dayname = sprintf('%02d',$i);
0 ignored issues
show
Bug introduced by
The property dayname 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...
498
			$i++;
499
			return true;
500
		}
501
		else
502
			return false;
503
	}
504
	
505
	
506
	/**
507
	 *
508
	 */
509
	public function getmonth()
510
	{
511
		static $i = 0;
512
		if( $i < $this->nbmonth)
513
		{
514
	
515
			$dateb = new BAB_DateTime($this->year, $this->month + $i, 1);
516
	
517
			$this->curyear = $dateb->getYear();
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...
518
			$this->curmonth = $dateb->getMonth();
0 ignored issues
show
Bug introduced by
The property curmonth 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...
519
			$months = bab_DateStrings::getMonths();
520
			$this->monthname = bab_toHtml($months[$this->curmonth]);
0 ignored issues
show
Bug introduced by
The property monthname 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...
521
			$this->totaldays = date("t", $dateb->getTimeStamp());
0 ignored issues
show
Bug introduced by
The property totaldays does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
522
			$this->previous_period = NULL;
0 ignored issues
show
Bug introduced by
The property previous_period 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...
523
			$i++;
524
			return true;
525
		}
526
		else
527
			return false;
528
	}
529
	
530
	
531
	
532
	
533
534
	public function getnextuser()
535
	{
536
		static $i = 0;
537
538
		$n = $this->nbusers;
539
540
		if ( $n == 0 )
541
			$n = 1;
542
543
		$this->rowspan = $this->emptylines ? $this->nbusers : $n;
0 ignored issues
show
Bug introduced by
The property rowspan 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...
544
545
		if ($i < $n)
546
		{
547
			$this->first = $i == 0 ;
0 ignored issues
show
Bug introduced by
The property first 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...
548
			$this->id_user = $this->idusers[$i];
0 ignored issues
show
Bug introduced by
The property id_user does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
549
			$this->username = bab_toHtml($this->userNameArr[$this->id_user]);
0 ignored issues
show
Bug introduced by
The property username does not seem to exist. Did you mean userNameArr?

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...
550
			try {
551
				$agent = absences_Agent::getCurrentUser();
552
				if ($agent->isManager())
553
				{
554
					$this->userurl = bab_toHtml('?tg=addon/absences/vacadm&idx=modp&idp='.$this->idusers[$i]);
0 ignored issues
show
Bug introduced by
The property userurl 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...
555
				} else {
556
					$this->userurl = false;
557
				}
558
			} catch(Exception $e)
559
			{
560
				$this->userurl = false;
561
			}
562
			
563
564
			$i++;
565
			return true;
566
		}
567
		else
568
		{
569
			$i = 0;
570
			return false;
571
		}
572
	}
573
574
575
	/**
576
	 * 
577
	 * @return boolean
578
	 */
579
	public function getday()
580
	{
581
		static $d = 1;
582
		static $total = 0;
583
		if( $d <= 31)
584
		{
585
			$time = mktime(0, 0, 0, $this->curmonth, $d, $this->curyear);
586
            $this->day = bab_formatDate('%D', $time).' '.date('j', $time);
0 ignored issues
show
Bug introduced by
The property 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...
587
			$d++;
588
			return true;
589
		}
590
		else
591
		{
592
			$d = 1;
593
			return false;
594
		}
595
	}
596
597
	public function getnexttype()
598
	{
599
600
		if (!$this->display_types) {
601
			return false;
602
		}
603
604
		global $babDB;
605
		if ($this->arr = $babDB->db_fetch_array($this->restypes)) {
606
			$this->arr['name'] 			= bab_toHtml($this->arr['name']);
0 ignored issues
show
Bug introduced by
The property arr does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
607
			$this->arr['description'] 	= bab_toHtml($this->arr['description']);
608
			return true;
609
		}
610
		else {
611
			return false;
612
		}
613
	}
614
	
615
	
616
	public function entity($ide, $all = false)
617
	{
618
	    // permettre de charger les sous-entites fusionnes dans le meme planning
619
	    
620
	    $url = bab_url::get_request_gp();
621
	    $url->all = $all ? '0' : '1';
622
	    
623
	    $this->mergedurl = false;
0 ignored issues
show
Bug introduced by
The property mergedurl 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...
624
	    
625
	    if (bab_OCGetChildCount($ide)) {
626
	        $this->mergedurl = bab_toHtml($url->toString());
627
	    }
628
	    
629
	    if ($all) {
630
	        $this->t_merged = absences_translate('View the entity only');
0 ignored issues
show
Bug introduced by
The property t_merged does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
631
	    } else {
632
	        $this->t_merged = absences_translate('View users from all entities');
633
	    }
634
	}
635
	
636
	
637
	public function publiccalendar($total)
638
	{
639
		$this->display_firstuser = false;
0 ignored issues
show
Bug introduced by
The property display_firstuser does not seem to exist. Did you mean firstuser?

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...
640
		$this->public = true;
641
		$this->t_search_name = absences_translate('Search by name');
0 ignored issues
show
Bug introduced by
The property t_search_name does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
642
		$this->t_search_entity = absences_translate('By entity');
0 ignored issues
show
Bug introduced by
The property t_search_entity 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...
643
		$this->keyword = bab_rp('keyword');
0 ignored issues
show
Bug introduced by
The property keyword 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...
644
		$this->t_ok = absences_translate('Ok');
0 ignored issues
show
Bug introduced by
The property t_ok 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...
645
		
646
		$this->total = $total;
647
		$this->t_total = sprintf(absences_translate('%d result found', '%d results found', $total), $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...
648
		
649
		
650
		// prepare button for first load
651
		
652
		$this->t_use_month_view = false;
0 ignored issues
show
Bug introduced by
The property t_use_month_view 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...
653
		
654
		$this->t_loadall = absences_translate('View all results');
0 ignored issues
show
Bug introduced by
The property t_loadall does not seem to exist. Did you mean loadall?

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...
655
		$this->t_viewBegin = absences_translate('View the first 30 only');
0 ignored issues
show
Bug introduced by
The property t_viewBegin 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...
656
		
657
		if ($total > $this->nbusers)
658
		{
659
			$last = $total - $this->nbusers;
660
			
661
			if (1 < $this->nbmonth)
662
			{
663
				$this->t_use_month_view = sprintf(absences_translate('The planning display only %d results from %d total results, use the month view to fetch next results'), $this->nbusers, $total);
664
				$this->loadmore = false;
665
				$this->loadall = false;
666
			} else {
667
668
			    $this->loadall = false;
669
				$this->loadmore = $this->limit < $last ? $this->limit : $last;
670
				$this->t_loadmore = sprintf(absences_translate('Load the next %d results'), $this->loadmore);
0 ignored issues
show
Bug introduced by
The property t_loadmore does not seem to exist. Did you mean loadmore?

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...
671
			}
672
		} else {
673
			$this->loadmore = false;
674
			$this->loadall = false;
675
		}
676
	}
677
	
678
	
679
	public function getHtml()
680
	{
681
	    // dans les vielles versions d'ovidentia
682
	    // l'access a l'api des organigramme renvoi un message d'erreur si on a pas les droits de lecture
683
	    // dans le planning le bouton qui permet d'acceder au sous-entites a besoin de cette api
684
	    // on supprime le message d'erreur pour eviter qui apparaisse sur le planning perso
685
	    // dans le vielles versions d'ovidentia < 8.4.0 le bouton pour afficher les sous-entites dans le meme planning sera probablement inoperant
686
	    // tant que l'organigramme n'est pas accessible en lecture
687
	    
688
	    $babBody = bab_getBody();
689
	    
690
	    if ($babBody->msgerror === bab_translate('Error: Right insufficient')) {
691
	       bab_debug($babBody->msgerror);
692
	       $babBody->msgerror = null;
693
	    }
694
	    
695
		return bab_printTemplate($this, absences_addon()->getRelativePath()."vacuser.html", "calendarbyuser");
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...
696
	}
697
	
698
	
699
700
	public function printhtml()
701
	{
702
		global $babBody;
703
		
704
		/*@var $babBody babBody */
705
		
706
		$html = $this->getHtml();
707
		
708
		/*@var $jquery Func_Jquery */
709
		$jquery = bab_functionality::get('jquery');
710
		$jquery->includeCore();
711
712
		$babBody->addStyleSheet(absences_addon()->getStylePath().'vacation.css');
713
		$babBody->addJavascriptFile(absences_addon()->getTemplatePath().'calendar.jquery.js', true);
714
715
		if (isset($_REQUEST['popup']) && $_REQUEST['popup'] == 1) {
716
			$babBody->babpopup($html);
717
		}
718
		else {
719
			$babBody->babecho($html);
720
		}
721
	}
722
}
723
724
725
726
727
728
729
730
/**
731
 * Display a vacation calendar
732
 * @param	array		$users			array of id_user to display
733
 * @param	boolean		$period			allow period selection, first step of vacation request
734
 * @param	boolean		$display_types	Display types color and legend on planning
735
 * @param	int			$nbmonth		Number of month to display
736
 * @param	bool		$dispusers		display a column with user names
737
 * @param 	int			$total			Total number of results in search
738
 */
739
function absences_viewVacationCalendar($users, $period, $display_types, $nbmonth = 12, $dispusers = true, $total = null )
740
{
741
	global $babBody;
742
743
	$temp = new absences_viewVacationCalendarCls($users, $period, $display_types, $nbmonth, $dispusers);
744
745
	if (count($users) == 0)
746
	{
747
		$babBody->addError(absences_translate("ERROR: No members"));
748
	}
749
	
750
	if (bab_rp('idx') == 'entity_cal')
751
	{
752
	    $temp->entity(bab_rp('ide'), (bool) bab_rp('all', false));
753
	}
754
	
755
	if (bab_rp('idx') == 'public')
756
	{
757
		$temp->publiccalendar($total);
758
	}
759
	
760
	$temp->printhtml();
761
}
762
763
764
765
/**
766
 * Serach in active users to display the public calendar
767
 * @param string $keyword
768
 * @param array $departments
769
 * @param string $dateb
770
 * @param string $datee
771
 * @param string $date
772
 */
773
function absences_publicCalendarUsers($keyword, $departments, $searchtype, $dateb, $datee, $date)
774
{
775
	global $babDB;
776
	require_once $GLOBALS['babInstallPath'].'utilit/userinfosincl.php';
777
	
778
	
779
	$W = bab_Widgets();
780
	$datePicker = $W->DatePicker();
781
	
782
	switch($searchtype) {
783
	    default:
784
	    case 1:
785
	        $dateb = '0000-00-00';
786
	        $datee = '0000-00-00';
787
	        $date = $datePicker->getISODate($date);
788
	        break;
789
	        
790
	    case 2:
791
	        $dateb = $datePicker->getISODate($dateb);
792
	        $datee = $datePicker->getISODate($datee);
793
	        $date = '0000-00-00';
794
	        break;
795
	}
796
	
797
	
798
	if ('0000-00-00' !== $date && false !== $date) {
799
	    $dateb = $date;
800
	    $datee = $date;
801
	}
802
	
803
	
804
	$query = 'SELECT
805
			u.id,
806
			u.lastname,
807
			u.firstname
808
		FROM
809
			bab_users u
810
	           LEFT JOIN bab_oc_roles_users ru ON ru.id_user=u.id 
811
	           LEFT JOIN bab_oc_roles r ON r.id=ru.id_role,
812
			absences_personnel p
813
	
814
		WHERE
815
			p.id_user=u.id AND '.bab_userInfos::queryAllowedUsers('u');
816
817
	
818
	if (isset($keyword))
819
	{
820
		$query .= ' AND (u.lastname LIKE \'%'.$babDB->db_escape_like($keyword).'%\' OR u.firstname LIKE \'%'.$babDB->db_escape_like($keyword).'%\')';
821
	}
822
	
823
	if (isset($departments))
824
	{
825
	    $query .= ' AND r.id_entity IN('.$babDB->quote($departments).')';
826
	}
827
	
828
	if ('0000-00-00' !== $dateb && '0000-00-00' !== $datee && false !== $dateb && false !== $datee) {
829
	    $subquery = 'SELECT id_user FROM absences_entries WHERE date_begin<'.$babDB->quote($datee.' 23:59:59').' AND date_end>'.$babDB->quote($dateb.' 00:00:00').' GROUP BY id_user';
830
	    $query .= ' AND u.id IN('.$subquery.')';
831
	}
832
	
833
	
834
	$query .= 'GROUP BY u.id ORDER BY u.lastname, u.firstname';
835
	
836
	$res = $babDB->db_query($query);
837
	
838
	return $res;
839
}
840
841
842
function absences_getSearchLimit($nbmonth)
843
{
844
    $initusers = (int) bab_rp('limit');
845
    if (empty($initusers)) {
846
        // preload the 30 first users if limit not set
847
        $initusers = 1 === $nbmonth ? 30 : 10;
848
    }
849
    
850
    return $initusers;
851
}
852