Subversion Repositories portal2

Rev

Rev 699 | 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

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

if(!isset($_POST['form_token'], $_POST['form_tracker_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']))
{
        echo '???';
        $error->push(_('Operation aborted.'));

        $id      = link_get_id_from_filename("trackers_list.php");
        $refresh = $_SESSION['refresh_redirection'];
        echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";
}
else
{
        $form_tracker_key = filter_var($_POST['form_tracker_key'], FILTER_SANITIZE_STRING);
}

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

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

        $device        = $park->getDeviceFromPath($form_tracker_key);
        $device_name   = $device->getName();

        $sensor        = $park->getSensorFromPath($form_tracker_key);
        $sensor_name   = $sensor->getName();

        $variable      = $park->getVariableFromPath($form_tracker_key);
        $variable_name = $variable->getName();
}
else
{
        $error->push(_('Internal error.'));
}
?>

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

        <?php
        $id = link_get_id_from_filename("form_trackers_modify_submit.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>
        <fieldset>
                <legend>
                        <?php echo $device_name . ':' . $sensor_name . ':' . $variable_name; ?>
                </legend>


                <?php
                if(isset($_SESSION['park']))
                {
                        $tracker        = $device->getTracker($form_tracker_key);

                        $tracker_name   = $tracker->getName();
                        $tracker_offset = $tracker->getOffset();
                        if($tracker_offset == null)
                        {
                                $tracker_offset = 0;
                        }
                        $tracker_step   = $tracker->getStep();
                        if($tracker_step == null)
                        {
                                $tracker_step = 1;
                        }
                        $tracker_index= $tracker->getIndex();
                        $tracker_unit = $tracker->getUnit();

                        $select       = "\n";
                        $select .= "<label for=\"form_variable_key\">Variable:</label>\n";
                        $select .= "<select name=\"form_variable_key\" id=\"form_variable_key\">\n";

                        foreach($sensor as $key => $variable)
                        {
                                $name         = $variable->getName();
                                $variable_key = $key;
                                //echo $key; echo " < br />";
                                //echo $name; echo " < br />";

                                $selected     = ($name == $variable_name) ? "selected" : "";
                                $select .= "  <option label=\"$variable_key\" value=\"$variable_name\" $selected readonly=\"readonly\"> $name </option>\n";
                        }

                        $select .= "</select>\n";
                        echo $select;
                }
                ?>
                <br/>

                <label for="form_tracker_name">
                        Name:
                </label>
                <input type="text" id="form_tracker_name" name="form_tracker_name" value=<?php echo "\"$tracker_name\"" ?> placeholder="Compteur_eau_1" />
                <br/>

                <label for="form_tracker_step">
                        Step:
                </label>
                <input type="text" id="form_tracker_step" name="form_tracker_step" value=<?php echo "$tracker_step" ?> />
                <br/>

                <label for="form_tracker_offset">
                        Offset:
                </label>
                <input type="text" id="form_tracker_offset" name="form_tracker_offset" value=<?php echo "$tracker_offset" ?> />
                <br/>

                <label for="form_tracker_unit">
                        Unit:
                </label>
                <input type="text" id="form_tracker_unit" name="form_tracker_unit" value=<?php echo "$tracker_unit" ?> />
                <br/>

                <label for="form_tracker_index">
                        Index:
                </label>
                <input type="text" id="form_tracker_index" name="form_tracker_index" value=<?php echo "$tracker_index" ?> readonly="readonly" disabled />
                <br/>

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

        </fieldset>
        </form>

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