Subversion Repositories portal2

Rev

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

?>

<div id="page_form_trackers_add_submit">
        <h1>
                <?php echo _('Add data to a group'); ?>
        </h1>
</div>

<?php

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

if(count($_POST) < 3)
{
        $error->push(_('One or more argument(s) is/are missing.'));
}
elseif(!isset($_POST['form_token'], $_POST['form_add']))
{
        $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['form_cancel']))
{
        $error->push(_('Operation aborted.'));
}
else
{
        if($_SESSION['data'])
        {
                $park = $_SESSION['park'];
                $data = $_SESSION['data'];

                foreach($_POST as $key => $elt)
                {
                        $array = str_getcsv($key, ':');
                        if(count($array) != 3)
                        {
                                continue;
                        }
                        //var_dump($array);

                        if(!isset($_SESSION['groups']))
                        {
                                $_SESSION['groups'] = GroupsFactory::createCollection('', '');
                        }
                        $groups       = $_SESSION['groups'];

                        $tracker      = $park->getTrackerFromPath($key);
                        $tracker_name = $tracker->getName();
                        $tracker_key  = $key;

                        $group        = new Group($tracker_name);
                        $group->setPath($key);
                        //$group->setRank($form_group_rank);

                        $group_name   = "$tracker_name";

                        if($groups->isItemExists($group_name))
                        {
                                //$error->push("Tracker already exists. Choose another name.";
                                //$ok = false;
                        }
                        else
                        {
                                $groups->addItem($tracker_key, $group);

                                $error->push(_('Item added to the group.'));
                                echo "<br/>\n";
                                $ok = true;
                        }
                }
        }

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

echo $error->display();

/* Redirection */
if(isset($_POST['form_cancel']) || ($ok === true))
{
        $id = link_get_id_from_filename("form_data_add.php");
        $refresh = $_SESSION['refresh_redirection'];
        echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";
}
else if($ok == false)
{
        $id = link_get_id_from_filename("form_groups_add.php");
        $refresh = $_SESSION['refresh_redirection'];
        echo "<meta http-equiv=\"refresh\" content=\"$refresh; URL=index.php?id_page=$id\">";
}

?>