Source for file edit_agent_details.act.php

Documentation is available at edit_agent_details.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.agents
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: edit_agent_details.act.php,v 1.23 2007/09/19 14:04:52 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13. require_once(HARMONI."GUIManager/Components/Blank.class.php");
  14. require_once(POLYPHONY."/main/modules/coursemanagement/suck_by_agent.act.php");
  15. /**
  16. * This action will allow for the modification of group Membership.
  17. *
  18. * @since 11/10/04
  19. *
  20. * @package polyphony.agents
  21. *
  22. * @copyright Copyright &copy; 2005, Middlebury College
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  24. *
  25. * @version $Id: edit_agent_details.act.php,v 1.23 2007/09/19 14:04:52 adamfranco Exp $
  26. */
  27. class edit_agent_detailsAction
  28. extends MainWindowAction
  29. {
  30. /**
  31. * Check Authorizations
  32. *
  33. * @return boolean
  34. * @access public
  35. * @since 4/26/05
  36. */
  37. function isAuthorizedToExecute () {
  38. // Check for authorization
  39. $authZManager = Services::getService("AuthZ");
  40. $idManager = Services::getService("IdManager");
  41. $harmoni = Harmoni::instance();
  42. $harmoni->request->startNamespace("polyphony-agents");
  43. $agentIdString = $harmoni->request->get("agentId");
  44.  
  45. $harmoni->request->endNamespace();
  46. if ($authZManager->isUserAuthorized(
  47. $idManager->getId("edu.middlebury.authorization.modify"),
  48. $idManager->getId($agentIdString)))
  49. {
  50. return TRUE;
  51. } else
  52. return FALSE;
  53. }
  54. /**
  55. * Return the heading text for this action, or an empty string.
  56. *
  57. * @return string
  58. * @access public
  59. * @since 4/26/05
  60. */
  61. function getHeadingText () {
  62. $harmoni = Harmoni::instance();
  63. $harmoni->request->startNamespace("polyphony-agents");
  64. $harmoni->request->passthrough("agentId");
  65. $agentIdString = $harmoni->request->get("agentId");
  66. $idManager = Services::getService("Id");
  67. $agentId =$idManager->getId($agentIdString);
  68. $agentManager = Services::getService("Agent");
  69. $agent =$agentManager->getAgent($agentId);
  70. return dgettext("polyphony", $agent->getDisplayName());
  71. }
  72. /**
  73. * Build the content for this action
  74. *
  75. * @return void
  76. * @access public
  77. * @since 4/26/05
  78. */
  79. function buildContent () {
  80. $defaultTextDomain = textdomain("polyphony");
  81. $actionRows =$this->getActionRows();
  82. $pageRows = new Container(new YLayout(), OTHER, 1);
  83. $harmoni = Harmoni::instance();
  84. $harmoni->request->startNamespace("polyphony-agents");
  85. $harmoni->request->passthrough("agentId");
  86. $agentIdString = $harmoni->request->get("agentId");
  87. $furtherAction = $harmoni->request->get("furtherAction");
  88.  
  89. $idManager = Services::getService("Id");
  90. $agentId =$idManager->getId($agentIdString);
  91. $agentManager = Services::getService("Agent");
  92.  
  93. //we can't really do anything if its not an editableAgent
  94. if($agentManager->getAgentFlavor()!="HarmoniEditableAgent"){
  95. $centerPane->add(new Block("Sorry but this agent isn't editable!", 2), "100%", null, CENTER, TOP);
  96. return $mainScreen;
  97. }
  98. $agent =$agentManager->getAgent($agentId);
  99. ob_start();
  100. print "<div style='margin-left: 15px'>";
  101. if (!$furtherAction) $furtherAction = "edit_agent_detailsAction::viewAgentDetails";
  102. $actionFunctions = array(
  103. "edit_agent_detailsAction::viewAgentDetails",
  104. "edit_agent_detailsAction::advancedViewAgentDetails",
  105. "edit_agent_detailsAction::confirmClearProperties",
  106. "edit_agent_detailsAction::clearProperties",
  107. "edit_agent_detailsAction::confirmDeleteAgent",
  108. "edit_agent_detailsAction::deleteAgent",
  109. "edit_agent_detailsAction::editAgent",
  110. "edit_agent_detailsAction::updateProperty",
  111. "edit_agent_detailsAction::addProperty",
  112. "edit_agent_detailsAction::deleteProperty",
  113. "edit_agent_detailsAction::updateDisplayName"
  114. );
  115. if($furtherAction && in_array($furtherAction, $actionFunctions)){
  116. eval($furtherAction.'($agent);');
  117. }
  118. print "</div>";
  119. // Layout
  120. $actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  121. ob_end_clean();
  122. $harmoni->request->forget("agentId");
  123. $harmoni->request->endNamespace();
  124. textdomain($defaultTextDomain);
  125. }
  126.  
  127. /***************************FUNCTIONS***************************************/
  128.  
  129.  
  130. /**
  131. * shows the details of the agent's properties and gives menu of actions
  132. *
  133. * @param object Agent $agent
  134. * @return void
  135. * @access public
  136. * @since 7/19/05
  137. */
  138. function viewAgentDetails($agent){
  139. suck_by_agentAction::refreshAgentDetails($agent);
  140. $agentId =$agent->getId();
  141. $agentIdString = $agentId->getIdString();
  142. //display agent info
  143. print "\n<h3>".$agent->getDisplayName()."</h3>";
  144. print "\n<table><tr><td>";
  145. print "\n<table bgcolor='#AAAAAA' cellspacing='1' cellpadding='3'>";
  146. /*<tr bgcolor='#DDDDDD'>
  147. <td>
  148. Property
  149. </td>
  150. <td>
  151. Value
  152. </td>
  153. </tr>";*/
  154. $propertiesArray = edit_agent_detailsAction::_getUsableProperties($agent);
  155. //show the uneditable list of properties and their types and values
  156. //foreach($propertiesArray as $key=>$property){
  157. // print "<tr bgcolor='#FFFFFF'>
  158. // <td>$key</td>
  159. // <td>".$property['value']."</td>
  160. // <td>".$property['type']."</td>
  161. // </tr>";
  162. //
  163. //}
  164. edit_agent_detailsAction::_printRowFromPropertiesArray($propertiesArray,"name", "Name:");
  165. edit_agent_detailsAction::_printRowFromPropertiesArray($propertiesArray,"username", "Username:");
  166. edit_agent_detailsAction::_printRowFromPropertiesArray($propertiesArray,"email", "Email address:");
  167. edit_agent_detailsAction::_printRowFromPropertiesArray($propertiesArray,"department","Department:");
  168. print "\n</table>";
  169. print "\n</td><td>";
  170. //actions menu
  171. $harmoni = Harmoni::instance();
  172. $url =$harmoni->request->mkURL();
  173.  
  174. print "<ul>
  175. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::editAgent")."'>Edit agent</a></li>
  176. <li><a href='";
  177. $harmoni->request->startNamespace("polyphony-authorizations");
  178. print $harmoni->request->quickURL("authorization","edit_authorizations",
  179. array("agentId" => $agentId->getIdString()));
  180. $harmoni->request->endNamespace();
  181.  
  182. print "'>Edit authorizations</a></li>
  183. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::confirmClearProperties")."'>Clear properties</a></li>
  184. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::confirmDeleteAgent")."'>Delete agent</a></li>
  185. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::advancedViewAgentDetails")."'>Advanced View</a></li>
  186. </ul>";
  187. print "\n</td></tr></table>";
  188. print "<h2>Classes:</h2>";
  189. //sort the courses by term and the terms by date
  190. $cm = Services::getService("CourseManagement");
  191. $offerings =$cm->getCourseOfferings($agentId);
  192. edit_agent_detailsAction::printCourseOfferings($offerings);
  193. }
  194.  
  195. /**
  196. * shows all the details of the agent's properties and gives menu of actions
  197. *
  198. * @param object Agent $agent
  199. * @return void
  200. * @access public
  201. * @since 7/19/05
  202. */
  203. function advancedViewAgentDetails($agent){
  204. $agentId =$agent->getId();
  205. $agentIdString = $agentId->getIdString();
  206. //display agent info
  207. print "<h3>Details for User: ".$agent->getDisplayName()."</h3>";
  208. print "<table bgcolor='#AAAAAA' cellspacing='1' cellpadding='3'>
  209. <tr bgcolor='#DDDDDD'>
  210. <td>
  211. Property
  212. </td>
  213. <td>
  214. Value
  215. </td>
  216. <td>
  217. Type
  218. </td>
  219. </tr>";
  220. $propertiesArray = edit_agent_detailsAction::_getUsableProperties($agent);
  221. //show the uneditable list of properties and their types and values
  222. foreach($propertiesArray as $key=>$property){
  223. print "<tr bgcolor='#FFFFFF'>
  224. <td>$key</td>
  225. <td>".$property['value']."</td>
  226. <td>".$property['type']."</td>
  227. </tr>";
  228. }
  229. print "</table>";
  230. //actions menu
  231. $harmoni = Harmoni::instance();
  232. $url =$harmoni->request->mkURL();
  233. print "<h3>Actions</h3>
  234. <ul>
  235. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::editAgent")."'>Edit agent</a></li>
  236. <li><a href='";
  237. $harmoni->request->startNamespace("polyphony-authorizations");
  238. print $harmoni->request->quickURL("authorization","edit_authorizations",
  239. array("agentId" => $agentId->getIdString()));
  240. $harmoni->request->endNamespace();
  241. print "'>Edit authorizations</a></li>
  242. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::confirmClearProperties")."'>Clear properties</a></li>
  243. <li><a href='".$url->write("furtherAction","edit_agent_detailsAction::confirmDeleteAgent")."'>Delete agent</a></li>
  244. </ul>";
  245. // Groups
  246. print "<h3>Groups</h3>
  247. <ul>";
  248. $agentManager = Services::getService("Agent");
  249. $groups =$agentManager->getGroupsBySearch($agentId,
  250. new Type( "Agent & Group Search",
  251. "edu.middlebury.harmoni",
  252. "AncestorGroups"));
  253. while ($groups->hasNext()) {
  254. $group =$groups->next();
  255. $groupId =$group->getId();
  256. print "\n\t<li title=\"".addslashes($groupId->getIdString())."\">".$group->getDisplayName()."</li>";
  257. }
  258. print "
  259. </ul>";
  260. return;
  261. }
  262. /*
  263. * Offers a confirmation screen for clearing of properties
  264. */
  265. function confirmClearProperties($agent){
  266. $harmoni = Harmoni::instance();
  267. $url =$harmoni->request->mkURL();
  268. print "Do you really want to clear all properties of ".$agent->getDisplayName()."? (this will not reset system name or password)<br />";
  269. print "<form action='".$url->write("furtherAction","edit_agent_detailsAction::clearProperties")."' method='post'><input type='submit' value='Clear' /></form><input type='button' value='Cancel' onclick='history.back()' />";
  270. return;
  271. }
  272. /*
  273. * Clears all the properties
  274. */
  275. function clearProperties($agent){
  276. $propertyManager = Services::getService("Property");
  277. //clear the props
  278. $agent->clearAllProperties();
  279. //back to the menu
  280. viewAgentDetails($agent);
  281. return;
  282. }
  283. /*
  284. * offers a confirmation screen for deleting an entire agent
  285. */
  286. function confirmDeleteAgent($agent){
  287. $harmoni = Harmoni::instance();
  288. $url =$harmoni->request->mkURL();
  289. print "Do you really want to delete ".$agent->getDisplayName()."?<br />";
  290. print "<form action='".$url->write("furtherAction","edit_agent_detailsAction::deleteAgent")."' method='post'><input type='submit' value='Delete' /></form><input type='button' value='Cancel' onclick='history.back()' />";
  291. return;
  292. }
  293. /*
  294. * Handles the actual deletion of an agent
  295. */
  296. function deleteAgent($agent){
  297. $agentManager = Services::getService("Agent");
  298. $agentManager->deleteAgent($agent->getId());
  299. $harmoni = Harmoni::instance();
  300. print "Agent deleted.<br />";
  301. print "<a href='".$harmoni->history->getReturnURL("polyphony/agents/edit_agent_details")."'>Go Back</a>";
  302. return;
  303. }
  304. /*
  305. * displays the screen for editing agents
  306. * Type for new property is arbitrarily set as the type of the agent
  307. * should probably draw from a list of usable types later on.
  308. * Some of these attributes are not "properties" per se and don't have types
  309. * in that case, I've arbitrarily entered "Immutable Reality" under type
  310. */
  311. function editAgent($agent){
  312. //to get the username and maybe the password.
  313. $tokenMappingManager = Services::getService("AgentTokenMappingManager");
  314. //a properties manager to handle, what else, properties
  315. $propertiesManager = Services::getService("Property");
  316. $mappings=$tokenMappingManager->getMappingsForAgentId($agent->getId());
  317. //there should only be one mapping but what the heck
  318. while($mappings->hasNextObject()){
  319. $mapping=$mappings->nextObject();
  320. $tokens =$mapping->getTokens();
  321. $userName=$tokens->getUsername();
  322. }
  323. if (!isset($userName)) { $userName = '&laquo; undefined &raquo;';}
  324. $harmoni = Harmoni::instance();
  325. $url =$harmoni->request->mkURL();
  326. //display name
  327. print "<h3>Editing User: ".$agent->getDisplayName()."</h3>";
  328. print "<table bgcolor='#AAAAAA' cellspacing='1' cellpadding='3'>";
  329. print "<tr bgcolor='#DDDDDD'>
  330. <td>Property</td>
  331. <td>Value</td>
  332. <td>Type</td>
  333. <td>Store new value</td>
  334. <td>Delete property</td>
  335. </tr>";
  336. //username
  337. print "<tr bgcolor='#FFFFFF'>
  338. <td><span style='color:red;'>*</span> User Name</td>
  339. <td>$userName</td>
  340. <td>Immutable Reality</td>
  341. <td>N/A</td>
  342. <td>N/A</td>
  343. </tr>";
  344. // @todo TO DO: Add password editing here. How it's implemented depends strongly on who this interface is for
  345. print "<tr bgcolor='#FFFFFF'>
  346. <td>Password</td>
  347. <td>Stored</td>
  348. <td>Immutable Reality</td>
  349. <td><form><input type='submit' value='Change' /></form></td>
  350. <td>N/A</td>
  351. </tr>";
  352. print "<tr bgcolor='#FFFFFF'>
  353. <form action='".$url->write("furtherAction","edit_agent_detailsAction::updateDisplayName")."' method='post'>
  354. <td>Display name</td>
  355. <td><input type='text' name='".RequestContext::name("display_name")."' value ='".$agent->getDisplayName()."' /></td>
  356. <td>Immutable Reality</td>
  357. <td><input type='submit' value='Change Display Name' /></td>
  358. <td>N/A</td>
  359. </form>
  360. </tr>";
  361. $type=$agent->getType();
  362. $propertiesArray = edit_agent_detailsAction::_getUsableProperties($agent);
  363. foreach($propertiesArray as $key=>$property){
  364. $typeParts = explode("::", $property['type']);
  365. print "<tr bgcolor='#FFFFFF'>
  366. <form action='".$url->write("furtherAction","edit_agent_detailsAction::updateProperty")."' method='post'>
  367. <td><input type='hidden' name='".RequestContext::name("property_name")."' value='$key' />$key</td>
  368. <td><input name='".RequestContext::name('property_value')."' value='{$property['value']}' /></td>
  369. <td>
  370. <input type='hidden' value='{$property['type']}' name='".RequestContext::name("property_type")."' />{$typeParts[2]}
  371. </td>
  372. <td>
  373. <input type='submit' value='Update' />
  374. </td>
  375. </form>
  376. <td>
  377. <form action='".$url->write("furtherAction","edit_agent_detailsAction::deleteProperty")."' method='post'><input type='submit' value='Delete Property' >
  378. <input type='hidden' name='".RequestContext::name("property_type")."' value='{$property['type']}' />
  379. <input type='hidden' name='".RequestContext::name("property_name")."' value='$key' />
  380. </form>
  381. </td>
  382. </tr>";
  383. }
  384. print "<tr bgcolor='#DDDDDD'>
  385. <form action='".$url->write("furtherAction","edit_agent_detailsAction::addProperty")."' method='post'>
  386. <td colspan='5'>
  387. Add New Property
  388. </td>
  389. <tr bgcolor='#FFFFFF'>
  390. <td>
  391. <input type='text' name='".RequestContext::name("name")."' />
  392. </td>
  393. <td>
  394. <input type='text' name='".RequestContext::name("value")."' />
  395. </td>
  396. <td>
  397. <input type='hidden' name='".RequestContext::name("property_type")."' value='".$type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword()."' />
  398. Type
  399. </td>
  400. <td>
  401. <input type='submit' value='Add Property' />
  402. </td>
  403. </form>
  404. <td>
  405. </td>
  406. </tr>";
  407. print "<tr bgcolor='#DDDDDD'>
  408. <td colspan='5' align='right'><a href='".$harmoni->request->quickURL()."'><input type='button' value='Go Back'/></a></td>
  409. </tr>";
  410. print "</table>";
  411. print "<br /><span style='color: red'>*</span> The system name may only be altered by creating a new user.";
  412. return;
  413. }
  414. /**
  415. * Updates property from the edit agent form
  416. */
  417. function updateProperty($agent){
  418. $propertyKey = RequestContext::value("property_name");
  419. $propertyValue = RequestContext::value("property_value");
  420. //break the type so we can create an object
  421. $propertyTypeArray = explode("::",RequestContext::value("property_type"));
  422. //create type object
  423. $propertyType = new HarmoniType($propertyTypeArray[0], $propertyTypeArray[1], $propertyTypeArray[2]);
  424. //update the agent propreties
  425. if($agent->updateProperty($propertyType, $propertyKey, $propertyValue)){
  426. print ucfirst($propertyKey)." updated succesfully.";
  427. }else{
  428. print "Failed to update $propertyKey.";
  429. }
  430. //back to the form
  431. editAgent($agent);
  432. return;
  433. }
  434. /*
  435. * Adds a property to the agent
  436. */
  437. function addProperty($agent){
  438. $propertyName = RequestContext::value('name');
  439. $propertyValue = RequestContext::value('value');
  440. //create the type object
  441. $typeArray = explode("::", RequestContext::value('property_type'));
  442. $type = new HarmoniType($typeArray[0], $typeArray[1], $typeArray[2]);
  443. if($agent->addProperty($type, $propertyName, $propertyValue)){
  444. print ucfirst($propertyName)." added to ".$agent->getDisplayName();
  445. }else{
  446. print "Failed to add property.";
  447. }
  448. //back to the editing form
  449. editAgent($agent);
  450. return;
  451. }
  452. /*
  453. * Deletes a property from the agent. Duh.
  454. */
  455. function deleteProperty($agent){
  456. $propertyName = RequestContext::value('property_name');
  457. $propertyType = explode("::", RequestContext::value('property_type'));
  458. $type = new HarmoniType($propertyType[0], $propertyType[1], $propertyType[2]);
  459. if($agent->deleteProperty($type, $propertyName)){
  460. print "Deleted property.";
  461. }else{
  462. print "Could not delete property.";
  463. }
  464. editAgent($agent);
  465. return;
  466. }
  467. /*
  468. * Stores a new display name for the agent
  469. */
  470. function updateDisplayName($agent){
  471. if(!RequestContext::value('display_name')){
  472. print "If you want to update the display name you'll need to enter a new one!";
  473. editAgent($agent);
  474. return false;
  475. }
  476. if($agent->updateDisplayName(RequestContext::value('display_name'))){
  477. print "Display name changed to ".$agent->getDisplayName();
  478. }else{
  479. print "Failed to change display name.";
  480. }
  481. editAgent($agent);
  482. return;
  483. }
  484. /*
  485. * creates a two dimensional array of key (value/type) pairs,
  486. * preserving most of the information from the object modify at will
  487. */
  488. function _getUsableProperties($agent){
  489. $propertiesArray=array();
  490. $propertiesIterator =$agent->getProperties();
  491. $i=0;
  492. while($propertiesIterator->hasNext()){
  493. $property =$propertiesIterator->next();
  494. $type=$property->getType();
  495. $typeString = $type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  496. $keys =$property->getKeys();
  497. while($keys->hasNext()){
  498. $key=$keys->next();
  499. $propertiesArray[$key]['value'] = $property->getProperty($key);
  500. $propertiesArray[$key]['type'] = $typeString;
  501. }
  502. }
  503. return $propertiesArray;
  504. }
  505. /*
  506. * Tries to print a key value pair from the propertiesArray
  507. * from getUsableProperties in a table.
  508. * It ignores type, and uses an alias for the key
  509. */
  510. function _printRowFromPropertiesArray($propertiesArray, $key, $keyAlias){
  511. print "\n\t<tr>";
  512. print "\n\t\t<td>".$keyAlias."</td>";
  513. print "\n\t\t<td>";
  514. if(array_key_exists($key,$propertiesArray)){
  515. print $propertiesArray[$key]['value'];
  516. }
  517. print "</td>";
  518. print "\n\t</tr>";
  519. }
  520. /*
  521. * Print the course offering
  522. */
  523. function _printOffering($offering, $term){
  524. if(!is_null($term)){
  525. //print "\n</table>";
  526. print "\n\t<tr>";
  527. print "\n\t\t<td><h4>";
  528. print $term->getDisplayName();
  529. print "</h4</td>";
  530. }else{
  531. print "\n\t<tr>";
  532. print "\n\t\t<td>";
  533. print "</td>";
  534. }
  535. $harmoni = Harmoni::instance();
  536. $id =$offering->getId();
  537. print "\n\t\t<td>";
  538. $url = new GETMethodURLWriter();
  539. $url->setModuleAction("coursemanagement","edit_offering_details");
  540. $url->setValue("courseId",$id->getIdString());
  541. print "\n<a href='".$url->write()."'>";
  542. print $offering->getDisplayName()."</a>";
  543. print "\n - <a href=\"Javascript:alert('"._("Id:").'\n\t'.addslashes($id->getIdString())."')\">"._("Id")."</a>";
  544. print "</td>";
  545. //print "\n\t\t<td>";
  546. //$term =$offering->getTerm();
  547. //print $term->getDisplayName();
  548. //print "</td>";
  549. print "\n\t</tr>";
  550. }
  551. function printCourseOfferings($offerings){
  552. $denominator = 60000;
  553. //get the offerings and arrange put them in an array and index them according to chronological order
  554. $offerings2 = array();
  555. //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.
  556. $courseNum = 0;
  557. while($offerings->hasNextCourseOffering()){
  558. $offering =$offerings->nextCourseOffering();
  559. $term =$offering->getTerm();
  560. $schedule =$term->getSchedule();
  561. if($schedule->hasNextScheduleItem()){
  562. $item1 =$schedule->nextScheduleItem();
  563. //@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.
  564. $index = $item1->getStart()/$denominator+$courseNum;
  565. $offerings2[$index] = $offering;
  566. }else{
  567. //
  568. $offerings2[$courseNum] =$offering;
  569. }
  570. $courseNum++;
  571.  
  572. }
  573. //reverse sort the arrays by keys. This is the key function. Oops, that was a pun.
  574. krsort($offerings2);
  575. print "\n<table cellpadding=6>";
  576. //chrono will keep track of whether this semester is in the past, present or future.
  577. //lastChrono will keep track of the last value of Chrono, so we know when a change occured.
  578. $chrono = -1;
  579. //-1 is not started
  580. //0 means that we've seen at least one course
  581. //1 means we've seen the present term
  582. //2 means we've seen a past term.
  583. $lastChrono = -1;
  584. $cm = Services::getService("CourseManagement");
  585. $time = time()*1000;
  586. $currentTermIterator =$cm->getTermsByDate($time);
  587. $time /= $denominator;
  588.  
  589. if($currentTermIterator->hasNextTerm()){
  590. $term =$currentTermIterator->nextTerm();
  591. $schedule =$term->getSchedule();
  592. if($schedule->hasNextScheduleItem()){
  593. $item =$schedule->nextScheduleItem();
  594. $currSemesterStart = $item->getStart();
  595.  
  596.  
  597. }else{
  598. $currSemesterStart=$time;
  599. }
  600. }else{
  601. $currSemesterStart=$time;
  602. }
  603. $harmoni = Harmoni::instance();
  604. $harmoni->request->startNamespace("polyphony-agents");
  605. $lastTermId = null;
  606. foreach($offerings2 as $start=>$offering){
  607. $term=$offering->getTerm();
  608. $termId =$term->getId();
  609. if(!is_null($lastTermId)&&$termId->isEqual($lastTermId)){
  610. edit_agent_detailsAction::_printOffering($offering,null);
  611. }else{
  612. if($start>$time){
  613. $chrono=0;
  614. }else{
  615. $chrono=2;
  616. if($start>=$currSemesterStart){
  617. $chrono=1;
  618. }
  619. }
  620. if($chrono!=$lastChrono){
  621. if($chrono==0){
  622. $string = "Future Terms";
  623. }elseif($chrono==1){
  624. $string = "Present Term";
  625. }elseif($chrono==2){
  626. $string = "Past Terms";
  627. }
  628. print "\n</table>";
  629. print "\n<hr>";
  630. print "<h2>".$string."</h2>";
  631. print "\n<table cellpadding=6>";
  632. }else{
  633. print "\n\t<tr>";
  634. print "\n<td>&nbsp</td>";
  635. print "\n<td><hr></td>";
  636. print "\n\t\t</tr>";
  637. }
  638. $lastChrono =$chrono;
  639. edit_agent_detailsAction::_printOffering($offering,$term);
  640. }
  641. $lastTermId =$termId;
  642. }
  643. print "\n</table>";
  644. }
  645. }

Documentation generated on Wed, 19 Sep 2007 10:22:53 -0400 by phpDocumentor 1.3.0RC3