/
poste_class.php
159 lines (134 loc) · 6.21 KB
/
poste_class.php
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
class POSTE {
// --- Partie privée : les variables
var $champs, $valeurs, $champsValeurs, $idx, $nomTable;
var $poste_id, $instance_id, $poste_no, $poste_nom, $poste_proc;
var $enregis = array("instance_id", "poste_no", "poste_nom", "poste_proc");
/* fonctions accesseurs */
function set_instance_id ($instance_id) { $this->instance_id = Clean($instance_id); }
function get_instance_id () { return $this->instance_id; }
function set_poste_no ($poste_no) { $this->poste_no = Clean($poste_no); }
function get_poste_no () { return $this->poste_no; }
function set_poste_nom ($poste_nom) { $this->poste_nom = Clean($poste_nom); }
function get_poste_nom () { return $this->poste_nom; }
function set_poste_proc ($poste_proc) { $this->poste_proc = Clean($poste_proc); }
function get_poste_proc () { return $this->poste_proc; }
//---- partie publique : les méthodes
Function POSTE ($table) { // constructeur
/*********************************************************
liste des champs de l'enregistrement
le champ « poste_id » n'est pas inclus à cause de la
fonction MAJ qui ne doit pas comprendre la clé primaire
*******************************************************
*/
$this->i = 0;
foreach($this->enregis as $value) {
if ($this->i == 0) {
$this->champs = $value ;
} else {
$this->champs .= ", " . $value ;
}
$this->{$value} = "";
$this->i++;
}
$this->nomTable = $table;
return;
}//---------------------- constructeur pour POSTE
Function Imprimer_form ($css, $mode, $forme, $listePostes) {
print('<table border="0" bgcolor="#EBEBEB" align="center"><tr><td>');
print(Imprime_titreListe("Gestion d'un poste d'une instance", "titre"));
print("<br>");
$f = new Formulaire ("post", "postes.php", "", TRUE , $forme);
$f->debutTable(HORIZONTAL);
$f->champListe("$instance_id", "instance_id", $this->instance_id, 1, $listePostes);
$f->champTexte("$poste_no", "poste_no", $this->poste_no, 3, 58);
$f->champTexte("$poste_nom", "poste_nom", $this->poste_nom, 3, 58);
$f->champTexte("$poste_proc", "poste_proc", $this->poste_proc, 3, 58);
$f->finTable();
$f->debutTable(HORIZONTAL);
if($mode == "ajouter") {
$f->champValider ("sauver", "action");
} else {
$f->champValider ("sauver", "action");
$f->champValider ("sauver", "action");
}
$f->finTable();
$f->champCache("poste_id", $this->poste_id);
$f->fin();
print('</td></tr></table>');
}//--------
Function Sauver ($bd) {
$requete = "SELECT poste_id FROM $this->nomTable WHERE poste_id = '$this->poste_id' ";
$res = $bd->execRequete($requete);
if (mysql_num_rows($res) > 0 )
$this->Maj($bd);
else
$this->Inserer($bd);
}//--------
Function Inserer ($bd) {
$this->i = 0;
foreach($this->enregis as $value) {
if ($this->i == 0) {
$this->valeurs = "'" . addslashes($this->{$value}) . "'";
} else {
$this->valeurs .= ", '" . addslashes($this->{$value}) . "'";
}
$this->i++;
}
//----- clé primaire « poste_id » placée au début des champs existants
//----- « 0 » comme valeur correspondante dans les valeurs
$this->champs = "poste_id, " . $this->champs;
$this->valeurs = "0, " . $this->valeurs;
$requete = "INSERT INTO $this->nomTable (" . $this->champs . ") VALUES (" . $this->valeurs . ")";
$res = $bd->execRequete($requete);
$this->poste_id = mysql_insert_id(); //--- pour initialiser « poste_id » dans l'objet après l'insertion dans la BD
$this->operation = "INSERTION ok -- $this->poste_id -- (enr. $this->poste_id)";
return;
}//--------
Function Maj ($bd) {
$this->i = 0;
foreach($this->enregis as $value) {
if ($this->i == 0) {
$this->champsValeurs .= $value . " = '" . addslashes($this->{$value}) . "'";
} else {
$this->champsValeurs .= ", " . $value . " = '" . addslashes($this->{$value}) . "'";
}
$this->i++;
}
$requete = "UPDATE $this->nomTable SET " . $this->champsValeurs . " WHERE poste_id = '$this->poste_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "MAJ ok -- $this->poste_id -- (enr. $this->poste_id)";
return $resultat;
}//--------
Function Detruire ($bd) {
$requete = "DELETE FROM $this->nomTable WHERE poste_id = '$this->poste_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "DESTRUCTION ok -- $this->poste_id -- (enr. $this->poste_id)";
return $resultat;
}//--------
Function Affectation ($ligne, $poste_id) {
foreach($ligne as $index=>$value) {
if (in_array($index, $this->enregis)) { // initialiser seulement les éléments
$this->{$index} = stripslashes($value); // de $_POST qui font partie de l'enr.
}
}
$this->poste_id = $poste_id; //****** pour initialiser poste_id dans la classe POSTE
return;
}//--------
Function Get_operation () {
return $this->operation;
}//--------
Function Get_poste ($bd, $poste_id) {
$requete = "SELECT * FROM $this->nomTable WHERE poste_id = '$poste_id' ";
$res = $bd->execRequete($requete);
if (mysql_num_rows($res) > 0 ) {
$ligne = $bd->ligneSuivante($res);
$this->Affectation($ligne, $poste_id);
$this->operation = "";
} else {
$this->poste_id = $poste_id;
}
return $res;
}//--------
}//---fin de la classe
?>