|
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__).'/csv.class.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Export all rights or year rights for each agents on a list of agents |
|
29
|
|
|
* |
|
30
|
|
|
*/ |
|
31
|
|
|
class absences_RightExportCsv extends absences_Csv |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* |
|
36
|
|
|
* @var int |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $org; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* |
|
42
|
|
|
* @var int |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $year; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var array |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $dirFields; |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $separator = ','; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $decsep = '.'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* |
|
67
|
|
|
* @var string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $outputCharset = null; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $org |
|
73
|
|
|
* @param int $year |
|
74
|
|
|
* @param array $dirFields List of additional directory fields |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __construct($org, $year, Array $dirFields, $separator = null, $decsep = null, $outputCharset = null) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->org = $org; |
|
79
|
|
|
$this->year = $year; |
|
80
|
|
|
$this->dirFields = $dirFields; |
|
81
|
|
|
|
|
82
|
|
|
if (isset($separator)) { |
|
83
|
|
|
$this->separator = $separator; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (isset($decsep)) { |
|
87
|
|
|
$this->decsep = $decsep; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$this->outputCharset = bab_Charset::getIso(); |
|
91
|
|
|
|
|
92
|
|
|
if (isset($outputCharset)) { |
|
93
|
|
|
$this->outputCharset = $outputCharset; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return absences_AgentIterator |
|
100
|
|
|
*/ |
|
101
|
|
|
protected function selectAgents() |
|
102
|
|
|
{ |
|
103
|
|
|
require_once dirname(__FILE__).'/organization.class.php'; |
|
104
|
|
|
|
|
105
|
|
|
$res = new absences_AgentIterator(); |
|
106
|
|
|
|
|
107
|
|
|
if (isset($this->org)) { |
|
108
|
|
|
$organization = absences_Organization::getById($this->org); |
|
109
|
|
|
$res->setOrganization($organization); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $res; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* |
|
120
|
|
|
* @param absences_Agent $agent |
|
121
|
|
|
* @return absences_AgentRightManagerIterator |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function selectAgentRights(absences_Agent $agent) |
|
124
|
|
|
{ |
|
125
|
|
|
require_once dirname(__FILE__).'/agent_right.class.php'; |
|
126
|
|
|
$I = new absences_AgentRightManagerIterator; |
|
127
|
|
|
$I->setAgent($agent); |
|
128
|
|
|
|
|
129
|
|
|
if (isset($this->year)) { |
|
130
|
|
|
$I->year = $this->year; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $I; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return array |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function getHeader() |
|
141
|
|
|
{ |
|
142
|
|
|
$row = array( |
|
143
|
|
|
absences_translate('Lastname'), |
|
144
|
|
|
absences_translate('First name'), |
|
145
|
|
|
absences_translate('Right collection'), |
|
146
|
|
|
absences_translate('Organization'), |
|
147
|
|
|
absences_translate('Right description'), |
|
148
|
|
|
absences_translate('Type'), |
|
149
|
|
|
absences_translate('Initial quantity'), |
|
150
|
|
|
absences_translate('Consumed'), |
|
151
|
|
|
absences_translate('Waiting approval'), |
|
152
|
|
|
absences_translate('Balance'), |
|
153
|
|
|
absences_translate('Begin date'), |
|
154
|
|
|
absences_translate('End date'), |
|
155
|
|
|
absences_translate('Accessible') |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
foreach ($this->dirFields as $field) { |
|
159
|
|
|
$row[] = $field; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $row; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return array |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function getRow(absences_Agent $agent, absences_AgentRight $agentRight) |
|
169
|
|
|
{ |
|
170
|
|
|
$collectionName = ''; |
|
171
|
|
|
$collection = $agent->getCollection(); |
|
172
|
|
|
if ($collection->getRow()) { |
|
173
|
|
|
$collectionName = $collection->name; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
$organizationName = ''; |
|
177
|
|
|
$organization = $agent->getOrganization(); |
|
178
|
|
|
if ($organization->getRow()) { |
|
179
|
|
|
$organizationName = $organization->name; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
$right = $agentRight->getRight(); |
|
183
|
|
|
|
|
184
|
|
|
$row = array( |
|
185
|
|
|
$collectionName, |
|
186
|
|
|
$organizationName, |
|
187
|
|
|
$right->description, |
|
188
|
|
|
$right->getType()->name, |
|
189
|
|
|
$agentRight->getQuantity(), |
|
190
|
|
|
$agentRight->getConfirmedQuantity(), |
|
191
|
|
|
$agentRight->getWaitingQuantity(), |
|
192
|
|
|
$agentRight->getBalance(), |
|
193
|
|
|
$this->date($right->date_begin), |
|
194
|
|
|
$this->date($right->date_end) |
|
195
|
|
|
); |
|
196
|
|
|
|
|
197
|
|
|
foreach ($this->dirFields as $field) { |
|
198
|
|
|
$row[] = $this->getAgentDirValue($agent, $field); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
return $row; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* output an array on raw values |
|
208
|
|
|
* @param array $arr |
|
209
|
|
|
* |
|
210
|
|
|
*/ |
|
211
|
|
|
protected function outputArr(Array $arr) |
|
212
|
|
|
{ |
|
213
|
|
|
array_walk($arr, array($this, 'csvEncode')); |
|
214
|
|
|
echo implode($this->separator, $arr); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
public function download() |
|
219
|
|
|
{ |
|
220
|
|
|
$this->setHeaders(absences_translate('rights')); |
|
221
|
|
|
|
|
222
|
|
|
$this->outputArr($this->getHeader()); |
|
223
|
|
|
|
|
224
|
|
|
foreach ($this->selectAgents() as $agent) { |
|
225
|
|
|
foreach ($this->selectAgentRights($agent) as $agentRight) { |
|
226
|
|
|
|
|
227
|
|
|
$this->outputArr($this->getRow($agent, $agentRight)); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
die(); |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
|
|
241
|
|
|
class absences_RightExportTemplate |
|
242
|
|
|
{ |
|
243
|
|
|
public $separatortxt; |
|
244
|
|
|
public $other; |
|
245
|
|
|
public $comma; |
|
246
|
|
|
public $tab; |
|
247
|
|
|
public $semicolon; |
|
248
|
|
|
public $export; |
|
249
|
|
|
public $sepdectxt; |
|
250
|
|
|
public $t_year; |
|
251
|
|
|
public $t_organization; |
|
252
|
|
|
public $additional_fields; |
|
253
|
|
|
|
|
254
|
|
|
public function __construct() |
|
255
|
|
|
{ |
|
256
|
|
|
global $babDB; |
|
257
|
|
|
|
|
258
|
|
|
$this->separatortxt = absences_translate("Separator"); |
|
259
|
|
|
$this->other = absences_translate("Other"); |
|
260
|
|
|
$this->comma = absences_translate("Comma"); |
|
261
|
|
|
$this->tab = absences_translate("Tab"); |
|
262
|
|
|
$this->semicolon = absences_translate("Semicolon"); |
|
263
|
|
|
$this->export = absences_translate("Export"); |
|
264
|
|
|
$this->sepdectxt = absences_translate("Decimal separator"); |
|
265
|
|
|
$this->t_year = absences_translate('Year filter'); |
|
266
|
|
|
$this->t_organization = absences_translate('Organization'); |
|
267
|
|
|
$this->additional_fields = absences_translate("Additional fields to export:"); |
|
268
|
|
|
|
|
269
|
|
|
$W = bab_Widgets(); |
|
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
$this->resYears = $babDB->db_query("SELECT YEAR(date_begin) year FROM absences_rights WHERE YEAR(date_begin)<>'0' GROUP BY year"); |
|
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
$this->resOrganization = $babDB->db_query("SELECT * FROM `absences_organization` ORDER BY name ASC"); |
|
|
|
|
|
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
$this->dirfields = bab_getDirEntry(BAB_REGISTERED_GROUP, BAB_DIR_ENTRY_ID_GROUP); |
|
|
|
|
|
|
277
|
|
|
|
|
278
|
|
|
unset($this->dirfields['sn']); |
|
279
|
|
|
unset($this->dirfields['givenname']); |
|
280
|
|
|
unset($this->dirfields['jpegphoto']); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* template method to list available years |
|
287
|
|
|
*/ |
|
288
|
|
View Code Duplication |
public function getnextyear() |
|
|
|
|
|
|
289
|
|
|
{ |
|
290
|
|
|
global $babDB; |
|
291
|
|
|
|
|
292
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->resYears)) |
|
293
|
|
|
{ |
|
294
|
|
|
$this->year = bab_toHtml($arr['year']); |
|
|
|
|
|
|
295
|
|
|
return true; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
return false; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
|
|
302
|
|
View Code Duplication |
public function getnextfield() |
|
|
|
|
|
|
303
|
|
|
{ |
|
304
|
|
|
if (list($name,$arr) = each($this->dirfields)) |
|
305
|
|
|
{ |
|
306
|
|
|
$this->fieldname = bab_toHtml($name); |
|
|
|
|
|
|
307
|
|
|
$this->fieldlabel = bab_toHtml($arr['name']); |
|
|
|
|
|
|
308
|
|
|
return true; |
|
309
|
|
|
} |
|
310
|
|
|
return false; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
|
|
314
|
|
View Code Duplication |
public function getnextorganization() |
|
|
|
|
|
|
315
|
|
|
{ |
|
316
|
|
|
global $babDB; |
|
317
|
|
|
|
|
318
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->resOrganization)) |
|
319
|
|
|
{ |
|
320
|
|
|
$this->organization = bab_toHtml($arr['name']); |
|
|
|
|
|
|
321
|
|
|
$this->id_organization = bab_toHtml($arr['id']); |
|
|
|
|
|
|
322
|
|
|
return true; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
return false; |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
|
|
330
|
|
|
|
|
331
|
|
|
|
|
332
|
|
|
|
|
333
|
|
|
|
|
334
|
|
|
|
|
335
|
|
|
|
|
336
|
|
|
|
|
337
|
|
|
|
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
function absences_exportForm() |
|
341
|
|
|
{ |
|
342
|
|
|
if (!empty($_POST)) { |
|
343
|
|
|
|
|
344
|
|
|
$export = new absences_RightExportCsv(bab_rp('org'), bab_rp('year'), (array) bab_rp('dirfields')); |
|
345
|
|
|
$export->download(); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
|
|
349
|
|
|
$addon = bab_getAddonInfosInstance('absences'); |
|
350
|
|
|
|
|
351
|
|
|
$template = new absences_RightExportTemplate(); |
|
352
|
|
|
bab_getBody()->babecho($addon->printTemplate($template, 'rightexport.html')); |
|
353
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.