if (isset($_POST['action'])) {
	$action = $_POST['action'];
} else if (isset($_GET['action'])) {
	$action = $_GET['action'];
}

switch ($action) {

case 'group_update':
	$id = -1;
	$newname = "";
	if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']))  { $id = intval($_REQUEST['id']); }
	if( isset($_REQUEST['gname']) && (strlen($_REQUEST['gname'])>0) )  { $newname = $_REQUEST['gname']; }
	
	if($id >= 0 && $newname != "") weathermap_group_update($id,$newname);
	if($id < 0 && $newname != "") weathermap_group_create($newname);
	header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin");	
	
	break;

case 'groupadmin_delete':

	$id = -1;
	
	if( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']))  { $id = intval($_REQUEST['id']); }
	
	if($id>=1)
	{
		weathermap_group_delete($id);
	}
	header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin");	
}
switch ($action) {
    case 'group_update':
        $id = -1;
        $newname = "";
        if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
            $id = intval($_REQUEST['id']);
        }
        if (isset($_REQUEST['gname']) && strlen($_REQUEST['gname']) > 0) {
            $newname = $_REQUEST['gname'];
        }
        if ($id >= 0 && $newname != "") {
            weathermap_group_update($id, $newname);
        }
        if ($id < 0 && $newname != "") {
            weathermap_group_create($newname);
        }
        header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin");
        break;
    case 'groupadmin_delete':
        $id = -1;
        if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
            $id = intval($_REQUEST['id']);
        }
        if ($id >= 1) {
            weathermap_group_delete($id);
        }
        header("Location: weathermap-cacti-plugin-mgmt.php?action=groupadmin");
        break;
    case 'group_form':
        $id = -1;