/
pu_class.php
166 lines (136 loc) · 6.46 KB
/
pu_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
160
161
162
163
164
165
166
<?php
class PU {
// --- Partie privée : les variables
var $champs, $valeurs, $champsValeurs, $idx, $nomTable;
var $pu_id, $usager_id, $pj_id, $pu_date, $pu_role;
var $enregis = array("usager_id", "pj_id", "pu_date", "pu_role");
/* fonctions accesseurs */
function set_usager_id ($usager_id) { $this->usager_id = Clean($usager_id); }
function get_usager_id () { return $this->usager_id; }
function set_pj_id ($pj_id) { $this->pj_id = Clean($pj_id); }
function get_pj_id () { return $this->pj_id; }
function set_pu_date ($pu_date) { $this->pu_date = Clean($pu_date); }
function get_pu_date () { return $this->pu_date; }
function set_pu_role ($pu_role) { $this->pu_role = Clean($pu_role); }
function get_pu_role () { return $this->pu_role; }
//---- partie publique : les méthodes
Function PU ($table) { // constructeur
/*********************************************************
liste des champs de l'enregistrement
le champ « pu_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 PU
Function Imprimer_form ($parametres, $action)
{
print('<table border="0" bgcolor="#EBEBEB" align="center"><tr><td>');
print(Imprime_titreListe("Accès aux projets", "titre"));
print("<br>");
$f = new Formulaire ("POST", "pus.php");
$f->debutTable(VERTICAL);
//$f->champTexte("$this->{$value}", "$this->{$value}", $this->{$value}, 3, 58);
//$f->champListe("chosir un élément de la liste", $this->{variable}, $this->{variable}, 1, $uneListe);
//$f->champFenetre("fenêtre", $this->{$value}, $this->{$value}, 1, 79);
$f->champCache("pu_id", $this->pu_id);
$f->finTable();
$f->debutTable(HORIZONTAL);
$f->champValider ("sauver", "action");
$f->finTable();
$f->fin();
print('</td></tr></table>');
} // fin Imprimer_form -----------------------
Function Sauver ($bd)
{
$requete = "SELECT pu_id FROM $this->nomTable WHERE pu_id = '$this->pu_id' ";
$res = $bd->execRequete($requete);
if (mysql_num_rows($res) > 0 )
$this->Maj($bd);
else
$this->Inserer($bd);
} //---------------------------------------- sauver
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 « pu_id » placée au début des champs existants
//----- « 0 » comme valeur correspondante dans les valeurs
$this->champs = "pu_id, " . $this->champs;
$this->valeurs = "0, " . $this->valeurs;
$requete = "INSERT INTO $this->nomTable (" . $this->champs . ") VALUES (" . $this->valeurs . ")";
$res = $bd->execRequete($requete);
$this->pu_id = mysql_insert_id(); //--- pour initialiser « pu_id » dans l'objet après l'insertion dans la BD
$this->operation = "opération INSÉRER ok -- $this->pu_id -- (enr. $this->pu_id)";
return;
} //------------------------------------------------- Inserer
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 pu_id = '$this->pu_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "opération MAJ ok -- $this->pu_id -- (enr. $this->pu_id)";
return $resultat;
} //---------------------------------------------------------- Maj
Function Detruire ($bd)
{
$requete = "DELETE FROM $this->nomTable WHERE pu_id = '$this->pu_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "opération DÉTRUIRE ok -- $this->pu_id -- (enr. $this->pu_id)";
return $resultat;
} //---------------------------------------------------------- Detruire
Function Affectation ($ligne, $pu_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->pu_id = $pu_id; //****** pour initialiser pu_id dans la classe PU
return;
} //-------------------------------------------------
Function Get_operation ()
{
return $this->operation;
} //-------------------------------------------
Function Get_pu ($bd, $pu_id)
{
$requete = "SELECT * FROM $this->nomTable WHERE pu_id = '$pu_id' ";
$res = $bd->execRequete($requete);
if (mysql_num_rows($res) > 0 ) {
$ligne = $bd->ligneSuivante($res);
$this->Affectation($ligne, $pu_id);
$this->operation = "";
} else {
$this->pu_id = $pu_id;
}
return $res;
} //-----------------------------
} //---fin de la classe ----------------------------
?>