|
1
|
|
|
<?php |
|
2
|
|
|
//------------------------------------------------------------------------- |
|
3
|
|
|
// OVIDENTIA http://www.ovidentia.org |
|
4
|
|
|
// Ovidentia is free software; you can redistribute it and/or modify |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by |
|
6
|
|
|
// the Free Software Foundation; either version 2, or (at your option) |
|
7
|
|
|
// any later version. |
|
8
|
|
|
// |
|
9
|
|
|
// This program is distributed in the hope that it will be useful, but |
|
10
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
12
|
|
|
// See the GNU General Public License for more details. |
|
13
|
|
|
// |
|
14
|
|
|
// You should have received a copy of the GNU General Public License |
|
15
|
|
|
// along with this program; if not, write to the Free Software |
|
16
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
17
|
|
|
// USA. |
|
18
|
|
|
//------------------------------------------------------------------------- |
|
19
|
|
|
/** |
|
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL) |
|
21
|
|
|
* @copyright Copyright (c) 2006 by CANTICO ({@link http://www.cantico.fr}) |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
require_once dirname(__FILE__).'/utilit/vacincl.php'; |
|
26
|
|
|
require_once dirname(__FILE__).'/functions.php'; |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* formulaire de recherche pour les liste des demandes gestionnaire |
|
34
|
|
|
*/ |
|
35
|
|
|
class absences_getAbsenceSearchForm |
|
36
|
|
|
{ |
|
37
|
|
|
public function getForm() |
|
38
|
|
|
{ |
|
39
|
|
|
bab_functionality::includeOriginal('Icons'); |
|
40
|
|
|
$W = bab_Widgets(); |
|
41
|
|
|
$form = $W->Form(null, $W->FlowLayout()->setSpacing(1, 'em', 3,'em')); |
|
42
|
|
|
$form->setSelfPageHiddenFields()->setReadOnly(); |
|
43
|
|
|
|
|
44
|
|
|
$form->addClass('absences-filterform'); |
|
45
|
|
|
$form->addClass('widget-bordered'); |
|
46
|
|
|
$form->addClass('BabLoginMenuBackground'); |
|
47
|
|
|
$form->addClass('widget-centered'); |
|
48
|
|
|
$form->addClass(Func_Icons::ICON_LEFT_16); |
|
49
|
|
|
$form->colon(); |
|
50
|
|
|
|
|
51
|
|
|
$form->setCanvasOptions($form->Options()->width(97,'%')); |
|
52
|
|
|
|
|
53
|
|
|
$period = $W->LabelledWidget( |
|
54
|
|
|
absences_translate('Date'), |
|
55
|
|
|
$W->PeriodPicker()->setNames('dateb', 'datee') |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$date = $W->LabelledWidget( |
|
59
|
|
|
absences_translate('Date'), |
|
60
|
|
|
$W->DatePicker(), |
|
61
|
|
|
'date' |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$form->addItem( |
|
67
|
|
|
$W->LabelledWidget( |
|
68
|
|
|
absences_translate('Search absences'), |
|
69
|
|
|
$W->Select() |
|
70
|
|
|
->setAssociatedDisplayable($date, array('1')) |
|
71
|
|
|
->setAssociatedDisplayable($period, array('2')) |
|
72
|
|
|
->addOption('1', absences_translate("Absences on a date")) |
|
73
|
|
|
->addOption('2', absences_translate("Absences in a period")), |
|
74
|
|
|
'searchtype' |
|
75
|
|
|
) |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$form->addItem($period); |
|
80
|
|
|
$form->addItem($date); |
|
81
|
|
|
|
|
82
|
|
|
$values = array( |
|
83
|
|
|
'searchtype' => $this->param('searchtype'), |
|
84
|
|
|
'dateb' => $this->param('dateb'), |
|
85
|
|
|
'datee' => $this->param('datee'), |
|
86
|
|
|
'date' => $this->param('date'), |
|
87
|
|
|
'vpos' => (int) $this->param('vpos', 0) |
|
88
|
|
|
); |
|
89
|
|
|
|
|
90
|
|
|
$form->setValues($values); |
|
91
|
|
|
$form->addItem($W->SubmitButton()->setLabel(absences_translate('Search'))); |
|
92
|
|
|
|
|
93
|
|
|
return $form; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
View Code Duplication |
public function getHtmlForm(Array $statarr = null) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
$W = bab_Widgets(); |
|
101
|
|
|
$form = $this->getForm($statarr); |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
return $form->display($W->HtmlCanvas()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
public function param($name, $default = '') |
|
108
|
|
|
{ |
|
109
|
|
|
if (isset($_REQUEST[$name])) |
|
110
|
|
|
{ |
|
111
|
|
|
$_SESSION['babVacationSearch'][$name] = $_REQUEST[$name]; |
|
112
|
|
|
return $_REQUEST[$name]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (isset($_SESSION['babVacationSearch'][$name])) |
|
116
|
|
|
{ |
|
117
|
|
|
return $_SESSION['babVacationSearch'][$name]; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $default; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
class absences_SearchList extends absences_Paginate |
|
130
|
|
|
{ |
|
131
|
|
|
const MAX = 30; |
|
132
|
|
|
|
|
133
|
|
|
private $res; |
|
134
|
|
|
|
|
135
|
|
|
public $altbg = true; |
|
136
|
|
|
|
|
137
|
|
|
public function __construct() |
|
138
|
|
|
{ |
|
139
|
|
|
$this->t_user = absences_translate('User'); |
|
|
|
|
|
|
140
|
|
|
$this->t_begin = absences_translate('Begin'); |
|
|
|
|
|
|
141
|
|
|
$this->t_end = absences_translate('End'); |
|
|
|
|
|
|
142
|
|
|
$this->t_quantity = absences_translate('Quantity'); |
|
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
$f = new absences_getAbsenceSearchForm(); |
|
145
|
|
|
|
|
146
|
|
|
require_once dirname(__FILE__).'/utilit/entry.class.php'; |
|
147
|
|
|
$this->res = new absences_EntryIterator(); |
|
148
|
|
|
|
|
149
|
|
|
$this->res->orderby = 'date_begin DESC'; |
|
150
|
|
|
|
|
151
|
|
|
$this->res->archived = 0; |
|
152
|
|
|
$this->res->status = 'Y'; |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
$W = bab_Widgets(); |
|
156
|
|
|
$datePicker = $W->DatePicker(); |
|
157
|
|
|
|
|
158
|
|
|
if (2 === (int) bab_rp('searchtype')) { |
|
159
|
|
|
if ('0000-00-00' !== $begin = $datePicker->getISODate($f->param('dateb', null))) { |
|
160
|
|
|
$this->res->from = $begin; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
View Code Duplication |
if ('0000-00-00' !== $end = $datePicker->getISODate($f->param('datee', null))) { |
|
|
|
|
|
|
164
|
|
|
$this->res->to = $this->addOneDay($end); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
if (1 === (int) bab_rp('searchtype')) { |
|
169
|
|
View Code Duplication |
if ('0000-00-00' !== $date = $datePicker->getISODate($f->param('date', null))) { |
|
|
|
|
|
|
170
|
|
|
$this->res->from = $date; |
|
171
|
|
|
$this->res->to = $this->addOneDay($date); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
$this->res->rewind(); |
|
176
|
|
|
|
|
177
|
|
|
$this->paginate($this->res->count(), self::MAX); |
|
178
|
|
|
$this->res->seek($this->pos); |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
$this->searchform = $f->getHtmlForm(); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Add one day |
|
187
|
|
|
* @return string |
|
188
|
|
|
*/ |
|
189
|
|
|
private function addOneDay($strDate) { |
|
190
|
|
|
$date = BAB_DateTime::fromIsoDateTime($strDate); |
|
191
|
|
|
$date->add(1, BAB_DATETIME_DAY); |
|
192
|
|
|
return $date->getIsoDate(); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
public function getnext() |
|
197
|
|
|
{ |
|
198
|
|
|
if (($this->res->key() - $this->pos) >= self::MAX) |
|
199
|
|
|
{ |
|
200
|
|
|
return false; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
if ($this->res->valid()) |
|
204
|
|
|
{ |
|
205
|
|
|
$entry = $this->res->current(); |
|
206
|
|
|
/*@var $entry absences_Entry */ |
|
207
|
|
|
|
|
208
|
|
|
$this->altbg = !$this->altbg; |
|
209
|
|
|
|
|
210
|
|
|
$this->username = bab_toHtml(bab_getUserName($entry->id_user)); |
|
|
|
|
|
|
211
|
|
|
$this->begin = bab_toHtml(bab_shortDate(bab_mktime($entry->date_begin))); |
|
|
|
|
|
|
212
|
|
|
$this->end = bab_toHtml(bab_shortDate(bab_mktime($entry->date_end))); |
|
|
|
|
|
|
213
|
|
|
$this->quantity = bab_toHtml(absences_quantity($entry->getTotalDays(), 'D')); |
|
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
$this->res->next(); |
|
216
|
|
|
return true; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
return false; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
|
|
235
|
|
|
function absences_search() |
|
236
|
|
|
{ |
|
237
|
|
|
$babBody = bab_getBody(); |
|
238
|
|
|
|
|
239
|
|
|
$list = new absences_SearchList(); |
|
240
|
|
|
|
|
241
|
|
|
$babBody->setTitle(absences_translate('Absences')); |
|
242
|
|
|
|
|
243
|
|
|
$babBody->addStyleSheet(absences_Addon()->getStylePath().'vacation.css'); |
|
244
|
|
|
$babBody->babEcho(bab_printTemplate($list, absences_addon()->getRelativePath()."search.html", "list")); |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
// Main |
|
250
|
|
|
|
|
251
|
|
|
|
|
252
|
|
|
bab_requireAccess('absences_search_absences_groups', 1, absences_translate('You must be logged in')); |
|
253
|
|
|
bab_siteMap::setPosition('absences','User'); |
|
254
|
|
|
|
|
255
|
|
|
absences_search(); |
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.