|
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
|
|
|
bab_Widgets()->includePhpClass('Widget_Form'); |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
class absences_CetDepositRequestEditor extends Widget_Form |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
protected $deposit; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* |
|
35
|
|
|
* @var absences_AgentCet |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $cet; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* |
|
41
|
|
|
* @var bool |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $withCardFrame; |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function __construct(absences_CetDepositRequest $deposit = null, $withCardFrame = null) |
|
47
|
|
|
{ |
|
48
|
|
|
$W = bab_Widgets(); |
|
49
|
|
|
|
|
50
|
|
|
$this->deposit = $deposit; |
|
51
|
|
|
$this->withCardFrame = isset($withCardFrame) ? $withCardFrame : isset($deposit); |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(2,'em')); |
|
55
|
|
|
|
|
56
|
|
|
$this->setName('cet'); |
|
57
|
|
|
$this->addClass('widget-bordered'); |
|
58
|
|
|
$this->addClass('BabLoginMenuBackground'); |
|
59
|
|
|
$this->addClass('widget-centered'); |
|
60
|
|
|
$this->colon(); |
|
61
|
|
|
|
|
62
|
|
|
$this->setCanvasOptions($this->Options()->width(50,'em')); |
|
63
|
|
|
|
|
64
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
|
65
|
|
|
|
|
66
|
|
|
if (isset($this->deposit)) |
|
67
|
|
|
{ |
|
68
|
|
|
$agent = $this->deposit->getAgent(); |
|
69
|
|
|
} else { |
|
70
|
|
|
$agent = absences_Agent::getCurrentUser(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->cet = $agent->Cet(); |
|
74
|
|
|
|
|
75
|
|
|
$this->addFields(); |
|
76
|
|
|
$this->addButtons(); |
|
77
|
|
|
$this->setSelfPageHiddenFields(); |
|
78
|
|
|
|
|
79
|
|
|
$this->loadValues(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
protected function loadValues() |
|
84
|
|
|
{ |
|
85
|
|
|
if (isset($_POST['cet'])) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->setValues(array('cet' => $_POST['cet'])); |
|
88
|
|
|
return; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (isset($this->deposit)) |
|
92
|
|
|
{ |
|
93
|
|
|
$values = $this->deposit->getRow(); |
|
94
|
|
|
$this->setValues(array('cet' => $values)); |
|
95
|
|
|
|
|
96
|
|
|
if (isset($values['id'])) { |
|
97
|
|
|
$this->setHiddenValue('cet[id]', $values['id']); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (isset($values['id_user'])) { |
|
101
|
|
|
$this->setHiddenValue('cet[id_user]', $values['id_user']); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
protected function addFields() |
|
109
|
|
|
{ |
|
110
|
|
|
$W = bab_Widgets(); |
|
111
|
|
|
|
|
112
|
|
|
if (isset($this->deposit)) |
|
113
|
|
|
{ |
|
114
|
|
|
require_once dirname(__FILE__).'/agent.class.php'; |
|
115
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
|
116
|
|
|
|
|
117
|
|
|
if ($this->withCardFrame) |
|
118
|
|
|
{ |
|
119
|
|
|
$agent = absences_Agent::getFromIdUser($this->deposit->id_user); |
|
120
|
|
|
$cardFrame = new absences_AgentCardFrame($agent); |
|
121
|
|
|
$this->addItem($cardFrame); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
if ('' === $this->deposit->status) |
|
125
|
|
|
{ |
|
126
|
|
|
// modification of a waiting request |
|
127
|
|
|
$this->addItem($this->quantity()); |
|
128
|
|
|
$this->addItem($this->id_agent_right_source()); |
|
129
|
|
|
} else { |
|
130
|
|
|
|
|
131
|
|
|
// modification of a confirmed/rejected request |
|
132
|
|
|
|
|
133
|
|
|
$this->addItem($W->Label(sprintf(absences_translate('Deposit on the time saving account : %s'), absences_quantity($this->deposit->quantity, 'D')))); |
|
134
|
|
|
|
|
135
|
|
|
$right = $this->deposit->getAgentRightSource()->getRight(); |
|
136
|
|
|
if (isset($right)) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->addItem($W->Label(sprintf(absences_translate('Taken from right : %s'), $right->description))); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} else { |
|
142
|
|
|
|
|
143
|
|
|
// a request |
|
144
|
|
|
$this->addItem($this->quantity()); |
|
145
|
|
|
$this->addItem($this->id_agent_right_source()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
$this->addItem($this->comment()); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
protected function id_agent_right_source() |
|
153
|
|
|
{ |
|
154
|
|
|
$W = bab_Widgets(); |
|
155
|
|
|
$select = $W->Select(); |
|
156
|
|
|
|
|
157
|
|
|
foreach($this->cet->getRightsIterator() as $agentRight) |
|
158
|
|
|
{ |
|
159
|
|
|
/*@var $agentRight absences_AgentRight */ |
|
160
|
|
|
$right = $agentRight->getRight(); |
|
161
|
|
|
$select->addOption($agentRight->id, $right->description); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
return $W->LabelledWidget( |
|
165
|
|
|
absences_translate('Taken from right'), |
|
166
|
|
|
$select, |
|
167
|
|
|
__FUNCTION__ |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
View Code Duplication |
protected function comment() |
|
|
|
|
|
|
174
|
|
|
{ |
|
175
|
|
|
$W = bab_Widgets(); |
|
176
|
|
|
|
|
177
|
|
|
return $W->LabelledWidget( |
|
178
|
|
|
absences_translate('Comment'), |
|
179
|
|
|
$W->TextEdit()->setColumns(60)->setLines(4), |
|
180
|
|
|
__FUNCTION__ |
|
181
|
|
|
); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
protected function quantity() |
|
186
|
|
|
{ |
|
187
|
|
|
$W = bab_Widgets(); |
|
188
|
|
|
|
|
189
|
|
|
$quantity_unit = $this->cet->getQuantityUnit(); |
|
190
|
|
|
switch($quantity_unit) |
|
191
|
|
|
{ |
|
192
|
|
|
case 'D': |
|
193
|
|
|
$unit = absences_translate('Day(s)'); |
|
194
|
|
|
break; |
|
195
|
|
|
|
|
196
|
|
|
case 'H': |
|
197
|
|
|
$unit = absences_translate('Hour(s)'); |
|
198
|
|
|
break; |
|
199
|
|
|
|
|
200
|
|
|
default: |
|
201
|
|
|
$unit = $quantity_unit; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
return $W->LabelledWidget( |
|
205
|
|
|
absences_translate('Move into the time saving account'), |
|
206
|
|
|
$W->LineEdit()->setSize(6)->setMaxSize(10)->setMandatory(true, absences_translate('The quantity is mandatory')), |
|
207
|
|
|
__FUNCTION__, |
|
208
|
|
|
null, |
|
209
|
|
|
$unit |
|
210
|
|
|
); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
|
|
215
|
|
View Code Duplication |
protected function addButtons() |
|
|
|
|
|
|
216
|
|
|
{ |
|
217
|
|
|
$W = bab_Widgets(); |
|
218
|
|
|
|
|
219
|
|
|
$button = $W->FlowItems( |
|
220
|
|
|
|
|
221
|
|
|
$W->SubmitButton()->setName('save')->setLabel(absences_translate('Save')), |
|
222
|
|
|
$W->SubmitButton()->setName('cancel')->setLabel(absences_translate('Cancel')) |
|
223
|
|
|
)->setSpacing(1,'em'); |
|
224
|
|
|
|
|
225
|
|
|
$this->addItem($button); |
|
226
|
|
|
} |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
class absences_CetDepositRequestApprobEditor extends absences_CetDepositRequestEditor |
|
233
|
|
|
{ |
|
234
|
|
|
public function __construct(absences_CetDepositRequest $deposit) |
|
235
|
|
|
{ |
|
236
|
|
|
|
|
237
|
|
|
parent::__construct($deposit); |
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Load values into editor |
|
244
|
|
|
* |
|
245
|
|
|
*/ |
|
246
|
|
View Code Duplication |
protected function loadValues() |
|
|
|
|
|
|
247
|
|
|
{ |
|
248
|
|
|
if (isset($_POST['cet'])) |
|
249
|
|
|
{ |
|
250
|
|
|
$this->setValues(array('cet' => $_POST['cet'])); |
|
251
|
|
|
} else { |
|
252
|
|
|
if (isset($this->deposit)) |
|
253
|
|
|
{ |
|
254
|
|
|
$this->setValues(array('cet' => $this->deposit->getRow())); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
if (isset($this->deposit)) |
|
259
|
|
|
{ |
|
260
|
|
|
$this->setHiddenValue('cet[id]', $this->deposit->id); |
|
261
|
|
|
$this->setHiddenValue('id_deposit', $this->deposit->id); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
|
|
266
|
|
|
protected function addFields() |
|
267
|
|
|
{ |
|
268
|
|
|
$W = bab_Widgets(); |
|
269
|
|
|
|
|
270
|
|
|
require_once dirname(__FILE__).'/agent.ui.php'; |
|
271
|
|
|
|
|
272
|
|
|
$agent = $this->deposit->getAgent(); |
|
273
|
|
|
$card = new absences_AgentCardFrame($agent); |
|
274
|
|
|
|
|
275
|
|
|
$this->addItem($card); |
|
276
|
|
|
|
|
277
|
|
|
$this->addItem($this->agent_right_source()); |
|
278
|
|
|
$this->addItem($this->quantity()); |
|
279
|
|
|
|
|
280
|
|
|
if ($comment = $this->comment()) |
|
281
|
|
|
{ |
|
282
|
|
|
$this->addItem($comment); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
$this->addItem($this->comment2()); |
|
286
|
|
|
|
|
287
|
|
|
$this->addItem($W->Icon(absences_translate('The acceptation will add the specified quantity in the applicant time saving account'), Func_Icons::STATUS_DIALOG_INFORMATION)); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* |
|
292
|
|
|
*/ |
|
293
|
|
|
protected function agent_right_source() |
|
294
|
|
|
{ |
|
295
|
|
|
$W = bab_Widgets(); |
|
296
|
|
|
|
|
297
|
|
|
$agentRight = $this->deposit->getAgentRightSource(); |
|
298
|
|
|
if (!$agentRight->getRow()) |
|
299
|
|
|
{ |
|
300
|
|
|
$description = absences_translate('Unknown'); |
|
301
|
|
|
} else { |
|
302
|
|
|
$right = $agentRight->getRight(); |
|
303
|
|
|
$description = $right->description; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
return $W->VBoxItems( |
|
308
|
|
|
$W->Label(absences_translate('From right'))->colon(), |
|
309
|
|
|
$W->Label($description) |
|
310
|
|
|
); |
|
311
|
|
|
|
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* |
|
317
|
|
|
*/ |
|
318
|
|
|
protected function comment() |
|
319
|
|
|
{ |
|
320
|
|
|
$W = bab_Widgets(); |
|
321
|
|
|
|
|
322
|
|
|
if (empty($this->deposit->comment)) |
|
323
|
|
|
{ |
|
324
|
|
|
return null; |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return $W->VBoxItems( |
|
328
|
|
|
$W->Label(absences_translate('Reason for the request'))->colon(), |
|
329
|
|
|
$W->RichText($this->deposit->comment) |
|
330
|
|
|
); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
|
|
334
|
|
|
|
|
335
|
|
View Code Duplication |
protected function comment2() |
|
|
|
|
|
|
336
|
|
|
{ |
|
337
|
|
|
$W = bab_Widgets(); |
|
338
|
|
|
|
|
339
|
|
|
return $W->LabelledWidget( |
|
340
|
|
|
absences_translate('Approver comment'), |
|
341
|
|
|
$W->TextEdit()->setColumns(60)->setLines(5), |
|
342
|
|
|
__FUNCTION__ |
|
343
|
|
|
); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
|
|
347
|
|
|
|
|
348
|
|
View Code Duplication |
protected function addButtons() |
|
|
|
|
|
|
349
|
|
|
{ |
|
350
|
|
|
$W = bab_Widgets(); |
|
351
|
|
|
|
|
352
|
|
|
$button = $W->FlowItems( |
|
353
|
|
|
|
|
354
|
|
|
$W->SubmitButton()->setName('confirm')->setLabel(absences_translate('Confirm')), |
|
355
|
|
|
$W->SubmitButton()->setName('refuse')->setLabel(absences_translate('Refuse')) |
|
356
|
|
|
)->setSpacing(1,'em'); |
|
357
|
|
|
|
|
358
|
|
|
$this->addItem($button); |
|
359
|
|
|
} |
|
360
|
|
|
} |
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.