Source for file browse.act.php

Documentation is available at browse.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.logging
  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: browse.act.php,v 1.17 2007/09/19 14:04:56 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13. require_once(POLYPHONY."/main/library/ResultPrinter/TableIteratorResultPrinter.class.php");
  14. require_once(HARMONI."GUIManager/Components/Blank.class.php");
  15.  
  16. /**
  17. * This action provides browsing access for logs.
  18. *
  19. * @since 11/10/04
  20. *
  21. * @package polyphony.agents
  22. *
  23. * @copyright Copyright &copy; 2005, Middlebury College
  24. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  25. *
  26. * @version $Id: browse.act.php,v 1.17 2007/09/19 14:04:56 adamfranco Exp $
  27. */
  28. class browseAction
  29. extends MainWindowAction
  30. {
  31. /**
  32. * Check Authorizations
  33. *
  34. * @return boolean
  35. * @access public
  36. * @since 4/26/05
  37. */
  38. function isAuthorizedToExecute () {
  39. // Check for authorization
  40. $authZManager = Services::getService("AuthZ");
  41. $idManager = Services::getService("IdManager");
  42. if ($authZManager->isUserAuthorized(
  43. $idManager->getId("edu.middlebury.authorization.view"),
  44. $idManager->getId("edu.middlebury.authorization.root")))
  45. {
  46. return TRUE;
  47. } else {
  48. return FALSE;
  49. }
  50. }
  51. /**
  52. * Return the heading text for this action, or an empty string.
  53. *
  54. * @return string
  55. * @access public
  56. * @since 4/26/05
  57. */
  58. function getHeadingText () {
  59. return dgettext("polyphony", "Browse Logs");
  60. }
  61. /**
  62. * Build the content for this action
  63. *
  64. * @return void
  65. * @access public
  66. * @since 4/26/05
  67. */
  68. function buildContent () {
  69. $defaultTextDomain = textdomain("polyphony");
  70. $actionRows =$this->getActionRows();
  71. $harmoni = Harmoni::instance();
  72. $harmoni->request->startNamespace("polyphony-logs");
  73. $harmoni->request->passthrough('log', 'priority',
  74. 'startYear', 'startMonth', 'startDay', 'startHour',
  75. 'endYear', 'endMonth', 'endDay', 'endHour',
  76. 'agent_id', 'node_id', 'category');
  77.  
  78. $agentManager = Services::getService("Agent");
  79. $idManager = Services::getService("Id");
  80. $hierarchyManager = Services::getService("Hierarchy");
  81. /*********************************************************
  82. * the log search form
  83. *********************************************************/
  84. // Log header
  85. $actionRows->add(new Heading(_("Logs"), 2), "100%", null, LEFT, CENTER);
  86. $loggingManager = Services::getService("Logging");
  87. $log =$loggingManager->getLogForWriting("test_log");
  88. $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes",
  89. "A format in which the acting Agent[s] and the target nodes affected are specified.");
  90. $priorityType = new Type("logging", "edu.middlebury", "normal",
  91. "An action which involves reading.");
  92. // Links to other logs
  93. $logNames =$loggingManager->getLogNamesForReading();
  94. ob_start();
  95. if (RequestContext::value("log"))
  96. $currentLogName = RequestContext::value("log");
  97. while ($logNames->hasNext()) {
  98. $logName = $logNames->next();
  99. if (!isset($currentLogName))
  100. $currentLogName = $logName;
  101. if ($logName != $currentLogName) {
  102. print "\n<a href='";
  103. print $harmoni->request->quickURL("logs", "browse",
  104. array( "log" => $logName));
  105. print "'>".$logName."</a>";
  106. } else
  107. print $logName;
  108. if ($logNames->hasNext())
  109. print " | ";
  110. }
  111. print "
  112. <table border='0'>
  113. <tr>
  114. <th valign='top'>"._("Date Range: ")."</th>
  115. <td>
  116.  
  117. ";
  118. $startDate =$this->getStartDate();
  119. $endDate =$this->getEndDate();
  120. $this->printDateRangeForm($startDate, $endDate);
  121.  
  122. print "
  123.  
  124. </td>
  125. </tr>
  126. ";
  127. if (RequestContext::value('agent_id') || RequestContext::value('node_id')
  128. || RequestContext::value('category'))
  129. {
  130. print "
  131. <tr>
  132. <th>"._("Filters:")."</th>
  133. <td>
  134. ";
  135. if (RequestContext::value('agent_id')) {
  136. print "\n\t\t\t";
  137. $id =$idManager->getId(RequestContext::value('agent_id'));
  138. $url = $harmoni->request->quickURL("logs", "browse",
  139. array( "agent_id" => ''));
  140. $agent =$agentManager->getAgent($id);
  141. print $agent->getDisplayName();
  142. print "\n\t\t\t\t<input type='button' onclick='window.location=\"";
  143. print str_replace('&amp;', '&', $url);
  144. print "\"' value='X'/>";
  145. }
  146. if (RequestContext::value('agent_id') && RequestContext::value('node_id'))
  147. print "\n\t\t\t &nbsp; &nbsp; &nbsp; &nbsp; ";
  148. if (RequestContext::value('node_id')) {
  149. print "\n\t\t\t";
  150. $id =$idManager->getId(RequestContext::value('node_id'));
  151. $url = $harmoni->request->quickURL("logs", "browse",
  152. array( "node_id" => ''));
  153. $node =$hierarchyManager->getNode($id);
  154. print $node->getDisplayName();
  155. print "\n\t\t\t\t<input type='button' onclick='window.location=\"";
  156. print str_replace('&amp;', '&', $url);
  157. print "\"' value='X'/>";
  158. }
  159. if ((RequestContext::value('agent_id') || RequestContext::value('node_id')) && RequestContext::value('category'))
  160. print "\n\t\t\t &nbsp; &nbsp; &nbsp; &nbsp; ";
  161. if (RequestContext::value('category')) {
  162. print "\n\t\t\t";
  163. $url = $harmoni->request->quickURL("logs", "browse",
  164. array( "category" => ''));
  165. print urldecode(RequestContext::value('category'));
  166. print "\n\t\t\t\t<input type='button' onclick='window.location=\"";
  167. print str_replace('&amp;', '&', $url);
  168. print "\"' value='X'/>";
  169. }
  170. }
  171. print "\n\t</table>";
  172. $actionRows->add(new Block(ob_get_clean(), STANDARD_BLOCK), "100%", null, LEFT, TOP);
  173. // --- The Current log ---
  174. if (isset($currentLogName)) {
  175. $log =$loggingManager->getLogForReading($currentLogName);
  176. $actionRows->add(new Heading($log->getDisplayName(), 3), "100%", null, LEFT, CENTER);
  177. ob_start();
  178. // Links to other priorities
  179. print "<strong>"._("Priority: ")."</strong>";
  180. if (RequestContext::value("priority")) {
  181. $currentPriorityType = Type::fromString(
  182. RequestContext::value("priority"));
  183. $entries =$log->getEntries($formatType, $currentPriorityType);
  184. if (!$entries->hasNext()) {
  185. unset($currentPriorityType, $entries);
  186. }
  187. }
  188. $priorityTypes =$loggingManager->getPriorityTypes();
  189. $priorityLinks = array();
  190. while ($priorityTypes->hasNext()) {
  191. $priorityType =$priorityTypes->next();
  192. // Only print priority types with entries
  193. $entries =$log->getEntries($formatType, $priorityType);
  194. if ($entries->hasNext()) {
  195. if (!isset($currentPriorityType))
  196. $currentPriorityType =$priorityType;
  197. if (!$priorityType->isEqual($currentPriorityType)) {
  198. $string = "\n<a href='";
  199. $string .= $harmoni->request->quickURL("logs", "browse",
  200. array( "log" => RequestContext::value("log"),
  201. "priority" => Type::typeToString($priorityType)));
  202. $string .= "'>".$priorityType->getKeyword()."</a>";
  203. } else
  204. $string = $priorityType->getKeyword();
  205. $priorityLinks[] = $string;
  206. }
  207. unset($entries);
  208. }
  209. print implode(" | ", $priorityLinks);
  210. if (isset($currentPriorityType)) {
  211. // Entries
  212. print<<<END
  213. <script type='text/javascript'>
  214. /* <![CDATA[ */
  215. function showTrace(buttonElement) {
  216. newWindow = window.open("", "traceWindow", 'toolbar=no,width=600,height=500,resizable=yes,scrollbars=yes,status=no')
  217. // the next sibling is text, the one after that is our hidden div
  218. newWindow.document.write(buttonElement.nextSibling.nextSibling.innerHTML)
  219. newWindow.document.bgColor="lightpink"
  220. newWindow.document.close()
  221. }
  222. /* ]]> */
  223. </script>
  224. END;
  225. // Do a search if needed
  226. if (!$startDate->isEqualTo($this->minDate())
  227. || !$endDate->isEqualTo(DateAndTime::tomorrow())
  228. || RequestContext::value('agent_id')
  229. || RequestContext::value('node_id')
  230. || RequestContext::value('category'))
  231. {
  232. $criteria = array();
  233. $criteria['start'] =$startDate;
  234. $criteria['end'] =$endDate;
  235. if (RequestContext::value('agent_id'))
  236. $criteria['agent_id'] =$idManager->getId(
  237. RequestContext::value('agent_id'));
  238. if (RequestContext::value('node_id'))
  239. $criteria['node_id'] =$idManager->getId(
  240. RequestContext::value('node_id'));
  241. if (RequestContext::value('category'))
  242. $criteria['category'] = urldecode(RequestContext::value('category'));
  243. $searchType = new Type("logging_search", "edu.middlebury", "Date-Range/Agent/Node");
  244. $entries =$log->getEntriesBySearch($criteria, $searchType,
  245. $formatType, $currentPriorityType);
  246. } else {
  247. $entries =$log->getEntries($formatType, $currentPriorityType);
  248. }
  249. $headRow = "
  250. <tr>
  251. <th>timestamp</th>
  252. <th>category</th>
  253. <th>description</th>
  254. <th>trace</th>
  255. <th>agents</th>
  256. <th>nodes</th>
  257. </tr>";
  258. $resultPrinter = new TableIteratorResultPrinter($entries, $headRow,
  259. 20, "printLogRow", 1);
  260. print $resultPrinter->getTable();
  261. }
  262. if (isset($currentLogName) && isset($currentPriorityType)) {
  263. $url = $harmoni->request->quickURL('logs', 'browse_rss',
  264. array("log" => $currentLogName,
  265. "priority" => Type::typeToString($currentPriorityType)));
  266. $title = $currentLogName." ".$currentPriorityType->getKeyword()." "._("Logs");
  267. $outputHandler =$harmoni->getOutputHandler();
  268. $outputHandler->setHead($outputHandler->getHead()
  269. ."\n\t\t<link rel='alternate' type='application/rss+xml'"
  270. ." title='".$title."' href='".$url."'/>");
  271. print "\n\t\t<div style='text-align: right'>";
  272. print "\n\t\t<a href='".$url."' style='white-space: nowrap;' title='".$title."'>";
  273. print "\n\t\t\t<img src='".POLYPHONY_PATH."icons/rss_icon02.png' border='0'/>";
  274. print "\n\t\t\t"._("Subscribe to the RSS feed of this log");
  275. print "\n\t\t</a>";
  276. print "\n\t\t</div>";
  277. }
  278. $actionRows->add(new Block(ob_get_clean(), STANDARD_BLOCK), "100%", null, LEFT, TOP);
  279. }
  280. textdomain($defaultTextDomain);
  281. }
  282. /**
  283. * Answer the current starting date
  284. *
  285. * @return object DateAndTime
  286. * @access public
  287. * @since 3/8/06
  288. */
  289. function getStartDate () {
  290. if (RequestContext::value("startYear"))
  291. return DateAndTime::withYearMonthDayHourMinute(
  292. RequestContext::value("startYear"),
  293. RequestContext::value("startMonth"),
  294. RequestContext::value("startDay"),
  295. RequestContext::value("startHour"),
  296. 0);
  297. else
  298. return $this->minDate();
  299. }
  300. /**
  301. * Answer the current end date
  302. *
  303. * @return object DateAndTime
  304. * @access public
  305. * @since 3/8/06
  306. */
  307. function getEndDate () {
  308. if (RequestContext::value("endYear"))
  309. return DateAndTime::withYearMonthDayHourMinute(
  310. RequestContext::value("endYear"),
  311. RequestContext::value("endMonth"),
  312. RequestContext::value("endDay"),
  313. RequestContext::value("endHour"),
  314. 0);
  315. else
  316. return DateAndTime::tomorrow();
  317. }
  318. /**
  319. * Answer the minumum date to display
  320. *
  321. * @return object DateAndTime
  322. * @access public
  323. * @since 3/8/06
  324. */
  325. function minDate () {
  326. return DateAndTime::withYearDay(2000, 1);
  327. }
  328. /**
  329. * Print the dateRange form
  330. *
  331. * @param object DateAndTime $startDate
  332. * @param object DateAndTime $endDate
  333. * @return void
  334. * @access public
  335. * @since 3/8/06
  336. */
  337. function printDateRangeForm( $startDate, $endDate ) {
  338. $min =$this->minDate();
  339. $max = DateAndTime::tomorrow();
  340. $harmoni = Harmoni::instance();
  341. print "\n<form action='";
  342. print $harmoni->request->quickURL('logs', 'browse');
  343. print "' method='post'>";
  344. print "\n\t<select name='".RequestContext::name("startMonth")."'>";
  345. $month = 1;
  346. while ($month <= 12) {
  347. print "\n\t\t<option value='".$month."'";
  348. print (($month == $startDate->month())?" selected='selected'":"");
  349. print ">".Month::nameOfMonth($month)."</option>";
  350. $month++;
  351. }
  352. print "\n\t</select>";
  353. print "\n\t<select name='".RequestContext::name("startDay")."'>";
  354. $day = 1;
  355. while ($day <= 31) {
  356. print "\n\t\t<option value='".$day."'";
  357. print (($day == $startDate->dayOfMonth())?" selected='selected'":"");
  358. print ">".$day."</option>";
  359. $day++;
  360. }
  361. print "\n\t</select>";
  362. print "\n\t<select name='".RequestContext::name("startYear")."'>";
  363. $year = $max->year();
  364. $minYear = $min->year();
  365. while ($year >= $minYear) {
  366. print "\n\t\t<option value='".$year."'";
  367. print (($year == $startDate->year())?" selected='selected'":"");
  368. print ">$year</option>";
  369. $year--;
  370. }
  371. print "\n\t</select>";
  372. print "\n\t<select name='".RequestContext::name("startHour")."'>";
  373. $hour = 0;
  374. while ($hour <= 23) {
  375. print "\n\t\t<option value='".$hour."'";
  376. print (($hour == $startDate->hour())?" selected='selected'":"");
  377. print ">".sprintf("%02d", $hour).":00</option>";
  378. $hour++;
  379. }
  380. print "\n\t</select>";
  381. print "\n\t<strong> to: </strong>";
  382. print "\n\t<select name='".RequestContext::name("endMonth")."'>";
  383. $month = 1;
  384. while ($month <= 12) {
  385. print "\n\t\t<option value='".$month."'";
  386. print (($month == $endDate->month())?" selected='selected'":"");
  387. print ">".Month::nameOfMonth($month)."</option>";
  388. $month++;
  389. }
  390. print "\n\t</select>";
  391. print "\n\t<select name='".RequestContext::name("endDay")."'>";
  392. $day = 1;
  393. while ($day <= 31) {
  394. print "\n\t\t<option value='".$day."'";
  395. print (($day == $endDate->dayOfMonth())?" selected='selected'":"");
  396. print ">".$day."</option>";
  397. $day++;
  398. }
  399. print "\n\t</select>";
  400. print "\n\t<select name='".RequestContext::name("endYear")."'>";
  401. $year = $max->year();
  402. $minYear = $min->year();
  403. while ($year >= $minYear) {
  404. print "\n\t\t<option value='".$year."'";
  405. print (($year == $endDate->year())?" selected='selected'":"");
  406. print ">$year</option>";
  407. $year--;
  408. }
  409. print "\n\t</select>";
  410. print "\n\t<select name='".RequestContext::name("endHour")."'>";
  411. $hour = 0;
  412. while ($hour <= 23) {
  413. print "\n\t\t<option value='".$hour."'";
  414. print (($hour == $endDate->hour())?" selected='selected'":"");
  415. print ">".sprintf("%02d", $hour).":00</option>";
  416. $hour++;
  417. }
  418. print "\n\t</select>";
  419. print "\n\t<input type='submit' value='"._("Submit")."'/>";
  420. print "\n\t<a href='";
  421. print $harmoni->request->quickURL('logs', 'browse', array(
  422. 'startYear' => $min->year(),
  423. 'startMonth' => $min->month(),
  424. 'startDay' => $min->dayOfMonth(),
  425. 'startHour' => $min->hour(),
  426. 'endYear' => $max->year(),
  427. 'endMonth' => $max->month(),
  428. 'endDay' => $max->dayOfMonth(),
  429. 'endHour' => $max->hour()
  430. ));
  431. print "'>";
  432. print "\n\t\t<input type='button' value='"._("Clear")."' />";
  433. print "</a>";
  434. print "\n</form>";
  435. }
  436. }
  437.  
  438. /**
  439. * Print the row for an entry
  440. *
  441. * @param object Entry $entry
  442. * @return void
  443. * @access public
  444. * @since 3/9/06
  445. */
  446. function printLogRow ( $entry ) {
  447. $harmoni = Harmoni::instance();
  448. $agentManager = Services::getService("Agent");
  449. $idManager = Services::getService("Id");
  450. $hierarchyManager = Services::getService("Hierarchy");
  451. print "\n\t<tr>";
  452. $timestamp =$entry->getTimestamp();
  453. $timezone =$timestamp->timeZone();
  454. $timezoneOffset =$timezone->offset();
  455. print "\n\t\t<td title='";
  456. print $timezone->name()." (".$timezoneOffset->hours().":".sprintf("%02d", abs($timezoneOffset->minutes())).")";
  457. print "' style='white-space: nowrap'>";
  458. print $timestamp->monthName()." ";
  459. print $timestamp->dayOfMonth().", ";
  460. print $timestamp->year()." ";
  461. print $timestamp->hmsString();
  462. print "</td>";
  463. $item =$entry->getItem();
  464. print "\n\t\t<td style='white-space: nowrap'>";
  465. print "\n\t\t\t<a href='";
  466. print $harmoni->request->quickURL("logs", "browse",
  467. array( "category" => urlencode($item->getCategory())));
  468. print "'>";
  469. print $item->getCategory();
  470. print "</a>";
  471. print "\n\t\t</td>";
  472. print "\n\t\t<td>".$item->getDescription()."</td>";
  473. print "\n\t\t<td>";
  474. if ($trace = $item->getBacktrace()) {
  475. print "\n\t\t\t<input type='button' value='"._("Show Trace")."' onclick='showTrace(this)'/>";
  476. print "\n\t\t\t<div style='display: none'>".$trace."</div>";
  477. }
  478. print "</td>";
  479. print "\n\t\t<td style='white-space: nowrap'>";
  480. $agentIds =$item->getAgentIds(true);
  481. while ($agentIds->hasNext()) {
  482. $agentId =$agentIds->next();
  483. if ($agentManager->isAgent($agentId) || $agentManager->isGroup($agentId)) {
  484. $agent =$agentManager->getAgent($agentId);
  485. print "<a href='";
  486. print $harmoni->request->quickURL("logs", "browse",
  487. array( "agent_id" => $agentId->getIdString()));
  488. print "'>";
  489. print $agent->getDisplayName();
  490. print "</a>";
  491. } else
  492. print _("Id: ").$agentId->getIdString();
  493. if ($agentIds->hasNext())
  494. print ", <br/>";
  495. }
  496. print "\n\t\t</td>";
  497. print "\n\t\t<td style='white-space: nowrap'>";
  498. $nodeIds =$item->getNodeIds(true);
  499. while ($nodeIds->hasNext()) {
  500. $nodeId =$nodeIds->next();
  501. print "<a href='";
  502. print $harmoni->request->quickURL("logs", "browse",
  503. array( "node_id" => $nodeId->getIdString()));
  504. print "'>";
  505. if ($hierarchyManager->nodeExists($nodeId)) {
  506. $node =$hierarchyManager->getNode($nodeId);
  507. if ($node->getDisplayName())
  508. print $node->getDisplayName();
  509. else
  510. print _("Id: ").$nodeId->getIdString();
  511. } else {
  512. print _("Id: ").$nodeId->getIdString();
  513. }
  514. print "</a>";
  515. if ($nodeIds->hasNext())
  516. print ", <br/>";
  517. }
  518. print "\n\t\t</td>";
  519. print "\n\t</tr>";
  520. }

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