1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2007-2012 Laurent Destailleur <[email protected]> |
3
|
|
|
* Copyright (C) 2014 Juanjo Menent <[email protected]> |
4
|
|
|
* Copyright (C) 2015 Florian Henry <[email protected]> |
5
|
|
|
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]> |
6
|
|
|
* Copyright (C) ---Put here your own copyright and developer email--- |
7
|
|
|
* |
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by |
10
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* \file flightlog/bbcvols.class.php |
24
|
|
|
* \ingroup flightlog |
25
|
|
|
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete) |
26
|
|
|
* Put some comments here |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
// Put here all includes required by your class file |
30
|
|
|
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; |
31
|
|
|
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
|
|
|
32
|
|
|
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class Bbcvols |
36
|
|
|
* |
37
|
|
|
* Put here description of your class |
38
|
|
|
* @see CommonObject |
39
|
|
|
*/ |
40
|
|
|
class Bbcvols extends CommonObject |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var string Id to identify managed objects |
44
|
|
|
*/ |
45
|
|
|
public $element = 'flightlog_bbcvols'; |
46
|
|
|
/** |
47
|
|
|
* @var string Name of table without prefix where object is stored |
48
|
|
|
*/ |
49
|
|
|
public $table_element = 'bbc_vols'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var BbcvolsLine[] Lines |
53
|
|
|
*/ |
54
|
|
|
public $lines = array(); |
55
|
|
|
|
56
|
|
|
public $idBBC_vols; |
57
|
|
|
public $date = ''; |
58
|
|
|
public $lieuD; |
59
|
|
|
public $lieuA; |
60
|
|
|
public $heureD; |
61
|
|
|
public $heureA; |
62
|
|
|
public $BBC_ballons_idBBC_ballons; |
63
|
|
|
public $nbrPax; |
64
|
|
|
public $remarque; |
65
|
|
|
public $incidents; |
66
|
|
|
public $fk_type; |
67
|
|
|
public $fk_pilot; |
68
|
|
|
public $fk_organisateur; |
69
|
|
|
public $is_facture; |
70
|
|
|
public $kilometers; |
71
|
|
|
public $cost; |
72
|
|
|
public $fk_receiver; |
73
|
|
|
public $justif_kilometers; |
74
|
|
|
public $date_creation; |
75
|
|
|
public $date_update; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
|
|
public function getIdBBCVols() |
81
|
|
|
{ |
82
|
|
|
return $this->idBBC_vols; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
|
|
public function getId() |
89
|
|
|
{ |
90
|
|
|
return $this->getIdBBCVols(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string|int $ref |
95
|
|
|
* |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function setRef($ref) |
99
|
|
|
{ |
100
|
|
|
$this->ref = $ref; |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Constructor |
106
|
|
|
* |
107
|
|
|
* @param DoliDb $db Database handler |
108
|
|
|
*/ |
109
|
|
|
public function __construct(DoliDB $db) |
110
|
|
|
{ |
111
|
|
|
$this->db = $db; |
112
|
|
|
$this->cost = 0; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Create object into database |
117
|
|
|
* |
118
|
|
|
* @param User $user User that creates |
119
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
120
|
|
|
* |
121
|
|
|
* @return int <0 if KO, Id of created object if OK |
122
|
|
|
*/ |
123
|
|
|
public function create(User $user, $notrigger = false) |
124
|
|
|
{ |
125
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
126
|
|
|
|
127
|
|
|
$error = 0; |
128
|
|
|
|
129
|
|
|
// Clean parameters |
130
|
|
|
|
131
|
|
|
if (isset($this->idBBC_vols)) { |
132
|
|
|
$this->idBBC_vols = trim($this->idBBC_vols); |
133
|
|
|
} |
134
|
|
|
if (isset($this->lieuD)) { |
135
|
|
|
$this->lieuD = trim($this->lieuD); |
136
|
|
|
} |
137
|
|
|
if (isset($this->lieuA)) { |
138
|
|
|
$this->lieuA = trim($this->lieuA); |
139
|
|
|
} |
140
|
|
|
if (isset($this->heureD)) { |
141
|
|
|
$this->heureD = trim($this->heureD); |
142
|
|
|
} |
143
|
|
|
if (isset($this->heureA)) { |
144
|
|
|
$this->heureA = trim($this->heureA); |
145
|
|
|
} |
146
|
|
|
if (isset($this->BBC_ballons_idBBC_ballons)) { |
147
|
|
|
$this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons); |
148
|
|
|
} |
149
|
|
|
if (isset($this->nbrPax)) { |
150
|
|
|
$this->nbrPax = trim($this->nbrPax); |
151
|
|
|
} |
152
|
|
|
if (isset($this->remarque)) { |
153
|
|
|
$this->remarque = trim($this->remarque); |
154
|
|
|
} |
155
|
|
|
if (isset($this->incidents)) { |
156
|
|
|
$this->incidents = trim($this->incidents); |
157
|
|
|
} |
158
|
|
|
if (isset($this->fk_type)) { |
159
|
|
|
$this->fk_type = trim($this->fk_type); |
160
|
|
|
} |
161
|
|
|
if (isset($this->fk_pilot)) { |
162
|
|
|
$this->fk_pilot = trim($this->fk_pilot); |
163
|
|
|
} |
164
|
|
|
if (isset($this->fk_organisateur)) { |
165
|
|
|
$this->fk_organisateur = trim($this->fk_organisateur); |
166
|
|
|
} |
167
|
|
|
if (isset($this->is_facture)) { |
168
|
|
|
$this->is_facture = trim($this->is_facture); |
169
|
|
|
} |
170
|
|
|
if (isset($this->kilometers)) { |
171
|
|
|
$this->kilometers = trim($this->kilometers); |
172
|
|
|
} |
173
|
|
|
if (isset($this->cost)) { |
174
|
|
|
$this->cost = trim($this->cost); |
175
|
|
|
} |
176
|
|
|
if (isset($this->fk_receiver)) { |
177
|
|
|
$this->fk_receiver = trim($this->fk_receiver); |
178
|
|
|
} |
179
|
|
|
if (isset($this->justif_kilometers)) { |
180
|
|
|
$this->justif_kilometers = trim($this->justif_kilometers); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
// Check parameters |
185
|
|
|
// Put here code to add control on parameters values |
186
|
|
|
|
187
|
|
|
// Insert request |
188
|
|
|
$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; |
189
|
|
|
|
190
|
|
|
$sql .= 'date,'; |
191
|
|
|
$sql .= 'lieuD,'; |
192
|
|
|
$sql .= 'lieuA,'; |
193
|
|
|
$sql .= 'heureD,'; |
194
|
|
|
$sql .= 'heureA,'; |
195
|
|
|
$sql .= 'BBC_ballons_idBBC_ballons,'; |
196
|
|
|
$sql .= 'nbrPax,'; |
197
|
|
|
$sql .= 'remarque,'; |
198
|
|
|
$sql .= 'incidents,'; |
199
|
|
|
$sql .= 'fk_type,'; |
200
|
|
|
$sql .= 'fk_pilot,'; |
201
|
|
|
$sql .= 'fk_organisateur,'; |
202
|
|
|
$sql .= 'is_facture,'; |
203
|
|
|
$sql .= 'kilometers,'; |
204
|
|
|
$sql .= 'cost,'; |
205
|
|
|
$sql .= 'fk_receiver,'; |
206
|
|
|
$sql .= 'justif_kilometers,'; |
207
|
|
|
$sql .= 'date_creation,'; |
208
|
|
|
$sql .= 'date_update'; |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
$sql .= ') VALUES ('; |
212
|
|
|
|
213
|
|
|
$sql .= ' ' . (!isset($this->date) || dol_strlen($this->date) == 0 ? 'NULL' : "'" . $this->db->idate($this->date) . "'") . ','; |
214
|
|
|
$sql .= ' ' . (!isset($this->lieuD) ? 'NULL' : "'" . $this->db->escape($this->lieuD) . "'") . ','; |
215
|
|
|
$sql .= ' ' . (!isset($this->lieuA) ? 'NULL' : "'" . $this->db->escape($this->lieuA) . "'") . ','; |
216
|
|
|
$sql .= ' ' . (!isset($this->heureD) ? 'NULL' : "'" . $this->heureD . "'") . ','; |
217
|
|
|
$sql .= ' ' . (!isset($this->heureA) ? 'NULL' : "'" . $this->heureA . "'") . ','; |
218
|
|
|
$sql .= ' ' . (!isset($this->BBC_ballons_idBBC_ballons) ? 'NULL' : $this->BBC_ballons_idBBC_ballons) . ','; |
219
|
|
|
$sql .= ' ' . (!isset($this->nbrPax) ? 'NULL' : "'" . $this->db->escape($this->nbrPax) . "'") . ','; |
220
|
|
|
$sql .= ' ' . (!isset($this->remarque) ? 'NULL' : "'" . $this->db->escape($this->remarque) . "'") . ','; |
221
|
|
|
$sql .= ' ' . (!isset($this->incidents) ? 'NULL' : "'" . $this->db->escape($this->incidents) . "'") . ','; |
222
|
|
|
$sql .= ' ' . (!isset($this->fk_type) ? 'NULL' : $this->fk_type) . ','; |
223
|
|
|
$sql .= ' ' . (!isset($this->fk_pilot) ? 'NULL' : $this->fk_pilot) . ','; |
224
|
|
|
$sql .= ' ' . (!isset($this->fk_organisateur) ? 'NULL' : $this->fk_organisateur) . ','; |
225
|
|
|
$sql .= ' ' . (!isset($this->is_facture) ? '0' : $this->is_facture) . ','; |
226
|
|
|
$sql .= ' ' . (!isset($this->kilometers) || empty($this->kilometers) ? '0' : $this->kilometers) . ','; |
227
|
|
|
$sql .= ' ' . (!isset($this->cost) ? 'NULL' : "'" . $this->db->escape($this->cost) . "'") . ','; |
228
|
|
|
$sql .= ' ' . (!isset($this->fk_receiver) ? 'NULL' : $this->fk_receiver) . ','; |
229
|
|
|
$sql .= ' ' . (!isset($this->justif_kilometers) ? 'NULL' : "'" . $this->db->escape($this->justif_kilometers) . "'") . ','; |
230
|
|
|
$sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ','; |
231
|
|
|
$sql .= ' ' . "'" . date('Y-m-d H:i:s') . "'" . ''; |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
$sql .= ')'; |
235
|
|
|
|
236
|
|
|
$this->db->begin(); |
237
|
|
|
|
238
|
|
|
$resql = $this->db->query($sql); |
239
|
|
|
if (!$resql) { |
240
|
|
|
$error++; |
241
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
242
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
View Code Duplication |
if (!$error) { |
|
|
|
|
246
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
247
|
|
|
|
248
|
|
|
if (!$notrigger) { |
|
|
|
|
249
|
|
|
// Uncomment this and change MYOBJECT to your own tag if you |
250
|
|
|
// want this action to call a trigger. |
251
|
|
|
|
252
|
|
|
//// Call triggers |
253
|
|
|
//$result=$this->call_trigger('MYOBJECT_CREATE',$user); |
|
|
|
|
254
|
|
|
//if ($result < 0) $error++; |
|
|
|
|
255
|
|
|
//// End call triggers |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
// Commit or rollback |
260
|
|
|
if ($error) { |
261
|
|
|
$this->db->rollback(); |
262
|
|
|
|
263
|
|
|
return -1 * $error; |
264
|
|
|
} else { |
265
|
|
|
$this->db->commit(); |
266
|
|
|
|
267
|
|
|
return $this->id; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Load object in memory from the database |
273
|
|
|
* |
274
|
|
|
* @param int $id Id object |
275
|
|
|
* @param string $ref Ref |
276
|
|
|
* |
277
|
|
|
* @return int <0 if KO, 0 if not found, >0 if OK |
278
|
|
|
*/ |
279
|
|
|
public function fetch($id, $ref = null) |
280
|
|
|
{ |
281
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
282
|
|
|
|
283
|
|
|
$sql = 'SELECT'; |
284
|
|
|
$sql .= " t.idBBC_vols,"; |
285
|
|
|
$sql .= " t.date,"; |
286
|
|
|
$sql .= " t.lieuD,"; |
287
|
|
|
$sql .= " t.lieuA,"; |
288
|
|
|
$sql .= " t.heureD,"; |
289
|
|
|
$sql .= " t.heureA,"; |
290
|
|
|
$sql .= " t.BBC_ballons_idBBC_ballons,"; |
291
|
|
|
$sql .= " t.nbrPax,"; |
292
|
|
|
$sql .= " t.remarque,"; |
293
|
|
|
$sql .= " t.incidents,"; |
294
|
|
|
$sql .= " t.fk_type,"; |
295
|
|
|
$sql .= " t.fk_pilot,"; |
296
|
|
|
$sql .= " t.fk_organisateur,"; |
297
|
|
|
$sql .= " t.is_facture,"; |
298
|
|
|
$sql .= " t.kilometers,"; |
299
|
|
|
$sql .= " t.cost,"; |
300
|
|
|
$sql .= " t.fk_receiver,"; |
301
|
|
|
$sql .= " t.justif_kilometers,"; |
302
|
|
|
$sql .= " t.date_creation,"; |
303
|
|
|
$sql .= " t.date_update"; |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
307
|
|
View Code Duplication |
if (null !== $ref) { |
|
|
|
|
308
|
|
|
$sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; |
309
|
|
|
} else { |
310
|
|
|
$sql .= ' WHERE t.idBBC_vols = ' . $id; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
$resql = $this->db->query($sql); |
314
|
|
|
if ($resql) { |
315
|
|
|
$numrows = $this->db->num_rows($resql); |
316
|
|
|
if ($numrows) { |
317
|
|
|
$obj = $this->db->fetch_object($resql); |
318
|
|
|
|
319
|
|
|
$this->id = $obj->idBBC_vols; |
320
|
|
|
|
321
|
|
|
$this->idBBC_vols = $obj->idBBC_vols; |
322
|
|
|
$this->date = $this->db->jdate($obj->date); |
323
|
|
|
$this->lieuD = $obj->lieuD; |
324
|
|
|
$this->lieuA = $obj->lieuA; |
325
|
|
|
$this->heureD = $obj->heureD; |
326
|
|
|
$this->heureA = $obj->heureA; |
327
|
|
|
$this->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons; |
328
|
|
|
$this->nbrPax = $obj->nbrPax; |
329
|
|
|
$this->remarque = $obj->remarque; |
330
|
|
|
$this->incidents = $obj->incidents; |
331
|
|
|
$this->fk_type = $obj->fk_type; |
332
|
|
|
$this->fk_pilot = $obj->fk_pilot; |
333
|
|
|
$this->fk_organisateur = $obj->fk_organisateur; |
334
|
|
|
$this->is_facture = $obj->is_facture; |
335
|
|
|
$this->kilometers = $obj->kilometers; |
336
|
|
|
$this->cost = $obj->cost; |
337
|
|
|
$this->fk_receiver = $obj->fk_receiver; |
338
|
|
|
$this->justif_kilometers = $obj->justif_kilometers; |
339
|
|
|
$this->date_creation = $obj->date_creation; |
340
|
|
|
$this->date_update = $obj->date_update; |
341
|
|
|
|
342
|
|
|
|
343
|
|
|
} |
344
|
|
|
$this->db->free($resql); |
345
|
|
|
|
346
|
|
|
if ($numrows) { |
347
|
|
|
return 1; |
348
|
|
|
} else { |
349
|
|
|
return 0; |
350
|
|
|
} |
351
|
|
View Code Duplication |
} else { |
|
|
|
|
352
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
353
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
354
|
|
|
|
355
|
|
|
return -1; |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Load object in memory from the database |
361
|
|
|
* |
362
|
|
|
* @param string $sortorder Sort Order |
363
|
|
|
* @param string $sortfield Sort field |
364
|
|
|
* @param int $limit offset limit |
365
|
|
|
* @param int $offset offset limit |
366
|
|
|
* @param array $filter filter array |
367
|
|
|
* @param string $filtermode filter mode (AND or OR) |
368
|
|
|
* |
369
|
|
|
* @return int <0 if KO, >0 if OK |
370
|
|
|
*/ |
371
|
|
|
public function fetchAll( |
372
|
|
|
$sortorder = '', |
373
|
|
|
$sortfield = '', |
374
|
|
|
$limit = 0, |
375
|
|
|
$offset = 0, |
376
|
|
|
array $filter = array(), |
377
|
|
|
$filtermode = 'AND' |
378
|
|
|
) { |
379
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
380
|
|
|
|
381
|
|
|
$sql = 'SELECT'; |
382
|
|
|
$sql .= " t.idBBC_vols,"; |
383
|
|
|
$sql .= " t.date,"; |
384
|
|
|
$sql .= " t.lieuD,"; |
385
|
|
|
$sql .= " t.lieuA,"; |
386
|
|
|
$sql .= " t.heureD,"; |
387
|
|
|
$sql .= " t.heureA,"; |
388
|
|
|
$sql .= " t.BBC_ballons_idBBC_ballons,"; |
389
|
|
|
$sql .= " t.nbrPax,"; |
390
|
|
|
$sql .= " t.remarque,"; |
391
|
|
|
$sql .= " t.incidents,"; |
392
|
|
|
$sql .= " t.fk_type,"; |
393
|
|
|
$sql .= " t.fk_pilot,"; |
394
|
|
|
$sql .= " t.fk_organisateur,"; |
395
|
|
|
$sql .= " t.is_facture,"; |
396
|
|
|
$sql .= " t.kilometers,"; |
397
|
|
|
$sql .= " t.cost,"; |
398
|
|
|
$sql .= " t.fk_receiver,"; |
399
|
|
|
$sql .= " t.justif_kilometers,"; |
400
|
|
|
$sql .= " t.date_creation,"; |
401
|
|
|
$sql .= " t.date_update"; |
402
|
|
|
|
403
|
|
|
|
404
|
|
|
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
405
|
|
|
|
406
|
|
|
// Manage filter |
407
|
|
|
$sqlwhere = array(); |
408
|
|
|
if (count($filter) > 0) { |
409
|
|
|
foreach ($filter as $key => $value) { |
410
|
|
|
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; |
411
|
|
|
} |
412
|
|
|
} |
413
|
|
View Code Duplication |
if (count($sqlwhere) > 0) { |
|
|
|
|
414
|
|
|
$sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
if (!empty($sortfield)) { |
418
|
|
|
$sql .= $this->db->order($sortfield, $sortorder); |
419
|
|
|
} |
420
|
|
|
if (!empty($limit)) { |
421
|
|
|
$sql .= ' ' . $this->db->plimit($limit + 1, $offset); |
422
|
|
|
} |
423
|
|
|
$this->lines = array(); |
424
|
|
|
|
425
|
|
|
$resql = $this->db->query($sql); |
426
|
|
|
if ($resql) { |
427
|
|
|
$num = $this->db->num_rows($resql); |
428
|
|
|
|
429
|
|
|
while ($obj = $this->db->fetch_object($resql)) { |
430
|
|
|
$line = new BbcvolsLine(); |
431
|
|
|
|
432
|
|
|
$line->id = $obj->idBBC_vols; |
433
|
|
|
|
434
|
|
|
$line->idBBC_vols = $obj->idBBC_vols; |
435
|
|
|
$line->date = $this->db->jdate($obj->date); |
436
|
|
|
$line->lieuD = $obj->lieuD; |
437
|
|
|
$line->lieuA = $obj->lieuA; |
438
|
|
|
$line->heureD = $obj->heureD; |
439
|
|
|
$line->heureA = $obj->heureA; |
440
|
|
|
$line->BBC_ballons_idBBC_ballons = $obj->BBC_ballons_idBBC_ballons; |
441
|
|
|
$line->nbrPax = $obj->nbrPax; |
442
|
|
|
$line->remarque = $obj->remarque; |
443
|
|
|
$line->incidents = $obj->incidents; |
444
|
|
|
$line->fk_type = $obj->fk_type; |
445
|
|
|
$line->fk_pilot = $obj->fk_pilot; |
446
|
|
|
$line->fk_organisateur = $obj->fk_organisateur; |
447
|
|
|
$line->is_facture = $obj->is_facture; |
448
|
|
|
$line->kilometers = $obj->kilometers; |
449
|
|
|
$line->cost = $obj->cost; |
450
|
|
|
$line->fk_receiver = $obj->fk_receiver; |
451
|
|
|
$line->justif_kilometers = $obj->justif_kilometers; |
452
|
|
|
$line->date_creation = $obj->date_creation; |
453
|
|
|
$line->date_update = $obj->date_update; |
454
|
|
|
|
455
|
|
|
|
456
|
|
|
$this->lines[$line->id] = $line; |
457
|
|
|
} |
458
|
|
|
$this->db->free($resql); |
459
|
|
|
|
460
|
|
|
return $num; |
461
|
|
View Code Duplication |
} else { |
|
|
|
|
462
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
463
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
464
|
|
|
|
465
|
|
|
return -1; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Update object into database |
471
|
|
|
* |
472
|
|
|
* @param User $user User that modifies |
473
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
474
|
|
|
* |
475
|
|
|
* @return int <0 if KO, >0 if OK |
476
|
|
|
*/ |
477
|
|
|
public function update(User $user, $notrigger = false) |
478
|
|
|
{ |
479
|
|
|
$error = 0; |
480
|
|
|
|
481
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
482
|
|
|
|
483
|
|
|
// Clean parameters |
484
|
|
|
|
485
|
|
|
if (isset($this->idBBC_vols)) { |
486
|
|
|
$this->idBBC_vols = trim($this->idBBC_vols); |
487
|
|
|
} |
488
|
|
|
if (isset($this->lieuD)) { |
489
|
|
|
$this->lieuD = trim($this->lieuD); |
490
|
|
|
} |
491
|
|
|
if (isset($this->lieuA)) { |
492
|
|
|
$this->lieuA = trim($this->lieuA); |
493
|
|
|
} |
494
|
|
|
if (isset($this->heureD)) { |
495
|
|
|
$this->heureD = trim($this->heureD); |
496
|
|
|
} |
497
|
|
|
if (isset($this->heureA)) { |
498
|
|
|
$this->heureA = trim($this->heureA); |
499
|
|
|
} |
500
|
|
|
if (isset($this->BBC_ballons_idBBC_ballons)) { |
501
|
|
|
$this->BBC_ballons_idBBC_ballons = trim($this->BBC_ballons_idBBC_ballons); |
502
|
|
|
} |
503
|
|
|
if (isset($this->nbrPax)) { |
504
|
|
|
$this->nbrPax = trim($this->nbrPax); |
505
|
|
|
} |
506
|
|
|
if (isset($this->remarque)) { |
507
|
|
|
$this->remarque = trim($this->remarque); |
508
|
|
|
} |
509
|
|
|
if (isset($this->incidents)) { |
510
|
|
|
$this->incidents = trim($this->incidents); |
511
|
|
|
} |
512
|
|
|
if (isset($this->fk_type)) { |
513
|
|
|
$this->fk_type = trim($this->fk_type); |
514
|
|
|
} |
515
|
|
|
if (isset($this->fk_pilot)) { |
516
|
|
|
$this->fk_pilot = trim($this->fk_pilot); |
517
|
|
|
} |
518
|
|
|
if (isset($this->fk_organisateur)) { |
519
|
|
|
$this->fk_organisateur = trim($this->fk_organisateur); |
520
|
|
|
} |
521
|
|
|
if (isset($this->is_facture)) { |
522
|
|
|
$this->is_facture = trim($this->is_facture); |
523
|
|
|
} |
524
|
|
|
if (isset($this->kilometers)) { |
525
|
|
|
$this->kilometers = trim($this->kilometers); |
526
|
|
|
} |
527
|
|
|
if (isset($this->cost)) { |
528
|
|
|
$this->cost = trim($this->cost); |
529
|
|
|
} |
530
|
|
|
if (isset($this->fk_receiver)) { |
531
|
|
|
$this->fk_receiver = trim($this->fk_receiver); |
532
|
|
|
} |
533
|
|
|
if (isset($this->justif_kilometers)) { |
534
|
|
|
$this->justif_kilometers = trim($this->justif_kilometers); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
|
538
|
|
|
// Check parameters |
539
|
|
|
// Put here code to add a control on parameters values |
540
|
|
|
|
541
|
|
|
// Update request |
542
|
|
|
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; |
543
|
|
|
|
544
|
|
|
$sql .= ' date = ' . (!isset($this->date) || dol_strlen($this->date) != 0 ? "'" . $this->db->idate($this->date) . "'" : 'null') . ','; |
545
|
|
|
$sql .= ' lieuD = ' . (isset($this->lieuD) ? "'" . $this->db->escape($this->lieuD) . "'" : "null") . ','; |
546
|
|
|
$sql .= ' lieuA = ' . (isset($this->lieuA) ? "'" . $this->db->escape($this->lieuA) . "'" : "null") . ','; |
547
|
|
|
$sql .= ' heureD = ' . (isset($this->heureD) ? "'" . $this->heureD . "'" : "null") . ','; |
548
|
|
|
$sql .= ' heureA = ' . (isset($this->heureA) ? "'" . $this->heureA . "'" : "null") . ','; |
549
|
|
|
$sql .= ' BBC_ballons_idBBC_ballons = ' . (isset($this->BBC_ballons_idBBC_ballons) ? $this->BBC_ballons_idBBC_ballons : "null") . ','; |
550
|
|
|
$sql .= ' nbrPax = ' . (isset($this->nbrPax) ? "'" . $this->db->escape($this->nbrPax) . "'" : "null") . ','; |
551
|
|
|
$sql .= ' remarque = ' . (isset($this->remarque) ? "'" . $this->db->escape($this->remarque) . "'" : "null") . ','; |
552
|
|
|
$sql .= ' incidents = ' . (isset($this->incidents) ? "'" . $this->db->escape($this->incidents) . "'" : "null") . ','; |
553
|
|
|
$sql .= ' fk_type = ' . (isset($this->fk_type) ? $this->fk_type : "null") . ','; |
554
|
|
|
$sql .= ' fk_pilot = ' . (isset($this->fk_pilot) ? $this->fk_pilot : "null") . ','; |
555
|
|
|
$sql .= ' fk_organisateur = ' . (isset($this->fk_organisateur) ? $this->fk_organisateur : "null") . ','; |
556
|
|
|
$sql .= ' is_facture = ' . (isset($this->is_facture) ? $this->is_facture : "0") . ','; |
557
|
|
|
$sql .= ' kilometers = ' . (!empty($this->kilometers) ? $this->kilometers : "0") . ','; |
558
|
|
|
$sql .= ' cost = ' . (isset($this->cost) ? "'" . $this->db->escape($this->cost) . "'" : "''") . ','; |
559
|
|
|
$sql .= ' fk_receiver = ' . (isset($this->fk_receiver) ? $this->fk_receiver : "null") . ','; |
560
|
|
|
$sql .= ' justif_kilometers = ' . (isset($this->justif_kilometers) ? "'" . $this->db->escape($this->justif_kilometers) . "'," : "'',"); |
561
|
|
|
$sql .= ' date_update = ' . "'" . date('Y-m-d H:i:s') . "'"; |
562
|
|
|
|
563
|
|
|
$sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols; |
564
|
|
|
|
565
|
|
|
$this->db->begin(); |
566
|
|
|
|
567
|
|
|
$resql = $this->db->query($sql); |
568
|
|
|
if (!$resql) { |
569
|
|
|
$error++; |
570
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
571
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
if (!$error && !$notrigger) { |
|
|
|
|
575
|
|
|
// Uncomment this and change MYOBJECT to your own tag if you |
576
|
|
|
// want this action calls a trigger. |
577
|
|
|
|
578
|
|
|
//// Call triggers |
579
|
|
|
//$result=$this->call_trigger('MYOBJECT_MODIFY',$user); |
|
|
|
|
580
|
|
|
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
|
|
|
581
|
|
|
//// End call triggers |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
// Commit or rollback |
585
|
|
|
if ($error) { |
586
|
|
|
$this->db->rollback(); |
587
|
|
|
|
588
|
|
|
return -1 * $error; |
589
|
|
|
} else { |
590
|
|
|
$this->db->commit(); |
591
|
|
|
|
592
|
|
|
return 1; |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Delete object in database |
598
|
|
|
* |
599
|
|
|
* @param User $user User that deletes |
600
|
|
|
* @param bool $notrigger false=launch triggers after, true=disable triggers |
601
|
|
|
* |
602
|
|
|
* @return int <0 if KO, >0 if OK |
603
|
|
|
*/ |
604
|
|
View Code Duplication |
public function delete(User $user, $notrigger = false) |
|
|
|
|
605
|
|
|
{ |
606
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
607
|
|
|
|
608
|
|
|
$error = 0; |
609
|
|
|
|
610
|
|
|
$this->db->begin(); |
611
|
|
|
|
612
|
|
|
if (!$error) { |
613
|
|
|
if (!$notrigger) { |
|
|
|
|
614
|
|
|
// Uncomment this and change MYOBJECT to your own tag if you |
615
|
|
|
// want this action calls a trigger. |
616
|
|
|
|
617
|
|
|
//// Call triggers |
618
|
|
|
//$result=$this->call_trigger('MYOBJECT_DELETE',$user); |
|
|
|
|
619
|
|
|
//if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} |
|
|
|
|
620
|
|
|
//// End call triggers |
621
|
|
|
} |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
if (!$error) { |
625
|
|
|
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; |
626
|
|
|
$sql .= ' WHERE idBBC_vols=' . $this->idBBC_vols; |
627
|
|
|
|
628
|
|
|
$resql = $this->db->query($sql); |
629
|
|
|
if (!$resql) { |
630
|
|
|
$error++; |
631
|
|
|
$this->errors[] = 'Error ' . $this->db->lasterror(); |
632
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
633
|
|
|
} |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
// Commit or rollback |
637
|
|
|
if ($error) { |
638
|
|
|
$this->db->rollback(); |
639
|
|
|
|
640
|
|
|
return -1 * $error; |
641
|
|
|
} else { |
642
|
|
|
$this->db->commit(); |
643
|
|
|
|
644
|
|
|
return 1; |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* Load an object from its id and create a new one in database |
650
|
|
|
* |
651
|
|
|
* @param int $fromid Id of object to clone |
652
|
|
|
* |
653
|
|
|
* @return int New id of clone |
654
|
|
|
*/ |
655
|
|
View Code Duplication |
public function createFromClone($fromid) |
|
|
|
|
656
|
|
|
{ |
657
|
|
|
dol_syslog(__METHOD__, LOG_DEBUG); |
658
|
|
|
|
659
|
|
|
global $user; |
660
|
|
|
$error = 0; |
661
|
|
|
$object = new Bbcvols($this->db); |
662
|
|
|
|
663
|
|
|
$this->db->begin(); |
664
|
|
|
|
665
|
|
|
// Load source object |
666
|
|
|
$object->fetch($fromid); |
667
|
|
|
// Reset object |
668
|
|
|
$object->id = 0; |
669
|
|
|
|
670
|
|
|
// Clear fields |
671
|
|
|
// ... |
672
|
|
|
|
673
|
|
|
// Create clone |
674
|
|
|
$result = $object->create($user); |
675
|
|
|
|
676
|
|
|
// Other options |
677
|
|
|
if ($result < 0) { |
678
|
|
|
$error++; |
679
|
|
|
$this->errors = $object->errors; |
680
|
|
|
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
// End |
684
|
|
|
if (!$error) { |
685
|
|
|
$this->db->commit(); |
686
|
|
|
|
687
|
|
|
return $object->id; |
688
|
|
|
} else { |
689
|
|
|
$this->db->rollback(); |
690
|
|
|
|
691
|
|
|
return -1; |
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
|
695
|
|
|
/** |
696
|
|
|
* Return a link to the user card (with optionaly the picto) |
697
|
|
|
* Use this->id,this->lastname, this->firstname |
698
|
|
|
* |
699
|
|
|
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
700
|
|
|
* @param string $option On what the link point to |
701
|
|
|
* @param integer $notooltip 1=Disable tooltip |
702
|
|
|
* @param int $maxlen Max length of visible user name |
703
|
|
|
* @param string $morecss Add more css on link |
704
|
|
|
* |
705
|
|
|
* @return string String with URL |
706
|
|
|
*/ |
707
|
|
|
function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '') |
|
|
|
|
708
|
|
|
{ |
709
|
|
|
global $langs, $conf, $db; |
710
|
|
|
global $dolibarr_main_authentication, $dolibarr_main_demo; |
711
|
|
|
global $menumanager; |
712
|
|
|
|
713
|
|
|
$result = ''; |
714
|
|
|
$companylink = ''; |
|
|
|
|
715
|
|
|
|
716
|
|
|
$label = '<u>' . $langs->trans("MyModule") . '</u>'; |
717
|
|
|
$label .= '<div width="100%">'; |
718
|
|
|
$label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->idBBC_vols . '<br>'; |
719
|
|
|
$label .= '<b>' . $langs->trans('Date') . ':</b> ' . dol_print_date($this->date, '%d-%m-%Y'); |
720
|
|
|
$label .= '</div>'; |
721
|
|
|
|
722
|
|
|
$link = '<a href="' . DOL_URL_ROOT . '/flightlog/card.php?id=' . $this->idBBC_vols . '"'; |
723
|
|
|
$link .= ($notooltip ? '' : ' title="' . dol_escape_htmltag($label, |
724
|
|
|
1) . '" class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"'); |
725
|
|
|
$link .= '>'; |
726
|
|
|
$linkend = '</a>'; |
727
|
|
|
|
728
|
|
View Code Duplication |
if ($withpicto) { |
|
|
|
|
729
|
|
|
$result .= ($link . img_object(($notooltip ? '' : $label), 'label', |
730
|
|
|
($notooltip ? '' : 'class="classfortooltip"')) . $linkend); |
731
|
|
|
if ($withpicto != 2) { |
732
|
|
|
$result .= ' '; |
733
|
|
|
} |
734
|
|
|
} |
735
|
|
|
$result .= $link . $this->idBBC_vols . $linkend; |
736
|
|
|
return $result; |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
/** |
740
|
|
|
* Retourne le libelle du status d'un user (actif, inactif) |
741
|
|
|
* |
742
|
|
|
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
743
|
|
|
* |
744
|
|
|
* @return string Label of status |
745
|
|
|
*/ |
746
|
|
|
function getLibStatut($mode = 0) |
|
|
|
|
747
|
|
|
{ |
748
|
|
|
return $this->LibStatut($this->is_facture, $mode); |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
/** |
752
|
|
|
* Renvoi le libelle d'un status donne |
753
|
|
|
* |
754
|
|
|
* @param int $status Id status |
755
|
|
|
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
756
|
|
|
* |
757
|
|
|
* @return string Label of status |
758
|
|
|
*/ |
759
|
|
View Code Duplication |
private function LibStatut($status, $mode = 0) |
|
|
|
|
760
|
|
|
{ |
761
|
|
|
global $langs; |
762
|
|
|
|
763
|
|
|
if ($mode == 0) { |
764
|
|
|
$prefix = ''; |
|
|
|
|
765
|
|
|
if ($status == 1) { |
766
|
|
|
return $langs->trans('Enabled'); |
767
|
|
|
} |
768
|
|
|
if ($status == 0) { |
769
|
|
|
return $langs->trans('Disabled'); |
770
|
|
|
} |
771
|
|
|
} |
772
|
|
|
if ($mode == 1) { |
773
|
|
|
if ($status == 1) { |
774
|
|
|
return $langs->trans('Enabled'); |
775
|
|
|
} |
776
|
|
|
if ($status == 0) { |
777
|
|
|
return $langs->trans('Disabled'); |
778
|
|
|
} |
779
|
|
|
} |
780
|
|
|
if ($mode == 2) { |
781
|
|
|
if ($status == 1) { |
782
|
|
|
return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled'); |
783
|
|
|
} |
784
|
|
|
if ($status == 0) { |
785
|
|
|
return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled'); |
786
|
|
|
} |
787
|
|
|
} |
788
|
|
|
if ($mode == 3) { |
789
|
|
|
if ($status == 1) { |
790
|
|
|
return img_picto($langs->trans('Enabled'), 'statut4'); |
791
|
|
|
} |
792
|
|
|
if ($status == 0) { |
793
|
|
|
return img_picto($langs->trans('Disabled'), 'statut5'); |
794
|
|
|
} |
795
|
|
|
} |
796
|
|
|
if ($mode == 4) { |
797
|
|
|
if ($status == 1) { |
798
|
|
|
return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled'); |
799
|
|
|
} |
800
|
|
|
if ($status == 0) { |
801
|
|
|
return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled'); |
802
|
|
|
} |
803
|
|
|
} |
804
|
|
|
if ($mode == 5) { |
805
|
|
|
if ($status == 1) { |
806
|
|
|
return $langs->trans('Enabled') . ' ' . img_picto($langs->trans('Enabled'), 'statut4'); |
807
|
|
|
} |
808
|
|
|
if ($status == 0) { |
809
|
|
|
return $langs->trans('Disabled') . ' ' . img_picto($langs->trans('Disabled'), 'statut5'); |
810
|
|
|
} |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
return ""; |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
|
817
|
|
|
/** |
818
|
|
|
* Initialise object with example values |
819
|
|
|
* Id must be 0 if object instance is a specimen |
820
|
|
|
* |
821
|
|
|
* @return void |
822
|
|
|
*/ |
823
|
|
|
public function initAsSpecimen() |
824
|
|
|
{ |
825
|
|
|
$this->id = 0; |
826
|
|
|
|
827
|
|
|
$this->idBBC_vols = ''; |
828
|
|
|
$this->date = ''; |
829
|
|
|
$this->lieuD = ''; |
830
|
|
|
$this->lieuA = ''; |
831
|
|
|
$this->heureD = ''; |
832
|
|
|
$this->heureA = ''; |
833
|
|
|
$this->BBC_ballons_idBBC_ballons = ''; |
834
|
|
|
$this->nbrPax = ''; |
835
|
|
|
$this->remarque = ''; |
836
|
|
|
$this->incidents = ''; |
837
|
|
|
$this->fk_type = ''; |
838
|
|
|
$this->fk_pilot = ''; |
839
|
|
|
$this->fk_organisateur = ''; |
840
|
|
|
$this->is_facture = ''; |
841
|
|
|
$this->kilometers = ''; |
842
|
|
|
$this->cost = ''; |
843
|
|
|
$this->fk_receiver = ''; |
844
|
|
|
$this->justif_kilometers = ''; |
845
|
|
|
|
846
|
|
|
|
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
/** |
850
|
|
|
* @return string |
851
|
|
|
*/ |
852
|
|
|
public function __toString() |
853
|
|
|
{ |
854
|
|
|
return $this->idBBC_vols . " " . $this->lieuD . " " . $this->lieuA; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
/** |
858
|
|
|
* @return string |
859
|
|
|
*/ |
860
|
|
|
public function toString() |
861
|
|
|
{ |
862
|
|
|
return "" . $this; |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
/** |
866
|
|
|
* @return string |
867
|
|
|
*/ |
868
|
|
|
public function getStatus() |
869
|
|
|
{ |
870
|
|
|
return $this->statut; |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
/** |
874
|
|
|
* @return boolean |
875
|
|
|
*/ |
876
|
|
|
public function hasFacture(){ |
877
|
|
|
return count($this->linkedObjectsIds) > 0; |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
} |
881
|
|
|
|
882
|
|
|
/** |
883
|
|
|
* Class BbcvolsLine |
884
|
|
|
*/ |
885
|
|
|
class BbcvolsLine |
886
|
|
|
{ |
887
|
|
|
/** |
888
|
|
|
* @var int ID |
889
|
|
|
*/ |
890
|
|
|
public $id; |
891
|
|
|
/** |
892
|
|
|
* @var mixed Sample line property 1 |
893
|
|
|
*/ |
894
|
|
|
|
895
|
|
|
public $idBBC_vols; |
896
|
|
|
public $date = ''; |
897
|
|
|
public $lieuD; |
898
|
|
|
public $lieuA; |
899
|
|
|
public $heureD; |
900
|
|
|
public $heureA; |
901
|
|
|
public $BBC_ballons_idBBC_ballons; |
902
|
|
|
public $nbrPax; |
903
|
|
|
public $remarque; |
904
|
|
|
public $incidents; |
905
|
|
|
public $fk_type; |
906
|
|
|
public $fk_pilot; |
907
|
|
|
public $fk_organisateur; |
908
|
|
|
public $is_facture; |
909
|
|
|
public $kilometers; |
910
|
|
|
public $cost; |
911
|
|
|
public $fk_receiver; |
912
|
|
|
public $justif_kilometers; |
913
|
|
|
public $date_creation; |
914
|
|
|
public $date_update; |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* @var mixed Sample line property 2 |
918
|
|
|
*/ |
919
|
|
|
|
920
|
|
|
} |
921
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.