<?php
/*********************************************************************************
 * Gest'Ecole is a school management software developped by
 * DOX Conception Copyright (C) 2012-2013 DOX Conception
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the license published by DOX Conception.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY.  See the Software License for more details.
 * 
 * You should have received a copy of the software license along with
 * this program; if not, see:
 * http://www.doxconception.com/index.php/licence-de-gestecole.html
 ********************************************************************************/

  $type=$_POST['periode'];
  $id=$_POST['id'];
  $l=explode("_",$id);
  $id_eleve=$l[0];
  if ($gestclasse_config_plus['etendue_annee_scolaire']=="1")
  {
    $annee=$_SESSION['annee_scolaire'];
  }
  else
  {
    if ($_SESSION['mois_en_cours']<=$gestclasse_config_plus['mois_annee_scolaire']) { $annee=$_SESSION['annee_scolaire']+1; } else { $annee=$_SESSION['annee_scolaire']; }
  }
  $date=date("Y-m-d",mktime(0,0,0,$_SESSION['mois_en_cours'],$l[1],$annee));

  switch ($type)
  {
    case "matin":
      $req=mysql_query("INSERT INTO `absences` (date,id_eleve,matin,apres_midi) VALUES ('$date','$id_eleve','1','0')");
      break;
    case "am":
      $req=mysql_query("DELETE FROM `absences` WHERE date='$date' AND id_eleve='$id_eleve'");
      $req=mysql_query("INSERT INTO `absences` (date,id_eleve,matin,apres_midi) VALUES ('$date','$id_eleve','0','1')");
      break;
    case "journee":
      $req=mysql_query("DELETE FROM `absences` WHERE date='$date' AND id_eleve='$id_eleve'");
      $req=mysql_query("INSERT INTO `absences` (date,id_eleve,matin,apres_midi) VALUES ('$date','$id_eleve','1','1')");
      break;
    case "present":
      $req=mysql_query("DELETE FROM `absences` WHERE date='$date' AND id_eleve='$id_eleve'");
      break;
  }
?>