/**
     * Build the content for this action
     * 
     * @return void
     * @access public
     * @since 4/26/05
     */
    function buildContent()
    {
        $defaultTextDomain = textdomain("polyphony");
        $actionRows = $this->getActionRows();
        $pageRows = new Container(new YLayout(), OTHER, 1);
        $harmoni = Harmoni::instance();
        // start our namespace
        $harmoni->history->markReturnURL("polyphony/authorization/edit_authorizations");
        $harmoni->request->startNamespace("polyphony-authorizations");
        $harmoni->request->passthrough();
        $agentManager = Services::getService("Agent");
        $idManager = Services::getService("Id");
        $everyoneId = $idManager->getId("edu.middlebury.agents.everyone");
        $usersId = $idManager->getId("edu.middlebury.agents.users");
        /*********************************************************
         * Buttons
         *********************************************************/
        ob_start();
        print "<table width='100%'><tr><td align='left'>";
        print "<a href='" . $harmoni->request->quickURL("admin", "main") . "'><button>" . _("Return to the Admin Tools") . "</button></a>";
        print "</td><td align='right'>";
        print "<input type='button'";
        print " onclick='Javascript:submitAgentChoice()'";
        print " value='" . _("Edit Authorizations for the selected User/Group") . " --&gt;' />";
        print "</td></tr></table>";
        $submit = new Block(ob_get_contents(), STANDARD_BLOCK);
        $actionRows->add($submit, "100%", null, LEFT, CENTER);
        ob_end_clean();
        // Users header
        $actionRows->add(new Heading("Users", 2), "100%", null, LEFT, CENTER);
        /*********************************************************
         * the agent search form
         *********************************************************/
        ob_start();
        $self = $harmoni->request->quickURL();
        $lastCriteria = $harmoni->request->get('search_criteria');
        $search_criteria_name = RequestContext::name('search_criteria');
        $search_type_name = RequestContext::name('search_type');
        print _("Search For Users") . ": ";
        print <<<END
\t\t<form action='{$self}' method='post'>
\t\t\t<div>
\t\t\t<input type='text' name='{$search_criteria_name}' value='{$lastCriteria}' />
\t\t\t<br /><select name='{$search_type_name}'>
END;
        $searchTypes = $agentManager->getAgentSearchTypes();
        while ($searchTypes->hasNext()) {
            $type = $searchTypes->next();
            $typeString = $type->getDomain() . "::" . $type->getAuthority() . "::" . $type->getKeyword();
            print "\n\t\t<option value='" . htmlspecialchars($typeString, ENT_QUOTES) . "'";
            if ($harmoni->request->get("search_type") == $typeString) {
                print " selected='selected'";
            }
            print ">" . htmlspecialchars($typeString) . "</option>";
        }
        print "\n\t</select>";
        print "\n\t<br /><input type='submit' value='" . _("Search") . "' />";
        print "\n\t<a href='" . $harmoni->request->quickURL() . "'>";
        print "\n\t\t<input type='button' value='" . _("Clear") . "' />\n\t</a>";
        print "\n</div>\n</form>";
        $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK));
        ob_end_clean();
        /*********************************************************
         * Form and Javascript
         *********************************************************/
        // In order to preserve proper nesting on the HTML output put the form
        // around the row layout
        ob_start();
        $errorString = _("You must select a User or Group.");
        $agentFieldName = RequestContext::name("agentId");
        print <<<END
\t\t
\t\t<script type='text/javascript'>
\t\t//<![CDATA[ 
\t\t
\t\t\t// Make sure a selection has been made and submit if it has.
\t\t\tfunction submitAgentChoice() {
\t\t\t\tvar f;\t\t
\t\t\t\tfor (i = 0; i < document.forms.length; i++) {
\t\t\t\t\tf = document.forms[i];\t\t\t
\t\t\t\t\tif (f.id == 'chooseform') {
\t\t\t\t\t\tvar form = f;
\t\t\t\t\t\tbreak;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t
\t\t\t\tvar radioArray = form.agentId;
\t\t\t\tvar isChecked = false;
\t\t\t\t
\t\t\t\tfor (i=0; i<radioArray.length; i++) {
\t\t\t\t\tif (radioArray[i].checked) {
\t\t\t\t\t\tisChecked = true;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t
\t\t\t\tif (isChecked) {
\t\t\t\t\tform.submit();
\t\t\t\t} else {
\t\t\t\t\talert("{$errorString}");
\t\t\t\t}
\t\t\t}
\t\t\t
\t\t//]]> 
\t\t</script>
\t\t
END;
        print "<form id='chooseform' method='post' action='" . $harmoni->request->quickURL("authorization", "edit_authorizations") . "'>\n";
        $pageRows->setPreHTML(ob_get_contents());
        ob_end_clean();
        $pageRows->setPostHTML("</form>");
        /*********************************************************
         * the agent search results
         *********************************************************/
        $search_criteria = $harmoni->request->get("search_criteria");
        $search_type = $harmoni->request->get("search_type");
        if ($search_criteria && $search_type) {
            $typeParts = explode("::", $search_type);
            $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
            $agents = new MultiIteratorIterator();
            $agents->addIterator($agentManager->getGroupsBySearch($search_criteria, $searchType));
            $agents->addIterator($agentManager->getAgentsBySearch($search_criteria, $searchType));
            print <<<END
\t\t
\t\t
\t\t<table>
\t\t\t<tr>
\t\t\t\t<td valign='top'>
\t\t\t\t\t<div style='
\t\t\t\t\t\tborder: 1px solid #000; 
\t\t\t\t\t\twidth: 15px; 
\t\t\t\t\t\theight: 15px;
\t\t\t\t\t\ttext-align: center;
\t\t\t\t\t\ttext-decoration: none;
\t\t\t\t\t\tfont-weight: bold;
\t\t\t\t\t'>
\t\t\t\t\t\t-
\t\t\t\t\t</div>
\t\t\t\t</td>
\t\t\t\t<td>
END;
            print "\n\t\t\t" . _("Search Results");
            print <<<END
\t\t\t\t</td>
\t\t\t</tr>
\t\t</table>
\t\t<div style='
\t\t\tmargin-left: 13px; 
\t\t\tmargin-right: 0px; 
\t\t\tmargin-top:0px; 
\t\t\tpadding-left: 10px;
\t\t\tborder-left: 1px solid #000;
\t\t'>
END;
            while ($agents->hasNext()) {
                $agent = $agents->next();
                if ($agent->isGroup()) {
                    $this->printGroup($agent);
                } else {
                    $this->printMember($agent);
                }
                print "<br />";
            }
            print "\n</div>";
            $pageRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
            ob_end_clean();
        }
        /*********************************************************
         * Groups
         *********************************************************/
        // Users header
        $pageRows->add(new Heading(_("Groups"), 2), "100%", null, LEFT, CENTER);
        // Loop through all of the Groups
        $childGroupIds = array();
        $groups = $agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
        while ($groups->hasNext()) {
            $group = $groups->next();
            $groupId = $group->getId();
            // Create a layout for this group using the GroupPrinter
            ob_start();
            GroupPrinter::printGroup($group, $harmoni, 2, array($this, "printGroup"), array($this, "printMember"));
            $groupLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
            ob_end_clean();
            $pageRows->add($groupLayout, "100%", null, LEFT, CENTER);
        }
        $pageRows->add($submit, "100%", null, LEFT, CENTER);
        $actionRows->add($pageRows);
        $harmoni->request->endNamespace();
        textdomain($defaultTextDomain);
    }
    /**
     * Print a group and the expanded children (other groups or members)
     * 
     * @param object $group
     * @param string $printGroupFunction Prints current group in group format.
     * @param string $printMemberFunction Prints current group in member format.
     * @return void
     * @access public
     * @since 11/8/04
     */
    public static function printGroup($group, $harmoni, $startingPathInfoKey, $printGroupFunction, $printMemberFunction)
    {
        // Get a string of our groupIds
        $groupId = $group->getId();
        $groupIdString = urlencode($groupId->getIdString());
        // Break the path info into parts for the enviroment and parts that
        // designate which groups to expand.
        $environmentInfo = array();
        $expandedGroups = array();
        if ($tmp = $harmoni->request->get("expandedGroups")) {
            $expandedGroups = explode(",", $tmp);
        }
        print "\n\n<table>\n\t<tr><td valign='top'>";
        // Print The Group
        print <<<END

<div style='
border: 1px solid #000; 
width: 15px; 
height: 15px;
text-align: center;
text-decoration: none;
font-weight: bold;
'>

END;
        // The child groups are already expanded for this group.
        // Show option to collapse the list.
        if (in_array($groupIdString, $expandedGroups)) {
            $groupsToRemove = array($groupIdString);
            $newGroups = array_diff($expandedGroups, $groupsToRemove);
            $url = $harmoni->request->mkURL();
            $url->setValue("expandedGroups", implode(",", $newGroups));
            print "<a style='text-decoration: none;' href='";
            print $url->write();
            print "'>-</a>";
            // The group is not already expanded.  Show option to expand.
        } else {
            $newGroups = $expandedGroups;
            $newGroups[] = $groupIdString;
            print "<a style='text-decoration: none;' href='";
            $url = $harmoni->request->mkURL();
            $url->setValue("expandedGroups", implode(",", $newGroups));
            print $url->write();
            print "'>+</a>";
        }
        print "\n\t\t</div>";
        print "\n\t</td><td valign='top'>\n\t\t";
        call_user_func_array($printGroupFunction, array($group));
        print "\n\t</td></tr>\n</table>";
        // If the group was expanded, we need to recursively print its children.
        if (in_array($groupIdString, $expandedGroups)) {
            print <<<END

<div style='
\tmargin-left: 13px; 
\tmargin-right: 0px; 
\tmargin-top:0px; 
\tpadding-left: 10px;
\tborder-left: 1px solid #000;
'>

END;
            $childGroups = $group->getGroups(false);
            $childMembers = $group->getMembers(false);
            while ($childGroups->hasNext()) {
                $childGroup = $childGroups->next();
                GroupPrinter::printGroup($childGroup, $harmoni, $startingPathInfoKey, $printGroupFunction, $printMemberFunction);
            }
            // And finally print all the members for the group
            while ($childMembers->hasNext()) {
                $childMember = $childMembers->next();
                print "\n\n<table>\n\t<tr><td valign='top'>";
                print "\n\t\t<div style='width: 15px;'>&nbsp;</div>";
                print "\n\t</td><td valign='top'>\n\t\t";
                call_user_func_array($printMemberFunction, array($childMember));
                print "\n\t</td></tr>\n</table>";
            }
            print "\n</div>";
        }
    }
    /**
     * Build the content for this action
     * 
     * @return void
     * @access public
     * @since 4/26/05
     */
    function buildContent()
    {
        $defaultTextDomain = textdomain("polyphony");
        $actionRows = $this->getActionRows();
        $pageRows = new Container(new YLayout(), OTHER, 1);
        $harmoni = Harmoni::instance();
        $harmoni->request->startNamespace("polyphony-agents");
        $agentManager = Services::getService("Agent");
        $idManager = Services::getService("Id");
        $everyoneId = $idManager->getId("edu.middlebury.agents.everyone");
        $usersId = $idManager->getId("edu.middlebury.agents.users");
        /*********************************************************
         * the agent search form
         *********************************************************/
        // Users header
        $actionRows->add(new Heading(_("Users"), 2), "100%", null, LEFT, CENTER);
        ob_start();
        $self = $harmoni->request->quickURL();
        $lastCriteria = $harmoni->request->get("search_criteria");
        $search_criteria_name = RequestContext::name("search_criteria");
        $search_type_name = RequestContext::name("search_type");
        print _("Search For Users") . ": ";
        print <<<END
\t\t<form action='{$self}' method='post'>
\t\t\t<div>
\t\t\t<input type='text' name='{$search_criteria_name}' value='{$lastCriteria}' />
\t\t\t<br /><select name='{$search_type_name}'>
END;
        $searchTypes = $agentManager->getAgentSearchTypes();
        while ($searchTypes->hasNext()) {
            $type = $searchTypes->next();
            $typeString = htmlspecialchars($type->getDomain() . "::" . $type->getAuthority() . "::" . $type->getKeyword());
            print "\n\t\t<option value='{$typeString}'";
            if ($harmoni->request->get("search_type") == $typeString) {
                print " selected='selected'";
            }
            print ">{$typeString}</option>";
        }
        print "\n\t</select>";
        print "\n\t<br /><input type='submit' value='" . _("Search") . "' />";
        print "\n\t<a href='" . $harmoni->request->quickURL() . "'>";
        print "<input type='button' value='" . _("Clear") . "' /></a>";
        print "\n</div>\n</form>";
        $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
        ob_end_clean();
        /*********************************************************
         * the agent search results
         *********************************************************/
        ob_start();
        if (($search_criteria = $harmoni->request->get('search_criteria')) && ($search_type = $harmoni->request->get('search_type'))) {
            $typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8'));
            $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
            $agents = $agentManager->getAgentsBySearch($search_criteria, $searchType);
            print "search: " . $search_criteria;
            print <<<END
\t\t
\t\t
\t\t<table>
\t\t\t<tr>
\t\t\t\t<td valign='top'>
\t\t\t\t\t<div style='
\t\t\t\t\t\tborder: 1px solid #000; 
\t\t\t\t\t\twidth: 15px; 
\t\t\t\t\t\theight: 15px;
\t\t\t\t\t\ttext-align: center;
\t\t\t\t\t\ttext-decoration: none;
\t\t\t\t\t\tfont-weight: bold;
\t\t\t\t\t'>
\t\t\t\t\t\t-
\t\t\t\t\t</div>
\t\t\t\t</td>
\t\t\t\t<td>
END;
            print "\n\t\t\t" . _("Search Results");
            print <<<END
\t\t\t\t</td>
\t\t\t</tr>
\t\t</table>
\t\t<div style='
\t\t\tmargin-left: 13px; 
\t\t\tmargin-right: 0px; 
\t\t\tmargin-top:0px; 
\t\t\tpadding-left: 10px;
\t\t\tborder-left: 1px solid #000;
\t\t'>
END;
            while ($agents->hasNext()) {
                $agent = $agents->next();
                group_browseAction::printMember($agent);
                print "<br />";
            }
            print "\n</div>";
            $pageRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
            ob_end_clean();
        }
        /*********************************************************
         * Groups
         *********************************************************/
        $pageRows->add(new Heading(_("Groups"), 2), "100%", null, LEFT, CENTER);
        // Loop through all of the Root Groups
        $childGroupIds = array();
        $groups = $agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
        while ($groups->hasNext()) {
            $group = $groups->next();
            $groupId = $group->getId();
            // Create a layout for this group using the GroupPrinter
            ob_start();
            GroupPrinter::printGroup($group, $harmoni, 2, array($this, "printGroup"), array($this, "printMember"));
            $groupLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
            ob_end_clean();
            $pageRows->add($groupLayout, "100%", null, LEFT, CENTER);
        }
        // In order to preserve proper nesting on the HTML output, the checkboxes
        // are all in the pagerows layout instead of actionrows.
        $actionRows->add($pageRows, null, null, CENTER, CENTER);
        textdomain($defaultTextDomain);
        $harmoni->request->endNamespace();
    }
    /**
     * Build the content for this action
     * 
     * @return void
     * @access public
     * @since 4/26/05
     */
    function buildContent()
    {
        $defaultTextDomain = textdomain("polyphony");
        $actionRows = $this->getActionRows();
        $pageRows = new Container(new YLayout(), OTHER, 1);
        $harmoni = Harmoni::instance();
        $harmoni->request->startNamespace("polyphony-agents");
        $harmoni->request->passthrough();
        // register this action as the return-point for the following operations:
        $harmoni->history->markReturnURL("polyphony/agents/add_to_group");
        $harmoni->history->markReturnURL("polyphony/agents/remove_from_group");
        $agentManager = Services::getService("Agent");
        $idManager = Services::getService("Id");
        $everyoneId = $idManager->getId("edu.middlebury.agents.everyone");
        $usersId = $idManager->getId("edu.middlebury.agents.users");
        $allGroupsId = $idManager->getId("edu.middlebury.agents.all_groups");
        /*********************************************************
         * the agent search form
         *********************************************************/
        // Users header
        $actionRows->add(new Heading(_("Users"), 2), "100%", null, LEFT, CENTER);
        ob_start();
        $self = $harmoni->request->quickURL();
        $lastCriteria = $harmoni->request->get("search_criteria");
        $search_criteria_name = RequestContext::name("search_criteria");
        $search_type_name = RequestContext::name("search_type");
        print _("Search For Users") . ": ";
        print <<<END
\t\t<form action='{$self}' method='post'>
\t\t\t<div>
\t\t\t<input type='text' name='{$search_criteria_name}' value='{$lastCriteria}' />
\t\t\t<br /><select name='{$search_type_name}'>
END;
        $searchTypes = $agentManager->getAgentSearchTypes();
        while ($searchTypes->hasNext()) {
            $type = $searchTypes->next();
            $typeString = htmlspecialchars($type->getDomain() . "::" . $type->getAuthority() . "::" . $type->getKeyword());
            print "\n\t\t<option value='{$typeString}'";
            if ($harmoni->request->get("search_type") == $typeString) {
                print " selected='selected'";
            }
            print ">{$typeString}</option>";
        }
        print "\n\t</select>";
        print "\n\t<br /><input type='submit' value='" . _("Search") . "' />";
        print "\n\t<a href='" . $harmoni->request->quickURL() . "'>";
        print "<input type='button' value='" . _("Clear") . "' /></a>";
        print "\n</div>\n</form>";
        $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
        ob_end_clean();
        /*********************************************************
         * the agent search results
         *********************************************************/
        ob_start();
        if (($search_criteria = $harmoni->request->get('search_criteria')) && ($search_type = $harmoni->request->get('search_type'))) {
            $typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8'));
            $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
            $agents = new MultiIteratorIterator();
            $agents->addIterator($agentManager->getAgentsBySearch($search_criteria, $searchType));
            $agents->addIterator($agentManager->getGroupsBySearch($search_criteria, $searchType));
            print "search: " . $search_criteria;
            print <<<END
\t\t
\t\t
\t\t<table>
\t\t\t<tr>
\t\t\t\t<td valign='top'>
\t\t\t\t\t<div style='
\t\t\t\t\t\tborder: 1px solid #000; 
\t\t\t\t\t\twidth: 15px; 
\t\t\t\t\t\theight: 15px;
\t\t\t\t\t\ttext-align: center;
\t\t\t\t\t\ttext-decoration: none;
\t\t\t\t\t\tfont-weight: bold;
\t\t\t\t\t'>
\t\t\t\t\t\t-
\t\t\t\t\t</div>
\t\t\t\t</td>
\t\t\t\t<td>
END;
            print "\n\t\t\t" . _("Search Results");
            print <<<END
\t\t\t\t</td>
\t\t\t</tr>
\t\t</table>
\t\t<div style='
\t\t\tmargin-left: 13px; 
\t\t\tmargin-right: 0px; 
\t\t\tmargin-top:0px; 
\t\t\tpadding-left: 10px;
\t\t\tborder-left: 1px solid #000;
\t\t'>
END;
            while ($agents->hasNext()) {
                $agent = $agents->next();
                group_membershipAction::printMember($agent);
                print "<br />";
            }
            print "\n</div>";
            $pageRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
            ob_end_clean();
        }
        /*********************************************************
         * Groups
         *********************************************************/
        $pageRows->add(new Heading(_("Groups"), 2), "100%", null, LEFT, CENTER);
        // Define some global variables to store javascript array definitions
        // for validating adding/removing inputs.
        $GLOBALS['decendent_groups_string'] = "";
        $GLOBALS['child_groups_string'] = "";
        $GLOBALS['child_agents_string'] = "";
        // Loop through all of the Root Groups
        $groups = $agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
        while ($groups->hasNext()) {
            $group = $groups->next();
            $groupId = $group->getId();
            // Create a layout for this group using the GroupPrinter
            ob_start();
            GroupPrinter::printGroup($group, $harmoni, 2, array($this, "printGroup"), array($this, "printMember"));
            $groupLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
            ob_end_clean();
            $pageRows->add($groupLayout, "100%", null, LEFT, CENTER);
        }
        /*********************************************************
         * Javascript for validating checkboxes,
         * Form Definition.
         *********************************************************/
        ob_start();
        // Create translated errorstrings
        $cannotAddGroup = _("Cannot add group");
        $toItsself = _("to itself");
        $deselecting = _("Deselecting");
        $toOwnDesc = _("to its own descendent");
        $groupString = _("Group");
        $isAlreadyInGroup = _("is alread in this group");
        $agentString = _("Agent");
        $fromItsself = _("from itself");
        $cannotRemoveGroup = _("Cannot remove group");
        $notInGroup = _("is not in this group");
        $confirmAdd = _("Are you sure that you wish to add the selected Groups and Agents to Group");
        $confirmRemove = _("Are you sure that you wish to remove the selected Groups and Agents from Group");
        $destinationgroup_name = RequestContext::name("destinationgroup");
        $operation_name = RequestContext::name("operation");
        $actionURL = $harmoni->request->quickURL("agents", "add_to_group");
        // Print out a Javascript function for submitting our groups choices
        $decendentGroups = $GLOBALS['decendent_groups_string'];
        $childGroups = $GLOBALS['child_groups_string'];
        $childAgents = $GLOBALS['child_agents_string'];
        print <<<END
\t\t
\t\t<script type='text/javascript'>
\t\t//<![CDATA[ 
\t\t
\t\t\t// Validate ancestory and submit to add checked to the group
\t\t\tfunction submitCheckedToGroup ( destGroupId ) {
\t\t\t\tvar f;
\t\t\t\tvar form;
\t\t\t\tfor (i = 0; i < document.forms.length; i++) {
\t\t\t\t\tf = document.forms[i];\t\t\t
\t\t\t\t\tif (f.id == 'memberform') {
\t\t\t\t\t\tform = f;
\t\t\t\t\t\tbreak;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t
\t\t\t\tvar elements = form.elements;
\t\t\t\tvar i;
\t\t\t\tvar numToAdd = 0;
\t\t\t\t\t\t
\t\t\t\tfor (i = 0; i < elements.length; i++) {
\t\t\t\t\tvar element = elements[i];
\t\t\t\t\t
\t\t\t\t\tif (element.type == 'checkbox' && element.checked == true) {
\t\t\t\t\t\t
\t\t\t\t\t\tif (element.className == 'group') {
\t\t\t\t\t\t\t// Check that the destination is not the new member
\t\t\t\t\t\t\tif ( element.id == destGroupId ) {
\t\t\t\t\t\t\t\talert ("{$cannotAddGroup} " + element.id + " {$toItsself}. {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t
\t\t\t\t\t\t\t// Check that the destination is not a decendent of the new member
\t\t\t\t\t\t\tif ( in_array(destGroupId, decendentGroups[element.id]) ) {
\t\t\t\t\t\t\t\talert ("{$cannotAddGroup} " + element.id + " {$toOwnDesc}.  {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t\t
\t\t\t\t\t\t\t// Check that the new member is not already a child of the destination
\t\t\t\t\t\t\tif ( in_array(element.id, childGroups[destGroupId]) ) {
\t\t\t\t\t\t\t\talert ("{$groupString} " + element.id + " {$isAlreadyInGroup}.  {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t} else {
\t\t\t\t\t\t\t// Check that the new member is not already a child of the destination
\t\t\t\t\t\t\tif ( in_array(element.id, childAgents[destGroupId]) ) {
\t\t\t\t\t\t\t\talert ("{$agentString} " + element.id + " {$isAlreadyInGroup}.  {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t\t
\t\t\t\t\t\t// If we haven't skipped back to the top of the loop yet, increment our ticker.
\t\t\t\t\t\tnumToAdd++;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t
\t\t\t\t
\t\t\t\tif (numToAdd && confirm("{$confirmAdd} " + destGroupId + "?")) {
\t\t\t\t\tform.destinationgroup.value = destGroupId;
\t\t\t\t\tform.submit();
\t\t\t\t}
\t\t\t}
\t\t\t
\t\t\t// Validate that the check are children and submit to remove them from the group
\t\t\tfunction submitCheckedFromGroup ( destGroupId ) {
\t\t\t\tvar f;
\t\t\t\tvar form;
\t\t\t\tfor (i = 0; i < document.forms.length; i++) {
\t\t\t\t\tf = document.forms[i];\t\t\t
\t\t\t\t\tif (f.id == 'memberform') {
\t\t\t\t\t\tform = f;
\t\t\t\t\t\tbreak;
\t\t\t\t\t}
\t\t\t\t}\t\t
\t\t\t\t
\t\t\t\tvar elements = form.elements;
\t\t\t\tvar i;
\t\t\t\tvar numToAdd = 0;
\t\t\t\t\t\t\t\t
\t\t\t\tfor (i = 0; i < elements.length; i++) {
\t\t\t\t\tvar element = elements[i];
\t\t\t\t\t
\t\t\t\t\tif (element.type == 'checkbox' && element.checked == true) {
\t\t\t\t\t\t// Check that the destination is not the new member
\t\t\t\t\t\tif ( element.id == destGroupId ) {
\t\t\t\t\t\t\talert ("{$cannotRemoveGroup} " + element.id + " {$fromItsself}. {$deselecting}...");
\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t}
\t\t\t\t\t\t
\t\t\t\t\t\tif (element.className == 'group') {\t\t\t\t\t
\t\t\t\t\t\t\t// Check that the new member is not already a child of the destination
\t\t\t\t\t\t\tif ( !in_array(element.id, childGroups[destGroupId]) ) {
\t\t\t\t\t\t\t\talert ("{$groupString} " + element.id + " {$notInGroup}.  {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t} else {
\t\t\t\t\t\t\t// Check that the new member is not already a child of the destination
\t\t\t\t\t\t\tif ( !in_array(element.id, childAgents[destGroupId]) ) {
\t\t\t\t\t\t\t\talert ("{$agentString} " + element.id + " {$notInGroup}.  {$deselecting}...");
\t\t\t\t\t\t\t\telement.checked = false;
\t\t\t\t\t\t\t\tcontinue;
\t\t\t\t\t\t\t}
\t\t\t\t\t\t}
\t\t\t\t\t\t
\t\t\t\t\t\t// If we haven't skipped back to the top of the loop yet, increment our ticker.
\t\t\t\t\t\tnumToAdd++;
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\t
\t\t\t\tif (numToAdd && confirm("{$confirmRemove} " + destGroupId + "?")) {
\t\t\t\t\tform.destinationgroup.value = destGroupId;
\t\t\t\t\tform.action = form.action.replace('add_to_group','remove_from_group');
\t\t\t\t\tform.submit();
\t\t\t\t}
\t\t\t}
\t\t\t
\t\t\tfunction in_array( aValue, anArray) {
\t\t\t\tfor (i = 0; i < anArray.length; i++) {
\t\t\t\t\tif (anArray[i] == aValue)
\t\t\t\t\t\treturn true;
\t\t\t\t}
\t\t\t\t
\t\t\t\treturn false;
\t\t\t}
\t\t\t
\t\t\t// Decendent Groups
\t\t\tvar decendentGroups = new Array ();
{$decendentGroups}
\t\t
\t\t\t// Child Groups
\t\t\tvar childGroups = new Array ();
{$childGroups}
\t\t\t
\t\t\t// Child Agents
\t\t\tvar childAgents = new Array ();
{$childAgents}
\t\t\t
\t\t//]]> 
\t\t</script>
\t\t
\t\t<form id='memberform' method='post' action='{$actionURL}'>
\t\t<input type='hidden' id='destinationgroup' name='{$destinationgroup_name}' value=''/>
\t\t
END;
        $pageRows->setPreHTML(ob_get_contents());
        ob_end_clean();
        $pageRows->setPostHTML("</form>");
        // In order to preserve proper nesting on the HTML output, the checkboxes
        // are all in the pagerows layout instead of actionrows.
        $actionRows->add($pageRows, null, null, CENTER, CENTER);
        textdomain($defaultTextDomain);
    }
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace("polyphony-agents");
     $harmoni->history->markReturnURL("polyphony/agents/delete_group", $harmoni->request->mkURLWithPassthrough());
     // Our
     $actionRows = $this->getActionRows();
     $agentManager = Services::getService("Agent");
     // pass our search variables through to new URLs
     $harmoni->request->passthrough();
     /*********************************************************
      * Deleting a Group
      *********************************************************/
     // 'Delete a Group' header
     /*		$deleteHeader = new Heading(_("Delete a Group"), 3);
     		$actionRows->add($deleteHeader, "100%", null, null, LEFT, CENTER);
     */
     ob_start();
     $addURL = $harmoni->request->quickURL("agents", "add_group");
     $harmoni->history->markReturnURL("polyphony/agents/add_group", $harmoni->request->mkURLWithPassthrough());
     print sprintf(_("On this page you may delete existing groups with the interface below, or %s."), "<input type='button' value='" . _("Add a New Group") . "' onclick='javascript: window.location = \"{$addURL}\"'/>");
     $actionRows->add(new Block(ob_get_contents(), 4));
     ob_end_clean();
     // Loop through all of the Root Groups
     $groups = $agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
     while ($groups->hasNext()) {
         $group = $groups->next();
         $groupId = $group->getId();
         // Create a layout for this group using the GroupPrinter
         ob_start();
         GroupPrinter::printGroup($group, $harmoni, 2, array($this, "printGroup"), array($this, "printMember"));
         $groupLayout = new Block(ob_get_contents(), 4);
         ob_end_clean();
         $actionRows->add($groupLayout, "100%", null, LEFT, CENTER);
     }
     $harmoni->request->endNamespace();
     /*********************************************************
      * Return the main layout.
      *********************************************************/
     return $actionRows;
 }