ModifyGroupMembership.csp


<%@ Language=JavaScript%>

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

<html>

<body>

<%

    

function AddUserToNewGroup(IStore, UserID, NewGroupName)

{

    // Retrieve the Plugin Manager.

    var PluginMgr = IStore.PluginManager;

    // Retrieve the UserGroup interface.

    var UserPlugin = PluginMgr.PluginInfo("CrystalEnterprise.UserGroup");

    // Create a new InfoObjects collection.

    var NewInfoObjects  = IStore.NewInfoObjectCollection();

    // Add the UserGroup interface to the new InfoObjects collection.

    NewInfoObjects.Add (UserPlugin);

    // Get the new UserGroup object.

    var NewUser = NewInfoObjects.Item(1);

    // Set the UserGroup properties.

    NewUser.Title = NewGroupName;

    // Add a User to the new UserGroup.

    NewUser.PluginInterface("").Users.Add(Number(UserID));

    // Commit the changes to the APS.

    IStore.Commit (NewInfoObjects);

    Response.Write ("Done");

}


function RemoveUserFromGroup(IStore, UserID, GroupID)

{

    Response.Write("Removing user with ID " + UserID + " from group with ID " + GroupID + "<BR>");

    // Retrieve the User you wish to remove from the group.

    var Result = IStore.Query("SELECT SI_ID, SI_USERGROUPS FROM CI_SYSTEMOBJECTS WHERE    SI_ID="+UserID);

    

    if (Result.Count == 0)

    {    

        return false;

    }


    // Retrieve the User Object.

    var User = Result.Item(1);

    // Retrieve the Groups collection.

    var MemberGroups = User.PluginInterface("").Groups;

    // Delete the Group from the collection.

    MemberGroups.Delete("#"+GroupID);

    IStore.Commit (Result);

    Response.Write ("Done");

}


function AddUserToGroup(IStore, UserID, GroupID)

{

    Response.Write("Adding user with ID " + UserID + " to group with ID " + GroupID);

    // Retrieve the User object you want to add the Group to.

    var Result = IStore.Query("SELECT SI_ID FROM CI_SYSTEMOBJECTS WHERE SI_ID="+UserID);


    if (Result.Count == 0)

    {    

        return false;

    }

    

    // Retrieve the User Object.

    var User = Result.Item(1);

    // Retrieve the Groups collection.

    var MemberGroups = User.PluginInterface("").Groups;

    // Add the Group to the collection.

    MemberGroups.Add(Number(GroupID));

    Response.Write ("<BR>Now ID for group is " + GroupID);

    IStore.Commit (Result);

}


function Main()

{

    IStore = RetrieveIStore();

    if (IStore == null)

    {

        Response.Redirect("Start.csp");

        return;

    }

    var UserID = Request.QueryString.Item ("UserID");

    var NewGroupName = Request.Form.Item("NewGroupName");    

    var AvailableGroupID = Request.Form.Item("GroupList");

    var GroupMemberID = Request.Form.Item("MemberGroups");


    if (Request.Form.Item("Add") == "Add user to group") AddUserToGroup(IStore,UserID,AvailableGroupID);

    if (Request.Form.Item("Remove") == "Remove user from group") RemoveUserFromGroup(IStore,UserID,GroupMemberID);

    if (Request.Form.Item("New") =="Create") AddUserToNewGroup(IStore,UserID, NewGroupName);

}


Main();

    

%>

</body>

</html>





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