Source for file browse_authorizations.act.php

Documentation is available at browse_authorizations.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.authorization
  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_authorizations.act.php,v 1.25 2007/09/19 14:04:53 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13.  
  14. /**
  15. * This file will allow the user to browse authorizations.
  16. *
  17. * @since 11/11/04
  18. * @author Ryan Richards
  19. * @author Adam Franco
  20. *
  21. * @package polyphony.authorization
  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_authorizations.act.php,v 1.25 2007/09/19 14:04:53 adamfranco Exp $
  27. */
  28. class browse_authorizationsAction
  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. $authN = Services::getService("AuthN");
  40. $idM = Services::getService("Id");
  41. $authTypes =$authN->getAuthenticationTypes();
  42. while ($authTypes->hasNext()) {
  43. $authType =$authTypes->next();
  44. $id =$authN->getUserId($authType);
  45. if (!$id->isEqual($idM->getId('edu.middlebury.agents.anonymous'))) {
  46. return true;
  47. }
  48. }
  49. return false;
  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 Authorizations");
  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.  
  71. $idManager = Services::getService("Id");
  72. $actionRows =$this->getActionRows();
  73. $harmoni = Harmoni::instance();
  74. $harmoni->request->startNamespace("polyphony-authorizations");
  75.  
  76. $actionRows->add(new Block("&nbsp; &nbsp; "._("Below is a listing of all of the Users/Groups who are authorized to do various functions in the system. Click on a name to edit the authorizations for that User/Group")."<br /><br />",STANDARD_BLOCK));
  77. // Buttons to go back to edit auths for a different user, or to go home
  78. ob_start();
  79. print "<table width='100%'><tr><td align='left'>";
  80. print "</td><td align='right'>";
  81. print "<a href='".$harmoni->request->quickURL("admin","main")."'><button>"._("Return to the Admin Tools")."</button></a>";
  82. print "</td></tr></table>";
  83. $nav = new Block(ob_get_contents(), STANDARD_BLOCK);
  84. $actionRows->add($nav, "100%", null, LEFT, CENTER);
  85. ob_end_clean();
  86. // Get all hierarchies and their root qualifiers
  87. $authZManager = Services::getService("AuthorizationManager");
  88. $hierarchyIds =$authZManager->getQualifierHierarchies();
  89. $hierarchyManager = Services::getService("Hierarchy");
  90. while ($hierarchyIds->hasNext()) {
  91. $hierarchyId =$hierarchyIds->next();
  92. $hierarchy =$hierarchyManager->getHierarchy($hierarchyId);
  93. $header = new Heading($hierarchy->getDisplayName()." - <em>".$hierarchy->getDescription()."</em>", 2);
  94. $actionRows->add($header, "100%", null, LEFT, CENTER);
  95. // Get the root qualifiers for the Hierarchy
  96. $qualifiers =$authZManager->getRootQualifiers($hierarchyId);
  97. while ($qualifiers->hasNext()) {
  98. $qualifier =$qualifiers->next();
  99. //print get_class($qualifier);
  100. // Create a layout for this qualifier
  101. // if ($authZManager->isUserAuthorizedInChildren(
  102. // $idManager->getId("edu.middlebury.authorization.view"),
  103. // $qualifier->getId())) {
  104. ob_start();
  105. HierarchyPrinter::printNode($qualifier, $harmoni,
  106. 2,
  107. "browse_authorizationsAction::printQualifier",
  108. "browse_authorizationsAction::hasChildQualifiers",
  109. "browse_authorizationsAction::getChildQualifiers",
  110. new HTMLColor("#ddd")
  111. );
  112. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  113. ob_end_clean();
  114. // }
  115. }
  116. }
  117. // Buttons to go back to edit auths for a different user, or to go home
  118. $actionRows->add($nav, "100%", null, LEFT, CENTER);
  119. $harmoni->request->endNamespace();
  120. textdomain($defaultTextDomain);
  121. }
  122.  
  123.  
  124. /*******************************************************
  125. * Callback functions for printing
  126. *********************************************************/
  127.  
  128. /**
  129. * Callback function for printing a qualifier.
  130. *
  131. * @param object Qualifier $qualifier
  132. * @return void
  133. * @access public
  134. * @ignore
  135. */
  136. function printQualifier($qualifier) {
  137. $id =$qualifier->getId();
  138. $type =$qualifier->getQualifierType();
  139. $title = _("Id: ").$id->getIdString()." ";
  140. $title .= _("Type: ").$type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  141. print "\n<a title='$title'><strong>".$qualifier->getReferenceName()."</strong></a>";
  142. // Check that the current user is authorized to see the authorizations.
  143. $authZ = Services::getService("AuthZ");
  144. $idManager = Services::getService("Id");
  145. if ($authZ->isUserAuthorized(
  146. $idManager->getId("edu.middlebury.authorization.view_authorizations"),
  147. $id))
  148. {
  149. print "\n<div style='margin-left: 10px;'>";
  150. browse_authorizationsAction::printEditOptions($qualifier);
  151. print "\n</div>";
  152. }
  153. // If they are not authorized to view the AZs, notify
  154. else {
  155. print " <em>"._("You are not authorized to view authorizations here.")."<em>";
  156. }
  157. }
  158. /**
  159. * Callback function for determining if a qualifier has children.
  160. *
  161. * @param object Qualifier $qualifier
  162. * @return boolean
  163. * @access public
  164. * @ignore
  165. */
  166. function hasChildQualifiers($qualifier) {
  167. return $qualifier->isParent();
  168. }
  169. /**
  170. * Callback function for fetching the children of a qualifier.
  171. *
  172. * @param object Qualifier $qualifier
  173. * @return array
  174. * @access public
  175. * @ignore
  176. */
  177. function getChildQualifiers($qualifier) {
  178. $array = array();
  179. $iterator =$qualifier->getChildren();
  180. while ($iterator->hasNext()) {
  181. $array[] =$iterator->next();
  182. }
  183. return $array;
  184. }
  185. /**
  186. * Callback function for printing a table of all functions.
  187. * To be used for each qualifier in the hierarchy.
  188. *
  189. * @param object Qualifier $qualifier
  190. * @return void
  191. * @access public
  192. * @ignore
  193. */
  194. function printEditOptions($qualifier) {
  195. $qualifierId =$qualifier->getId();
  196. $harmoni = Harmoni::instance();
  197. $authZManager = Services::getService("AuthZ");
  198. $agentManager = Services::getService("Agent");
  199. $expandedNodes = array();
  200. if ($tmp = $harmoni->request->get("expandedNodes")) $expandedNodes = explode(",", $tmp);
  201. $functionTypes =$authZManager->getFunctionTypes();
  202. print "\n<table>";
  203. while ($functionTypes->hasNext()) {
  204. print "\n<tr>";
  205. $functionType =$functionTypes->next();
  206. $functions =$authZManager->getFunctions($functionType);
  207. $title = _("Functions for")." ";
  208. $title .= $functionType->getKeyword();
  209. print "\n\t<th style='margin-bottom: 3px'>";
  210. print "\n\t\t<a";
  211. print " title='".$title."'";
  212. print " href=\"Javascript:window.alert('".$title."')\"";
  213. print ">?</a>";
  214. print "\n\t</th>";
  215. $numFunctions = 0;
  216. while ($functions->hasNext()) {
  217. $numFunctions++;
  218. $function =$functions->next();
  219. $functionId =$function->getId();
  220. print "\n\t<td style='border: 1px solid #000; border-right: 0px solid #000; font-weight: bold' align='right' valign='top'>";
  221. print "\n\t<span style='white-space: nowrap'>".$function->getReferenceName().":</span>";
  222. print "\n\t</td>";
  223. print "\n\t<td style='border: 1px solid #000; border-left: 0px solid #000;' valign='top'>";
  224. $agentsThatCanDo =$authZManager->getWhoCanDo($functionId, $qualifierId, TRUE);
  225. while ($agentsThatCanDo->hasNext()) {
  226. $agentId =$agentsThatCanDo->next();
  227. print "<span style='white-space: nowrap'>";
  228. print "<a href='"
  229. .$harmoni->request->quickURL(
  230. "authorization",
  231. "edit_authorizations",
  232. array("agentId" => $agentId->getIdString(),
  233. "expanded_nodes" => RequestContext::value("expanded_nodes"))).
  234. "' title='Edit Authorizations for this User/Group'>";
  235. if ($agentManager->isAgent($agentId)) {
  236. $agent =$agentManager->getAgent($agentId);
  237. print $agent->getDisplayName();
  238. } else if ($agentManager->isGroup($agentId)) {
  239. $group =$agentManager->getGroup($agentId);
  240. print $group->getDisplayName();
  241. } else {
  242. print "Agent/Group Id ".$agentId->getIdString()."";
  243. }
  244. print "</a>";
  245. if ($agentsThatCanDo->hasNext())
  246. print ", ";
  247. print "</span>";
  248. }
  249. print "\n\t</td>";
  250. // If we are up to six and we have more, start a new row.
  251. if ($numFunctions % 3 == 0 && $functions->hasNext())
  252. print "\n</tr>\n<tr>\n\t<th>\n\t\t&nbsp;\n\t</th>";
  253. }
  254. print "\n</tr>";
  255. }
  256. print"\n</table>";
  257. }
  258. }
  259.  
  260. ?>

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