objet.inc.php 18.7 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

/* Copyright 2006
 * - Julien Etelain < julien at pmad dot net >
 *
 * Ce fichier fait partie du site de l'Association des Étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

/**
 * @file
 * Gestion de l'inventaire
 */
29

Ayolo's avatar
Ayolo committed
30
31
/**
 * Type d'objet
32
 * @ingroup inventaire
Ayolo's avatar
Ayolo committed
33
34
35
36
37
38
39
40
41
42
43
 */
class objtype extends stdentity
{
	var $nom;
	var $prix;
	var $caution;
	var $prix_emprunt;
	var $code;
	var $empruntable;
	var $notes;

44

Ayolo's avatar
Ayolo committed
45
46
47
48
49
50
51
52
	/** Charge un type d'objet en fonction de son id
	 * $this->id est égal à -1 en cas d'erreur
	 * @param $id id de la fonction
	 */
	function load_by_id ( $id )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_type_objets`
				WHERE `id_objtype` = '" . mysql_real_escape_string($id) . "'
53
54
				LIMIT 1");

Ayolo's avatar
Ayolo committed
55
56
57
58
59
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
60
61

		$this->id = null;
Ayolo's avatar
Ayolo committed
62
63
		return false;
	}
64

Ayolo's avatar
Ayolo committed
65
66
67
68
	function load_by_code ( $code )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_type_objets`
				WHERE `code_objtype` = '" . mysql_real_escape_string($code) . "'
69
70
				LIMIT 1");

Ayolo's avatar
Ayolo committed
71
72
73
74
75
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
76
77

		$this->id = null;
Ayolo's avatar
Ayolo committed
78
79
80
		return false;
	}

81
82


Ayolo's avatar
Ayolo committed
83
84
85
86
87
88
89
90
91
92
93
	function _load ( $row )
	{
		$this->id			= $row['id_objtype'];
		$this->nom			= $row['nom_objtype'];
		$this->prix			= $row['prix_objtype'];
		$this->caution		= $row['caution_objtype'];
		$this->prix_emprunt	= $row['prix_emprunt_objtype'];
		$this->code			= $row['code_objtype'];
		$this->empruntable	= $row['empruntable_objtype'];
		$this->notes			= $row['notes_objtype'];
	}
94

Ayolo's avatar
Ayolo committed
95
96
97
98
99
100
101
102
	function add ( $nom, $prix, $caution, $prix_emprunt, $code, $empruntable, $notes )
	{
		$this->nom = $nom;
		$this->prix = $prix;
		$this->caution = $caution;
		$this->prix_emprunt = $prix_emprunt;
		$this->code = $code;
		$this->empruntable = $empruntable;
103
104
		$this->notes = $notes;

Ayolo's avatar
Ayolo committed
105
106
107
108
109
110
111
112
113
114
115
116
		$sql = new insert ($this->dbrw,
			"inv_type_objets",
			array(
				"nom_objtype" => $this->nom,
				"prix_objtype" => $this->prix,
				"caution_objtype" => $this->caution,
				"prix_emprunt_objtype" => $this->prix_emprunt,
				"code_objtype" => $this->code,
				"empruntable_objtype" => $this->empruntable,
				"notes_objtype" => $this->notes
				)
			);
117

Ayolo's avatar
Ayolo committed
118
119
120
121
122
123
		if ( $sql )
			$this->id = $sql->get_id();
		else
			$this->id = null;

	}
124

Ayolo's avatar
Ayolo committed
125
126
127
128
129
130
131
132
	function save ( $nom, $prix, $caution, $prix_emprunt, $code, $empruntable, $notes )
	{
		$this->nom = $nom;
		$this->prix = $prix;
		$this->caution = $caution;
		$this->prix_emprunt = $prix_emprunt;
		$this->code = $code;
		$this->empruntable = $empruntable;
133
134
		$this->notes = $notes;

Ayolo's avatar
Ayolo committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		$sql = new update ($this->dbrw,
			"inv_type_objets",
			array(
				"nom_objtype" => $this->nom,
				"prix_objtype" => $this->prix,
				"caution_objtype" => $this->caution,
				"prix_emprunt_objtype" => $this->prix_emprunt,
				"code_objtype" => $this->code,
				"empruntable_objtype" => $this->empruntable,
				"notes_objtype" => $this->notes
				),
			array(
				"id_objtype" => $this->id
				)
			);
	}
