<?php
#=
/****************************************************************************
Copyright 2002, Daniel Deycard, Jacques Messines, Stéphanie Roussel, Jean-Marie Treins
(CATICE Académie de Bordeaux)

This file is part of Gibii/Melia.

Gibii/Melia 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.

Gibii/Melia 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 Gibii/Melia; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

****************************************************************************/
include("../include/vars_adm.php");
include("../include/util.inc.php");
$statut=$_REQUEST['statut'];
opensession($statut);
$PHP_SELF=basename($_SERVER['PHP_SELF']);

 
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
?>
<HTML>

<HEAD>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<TITLE>nom1</TITLE>
<BASE TARGET="form">
<link rel="stylesheet" href="<?php echo "../themes/".$etab_theme."/b2i.css" ?>">
</HEAD>

<?php
switch ($statut) {
       case "Prof":
           echo "<BODY class='arialprof'>";
           break;
       case "Admin":
           echo "<BODY class='arialadmin'>";
           break;
       case "Gest":
           echo "<BODY class='arialgest'>";
           break;
   }
   
   
   
switch ($action)   {
    case 'fposition':
        if (strstr($etab_niveau,'1')) {
        print "<form name='formpdf' method='POST' action='classes_liste.php?action=fposition&statut=$statut' target='_self'>";
// old        print "<form name='formpdf' method='POST' action='classes_liste.php?action=fposition&statut=Gest' target='_self'>";
        print "<input type='hidden' name='testsauve' value='1'>\n";
        $chkpdf=@$_POST['chkpdf'];
        
        if (!isset($testsauve)) {
            //premier passage, on respecte la valeur de $etab_fposition
            if ($etab_fposition==2) {
               $check='checked';
               $fpos=2; 
               }
            else {
                $check='';
                $fpos=1;
                }
           }
        else  {  //Passage après submit on sauve
            if (isset($chkpdf)) {
                $check='checked';
                $fpos=2;
                if (champ_dans_table($action,'etablissements',$db)) {
                  $conn  = connecte($host, $user, $mdp, $db);
                  if ($action=='fposition') $sqlsauve="UPDATE etablissements SET fposition=".seci($fpos)." WHERE etab_id=$etab_id";
                  query($sqlsauve);
                  } 
                } 
            else {
                $check='';
                $fpos=1;
                if (champ_dans_table($action,'etablissements',$db)) {
                  $conn  = connecte($host, $user, $mdp, $db);
                  if ($action=='fposition') $sqlsauve="UPDATE etablissements SET fposition=".seci($fpos)." WHERE etab_id=$etab_id";
                  query($sqlsauve);
                  }
                }           
            
            }
        print "<a class='bulle taillebullepte' href=# target='_self'><span>Laisse une zone vide en regard de chaque item, pour des commentaires manuels</span><input type='checkbox' name='chkpdf' value='pdf2' $check onclick=\"document.formpdf.submit()\";>&nbsp;F. de position avec commentaires (1° degr&eacute;)</a>";
        print "</form>";
        } 
        else $fpos=1;
        
        break;
        
    case 'diplomes':
        $checkA4="";
        $checkA5="";
        print "<form name='formpdf' method='POST' action='classes_liste.php?action=diplomes&statut=$statut' target='_self'>";
        print "<input type='hidden' name='testsauve' value='1'>\n"; 
    
        $chk_format=@$_POST['chk_format'];
        
        if (!isset($testsauve)) {
            //premier passage, on respecte la valeur de $etab_attestation
            if ($etab_attestation=="A4")    {
               $checkA4="checked";
               $chk_format="A4";
               }    
            else {
               $checkA5="checked";      
               $chk_format="A5";
              }
            }
        else {  //Passage après submit, on sauve
            if (!isset($chk_format)) $chk_format="A5";
            if ($chk_format=='A4') $checkA4="checked"; else $checkA5="checked";
            if (champ_dans_table('attestation','etablissements',$db)) {
                $conn  = connecte($host, $user, $mdp, $db);
                $sqlsauve="UPDATE etablissements SET attestation='".$chk_format."' WHERE etab_id=$etab_id";
                query($sqlsauve);
                }               
            }
        
        print "Attestation en :<br />";
        print "<a class='bulle taillebullepte' href=# target='_self'><span>Une seule attestation par page A4 (mode paysage)</span><input type='radio' name='chk_format' value='A4' $checkA4 onclick=\"document.formpdf.submit()\";>&nbsp;A4</a>";
        print "&nbsp;&nbsp;<a class='bulle taillebullepte' href=# target='_self'><span>Deux attestations par page A4 (mode portrait)</span><input type='radio' name='chk_format' value='A5' $checkA5 onclick=\"document.formpdf.submit()\";>&nbsp;A5</a><br />";
        print "</form>";
        break;  
}

