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
|
|
|
|
26
|
|
|
|
27
|
|
|
class absences_RightCopyStep1 |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
public $altbg; |
31
|
|
|
|
32
|
|
|
public function __construct() { |
33
|
|
|
$this->t_help = absences_translate("The right theoretical period is used to determine the year"); |
|
|
|
|
34
|
|
|
$this->t_year_from = absences_translate("Year"); |
|
|
|
|
35
|
|
|
$this->t_year_to = absences_translate("Create rights for year"); |
|
|
|
|
36
|
|
|
$this->t_record = absences_translate("Record"); |
|
|
|
|
37
|
|
|
$this->t_report = absences_translate("Create report rights with type"); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->t_right_name = absences_translate("Right name"); |
|
|
|
|
40
|
|
|
$this->t_right_kind = absences_translate("Right kind"); |
|
|
|
|
41
|
|
|
$this-> t_quantity = absences_translate("Quantity"); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$this->t_help = absences_translate("Users will be associated to rights as in the previous period but the specific quantities of users will not be retained. Only the rights configured with a theoretical period can be renewed using this form."); |
44
|
|
|
|
45
|
|
|
global $babDB; |
46
|
|
|
|
47
|
|
|
$this->resyear = $babDB->db_query("SELECT |
|
|
|
|
48
|
|
|
YEAR(date_begin) year |
49
|
|
|
FROM |
50
|
|
|
absences_rights |
51
|
|
|
WHERE |
52
|
|
|
date_begin<>'0000-00-00' |
53
|
|
|
AND kind IN(".$babDB->quote($this->getAllowedKinds()).") |
54
|
|
|
GROUP BY year ORDER BY year DESC"); |
55
|
|
|
|
56
|
|
|
$this->year_to = isset($_POST['year_to']) ? $_POST['year_to'] : ''; |
|
|
|
|
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
protected function getAllowedKinds() |
62
|
|
|
{ |
63
|
|
|
return array( |
64
|
|
|
absences_Right::REGULAR, |
65
|
|
|
absences_Right::CET, |
66
|
|
|
absences_Right::INCREMENT |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function getnextyear() { |
72
|
|
|
global $babDB; |
73
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->resyear)) { |
74
|
|
|
$this->year = bab_toHtml($arr['year']); |
|
|
|
|
75
|
|
|
if (empty($this->year_to)) { |
|
|
|
|
76
|
|
|
$this->year_to = $this->year; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
$this->selected = isset($_POST['year_from']) && $_POST['year_from'] == $arr['year']; |
|
|
|
|
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function year_to() { |
85
|
|
|
$selected_year = isset($_POST['year_from']) ? $_POST['year_from'] : $this->year_to; |
|
|
|
|
86
|
|
|
if (!isset($_POST['year_to'])) { |
87
|
|
|
$this->year_to++; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
global $babDB; |
90
|
|
|
|
91
|
|
|
$this->resrights = $babDB->db_query(" |
|
|
|
|
92
|
|
|
SELECT |
93
|
|
|
r.* |
94
|
|
|
FROM |
95
|
|
|
".ABSENCES_RIGHTS_TBL." r |
96
|
|
|
WHERE |
97
|
|
|
YEAR(r.date_begin) = ".$babDB->quote($selected_year)." |
98
|
|
|
AND r.kind IN(".$babDB->quote($this->getAllowedKinds()).") |
99
|
|
|
|
100
|
|
|
GROUP BY r.id |
101
|
|
|
ORDER BY r.sortkey, r.description |
102
|
|
|
"); |
103
|
|
|
|
104
|
|
|
return false; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getnextright() { |
108
|
|
|
global $babDB; |
109
|
|
|
if ($arr = $babDB->db_fetch_assoc($this->resrights)) { |
110
|
|
|
|
111
|
|
|
$this->altbg = !$this->altbg; |
112
|
|
|
|
113
|
|
|
$right = new absences_Right($arr['id']); |
114
|
|
|
$right->setRow($arr); |
115
|
|
|
|
116
|
|
|
$this->right_description = bab_toHtml($right->description); |
|
|
|
|
117
|
|
|
$this->right_kind = bab_toHtml($right->getKindLabel()); |
|
|
|
|
118
|
|
|
$this->id_right = bab_toHtml($right->id); |
|
|
|
|
119
|
|
|
$this->quantity = bab_toHtml(absences_editQuantity($right->quantity, $right->quantity_unit)); |
|
|
|
|
120
|
|
|
$this->right_unit = bab_toHtml($right->getUnitLabel()); |
|
|
|
|
121
|
|
|
$this->checked = (isset($_POST['rights']) && isset($_POST['rights'][$arr['id']])) || empty($_POST); |
|
|
|
|
122
|
|
|
return true; |
123
|
|
|
} |
124
|
|
|
return false; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
|
132
|
|
|
class absences_RightCopyStep2 { |
133
|
|
|
|
134
|
|
|
var $messages = array(); |
135
|
|
|
|
136
|
|
|
public function __construct() { |
137
|
|
|
|
138
|
|
|
include_once $GLOBALS['babInstallPath']."utilit/dateTime.php"; |
139
|
|
|
|
140
|
|
|
global $babDB; |
141
|
|
|
$this->increment = ((int) $_POST['year_to']) - ((int) $_POST['year_from']); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$this->nb_right_insert = 0; |
|
|
|
|
144
|
|
|
|
145
|
|
|
|
146
|
|
|
$renewal_uid = date('YmdHis').'-'.$_POST['year_from'].'-'.$_POST['year_to']; |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
// create rights |
150
|
|
|
|
151
|
|
|
if (isset($_POST['rights'])) { |
152
|
|
|
|
153
|
|
|
foreach($_POST['rights'] as $arr) { |
154
|
|
|
|
155
|
|
|
if (!isset($arr['checked'])) { |
156
|
|
|
continue; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$row = $this->get_row($arr['id']); |
160
|
|
|
$row['quantity'] = str_replace(',', '.', $arr['quantity']); |
161
|
|
|
$row['quantity'] = str_replace(' ', '', $row['quantity']); |
162
|
|
|
if (true === $this->transform_row($row)) { |
163
|
|
|
|
164
|
|
|
$row['renewal_uid'] = $renewal_uid; |
165
|
|
|
$this->insert_row($row); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
$this->addMessage( sprintf( absences_translate("%d rights has been inserted"), $this->nb_right_insert) ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
private function addMessage($str) { |
176
|
|
|
$this->messages[] = $str; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function getnextmessage() { |
180
|
|
|
return list(,$this->message) = each($this->messages); |
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
private function get_row($id_right) { |
185
|
|
|
global $babDB; |
186
|
|
|
$res = $babDB->db_query("SELECT * FROM ".ABSENCES_RIGHTS_TBL." WHERE id=".$babDB->quote($id_right)); |
187
|
|
|
return $babDB->db_fetch_assoc($res); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
private function increment_ISO($date) { |
192
|
|
|
if ('0000-00-00' === $date) { |
193
|
|
|
return $date; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
if ('0000-00-00 00:00:00' === $date) { |
197
|
|
|
return $date; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
$obj = BAB_DateTime::fromIsoDateTime($date); |
201
|
|
|
$obj->add($this->increment,BAB_DATETIME_YEAR); |
202
|
|
|
|
203
|
|
|
if (10 == mb_strlen($date)) { |
204
|
|
|
return $obj->getIsoDate(); |
205
|
|
|
} else { |
206
|
|
|
return $obj->getIsoDateTime(); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
public function transform_row(&$row) { |
212
|
|
|
|
213
|
|
|
global $babDB; |
214
|
|
|
|
215
|
|
|
$row['id_creditor'] = $GLOBALS['BAB_SESS_USERID']; |
216
|
|
|
|
217
|
|
|
$row['createdOn'] = date('Y-m-d H:i:s'); |
218
|
|
|
$row['date_entry'] = date('Y-m-d H:i:s'); |
219
|
|
|
$row['date_begin'] = $this->increment_ISO($row['date_begin']); |
220
|
|
|
$row['date_end'] = $this->increment_ISO($row['date_end']); |
221
|
|
|
$row['date_begin_valid'] = $this->increment_ISO($row['date_begin_valid']); |
222
|
|
|
$row['date_end_valid'] = $this->increment_ISO($row['date_end_valid']); |
223
|
|
|
$row['date_end_fixed'] = $this->increment_ISO($row['date_end_fixed']); |
224
|
|
|
$row['date_begin_fixed'] = $this->increment_ISO($row['date_begin_fixed']); |
225
|
|
|
|
226
|
|
|
$row['date_end_report'] = $this->increment_ISO($row['date_end_report']); |
227
|
|
|
$row['quantity_alert_begin']= $this->increment_ISO($row['quantity_alert_begin']); |
228
|
|
|
$row['quantity_alert_end'] = $this->increment_ISO($row['quantity_alert_end']); |
229
|
|
|
|
230
|
|
|
$row['dynconf_begin'] = $this->increment_ISO($row['dynconf_begin']); |
231
|
|
|
$row['dynconf_end'] = $this->increment_ISO($row['dynconf_end']); |
232
|
|
|
|
233
|
|
|
$row['description'] = preg_replace_callback("/\d{4}/", |
234
|
|
|
create_function( |
235
|
|
|
'$matches', |
236
|
|
|
'return $matches[0] + '.$this->increment.';' |
237
|
|
|
), |
238
|
|
|
$row['description'] |
239
|
|
|
); |
240
|
|
|
|
241
|
|
|
$row['renewal_parent'] = $row['id']; |
242
|
|
|
|
243
|
|
|
|
244
|
|
|
|
245
|
|
|
$res = $babDB->db_query(" |
246
|
|
|
SELECT COUNT(*) FROM ".ABSENCES_RIGHTS_TBL." |
247
|
|
|
WHERE |
248
|
|
|
description=".$babDB->quote($row['description'])." |
249
|
|
|
AND date_begin=".$babDB->quote($row['date_begin'])." |
250
|
|
|
AND date_end=".$babDB->quote($row['date_end'])." |
251
|
|
|
"); |
252
|
|
|
|
253
|
|
|
list($n) = $babDB->db_fetch_array($res); |
254
|
|
|
|
255
|
|
|
if ($n > 0) { |
256
|
|
|
$this->addMessage(sprintf(absences_translate("The right %s already exists"), $row['description'])); |
257
|
|
|
return false; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
return true; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
|
265
|
|
|
private function insert_row($row) { |
266
|
|
|
|
267
|
|
|
global $babDB; |
268
|
|
|
|
269
|
|
|
$old_id_right = $row['id']; |
270
|
|
|
|
271
|
|
|
unset($row['id']); |
272
|
|
|
|
273
|
|
|
foreach($row as $key => $value) { |
274
|
|
|
$row[$key] = $babDB->db_escape_string($value); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_RIGHTS_TBL." (".implode(',',array_keys($row)).") VALUES (".$babDB->quote($row).")"); |
278
|
|
|
|
279
|
|
|
$this->nb_right_insert++; |
280
|
|
|
|
281
|
|
|
$new_id_right = $babDB->db_insert_id(); |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
$res = $babDB->db_query("SELECT * FROM ".ABSENCES_RIGHTS_RULES_TBL." WHERE id_right=".$babDB->quote($old_id_right)); |
285
|
|
|
if ($rule = $babDB->db_fetch_assoc($res)) { |
286
|
|
|
unset($rule['id']); |
287
|
|
|
$rule['id_right'] = $new_id_right; |
288
|
|
|
|
289
|
|
|
$rule['trigger_p1_begin'] = $this->increment_ISO($rule['trigger_p1_begin']); |
290
|
|
|
$rule['trigger_p1_end'] = $this->increment_ISO($rule['trigger_p1_end']); |
291
|
|
|
|
292
|
|
|
$rule['trigger_p2_begin'] = $this->increment_ISO($rule['trigger_p2_begin']); |
293
|
|
|
$rule['trigger_p2_end'] = $this->increment_ISO($rule['trigger_p2_end']); |
294
|
|
|
|
295
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_RIGHTS_RULES_TBL." (".implode(',',array_keys($rule)).") VALUES (".$babDB->quote($rule).")"); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
$res = $babDB->db_query("SELECT * FROM ".ABSENCES_RIGHTS_INPERIOD_TBL." WHERE id_right=".$babDB->quote($old_id_right)); |
300
|
|
|
if ($inperiod = $babDB->db_fetch_assoc($res)) { |
301
|
|
|
unset($inperiod['id']); |
302
|
|
|
$inperiod['id_right'] = $new_id_right; |
303
|
|
|
|
304
|
|
|
$inperiod['period_start'] = $this->increment_ISO($inperiod['period_start']); |
305
|
|
|
$inperiod['period_end'] = $this->increment_ISO($inperiod['period_end']); |
306
|
|
|
|
307
|
|
|
$babDB->db_query("INSERT INTO ".ABSENCES_RIGHTS_INPERIOD_TBL." (".implode(',',array_keys($inperiod)).") VALUES (".$babDB->quote($inperiod).")"); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
|
312
|
|
|
|
313
|
|
|
$res = $babDB->db_query("SELECT * FROM absences_dynamic_configuration WHERE id_right=".$babDB->quote($old_id_right)); |
314
|
|
View Code Duplication |
while ($arr = $babDB->db_fetch_assoc($res)) |
|
|
|
|
315
|
|
|
{ |
316
|
|
|
$babDB->db_query('INSERT INTO absences_dynamic_configuration (id_right, test_quantity, quantity) |
317
|
|
|
VALUES ('.$babDB->quote($new_id_right).', '.$babDB->quote($arr['test_quantity']).', '.$babDB->quote($arr['quantity']).')'); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
// recopier les liens droit-regime |
322
|
|
|
|
323
|
|
|
$res = $babDB->db_query('SELECT * FROM absences_coll_rights WHERE id_right='.$babDB->quote($old_id_right)); |
324
|
|
View Code Duplication |
while ($arr = $babDB->db_fetch_assoc($res)) |
|
|
|
|
325
|
|
|
{ |
326
|
|
|
$babDB->db_query('INSERT INTO absences_coll_rights (id_coll, id_right) VALUES ('.$babDB->quote($arr['id_coll']).', '.$babDB->quote($new_id_right).')'); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
|
330
|
|
|
|
331
|
|
|
// recopier les liens droit-utilisateur |
332
|
|
|
|
333
|
|
|
$res = $babDB->db_query("SELECT |
334
|
|
|
t2.* |
335
|
|
|
FROM |
336
|
|
|
absences_users_rights t2 |
337
|
|
|
WHERE t2.id_right=".$babDB->quote($old_id_right)." AND renewal='1'"); |
338
|
|
|
|
339
|
|
|
while ($arr = $babDB->db_fetch_assoc($res)) { |
340
|
|
|
$babDB->db_query("INSERT INTO absences_users_rights ( |
341
|
|
|
id_user, |
342
|
|
|
id_right, |
343
|
|
|
date_begin_valid, |
344
|
|
|
date_end_valid, |
345
|
|
|
inperiod_start, |
346
|
|
|
inperiod_end, |
347
|
|
|
validoverlap, |
348
|
|
|
saving_begin, |
349
|
|
|
saving_end |
350
|
|
|
) VALUES ( |
351
|
|
|
".$babDB->quote($arr['id_user']).", |
352
|
|
|
".$babDB->quote($new_id_right).", |
353
|
|
|
".$babDB->quote($this->increment_ISO($arr['date_begin_valid'])).", |
354
|
|
|
".$babDB->quote($this->increment_ISO($arr['date_begin_valid'])).", |
355
|
|
|
".$babDB->quote($this->increment_ISO($arr['inperiod_start'])).", |
356
|
|
|
".$babDB->quote($this->increment_ISO($arr['inperiod_end'])).", |
357
|
|
|
".$babDB->quote($arr['validoverlap']).", |
358
|
|
|
".$babDB->quote($this->increment_ISO($arr['saving_begin'])).", |
359
|
|
|
".$babDB->quote($this->increment_ISO($arr['saving_end']))." |
360
|
|
|
)"); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
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: