Subversion Repositories portal2

Rev

Rev 708 | 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();
$park = $_SESSION['park'];

if($park && $park->countDevices() > 0)
{
        $device_keys     = $park->getDevicesKeys();
       
        if(isset($_POST['form_device_key']))
        {
                $form_device_key = $_POST['form_device_key'];
        }
        else
        {
                $form_device_key = $device_keys[0];            
        }
       
        $device          = $park->getDeviceFromPath($form_device_key);
        $uuid            = $device->getUuid();
        $cfg             = SsmtpConfFactory::createInstance($uuid);
}
else
{
        $form_device_key = null;
}

if(isset($_POST['form_mail_submit']))
{
        if(!isset( $_POST['form_mail_hub'], $_POST['form_mail_address'], $_POST['form_token']))
        {
                $error->push(_('Please enter a valid mail hub (IP or DN).'));
        }
        elseif(strlen( $_POST['form_mail_hub']) > 32 || strlen($_POST['form_mail_hub']) < 4)
        {
                $error->push(_('Mail hub must have [4-32] characters.'));
        }
        elseif(strlen( $_POST['form_mail_address']) > 32 || strlen($_POST['form_mail_address']) < 4)
        {
                $error->push(_('Mail address must have [4-32] characters.'));
        }
        else
        {
                $form_mail_hub     = filter_var($_POST['form_mail_hub'], FILTER_SANITIZE_STRING);
                $form_mail_address = filter_var($_POST['form_mail_address'], FILTER_SANITIZE_STRING);

                $cfg->mail_hub = $form_mail_hub;
                $cfg->mail_address = $form_mail_address;

                try
                {
                        $cfg->save();  
                }      
                catch (MyException $e)
                {
                        $error->push($e->getErrorReport());
                }      
               
                $error->push(_('Parameters updated.'));
        }
}
else
{
        //
}

//if(isset($_POST['form_mail_refresh']))
{
        try
        {
                $cfg->load();  
        }      
        catch (MyException $e)
        {
                $error->push($e->getErrorReport());
        }      

        $form_mail_hub     = $cfg->mail_hub;
        $form_mail_address = $cfg->mail_address;
}

?>

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

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

        // Create device list form
        if(isset($_SESSION['park']) && ($_SESSION['park']->CountDevices() > 1))
        {
                $park = $_SESSION['park'];

                echo "<label for=\"form_device_key\">" . _('Device:') . "</label>";

                $select = "\r\n";
                $select .= "<select name=\"form_device_key\" id=\"form_device_key\">";

                if($park && $park->countDevices() > 0)
                {
                        foreach($park as $key => $device)
                        {
                                $device_name = $device->getName();

                                if($key == $form_device_key)
                                $select .= "<option value=\"$key\" selected=\"selected\"> $device_name </option>";
                                else
                                $select .= "<option value=\"$key\"> $device_name </option>";
                        }
                }

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

                echo "<input type=\"submit\" value=\"Select\" id=\"form_mail_refresh\" name=\"form_mail_refresh\" />";
        }
        ?>
        </form>

        <br/>

        <?php
        $id = link_get_id_from_filename("form_mail.php");
        echo "<form action=\"index.php?id_page=$id\" method=\"post\">";
        ?>
        <fieldset>
                <legend>
                        <?php echo _('Parameters'); ?>
                </legend>

                <label for="form_mail_hub">
                        <?php echo _('Mail Hub'); ?>:
                </label>
                <input type="text" id="form_mail_hub" name="form_mail_hub" value=<?php echo "\"$form_mail_hub\""; ?> />
                <br/>

                <label for="form_mail_address">
                        <?php echo _('Mail Address'); ?>:
                </label>
                <input type="text" id="form_mail_address" name="form_mail_address" value=<?php echo "\"$form_mail_address\""; ?> />
                <br/>

                <p>
                        <?php echo _('Mail Hub has to be a valid SMTP server (ISP)'); ?>.
                </p>

                <hr/>
                <div class="buttons">
                        <input type="hidden" name="form_token" value="<?php echo $form_token; ?>" />
                        <input type="hidden" name="form_device_key" value="<?php echo $form_device_key; ?>" />
                        <input type="submit" name="form_mail_submit" id="form_mail_submit" value=<?php echo _('Update'); ?> alt="update" />
                </div>

        </fieldset>
        </form>

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

</div>