<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  Sylvain FATOME
 * 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
 * (in the directory docs);
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Contact : galawa@free.fr
 *
 * Web : http://smi.no-ip.org
 ****************************************************************************************/

/********************************************************/
/* Vérification Evénement en fonction choix date/heure  */
/********************************************************/

session_start();
sleep(1);
if (array_key_exists('id', $_REQUEST)) {
    $tomorrow = 0; //60*60*24; // en nb de secondes
    header("Cache-Control: max-age=$tomorrow");
    upd_plan();
} else {
    print "Usage : $_SERVER[PHP_SELF]?id=idorig_typd_coded_date_heure_duree";
}

function upd_plan()
{
    header('Content-type: text/html; charset=UTF-8');
    $tab_codeid = explode('_', $_REQUEST['id']);

    $idorig = (int)$tab_codeid[0];
    $typd = (int)$tab_codeid[1];
    $coded = $tab_codeid[2];

    require_once('../lib/gettext/gettext.inc');
    include_once('../inc/config.inc.php');
    include_once('../inc/func_date.inc.php');
    include_once('../inc/func_time.inc.php');
    include_once('../inc/func_txt.inc.php');
    include_once('../classes/ezSQL/shared/ez_sql_core.php');
    include_once('../classes/ezSQL/mysqli/ez_sql_mysqli.php');
    include_once('../inc/func_sql.inc.php');
    include_once('../inc/fic_int.inc.php');
    include_once('../inc/fic_plan.inc.php');
    include_once('../inc/fic_tec.inc.php');

    $dayweek = njour_semaine(datetomysql($tab_codeid[3])) + 1;

    $heure = $tab_codeid[4] . ':00';
    $dureem = (int)$tab_codeid[5];

    // On vérifie si l'utilisateur courant est autorisé à modifier l'évènement
    if (evt_modifiable($idorig) == TRUE) {
        $mess_err = chk_evt_tec($typd, $coded, $dayweek, $heure, $dureem);
    } else {
        $mess_err = _("Vous n'avez pas le droit de modifier cet événement");
    }

    if ($mess_err <> '') {
        print($mess_err);
    }
}
