<?php
/*
Copyright (C) 2001 Loc Dayot
EPNadmin - Version 0.7
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
http://epnadmin.pierrefitte93.fr/
*/
require_once("header.inc.php");
if (! defined("FCT_PARC"))
{
$fctnonactive;
exit;
}
require_once("constantes.inc.php"); // dfinition des constantes
//require_once("fonctions.inc.php"); // concernant des fonctions transversales inclassables
require_once("mysql.inc.php"); // concernant mysql
//require_once("sessions.inc.php"); // concernant les sessions et initiations
//require_once("usagers.inc.php"); // concernant la gestion des usagers
//require_once("reservations.inc.php"); // concernant les rservations des postes en accs individuel par des usagers
//require_once("tableaux.inc.php"); // Concernant l'affichage transpos d'un tableau
//require_once("siteweb.inc.php"); // concernant les pages perso des usagers et les sites web des structures
//require_once("dateheure.inc.php"); // concernant la manipulation des heures et des dates, formulaire, conversion...
require_once("structures.inc.php"); // concernant les structures
//require_once("initiations.inc.php"); // concernant les initiations et les thmes
//require_once("parcours.inc.php"); // concernant les parcours des usagers et leur positionnement
$stitr= $smateriels;
$titr = $stitremateriel;
$datemaj="13 juin 2003";
define("COULEUR", COULEUR_PARC);
require("entete.inc.php");
if (PARC<="~")
echo $pasledroit;
else
if (PARC_AUTRES>="r")
echo "<a href=\"logiciels.php?operation=5\">$svoirlistelogiciels</a>
- <a href=\"materiels.php?operation=5\">$svoirlistemateriels</a>\n";
elseif (PARC_MOI>="r")
echo "<a href=\"logiciels.php?operation=5\">$svoirmalistelogiciels</a> -
<a href=\"materiels.php?operation=5\">$svoirmalistemateriels</a>\n";
echo "<hr>";
function verifdroits($droit="r", $affiche=TRUE)
{
global $id_materiel, $id_structure,
$pasledroit, $materielintrouvable, $manqueinformateriel;
if (!$id_materiel)
{
if ($affiche)
echo $manqueinfomateriel;
return FALSE;
}
$req="SELECT id_structure FROM materiels
LEFT JOIN localisations ON materiels.id_localisation=localisations.id
WHERE materiels.id=\"$id_materiel\"";
$res=executeRequete($req);
if (! $materiel=fetch_object($res))
{
if ($affiche)
echo $materielintrouvable;
return FALSE;
}
if (!(PARC_AUTRES>=$droit || (PARC_MOI>=$droit && $materiel->id_structure==$id_structure)))
{
if ($affiche)
echo $pasledroit;
return FALSE;
}
return TRUE;
}
switch ($operation)
{
case 11 : // confirmation d'ajout ou mise jour
echo cadre_debut($smajmateriel, "align=center", COULEUR_PARC);
if ($id_materiel)
{
if (! verifdroits("w"))
{
echo cadre_fin(COULEUR_PARC);
break;
}
}
elseif (PARC_MOI<"w" && PARC_AUTRES<"w")
{
echo cadre_fin(COULEUR_PARC);
break;
}
$mes="";
if ($type=="") $mes.=$smanquetype."<br>";
if ($description=="") $mes.=$smanquetitre."<br>";
if ($pret_possible=="") $mes.=$smanquepret."<br>";
if ($reservable=="") $mes.="$smanqueresa<br>";
if ($mes!="")
{
echo "<p>$mes</p>";
echo cadre_fin(COULEUR_PARC);
}
else
{
$sep=""; $i=0; $usagess="";
while ($u=$usages[$i])
{
$usagess.=$sep.$u;
$sep=",";
$i++;
}
if (!$id_materiel)
{
echo "<p>$senrnouvmateriel</p>\n";
$req = "INSERT INTO materiels "
. "(type, materiel, specificite, ip, info_achat, "
. " description, usages, pret_possible, reservable, image, id_localisation) "
. "VALUES "
. "(\"$type\", \"$materiel\", \"$specificite\", \"$ip\", \"$info_achat\", "
. " \"$description\", \"$usagess\", \"$pret_possible\",
\"$reservable\", \"$image\", \"$id_localisation\")";
$res = executeRequete($req);
// on recherche l'id_materiel pour pouvoir faire le lien avec les logiciels
$req = "SELECT MAX(id) as mx FROM materiels";
$res = executeRequete($req);
$max = fetch_object($res);
$id_materiel = $max->mx;
}
else
{ // C'est une mise jour de l'enregistrement.
echo "<p>$smaj</p>\n";
$req = "UPDATE materiels SET type=\"$type\", "
. "materiel=\"$materiel\", specificite=\"$specificite\", ip=\"$ip\", "
. "info_achat=\"$info_achat\", "
. "description=\"$description\", usages=\"$usagess\", pret_possible=\"$pret_possible\",
reservable=\"$reservable\", image=\"$image\", id_localisation=\"$id_localisation\"";
$req .= " WHERE id = \"$id_materiel\"";
$res = executeRequete($req);
// Suppression des liens entre matriel et logiciels
$req = "DELETE FROM logi_mate WHERE id_materiel=$id_materiel";
$res = executeRequete($req);
}
// Affectation des liens
$i=0;
while ($id_logiciel[$i])
{
$req = "INSERT INTO logi_mate (id_logiciel, id_materiel) "
. "VALUES ($id_logiciel[$i], $id_materiel)";
$res = executeRequete($req);
$i++;
}
echo cadre_fin(COULEUR_PARC);
break; // tout c'est bien pass
}
// pas de break si jamais il y avait besoin d'une nouvelle saisie.
case 2 : // formulaire d'dition
// Saisie pour modification d'un enregistrement
if (! verifdroits("w") && $operation!=11)
break;
$req = "SELECT * FROM materiels WHERE id=$id_materiel";
$res = recherche("materiels", "id", $id_materiel);
if ($mate = fetch_array($res))
extract($mate);
// pas de break, on enchane avec le formulaire d'dition
case 1 : // formulaire d'ajout
// Dbut du fomulaire de saisie d'enregistrement de logiciels
echo cadre_debut($smajmateriel, "align=center", COULEUR_PARC);
if ($id_materiel)
{
if (! verifdroits("w"))
{
echo cadre_fin(COULEUR_PARC);
break;
}
}
elseif (PARC_MOI<"w" && PARC_AUTRES<"w")
{
echo cadre_fin(COULEUR_PARC);
break;
}
echo "<form action=\"$PHP_SELF\" method=\"post\">";
echo "<input type=\"hidden\" name=\"operation\" value=\"11\">";
if ($id_materiel)
echo "<input type=\"hidden\" name=\"id_materiel\" value=\"$id_materiel\">";
echo "<table align=\"center\">
<tr><td>$stype*</td><td><select name=\"type\" size=\"1\">
<option></option>";
for ($ntype=0; $slistetypemateriels[$ntype]; $ntype++)
{
echo " <option value=\"$slistetypemateriels[$ntype]\"";
if ($type==$slistetypemateriels[$ntype]) echo " SELECTED";
echo ">$slistetypemateriels[$ntype]</option>\n";
}
echo " </select></td></tr>
<tr><td>$sCommentaire</td><td><textarea name=\"description\" rows=\"4\" cols=\"30\">$description</textarea></td></tr>
<tr><td>$sAppellation</td><td><input type=\"text\" name=\"materiel\" value=\"$materiel\" size=\"20\" maxlength=\"20\"></td></tr>
<tr><td>$sSpecificite</td><td><input type=\"text\" name=\"specificite\" value=\"$specificite\" size=\"20\" maxlength=\"20\"></td></tr>
<tr><td>IP</td><td><input type=\"text\" name=\"ip\" value=\"$ip\" size=\"20\" maxlength=\"20\"></td></tr>
<tr><td>$sLocalisation</td>";
choixSalle($id_localisation, "enable", PARC_AUTRES>="w");
echo "</tr>
<tr><td>$slielogiciels</td>
<td><select name=\"id_logiciel[]\" size=\"10\" multiple>";
$req = "SELECT * FROM logiciels
LEFT JOIN logi_mate ON logiciels.id=logi_mate.id_logiciel";
if (! (PARC_AUTRES>="w" && $id_structure))
$req.=" LEFT JOIN materiels ON materiels.id=id_materiel
LEFT JOIN localisations ON localisations.id=materiels.id_localisation
WHERE (id_structure=\"$id_localisation\" OR id_localisation=\"\"";
$req.=" ORDER BY type,titre,licence";
$res = executeRequete($req);
$mat = fetch_object($res);
$ancien_id_mat=$mat->id;
while ($mat)
{
$l = "<option value=\"$mat->id\"";
$l2 = ">$mat->type : $mat->titre ($mat->licence)\n";
$l1 = "";
while (($mat) && ($mat->id == $ancien_id_mat))
{
if ($mat->id_materiel==$id_materiel) $l1 = " SELECTED";
$mat = fetch_object($res);
}
echo "$l$l1$l2\n";
$ancien_id_mat=$mat->id;
}
echo "</select>\n";
echo "</td></tr>\n";
if (defined("FCT_USAGES"))
{
echo "<tr><td>$usagesimpossibles</td>
<td><select name=\"usages[]\" size=10 multiple>";
if ($usages=="") $usages="0";
$req = "SELECT * FROM usages WHERE id IN ($usages) ORDER BY 'nom'";
$res = executeRequete($req);
while ($usage=fetch_object($res))
echo "<option value=\"$usage->id\" SELECTED>$usage->nom\n";
$req = "SELECT * FROM usages WHERE id NOT IN ($usages) ORDER BY 'nom'";
$res = executeRequete($req);
while ($usage=fetch_object($res))
echo "<option value=\"$usage->id\">$usage->nom\n";
echo "</select>\n";
echo "</td></tr>\n";
}
echo "<tr><td>$spretpossible*</td><td><select name=\"pret_possible\" size=\"1\">
<option>
<option value=\"oui\"";
if ($pret_possible=="oui") echo " SELECTED";
echo ">$soui
<option value=\"non\"";
if ($pret_possible=="non") echo " SELECTED";
echo ">$snon
</select></td></tr>\n
<tr><td>$smaterielreservable*</td><td><select name=\"reservable\" size=\"1\">
<option>
<option value=\"oui\"";
if ($reservable=="oui") echo " SELECTED";
echo ">$soui
<option value=\" deux\"";
if ($reservable==" deux") echo " SELECTED";
echo ">$sreservablea2
<option value=\"non\"";
if ($reservable=="non") echo " SELECTED";
echo ">$snon
</select></td></tr>\n
<tr><td>$sinfoachat</td>
<td><textarea name=\"info_achat\" rows=\"5\" cols=\"40\">$info_achat</textarea></td>
</tr>
<tr><td>$slienimage</td><td><input type=\"text\" name=\"image\" value=\"$image\" size=\"30\" maxlength=\"50\"></td></tr>
<tr><td colspan=\"2\"><center><input type=\"submit\" name=\"send\" value=\"$envoyer\"></center></td></tr>
</table>
</form>\n";
// Fin du formulaire de saisie.
echo cadre_fin(COULEUR_PARC);
break;
case 3 : // formulaire de suppression
if (! verifdroits("w"))
break;
$contenu="<p align=center>$sattentionsupprmateriel</p>
<p align=center>
<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">
<input type=\"hidden\" name=\"operation\" value=31>
<input type=\"hidden\" name=\"id_materiel\" value=\"$id_materiel\">
<input type=\"submit\" value=\"$sconfirmer\">
</form></p>\n";
echo cadre($ssupprmateriel, $contenu, "align=center", COULEUR_PARC);
break;
case 31 : // confirmation de suppression
cadre_debut($ssupprmateriel, "align=center", COULEUR_PARC);
if (verifdroits("w"))
{
echo "<p>$smaterielsupprime</p>\n";
$req = "DELETE FROM materiels WHERE id=$id_materiel";
$res = executeRequete($req);
$req = "DELETE FROM logi_mate WHERE id_materiel=$id_materiel";
$res = executeRequete($req);
}
cadre_fin(COULEUR_PARC);
break;
case 5 :
// Affichage de la liste des materiels
echo cadre_debut($slistemateriels, "align=center", COULEUR_PARC);
if (PARC<="~")
{
echo cadre_fin(COULEUR_PARC);
break;
}
$req = "SELECT *, materiels.id AS id, materiels.description AS description FROM materiels ";
$req.=" LEFT JOIN localisations ON localisations.id=id_localisation
LEFT JOIN structures ON structures.id=localisations.id_structure ";
$req.=" WHERE (0=0) ";
if (PARC_AUTRES<"r")
$req.=" AND id_structure=\"$id_structure\" ";
if ($lieuv>"0" && $lieuv!="*")
$req.=" AND ((CONCAT(\"V\",structures.ville)=\"$lieuv\") OR
(CONCAT(\"S\",localisations.id_structure)=\"$lieuv\") OR
(CONCAT(\"L\",localisations.id)=\"$lieuv\")) ";
if ($type>"" && $type!="*")
$req.=" AND type=\"$type\"";
$req.=" ORDER BY type, id_localisation, materiel, localisations.description";
$res = executeRequete($req);
echo "<table border=1 align=center>
<tr><th>$stype";
echo "</th><th>$sLocalisation</th><th>$sAppellation</th><th>$sCommentaire</th><th>$sActions";
echo "</th></tr>\n\n";
echo "<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">
<input type=\"hidden\" name=\"operation\" value=\"$operation\">
<tr><td>";
echo " <select name=\"type\"><option value=\"*\">Tous</option>";
$reqtype="SELECT type FROM materiels GROUP BY type ORDER BY type";
$restype=executeRequete($reqtype);
while ($enrtype=fetch_object($restype))
{
echo "<option value=\"$enrtype->type\"";
if ($enrtype->type==$type) echo " selected";
echo ">$enrtype->type</option>\n";
}
echo "</select>\n";
echo "</td><td>";
choix_lieu($lieuv, "lieuv");
echo "</td><td></td><td></td><td><input type=\"submit\" value=\"$srechercher\">";
echo "</td></tr>\n</form>\n";
$type="";
while ($log = fetch_object($res))
{
echo "<tr>\n";
if ($type!=$log->type)
{
echo "<th>$log->type</th>\n";
$type=$log->type;
}
else
echo "<td></td>\n";
echo "<td>".localisation($log->id_localisation)."</td>
<td><b>$log->materiel</b> ($log->specificite)</td>
<td>$log->description</td>
<td nowrap><a href=\"$PHP_SELF?id_materiel=$log->id\">$info</a>";
if ((PARC_MOI>="w" && $log->id_structure==$id_structure) || PARC_AUTRES>="w")
echo "<a href=\"$PHP_SELF?operation=2&id_materiel=$log->id\">$modifier</a>
<a href=\"$PHP_SELF?operation=3&id_materiel=$log->id\">$supprimer</a>";
echo "</td></tr>\n";
}
if (PARC_MOI>="w" || PARC_AUTRES>="w")
echo "<tr><td colspan='4'></td><td><a href=\"$PHP_SELF?operation=1\">$ajouter</a></td></tr>\n";
echo "</table>\n";
echo cadre_fin(COULEUR_PARC);
break;
default : // affichage dtails
echo cadre_debut($sdetailmateriel, "align=center", COULEUR_PARC);
if (! verifdroits("r"))
{
echo cadre_fin(COULEUR_PARC);
break;
}
// affichage d'un rsum du matriel et des lments attenants
$req1 = "SELECT * FROM materiels WHERE id=$id_materiel";// AND type='Unit centrale'";
$res1 = executeRequete($req1);
if ($materiel=fetch_object($res1))
{
echo "<table align=center border=1>
<tr><td colspan=2 align=center><h3>$materiel->materiel</h3>";
if ($materiel->specificite!="")
echo "<p>($materiel->specificite)</p>";
if ($materiel->ip!="")
echo "<p>($materiel->ip)</p>";
echo "</td></tr>\n";
echo "<tr><td colspan=2>".nl2br($materiel->description)."</td>";
if (verifdroits("w", FALSE))
echo "<td><a href=\"materiels.php?operation=2&id_materiel=$materiel->id&$idu\">$modifier</a>
<a href=\"materiels.php?operation=3&id_materiel=$materiel->id&$idu\">$supprimer</a>\n";
echo "</tr>\n";
echo "<tr><td>Rservable</td><td>";
switch ($materiel->reservable)
{
case "oui" : echo "Oui, un seul utilisateur."; break;
case "non" : echo "Non"; break;
case " deux" : echo "Oui, un ou deux utilisateurs"; break;
}
echo "</td></tr>\n";
if ($materiel->localisation!="")
echo "<tr><td>Localisation</td><td>$materiel->localisation</td></tr>\n";
if ($materiel->materiel!="")
{
echo "<tr><td colspan=2 align=center><b>Liste des lments attachs</b></td></tr>\n";
$res2 = recherche ("materiels", "materiel", $materiel->materiel, "type");
while ($materiel2 = fetch_object($res2))
{
echo "<tr><td>$materiel2->type</a>";
if ($materiel2->specificite!="")
echo " (".$materiel2->specificite.")";
echo "</td><td>".nl2br($materiel2->description)."</td>";
echo "<td><a href=\"materiels.php?id_materiel=$materiel2->id\">$info</a> ";
if (verifdroits("w", FALSE))
echo "<a href=\"materiels.php?operation=2&id_materiel=$materiel2->id\">$modifier</a>
<a href=\"materiels.php?operation=3&id_materiel=$materiel2->id\">$supprimer</a>\n";
echo "</td></tr>\n";
}
// affichage des logiciels attachs la machine
$res2 = recherche ("materiels", "materiel", $materiel->materiel, "type");
echo "<tr><td colspan=2 align=center><b>Liste des logiciels attachs ce matriel</b></td></tr>\n";
while ($materiel2 = fetch_object($res2))
{
$req3 = "SELECT * FROM logiciels LEFT JOIN logi_mate ON logiciels.id=logi_mate.id_logiciel WHERE id_materiel=$materiel2->id ORDER BY type, titre, licence";
$res3 = executeRequete($req3);
while ($logiciel=fetch_object($res3)) // il y a des logiciels attachs au matriel $id_materiel
{
echo "<tr><td>$logiciel->type</td><td>$logiciel->titre";
//if ($logiciel->licence!="")
// echo "<br>$logiciel->licence";
if ($logiciel->commentaire!="")
echo "<br><i>".nl2br($logiciel->commentaire)."</i>";
echo "</td>";
echo "<td><a href=\"logiciels.php?id_logiciel=$logiciel->id\">$info</a>\n";
echo "</tr>\n";
}
}
}
else // affichage pour le seul matriel slectiionn s'il n'a pas de nom
{
$req3 = "SELECT * FROM logiciels LEFT JOIN logi_mate ON logiciels.id=logi_mate.id_logiciel WHERE id_materiel=$materiel->id";
$res3 = executeRequete($req3);
while ($logiciel=fetch_object($res3)) // il y a des logiciels attachs au matriel $id_materiel
{
echo "<tr><td>$logiciel->type</td><td>$logiciel->titre";
if ($logiciel->commentaire!="")
echo "<br><i>".nl2br($logiciel->commentaire)."</i>";
echo "</td>";
echo "<td><a href=\"logiciels.php?id_logiciel=$logiciel->id\">$info</a>\n";
echo "</tr>\n";
}
}
// affichage des usages possibles sur cet ordinateur si c'est une UC.
if ($materiel->type="Unit centrale" && defined("FCT_USAGES"))
{
if ($materiel->usages=="") $materiel->usages="0";
$req4 = "SELECT * FROM usages WHERE id NOT IN ($materiel->usages) ORDER BY 'nom'";
$res4 = executeRequete($req4);
echo "<tr><td colspan=2 align=center><b>Liste des usages possibles</b></td></tr>\n<tr><td colspan=2>";
while ($usage = fetch_object($res4)) // il y a des logiciels attachs au matriel $id_materiel
echo "$usage->nom, ";
echo "</td></tr>\n";
}
echo "</table>\n";
}
echo cadre_fin(COULEUR_PARC);
} // switch
if ($operation || $id_materiel)
{
echo "<hr>\n";
if (PARC_AUTRES>="r")
echo "<a href=\"logiciels.php?operation=5\">$svoirlistelogiciels</a>
- <a href=\"materiels.php?operation=5\">$svoirlistemateriels</a>\n";
elseif (PARC_MOI>="r")
echo "<a href=\"logiciels.php?operation=5\">$svoirmalistelogiciels</a> -
<a href=\"materiels.php?operation=5\">$svoirmalistemateriels</a>\n";
}
require("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
?>