/
projet.class.php
171 lines (140 loc) · 6.57 KB
/
projet.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
167
168
169
170
171
<?php
class PJ {
// --- Partie privée : les variables
var $champs, $valeurs, $champsValeurs, $idx, $nomTable;
var $pj_id, $pj_no, $pj_nom, $usager_id, $pj_acces;
var $enregis = array("pj_no", "pj_nom", "usager_id", "pj_acces");
/* fonctions accesseurs */
function set_pj_no ($pj_no) { $this->pj_no = Clean($pj_no); }
function get_pj_no () { return $this->pj_no; }
function set_pj_nom ($pj_nom) { $this->pj_nom = Clean($pj_nom); }
function get_pj_nom () { return $this->pj_nom; }
function set_pj_usager_id ($pj_usager_id) { $this->pj_usager_id = Clean($pj_usager_id); }
function get_pj_usager_id () { return $this->pj_usager_id; }
function set_pj_acces ($pj_acces) { $this->pj_acces = Clean($pj_acces); }
function get_pj_acces () { return $this->pj_acces; }
//---- partie publique : les méthodes
Function PJ ($table) { // constructeur
/*********************************************************
liste des champs de l'enregistrement
le champ « pj_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 PJ
Function Imprimer_form ($action, $css, $listeUsagers)
{
$listeAcces[0] = "non ";
$listeAcces[1] = "oui";
print('<table border="0" bgcolor="#EBEBEB" align="center"><tr><td>');
print(Imprime_titreListe("Gestion d'un projet", "titre"));
print("<br>");
$f = new Formulaire ("post", "projets.php");
$f->debutTable(HORIZONTAL);
$f->champTexte("no du projet", "pj_no", $this->pj_no, 15, 15);
$f->champTexte("nom du projet", "pj_nom", $this->pj_nom, 50, 50);
$f->champListe("nom du responsable", "usager_id", $this->usager_id, 1, $listeUsagers);
$f->champListe("peut éditer ?", "pj_acces", $this->pj_acces, 1, $listeAcces);
$f->champCache("pj_id", $this->pj_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 pj_id FROM $this->nomTable WHERE pj_id = '$this->pj_id' ";
$res = $bd->execRequete($requete);
if(substr($this->pj_no, 2, 1) == "0") $this->pj_nom = strtoupper($this->pj_nom);
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 « pj_id » placée au début des champs existants
//----- « 0 » comme valeur correspondante dans les valeurs
$this->champs = "pj_id, " . $this->champs;
$this->valeurs = "0, " . $this->valeurs;
$requete = "INSERT INTO $this->nomTable (" . $this->champs . ") VALUES (" . $this->valeurs . ")";
$res = $bd->execRequete($requete);
$this->pj_id = mysql_insert_id(); //--- pour initialiser « pj_id » dans l'objet après l'insertion dans la BD
$this->operation = "opération INSÉRER ok __ $this->pj_no __ (enr. $this->pj_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 pj_id = '$this->pj_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "opération MAJ ok __ $this->pj_no __ (enr. $this->pj_id)";
return $resultat;
} //---------------------------------------------------------- Maj
Function Detruire ($bd)
{
$requete = "DELETE FROM $this->nomTable WHERE pj_id = '$this->pj_id' " ;
$resultat = $bd->execRequete($requete);
$this->operation = "opération DÉTRUIRE ok __ $this->pj_no __ (enr. $this->pj_id)";
return $resultat;
} //---------------------------------------------------------- Detruire
Function Affectation ($ligne, $pj_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->pj_id = $pj_id; //****** pour initialiser pj_id dans la classe PJ
return;
} //-------------------------------------------------
Function Get_operation ()
{
return $this->operation;
} //-------------------------------------------
Function Get_pj ($bd, $pj_id)
{
$requete = "SELECT * FROM $this->nomTable WHERE pj_id = '$pj_id' ";
$res = $bd->execRequete($requete);
if (mysql_num_rows($res) > 0 ) {
$ligne = $bd->ligneSuivante($res);
$this->Affectation($ligne, $pj_id);
$this->operation = "";
} else {
$this->pj_id = $pj_id;
}
return $res;
} //-----------------------------
} //---fin de la classe ----------------------------
?>