Subversion Repositories portal2

Rev

Rev 690 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/*  emg - Energy Monitoring & Graphing
*  Copyright (C) 2006-2012 Romain Lievin
*
*  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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

?>

<div id="page_form_data_del_submit">
        <h1>
                <?php echo _('Remove Data'); ?>
        </h1>
</div>

<?php

$error = new Error();
$ok = false;

if(!isset($_POST['form_token'], $_POST['form_datum_key']))
{
        $error->push(_('One or more fields are missing.'));
}
else
if( $_POST['form_token'] != $_SESSION['form_token'])
{
        $error->push(_('Internal error: invalid token.'));
}
else
if(isset($_POST['data_cancel']))
{
        $error->push(_('Operation aborted.'));
}
else
{
        // retrieve data name
        $form_datum_key = filter_var($_POST['form_datum_key'], FILTER_SANITIZE_STRING);

        if(isset($_SESSION['data']))
        {
                $data       = $_SESSION['data'];

                $datum      = $data->getItem($form_datum_key);
                $datum_name = $datum->getName();

                if($datum->getType() != DatumFactory::SINGLE)
                {
                        $data->delItem($form_datum_key);
                        $error->push(_('Data deleted.'));
                }
                else
                {
                        $error->push(_('Single data can\'t be deleted; only aggregates (sum/diff/external).'));
                }
        }
        else
        {
                /* does nothing */
        }

        /*** save configuration contents ***/
        config_save();
}

echo $error->display();

/* Redirection */
if(isset($_POST['form_cancel']) || ($ok === true))
{
        $id = link_get_id_from_filename("form_data_list.php");
        $refresh = $_SESSION['refresh_redirection'];
echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";
}
else if($ok == false)
{
        $id = link_get_id_from_filename("form_data_del.php");
        $refresh = $_SESSION['refresh_redirection'];
echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";
}

?>