<?php
/*
Copyright (C) 2001, 2002 Loc Dayot
EPNadmin - Version 0.6
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"))
{
echo $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
/* LD : 22/02/2003
Un nouveau champ dans la table logiciels a t ajout.
En effet, certains logiciels en prt notamment ne sont pas affects
un matriel. Il faut donc savoir dans quelle structure le logiciel se
trouve. D'o l'introduction du champ id_structure dans la table.
*/
$ptitr=$slogiciels;
$titr = $stitrelogiciels;
$datemaj="23 fvrier 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" && $isident="structure")
echo "<a href=\"logiciels.php?operation=5\">$svoirmalistelogiciels</a> -
<a href=\"materiels.php?operation=5\">$svoirmalistemateriels</a>\n";
echo "<hr>";
function verifiedroits($droit="r", $affiche=TRUE)
{
global $id_logiciel, $id_structure,
$manqueinfologiciel, $logicielintrouvable, $pasledroit;
if (!$id_logiciel)
{
if ($affiche)
echo $manqueinfologiciel;
return FALSE;
}
$req="SELECT id_structure FROM logiciels
WHERE id=\"$id_logiciel\"";
$res=executeRequete($req);
if (! $logiciel=fetch_object($res))
{
if ($affiche)
echo $logicielintrouvable;
return FALSE;
}
if (!(PARC_AUTRES>=$droit || (PARC_MOI>=$droit && $logiciel->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($smajlogiciel, "align=center", COULEUR_PARC);
if ($id_logiciel)
{
if (! verifiedroits("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 ($id_stru=="") $mes.=$smanquestrupropri."<br>";
if ($titre=="") $mes.=$smanquetitre."<br>";
if ($pret_possible=="") $mes.=$smanquepret."<br>";
if ($reservable=="") $mes.=$smanqueresa."<br>";
if ($mes!="")
echo "<p>$mes</p>";
else
{
if (!$id_logiciel)
{
echo "<p>$senrnouvlogiciel</p>\n";
$req = "INSERT INTO logiciels "
. "(type, titre, licence, id_structure, info_achat, "
. " commentaire, pret_possible, reservable, image) "
. "VALUES "
. "(\"$type\", \"$titre\", \"$licence\", \"$id_stru\", \"$info_achat\",
\"$commentaire\", \"$pret_possible\", \"$reservable\", \"$image\")";
$res = executeRequete($req);
// on recherche l'id_materiel pour pouvoir faire le lien avec les logiciels
$req = "SELECT MAX(id) as mx FROM logiciels";
$res = executeRequete($req);
$max = fetch_object($res);
$id_logiciel = $max->mx;
}
else
{ // C'est une mise jour de l'enregistrement.
echo "<p>$smaj</p>\n";
$req = "UPDATE logiciels SET type=\"$type\",
titre=\"$titre\", licence=\"$licence\", id_structure=\"$id_stru\",
info_achat=\"$info_achat\",
commentaire=\"$commentaire\", pret_possible=\"$pret_possible\",
reservable=\"$reservable\", image=\"$image\" ";
$req .= " WHERE id = \"$id_logiciel\"";
$res = executeRequete($req);
// Suppression des liens entre matriel et logiciels
$req = "DELETE FROM logi_mate WHERE id_logiciel=$id_logiciel";
$res = executeRequete($req);
}
// Affectation des liens
$i=0;
while ($id_materiel[$i])
{
$req = "INSERT INTO logi_mate (id_logiciel, id_materiel) "
. "VALUES ($id_logiciel, $id_materiel[$i])";
$res = executeRequete($req);
$i++;
}
echo cadre_fin(COULEUR_PARC);
break; // tout c'est bien pass
}
echo cadre_fin(COULEUR_PARC);
// pas de break si jamais il y avait besoin d'une nouvelle saisie.
case 2 : // formulaire d'dition
if (! verifiedroits("w"))
break;
$res = recherche("logiciels", "id", $id_logiciel);
if ($logi = mysql_fetch_array($res))
{
$id_structure_logguee=$id_structure; // Sauvegarde de la structure qui est identifie
extract($logi);
$id_stru=$id_structure;
$id_structure=$id_structure_logguee; // On la retrouve.
}
// 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($smajlogiciel, "align=center", COULEUR_PARC);
if (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_logiciel)
echo "<input type=\"hidden\" name=\"id_logiciel\" value=\"$id_logiciel\">";
echo "<table align=\"center\" border=1>
<tr><td>$stype*</td><td><select name=\"type\" size=\"1\">
<option></option>";
for ($ntype=0; $slistetypelogiciels[$ntype]; $ntype++)
{
echo " <option value=\"$slistetypelogiciels[$ntype]\"";
if ($type==$slistetypelogiciels[$ntype]) echo " SELECTED";
echo ">$slistetypelogiciels[$ntype]</option>\n";
}
echo " </select></td></tr>
<tr><td>$sstruproprio</td><td>";
if (!$id_stru) $id_stru=$id_structure;
choix_structure($id_stru, "id_stru", "");
echo " </td></tr>
<tr><td>$sTitre</td><td><input type=\"text\" name=\"titre\" value=\"$titre\" size=\"30\" maxlength=\"80\"></td></tr>
<tr><td>$sLicence</td><td><input type=\"text\" name=\"licence\" value=\"$licence\" size=\"30\" maxlength=\"40\"></td></tr>
<tr><td>$sCommentaire</td><td><textarea name=\"commentaire\" rows=\"4\" cols=\"30\">$commentaire</textarea></td></tr>
<tr><td>$sliemateriel</td>
<td><select name=\"id_materiel[]\" size=\"10\" multiple>";
$req = "SELECT * FROM materiels
LEFT JOIN logi_mate ON materiels.id=logi_mate.id_materiel";
if (PARC_AUTRES<"w")
$req.=" LEFT JOIN localisations ON localisations.id=materiels.id_localisation
WHERE id_structure=\"$id_structure\"";
$req.=" ORDER BY type,id_localisation,materiel";
$res = executeRequete($req);
$mat = fetch_object($res);
$ancien_id_mat=$mat->id;
while ($mat)
{
$l = "<option value=\"$mat->id\"";
$l2 = ">$mat->type ($mat->localisation) : $mat->materiel ($mat->specificite) ".substr($mat->description, 0, 20)."\n";
$l1 = "";
while (($mat) & ($mat->id == $ancien_id_mat))
{
if ($mat->id_logiciel==$id_logiciel) $l1 = " SELECTED";
$mat = fetch_object($res);
}
echo "$l$l1$l2\n";
$ancien_id_mat=$mat->id;
}
echo "</select>\n";
echo "
</td></tr>
<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>$slogicielreservable*</td><td><select name=\"reservable\" size=\"1\">
<option>
<option value=\"oui\"";
if ($reservable=="oui") echo " SELECTED";
echo ">$soui
<option value=\"non\"";
if ($reservable=="non") echo " SELECTED";
echo ">$snon
</select></td></tr>\n
<tr><td>$sinfoachat</td><td><textarea name=\"info_achat\">$info_achat</textarea></td></tr>
<tr><td>$slienimage</td><td><input type=\"text\" name=\"image\" value=\"$image\" size=\"40\" maxlength=\"64\"></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 (! verifiedroits("w"))
break;
$contenu="<p align=center>$sattentionsupprlogiciel</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_logiciel\" value=\"$id_logiciel\">
<input type=\"submit\" value=\"$sconfirmer\">
</form></p>\n";
echo cadre($ssupprlogiciel, $contenu, "align=center", COULEUR_PARC);
break;
case 31 : // confirmation de suppression
cadre_debut($ssupprlogiciel, "align=center", COULEUR_PARC);
if (verifiedroits("w"))
{
echo "<p>$slogicielsupprime</p>\n";
$req = "DELETE FROM logiciels WHERE id=$id_logiciel";
$res = executeRequete($req);
$req = "DELETE FROM logi_mate WHERE id_logiciel=$id_logiciel";
$res = executeRequete($req);
}
cadre_fin(COULEUR_PARC);
break;
case 5 :
// Affichage de la liste des materiels
echo cadre_debut($slistelogiciels, "align=center", COULEUR_PARC);
if (PARC>"~")
{
$req = "SELECT * FROM logiciels WHERE (0=0) ";
if (PARC_AUTRES<"r") // On limite la visibilit si on a pas tous les droits
$req.=" AND id_structure=$id_structure ";
if ($type>"" && $type!="*")
$req.=" AND type=\"$type\"";
if ($stru>0 && $stru!="*")
$req.=" AND id_structure=$stru ";
$req.=" ORDER BY type, id_structure, titre, licence";
$res = executeRequete($req);
// Ligne de titres
echo "<table border=1 align=center>
<tr><th>$stype</th><th>$sstruproprio<th>$sTitre (licence)</th><th>$sActions</th></tr>\n";
// Ligne pour les critres de slection
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 logiciels 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_structure($stru, "stru");
echo "</td><td></td><td><input type=\"submit\" value=\"$srechercher\">";
echo "</td></tr>\n</form>\n";
$type="";
while ($log = fetch_object($res))
{
$id_logiciel=$log->id;
if (verifiedroits("r", FALSE))
{
echo "<tr>\n";
if ($type!=$log->type)
{
echo "<th>$log->type</th>\n";
$type=$log->type;
}
else
echo "<td></td>\n";
echo "<td>".structure($log->id_structure)."</td>\n";
echo "<td>$log->titre";
if (verifiedroits("w", FALSE))
echo " ($log->licence)";
if ($log->commentaire!="") echo "<br><i>$log->commentaire</i>";
echo "</td>
<td nowrap><a href=\"$PHP_SELF?id_logiciel=$log->id\">$info</a>\n";
if (verifiedroits("w", FALSE))
echo " <a href=\"$PHP_SELF?operation=2&id_logiciel=$log->id\">$modifier</a>
<a href=\"$PHP_SELF?operation=3&id_logiciel=$log->id\">$supprimer</a></td></tr>\n";
}
}
if (PARC_MOI>="w" || PARC_AUTRES>="w")
echo "<tr><td colspan='3'></td><td><a href=\"$PHP_SELF?operation=1\">$ajouter</a></td></tr>\n";
echo "</table>\n";
}
else
echo $pasledroit;
echo cadre_fin(COULEUR_PARC);
break;
default : // affichage dtails
echo cadre_debut($sdetaillogiciel, "align=center", COULEUR_PARC);
if (verifiedroits("r"))
{
// affichage d'un rsum du matriel et des lments attenants
$req1 = "SELECT * FROM logiciels WHERE id=$id_logiciel ";// AND type='Unit centrale'";
$res1 = executeRequete($req1);
if ($logiciel=fetch_object($res1))
{
echo "<table align=center border=1>
<tr><td colspan=2 align=center><h3>$logiciel->titre</h3>";
if ($logiciel->licence!="" && verifiedroits("w", FALSE))
echo "($logiciel->licence)";
echo "<br>$sstruproprio : ".structure($logiciel->id_structure);
echo "</td></tr>\n";
echo "<tr><td colspan=2>".nl2br($logiciel->description)."</td>
<td><a href=\"logiciels.php?id_logiciel=$logiciel->id\">$info</a>";
$id_logiciel=$logiciel->id;
if (verifiedroits("w", FALSE))
echo " <a href=\"logiciels.php?operation=2&id_logiciel=$logiciel->id\">$modifier</a>
<a href=\"logiciels.php?operation=3&id_logiciel=$logiciel->id\">$supprimer</a>\n";
echo "</td></tr>\n";
// affichage des materiels attachs au logiciel
echo "<tr><td colspan=2 align=center><b>Liste des materiels attachs ce logiciel</b></td></tr>\n";
$req3 = "SELECT * FROM materiels LEFT JOIN logi_mate ON materiels.id=logi_mate.id_materiel
WHERE id_logiciel=$id_logiciel ORDER BY type, id_localisation, materiel";
$res3 = executeRequete($req3);
while ($materiel=fetch_object($res3)) // il y a des logiciels attachs au matriel $id_materiel
{
echo "<tr><td>$materiel->type</td><td>".localisation($materiel->id_localisation);
if ($materiel->materiel>"")
echo "<br><b>$materiel->materiel</b>";
if ($materiel->description!="")
echo "<br><i>".nl2br($materiel->description)."</i>";
echo "</td>";
//if ()
echo "<td><a href=\"materiels.php?id_materiel=$materiel->id\">$info</a>\n";
echo "</tr>\n";
}
echo "</table>\n";
}
}
else
echo $pasledroit;
echo cadre_fin(COULEUR_PARC);
break;
} // switch
if ($operation || $id_logiciel)
{
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");
?>