sync_client.php ➔ absences_syncClientEdit()   B
last analyzed

Complexity

Conditions 4
Paths 9

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
c 0
b 0
f 0
nc 9
nop 0
dl 0
loc 29
rs 8.5806
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__).'/functions.php';
26
require_once dirname(__FILE__).'/utilit/vacincl.php';
27
require_once dirname(__FILE__).'/utilit/right.class.php';
28
require_once dirname(__FILE__).'/utilit/agent.class.php';
29
require_once dirname(__FILE__).'/utilit/sync.ui.php';
30
require_once dirname(__FILE__).'/utilit/client.class.php';
31
32
/**
33
 * 
34
 * @param array $values
35
 */
36
function absences_syncClientSave($values)
37
{
38
	global $babDB;
39
	
40
	
41
	$babBody = bab_getInstance('babBody');
42
	/*@var $babBody babBody */
43
	
44
	$client = new absences_client;
45
	$checked_uuid = array();
46
	
47
	
48
	
49
	foreach($values['right'] as $uuid => $checked)
50
	{
51
		if ($checked)
52
		{
53
			
54
			$checked_uuid[] = $uuid;
55
			
56
			$right = absences_Right::getByUuid($uuid);
57
			
58
			if (!$right->getRow())
59
			{
60
				// the right does not exists in client database
61
				$new_right = $client->addRight($uuid);
62
				$babBody->addNextPageMessage(sprintf(absences_translate('The right %s has been created'), $new_right->description));
0 ignored issues
show
Documentation introduced by
sprintf(absences_transla...new_right->description) is of type string, but the function expects a object<unknown_type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
			
64
			} else {
65
				// the right exists, update sync status
66
				$client->updateRight($uuid);
67
				$babBody->addNextPageMessage(sprintf(absences_translate('The right %s has been updated'), $right->description));
0 ignored issues
show
Documentation introduced by
sprintf(absences_transla...), $right->description) is of type string, but the function expects a object<unknown_type>.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
			}
69
		}
70
	}
71
	
72
	$babDB->db_query('UPDATE absences_rights SET sync_status='.$babDB->quote(0).' WHERE uuid NOT IN('.$babDB->quote($checked_uuid).')');
73
	
74
	
75
	require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
76
	
77
	$url = bab_url::get_request('tg');
78
	$url->location();
79
	
80
}
81
82
83
84
85
86
function absences_syncClientEdit()
87
{
88
	$W = bab_Widgets();
89
	$page = $W->BabPage();
90
	
91
	if (isset($_POST['sync_client']))
92
	{
93
		
94
		if( isset($_POST['sync_client']['save'] ))
95
		{
96
			
97
			// modification uniquement
98
	
99
			$values = $_POST['sync_client'];
100
			absences_syncClientSave($values);
101
		}
102
	}
103
	
104
	$page->setTitle(absences_translate('Add vacation rights'));
105
	try {
106
		$editor = new absences_SyncClientEditor();
107
		$page->addItem($editor);
108
	} catch(Exception $e)
109
	{
110
		$page->addError($e->getMessage());
111
	}
112
	
113
	$page->displayHtml();
114
}
115
116
117
118
119
120
/* main */
121
bab_requireCredential();
122
$agent = absences_Agent::getCurrentUser();
123
if( !$agent->isManager())
124
{
125
	$babBody->msgerror = absences_translate("Access denied");
126
	return;
127
}
128
129
if ($agent->isInPersonnel())
130
{
131
	$babBody->addItemMenu("vacuser", absences_translate("Vacations"), absences_addon()->getUrl()."vacuser");
132
}
133
$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
134
135
$idx = bab_rp('idx', "edit");
136
137
138 View Code Duplication
switch($idx)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
139
{
140
	case 'edit':
141
		absences_syncClientEdit();
142
		$babBody->addItemMenu("edit", absences_translate("Edit"), absences_addon()->getUrl()."sync_client&idx=edit");
143
		break;
144
}
145
146
147
$babBody->setCurrentItemMenu($idx);
148
bab_siteMap::setPosition('absences','User');