sync_server.php ➔ absences_syncServerSave()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 31
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
c 0
b 0
f 0
nc 9
nop 1
dl 0
loc 31
rs 8.439
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
31
32
33
34
function absences_syncServerSave($values)
35
{
36
	global $babDB;
37
	
38
	// uncheck non-visible rights
39
	
40
	$I = new absences_RightIterator();
41
	foreach($I as $right)
42
	{
43
		/*@var $right absences_Right */
44
		
45
		if (!isset($values[$right->id]) && absences_Right::SYNC_SERVER === $right->getSyncStatus())
46
		{
47
			$babDB->db_query('UPDATE absences_rights SET sync_status='.$babDB->quote(0).', date_entry=NOW() WHERE id='.$babDB->quote($right->id));
48
		}
49
	}
50
	
51
	
52
	foreach($values['right'] as $id_right => $checked)
53
	{
54
		$status = $checked ? absences_Right::SYNC_SERVER : 0;
55
		$babDB->db_query('UPDATE absences_rights SET sync_status='.$babDB->quote($status).', date_entry=NOW() WHERE id='.$babDB->quote($id_right));
56
	}
57
	
58
	// redirect to form page
59
	
60
	require_once $GLOBALS['babInstallPath'].'utilit/urlincl.php';
61
	
62
	$url = bab_url::get_request('tg');
63
	$url->location();
64
}
65
66
67
68
function absences_syncServerEdit()
69
{
70
	$W = bab_Widgets();
71
	$page = $W->BabPage();
72
	
73
	
74
	if (isset($_POST['sync_server']))
75
	{
76
77
		if( isset($_POST['sync_server']['save'] ))
78
		{
79
	
80
			// modification uniquement
81
	
82
			$values = $_POST['sync_server'];
83
			absences_syncServerSave($values);
84
		}
85
	}
86
	
87
88
	
89
	$editor = new absences_SyncServerEditor();
90
	
91
	$page->setTitle(absences_translate('Edit the shared vacation rights'));
92
	$page->addItem($editor);
93
	$page->displayHtml();
94
}
95
96
97
98
99
100
/* main */
101
bab_requireCredential();
102
$agent = absences_Agent::getCurrentUser();
103
if( !$agent->isManager())
104
{
105
	$babBody->msgerror = absences_translate("Access denied");
106
	return;
107
}
108
109
if ($agent->isInPersonnel())
110
{
111
	$babBody->addItemMenu("vacuser", absences_translate("Vacations"), absences_addon()->getUrl()."vacuser");
112
}
113
$babBody->addItemMenu("menu", absences_translate("Management"), absences_addon()->getUrl()."vacadm&idx=menu");
114
115
$idx = bab_rp('idx', "edit");
116
117
118 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...
119
{
120
	case 'edit':
121
		absences_syncServerEdit();
122
		$babBody->addItemMenu("edit", absences_translate("Edit"), absences_addon()->getUrl()."sync_server&idx=edit");
123
		break;
124
}
125
126
127
$babBody->setCurrentItemMenu($idx);
128
bab_siteMap::setPosition('absences','User');