/**
  * Get all the groups with the specified search criteria and search Type.
  * 
  * @param object mixed $searchCriteria (original type: java.io.Serializable)
  * @param object Type $groupSearchType
  *	
  * @return object AgentIterator
  * 
  * @throws object AgentException An exception with one of the
  *		   following messages defined in org.osid.agent.AgentException may
  *		   be thrown:  {@link
  *		   org.osid.agent.AgentException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.agent.AgentException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.agent.AgentException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.agent.AgentException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE}
  * 
  * @access public
  */
 function getGroupsBySearch($searchCriteria, Type $groupSearchType)
 {
     $typeString = $groupSearchType->getDomain() . "::" . $groupSearchType->getAuthority() . "::" . $groupSearchType->getKeyword();
     // get the Group Search object
     $groupSearch = $this->_groupSearches[$typeString];
     if (!is_object($groupSearch)) {
         throwError(new Error(AgentException::UNKNOWN_TYPE() . ", " . $groupSearchType->asString(), "GroupManager", true));
     }
     return $groupSearch->getGroupsBySearch($searchCriteria);
 }
 /**
  * Answer the login HTML
  * 
  * @return string
  * @access public
  * @since 6/5/08
  */
 public function getLoginForm()
 {
     ob_start();
     $harmoni = Harmoni::instance();
     $authN = Services::getService("AuthN");
     $agentM = Services::getService("Agent");
     $idM = Services::getService("Id");
     $authTypes = $authN->getAuthenticationTypes();
     $users = '';
     while ($authTypes->hasNext()) {
         $authType = $authTypes->next();
         $id = $authN->getUserId($authType);
         if (!$id->isEqual($idM->getId('edu.middlebury.agents.anonymous'))) {
             $agent = $agentM->getAgent($id);
             $exists = false;
             foreach (explode("+", $users) as $user) {
                 if ($agent->getDisplayName() == $user) {
                     $exists = true;
                 }
             }
             if (!$exists) {
                 if ($users == '') {
                     $users .= $agent->getDisplayName();
                 } else {
                     $users .= " + " . $agent->getDisplayName();
                 }
             }
         }
     }
     if ($users != '') {
         print "\n<div class='' style='margin-top: 10px;'>";
         print "<strong>" . dgettext("polyphony", "Logged in as:") . "</strong> &nbsp;";
         if (count(explode("+", $users)) == 1) {
             print $users . "\t";
         } else {
             print dgettext("polyphony", "Users: ") . $users . "\t";
         }
         print " | <a href='" . $harmoni->request->quickURL("auth", "logout") . "'>" . dgettext("polyphony", "Log Out") . "</a></div>";
     } else {
         if (PolyphonyLogin::instance()->hasLoginFailed()) {
             $message = "<span class='error'>" . _("Login Failed") . "</span> &nbsp; &nbsp;";
         } else {
             $message = "";
         }
         // set bookmarks for success and failure
         $harmoni->history->markReturnURL("polyphony/display_login", $harmoni->request->quickURL($harmoni->config->get('defaultModule'), $harmoni->config->get('defaultAction')));
         $harmoni->history->markReturnURL("polyphony/login_fail", $harmoni->request->quickURL("user", "main", array('login_failed' => 'true')));
         $harmoni->request->startNamespace("harmoni-authentication");
         $usernameField = $harmoni->request->getName("username");
         $passwordField = $harmoni->request->getName("password");
         $harmoni->request->endNamespace();
         $harmoni->request->startNamespace("polyphony");
         $visitorAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Visitors");
         print "\n<div style='margin-top: 10px;'>" . "\n\t<strong>Visitor Login:</strong>" . "\n<form action='" . $harmoni->request->quickURL("auth", "login_type", array('type' => $visitorAuthType->asString())) . "' style='' method='post'>" . $message . "\n\t" . dgettext("polyphony", "Username (email address):") . " <input class='' type='text' size='8' \n\t\t\t\t\tname='{$usernameField}'/>" . "\n\t" . dgettext("polyphony", "Password:"******" <input class='' type='password' size ='8' \n\t\t\t\t\tname='{$passwordField}'/>" . "\n\t <input class='button' type='submit' value='Log in' />" . "\n</form></div>\n";
         $harmoni->request->endNamespace();
     }
     return ob_get_clean();
 }
Example #3
0
 /**
  * Answer a plugin directory
  * 
  * @param object Type
  * @return string
  * @access public
  * @since 10/8/08
  */
 public function getPluginDir(Type $type)
 {
     $typeString = $type->asString();
     if (!isset($this->pluginDirs[$typeString])) {
         $localPluginDir = $this->_getPluginDir($type, 'plugins-local');
         if (file_exists($localPluginDir)) {
             $this->pluginDirs[$typeString] = $localPluginDir;
         } else {
             $this->pluginDirs[$typeString] = $this->_getPluginDir($type, 'plugins-dist');
         }
     }
     return $this->pluginDirs[$typeString];
 }
 /**
  * Answer the nodes matching a type
  * 
  * @param object Type $type
  * @return array
  * @access private
  * @since 4/3/08
  */
 private function getNodesFromDbByType_Harmoni_Db(Type $type)
 {
     $this->getNodesByType_stmt->bindValue($this->getNodesByType_domain_key, $type->getDomain());
     $this->getNodesByType_stmt->bindValue($this->getNodesByType_authority_key, $type->getAuthority());
     $this->getNodesByType_stmt->bindValue($this->getNodesByType_keyword_key, $type->getKeyword());
     $this->getNodesByType_stmt->execute();
     $nodeQueryResult = $this->getNodesByType_stmt->fetchAll();
     $this->getNodesByType_stmt->closeCursor();
     $result = array();
     $idManager = Services::getService("Id");
     if (!count($nodeQueryResult)) {
         throw new UnknownIdException("No nodes found for type " . $type->asString());
     }
     foreach ($nodeQueryResult as $nodeRow) {
         $idValue = $nodeRow['id'];
         $id = $idManager->getId($idValue);
         $type = new HarmoniType($nodeRow['domain'], $nodeRow['authority'], $nodeRow['keyword'], $nodeRow['type_description']);
         $node = new AuthZ2_Node($id, $type, $nodeRow['display_name'], $nodeRow['description'], $this);
         $result[] = $node;
     }
     return $result;
 }
 /**
  * print an option tag
  * 
  * @param object Type $type
  * @return void
  * @access private
  * @since 12/14/07
  */
 private function printTypeOption(Type $type)
 {
     print "\n\t\t\t<option value='" . $type->asString() . "'>";
     if (isset($this->_classNames[$type->getKeyword()])) {
         print $this->_classNames[$type->getKeyword()];
     } else {
         try {
             $pluginManager = Services::getService("PluginManager");
             $class = $pluginManager->getPluginClass($type);
             print call_user_func(array($class, 'getPluginDisplayName'));
         } catch (UnknownIdException $e) {
             print $type->getKeyword();
         }
     }
     print "</option>";
 }
 /**
  * Generate HTML for displaying particular fields of the Record 
  * 
  * @param object $record The record to print.
  * @param array $partStructures An array of partStructures to print. 
  * @return string
  * @access public
  * @since 10/19/04
  */
 function generateDisplayForPartStructures(Id $repositoryId, Id $assetId, Record $record, array $partStructures)
 {
     ArgumentValidator::validate($partStructures, new ArrayValidatorRuleWithRule(new ExtendsValidatorRule("PartStructure")));
     $recordStructure = $record->getRecordStructure();
     try {
         $type = $recordStructure->getType();
     } catch (UnimplementedException $e) {
         $type = new Type("RecordStructures", "edu.middlebury.harmoni", "text/plain");
     }
     if (!is_object($this->_modules[$type->asString()])) {
         throwError(new Error("Unsupported Format, '" . $type->asString() . "'", "RepositoryInputOutputModuleManager", true));
     }
     return $this->_modules[$type->asString()]->generateDisplayForPartStructures($repositoryId, $assetId, $record, $partStructures);
 }
 /**
  * Answer the database id for the type passed.
  * 
  * @param object Type $type
  * @return string
  * @access public
  * @since 3/1/06
  */
 function _getTypeId(Type $type)
 {
     if (!isset($this->_typeIds)) {
         $this->_typeIds = array();
     }
     if (!isset($this->_typeIds[$type->asString()])) {
         $dbc = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addColumn("id");
         $query->addTable("log_type");
         $query->addWhere("domain = '" . addslashes($type->getDomain()) . "'");
         $query->addWhere("authority = '" . addslashes($type->getAuthority()) . "'");
         $query->addWhere("keyword = '" . addslashes($type->getKeyword()) . "'");
         $results = $dbc->query($query, $this->_dbIndex);
         if ($results->getNumberOfRows()) {
             $this->_typeIds[$type->asString()] = $results->field("id");
             $results->free();
         } else {
             $results->free();
             $query = new InsertQuery();
             $query->setTable("log_type");
             $query->setAutoIncrementColumn("id", "log_type_id_seq");
             $query->setColumns(array("domain", "authority", "keyword", "description"));
             $query->addRowOfValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
             $results = $dbc->query($query, $this->_dbIndex);
             $this->_typeIds[$type->asString()] = $results->getLastAutoIncrementValue();
         }
     }
     return $this->_typeIds[$type->asString()];
 }
function getVisitorLoginLink()
{
    $harmoni = Harmoni::instance();
    $authN = Services::getService("AuthN");
    // Visitor Registration Link
    $authTypes = $authN->getAuthenticationTypes();
    $hasVisitorType = false;
    $visitorType = new Type("Authentication", "edu.middlebury.harmoni", "Visitors");
    while ($authTypes->hasNext()) {
        $authType = $authTypes->next();
        if ($visitorType->isEqual($authType)) {
            $hasVisitorType = true;
            break;
        }
    }
    if ($hasVisitorType && !$authN->isUserAuthenticatedWithAnyType()) {
        $harmoni->request->startNamespace('polyphony');
        $url = $harmoni->request->mkURL("auth", "login_type");
        $url->setValue("type", urlencode($visitorType->asString()));
        // Add return info to the visitor registration url
        $visitorReturnModules = array('view', 'ui1', 'ui2', 'versioning');
        if (in_array($harmoni->request->getRequestedModule(), $visitorReturnModules)) {
            $url->setValue('returnModule', $harmoni->request->getRequestedModule());
            $url->setValue('returnAction', $harmoni->request->getRequestedAction());
            $url->setValue('returnKey', 'node');
            $url->setValue('returnValue', SiteDispatcher::getCurrentNodeId());
        }
        $harmoni->request->endNamespace();
        return "\n\t<a href='" . $url->write() . "'>" . _("Visitor Login") . "</a>";
    }
    return null;
}
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     $values = $wizard->getAllValues();
     $props = $values["properties"];
     $list = $this->_getAgentList();
     print_r($props);
     $agentManager = Services::getService("Agent");
     $idManager = Services::getService("Id");
     $valuesHandled = array();
     // go through each agent and update all its properties at once
     foreach ($list as $idString) {
         // first clear all their properties, then reset them
         $id = $idManager->getId($idString);
         $agent = $agentManager->getAgentOrGroup($id);
         if (count($list) == 1) {
             $agent->deleteAllProperties();
         }
         foreach ($props as $values) {
             if ($values['type']) {
                 $type = HarmoniType::fromString($values['type']);
             } else {
                 $type = new Type("agent_properties", "harmoni", "custom", "Properties defined outside of an authentication system.");
             }
             $valuesHandled[$type->asString()][$values['key']] = true;
             if (count($list) == 1 || $values['value_update']) {
                 $key = $values['key'];
                 $value = $values['value'];
                 if (count($list) == 1 || !$agent->updateProperty($type, $key, $value)) {
                     $agent->addProperty($type, $key, $value);
                 }
             }
         }
     }
     if (count($list) > 1) {
         // now go through each agent and check if there are any properties that were not handled, delete them
         foreach ($list as $idString) {
             $id = $idManager->getId($idString);
             $agent = $agentManager->getAgentOrGroup($id);
             $properties = $agent->getProperties();
             while ($properties->hasNext()) {
                 $property = $properties->next();
                 $keys = $property->getKeys();
                 $type = $property->getType();
                 $typeString = $type->asString();
                 while ($keys->hasNext()) {
                     $key = $keys->next();
                     if (!isset($valuesHandled[$typeString][$key]) || !$valuesHandled[$typeString][$key]) {
                         $agent->deleteProperty($type, $key);
                     }
                 }
             }
         }
     }
     //		exit(0);
     return true;
 }