ManageServerGroupMembers.csp


<%@ Language=JavaScript%>

<%

// This file is called from ChooseServerGroupMembers.csp.

// Depending on the button clicked:

// A server is added or removed from the selected server group.

// A group associate is added or deleted from the server group.

%>

<!-- #include file="RetrieveIStore.csp" -->

<!-- #include file=helper_js.csp -->

<html>

<body>

<%


function AddServerGroupMember(IStore, ServerGroupId, ServerName)

// This function adds a server to a server group.


// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

// ServerName - The InfoObject Title of the selected Server object.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_GROUP_MEMBERS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");


        // Add the server. Note you are handing it the Server InfoObject's Title.

        ServerGroup.Servers.Add(ServerName);


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };

}


function DeleteServerGroupMember(IStore, ServerGroupId, MemberName)

// This function deletes a server from a server group.


// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

// MemberName - The InfoObject Title of the selected Server object.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_GROUP_MEMBERS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");

    

        // Delete the selected server by passing the Server InfoObject's Title.

        ServerGroup.Servers.Delete(MemberName);


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };

}


function ClearServers(IStore, ServerGroupId)

// This function deletes all servers from a server group.


// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_GROUP_MEMBERS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");


        // Clear all servers from the group.

        ServerGroup.Servers.Clear();


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };

}


function AddGroupAssociate(IStore,ServerGroupId, GroupID)

// This function adds a server group associate to a server group.

// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

//                   This is the main server group.

// GroupID - The InfoObject ID of the selected ServerGroup object.

//             This is the group associate.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_SUBGROUPS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");


        // Add the server group associate.

        // The ID of the server group is added to the collection.

        ServerGroup.SubGroups.Add(GroupID);


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };        

}


function DeleteGroupAssociate(IStore, ServerGroupId, GroupID)

// This function deletes a server group associate from a server group.

// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

//                   This is the main server group.

// GroupID - The InfoObject ID of the selected ServerGroup object.

//             This is the group associate.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_SUBGROUPS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");


        // Concatenate # with the ID and give it to the

        // Delete method. If you give it just the ID, it will

        // treat it as an array index and remove the wrong server.

        ServerGroup.SubGroups.Delete("#" + GroupID);


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };

}


function ClearGroups(IStore, ServerGroupId)

// This function deletes all associates from the group.

// Parameters:

// IStore - The InfoStore object.

// ServerGroupId - The InfoObject ID of the selected ServerGroup object.

{

    try{

        // Query for the selected server group.

        var ServerGroups = IStore.Query

        ("SELECT SI_SUBGROUPS FROM CI_SYSTEMOBJECTS WHERE SI_ID="+ServerGroupId);


        // Get the ServerGroup object.

        ServerGroup = ServerGroups.Item(1).PluginInterface("");


        // Clear all group associates from the group.

        ServerGroup.SubGroups.Clear();


        // Save the changes to the APS.

        IStore.Commit(ServerGroups);

    }

    catch (e){

        Response.Write("Error");

        return;

    };

}


function Main()

{

    IStore = RetrieveIStore();

    if (IStore == null)

    {

        Response.Redirect ("Start.csp");

        return;

    }

    ServerGroupId = String(Request.QueryString.Item("ServerGroupId"));

    // Depending on what the user selected in ChooseServerGroupMembers.csp:

    //  - Add or remove the server from the group.

    //  - Add or remove the group associate from the group.

    // Then return to the page.

    if (Request.Form.Item("AddServer") == "Add a server")

    {

        ServerName = String(Request.Form.Item("ServerName"));

        AddServerGroupMember(IStore,ServerGroupId, ServerName);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }

    if (Request.Form.Item("RemoveServer") == "Remove a server")

    {

        MemberName = String(Request.Form.Item("MemberName"));

        DeleteServerGroupMember(IStore,ServerGroupId, MemberName);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }

    if (Request.Form.Item("ClearServers") == "Clear all servers")

    {

        ClearServers(IStore,ServerGroupId);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }


    if (Request.Form.Item("AddGroup") == "Add a group")

    {

        GroupID = Number(Request.Form.Item("GroupID"));

        Response.Write("GROUPID: " + GroupID + "<BR>")

        AddGroupAssociate(IStore,ServerGroupId, GroupID);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }

    if (Request.Form.Item("RemoveGroup") == "Remove a group")

    {

        SubGroupID = String(Request.Form.Item("SubGroupID"));

        Response.Write("GROUPID" + SubGroupID + "<BR>")

        DeleteGroupAssociate(IStore,ServerGroupId, SubGroupID);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }

    if (Request.Form.Item("ClearGroups") == "Clear all groups")

    {

        ClearGroups(IStore,ServerGroupId);

        Response.Redirect ("ChooseServerGroupMembers.csp?ServerGroupId="+ServerGroupId);

    }

}


Main();

    

%>

</body>

</html>




Crystal Decisions, Inc.
http://www.crystaldecisions.com
Support services:
http://support.crystaldecisions.com