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/exportvac.php (13 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
include_once dirname(__FILE__).'/utilit/vacincl.php';
26
include_once dirname(__FILE__).'/functions.php';
27
include_once dirname(__FILE__).'/utilit/agent.class.php';
28
include_once dirname(__FILE__).'/utilit/organization.class.php';
29
include_once dirname(__FILE__).'/utilit/exportentry.class.php';
30
bab_Widgets()->includePhpClass('Widget_Form');
31
32
33
34
35
class absences_exportVacationRequestsCls
36
{
37
    public $datebegintxt;
38
    public $dateendtxt;
39
    public $dateformattxt;
40
    public $statustxt;
41
    public $separatortxt;
42
    public $other;
43
    public $comma;
44
    public $tab;
45
    public $semicolon;
46
    public $export;
47
    public $sepdectxt;
48
49
    public $t_yes;
50
    public $t_no;
51
    public $additional_fields;
52
    public $t_users_without_requests;
53
    public $t_organization;
54
    public $t_overlap;
55
    public $t_splittype;
56
57
    public $organization;
58
    public $id_organization;
59
60
    private $resOrganization;
61
    private $dirfields;
62
63
    public function __construct()
64
    {
65
        $this->datebegintxt = absences_translate("Begin date");
66
        $this->dateendtxt = absences_translate("End date");
67
        $this->dateformattxt = "( ".absences_translate("dd-mm-yyyy")." )";
68
        $this->statustxt = absences_translate("Status");
69
        $this->separatortxt = absences_translate("Separator");
70
        $this->other = absences_translate("Other");
71
        $this->comma = absences_translate("Comma");
72
        $this->tab = absences_translate("Tab");
73
        $this->semicolon = absences_translate("Semicolon");
74
        $this->export = absences_translate("Export");
75
        $this->sepdectxt = absences_translate("Decimal separator");
76
        $this->t_yes = absences_translate("Yes");
77
        $this->t_no = absences_translate("No");
78
        $this->additional_fields = absences_translate("Additional fields to export:");
79
        $this->t_users_without_requests = absences_translate("Include uers without requests on the period");
80
        $this->t_splittype = absences_translate("Split requests by types");
81
        $this->t_organization = absences_translate('Organization');
82
83
        $this->t_overlap = absences_translate("Quantities and dates of requests are modified to fit in the export period");
84
85
        $W = bab_Widgets();
86
        $Canvas = $W->HtmlCanvas();
87
88
        $this->widgetdateb = $W->DatePicker()->setName('dateb')->display($Canvas);
0 ignored issues
show
The property widgetdateb 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...
89
        $this->widgetdatee = $W->DatePicker()->setName('datee')->display($Canvas);
0 ignored issues
show
The property widgetdatee does not seem to exist. Did you mean widgetdateb?

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...
90
91
        $this->statarr = array(absences_translate("Waiting"), absences_translate("Accepted"), absences_translate("Refused"));
0 ignored issues
show
The property statarr 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...
92
93
        $this->dirfields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
94
95
        unset($this->dirfields['sn']);
96
        unset($this->dirfields['givenname']);
97
        unset($this->dirfields['jpegphoto']);
98
99
        $this->resOrganization = new absences_OrganizationIterator();
100
        $this->useorg = $this->resOrganization->count();
0 ignored issues
show
The property useorg 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
        $this->resOrganization->rewind();
102
    }
103
104
    public function getnextstatus()
105
    {
106
        static $i = 0;
107
        if( $i < count($this->statarr))
108
        {
109
            $this->statusid = $i;
0 ignored issues
show
The property statusid 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...
110
            $this->statusname = $this->statarr[$i];
0 ignored issues
show
The property statusname 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...
111
            $i++;
112
            return true;
113
        }
114
        else
115
            return false;
116
    }
117
118
    /**
119
     * template method to list available organization
120
     */
121
    public function getnextorganization()
122
    {
123
        	
124
        if ($this->resOrganization->valid())
125
        {
126
            $organization = $this->resOrganization->current();
127
            $this->organization = bab_toHtml($organization->name);
128
            $this->id_organization = bab_toHtml($organization->id);
129
            $this->resOrganization->next();
130
            return true;
131
        }
132
133
        return false;
134
    }
135
136
137 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...
138
    {
139
        if (list($name,$arr) = each($this->dirfields))
140
        {
141
            $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...
142
            $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...
143
            return true;
144
        }
145
        return false;
146
    }
147
}
148
149
150
151
function exportVacationRequests()
152
{
153
	global $babBody;
154
	
155
156
	$temp = new absences_exportVacationRequestsCls();
157
	$babBody->babecho(bab_printTemplate($temp, absences_addon()->getRelativePath()."exportvac.html", "reqexport"));
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...
158
}
159
160
161
162
163
164
165
166
167
168
169
class absences_SageExportEditor extends Widget_Form
170
{
171
	public function __construct()
172
	{
173
		$W = bab_Widgets();
174
175
		parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(1,'em'));
176
177
		$this->setName('sage');
178
		$this->addClass('widget-bordered');
179
		$this->addClass('BabLoginMenuBackground');
180
		$this->addClass('widget-centered');
181
		$this->colon();
182
183
		$this->setCanvasOptions($this->Options()->width(70,'em'));
0 ignored issues
show
It seems like $this->Options()->width(70, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
184
185
186
		$this->addFields();
187
		$this->addButtons();
188
		$this->setSelfPageHiddenFields();
189
190
		if (isset($_POST['sage']))
191
		{
192
			$this->setValues(array('sage' => $_POST['sage']));
193
		} else {
194
195
		    $default = array('sage' => array('types' => array()));
196
197
		    // set default values
198
		    global $babDB;
199
200
		    //TRANSLATORS: filter by name for vacation types availables in sage export
201
		    $res = $babDB->db_query("SELECT id FROM absences_types WHERE name LIKE '%".$babDB->db_escape_like(absences_translate('paid'))."%'");
202
		    while($arr = $babDB->db_fetch_assoc($res)) {
203
		        $default['sage']['types'][] = $arr['id'];
204
		    }
205
		    $this->setValues($default);
206
		}
207
	}
208
209
210
	protected function addFields()
211
	{
212
		$W = bab_Widgets();
213
214
		$this->addItem(
215
				$W->LabelledWidget(
216
						absences_translate('Export vacations on period'),
217
						$W->PeriodPicker()->setMandatory(true, absences_translate('The period is mandatory')),
218
						'period'
219
				)
220
		);
221
222
223
		$select = $W->Select();
224
		$fields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP);
225
		foreach($fields as $name => $arr)
226
		{
227
			$select->addOption($name, $arr['name']);
228
229
			if (false !== mb_strpos(mb_strtolower($arr['name']), 'matricule'))
230
			{
231
				$select->setValue($name);
232
			}
233
		}
234
235
		$this->addItem(
236
				$W->LabelledWidget(
237
						//TRANSLATORS: Matricule Sage directory field
238
						absences_translate('sage user number in'),
239
						$select,
240
						'user_number'
241
				)
242
		);
243
244
		/*
245
		$separator = $W->Frame()
246
			->addItem(
247
					$W->LabelledWidget(
248
							absences_translate('Separator'),
249
							$select_format = $W->Select()
250
							->addOption(';', absences_translate('Semicolon'))
251
							->addOption(',', absences_translate('Comma'))
252
							->addOption('{tab}', absences_translate('Tab')),
253
							'separator'
254
					)
255
			);
256
257
258
		$this->addItem(
259
				$W->LabelledWidget(
260
						absences_translate('Format'),
261
						$W->Select()
262
							->addOption('sage', absences_translate('Sage text'))
263
							->addOption('csv', absences_translate('CSV'))
264
							->setAssociatedDisplayable($separator, array('csv')),
265
						'format'
266
				)
267
		);
268
269
270
		$this->addItem($separator);
271
		*/
272
273
        $this->addItem($this->types());
274
        
275
        if ($org = $this->organization()) {
276
            $this->addItem($org);
277
        }
278
279
        $this->addItem($W->Label(absences_translate("Quantities are modified to fit in the export period according to the selected types (dates are not modified)")));
280
281
	}
282
283
	
284
	protected function organization()
285
	{
286
	    $W = bab_Widgets();
287
	
288
	    $select = $W->Select()->addClass('absences-select');
289
	    $select->addOption('', '');
290
	    
291
	    $res = new absences_OrganizationIterator();
292
	    
293
	    if (0 === $res->count()) {
294
	        return null;
295
	    }
296
	    
297
	    foreach ($res as $organization) {
298
	        $select->addOption($organization->id, $organization->name);
299
	    }
300
	
301
	    return $W->LabelledWidget(
302
	        absences_translate('Organization'),
303
	        $select,
304
	        __FUNCTION__
305
	    );
306
	}
307
308
309 View Code Duplication
	protected function types()
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...
310
	{
311
	    $W = bab_Widgets();
312
	    global $babDB;
313
314
	    $select = $W->Multiselect();
315
	    $select->setHeadersDisplay();
316
317
	    $res = $babDB->db_query('SELECT * FROM absences_types ORDER BY name');
318
	    while($arr = $babDB->db_fetch_assoc($res)) {
319
	        $select->addOption($arr['id'], $arr['name']);
320
	    }
321
322
	    return $W->LabelledWidget(
323
    	    absences_translate('Vacation type'),
324
    	    $select,
325
	        'types'
326
    	);
327
	}
328
329
330
331
332
333 View Code Duplication
	protected function addButtons()
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...
334
	{
335
		$W = bab_Widgets();
336
337
		$button = $W->FlowItems(
338
				$W->SubmitButton()->setName('export')->setLabel(absences_translate('Export'))
339
		)->setSpacing(1,'em');
340
341
		$this->addItem($button);
342
	}
343
}
344
345
346
347
348
349
350
class absences_sageExportFile
351
{
352
	const OUTPUT_CHARSET = 'CP1252';
353
354
355
	/**
356
	 * Datetime
357
	 * @var string
358
	 */
359
	public $from;
360
361
	/**
362
	 * Datetime
363
	 * @var string
364
	 */
365
	public $to;
366
367
368
	/**
369
	 * Array of id vacation types
370
	 * @var array
371
	 */
372
	public $types;
373
	
374
	
375
	/**
376
	 * Filter by organization
377
	 * @var int
378
	 */
379
	public $organization;
380
381
382
	/**
383
	 * Directory entry field name
384
	 * @var string
385
	 */
386
	public $user_number_fieldname;
387
388
	/**
389
	 *
390
	 * @var string
391
	 */
392
	public $separator;
393
394
	/**
395
	 *
396
	 * @var unknown_type
397
	 */
398
	private $res;
399
400
	
401
	public function init() {
402
403
	    global $babDB;
404
	    
405
	    $query = '
406
				SELECT
407
					p.id_user,
408
					u.lastname,
409
					u.firstname
410
				FROM
411
					absences_personnel p,
412
					bab_users u
413
				WHERE
414
					u.id=p.id_user
415
		';
416
	    
417
	    if ($this->organization > 0) {
418
	        $query .= ' AND p.id_organization='.$babDB->quote($this->organization);
419
	    }
420
	    
421
	    $query .= ' ORDER BY u.lastname, u.firstname';
422
	    
423
	    $this->res = $babDB->db_query($query);
424
	}
425
426
427
428
	/**
429
	 * @return array
430
	 */
431
	private function getEntries($id_user)
432
	{
433
		require_once dirname(__FILE__).'/utilit/entry.class.php';
434
435
		$I = new absences_EntryIterator();
436
		$I->users = array($id_user);
437
		$I->status = 'Y';
438
		$I->from = $this->from;
439
		$I->to = $this->to;
440
441
		$quantity = 0.0;
442
		$periods = array();
443
		foreach($I as $entry)
444
		{
445
			/*@var $entry absences_Entry */
446
447
		    $eeI = $entry->getElementsIterator();
448
		    $eeI->types = $this->types;
449
450
		    $entry_quantity = 0.0;
451
452
		    foreach($eeI as $element) {
453
			    /* @var $element absences_EntryElem */
454
455
		        $right = $element->getRight();
456
		        if (!isset($right)) {
457
		            continue;
458
		        }
459
460
		        $type = $right->getType();
461
		        if (!isset($type)) {
462
		            continue;
463
		        }
464
465
		        if (!in_array($type->id, $this->types)) {
466
		            continue;
467
		        }
468
469
		        // ici on recupere la quantite de l'element tronque avec les dates
470
		        // de la periode demandee
471
		        $elem_quantity = $element->getPlannedQuantityBetween($this->from, $this->to);
472
473
		        if ('H' === $right->quantity_unit) {
474
		            // l'export sage contient des jours uniqument
475
476
		            $elem_quantity = ($elem_quantity/8);
477
		        }
478
479
    			$entry_quantity += $elem_quantity;
480
    			
481
    			
482
    			// dans la liste des periodes on affiche les periodes des types selectionnes
483
    			// les dates ne peuvent depasser par rapport au mois demande
484
    			
485
    			
486
    			$elem_from = $element->date_begin > $this->from ? $element->date_begin : $this->from;
487
    			$elem_to = $element->date_end < $this->to ? $element->date_end : $this->to;
488
    			
489
    			$periods[] = array(
490
    			    'from' 	=> date('d/m/y', bab_mktime($elem_from)),
491
    			    'to' 	=> date('d/m/y', bab_mktime($elem_to))
492
    			);
493
		    }
494
495
		    if ($entry_quantity > 0.001) {
496
497
    		    // la quantite totale des demandes du mois doit contenir que les conges
498
    		    // payes, uniquement pour le mois demande
499
500
    		    $quantity += $entry_quantity;
501
		    }
502
		}
503
504
505
		return array($quantity, $periods);
506
	}
507
508
509
	public function getnext()
510
	{
511
		global $babDB;
512
513
		if ($arr = $babDB->db_fetch_assoc($this->res))
514
		{
515
			$direntry = bab_admGetDirEntry($arr['id_user'], BAB_DIR_ENTRY_ID_USER);
516
			$arr['user_number'] = $direntry[$this->user_number_fieldname]['value'];
517
518
			list($quantity, $periods) = $this->getEntries($arr['id_user']);
519
520
			$arr['quantity'] = round($quantity, 1);
521
			$arr['periods'] = $periods;
522
523
			return $arr;
524
		}
525
	}
526
527
528
	private function setHeaders($extension, $mime)
529
	{
530
		$filename = mb_substr($this->from, 0, 10).'_'.mb_substr($this->to, 0, 10);
531
532
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
533
		header("Pragma: public");
534
		header('Content-Disposition: attachment; filename="'.$filename.$extension.'"'."\n");
535
		header('Content-Type: '.$mime."\n");
536
		header('Content-transfert-encoding: binary'."\n");
537
	}
538
539
540
	public function downloadSage()
541
	{
542
		$this->setHeaders('.txt', 'text/plain');
543
544
		while($arr = $this->getnext())
545
		{
546
			$p = '';
547
			foreach($arr['periods'] as $dates)
548
			{
549
				$p .= $dates['from'].$dates['to'];
550
			}
551
552
553
			echo str_pad('VB'.$arr['user_number'], 446);
554
			echo str_pad(number_format($arr['quantity'], 1, ',', ''), 50);
555
			echo str_pad('0', 11);
556
			echo str_pad($p, 432);
557
558
			echo "\r\n";
559
		}
560
	}
561
562
563
	private function csvEncode($value)
564
	{
565
		return '"'.str_replace('"', '""', $value).'"';
566
	}
567
568
569
570
	public function downloadCsv()
571
	{
572
		$this->setHeaders('.csv', 'text/csv');
573
574
		while($arr = $this->getnext())
575
		{
576
			$p = '';
577
			foreach($arr['periods'] as $dates)
578
			{
579
				$p .= implode(' ', $dates).'-';
580
			}
581
582
			$row = array(
583
				$this->csvEncode($arr['user_number']),
584
				$this->csvEncode(number_format($arr['quantity'], 1, ',', '')),
585
				$this->csvEncode(bab_convertStringFromDatabase($arr['lastname'].' '.$arr['firstname'], self::OUTPUT_CHARSET)),
586
				$this->csvEncode($p)
587
			);
588
589
			echo implode($this->separator, $row)."\n";
590
		}
591
	}
592
}
593
594
595
596
597
598
599
600
function absences_sageExport()
601
{
602
	$W = bab_Widgets();
603
	$page = $W->BabPage();
604
	
605
	$page->addStyleSheet(absences_addon()->getStylePath().'vacation.css');
606
607
608
	if (isset($_POST['sage']))
609
	{
610
		$values = $_POST['sage'];
611
		$datePicker = $W->DatePicker();
612
613
		$file = new absences_sageExportFile;
614
		$file->from = $datePicker->getISODate($values['period']['from']).' 00:00:00';
615
		$file->to = $datePicker->getISODate($values['period']['to']).' 23:59:59';
616
		$file->user_number_fieldname = $values['user_number'];
617
		$file->separator = isset($values['separator']) ? $values['separator'] : ',';
618
		$file->types = $values['types'];
619
		$file->organization = (int) $values['organization'];
620
		
621
		$file->init();
622
623
		$format = isset($values['format']) ? $values['format'] : 'sage';
624
625
		switch($format)
626
		{
627
			case 'csv':
628
				$file->downloadCsv();
629
				die();
630
631
			case 'sage':
632
			    $file->downloadSage();
633
			    die();
634
		}
635
	}
636
637
638
	$editor = new absences_SageExportEditor();
639
640
	$page->setTitle(absences_translate('Export vacations requests for sage'));
641
	$page->addItem($editor);
642
	$page->displayHtml();
643
}
644
645
646
647
648
649
650
/* main */
651
bab_requireCredential();
652
$agent = absences_Agent::getCurrentUser();
653
if( !$agent->isManager())
654
{
655
	$babBody->msgerror = absences_translate("Access denied");
656
	return;
657
}
658
659
$idx = bab_rp('idx', "reqx");
660
661
662
663
if( isset($_POST['bexport']))
664
{
665
    $W = bab_Widgets();
666
    $datePicker = $W->DatePicker();
667
    $dateb = BAB_DateTime::fromIsoDateTime($datePicker->getISODate($_POST['dateb']).' 00:00:00');
668
    $datee = BAB_DateTime::fromIsoDateTime($datePicker->getISODate($_POST['datee']).' 00:00:00');
669
    $datee->add(1, BAB_DATETIME_DAY);
670
671
	$export = new absences_ExportEntry(
672
	    $dateb, $datee, 
673
	    $_POST['idstatus'], $_POST['wsepar'], $_POST['separ'], $_POST['sepdec'], 
674
	    $_POST['users_without_requests'], bab_pp('dirfields', array()), bab_pp('organization', ''), bab_pp('splittype'));
675
	$export->output();
676
}
677
678
679
switch($idx)
680
{
681
682
	case 'sage':
683
		absences_sageExport();
684
		$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
685
		$babBody->addItemMenu("sage", absences_translate("Sage"), absences_addon()->getUrl()."exportvac&idx=sage");
686
		break;
687
688
689
	case "reqx":
690
691
		$babBody->setTitle(absences_translate("Export vacations requests"));
692
		exportVacationRequests();
693
		$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
694
		$babBody->addItemMenu("reqx", absences_translate("Export"), absences_addon()->getUrl()."exportvac&idx=reqx");
695
		break;
696
}
697
698
$babBody->setCurrentItemMenu($idx);
699
bab_siteMap::setPosition('absences','User');