Issues (1940)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

programs/utilit/exportbalance.php (32 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
require_once dirname(__FILE__).'/agent_right.class.php';
26
require_once dirname(__FILE__).'/csv.class.php';
27
28
class exportAvailableBalancesCls extends absences_Csv
29
{
30
	private $resYears;
31
32
	/**
33
	 *
34
	 * @var array
35
	 */
36
	private $rights;
37
38
39
	/**
40
	 * @var array
41
	 */
42
	private $recoveries;
43
	
44
	
45
	/**
46
	 * @var string YYYY-MM-DD
47
	 */
48
	private $date = null;
49
	
50
	/**
51
	 * @var array
52
	 */
53
	private $dirfields;
54
55
56
	public function getHtml()
57
	{
58
		global $babDB;
59
60
		$this->separatortxt = absences_translate("Separator");
0 ignored issues
show
The property separatortxt does not seem to exist. Did you mean separator?

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...
61
		$this->other = absences_translate("Other");
0 ignored issues
show
The property other does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
		$this->sepdectxt = absences_translate("Decimal separator");
0 ignored issues
show
The property sepdectxt does not seem to exist. Did you mean sepdec?

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...
67
		$this->t_yes = absences_translate("Yes");
0 ignored issues
show
The property t_yes does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
		$this->t_date = absences_translate('Export day date');
0 ignored issues
show
The property t_date does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
70
		$this->t_year = absences_translate('Year filter');
0 ignored issues
show
The property t_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...
71
		$this->t_organization = absences_translate('Organization');
0 ignored issues
show
The property t_organization 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...
72
		$this->additional_fields = absences_translate("Additional fields to export:");
0 ignored issues
show
The property additional_fields 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...
73
		
74
		$W = bab_Widgets();
75
		$this->datePicker = $W->DatePicker()->setName('date')->display($W->HtmlCanvas()); 
0 ignored issues
show
The property datePicker 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...
76
77
		$this->resYears = $babDB->db_query("SELECT YEAR(date_begin) year FROM absences_rights WHERE YEAR(date_begin)<>'0' GROUP BY year");
78
79
		$this->resOrganization = $babDB->db_query("SELECT * FROM `absences_organization` ORDER BY name ASC");
0 ignored issues
show
The property resOrganization 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...
80
81
82
		$this->dirfields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
83
84
		unset($this->dirfields['sn']);
85
		unset($this->dirfields['givenname']);
86
		unset($this->dirfields['jpegphoto']);
87
88
		return bab_printTemplate($this, absences_addon()->getRelativePath()."vacadm.html", "abexport");
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...
89
	}
90
91
	/**
92
	 * template method to list available years
93
	 */
94 View Code Duplication
	public function getnextyear()
0 ignored issues
show
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...
95
	{
96
		global $babDB;
97
98
		if ($arr = $babDB->db_fetch_assoc($this->resYears))
99
		{
100
			$this->year = bab_toHtml($arr['year']);
0 ignored issues
show
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...
101
			return true;
102
		}
103
104
		return false;
105
	}
106
107
108 View Code Duplication
	public function getnextfield()
0 ignored issues
show
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...
109
	{
110
		if (list($name,$arr) = each($this->dirfields))
111
		{
112
			$this->fieldname = bab_toHtml($name);
0 ignored issues
show
The property fieldname 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...
113
			$this->fieldlabel = bab_toHtml($arr['name']);
0 ignored issues
show
The property fieldlabel 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...
114
			return true;
115
		}
116
		return false;
117
	}
118
119
	/**
120
	 * template method to list available organization
121
	 */
122 View Code Duplication
	public function getnextorganization()
0 ignored issues
show
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...
123
	{
124
		global $babDB;
125
126
		if ($arr = $babDB->db_fetch_assoc($this->resOrganization))
127
		{
128
			$this->organization = bab_toHtml($arr['name']);
0 ignored issues
show
The property organization does not seem to exist. Did you mean t_organization?

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...
129
			$this->id_organization = bab_toHtml($arr['id']);
0 ignored issues
show
The property id_organization 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...
130
			return true;
131
		}
132
133
		return false;
134
	}
135
136
137
138
	private function query($year, $groupby = '', $organization = '', $user = '')
139
	{
140
		global $babDB;
141
142
		if (!empty($year)) {
143
			$year = 'AND YEAR(r.date_begin)='.$babDB->quote($year);
144
		}
145
146
		if ($organization) {
147
			$organization = 'AND p.id_organization='.$babDB->quote($organization);
148
		}
149
		
150
		if ($user) {
151
		    $user = ' AND p.id_user='.$babDB->quote($user);
152
		}
153
154
155
		$query = "
156
			SELECT
157
				ur.* 
158
			FROM
159
				absences_users_rights ur, 
160
				absences_rights r,
161
				absences_personnel p,
162
				bab_users u
163
			WHERE
164
				ur.id_user=p.id_user
165
				AND p.id_user=u.id
166
				AND r.id = ur.id_right 
167
				$year
168
				$organization
169
				$user
170
			$groupby
171
			ORDER BY
172
				u.lastname,
173
				u.firstname,
174
				r.description
175
		";
176
177
		return $babDB->db_query($query);
178
	}
179
180
	
181
182
	
183
	
184
	
185
	/**
186
	 * New row for the user
187
	 * 
188
	 * @param absences_AgentRight $agentRight
189
	 * @param array $remain
190
	 * 
191
	 * @return Array
192
	 */
193
	private function getNewCurrentRow(absences_AgentRight $agentRight, Array $remain)
194
	{
195
	    $arr = bab_getUserName($agentRight->id_user, false);
196
	    
197
	    $currentRow = array(
198
	            $arr['lastname'],
199
	            $arr['firstname'],
200
	            (float) $remain['D'], // total days
201
	            (float) $remain['H']  // total hours
202
	    );
203
	    
204
	    foreach($this->rights as $initcol) {
205
	        $currentRow[$initcol] = 0.0;
206
	    }
207
	     
208
	    foreach($this->recoveries as $quantity_unit => $initcol) {
209
	        if (isset($initcol)) {
210
	            $currentRow[$initcol] = 0.0;
211
	        }
212
	    }
213
	    
214
	    return $currentRow;
215
	}
216
217
218
	/**
219
	 * Process one row
220
	 * if user row exists, add remain to the correct right column
221
	 * if the user row does not exists, create it
222
	 *
223
	 * return the row only if it is the first user row
224
	 * else return null
225
	 *
226
	 * @return array | null
227
	 */
228
	private function processRow($arr)
229
	{
230
		static $currentUser = null;
231
		static $currentRow = null;
232
233
		$return = null;
234
235
		if (null === $arr) {
236
		    
237
		    if (!isset($currentRow)) {
238
		        return array();
239
		    }
240
241
			return $currentRow;
242
		}
243
		
244
		$agentRight = new absences_AgentRight();
245
		$agentRight->setRow($arr);
246
		
247
		$right = $agentRight->getRight();
248
249
		$remain = array('D' => 0.0, 'H' => 0.0);
250
251
		$remain_line = $remain[$right->quantity_unit] = $agentRight->getAvailableQuantity($this->date);
252
253
254
		if ($currentUser !== $agentRight->id_user) {
255
			$currentUser = $agentRight->id_user;
256
257
			if (null !== $currentRow && !$this->isRowEmpty($currentRow)) {
0 ignored issues
show
$currentRow is of type null, but the function expects a array.

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...
258
				$return = $currentRow;
259
			}
260
261
			$currentRow = $this->getNewCurrentRow($agentRight, $remain);
262
			
263
			$this->addDirValues($arr['id_user'], $currentRow);
264
265
		} else {
266
267
			$currentRow[2] += (float) $remain['D']; // total days
268
			$currentRow[3] += (float) $remain['H']; // total hours
269
		}
270
271
272
        $this->setRightColumn($right, $currentRow, $remain, $remain_line);
273
		
274
275
		return $return;
276
	}
277
	
278
	
279
	/**
280
	 * Complete current row with right value
281
	 * @param absences_Right $right
282
	 * @param array &$currentRow
283
	 */
284
	private function setRightColumn(absences_Right $right, Array &$currentRow, Array $remain, $remain_line)
285
	{
286
	    
287
	    if (absences_Right::RECOVERY === $right->getKind()) {
288
	    
289
	        // recovery right
290
	        $col = $this->recoveries[$right->quantity_unit];
291
	        if ($col > 3) {
292
	            $currentRow[$col] += $remain[$right->quantity_unit];
293
	        }
294
	    
295
	    
296
	    } else {
297
	    
298
	    
299
	        //regular right, add to specific column
300
	        $col = $this->rights[$right->id];
301
	    
302
	        if ($col > 3) {
303
	            $currentRow[$col] = $remain_line;
304
	        }
305
	    }
306
	}
307
	
308
	/**
309
	 * Complete current row with directory entry values
310
	 * @param int $id_user
311
	 * @param array &$currentRow
312
	 */
313
	private function addDirValues($id_user, Array &$currentRow)
314
	{
315
	    $agent = absences_Agent::getFromIdUser($id_user);
316
	    
317
	    foreach ($this->dirfields as $name => $dummy) {
318
	        $currentRow[] = $this->getAgentDirValue($agent, $name);
319
	    }
320
	}
321
	
322
	
323
324
	
325
	/**
326
	 * @return string
327
	 */
328
	private function getSeparator()
329
	{
330
	    switch((int) bab_pp('wsepar'))
331
	    {
332
	        case 0: return bab_pp('separ');
333
	        case 1: return ',';
334
	        case 2: return "\t";
335
	        case 3: return ';';
336
	    }
337
	}
338
	
339
	
340
	
341
	protected function getDate()
342
	{
343
	    $W = bab_Widgets();
344
	    return $W->DatePicker()->getISODate(bab_rp('date'));
345
	}
346
	
347
	
348
	/**
349
	 * @return array
350
	 */
351
	private function getHeader($year = '', $organization = '')
352
	{
353
	    global $babDB;
354
	    
355
	    $columns = $this->query($year, 'GROUP BY r.id', $organization);
356
	    $this->rights = array();
357
	    
358
	    
359
	    if ($this->dirfields && !empty($this->dirfields))
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->dirfields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
360
	    {
361
	        $ov_fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
362
	    }
363
	    
364
	    $header = array(
365
	        absences_translate('Lastname'),
366
	        absences_translate('Firstname'),
367
	        absences_translate('Total days'),
368
	        absences_translate('Total hours')
369
	    );
370
	    
371
	    
372
	    $this->recoveries = array(
373
	        'D' => null,
374
	        'H' => null
375
	    );
376
	    
377
	    $recovery = array(
378
	        'D' => false,
379
	        'H' => false
380
	    );
381
	    
382
	    while ($arr = $babDB->db_fetch_assoc($columns))
383
	    {
384
	        $agentRight = new absences_AgentRight();
385
	        $agentRight->setRow($arr);
386
	    
387
	        $right = $agentRight->getRight();
388
	    
389
	        if (absences_Right::RECOVERY === $right->getKind()) {
390
	            $recovery[$right->quantity_unit] = true;
391
	            continue;
392
	        }
393
	    
394
	        $header[] = $right->description.' ('.$right->getUnitLabel().')';
395
	        $this->rights[$arr['id_right']] = (count($header) -1);
396
	    }
397
	    
398 View Code Duplication
	    if ($recovery['D']) {
0 ignored issues
show
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
	        $header[] = absences_translate('Recoveries (days)');
400
	        $this->recoveries['D'] = (count($header) -1);
401
	    }
402
	    
403 View Code Duplication
	    if ($recovery['H']) {
0 ignored issues
show
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...
404
	        $header[] = absences_translate('Recoveries (hours)');
405
	        $this->recoveries['H'] = (count($header) -1);
406
	    }
407
	    
408
	    foreach($this->dirfields as $name => $dummy)
409
	    {
410
	        $header[] = $ov_fields[$name]['name'];
0 ignored issues
show
The variable $ov_fields does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
411
	    }
412
	    
413
	    return $header;
414
	}
415
	
416
417
418
	public function csv()
419
	{
420
421
		$W = bab_Widgets();
422
		 
423
		if ($date = $W->DatePicker()->getISODate(bab_rp('date'))) {
424
		    if ('0000-00-00' !== $date) {
425
		        $this->date = $date;
426
		    }
427
		}
428
		 
429
		$this->dirfields = bab_rp('dirfields', array());
0 ignored issues
show
Documentation Bug introduced by
It seems like bab_rp('dirfields', array()) of type * is incompatible with the declared type array of property $dirfields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
430
431
		
432
		
433
        $this->separator = $this->getSeparator();
434
        $this->sepdec = bab_rp('sepdec');
435
        $header = $this->getHeader(bab_rp('year'), bab_rp('organization'));
436
        
437
438
        $this->echoCsv($header);
439
		
440
	}
441
	
442
	
443
	
444
	
445
	
446
	private function echoCsv($header)
447
	{
448
	    global $babDB;
449
	    
450
	    $this->setHeaders(absences_translate("Vacation"));
451
452
	    $this->outputArr($header);
453
454
	    $rows = $this->query(bab_rp('year'), 'GROUP BY u.id, r.id', bab_rp('organization'));
455
	    
456 View Code Duplication
	    while ($arr = $babDB->db_fetch_assoc($rows))
0 ignored issues
show
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...
457
	    {
458
	        if (null !== $line = $this->processRow($arr))
459
	        {
460
	            $this->outputArr($line);
461
	        }
462
	    }
463
	    
464
	    if (null !== $line = $this->processRow(null)) {
465
	        $this->outputArr($line);
466
	    }
467
	    
468
	    exit;
469
	}
470
	
471
	
472
	/**
473
	 * @return array
474
	 */
475
	private function getUserRow($id_user)
476
	{
477
	    global $babDB;
478
	    
479
	    $rows = $this->query('', 'GROUP BY u.id, r.id', '', $id_user);
480
	    
481 View Code Duplication
	    while ($arr = $babDB->db_fetch_assoc($rows))
0 ignored issues
show
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...
482
	    {
483
	        if (null !== $line = $this->processRow($arr))
484
	        {
485
	            return $line;
486
	        }
487
	    }
488
	     
489
	    return $this->processRow(null);
490
	}
491
	
492
	
493
	
494
	/**
495
	 * @return Widget_Displayable_Interface
496
	 */
497
	public function compareDateForOneUser($id_user)
498
	{
499
	    require_once $GLOBALS['babInstallPath'].'utilit/dateTime.php';
500
	    
501
	    $this->dirfields = array();
502
	    
503
	    $header = $this->getHeader();
504
	    
505
	    
506
	    $yesterday = BAB_DateTime::now();
507
	    $yesterday->less(1, BAB_DATETIME_DAY);
508
	    
509
	    $this->date = $yesterday->getIsoDate();
510
	    $arr0 = $this->getUserRow($id_user);
511
	    
512
	    $this->date = date('Y-m-d');
513
	    $arr1 = $this->getUserRow($id_user);
514
	    
515
	    $this->date = null;
516
	    $arr2 = $this->getUserRow($id_user);
517
	    
518
	    
519
	    $W = bab_Widgets();
520
	    $table = $W->TableView();
521
	    
522
	    $row = 0;
523
	    
524
	    $table->addItem($W->Label(''), $row, 0 );
525
	    $table->addItem($W->Label('Yesterday'), $row, 1);
526
	    $table->addItem($W->Label('Today'), $row, 2);
527
	    $table->addItem($W->Label('No date'), $row, 3);
528
	    $row++;
529
	    
530
	    foreach ($header as $k => $label) {
531
	        
532
	        if ('"0,0"' === $arr1[$k] && '"0,0"' === $arr2[$k]) {
533
	            continue;
534
	        }
535
	        
536
	        $table->addItem($W->Label($label), $row, 0 );
537
	        $table->addItem($l0 = $W->Label($arr0[$k]), $row, 1);
538
	        $table->addItem($l1 = $W->Label($arr1[$k]), $row, 2);
539
	        $table->addItem($l2 = $W->Label($arr2[$k]), $row, 3);
540
	        
541
	        $values = array_unique(array($arr0[$k], $arr1[$k], $arr2[$k]));
542
	        
543
	        if (1 !== count($values)) {
544
	            $l0->addClass('widget-strong');
545
	            $l1->addClass('widget-strong');
546
	            $l2->addClass('widget-strong');
547
	        }
548
	        
549
	        $row++;
550
	    }
551
	    
552
	    return $table;
553
	}
554
}