<?
/*
Copyright (C) 2003 Loc Dayot - Mairie de Pierrefitte (93)
Vincent Vairelles - Mairie de Dijon (21)
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://www.nongnu.org/epnadmin/ ou http://epnadmin.pierrefitte93.fr
*/
require_once("header.inc.php"); // C'est dans header.inc.php que sont retrouv les droits issus de la table droits
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("animateurs.inc.php"); // concernant les animateurs
//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
// Pour les explications, voir les commentaires dans header.inc.php //
$ptitr=$sconfiguration;
$titr = $titreconfiguration;
$datemaj="11 juin 2003";
define("COULEUR", COULEUR_DROITS);
require("entete.inc.php");
// Remarque : mme si la fonctionnalit droits (FCT_DROITS) n'est pas dfinie, on accde quand mme cette page.
if (FCT_DROITS!="y" && DROITS<"~")
{
echo $pasledroit;
include("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
exit;
}
function affiche_autorisations($id)
{
global $autorvisiteur,$autordefstructure,$autoranim,$autorusagers,$fonctionnalitesdeappli,
$sFonctionnalite,$smesinformations,$scellesdesautres,$sActif,
$sCommentaire,$sdependde,$sactive,$sinactive,$sindefinie,
$saucun,$svoir,$smodifier,$sindefini, $sfct;
if ($id>0) // Il s'agit d'une structure
{
// On regarde s'il y a une configuration pour cette structure
$req0="SELECT * FROM droits WHERE id_structure=$id";
$res0=executeRequete($req0);
if (! fetch_object($res0))
$id=-3; // On reprend la configuration par d�aut.
}
switch ($id)
{
case -4 : $t=$autorvisiteur; break;
case -3 : $t=$autordefstructure; break;
case -2 : $t=$autoranim; break;
case -1 : $t=$autorusagers; break;
case 0 : $t=$fonctionnalitesdeappli; break;
default : $t=structure($id); break;
} // switch
echo cadre_debut($t);
echo "<table align=center border=1>";
echo "<tr><th>$sFonctionnalite</th>";
if ($id!=0)
echo "<th>$smesinformations</th><th>$scellesdesautres</th>";
else
echo "<th>$sActif ?</th>";
echo "<th>$sCommentaire</th>";
if ($id==0)
echo "<th>$sdependde</th>";
echo "</tr>\n";
$req1="SELECT * FROM fonctions ORDER BY ordre";
$res1=executeRequete($req1);
while ($fonction=fetch_object($res1))
{
// Retrouver les droits
$req2="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=$id";
$res2=executeRequete($req2);
if (!$droit=fetch_object($res2))
{ //N'existe pas
if ($id>0)
{
// Si c'est une structure, on prend la valeur par d�aut.
$req2="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=-3";
$res2=executeRequete($req2);
}
if (!$droit=fetch_object($res2))
{ // Si on n'a toujours rien, on prend les fonctionnalit�
$req2="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=0";
$res2=executeRequete($req2);
}
}
if ($droit->id_fonction)
{
// Retrouver si la fonctionnalit�est active
$req11="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=0";
$res12=executeRequete($req11);
$fct=fetch_object($res12);
if ($fct->actif!="y")
{
echo "<tr bgcolor=\"#ADADAD\"><th>$fonction->fonction";
if ($id!=0)
echo " ($sINACTIVE)";
echo "</th>";
}
else
echo "<tr bgcolor=\"$fonction->couleur\"><th>$fonction->fonction</th>";
echo "<td>";
if ($id==0)
{ // fonctionnalit�
switch ($droit->actif)
{
case 'y' : echo "$sactive"; break;
case 'n' : echo "$sinactive"; break;
default : echo "<i>$sindefinie</i>"; break;
}
}
else
{ // autorisations
switch ($droit->moi)
{
case ' ' : echo "$saucun"; break;
case 'r' : echo "$svoir"; break;
case 'w' : echo "$smodifier"; break;
default : echo "<i>$sindefini</i>"; break;
}
echo "</td><td>";
switch ($droit->autres)
{
case ' ' : echo "$saucun"; break;
case 'r' : echo "$svoir"; break;
case 'w' : echo "$smodifier"; break;
default : echo "<i>$sindefini</i>"; break;
}
}
echo "</td><td>".nl2br($sfct[$fonction->id])."</td>";
if ($id==0 && $fonction->depend>"")
{ // On configure les fonctionnalit�, on affiche alors les d�endances.
echo "<td>";
$reqd="SELECT * FROM fonctions WHERE id IN ($fonction->depend) ORDER BY ordre";
$resd=executeRequete($reqd);
while ($fctd=fetch_object($resd))
echo $fctd->fonction."<br>";
echo "</td>";
}
echo "</tr>\n";
}
}
echo "</table>\n";
echo cadre_fin();
} // fonction affiche_autorisations
function saisie_autorisations($id_stru)
{
global $autorvisiteur,$autordefstructure,$autoranim,$autorusagers,$fonctionnalitesdeappli,
$sFonctionnalite,$smesinformations,$scellesdesautres,$sActif,
$sCommentaire,$sdependde,$sactive,$sinactive,$sindefinie,
$saucun,$svoir,$smodifier,$sindefini,$sconfirmer, $sfct;
if (($id=$id_stru) > 0) // Il s'agit d'une structure
{
// On regarde s'il y a une configuration pour cette structure
$req0="SELECT * FROM droits WHERE id_structure=$id";
$res0=executeRequete($req0);
if (! fetch_object($res0))
$id=-3; // On reprend la configuration par d�aut.
}
switch ($id)
{
case -4 : $t=$autorvisiteur; break;
case -3 : $t=$autordefstructure; break;
case -2 : $t=$autoranim; break;
case -1 : $t=$autorusagers; break;
case 0 : $t=$fonctionnalitesdeappli; break;
default : $t=structure($id); break;
} // switch
echo cadre_debut($t);
echo "<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">
<input type=\"hidden\" name=\"id_stru\" value=\"$id_stru\">
<input type=\"hidden\" name=\"operation\" value=\"1\">
<table align=center border=1>";
echo "<tr><th>$sFonctionnalite</th>";
if ($id!=0)
echo "<th>$smesinformations</th><th>$scellesdesautres</td>";
else
echo "<th>$sActif ?</th>";
echo "<th>$sCommentaire</th>";
if ($id==0)
echo "<th>$sdependde</th>";
echo "</tr>\n";
$req1="SELECT * FROM fonctions ORDER BY ordre";
$res1=executeRequete($req1);
while ($fonction=fetch_object($res1))
{
// Retrouver si la fonctionnalit�est active
$req11="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=0";
$res12=executeRequete($req11);
$fct=fetch_object($res12);
if ($fct->actif!="y")
{
echo "<tr bgcolor=\"#ADADAD\"><th>$fonction->fonction";
if ($id!=0)
echo " ($sINACTIVE)";
echo "</th>";
}
else
echo "<tr bgcolor=\"$fonction->couleur\"><th>$fonction->fonction</th>";
// Retrouver le droit pour cette fonctionnalit
$req2="SELECT * FROM droits WHERE id_fonction=$fonction->id AND id_structure=$id";
$res2=executeRequete($req2);
$droit=fetch_object($res2);
if ($id==0)
{ // Des fonctionalits de l'application
echo "<td nowrap>";
echo "<input type=\"radio\" name=\"fonction_$fonction->id\" value=\"\"";
if (! $droit->actif)
echo " checked";
echo "><i>$sindefinie</i>
<input type=\"radio\" name=\"fonction_$fonction->id\" value=\"y\"";
if ($droit->actif=="y")
echo " checked";
echo "><b>$sactive</b>
<input type=\"radio\" name=\"fonction_$fonction->id\" value=\"n\"";
if ($droit->actif=="n")
echo " checked";
echo ">$sinactive\n";
}
else // Des autorisations
{ // de structure, animateurs ou usagers
echo "<td nowrap>";
echo "<input type=\"radio\" name=\"fonction_moi_$fonction->id\" value=\"n\"";
if ($droit->moi=="n")
echo " checked";
echo ">$saucun<br /> <input type=\"radio\" name=\"fonction_moi_$fonction->id\" value=\"r\"";
if ($droit->moi=="r")
echo " checked";
echo ">$svoir<br /> <input type=\"radio\" name=\"fonction_moi_$fonction->id\" value=\"w\"";
if ($droit->moi=="w")
echo " checked";
echo ">$smodifier";
echo "</td>
<td><input type=\"radio\" name=\"fonction_autre_$fonction->id\" value=\"n\"";
if ($droit->autres=="n")
echo " checked";
echo ">$saucun<br /> <input type=\"radio\" name=\"fonction_autre_$fonction->id\" value=\"r\"";
if ($droit->autres=="r")
echo " checked";
echo ">$svoir<br /> <input type=\"radio\" name=\"fonction_autre_$fonction->id\" value=\"w\"";
if ($droit->autres=="w")
echo " checked";
echo ">$smodifier";
}
echo "</td>\n";
echo "<td>".nl2br($sfct[$fonction->id])."</td>";
if ($id==0 && $fonction->depend>"")
{ // On configure les fonctionnalit�, on affiche alors les d�endances.
echo "<td>";
$reqd="SELECT * FROM fonctions WHERE id IN ($fonction->depend) ORDER BY ordre";
$resd=executeRequete($reqd);
while ($fctd=fetch_object($resd))
echo $fctd->fonction."<br>";
echo "</td>";
}
echo "</tr>\n";
}
echo "<tr><td colspan=\"4\" align=center><input type=\"submit\"
name=\"Confirmer\" value=\"$sconfirmer\"></td></tr>\n";
echo "</table>\n
</form>";
echo cadre_fin();
} // fonction affiche_autorisations
function verifie_dependances_fonctionnalites()
{ // On doit regarder s'il y a des d�endances
$req1="SELECT * FROM droits WHERE id_structure='0'"; // On prend toutes les fonctionnalit�
$res1=executeRequete($req1);
while ($fonction1=fetch_object($res1)) //->fetchrow(DB_FETCHMODE_OBJECT))
if ($fonction1->actif=="y")
verifie_une_fonctionnalite($fonction1->id_fonction);
free_result($res1);
}
function verifie_une_fonctionnalite($id)
{
global $avisfctrenduactive;
$req1="SELECT * FROM fonctions WHERE id='$id'"; // On prend toutes les fonctionnalit�
$res1=executeRequete($req1);
$fonction1=fetch_object($res1); //->fetchrow(DB_FETCHMODE_OBJECT);
$dependance=$fonction1->depend;
while ($dependance>"")
{
$suivante=""; $carsuivant=""; // On retrouve le num�o de la fonctionnalit�indispensable
while ($dependance>"" && ($carsuivant=$dependance[0])!=",")
{
$suivante.=$carsuivant;
$dependance=substr($dependance,1);
}
// On l'a trouv
//debug($suivante);
$rendreactif=FALSE;
// On regarde si la fonctionnalit�existe.
$req2="SELECT * FROM droits WHERE id_structure='0' AND id_fonction='$suivante'";
$res2=executeRequete($req2);
if ($droit2=fetch_object($res2)) //->fetchrow(DB_FETCHMODE_OBJECT))
{ // Oui, alors est-elle active ?
if ($droit2->actif!="y")
{ // Non, alors on la rend active
$req3="UPDATE droits SET actif='y' WHERE id_fonction='$suivante'
AND id_structure='0'";
if ($res3=executeRequete($req3))
$rendreactif=TRUE;
}
} // $droit2
else
{ // Non, elle n'existe pas, alors on la cre
$req3="INSERT INTO droits (id_structure, id_fonction, actif)
VALUES ('0', '$suivante', 'y')";
// echo $req3;
// die(" STOP");
if ($res3=executeRequete($req3))
$rendreactif=TRUE;
}
if ($rendreactif)
{
// Retrouver la fonctionnalit�rendue active
$req4="SELECT * FROM fonctions WHERE id='$suivante'";
//debug($req4);
$res4=executeRequete($req4);
$fctajoutee=fetch_object($res4); //->fetchrow(DB_FETCHMODE_OBJECT);
printf($avisfctrenduactive, $fctajoutee->fonction, $fonction1->fonction);
verifie_une_fonctionnalite($suivante);
}
$dependance=substr($dependance,1);
}
// Ouf, on a �uis�la liste des d�endances
free_result($res1);
}
// Dbut de la page
switch ($operation)
{
case 1 : // Enregistrement apr� une saisie (retour du formulaire)
// Quelques v�ifications
echo cadre_debut($smaj);
$mes="";
// A-t-on le droit de modifier quelquechose ?
if ((DROITS_MES<"w" || $id_stru!=$id_structure)
&& DROITS_AUTRES<"w")
$mes.=$pasledroit;
// A-t-on bien le num�o de la structure �qui changer les droits ?
if (! isset($id_stru))
$mes.=$smanqueinformationentite;
if ($mes!="")
{
echo "<p>$mes</p>\n";
echo cadre_fin();
break;
}
// Ok, alors on fait !
// On dtruit toutes les autorisations de l'entit (Est-ce bien ce qu'il faut faire ???)
$req0="DELETE FROM droits WHERE id_structure=$id_stru";
$res0=executeRequete($req0);
//On prend chaque fonctionalit
$req1="SELECT * FROM fonctions";
$res1=executeRequete($req1);
while ($fonction1=fetch_object($res1)) //->fetchrow(DB_FETCHMODE_OBJECT))
{
// et on regarde s'il y a une affectation
$champ0="fonction_".$fonction1->id;
$champ1="fonction_moi_".$fonction1->id;
$champ2="fonction_autre_".$fonction1->id;
if ($$champ0 || $$champ1 || $$champ2)
{ // Oui, un champ a ��rempli
//debug($$champ);
$req2="INSERT INTO droits (id_structure, id_fonction, actif, moi, autres)
VALUES (\"$id_stru\", \"$fonction1->id\", \"${$champ0}\", \"${$champ1}\", \"${$champ2}\")";
$res2=executeRequete($req2);
}
}
free_result($res1);
if ($id==0) // Il s'agit des fonctionnalit�
verifie_dependances_fonctionnalites(); // comme son nom l'indique
echo $savertissementmodifdroits;
// Et c'est fini !
echo cadre_fin();
break;
case 11 : // Voir les droits des usagers
affiche_autorisations(-1);
break;
case 12 : // Modifier les droits des usagers
saisie_autorisations(-1);
break;
case 21 : // Voir les fonctionnalits de l'application
affiche_autorisations(-2);
break;
case 22 : // Modifier les fonctionnalits de l'application
saisie_autorisations(-2);
break;
case 311 :
if ($id)
affiche_autorisations($id);
case 321 : // Saisie des droits d'une structure
if ($operation==321 && $id)
saisie_autorisations($id);
case 31 : // Voir les droits des structures
case 32 : // Modifier les droits des structures
echo cadre_debut($sautorstructure);
$pasbeau=FALSE;
if ($operation==32 || $operation==321)
{
if (DROITS_AUTRES<"w") $pasbeau=TRUE;
}
else
if (DROITS_AUTRES<"r") $pasbeau=TRUE;
if ($pasbeau)
{
echo $pasledroit;
echo cadre_fin();
break;
}
echo "<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">
<input type=\"hidden\" name=\"operation\" value=";
if ($operation==31 || $operation==311)
echo "311";
else
echo "321";
echo "><p align=center>";
choix_structure($id, "id", "");
echo "</p>
<p align=center><input type=\"submit\" value=\""; //"
if ($operation==31 || $operation==311)
echo $svoir;
else
echo $smodifierlesdroits;
echo "\"></p>
</form>"; //"
echo cadre_fin();
break;
case 41 : // Voir les fonctionnalits de l'application
affiche_autorisations(0);
break;
case 42 : // Modifier les fonctionnalits de l'application
saisie_autorisations(0);
break;
case 51 : // Voir les fonctionnalits de l'application
affiche_autorisations(-4);
break;
case 52 : // Modifier les fonctionnalits de l'application
saisie_autorisations(-4);
break;
} // switch
echo cadre_debut($titreconfiguration);
echo "<table border='1'>\n";
if ((DROITS>="~") && DROITS_AUTRES>="r")
{
echo "<tr bgcolor=\"".COULEUR_DROITS."\"><th>$fonctionnalitesdeappli</th>";
echo "<td><a href='$PHP_SELF?operation=41' title='$svoir'>$info</a></td>";
if (DROITS_AUTRES>="w")
echo "<td><a href='$PHP_SELF?operation=42' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if (FCT_STRUCTURES=="y")
{
if (DROITS_AUTRES>="w")
{
echo "<tr bgcolor=\"".COULEUR_STRUCTURES."\"><th>$autordefstructure</th>";
echo "<td><a href='$PHP_SELF?operation=311&id=-3' title='$svoir'>$info</a></td>";
echo "<td><a href='$PHP_SELF?operation=321&id=-3' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if ($is_ident=="structure" && DROITS_MOI>="r")
{
echo "<tr bgcolor=\"".COULEUR_STRUCTURES."\"><th>$smesdroits</th>";
echo "<td><a href='$PHP_SELF?operation=311&id=$id_structure' title='$svoir'>$info</a></td>";
if (DROITS_MOI>="w")
echo "<td><a href='$PHP_SELF?operation=321&id=$id_structure' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if (DROITS_AUTRES>="r")
{
echo "<tr bgcolor=\"".COULEUR_STRUCTURES."\"><th>$sautorstructure</th>";
echo "<td><a href='$PHP_SELF?operation=31' title='$svoir'>$info</a></td>";
if (DROITS_AUTRES>="w")
echo "<td><a href='$PHP_SELF?operation=32' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
}
if (FCT_USAGERS=="y")
{
echo "<tr bgcolor=\"".COULEUR_USAGERS."\"><th>$autorusagers</th>";
if (DROITS_AUTRES>="r" || ($is_ident=="usager" && DROITS_MOI>="r"))
echo "<td><a href='$PHP_SELF?operation=11' title='$svoir'>$info</a></td>";
if (DROITS_AUTRES=="w" || ($is_ident=="usager" && DROITS_MOI>="r"))
echo "<td><a href='$PHP_SELF?operation=12' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if (ANIMATEURS>="~")
{
echo "<tr bgcolor=\"".COULEUR_ANIMATEURS."\"><th>$autordefanimateur</th>";
if (DROITS_AUTRES>="r" || ($is_ident=="animateur" && DROITS_MOI>="r"))
echo "<td><a href='$PHP_SELF?operation=21&id=-2' title='$svoir'>$info</a></td>";
if (DROITS_AUTRES>="w" || ($is_ident=="animateur" && DROITS_MOI>="w"))
echo "<td><a href='$PHP_SELF?operation=22&id=-2' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if ((DROITS>="~") && DROITS_AUTRES>="r")
{
echo "<tr><th>$autorvisiteur</th>";
echo "<td><a href='$PHP_SELF?operation=51' title='$svoir'>$info</a></td>";
if (DROITS_AUTRES>="w")
echo "<td><a href='$PHP_SELF?operation=52' title='$smodifier'>$modifier</a></td>";
echo "</tr>\n";
}
if (! $verrou_config)
echo "<tr><td colspan=3 align=center><a href=\"config.php\">$titreconfig</a></td></tr>\n";
echo "</table>\n";
echo cadre_fin();
// Fin de la page
include("basdepage.inc.php");
echo "</body></html>\n";
require("footer.inc.php");
?>