Subversion Repositories portal2

Rev

Rev 695 | 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
include_once('auth_check.php');
?>

<?php

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

$error = new Error();

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

        elseif($_POST['form_data'] == 'load')
        {
                $config = ConfigurationFactory::createInstance(
                        $_SESSION['root_folder']['config']['']);
                $config->load();

                $error->push(_('Configuration load successfully.'));
        }
}
elseif(isset($_POST['data_submit_save']))
{
        if(!isset($_POST['form_token'], $_POST['form_data']))
        {
                $error->push(_('One or more fields are missing.'));
        }

        else
        if($_POST['form_data'] == 'save')
        {
                $config = ConfigurationFactory::createInstance(
                        Configuration::CONFIG_DEFAULT_DIR);
                $config->save();

                $error->push(_('Configuration saved successfully.'));
        }
}
else
{
        ///
}

?>

<div id="page_form_config">
        <h1>
                <?php echo _('Configuration'); ?>
        </h1>

        <p>
                <?php echo _('This page allow you to save/restore your configuration data.'); ?>
                <br />
        </p>

        <?php
        $id = link_get_id_from_filename("form_config.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>

        <fieldset>
                <p>
                        <?php echo _('Save parameters.'); ?>
                </p>
               
                <hr/>
               
                <div class="buttons">
                        <input type="hidden" name="form_data" value="save" />
                        <input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
                        <input type="submit" value=<?php echo _('OK'); ?> id="data_submit_save" name="data_submit_save" alt="save" />
                </div>
        </fieldset>
        </form>

        <br/>

        <?php
        $id = link_get_id_from_filename("form_config.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>

        <fieldset>
                <p>
                        <?php echo _('Restore parameters.'); ?>
                </p>

                <hr/>
               
                <div class="buttons">
                        <input type="hidden" name="form_data" value="load" />
                        <input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
                        <input type="submit" value=<?php echo _('OK'); ?> id="data_submit_load" name="data_submit_load" alt="restore" />
                </div>

        </fieldset>
        </form>

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

</div>