function editAgent($agent) { //to get the username and maybe the password. $tokenMappingManager = Services::getService("AgentTokenMappingManager"); //a properties manager to handle, what else, properties $propertiesManager = Services::getService("Property"); $mappings = $tokenMappingManager->getMappingsForAgentId($agent->getId()); //there should only be one mapping but what the heck while ($mappings->hasNextObject()) { $mapping = $mappings->nextObject(); $tokens = $mapping->getTokens(); $userName = $tokens->getUsername(); } if (!isset($userName)) { $userName = '******'; } $harmoni = Harmoni::instance(); $url = $harmoni->request->mkURL(); //display name print "<h3>Editing User: "******"</h3>"; print "<table bgcolor='#AAAAAA' cellspacing='1' cellpadding='3'>"; print "<tr bgcolor='#DDDDDD'>\n\t\t\t\t<td>Property</td>\n\t\t\t\t<td>Value</td>\n\t\t\t\t<td>Type</td>\n\t\t\t\t<td>Store new value</td>\n\t\t\t\t<td>Delete property</td>\n\t\t\t </tr>"; //username print "<tr bgcolor='#FFFFFF'>\n\t\t\t\t <td><span style='color:red;'>*</span> User Name</td>\n\t\t\t\t <td>{$userName}</td>\n\t\t\t\t <td>Immutable Reality</td>\n\t\t\t\t <td>N/A</td>\n\t\t\t\t <td>N/A</td>\n\t\t\t\t</tr>"; // @todo TO DO: Add password editing here. How it's implemented depends strongly on who this interface is for print "<tr bgcolor='#FFFFFF'>\n\t\t\t\t <td>Password</td>\n\t\t\t\t <td>Stored</td>\n\t\t\t\t <td>Immutable Reality</td>\n\t\t\t\t <td><form><input type='submit' value='Change' /></form></td>\n\t\t\t\t <td>N/A</td>\n\t\t\t\t</tr>"; print "<tr bgcolor='#FFFFFF'>\n\t\t\t\t <form action='" . $url->write("furtherAction", "edit_agent_detailsAction::updateDisplayName") . "' method='post'>\n\t\t\t\t <td>Display name</td>\n\t\t\t\t <td><input type='text' name='" . RequestContext::name("display_name") . "' value ='" . $agent->getDisplayName() . "' /></td>\n\t\t\t\t <td>Immutable Reality</td>\n\t\t\t\t <td><input type='submit' value='Change Display Name' /></td>\n\t\t\t\t <td>N/A</td>\n\t\t\t\t </form>\n\t\t\t\t</tr>"; $type = $agent->getType(); $propertiesArray = edit_agent_detailsAction::_getUsableProperties($agent); foreach ($propertiesArray as $key => $property) { $typeParts = explode("::", $property['type']); print "<tr bgcolor='#FFFFFF'>\n\t\t\t\t\t<form action='" . $url->write("furtherAction", "edit_agent_detailsAction::updateProperty") . "' method='post'>\n\t\t\t\t\t<td><input type='hidden' name='" . RequestContext::name("property_name") . "' value='{$key}' />{$key}</td>\n\t\t\t\t\t<td><input name='" . RequestContext::name('property_value') . "' value='{$property['value']}' /></td>\n\t\t\t\t\t<td>\n\t\t\t\t\t\n\t\t\t\t\t<input type='hidden' value='{$property['type']}' name='" . RequestContext::name("property_type") . "' />{$typeParts[2]}\n\t\t\t\t\t</td>\n\t\t\t\t\t<td>\n\t\t\t\t\t<input type='submit' value='Update' />\n\t\t\t\t\t</td>\n\t\t\t\t\t</form>\n\t\t\t\t\t<td>\n\t\t\t\t\t<form action='" . $url->write("furtherAction", "edit_agent_detailsAction::deleteProperty") . "' method='post'><input type='submit' value='Delete Property' >\n\t\t\t\t\t<input type='hidden' name='" . RequestContext::name("property_type") . "' value='{$property['type']}' />\n\t\t\t\t\t<input type='hidden' name='" . RequestContext::name("property_name") . "' value='{$key}' />\n\t\t\t\t\t</form>\n\t\t\t\t\t</td>\n\t\t\t\t\t</tr>"; } print "<tr bgcolor='#DDDDDD'>\n\t\t\t\t<form action='" . $url->write("furtherAction", "edit_agent_detailsAction::addProperty") . "' method='post'>\n\t\t\t\t<td colspan='5'>\n\t\t\t\t\tAdd New Property\n\t\t\t\t</td>\n\t\t\t\t<tr bgcolor='#FFFFFF'>\n\t\t\t\t<td>\n\t\t\t\t<input type='text' name='" . RequestContext::name("name") . "' />\n\t\t\t\t\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<input type='text' name='" . RequestContext::name("value") . "' />\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<input type='hidden' name='" . RequestContext::name("property_type") . "' value='" . $type->getDomain() . "::" . $type->getAuthority() . "::" . $type->getKeyword() . "' />\n\t\t\t\tType\n\t\t\t\t</td>\n\t\t\t\t<td>\n\t\t\t\t<input type='submit' value='Add Property' />\n\t\t\t\t\n\t\t\t\t</td>\n\t\t\t\t</form>\n\t\t\t\t<td>\n\t\t\t\t</td>\n\t\t\t\t\n\t\t\t\t</tr>"; print "<tr bgcolor='#DDDDDD'>\n\t\t\t\t<td colspan='5' align='right'><a href='" . $harmoni->request->quickURL() . "'><input type='button' value='Go Back'/></a></td>\n\t\t\t\t\n\t\t\t\t</tr>"; print "</table>"; print "<br /><span style='color: red'>*</span> The system name may only be altered by creating a new user."; return; }
/** * Build the content for this action * * @return void * @access public * @since 4/26/05 */ function buildContent() { $cm = Services::getService("CourseManagement"); $defaultTextDomain = textdomain("polyphony"); $actionRows = $this->getActionRows(); $pageRows = new Container(new YLayout(), OTHER, 1); $harmoni = Harmoni::instance(); $searchNumber = RequestContext::value('search_number'); if (is_null($searchNumber)) { $searchNumber = ""; } ob_start(); /*************************************************************************************************** * The following performs a wild-card search through LDAP and sucks the courses into the database. * ***************************************************************************************************/ $self = $harmoni->request->quickURL(); print "<h2>Search for course offerings by the following criteria:</h2>" . ""; print "\n\t<form action='{$self}' method='post'>\n\t\t\t\n\t<div>"; print "<table>"; print "\n\t<tr><td>Number: </td><td><input type='text' name='search_number' value='" . $searchNumber . "'/></td></tr>"; print "\n\t<tr><td>Term: </td><td><select name='search_term'>"; print "\n\t<option value=''"; print "selected='selected'"; print ">Choose a term</option>"; //@TODO this sorting is probably pretty slow--it's multiple queries per term. $numOfImproperOfferingTerms = -1; $terms = $cm->getTerms(); while ($terms->hasNextTerm()) { $term = $terms->nextTerm(); $schedule = $term->getSchedule(); if ($schedule->hasNextScheduleItem()) { $item1 = $schedule->nextScheduleItem(); $terms2[$item1->getStart()] = $term; } else { $terms2[$numOfImproperOfferingTerms] = $term; $numOfImproperOfferingTerms--; } } krsort($terms2); foreach ($terms2 as $term) { $id = $term->getId(); print "\n\t<option value='" . $id->getIdString() . "'"; /*if($searchTerm==$id->getIdString()){ print "selected='selected'"; }*/ print ">" . $term->getDisplayName() . "</option>"; } print "\n\t</select></td></tr>"; print "\n</table>"; print "\n\t<p><input type='submit' value='" . _("Search") . "'/></p>"; print "\n\t</div></form>"; //$actionRows =$this->getActionRows(); $actionRows->add(new Block(ob_get_contents(), 2), "100%", null, CENTER, TOP); ob_end_clean(); $searchTerm = RequestContext::value('search_term'); if (is_null($searchTerm)) { $searchTerm = ""; } /* if ($search_criteria = $harmoni->request->get('search_criteria')) { //$typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8')); $searchType = new HarmoniType("Agent & Group Search", "edu.middlebury.harmoni", "TokenSearch"); //$searchType = new HarmoniType("Agent & Group Search", "edu.middlebury.harmoni", "WildcardSearch"); $string= "*".$search_criteria."*"; $agents =$agentManager->getAgentsBySearch($string, $searchType); print "search: " . $search_criteria; while ($agents->hasNext()) { $agent =$agents->next(); $id =$agent->getId(); $harmoni->history->markReturnURL("polyphony/agents/edit_agent_details"); print "\n<p align='center'><a href='".$harmoni->request->quickURL("agents","edit_agent_details", array("agentId"=>$id->getIdString()))."'>"; print "\n".$agent->getDisplayName()."</a>"; print "\n - <a href=\"Javascript:alert('"._("Id:").'\n\t'.addslashes($id->getIdString())."')\">Id</a></p>"; } print "\n</div>"; $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER); ob_end_clean(); } */ if ($searchNumber != "" || $searchTerm != "") { ob_start(); $pageRows->add(new Heading("Canonical course search results", STANDARD_BLOCK), "100%", null, LEFT, CENTER); ob_start(); print "<p><h2>Search Results</h2></p>"; $searchType = new ClassTokenSearch(); $string = "*" . $searchNumber . "*"; $DNs = $searchType->getClassDNsBySearch($string); print "search: " . $searchNumber; /* $dbHandler = Services::getService("DBHandler"); $query= new SelectQuery; $query->addTable('cm_offer'); $query->addColumn('id'); if($searchNumber!=null){ $query->addWhere("number like '%".addslashes($searchNumber)."%'"); } if($searchTerm!=null){ $query->addWhere("fk_cm_term='".addslashes($searchTerm)."'"); } $res =$dbHandler->query($query);*/ $sections = array(); $cm = Services::getService("CourseManagement"); $im = Services::getService("Id"); foreach ($DNs as $idString) { if (substr($idString, strlen($idString) - 42, 42) != ",OU=Classes,OU=Groups,DC=middlebury,DC=edu") { continue; } $len = 0; while ($idString[$len + 3] != "," && $len < strlen($idString)) { $len++; } $name = substr($idString, 3, $len); /* if(!$term somthings $searchTerm){ //continue } */ //filter out semesters if (substr($name, strlen($name) - 4, 1) != "-") { continue; } //filter out gym--actually, that's not fair, is it? //if(substr($name,0,4)=="phed"){ // // continue; //} $sections[] = suck_by_agentAction::_figureOut($name, $agentId = null); } $offerings = array(); $termId = null; if ($searchTerm != "") { //$term = substr($name, strlen($name)-3,3); $idManager = Services::getService("Id"); // $term =$cm->getTerm($idManager->getId($searchTerm)); // $termId =$term->getId(); $termId = $idManager->getId($searchTerm); } foreach ($sections as $section) { $offering = $section->getCourseOffering(); $term2 = $offering->getTerm(); $term2Id = $term2->getId(); if (!is_null($termId) && !$termId->isEqual($term2Id)) { continue; } $offeringId = $offering->getId(); $offerings[$offeringId->getIdString()] = $offering; } /* foreach($DNs as $DN){ $id =$im->getId($row['id']); $array[] =$cm->getCourseOffering($id); }*/ $iter = new HarmoniCourseOfferingIterator($offerings); edit_agent_detailsAction::printCourseOfferings($iter); $actionRows->add(new Block(ob_get_contents(), 2), "100%", null, CENTER, TOP); ob_end_clean(); } }
function printCourseOfferings($offerings) { $denominator = 60000; //get the offerings and arrange put them in an array and index them according to chronological order $offerings2 = array(); //note that this variable seperates any courses that start in the same term from being written to the same place in the array. It's a bit hacky, but shouldn't be a problem unless two terms start within an hour or so of each other. $courseNum = 0; while ($offerings->hasNextCourseOffering()) { $offering = $offerings->nextCourseOffering(); $term = $offering->getTerm(); $schedule = $term->getSchedule(); if ($schedule->hasNextScheduleItem()) { $item1 = $schedule->nextScheduleItem(); //@todo It seems that arrays can't be indexed by longs. Thus I divided by the number of milliseconds in a minute. This shouldn't be a problem, but it's hacky in a way that kinda bugs me. $index = $item1->getStart() / $denominator + $courseNum; $offerings2[$index] = $offering; } else { // $offerings2[$courseNum] = $offering; } $courseNum++; } //reverse sort the arrays by keys. This is the key function. Oops, that was a pun. krsort($offerings2); print "\n<table cellpadding=6>"; //chrono will keep track of whether this semester is in the past, present or future. //lastChrono will keep track of the last value of Chrono, so we know when a change occured. $chrono = -1; //-1 is not started //0 means that we've seen at least one course //1 means we've seen the present term //2 means we've seen a past term. $lastChrono = -1; $cm = Services::getService("CourseManagement"); $time = time() * 1000; $currentTermIterator = $cm->getTermsByDate($time); $time /= $denominator; if ($currentTermIterator->hasNextTerm()) { $term = $currentTermIterator->nextTerm(); $schedule = $term->getSchedule(); if ($schedule->hasNextScheduleItem()) { $item = $schedule->nextScheduleItem(); $currSemesterStart = $item->getStart(); } else { $currSemesterStart = $time; } } else { $currSemesterStart = $time; } $harmoni = Harmoni::instance(); $harmoni->request->startNamespace("polyphony-agents"); $lastTermId = null; foreach ($offerings2 as $start => $offering) { $term = $offering->getTerm(); $termId = $term->getId(); if (!is_null($lastTermId) && $termId->isEqual($lastTermId)) { edit_agent_detailsAction::_printOffering($offering, null); } else { if ($start > $time) { $chrono = 0; } else { $chrono = 2; if ($start >= $currSemesterStart) { $chrono = 1; } } if ($chrono != $lastChrono) { if ($chrono == 0) { $string = "Future Terms"; } elseif ($chrono == 1) { $string = "Present Term"; } elseif ($chrono == 2) { $string = "Past Terms"; } print "\n</table>"; print "\n<hr>"; print "<h2>" . $string . "</h2>"; print "\n<table cellpadding=6>"; } else { print "\n\t<tr>"; print "\n<td> </td>"; print "\n<td><hr></td>"; print "\n\t\t</tr>"; } $lastChrono = $chrono; edit_agent_detailsAction::_printOffering($offering, $term); } $lastTermId = $termId; } print "\n</table>"; }