151

Ayolo's avatar
Ayolo committed
152
153
154
155
156
157
158
159
160
}


define("OEVENT_ABIME",1);
define("OEVENT_NONUTILISABLE",2);
define("OEVENT_SORTIE_INVENTAIRE",4);
define("OEVENT_VOLE",4);
/**
 * Objet dans l'inventaire
161
 * @ingroup inventaire
Ayolo's avatar
Ayolo committed
162
163
164
 */
class objet extends stdentity
{
165

Ayolo's avatar
Ayolo committed
166
167
168
169
170
	var $id_asso;
	var $id_asso_prop;
	var $id_salle;
	var $id_objtype;
	var $id_op;
171

Ayolo's avatar
Ayolo committed
172
173
174
175
176
177
178
179
180
181
182
183
184
	var $nom;
	var $num;
	var $cbar;
	var $num_serie;
	var $date_achat;
	var $prix;
	var $caution;
	var $prix_emprunt;
	var $empruntable;
	var $en_etat;
	var $archive;
	var $notes;

185
186
  var $_is_book;
  var $_is_jeu;
187

Ayolo's avatar
Ayolo committed
188
189
190
191
192
193
194
195
	/** Charge un objet en fonction de son id
	 * $this->id est égal à -1 en cas d'erreur
	 * @param $id id de la fonction
	 */
	function load_by_id ( $id )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_objet`
				WHERE `id_objet` = '" . mysql_real_escape_string($id) . "'
196
197
				LIMIT 1");

Ayolo's avatar
Ayolo committed
198
199
200
201
202
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
203
204

		$this->id = null;
Ayolo's avatar
Ayolo committed
205
206
		return false;
	}
207

Ayolo's avatar
Ayolo committed
208
209
210
211
	function load_by_cbar ( $cbar )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_objet`
				WHERE `cbar_objet` = '" . mysql_real_escape_string($cbar) . "'
212
213
				LIMIT 1");

Ayolo's avatar
Ayolo committed
214
215
216
217
218
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
219
220

		$this->id = null;
Ayolo's avatar
Ayolo committed
221
222
		return false;
	}
223

