<?php
/*
Copyright (C) 2002 Loc Dayot - Mairie de Pierrefitte (93)
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_STRUCTURES"))
{
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
$ptitr=$sstructures;
$titr=$sstrutitre;
define("COULEUR", COULEUR_STRUCTURES);
$datemaj="3 mai 2003";
require("entete.inc.php");
// Affiche les informations concernant une structure
function affiche_structure($id_stru)
{
global $id_structure,
$pasledroit;
$res=recherche("structures", "id", $id_stru);
$structure=fetch_object($res);
echo "<table border=1 align=center>
<tr><th align=center colspan=2>$structure->structure</th></tr>
<tr><td>Raison sociale :</td><td>$structure->raison_sociale</td></tr>
<tr><td>Responsable :</td><td>$structure->nom_responsable</td></tr>
<tr><td>Adresse :</td><td>$structure->adresse</td></tr>
<tr><td>Ville :</td><td>$structure->ville</td></tr>
<tr><td>Courriel :</td><td>$structure->courriel</td></tr>
<tr><td>Site web :</td><td>$structure->siteweb</td></tr>\n";
if (STRUCTURES_AUTRES>="r")
echo "<tr><td>Commentaire :</td><td>$structure->commentaires</td></tr>";
echo "</table>\n";
}
function verifiedroits($acces="r", $id_stru, $affiche=TRUE)
{
global $id_structure, $pasledroit;
if (STRUCTURES_MOI>=$acces && $id_stru==$id_structure)
return TRUE;
if (STRUCTURES_AUTRES>=$acces)
return TRUE;
if ($affiche) echo $pasledroit;
return FALSE;
}
// Dbut du contenu de la page
if (STRUCTURES<="~")
{
echo $pasledroit;
exit;
}
if (!$id_stru)
$id_stru=$id_structure;
switch($operation)
{
case 61 : // Enregistrement du changement de mot de passe de l'usager
echo cadre_debut($schagnementmdp);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
$mes="";
if ((!$motdepasse || $motdepasse=="") && $id_structure==$id_stru)
$mes .= $smanquemotdepasseactuel."<br>";
$res=recherche("structures", "id", $id_stru);
if (! $structure=fetch_object($res))
$mes.="$sstructureintrouvable<br>";
// vrifier que l'ancien mot de passe est bien le bon
// uniquement si on n'est pas administrateur
if ($id_structure==$id_stru && $motdepasse!=$structure->motdepasse
&& md5($motdepasse)!=$structure->motdepasse)
$mes.="$smauvaismotdepasse<br>";
if ($motdepasse1=="" || $motdepasse2=="") $mes .= "$manquemotdepasse<br>";
if ($motdepasse1 != $motdepasse2) $mes .= "$motdepassedifferents<br>";
if ($mes!="")
echo "<p>$mes</p>";
else
{
// modification du compte de structure dans la base locale epnadmin
echo "<p>$schgmdpstruok</p>";
$motdepassec=md5($motdepasse1);
$query = "UPDATE structures SET motdepasse='$motdepassec' WHERE id='$id_stru'";
$result = executeRequete($query);
echo cadre_fin();
break;
}
echo cadre_fin();
case 6 : // Une structure demande changer de mot de passe
echo cadre_debut($schagnementmdp);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
$res=recherche("structures", "id", $id_stru);
if (! $structure=fetch_object($res))
{
echo "<p>$sstructureintrouvable</p>";
break;
}
echo "<form name=\"form_mp_structure\" method=\"post\" action=\"$PHP_SELF\">
<input type=\"hidden\" name=\"id_stru\" value=\"$id_stru\">
<input type=\"hidden\" name=\"operation\" value=\"61\">
<table border=\"1\">
<tr><th align=center colspan=2>$schangementmpd ".structure($id_stru)." ($structure->login)</th></tr>";
// Si on est administrateur, on ne demande pas le mot de passe en cours
if ($id_structure==$id_stru)
echo "<tr><td>$smotdepasseactuel*</td><td><input type=\"password\" name=\"motdepasse\"></td></tr>";
echo "<tr><td>$smotdepassenouveau*</td>
<td><input type=\"password\" name=\"motdepasse1\"></td></tr>
<tr><td>$smotdepassenouveau* ($sconfirmer)</td>
<td><input type=\"password\" name=\"motdepasse2\"></td></tr>
<tr><td align=center colspan=2><input type=\"submit\" value=\"$sconfirmer\"></td></tr>
<tr><td colspan=2>$savertissementmdpstru</td></tr>
</table></form>\n";
echo cadre_fin();
break;
case 3 : // Confirmation d'effacement
echo cadre_debut($sstruefface);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
$mes="";
if ($id_stru==$id_structure)
$mes.=$struestmoi;
$res = recherche("sessions", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$strusertsession;
$res = recherche("localisations", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$strusertlocal;
$res = recherche("animateurs", "id_structure_provenance", $id_stru);
if (fetch_object($res))
$mes.=$strusertanimateur;
$res = recherche("usagers", "id_structure_provenance", $id_stru);
if (fetch_object($res))
$mes.=$strusertusagers;
$res = recherche("pret_materiel", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$strusertpret;
if ($mes!="")
{
echo $mes;
echo cadre_fin();
break;
}
echo "<form name=\"form\" method=\"post\" action=\"structures.php\">
<input type=\"hidden\" name=\"id_stru\" value=\"$id_stru\">
<input type=\"hidden\" name=\"operation\" value=\"31\">
<b>$sconfirmersupprstru ";
echo structure($id_stru);
echo " ?</b>
<br><input type=\"submit\" action=\"structures.php\" name=\"Annuler\" value=\"$ssupprsuppr\">
</form>\n";
echo cadre_fin();
break;
case 31: // Efface final
echo cadre_debut($sstruefface);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
$mes="";
$res = recherche("sessions", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$strusertsession;
$res = recherche("localisations", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$strusertlocal;
$res = recherche("animateurs", "id_structure_provenance", $id_stru);
if (fetch_object($res))
$mes.=$strusertanimateur;
$res = recherche("usagers", "id_structure_provenance", $id_stru);
if (fetch_object($res))
$mes.=$strusertusagers;
$res = recherche("pret_materiel", "id_structure", $id_stru);
if (fetch_object($res))
$mes.=$struserthebergement;
if ($mes!="")
{
echo $mes;
echo cadre_fin();
break;
}
$query = "DELETE FROM structures WHERE id='$id_stru'";
if (executeRequete($query))
echo "<p>$sstrueffacee</p>";
$query = "DELETE FROM droits WHERE id_structure='$id_stru'";
if (executeRequete($query))
echo "<p>$sstrudroitseffaces</p>";
echo cadre_fin();
break;
case 2: // Formulaire modification
echo cadre_debut($smaj);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
$result = recherche("structures", "id", $id_stru);
$u=fetch_array($result);
$operation=21;
extract($u);
// pas de break
case 1: // Ajoute un nouveau partenaire (ou le modifie)
if ($operation==1)
{
echo cadre_debut($sajoutstru);
if (! verifiedroits("w", $id_stru))
break;
$operation=11;
$structure="";
$login="";
}
echo "<table align=center border=1>
<form name=\"modistru\" method=\"post\" action=\"structures.php\">\n";
if ($operation==21)
echo "<input type=\"hidden\" name=\"id_stru\" value=\"$id_stru\">\n";
echo "<input type=\"hidden\" name=\"operation\" value=\"$operation\">
<tr><td>$sStructure* :</td><td><input type=\"text\" name=\"structur\" value=\"$structure\" size=\"32\" maxlength=\"30\"></td></tr>
<tr><td>$sRaisonsociale :</td><td><input type=\"text\" name=\"raison_sociale\" value=\"$raison_sociale\" size=\"50\" maxlength=\"50\"></td></tr>
<tr><td>$sNomresponsable :</td><td><input type=\"text\" name=\"nom_responsable\" value=\"$nom_responsable\" size=\"32\" maxlength=\"50\"></td></tr>
<tr><td>$sIdentifiant* :</td><td>";
//if ($operation==11)
echo "<input type=\"text\" name=\"login\" value=\"$login\" size=\"32\" maxlength=\"30\">";
//else
//echo "<i>non modifiable</i>";
echo "</td></tr>
<tr><td>$sMotdepasse* :</td><td>";
if ($operation==21)
echo "<a href=\"$PHP_SELF?operation=6&id_stru=$id_stru\">$slemodifier</a>";
else
echo "<input type=\"password\" name=\"motdepasse\" value=\"\" size=\"32\" maxlength=\"32\"><br>
<input type=\"password\" name=\"motdepasse2\" value=\"\" size=\"32\" maxlength=\"32\">";
echo "</td></tr>
<tr><td>$sAdresse :</td><td><input type=\"text\" name=\"adresse\" value=\"$adresse\" size=\"32\" maxlength=\"100\"></td></tr>
<tr><td>$sVille* :</td><td><input type=\"text\" name=\"ville\" value=\"$ville\" size=\"32\" maxlength=\"50\"></td></tr>
<tr><td>$sCourrieldefaut :<br>(dj existant)</td><td><input type=\"text\" name=\"courriel\" value=\"$courriel\" size=\"32\" maxlength=\"50\"></td></tr>
<tr><td>$sSitewebdefaut :<br>(dj existant)</td><td><input type=\"text\" name=\"siteweb\" value=\"$siteweb\" size=\"32\" maxlength=\"50\"></td></tr>
<tr><td>$sCommentaires :</td><td><textarea name=\"commentaires\" rows=\"4\" cols=\"60\">$commentaires</textarea>\n";
echo "<tr><td align=center colspan=2>
<input type=\"submit\" name=\"Envoyer\" value=\"$envoyer\">
</td></tr></table></form>\n";
echo cadre_fin();
break;
case 11: // Ajout final
echo cadre_debut($sajoutstru);
if (! verifiedroits("w", $id_stru))
{
echo cadre_fin();
break;
}
// vrification des paramtres
$res=recherche("structures", "login", $login);
$mes="";
if (fetch_object($res))
$mes.=$logindejapris;
// TODO : plein de choses vrifier...
if ($mes!="")
{
echo $mes;
echo cadre_fin();
break;
}
$query = "INSERT INTO structures
(structure,raison_sociale,nom_responsable,login,motdepasse,
adresse,ville,courriel,siteweb,commentaires,
date )
VALUES (\"$structur\", \"$raison_sociale\", \"$nom_responsable\",
\"$login\", \"$motdepasse\", \"$adresse\", \"$ville\",
\"$courriel\", \"$siteweb\", \"$commentaires\",
NOW())";
if (executeRequete($query))
echo "<p>$sstruajoutee</p>";
echo cadre_fin();
break;
case 21: // Modif finale
echo cadre_debut($smaj);
if (! verifiedroits("w", $id_stru))
break;
$query = "UPDATE structures SET
structure=\"$structur\", raison_sociale=\"$raison_sociale\",
nom_responsable=\"$nom_responsable\",
adresse=\"$adresse\", ville=\"$ville\",
courriel=\"$courriel\", siteweb=\"$siteweb\",
commentaires=\"$commentaires\"
WHERE id=\"$id_stru\"";
if ($result = executeRequete($query))
echo "<p>$sstrumaj</p>";
echo cadre_fin();
break;
case 5 : // liste des structures
echo cadre_debut($slistestructures, "align=center", COULEUR_STRUCTURES);
if (STRUCTURES_AUTRES<"r")
{
echo $pasledroit;
echo cadre_fin(COULEUR_STRUCTURES);
break;
}
$req = "SELECT * FROM structures ORDER BY structure";
$res = executeRequete($req);
echo "<table align=center border=1>";
// <tr><td colspan=6><h3 align=center>Liste des partenaires</h3></td></tr>\n";
while ($u= fetch_object($res))
{
echo "<tr><td><b>$u->structure</b><br>$u->raison_sociale</td>
<td>$u->nom_responsable<br>$u->adresse<br><a href=\"mailto:$u->courriel\">$u->courriel</a></td>
<td>".nl2br($u->commentaires)."</td>
<td><a href=\"structures.php?id_stru=$u->id\">$info</a></td>";
if (verifiedroits("w", $u->id, FALSE)) // on ne peut pas se dtruire
echo " <td><a href=\"structures.php?operation=2&id_stru=$u->id\">$modifier</a></td>\n";
if (verifiedroits("w", $u->id, FALSE) && $u->id!=$id_structure) // on ne peut pas se dtruire
echo " <td><a href=\"structures.php?operation=3&id_stru=$u->id\">$supprimer</a></td>";
echo "</tr>\n";
}
if (STRUCTURES_AUTRES>="w")
echo "<tr><td colspan=6 align=right><a href=\"structures.php?operation=1\">$ajouter</a></td></tr>\n";
echo "</table>\n";
echo cadre_fin(COULEUR_STRUCTURES);
break;
default : // infos sur une structure
if (!$id_stru) $id_stru=$id_structure;
if (! verifiedroits("r", $id_stru))
break;
echo cadre_debut($sdetailstructure, "align=center", COULEUR_STRUCTURES);
/* echo "<table align=center bgcolor=\"".COULEUR_STRUCTURE."\">
<tr><td align=center><font size=\"+2\">Informations sur une structure</font></td></tr>
<tr><td align=center>\n"; */
affiche_structure($id_stru);
//echo "</td></tr></table>\n";
if (verifiedroits("w", $id_stru, FALSE))
echo "<p align=center><a href=\"$PHP_SELF?operation=2&id_stru=$id_stru\">$modifier Modifier des informations</a></p>\n";
if (STRUCTURES_AUTRES>="w" && $id_structure!=$id_stru) // On ne peut pas se dtruire soi mme.
echo "<p align=center><a href=\"$PHP_SELF?operation=3&id_stru=$id_stru\">$supprimer Supprimer la structure</a></p>\n";
echo cadre_fin(COULEUR_STRUCTURES);
if (defined("FCT_LOCALISATIONS")
&& ( (LOCALISTIONS_MOI>="r" && $id_stru==$id_structure)
|| LOCALISATIONS_AUTRES>="r"))
{
// Affichage des localisations
$req = "SELECT * FROM localisations";
$req.=" WHERE id_structure=$id_stru";
$req.=" ORDER BY id_structure, salle";
$res = executeRequete($req);
echo cadre_debut($slistelocalisations, "align=center", COULEUR_LOCALISATIONS);
echo "<table align=center border=1>\n";
while ($u=fetch_object($res))
{
echo "<tr><td>".localisation($u->id, TRUE)."</td>";
if ((LOCALISATIONS_MOI>="w" && $id_structure==$id_stru) || LOCALISATIONS_AUTRES>="w")
echo " <td><a href=\"localisations.php?operation=2&id_localisation=$u->id\">$modifier</a></td>
<td><a href=\"localisations.php?operation=3&id_localisation=$u->id\">$supprimer</a></td>";
echo "</tr>\n";
}
if ((LOCALISATIONS_MOI>="w" && $id_structure==$id_stru) || LOCALISATIONS_AUTRES>="w")
echo "<tr><td colspan=3 align=right><a href=\"localisations.php?operation=1&id_stru=$id_stru\">$ajouter</a></td></tr>\n";
echo "</table>";
echo cadre_fin(COULEUR_LOCALISATIONS);
}
break;
} // switch
if (LOCALISATIONS_AUTRES>="r")
echo "<p><a href=\"structures.php?operation=5\">$slistestructures</a>.</p>\n";
else
echo "<p><a href=\"structures.php\">$sinfomastructure</a>.</p>\n";
include("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
?>