//Recup dans la session mais avant on sauve le thème du statut en cours.
$themecourant=$etab_theme;
getparams_etab($etab_id);
$etab_theme=$themecourant;
session_puts("etab_theme");
?>


<p class="titre_petit" align="center">Choisissez une classe</p>

<p class="arial_petit">
<?php



//En mode prof, les classes sont limitées à celles qu'il a
if ($statut=="Prof") $where=", profs, lien_profs_classes WHERE classes.classe_id=lien_profs_classes.classe_id ".
                     "AND lien_profs_classes.prof_id=profs.prof_id ".
                     "AND profs.prof_id=$sess_mec_id ".
                     " AND classes.etab_id=$etab_id ";
   elseif (($action=="diplomes") and ($statut=="Gest"))  $where=" WHERE classes.etab_id=$etab_id AND divgro='D'";
   else     $where=" WHERE classes.etab_id=$etab_id ";

$conn  = mysql_connect($host, $user, $mdp);
mysql_select_db($db, $conn) or die ("Impossible d'accéder à $db");;
$sql="select classes.* from classes ".$where." and classes.etab_id=$etab_id ORDER by divgro, divcod ;";
$result=mysql_query ($sql,$conn) or die ("Echec de la requête $sql");

$niv=$etab_niveau;
if ($statut=="Admin")
    $ch="../admin/";
    else $ch="";

$divgro='D';
while($row=mysql_fetch_array($result)) {
    $divg=$divgro;
    $divgro=$row['divgro'];
    if ($divg!=$divgro) print "</p><p class=\"titre_petit\" align=\"center\">Ou un groupe :</p><p class=\"arial_petit\">";
    $divcod=$row['divcod'];
    $classe_id=$row['classe_id'];
    if (!isset($objet)) $objet='';
    
    //Lien vers frame de droite :
    $lien_liste="<BR>&nbsp;&nbsp;<a href='".$ch.stripslashes($action).".php?classe_id=$classe_id&divcod=$divcod&statut=$statut&objet=$objet&divgro=$divgro";
    if ($action=='fposition') $lien_liste.="&fpos=$fpos";
    if ($action=='diplomes') $lien_liste.="&chk_format=".$chk_format;
    
    $lien_liste.="' >$divcod</a>";
    print $lien_liste;
}

//Affichage de toutes les classes PM GIBON
//Uniquement pour cet appel depuis un compte Gestion
if (($action=="classes_form") and (($statut=='Gest') OR ($sess_statut_prof>1))) {
  if (!isset($fpos)) $fpos=1;
  echo "<p class=\"titre_petit\" align=\"center\">Autre</p>";
  echo "<p class=\"arial_petit\">";
  echo "<BR>&nbsp;&nbsp;<a href='".$ch.stripslashes($action).".php?classe_id=0&divcod=&statut=$statut&objet=Tous&divgro=&fpos=$fpos' >Tout l'établissement</a>";
  echo "</p>";
}

//Etablissement entier pour sauver les diplômes en fin d'année
/*if (($action=="diplomes") and ($statut=='Gest')) {
  echo "<p class=\"titre_petit\" align=\"center\">Autre</p>";
  echo "<p class=\"arial_petit\">";
  echo "<BR>&nbsp;&nbsp;<a href='sauve_attest.php?classe_id=&divcod=&statut=$statut&objet=sauve&divgro=&fpos=$fpos' >Etablissement</a>";
  echo "</p>";
  }

  */






mysql_free_result($result);
mysql_close($conn);
?>

</p>
</BODY>
</HTML>