<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Version 1.0.2

Copyright (C) 2006-2015  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
 ****************************************************************************************/

/**************************************************/
/* Mise à jour tableau de session des recherchers */
/**************************************************/

@session_start();
sleep(1);
if (array_key_exists("cmd", $_REQUEST)) {
    $tomorrow = 0; //60*60*24; // en nb de secondes
    header("Cache-Control: max-age=$tomorrow");
    print_plain();
} else {
    echo "Usage : $_SERVER[PHP_SELF]?cmd = un-code";
}

function print_plain()
{
    header("Content-type: text/html; charset=UTF-8");
    extract($_REQUEST);
    $ex_session = $_SESSION["tri_col"];
    switch ($cmd) {
        // On a validé : mise à jour
        case "valid" :
            $new_session = [];
            foreach ($ex_session as $key => $value) {
                // Si trouvé : on change
                if ($key == $chp) {
                    $tab_tmp = [
                        $value[0],
                        $comp,
                        $val];
                    $new_session[$key] = $tab_tmp;
                } // Si pas trouvé : on change pas
                else
                    $new_session[$key] = $value;
            }
            $_SESSION["tri_col"] = $new_session;
            echo "ok";
            break;
        // On a annulé : on récupère ce que l'on mettait avant
        case "close" :
            $tab_tmp = $ex_session[$chp];
            echo "ok_" . $tab_tmp[1] . "_" . $tab_tmp[2];
            break;
        // On vidé : on met à zéro uniquement cet enregistrement
        case "reset" :
            $new_session = [];
            if ($chp <> 'all') {
                foreach ($ex_session as $key => $value) {
                    // Si trouvé : on change
                    if ($key == $chp) {
                        $tab_tmp = [
                            $value[0],
                            'null',
                            ''];
                        $new_session[$key] = $tab_tmp;
                    } // Si pas trouvé : on change pas
                    else
                        $new_session[$key] = $value;
                }
            } else {
                foreach ($ex_session as $key => $value) {
                    $tab_tmp = [
                        $value[0],
                        'null',
                        ''];
                    $new_session[$key] = $tab_tmp;
                }
            }
            $_SESSION["tri_col"] = $new_session;
            echo "ok";
            break;
    }
}
?>