Subversion Repositories portal2

Rev

Rev 705 | 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 costs
*
* Called from: form_cost_list.php
*
* Input args (GET):
* - device_name
* - tracker_name
*
* Inputs args (POST): none
* - cost_add
*
* Output args:
* - device_name (GET)
* - tracker_name (GET)
* - button action: form_[add|cancel] (POST)
*
* Call: form_cost_add.php  or form_cost_del.php or form_cost_modify.php
*
*/

?>

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

<?php

$form_token = md5(uniqid('auth', true));
$_SESSION['form_token'] = $form_token;

$error = new Error();

if(!isset($_POST['form_datum_key'], $_POST['form_cost_key']))
{
        $error->push(_('One or more fields are missing.'));
}
else
/*
if(!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}->[0-9]{4}-[0-9]{2}-[0-9]{2}->[0-9]{1}$/", $_POST['form_cost_key']))
*/

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']))
{
        $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);

        // retrieve costs
        $data             = $_SESSION['data'];
        $datum            = $data->getItem($form_datum_key);
        $tracker          = $datum->getPath();

        $costs            = $datum->getCosts();
        $cost             = $costs->getItem($form_cost_key);

        $cost_start       = $cost->getInterval()->getStart();
        $cost_start_year  = $cost_start->format('Y');
        $cost_start_month = $cost_start->format('m');
        $cost_start_day   = $cost_start->format('d');

        $cost_end         = $cost->getInterval()->getEnd();
        $cost_end_year    = $cost_end->format('Y');
        $cost_end_month   = $cost_end->format('m');
        $cost_end_day     = $cost_end->format('d');

        $cost_subscription      = $cost->getSubscription();
        $cost_connsumption         = $cost->getConsumption();
}
?>

<div id="page_form_devices_modify">
        <h1>
                <?php echo _('Modify Cost'); ?>
        </h1>

        <?php
        $id = link_get_id_from_filename("form_cost_modify_submit.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>
       
        <fieldset>
                <legend>
                        <?php
                        $data       = $_SESSION['data'];
                        $datum      = $data->getItem($form_datum_key);
                        $datum_name = $datum->getName();
                        echo "$datum_name";
                        ?>
                </legend>

                <label for="form_start_date">
                        <?php echo _('Start'); ?>:
                </label>
               
                <?php
                include_once('ymd.php');
                form_create_day('form_start_day', $cost_start_day);
                form_create_month('form_start_month', $cost_start_month);
                form_create_year('form_start_year', $cost_start_year);
                ?>
                <br/>

                <label for="form_end_date">
                        <?php echo _('End'); ?>:
                </label>
                <?php
                include_once('ymd.php');
                form_create_day('form_end_day', $cost_end_day);
                form_create_month('form_end_month', $cost_end_month);
                form_create_year('form_end_year', $cost_end_year);
                ?>
                <br/>

                <label for="cost_subscription">
                        <?php echo _('Subscription'); ?>:
                </label>
                <input type="text" id="form_cost_subscription" name="form_cost_subscription" value=<?php echo "$cost_subscription"; ?>  placeholder="12.34 €" />
                <br/>

                <label for="cost_connsumption">
                        <?php echo _('Consumption'); ?>:
                </label>
                <input type="text" id="form_cost_connsumption" name="form_cost_connsumption" value=<?php echo "$cost_connsumption"; ?> placeholder="12.34 €" />
                        <?php echo _('unit (m^3, kWh)'); ?>
                <br/>

                <hr/>
                <div class="buttons">
                        <input type="hidden" name="form_datum_key" value="<?php echo $form_datum_key; ?>" />
                        <input type="hidden" name="form_cost_key" value="<?php echo $form_cost_key; ?>" />
                        <input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
                        <input type="submit" value=<?php echo _('OK'); ?> id="form_update" alt="update" />
                        <input type="submit" value=<?php echo _('Cancel');?> id="form_cancel" name="form_cancel" alt="cancel" />
                </div>

        </fieldset>
        </form>
        <?php echo $error->display(); ?>
</div>