Ayolo's avatar
Ayolo committed
224
225
226
	function load_by_num ( $id_objtype, $num )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_objet`
227
				WHERE `id_objtype` = '" . mysql_real_escape_string($id_objtype) . "'
Ayolo's avatar
Ayolo committed
228
				AND `num_objet` = '" . mysql_real_escape_string($num) . "'
229
230
				LIMIT 1");

Ayolo's avatar
Ayolo committed
231
232
233
234
235
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
236
237

		$this->id = null;
Ayolo's avatar
Ayolo committed
238
239
		return false;
	}
240

Ayolo's avatar
Ayolo committed
241
242
243
244
245
246
247
  function get_display_name()
  {
		if ( $this->nom )
			return $this->nom." (".$this->num.")";
		else
			return $this->num;
  }
248

Ayolo's avatar
Ayolo committed
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
	function _load ( $row )
	{
		$this->id			= $row['id_objet'];
		$this->id_asso		= $row['id_asso'];
		$this->id_asso_prop	= $row['id_asso_prop'];
		$this->id_salle		= $row['id_salle'];
		$this->id_objtype	= $row['id_objtype'];
		$this->id_op			= $row['id_op'];
		$this->nom			= $row['nom_objet'];
		$this->num			= $row['num_objet'];
		$this->cbar			= $row['cbar_objet'];
		$this->num_serie		= $row['num_serie'];
		$this->prix			= $row['prix_objet'];
		$this->caution		= $row['caution_objet'];
		$this->prix_emprunt	= $row['prix_emprunt_objet'];
		$this->empruntable	= $row['objet_empruntable'];
		$this->en_etat		= $row['en_etat'];
		$this->archive		= $row['archive_objet'];
		$this->notes			= $row['notes_objet'];
		$this->date_achat	= strtotime($row['date_achat']);
	}
270

271
272
273
274
  function _determine_special()
  {
    if ( !$this->is_valid() )
      return;
275

276
277
278
279
    if ( !isset($this->_is_book) )
    {
		  $req = new requete($this->db, "SELECT id_objet FROM `bk_book`
				WHERE `id_objet` = '" . mysql_real_escape_string($this->id) . "'
280
281
				LIMIT 1");

282
      $this->_is_book = $req->lines == 1;
283

284
285
		  $req = new requete($this->db, "SELECT id_objet FROM `inv_jeu`
				WHERE `id_objet` = '" . mysql_real_escape_string($this->id) . "'
286
287
				LIMIT 1");

288
289
      $this->_is_jeu = $req->lines == 1;
    }
290
291

  }
292

Feu's avatar
Feu committed
293
294
295
296
  /**
   * Determine si par ailleurs cet objet est un livre
   * @see livre
   */
297
  function is_book()
298
299
300
301
  {
    $this->_determine_special();
    return $this->_is_book;
  }
302

Feu's avatar
Feu committed
303
304
305
306
  /**
   * Determine si par ailleurs cet objet est un jeu
   * @see jeu
   */
307
  function is_jeu()
308
309
310
311
  {
    $this->_determine_special();
    return $this->_is_jeu;
  }
312

Ayolo's avatar
Ayolo committed
313
314
315
316
	function add ( $id_asso, $id_asso_prop, $id_salle, $id_objtype, $id_op, $nom,
				$code_objtype, $num_serie, $prix, $caution, $prix_emprunt, $empruntable,
				$en_etat, $date_achat, $notes )
	{
317

Ayolo's avatar
Ayolo committed
318
319
		$sql = new requete ( $this->db, "SELECT MAX(`num_objet`) FROM `inv_objet` " .
				"WHERE `id_objtype`='".intval($id_objtype)."'" );
320

Ayolo's avatar
Ayolo committed
321
322
323
324
325
		if ( $sql->lines == 1 )
			list($pnum) = $sql->get_row();
		else
			$pnum = 0;

326
327
		$this->num = $pnum + 1;

Ayolo's avatar
Ayolo committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
		$this->id_asso		= $id_asso;
		$this->id_asso_prop	= $id_asso_prop;
		$this->id_salle		= $id_salle;
		$this->id_objtype	= $id_objtype;
		$this->id_op			= $id_op;
		$this->nom			= $nom;
		$this->cbar			= sprintf("%s%04d",$code_objtype,$this->num);
		$this->num_serie		= $num_serie;
		$this->prix			= $prix;
		$this->caution		= $caution;
		$this->prix_emprunt	= $prix_emprunt;
		$this->empruntable	= $empruntable;
		$this->en_etat		= $en_etat;
		$this->archive		= false;
		$this->notes			= $notes;
		$this->date_achat	= $date_achat;
344

Ayolo's avatar
Ayolo committed
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
		$sql = new insert ($this->dbrw,
			"inv_objet",
			array(
				"id_asso" => $this->id_asso,
				"id_asso_prop" => $this->id_asso_prop,
				"id_salle" => $this->id_salle,
				"id_objtype" => $this->id_objtype,
				"id_op" => $this->id_op,
				"nom_objet" => $this->nom,
				"num_objet" => $this->num,
				"cbar_objet" => $this->cbar,
				"num_serie" => $this->num_serie,
				"prix_objet" => $this->prix,
				"caution_objet" => $this->caution,
				"prix_emprunt_objet" => $this->prix_emprunt,
				"objet_empruntable" => $this->empruntable==true,
				"en_etat" => $this->en_etat==true,
				"archive_objet"=>$this->archive,
				"date_achat"=> date("Y-m-d",$this->date_achat),
				"notes_objet" => $this->notes
				)
			);
367

Ayolo's avatar
Ayolo committed
368
369
370
371
372
373
		if ( $sql )
			$this->id = $sql->get_id();
		else
			$this->id = null;

	}
374

Ayolo's avatar
Ayolo committed
375
376
377
378
	function save_objet ( $id_asso, $id_asso_prop, $id_salle, $id_objtype, $id_op, $nom,
				$num_serie, $prix, $caution, $prix_emprunt, $empruntable,
				$en_etat, $date_achat, $notes,$cbar )
	{
379

Ayolo's avatar
Ayolo committed
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
		$this->id_asso		= $id_asso;
		$this->id_asso_prop	= $id_asso_prop;
		$this->id_salle		= $id_salle;
		$this->id_objtype	= $id_objtype;
		$this->id_op			= $id_op;
		$this->nom			= $nom;
		$this->cbar			= $cbar;
		$this->num_serie		= $num_serie;
		$this->prix			= $prix;
		$this->caution		= $caution;
		$this->prix_emprunt	= $prix_emprunt;
		$this->empruntable	= $empruntable;
		$this->en_etat		= $en_etat;
		$this->notes			= $notes;
		$this->date_achat	= $date_achat;
395

Ayolo's avatar
Ayolo committed
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
		$sql = new update ($this->dbrw,
			"inv_objet",
			array(
				"id_asso" => $this->id_asso,
				"id_asso_prop" => $this->id_asso_prop,
				"id_salle" => $this->id_salle,
				"id_objtype" => $this->id_objtype,
				"id_op" => $this->id_op,
				"nom_objet" => $this->nom,
				"num_objet" => $this->num,
				"cbar_objet" => $this->cbar,
				"num_serie" => $this->num_serie,
				"prix_objet" => $this->prix,
				"caution_objet" => $this->caution,
				"prix_emprunt_objet" => $this->prix_emprunt,
				"objet_empruntable" => $this->empruntable==true,
				"en_etat" => $this->en_etat==true,
				"archive_objet"=>$this->archive,
				"date_achat"=> date("Y-m-d",$this->date_achat),
				"notes_objet" => $this->notes
				),
			array ("id_objet"=>$this->id)
			);

420
421
422
	}


Ayolo's avatar
Ayolo committed
423
424
425
426
427
428
429
430
431
432
	function set_cbar ( $cbar)
	{
		$this->cbar			= $cbar;
		$sql = new update ($this->dbrw,
			"inv_objet",
			array(
				"cbar_objet" => $this->cbar
				),
			array ("id_objet"=>$this->id)
			);
433

Ayolo's avatar
Ayolo committed
434
	}
435
436


Ayolo's avatar
Ayolo committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
	function event ( $id_emprunt, $id_utilisateur, $type, $date, $notes )
	{
		$sql = new insert ($this->dbrw,
			"inv_objet_evenement",
			array(
				"id_objet" => $this->id,
				"id_emprunt" => $id_emprunt,
				"id_utilisateur" => $id_utilisateur,
				"type_objeven" => $type,
				"date_even" => date("Y-m-d H:i",$date),
				"notes_even" => $notes
				)
			);
	}
451

Ayolo's avatar
Ayolo committed
452
453
	function is_avaible ( $from, $to )
	{
454
455


Ayolo's avatar
Ayolo committed
456
457
458
459
460
461
		$req = new requete($this->db,"SELECT * FROM inv_emprunt_objet ".
			"INNER JOIN inv_emprunt ON inv_emprunt.id_emprunt=inv_emprunt_objet.id_emprunt ".
			"WHERE ".
			"(( inv_emprunt.date_debut_emp < '".date("Y-m-d H:i:s",$to)."' ) AND ".
			"( inv_emprunt.date_fin_emp > '".date("Y-m-d H:i:s",$from)."') ) ".
			"AND inv_emprunt_objet.id_objet=".$this->id." ".
462
463
			"AND inv_emprunt_objet.retour_effectif_emp IS NULL");

Ayolo's avatar
Ayolo committed
464
465
		return ($req->lines==0);
	}	//!(date_debut_emp > $to || (r).date_fin_emp < $from)
466

Ayolo's avatar
Ayolo committed
467
468
469
470
471
472
	/**
	 * Supprime l'objet de l'inventaire, à utiliser en cas d'erreur de saisie ou autre.
	 * En aucun cas à utiliser pour un objet manquant ou détruit : das ce cas il faut l'archiver.
	 */
	function delete_objet()
	{
473
474
		new delete($this->dbrw,"inv_objet",array("id_objet" => $this->id));
		new delete($this->dbrw,"inv_objet_evenement",array("id_objet" => $this->id));
475

476
477
478
479
		// Nettoyage des extentions
		new delete($this->dbrw,"inv_jeu",array("id_objet" => $this->id));
		new delete($this->dbrw,"bk_book",array("id_objet" => $this->id));
		new delete($this->dbrw,"bk_livre_auteur",array("id_objet" => $this->id));
480

Ayolo's avatar
Ayolo committed
481
482
		$this->id=null;
	}
483

Ayolo's avatar
Ayolo committed
484
485
486
487
488
489
490
491
492
	/**
	 * Marque l'etat d'archive ou non de l'objet
	 * @param $archive Etat d'archivage (true=archivé, false=actif)
	 */
	function set_archive($archive=true)
	{
		$this->archive=$archive;
		$req = new update($this->dbrw,"inv_objet",array("archive_objet"=>$this->archive),array("id_objet" => $this->id));
	}
493

Ayolo's avatar
Ayolo committed
494
495
496
497
}

/**
 * @defgroup empruntmod Etats d'un pret/une reservation de matériel
498
 * @ingroup inventaire
Ayolo's avatar
Ayolo committed
499
 * @{
500
 */
Ayolo's avatar
Ayolo committed
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
define("EMPRUNT_RESERVATION",0);
define("EMPRUNT_MODERE",1);
define("EMPRUNT_PRIS",2);
define("EMPRUNT_RETOURPARTIEL",3);
define("EMPRUNT_RETOUR",4);

$EmpruntObjetEtats = array (
EMPRUNT_RESERVATION => "En attente de modération",
EMPRUNT_MODERE => "Réservé",
EMPRUNT_PRIS => "Pris",
EMPRUNT_RETOURPARTIEL => "Retourné en partie",
EMPRUNT_RETOUR => "Retourné"
);

/**
 * @}
 */

/**
 * Reservation de matériel / Pret de matériel
521
 * @ingroup inventaire
Ayolo's avatar
Ayolo committed
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
 */
class emprunt extends stdentity /*inv_emprunt*/
{
	var $id_utilisateur;
	var $id_asso;
	var $id_utilisateur_op;
	var $date_demande;/*date_demande_emp */
	var $date_prise;/*date_prise_emp */
	var $date_retour;/*date_retour_emp */
	var $date_debut;/*date_debut_emp */
	var $date_fin;/*date_fin_emp */
	var $caution;/*caution_emp */
	var $prix_paye;/*prix_paye_emp */
	var $emprunteur_ext;	/*emprunteur_ext */
	var $notes;/*notes_emprunt */
	var $etat;/*etat_emprunt */


540

Ayolo's avatar
Ayolo committed
541
542
543
544
545
	/* inv_emprunt_objet
	 id_objet
	 id_emprunt
	 retour_effectif_emp
	 */
546

547

Ayolo's avatar
Ayolo committed
548
549
550
551
	function load_by_id ( $id )
	{
		$req = new requete($this->db, "SELECT * FROM `inv_emprunt`
				WHERE `id_emprunt` = '" . mysql_real_escape_string($id) . "'
552
553
				LIMIT 1");

Ayolo's avatar
Ayolo committed
554
555
556
557
558
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
559
560

		$this->id = null;
Ayolo's avatar
Ayolo committed
561
562
		return false;
	}
563

Ayolo's avatar
Ayolo committed
564
	/** Charge un emprunt en cours en fonction d'un objet
565
	 * $this->id est égal à null en cas d'erreur
Ayolo's avatar
Ayolo committed
566
567
568
569
	 * @param $id_objet id de l'objet
	 */
	function load_by_objet ( $id_objet )
	{
570
		$req = new requete($this->db, "SELECT inv_emprunt.* FROM `inv_emprunt_objet`
Ayolo's avatar
Ayolo committed
571
572
573
574
				INNER JOIN inv_emprunt ON inv_emprunt.id_emprunt=inv_emprunt_objet.id_emprunt
				WHERE inv_emprunt_objet.`id_objet` = '" . mysql_real_escape_string($id_objet) . "'
				AND inv_emprunt_objet.retour_effectif_emp IS NULL
				AND inv_emprunt.date_prise_emp IS NOT NULL
575
576
				LIMIT 1");

Ayolo's avatar
Ayolo committed
577
578
579
580
581
		if ( $req->lines == 1 )
		{
			$this->_load($req->get_row());
			return true;
		}
582
583

		$this->id = null;
Ayolo's avatar
Ayolo committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
		return false;
	}

	function _load ( $row )
	{

		$this->id			= $row['id_emprunt'];
		$this->id_utilisateur	= $row['id_utilisateur'];
		$this->id_asso		= $row['id_asso'];
		$this->id_utilisateur_op= $row['id_utilisateur_op'];
		$this->date_demande	= strtotime($row['date_demande_emp']);
		$this->date_prise	= strtotime($row['date_prise_emp']);
		$this->date_retour	= strtotime($row['date_retour_emp']);
		$this->date_debut	= strtotime($row['date_debut_emp']);
		$this->date_fin		= strtotime($row['date_fin_emp']);
		$this->caution		= $row['caution_emp'];
		$this->prix_paye		= $row['prix_paye_emp'];
		$this->emprunteur_ext	= $row['emprunteur_ext'];
		$this->notes			= $row['notes_emprunt'];
		$this->etat			= $row['etat_emprunt'];
	}
605

Ayolo's avatar
Ayolo committed
606
607
608
609
610
611
612
613
614
	function add_emprunt ( $id_utilisateur, $id_asso, $emprunteur_ext, $date_debut, $date_fin )
	{
		$this->id_utilisateur = $id_utilisateur;
		$this->id_asso = $id_asso;
		$this->emprunteur_ext = $emprunteur_ext;
		$this->date_debut = $date_debut;
		$this->date_fin = $date_fin;
		$this->etat = EMPRUNT_RESERVATION;
		$this->date_demande = time();
615

Ayolo's avatar
Ayolo committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
		$sql = new insert($this->dbrw,"inv_emprunt",
					array (
						"id_utilisateur"=>$this->id_utilisateur,
						"id_asso"=>$this->id_asso,
						"emprunteur_ext"=>$this->emprunteur_ext,
						"date_debut_emp"=>date("Y-m-d H:i:s",$this->date_debut),
						"date_fin_emp"=>date("Y-m-d H:i:s",$this->date_fin),
						"etat_emprunt"=>$this->etat,
						"date_demande_emp"=>date("Y-m-d H:i:s",$this->date_demande)
					) );
		if ( $sql )
			$this->id = $sql->get_id();
		else
			$this->id = null;
	}

	function modere ( $id_utilisateur_op, $caution, $prix_paye, $notes )
	{
		$this->id_utilisateur_op = $id_utilisateur_op;
		$this->caution = $caution;
		$this->prix_paye = $prix_paye;
		$this->notes = $notes;
		$this->etat = EMPRUNT_MODERE;
639

Ayolo's avatar
Ayolo committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
		$sql = new update($this->dbrw,"inv_emprunt",
					array (
						"id_utilisateur_op"=>$this->id_utilisateur_op,
						"caution_emp"=>$this->caution,
						"prix_paye_emp"=>$this->prix_paye,
						"notes_emprunt"=>$this->notes,
						"etat_emprunt"=>$this->etat
					),array("id_emprunt"=>$this->id) );
	}

	function retrait ( $id_utilisateur_op, $caution, $prix_paye, $notes)
	{
		$this->id_utilisateur_op = $id_utilisateur_op;
		$this->caution = $caution;
		$this->prix_paye = $prix_paye;
		$this->notes = $notes;
		$this->etat = EMPRUNT_PRIS;
		$this->date_prise = time();
658

Ayolo's avatar
Ayolo committed
659
660
661
662
663
664
665
666
667
668
669
		$sql = new update($this->dbrw,"inv_emprunt",
					array (
						"id_utilisateur_op"=>$this->id_utilisateur_op,
						"caution_emp"=>$this->caution,
						"prix_paye_emp"=>$this->prix_paye,
						"notes_emprunt"=>$this->notes,
						"etat_emprunt"=>$this->etat,
						"date_prise_emp"=>date("Y-m-d H:i:s",$this->date_prise)
					),array("id_emprunt"=>$this->id) );

	}
670

Ayolo's avatar
Ayolo committed
671
672
673
674
675
676
677
678
	function add_object($id_objet)
	{
		$sql = new insert($this->dbrw,"inv_emprunt_objet",
					array (
						"id_emprunt"=>$this->id,
						"id_objet"=>$id_objet
					) );
	}
679

Ayolo's avatar
Ayolo committed
680
681
682
683
684
685
686
687
	function remove_object($id_objet)
	{
		$sql = new delete($this->dbrw,"inv_emprunt_objet",
					array (
						"id_emprunt"=>$this->id,
						"id_objet"=>$id_objet
					) );
	}
688

Ayolo's avatar
Ayolo committed
689
690
691
692
693
694
695
696
697
	function remove_emp()
	{
		$sql = new delete($this->dbrw,"inv_emprunt_objet",
					array (
						"id_emprunt"=>$this->id,
					) );
		$sql = new delete($this->dbrw,"inv_emprunt",
					array (
						"id_emprunt"=>$this->id,
698
699
					) );

Ayolo's avatar
Ayolo committed
700
	}
701

Ayolo's avatar
Ayolo committed
702
703
704
705
706
707
	function full_back ()
	{
		$sql = new update($this->dbrw,"inv_emprunt_objet",
					array("retour_effectif_emp"=>date("Y-m-d H:i:s")),
					array (
						"id_emprunt"=>$this->id
708
709
					) );

Ayolo's avatar
Ayolo committed
710
711
712
713
714
715
		$this->etat = EMPRUNT_RETOUR;
		$this->date_retour = time();
		$sql = new update($this->dbrw,"inv_emprunt",
						array (
							"date_retour_emp"=>date("Y-m-d H:i:s",$this->date_retour),
							"etat_emprunt"=>$this->etat
716
						),array("id_emprunt"=>$this->id) );
Ayolo's avatar
Ayolo committed
717
	}
718
719


Ayolo's avatar
Ayolo committed
720
721
722
723
724
725
726
727
	function back_objet($id_objet)
	{
		$sql = new update($this->dbrw,"inv_emprunt_objet",
					array("retour_effectif_emp"=>date("Y-m-d H:i:s")),
					array (
						"id_emprunt"=>$this->id,
						"id_objet"=>$id_objet
					) );
728

Ayolo's avatar
Ayolo committed
729
730
		$req = new requete($this->db,"SELECT COUNT(*) FROM `inv_emprunt_objet` " .
				"WHERE `id_emprunt`='".$this->id."' AND `retour_effectif_emp` IS NULL");
731

Ayolo's avatar
Ayolo committed
732
		list($left) = $req->get_row();
733

Ayolo's avatar
Ayolo committed
734
735
736
737
738
739
740
741
		if ( $left == 0 )
		{
			$this->etat = EMPRUNT_RETOUR;
			$this->date_retour = time();
			$sql = new update($this->dbrw,"inv_emprunt",
						array (
							"date_retour_emp"=>date("Y-m-d H:i:s",$this->date_retour),
							"etat_emprunt"=>$this->etat
742
						),array("id_emprunt"=>$this->id) );
Ayolo's avatar
Ayolo committed
743
744
745
746
747
748
749
750
751
752
		}
		elseif ( $this->etat != EMPRUNT_RETOURPARTIEL )
		{
			$this->etat = EMPRUNT_RETOURPARTIEL;
			$sql = new update($this->dbrw,"inv_emprunt",
						array (
							"etat_emprunt"=>$this->etat
						),array("id_emprunt"=>$this->id) );
		}
	}
753

Ayolo's avatar
Ayolo committed
754
755
756

}

757
?>