|
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
|
|
|
bab_Widgets()->includePhpClass('Widget_Form'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Template class for organization list |
|
28
|
|
|
* |
|
29
|
|
|
*/ |
|
30
|
|
|
class absences_OrganizationList |
|
31
|
|
|
{ |
|
32
|
|
|
public $altbg = true; |
|
33
|
|
|
|
|
34
|
|
|
private $res; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
global $babDB; |
|
39
|
|
|
|
|
40
|
|
|
$this->t_edit = absences_translate('Edit'); |
|
|
|
|
|
|
41
|
|
|
$this->t_name = absences_translate('Name'); |
|
|
|
|
|
|
42
|
|
|
$this->t_agents = absences_translate('Personnel members'); |
|
|
|
|
|
|
43
|
|
|
$sync = (bool) absences_getVacationOption('organization_sync'); |
|
44
|
|
|
$this->allowedit = !$sync; |
|
|
|
|
|
|
45
|
|
|
$this->res = $babDB->db_query('SELECT |
|
46
|
|
|
|
|
47
|
|
|
o.id, o.name, COUNT(p.id) agents FROM absences_organization o |
|
48
|
|
|
LEFT JOIN absences_personnel p ON p.id_organization=o.id |
|
49
|
|
|
|
|
50
|
|
|
GROUP BY o.id |
|
51
|
|
|
ORDER BY o.name'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getnext() |
|
55
|
|
|
{ |
|
56
|
|
|
global $babDB; |
|
57
|
|
|
|
|
58
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->res)) { |
|
59
|
|
|
$this->altbg = !$this->altbg; |
|
60
|
|
|
$this->name = bab_toHtml($arr['name']); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$url = bab_url::get_request('tg'); |
|
63
|
|
|
$url->idx = 'edit'; |
|
64
|
|
|
$url->id_organization = $arr['id']; |
|
65
|
|
|
|
|
66
|
|
|
$this->editurl = bab_toHtml($url->toString()); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$this->agents = bab_toHtml($arr['agents']); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$url = new bab_url(absences_Addon()->getUrl().'vacadm'); |
|
71
|
|
|
$url->idx = 'lper'; |
|
72
|
|
|
$url->filter = array('organization' => $arr['id']); |
|
73
|
|
|
$this->agentsurl = bab_toHtml($url->toString()); |
|
|
|
|
|
|
74
|
|
|
return true; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get a html menu to create an organization |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
function absences_organizationMenu() |
|
90
|
|
|
{ |
|
91
|
|
|
$toolbar = absences_getToolbar(); |
|
92
|
|
|
|
|
93
|
|
|
$addon = bab_getAddonInfosInstance('absences'); |
|
94
|
|
|
$sImgPath = $GLOBALS['babInstallPath'] . 'skins/ovidentia/images/Puces/'; |
|
95
|
|
|
|
|
96
|
|
|
$sync = (int) absences_getVacationOption('organization_sync'); |
|
97
|
|
View Code Duplication |
if (!$sync) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
|
|
100
|
|
|
$toolbar->addToolbarItem( |
|
101
|
|
|
new BAB_ToolbarItem( |
|
102
|
|
|
absences_translate('Add organization'), |
|
103
|
|
|
$addon->getUrl().'organizations&idx=edit', |
|
104
|
|
|
$sImgPath . 'edit_add.png', '', '', '') |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $toolbar->printTemplate(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
class absences_OrganizationEditor extends Widget_Form |
|
117
|
|
|
{ |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @var absences_Organization |
|
121
|
|
|
*/ |
|
122
|
|
|
protected $organization; |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
View Code Duplication |
public function __construct(absences_Organization $organization) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
$W = bab_Widgets(); |
|
128
|
|
|
|
|
129
|
|
|
parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(2,'em')); |
|
130
|
|
|
|
|
131
|
|
|
$this->organization = $organization; |
|
132
|
|
|
|
|
133
|
|
|
$this->setName('organization'); |
|
134
|
|
|
$this->addClass('widget-bordered'); |
|
135
|
|
|
$this->addClass('BabLoginMenuBackground'); |
|
136
|
|
|
$this->addClass('widget-centered'); |
|
137
|
|
|
$this->addClass(Func_Icons::ICON_LEFT_16); |
|
138
|
|
|
|
|
139
|
|
|
$this->colon(); |
|
140
|
|
|
|
|
141
|
|
|
$this->setCanvasOptions($this->Options()->width(70,'em')); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
$this->addFields(); |
|
144
|
|
|
$this->setValues($organization->getRow(), array('organization')); |
|
145
|
|
|
|
|
146
|
|
|
$this->addButtons(); |
|
147
|
|
|
$this->setSelfPageHiddenFields(); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
protected function addFields() |
|
153
|
|
|
{ |
|
154
|
|
|
$W = bab_Widgets(); |
|
155
|
|
|
|
|
156
|
|
|
$this->addItem($W->LabelledWidget( |
|
157
|
|
|
absences_translate('Name'), |
|
158
|
|
|
$W->LineEdit()->setSize(70)->setMaxSize(255), |
|
159
|
|
|
'name' |
|
160
|
|
|
)); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
protected function addButtons() |
|
166
|
|
|
{ |
|
167
|
|
|
$W = bab_Widgets(); |
|
168
|
|
|
|
|
169
|
|
|
$button = $W->FlowItems( |
|
170
|
|
|
$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save')) |
|
171
|
|
|
)->setSpacing(2,'em')->setVerticalAlign('middle'); |
|
172
|
|
|
|
|
173
|
|
|
$url = bab_url::get_request('tg'); |
|
174
|
|
|
$url->idx = 'delete'; |
|
175
|
|
|
$url->id_organization = $this->organization->id; |
|
176
|
|
|
|
|
177
|
|
|
$agents = $this->organization->getAgentInterator(); |
|
178
|
|
|
|
|
179
|
|
|
if ($agents) { |
|
180
|
|
|
|
|
181
|
|
|
if ($agents->count()) { |
|
182
|
|
|
|
|
183
|
|
|
$button->addItem( |
|
184
|
|
|
$W->Link( |
|
185
|
|
|
$W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), |
|
186
|
|
|
$url->toString() |
|
187
|
|
|
)->setConfirmationMessage(sprintf(absences_translate('This organization is linked to %d users, do you really whant to delete it?'), $agents->count())) |
|
188
|
|
|
); |
|
189
|
|
|
} else { |
|
190
|
|
|
|
|
191
|
|
|
$button->addItem( |
|
192
|
|
|
$W->Link($W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $url->toString()) |
|
193
|
|
|
->setConfirmationMessage(absences_translate('Do you really whant to delete this organization?')) |
|
194
|
|
|
); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
$this->addItem($button); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: