Source for file edit_authorizations.act.php

Documentation is available at edit_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: edit_authorizations.act.php,v 1.48 2007/09/19 14:04:53 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  13.  
  14. /**
  15. * edit_authorizations.act.php
  16. * This file will allow the user to edit authorizations for a given user.
  17. * The chosen user information will have been passed from choose_agents.act.php via FORM action.
  18. * 11/11/04 Ryan Richards
  19. *
  20. * @since 11/11/04
  21. * @author Ryan Richards
  22. * @author Adam Franco
  23. *
  24. * @package polyphony.authorization
  25. *
  26. * @copyright Copyright &copy; 2005, Middlebury College
  27. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  28. *
  29. * @version $Id: edit_authorizations.act.php,v 1.48 2007/09/19 14:04:53 adamfranco Exp $
  30. */
  31. class edit_authorizationsAction
  32. extends MainWindowAction
  33. {
  34. /**
  35. * Check Authorizations
  36. *
  37. * @return boolean
  38. * @access public
  39. * @since 4/26/05
  40. */
  41. function isAuthorizedToExecute () {
  42. return TRUE;
  43. }
  44. /**
  45. * Return the heading text for this action, or an empty string.
  46. *
  47. * @return string
  48. * @access public
  49. * @since 4/26/05
  50. */
  51. function getHeadingText () {
  52. $harmoni = Harmoni::instance();
  53. $idManager = Services::getService("Id");
  54. $agentManager = Services::getService("Agent");
  55. // Get the id of the selected agent using $_REQUEST
  56. $harmoni->request->startNamespace("polyphony-authorizations");
  57. $mult = RequestContext::value("mult");
  58. $agents = RequestContext::value("agents");
  59. $idObject = $mult?null:$idManager->getId(RequestContext::value("agentId"));
  60. // $idObject =$idManager->getId(RequestContext::value("agentId"));
  61. $GLOBALS["agentId"] =$idObject;
  62. $harmoni->request->endNamespace();
  63. if ($mult) {
  64. return dgettext("polyphony", "Modify Authorizations for Multiple Agents");
  65. } else if ($agentManager->isGroup($idObject)) {
  66. $agent =$agentManager->getGroup($idObject);
  67. return dgettext("polyphony", "Modify Authorizations for Group").": <em> "
  68. .$agent->getDisplayName()."</em>";
  69. } else if ($agentManager->isAgent($idObject)) {
  70. $agent =$agentManager->getAgent($idObject);
  71. return dgettext("polyphony", "Modify Authorizations for User").": <em> "
  72. .$agent->getDisplayName()."</em>";
  73. } else {
  74. return dgettext("polyphony", "Modify Authorizations for the User/Group Id").": <em> "
  75. .$idObject->getIdString()."</em>";
  76. }
  77. }
  78. /**
  79. * Build the content for this action
  80. *
  81. * @return void
  82. * @access public
  83. * @since 4/26/05
  84. */
  85. function buildContent () {
  86. $defaultTextDomain = textdomain("polyphony");
  87. $actionRows =$this->getActionRows();
  88. $harmoni = Harmoni::instance();
  89. // start our namespace
  90. $harmoni->request->startNamespace("polyphony-authorizations");
  91. $harmoni->request->passthrough();
  92.  
  93. // set the return URL
  94. $harmoni->history->markReturnURL("polyphony/agents/process_authorizations");
  95.  
  96. // Intro
  97. $idManager = Services::getService("Id");
  98. $agentManager = Services::getService("Agent");
  99. $authZManager = Services::getService("AuthZ");
  100. // Intro message
  101. $intro = new Block("&nbsp; &nbsp; "._("Check or uncheck authorization(s) for the section(s) of your choice.")."<br />
  102. &nbsp; &nbsp; "._("After each change, the changes are saved automatically.")."<br /><br />", STANDARD_BLOCK);
  103. $actionRows->add($intro);
  104. // Get the id of the selected agent using $_REQUEST <-- !!! do we need this???
  105. $mult = RequestContext::value("mult");
  106. $agents = RequestContext::value("agents");
  107. $id = RequestContext::value("agentId");
  108. // get a list of agents we are editing
  109. if ($harmoni->request->get("mult")) {
  110. $agentIds = unserialize($harmoni->request->get("agents"));
  111. } else {
  112. $agentIds = array($harmoni->request->get("agentId"));
  113. }
  114. $totalAgents = count($agentIds);
  115. $this->_agentIds = array();
  116. foreach ($agentIds as $idString) {
  117. $this->_agentIds[] =$idManager->getId($idString);
  118. }
  119. // Break the path info into parts for the enviroment and parts that
  120. // designate which nodes to expand.
  121. $this->expandedNodes = explode("!", $harmoni->request->get('expanded_nodes'));
  122. // Buttons to go back to edit auths for a different user, or to go home
  123. ob_start();
  124. print "<table width='100%'><tr><td align='left'>";
  125. print "<a href='".$harmoni->history->getReturnURL("polyphony/authorization/edit_authorizations")."'><button>&lt;&lt; "._("Go back")."</button></a>";
  126. print "</td><td align='right'>";
  127. print "<a href='".$harmoni->request->quickURL("admin","main")."'><button>"._("Return to the Admin Tools")."</button></a>";
  128. print "</td></tr></table>";
  129. $nav = new Block(ob_get_contents(), STANDARD_BLOCK);
  130. $actionRows->add($nav, "100%", null, LEFT, CENTER);
  131. ob_end_clean();
  132. // Get all hierarchies and their root qualifiers
  133. $hierarchyIds =$authZManager->getQualifierHierarchies();
  134. $hierarchyManager = Services::getService("Hierarchy");
  135. while ($hierarchyIds->hasNext()) {
  136. $hierarchyId =$hierarchyIds->next();
  137. $hierarchy =$hierarchyManager->getHierarchy($hierarchyId);
  138. $header = new Heading($hierarchy->getDisplayName()." - <em>".$hierarchy->getDescription()."</em>", 2);
  139. $actionRows->add($header, "100%", null, LEFT, CENTER);
  140. // Get the root qualifiers for the Hierarchy
  141. $qualifiers =$authZManager->getRootQualifiers($hierarchyId);
  142. while ($qualifiers->hasNext()) {
  143. $qualifier =$qualifiers->next();
  144. // Create a layout for this qualifier
  145. ob_start();
  146. $this->printAZTable($qualifier);
  147. // HierarchyPrinter::printNode($qualifier, $harmoni,
  148. // 2,
  149. // "edit_authorizationsAction::printQualifier",
  150. // "edit_authorizationsAction::hasChildQualifiers",
  151. // "edit_authorizationsAction::getChildQualifiers",
  152. // new HTMLColor("#ddd")
  153. // );
  154. $qualifierLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
  155. ob_end_clean();
  156. $actionRows->add($qualifierLayout, "100%", null, LEFT, CENTER);
  157. }
  158. }
  159. $actionRows->add(new Block(_("Key: Im = Implicit authorization (an authorzation inherited further up the hierarchy or by group membership - must be changed where it was made Explicit)<br/>Ex = Explicit authorization (can be changed)"), STANDARD_BLOCK), "100%", null, TOP, LEFT);
  160. // Buttons to go back to edit auths for a different user, or to go home
  161. $actionRows->add($nav,"100%", null, LEFT,CENTER);
  162. $harmoni->request->endNamespace();
  163. textdomain($defaultTextDomain);
  164. }
  165. /**
  166. * Print the table of authorizations, topped by columns for the functions
  167. *
  168. * @param object Qualifier $qualifier
  169. * @return void
  170. * @access public
  171. * @since 1/6/06
  172. */
  173. function printAZTable ( $qualifier ) {
  174. $azManager = Services::getService("AuthZ");
  175. $functionOrder = array();
  176. print "\n\n<table border='0' style='text-align: center'>";
  177. $funcTypes =$azManager->getFunctionTypes();
  178. $funcTypeRow = '';
  179. ob_start();
  180. while ($funcTypes->hasNext()) {
  181. $funcType =$funcTypes->next();
  182. $functions =$azManager->getFunctions($funcType);
  183. $i = 0;
  184. while ($functions->hasNext()) {
  185. $i++;
  186. $function =$functions->next();
  187. $functionOrder[] =$function->getId();
  188. print "\n\t\t<th style='vertical-align: bottom; border: 1px solid; border-bottom: 0px;'>";
  189. $name = htmlspecialchars($function->getReferenceName());
  190. for ($m = 0; $m < strlen($name); $m++)
  191. print $name[$m].'<br/>';
  192. print "</th>";
  193. }
  194. $funcTypeRow .= "\n\t\t<th colspan='$i' style='vertical-align: top; text-align: center; border: 1px solid; border-bottom: 0px;'>";
  195. // $funcTypeRow .= "<span style='white-space: nowrap;'>"._("Functions for:")."</span><br/>";
  196. $funcTypeRow .= $funcType->getKeyword().":";
  197. print "</th>";
  198. }
  199. $funcRow = ob_get_clean();
  200. // Function Group Row
  201. print "\n\t<tr>";
  202. print "\n\t\t<td rowspan='2'>&nbsp;</td>";
  203. print $funcTypeRow;
  204. print "\n\t</tr>";
  205. // Function Row
  206. print "\n\t<tr>";
  207. print $funcRow;
  208. print "\n\t</tr>";
  209. // Recursively print the qualifier rows
  210. $this->printQualifierRows($qualifier, $functionOrder);
  211. print "\n</table>";
  212. }
  213. /**
  214. * print the qualifier AZ Row
  215. *
  216. * @param object Qualifier $qualifier
  217. * @param array $functionOrder
  218. * @param array $ancestorQualifierIds
  219. * @param optional integer $depth
  220. * @return void
  221. * @access public
  222. * @since 1/6/06
  223. */
  224. function printQualifierRows( $qualifier, $functionOrder, $depth=0 ) {
  225. $qualifierId =$qualifier->getId();
  226. $type =$qualifier->getQualifierType();
  227. $title = _("Id: ").$qualifierId->getIdString()." ";
  228. $title .= _("Type: ").$type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  229. print "\n\t<tr>";
  230. print "\n\t\t<th style='white-space: nowrap; text-align: left; border: 1px solid; border-right: 0px;'>";
  231. /*********************************************************/
  232. $marginLeft = ($depth * 20).'px';
  233. print "\n\t\t\t<table style='margin-left: $marginLeft'>";
  234. print "\n\t\t\t\t<tr><td valign='top'>";
  235. // Print The node
  236. if ($qualifier->isParent()) {
  237. ?>
  238.  
  239. <div style='
  240. border: 1px solid #000;
  241. width: 15px;
  242. height: 15px;
  243. text-align: center;
  244. text-decoration: none;
  245. font-weight: bold;
  246. '>
  247. <?php
  248. /**
  249. * @package polyphony.authorization
  250. */
  251. // The child nodes are already expanded for this node.
  252. // Show option to collapse the list.
  253. if (in_array($qualifierId->getIdString(), $this->expandedNodes)) {
  254. $newExpandedNodes = array_diff($this->expandedNodes,
  255. array($qualifierId->getIdString()));
  256. $symbol = '-';
  257. $expanded = TRUE;
  258. // The node is not already expanded. Show option to expand.
  259. } else {
  260. $newExpandedNodes = array_merge($this->expandedNodes,
  261. array($qualifierId->getIdString()));
  262. $symbol = '+';
  263. $expanded = FALSE;
  264. }
  265. $harmoni = Harmoni::instance();
  266. $url =$harmoni->request->mkURLWithPassthrough();
  267. $url->setValue('expanded_nodes', implode('!', $newExpandedNodes));
  268. print "<a style='text-decoration: none;' href='".$url->write()."'>".$symbol."</a>";
  269. print "\n\t\t</div>";
  270. // The node has no children. Do not show options to expand/collapse.
  271. } else {
  272. print "\n\t\t<div style='width: 15px;'>&nbsp;</div>";
  273. }
  274. print "\n\t\t\t\t</td>";
  275. print "\n\t\t\t\t<th>";
  276. /*********************************************************/
  277. print "\n\t\t\t\t\t<a title='".htmlspecialchars($title, ENT_QUOTES)."'>";
  278. print htmlspecialchars($qualifier->getReferenceName(), ENT_QUOTES);
  279. print "</a>";
  280. print "\n\t\t\t\t</th>";
  281. print "\n\t\t\t\t</tr>";
  282. print "\n\t\t\t</table>";
  283. print "\n\t\t</th>";
  284. // Load the explicit AZs that affect the agents
  285. $this->loadAZs($qualifierId);
  286. for ($i = 0; $i < count($functionOrder); $i++) {
  287. $this->printAZCell($qualifier, $functionOrder[$i]);
  288. }
  289. print "\n\t</tr>";
  290. // Recursively print the children.
  291. if (in_array($qualifierId->getIdString(), $this->expandedNodes)) {
  292. $children =$qualifier->getChildren();
  293. // Stuff for previous/next links
  294. $linkLeftSpace = (($depth + 1) * 20 + 25).'px';
  295. if (RequestContext::value($qualifierId->getIdString().'_start'))
  296. $start = intval(RequestContext::value($qualifierId->getIdString().'_start'));
  297. else
  298. $start = 0;
  299. $limit = 10;
  300. $total = $children->count();
  301. // previous link
  302. if ($total > $limit) {
  303. $harmoni = Harmoni::instance();
  304. $url =$harmoni->request->mkURLWithPassthrough();
  305. $url->setValue($qualifierId->getIdString().'_start', max($start - 10, 0));
  306. ob_start();
  307. print "\n\t<tr>";
  308. print "\n\t\t<td style='white-space: nowrap; text-align: left; border: 1px solid; border-right: 0px; padding-left: ".$linkLeftSpace."'>";
  309. print "\n\t\t\t"._("Displaying: ");
  310. $harmoni = Harmoni::instance();
  311. $url =$harmoni->request->mkURLWithPassthrough();
  312. $url->setValue($qualifierId->getIdString().'_start', 'STARTSTARTSTART');
  313. print "\n\t\t\t<select onchange='";
  314. print 'var url="'.$url->write().'"; var regex = /STARTSTARTSTART/; window.location = url.replace(regex, this.value);';
  315. print "'>";
  316. for ($i=0; $i<$total; $i=$i+10) {
  317. print "\n\t\t\t<option value='".$i."'";
  318. if ($i == $start)
  319. print " selected='selected'";
  320. print ">".($i+1)."-".($i+10)."</option>";
  321. }
  322. print "\n\t\t\t</select>";
  323. print "\n\t\t\t\t</td>";
  324. print "\n\t</tr>";
  325. $moreResults = ob_get_clean();
  326. print $moreResults;
  327. }
  328. // Children
  329. $skipping = 0;
  330. $printed = 0;
  331. while ($children->hasNext() && $printed < $limit) {
  332. if ($skipping < $start) {
  333. $children->skipNext();
  334. $skipping++;
  335. } else {
  336. $this->printQualifierRows( $children->next(), $functionOrder, $depth + 1 );
  337. $printed++;
  338. }
  339. }
  340. // next link
  341. if ($total > $limit)
  342. print $moreResults;
  343. }
  344. }
  345. /**
  346. * Print a cell with the authorizations for a given qualifier and function
  347. *
  348. * @param object Qualifier $qualifier
  349. * @param object Id $functionId
  350. * @return void
  351. * @access public
  352. * @since 1/6/06
  353. */
  354. function printAZCell ( $qualifier, $functionId ) {
  355. $harmoni = Harmoni::instance();
  356. $idManager = Services::getService("Id");
  357. $authZManager = Services::getService("AuthZ");
  358. $idManager = Services::getService("IdManager");
  359. $agentManager = Services::getService("AgentManager");
  360. print "\n\t\t<td>";
  361. // AZs
  362. print "\n\t\t\t<table>\n\t\t\t\t<tr>";
  363. $this->printNewEditOptions($qualifier, $functionId);
  364. print "\n\t\t\t\t</tr>\n\t\t\t</table>";
  365. // Old version
  366. // print "<hr/>";
  367. // print "\n\t\t<table><tr>";
  368. // $this->printEditOptions($qualifier, $functionId);
  369. // print "\n\t\t</tr></table>";
  370. print "\n\t\t</td>";
  371. }
  372. /**
  373. * Load the explicit AZs
  374. *
  375. * @return void
  376. * @access public
  377. * @since 1/9/06
  378. */
  379. function loadAZs ($qualifierId) {
  380. $this->_agentAZs = array();
  381. $azManager = Services::getService("AuthZ");
  382. foreach (array_keys($this->_agentIds) as $key) {
  383. $agentIdString = $this->_agentIds[$key]->getIdString();
  384. $null = null;
  385. $azs =$azManager->getAllAZs($this->_agentIds[$key], $null, $qualifierId, FALSE);
  386. $agentAZs[$agentIdString] = array();
  387. while ($azs->hasNext()) {
  388. $az =$azs->next();
  389. $function =$az->getFunction();
  390. $functionId =$function->getId();
  391. // $qualifier =$az->getQualifier();
  392. // $qualifierid =$qualifier->getId();
  393. if (!isset($this->_agentAZs[$agentIdString][$qualifierId->getIdString()]))
  394. $this->_agentAZs[$agentIdString][$qualifierId->getIdString()] = array();
  395. if (!isset($this->_agentAZs[$agentIdString][$qualifierId->getIdString()][$functionId->getIdString()]))
  396. $this->_agentAZs[$agentIdString][$qualifierId->getIdString()][$functionId->getIdString()] = array();
  397. $this->_agentAZs[$agentIdString][$qualifierId->getIdString()][$functionId->getIdString()][] =$az;
  398. }
  399. }
  400. }
  401.  
  402.  
  403. /*******************************************************
  404. * Callback Functions for printing
  405. *********************************************************/
  406.  
  407. /**
  408. * Callback function for printing a qualifier.
  409. *
  410. * @param object Qualifier $qualifier
  411. * @return void
  412. * @access public
  413. * @ignore
  414. */
  415. function printQualifier($qualifier) {
  416. $id =$qualifier->getId();
  417. $type =$qualifier->getQualifierType();
  418. $title = _("Id: ").$id->getIdString()." ";
  419. $title .= _("Type: ").$type->getDomain()."::".$type->getAuthority()."::".$type->getKeyword();
  420. print "\n<a title='".htmlspecialchars($title, ENT_QUOTES)."'><strong>".htmlspecialchars($qualifier->getReferenceName(), ENT_QUOTES)."</strong></a>";
  421. // Check that the current user is authorized to see the authorizations.
  422. $authZ = Services::getService("AuthZ");
  423. $idManager = Services::getService("IdManager");
  424. if ($authZ->isUserAuthorized(
  425. $idManager->getId("edu.middlebury.authorization.view_authorizations"),
  426. $id))
  427. {
  428. print "\n<div style='margin-left: 10px;'>";
  429. edit_authorizationsAction::printEditOptions($qualifier);
  430. print "\n</div>";
  431. }
  432. // If they are not authorized to view the AZs, notify
  433. else {
  434. print " <em>"._("You are not authorized to view authorizations here.")."<em>";
  435. }
  436. }
  437. /**
  438. * Callback function for printing a table of all functions.
  439. * To be used for each qualifier in the hierarchy.
  440. *
  441. * @param object Qualifier $qualifier
  442. * @return void
  443. * @access public
  444. * @ignore
  445. */
  446. function printEditOptions( $qualifier, $functionId ) {
  447. $qualifierId =$qualifier->getId();
  448. $harmoni = Harmoni::instance();
  449. $idManager = Services::getService("Id");
  450. $authZManager = Services::getService("AuthZ");
  451. $idManager = Services::getService("IdManager");
  452. $agentManager = Services::getService("AgentManager");
  453. $totalAgents = count($this->_agentIds);
  454. // IF an authorization exists for the user on this qualifier,
  455. // make checkbox already checked
  456. $numExplicit = 0;
  457. $numImplicit = 0;
  458. $authorized = 0;
  459. $implicitAZs = array();
  460. $implicitAZOwners = array();
  461. foreach (array_keys($this->_agentIds) as $key) {
  462. $allAZs =$authZManager->getAllAZs($this->_agentIds[$key], $functionId, $qualifierId, FALSE);
  463. $hasExplicit = $hasImplicit = false;
  464. while ($allAZs->hasNext()) {
  465. $az =$allAZs->next();
  466. if ($az->isExplicit()) {
  467. $hasExplicit = true;
  468. } else {
  469. $hasImplicit = true;
  470. $implicitAZs[] =$az;
  471. $implicitAZOwners[] =$this->_agentIds[$key];
  472. }
  473. }
  474. if ($hasExplicit) $numExplicit++;
  475. if ($hasImplicit) $numImplicit++;
  476. if ($hasExplicit || $hasImplicit) $authorized++;
  477. }
  478. // Store values for display output
  479. if ($authorized == $totalAgents)
  480. $borderColor = "green";
  481. else if ($authorized == 0)
  482. $borderColor = "red";
  483. else $borderColor = "yellow"; // partial authorizations
  484. if ($numExplicit > 0) {
  485. $explicitChecked = "checked='checked'";
  486. $toggleOperation = "delete";
  487. } else {
  488. $explicitChecked = "";
  489. $toggleOperation = "create";
  490. }
  491. print "\n\t\t<td style='border: 1px solid ".$borderColor.";'>";
  492. print "\n\t\t\t\t<table align='left'>";
  493. print "\n\t\t\t\t<tr>";
  494. // Print out a disabled checkbox for each implicit Auth.
  495. // $title = "";
  496. // for ($i=0; $i < count($implicitAZs); $i++) {
  497. // // Built info about the explicit AZs that cause this implictAZ
  498. // $implicitAZ =$implicitAZs[$i];
  499. // $AZOwnerId =$implicitAZOwners[$i];
  500. // $displayName = "";
  501. // if ($agentManager->isAgent($AZOwnerId)) {
  502. // $agent =$agentManager->getAgent($AZOwnerId);
  503. // $displayName = $agent->getDisplayName();
  504. // unset($agent);
  505. // } else if ($agentManager->isGroup($AZOwnerId)) {
  506. // $group =$agentManager->getGroup($AZOwnerId);
  507. // $displayName = $group->getDisplayName();
  508. // unset($group);
  509. // }
  510. // $explicitAZs =$authZManager->getExplicitUserAZsForImplicitAZ($implicitAZ);
  511. //
  512. // while ($explicitAZs->hasNext()) {
  513. // $title .= "$displayName - ";
  514. // $explicitAZ =$explicitAZs->next();
  515. // $explicitAgentId =$explicitAZ->getAgentId();
  516. // $explicitQualifier =$explicitAZ->getQualifier();
  517. // $explicitQualifierId =$explicitQualifier->getId();
  518. //
  519. // // get the agent/group for the AZ
  520. // if ($agentManager->isAgent($explicitAgentId)) {
  521. // $explicitAgent =$agentManager->getAgent($explicitAgentId);
  522. // $title .= _("User").": ".$explicitAgent->getDisplayName();
  523. // } else if ($agentManager->isGroup($explicitAgentId)) {
  524. // $explicitGroup =$agentManager->getGroup($explicitAgentId);
  525. // $title .= _("Group").": ".$explicitGroup->getDisplayName();
  526. // } else {
  527. // $title .= _("User/Group").": ".$explicitAgentId->getIdString();
  528. // }
  529. // $title .= ", "._("Location").": ".$explicitQualifier->getReferenceName();
  530. // // if ($explicitAZs->hasNext())
  531. // $title .= "; \n";
  532. // }
  533. //
  534. //
  535. // }
  536. print "\n\t\t\t\t\t<td style='white-space: nowrap'>";
  537. if ($numImplicit > 0) {
  538. // print out a checkbox for the implicit AZ
  539. // $safeTitle = str_replace("\n","\\n",htmlspecialchars($title, ENT_QUOTES));
  540. print "\n\t\t\t\t\t<span style='white-space: nowrap'>";
  541. print "\n\t\t\t\t\t\t<input type='checkbox' name='blah' value='blah'";
  542. // print " title='".htmlspecialchars($title, ENT_QUOTES)."'";
  543. print " checked='checked' disabled='disabled' />";
  544. if ($totalAgents > 1) {
  545. print "Im: <b>". $numImplicit . "/" . $totalAgents . "</b> ";
  546. }
  547. // print "\n\t\t\t\t\t\t<a";
  548. // // print " id='".$explicitAgentId->getIdString()
  549. // // ."-".$functionId->getIdString()
  550. // // ."-".$explicitQualifierId->getIdString()."'";
  551. // print " title='".htmlspecialchars($title, ENT_QUOTES)."'";
  552. // print " href=\"Javascript:window.alert('".str_replace("\n","\\n",htmlspecialchars($title, ENT_QUOTES))."')\"";
  553. // print ">?</a>";
  554. print "\n\t\t\t\t\t</span>";
  555. }
  556. // print an extra space
  557. if (count($implicitAZs))
  558. print "&nbsp;";
  559. $authZ = Services::getService("AuthZ");
  560. $idManager = Services::getService("IdManager");
  561. $canEdit = $authZ->isUserAuthorized(
  562. $idManager->getId("edu.middlebury.authorization.modify_authorizations"),
  563. $qualifierId);
  564.  
  565.  
  566. if ($totalAgents > 1) {
  567. $grantURL = $harmoni->request->quickURL("authorization","process_authorizations",
  568. array(
  569. "functionId"=>$functionId->getIdString(),
  570. "qualifierId"=>$qualifierId->getIdString(),
  571. "operation"=>"create"
  572. ));
  573. $revokeURL = $harmoni->request->quickURL("authorization","process_authorizations",
  574. array(
  575. "functionId"=>$functionId->getIdString(),
  576. "qualifierId"=>$qualifierId->getIdString(),
  577. "operation"=>"delete"
  578. ));
  579. print "\n\t\t\t\t\t\t";
  580. print "Ex: <b>".$numExplicit . "/" . $totalAgents . "</b>:\n";
  581. print "<select name='blah'".($canEdit?"":" disabled='disabled'")." onclick='if (this.value != \"nop\") window.location=this.value;'>\n";
  582. print "<option value='nop'>"._("action")."...</option>\n";
  583. print "<option value='$grantURL'>"._("Grant to All")."</option>\n";
  584. print "<option value='$revokeURL'>"._("Revoke Explicit")."</option>\n";
  585. print "</select><br/>\n";
  586. } else {
  587. print "\n\t\t\t\t\t\t<input type='checkbox' name='blah' value='blah' ";
  588. print $explicitChecked;
  589. // Check that the current user is authorized to modify the authorizations.
  590. $agentManager = Services::getService("AgentManager");
  591. if ($canEdit)
  592. {
  593. // The checkbox is really just for show, the link is where we send
  594. // to our processing to toggle the state of the authorization.
  595. $toggleURL = $harmoni->request->quickURL(
  596. "authorization",
  597. "process_authorizations",
  598. array(
  599. "functionId"=>$functionId->getIdString(),
  600. "qualifierId"=>$qualifierId->getIdString(),
  601. "operation"=>$toggleOperation
  602. ));
  603. print " onclick=\"Javascript:window.location='".$toggleURL."'\"";
  604. }
  605. // If they are not authorized to view the AZs, disable the checkbox
  606. else {
  607. print " disabled='disabled'";
  608. }
  609. print " />";
  610. }
  611. print "</td>";
  612. print "\n\t\t\t\t</tr>";
  613. print "\n\t\t\t\t</table>";
  614. print "\n\t\t</td>";
  615. }
  616. /**
  617. * Callback function for printing a table of all functions.
  618. * To be used for each qualifier in the hierarchy.
  619. *
  620. * @param object Qualifier $qualifier
  621. * @return void
  622. * @access public
  623. * @ignore
  624. */
  625. function printNewEditOptions( $qualifier, $functionId) {
  626. $qualifierId =$qualifier->getId();
  627. $harmoni = Harmoni::instance();
  628. $idManager = Services::getService("Id");
  629. $authZManager = Services::getService("AuthZ");
  630. $idManager = Services::getService("IdManager");
  631. $agentManager = Services::getService("AgentManager");
  632. $totalAgents = count($this->_agentIds);
  633. // IF an authorization exists for the user on this qualifier,
  634. // make checkbox already checked
  635. $numExplicit = 0;
  636. $numImplicit = 0;
  637. $authorized = 0;
  638. $implicitAZs = array();
  639. $implicitAZOwners = array();
  640. foreach (array_keys($this->_agentIds) as $key) {
  641. unset($allAZs);
  642. if (isset($this->_agentAZs
  643. [$this->_agentIds[$key]->getIdString()]
  644. [$qualifierId->getIdString()]
  645. [$functionId->getIdString()]))
  646. {
  647. $allAZs = $this->_agentAZs
  648. [$this->_agentIds[$key]->getIdString()]
  649. [$qualifierId->getIdString()]
  650. [$functionId->getIdString()];
  651. }
  652. $hasExplicit = $hasImplicit = false;
  653. if (isset($allAZs) && is_array($allAZs)) {
  654. foreach (array_keys($allAZs) as $azKey) {
  655. $az =$allAZs[$azKey];
  656. if ($az->isExplicit()) {
  657. $hasExplicit = true;
  658. } else {
  659. $hasImplicit = true;
  660. $implicitAZs[] =$az;
  661. $implicitAZOwners[] =$this->_agentIds[$key];
  662. }
  663. }
  664. if ($hasExplicit) $numExplicit++;
  665. if ($hasImplicit) $numImplicit++;
  666. if ($hasExplicit || $hasImplicit) $authorized++;
  667. }
  668. }
  669. // Store values for display output
  670. if ($authorized == $totalAgents)
  671. $borderColor = "green";
  672. else if ($authorized == 0)
  673. $borderColor = "red";
  674. else $borderColor = "yellow"; // partial authorizations
  675. if ($numExplicit > 0) {
  676. $explicitChecked = "checked='checked'";
  677. $toggleOperation = "delete";
  678. } else {
  679. $explicitChecked = "";
  680. $toggleOperation = "create";
  681. }
  682. print "\n\t\t<td style='border: 1px solid ".$borderColor.";'>";
  683. print "\n\t\t\t\t<table align='left'>";
  684. print "\n\t\t\t\t<tr>";
  685. // Print out a disabled checkbox for each implicit Auth.
  686. // $title = "";
  687. // for ($i=0; $i < count($implicitAZs); $i++) {
  688. // // Built info about the explicit AZs that cause this implictAZ
  689. // $implicitAZ =$implicitAZs[$i];
  690. // $AZOwnerId =$implicitAZOwners[$i];
  691. // $displayName = "";
  692. // if ($agentManager->isAgent($AZOwnerId)) {
  693. // $agent =$agentManager->getAgent($AZOwnerId);
  694. // $displayName = $agent->getDisplayName();
  695. // unset($agent);
  696. // } else if ($agentManager->isGroup($AZOwnerId)) {
  697. // $group =$agentManager->getGroup($AZOwnerId);
  698. // $displayName = $group->getDisplayName();
  699. // unset($group);
  700. // }
  701. // $explicitAZs =$authZManager->getExplicitUserAZsForImplicitAZ($implicitAZ);
  702. //
  703. // while ($explicitAZs->hasNext()) {
  704. // $title .= "$displayName - ";
  705. // $explicitAZ =$explicitAZs->next();
  706. // $explicitAgentId =$explicitAZ->getAgentId();
  707. // $explicitQualifier =$explicitAZ->getQualifier();
  708. // $explicitQualifierId =$explicitQualifier->getId();
  709. //
  710. // // get the agent/group for the AZ
  711. // if ($agentManager->isAgent($explicitAgentId)) {
  712. // $explicitAgent =$agentManager->getAgent($explicitAgentId);
  713. // $title .= _("User").": ".$explicitAgent->getDisplayName();
  714. // } else if ($agentManager->isGroup($explicitAgentId)) {
  715. // $explicitGroup =$agentManager->getGroup($explicitAgentId);
  716. // $title .= _("Group").": ".$explicitGroup->getDisplayName();
  717. // } else {
  718. // $title .= _("User/Group").": ".$explicitAgentId->getIdString();
  719. // }
  720. // $title .= ", "._("Location").": ".$explicitQualifier->getReferenceName();
  721. // // if ($explicitAZs->hasNext())
  722. // $title .= "; \n";
  723. // }
  724. //
  725. //
  726. // }
  727. print "\n\t\t\t\t\t<td style='white-space: nowrap'>";
  728. if ($numImplicit > 0) {
  729. // print out a checkbox for the implicit AZ
  730. // $safeTitle = str_replace("\n","\\n",htmlspecialchars($title, ENT_QUOTES));
  731. print "\n\t\t\t\t\t<span style='white-space: nowrap'>";
  732. print "\n\t\t\t\t\t\t<input type='checkbox' name='blah' value='blah'";
  733. // print " title='".htmlspecialchars($title, ENT_QUOTES)."'";
  734. print " checked='checked' disabled='disabled' />";
  735. if ($totalAgents > 1) {
  736. print "Im: <b>". $numImplicit . "/" . $totalAgents . "</b> ";
  737. }
  738. // print "\n\t\t\t\t\t\t<a";
  739. // // print " id='".$explicitAgentId->getIdString()
  740. // // ."-".$functionId->getIdString()
  741. // // ."-".$explicitQualifierId->getIdString()."'";
  742. // print " title='".htmlspecialchars($title, ENT_QUOTES)."'";
  743. // print " href=\"Javascript:window.alert('".str_replace("\n","\\n",htmlspecialchars($title, ENT_QUOTES))."')\"";
  744. // print ">?</a>";
  745. print "\n\t\t\t\t\t</span>";
  746. }
  747. // print an extra space
  748. if (count($implicitAZs))
  749. print "&nbsp;";
  750. $authZ = Services::getService("AuthZ");
  751. $idManager = Services::getService("IdManager");
  752. $canEdit = $authZ->isUserAuthorized(
  753. $idManager->getId("edu.middlebury.authorization.modify_authorizations"),
  754. $qualifierId);
  755.  
  756.  
  757. if ($totalAgents > 1) {
  758. $grantURL = $harmoni->request->quickURL("authorization","process_authorizations",
  759. array(
  760. "functionId"=>$functionId->getIdString(),
  761. "qualifierId"=>$qualifierId->getIdString(),
  762. "operation"=>"create"
  763. ));
  764. $revokeURL = $harmoni->request->quickURL("authorization","process_authorizations",
  765. array(
  766. "functionId"=>$functionId->getIdString(),
  767. "qualifierId"=>$qualifierId->getIdString(),
  768. "operation"=>"delete"
  769. ));
  770. print "\n\t\t\t\t\t\t";
  771. print "Ex: <b>".$numExplicit . "/" . $totalAgents . "</b>:\n";
  772. print "<select name='blah'".($canEdit?"":" disabled='disabled'")." onclick='if (this.value != \"nop\") window.location=this.value;'>\n";
  773. print "<option value='nop'>"._("action")."...</option>\n";
  774. print "<option value='$grantURL'>"._("Grant to All")."</option>\n";
  775. print "<option value='$revokeURL'>"._("Revoke Explicit")."</option>\n";
  776. print "</select><br/>\n";
  777. } else {
  778. print "\n\t\t\t\t\t\t<input type='checkbox' name='blah' value='blah' ";
  779. print $explicitChecked;
  780. // Check that the current user is authorized to modify the authorizations.
  781. $agentManager = Services::getService("AgentManager");
  782. if ($canEdit)
  783. {
  784. // The checkbox is really just for show, the link is where we send
  785. // to our processing to toggle the state of the authorization.
  786. $toggleURL = $harmoni->request->quickURL(
  787. "authorization",
  788. "process_authorizations",
  789. array(
  790. "functionId"=>$functionId->getIdString(),
  791. "qualifierId"=>$qualifierId->getIdString(),
  792. "operation"=>$toggleOperation
  793. ));
  794. print " onclick=\"Javascript:window.location='".$toggleURL."'\"";
  795. }
  796. // If they are not authorized to view the AZs, disable the checkbox
  797. else {
  798. print " disabled='disabled'";
  799. }
  800. print " />";
  801. }
  802. print "</td>";
  803. print "\n\t\t\t\t</tr>";
  804. print "\n\t\t\t\t</table>";
  805. print "\n\t\t</td>";
  806. }
  807.  
  808.  
  809. }
  810.  
  811.  
  812. ?>

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