Subversion Repositories portal2

Rev

Rev 688 | 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
*/

?>

<?php
/*
* List available variables to monito
*
* Called from: form_billin_add.php
*
* Input args (GET):
* - device_name
* - sensor_name
*
* Inputs args (POST): none
*
* Output args:
* - device_name
* - sensor_name
* - var_name
*
* Call: form_cost_list.php
*
*/

?>

<?php
include_once('auth_check.php');
?>

<div id="page_cost_del_submit">
        <h1>
                <?php echo _('Remove Cost Entry'); ?>
        </h1>
</div>

<?php

/*
echo "GET: ";
print_r($_GET); echo "<br />";
echo "POST: ";
print_r($_POST); echo "<br />";
*/


$error = new Error();

if(!isset($_POST['form_datum_key']))
{
        $error->push(_('One or more argument(s) is/are missing.'));
}

else
if(!isset($_POST['form_token'], $_POST['form_cost_key']))
{
        $error->push(_('One or more fields are missing.'));
}

/*** check the device name is the correct length ***/
// place regexp here
else
if(!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}->[0-9]{4}-[0-9]{2}-[0-9]{2}->$/", $_POST['form_cost_key']))
//elseif (strlen( $_POST['form_cost_key']) > 30 || strlen($_POST['form_cost_key']) < 10)
{
        $error->push(_('Name is invalid. Expected format is (YYYY-MM-DD => YYYY-MM-DD).'));
}

else
{
        // retrieve device name
        $form_datum_key = filter_var($_POST['form_datum_key'], FILTER_SANITIZE_STRING);
        $form_cost_key  = filter_var($_POST['form_cost_key'], FILTER_SANITIZE_STRING);

        // remove the item by its name
        $data           = $_SESSION['data'];
        $datum          = $data->getItem($form_datum_key);
        $tracker        = $datum->getPath();
        $costs          = $datum->getCosts();
        $costs->delItem($form_cost_key);

        $error->push(_('Cost deleted.'));

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

echo $error->display();

$id      = link_get_id_from_filename("form_cost_list.php");
$refresh = $_SESSION['refresh_redirection'];
echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";

?>