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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<?php
$fichier_xml = 'personnes.xml';
$fichier_xsl = 'personnes.xsl';
$fichier_xml2 = 'projets.xml';
$dom = DomDocument::load($fichier_xsl);
$proc = new XSLTProcessor;
$proc->importStylesheet($dom);
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->formatOutput = TRUE;
$dom->load($fichier_xml);
$dom2 = new DomDocument;
$dom2->preserveWhiteSpace = FALSE;
$dom2->formatOutput = TRUE;
$dom2->load($fichier_xml2);
function getFicheById($dom, $id)
{
$xpath = new DOMXPath($dom);
$res = $xpath->query(sprintf('//fiche[struct/var[@name = "id"]/text() = "%d"]', $id));
if ($res->length == 1) {
return $res->item(0);
} else {
return FALSE;
}
}
function getVarByName($fiche, $name)
{
$xpath = new DOMXPath($fiche->ownerDocument);
$res = $xpath->query(sprintf('struct/var[@name = "%s"]', $name), $fiche);
if (!$res or $res->length == 1) {
return $res->item(0)->nodeValue;
} else {
return FALSE;
}
}
if (isset($_POST['action'])) {
switch (strtolower($_POST['action'])) {
case 'editer':
$proj= array();
$i=0;
$listeProjets = $dom2->getElementsByTagName('nom');
foreach ($listeProjets as $projets)
{
$proj[$i]= $projets->firstChild->nodeValue ;
$i++;
}
if (is_array($_POST['selection'])) {
if ($fiche = getFicheById($dom, $_POST['selection'][0])) {
$id=$_POST['selection'][0];
if ($fiche->hasAttribute("type")) {
$type=$fiche->getAttribute("type");
}
$nom=getVarByName($fiche, 'nom');
$prenom=getVarByName($fiche, 'prenom');
$statut=getVarByName($fiche, 'statut');
$pageWeb=getVarByName($fiche, 'pageWebPerso');
$pageWebGRMIAO=getVarByName($fiche, 'pageWebGRMIAO');
$photo=getVarByName($fiche, 'photo');
$distinctions=utf8_decode(getVarByName($fiche, 'distinctions'));
$implicationprojet=getVarByName($fiche, 'implicationprojet');
$projets=split("/",$implicationprojet);
echo"
<div class=\"formulaire\">
<FORM method=post action=\"modif.php\">
<TABLE BORDER=0>
<TR>
<TD>type</TD>
<TD>
<INPUT type=text name=\"type\" value=$type>
</TD>
</TR>
<TR>
<TD>id</TD>
<TD>
<INPUT type=text name=\"id\" value= $id>
</TD>
</TR>
<TR>
<TD>nom</TD>
<TD>
<INPUT type=text name=\"nom\" value= $nom >
</TD>
</TR>
<TR>
<TD>prenom</TD>
<TD>
<INPUT type=text name=\"prenom\" value= $prenom>
</TD>
</TR>
<TR>
<TD>statut</TD><td>
<select name=\"statut\" title=\"statut\" STYLE=\"width:145\"><option value=\"\"></option><option value=\"Professeur\"";
if($statut == 'Professeur'){
echo 'selected = "selected"';
}
echo ">Professeur</option><option value=\"Etudiant\"";
if($statut == 'Etudiant'){
echo 'selected = "selected"';
}
echo ">Etudiant</option><option value=\"Chercheur\"";
if($statut == 'Chercheur'){
echo 'selected = "selected"';
}
echo ">Chercheur</option></select>";
echo"</td></TR>";
echo"<TR>
<TD>pageWebPerso</TD>
<TD>
<INPUT type=text name=\"pageWebPerso\" value=$pageWeb>
</TD>
</TR>
<TR>
<TD>pageWebGRMIAO</TD>
<TD>
<INPUT type=text name=\"pageWebGRMIAO\" value= $pageWebGRMIAO>
</TD>
</TR>
<TR>
<TD>photo</TD>
<TD>
<INPUT type=text name=\"photo\" value= $photo>
</TD>
</TR>
<TR>
<TD>distinctions</TD>
<TD>
<INPUT type=text name=\"distinctions\" value= \"$distinctions\">
</TD>
</TR>
<TR>
<TD>Implication dans le projet</TD>
<TD>";
$tmp=0;
foreach ($proj as $v) {
for($i=0;$i<count($projets);$i++)
{
if($v==$projets[$i])
$tmp++;
}
if($tmp==1){
echo "<input type=\"checkbox\" name=\"implicationprojet[]\" value=$v CHECKED> ";
echo" $v <Br/>";
}
else{
echo "<input type=\"checkbox\" name=\"implicationprojet[]\" value=$v> ";
echo" $v <Br/>";
}
$tmp=0;
}
echo"</TD>
</TR>
<TR>
<TD COLSPAN=2> </TD>
</TR>
</TABLE>
<input name=\"modifier\" type=\"submit\" value=\"Modifier\" />
<input name=\"annuler\" type=\"submit\" value=\"Annuler\" />
</FORM>
</div>
";
}
}
break;
case 'supprimer':
if (is_array($_POST['selection'])) {
foreach ($_POST['selection'] as $id) {
if ($fiche = getFicheById($dom, $id)) {
$fiche->parentNode->removeChild($fiche);
} else {
die("Erreur au niveau de l'expression XPath");
}
}
}
break;
}
$dom->save('personnes.xml');
}
echo $proc->transformToXML($dom);//l'erreur est ici!!!
?>
</body>
</html> |
Partager