Source for file choose_agent.act.php

Documentation is available at choose_agent.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: choose_agent.act.php,v 1.43 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 choose which agent they wish to modify
  16. * authorizations for.
  17. *
  18. * @since 11/11/04
  19. * @author Ryan Richards
  20. * @author Adam Franco
  21. *
  22. * @package polyphony.authorization
  23. *
  24. * @copyright Copyright &copy; 2005, Middlebury College
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  26. *
  27. * @version $Id: choose_agent.act.php,v 1.43 2007/09/19 14:04:53 adamfranco Exp $
  28. */
  29. class choose_agentAction
  30. extends MainWindowAction
  31. {
  32. /**
  33. * Check Authorizations
  34. *
  35. * @return boolean
  36. * @access public
  37. * @since 4/26/05
  38. */
  39. function isAuthorizedToExecute () {
  40. $authN = Services::getService("AuthN");
  41. $idM = Services::getService("Id");
  42. $authTypes =$authN->getAuthenticationTypes();
  43. while ($authTypes->hasNext()) {
  44. $authType =$authTypes->next();
  45. $id =$authN->getUserId($authType);
  46. if (!$id->isEqual($idM->getId('edu.middlebury.agents.anonymous'))) {
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. /**
  53. * Return the heading text for this action, or an empty string.
  54. *
  55. * @return string
  56. * @access public
  57. * @since 4/26/05
  58. */
  59. function getHeadingText () {
  60. return dgettext("polyphony", "Modify Authorizations for which User/Group?");
  61. }
  62. /**
  63. * Build the content for this action
  64. *
  65. * @return void
  66. * @access public
  67. * @since 4/26/05
  68. */
  69. function buildContent () {
  70. $defaultTextDomain = textdomain("polyphony");
  71. $actionRows =$this->getActionRows();
  72. $pageRows = new Container(new YLayout(), OTHER, 1);
  73. $harmoni = Harmoni::instance();
  74. // start our namespace
  75. $harmoni->history->markReturnURL("polyphony/authorization/edit_authorizations");
  76. $harmoni->request->startNamespace("polyphony-authorizations");
  77. $harmoni->request->passthrough();
  78. $agentManager = Services::getService("Agent");
  79. $idManager = Services::getService("Id");
  80. $everyoneId =$idManager->getId("edu.middlebury.agents.everyone");
  81. $usersId =$idManager->getId("edu.middlebury.agents.users");
  82. /*********************************************************
  83. * Buttons
  84. *********************************************************/
  85. ob_start();
  86. print "<table width='100%'><tr><td align='left'>";
  87. print "<a href='".$harmoni->request->quickURL("admin","main")."'><button>"._("Return to the Admin Tools")."</button></a>";
  88. print "</td><td align='right'>";
  89. print "<input type='button'";
  90. print " onclick='Javascript:submitAgentChoice()'";
  91. print " value='"._("Edit Authorizations for the selected User/Group")." --&gt;' />";
  92. print "</td></tr></table>";
  93. $submit = new Block(ob_get_contents(), STANDARD_BLOCK);
  94. $actionRows->add($submit, "100%", null, LEFT, CENTER);
  95. ob_end_clean();
  96. // Users header
  97. $actionRows->add(new Heading("Users", 2), "100%", null, LEFT, CENTER);
  98. /*********************************************************
  99. * the agent search form
  100. *********************************************************/
  101. ob_start();
  102. $self = $harmoni->request->quickURL();
  103. $lastCriteria = $harmoni->request->get('search_criteria');
  104. $search_criteria_name = RequestContext::name('search_criteria');
  105. $search_type_name = RequestContext::name('search_type');
  106. print _("Search For Users").": ";
  107. print <<<END
  108. <form action='$self' method='post'>
  109. <div>
  110. <input type='text' name='$search_criteria_name' value='$lastCriteria' />
  111. <br /><select name='$search_type_name'>
  112. END;
  113. $searchTypes =$agentManager->getAgentSearchTypes();
  114. while ($searchTypes->hasNext()) {
  115. $type =$searchTypes->next();
  116. $typeString = $type->getDomain()
  117. ."::".$type->getAuthority()
  118. ."::".$type->getKeyword();
  119. print "\n\t\t<option value='".htmlspecialchars($typeString, ENT_QUOTES)."'";
  120. if ($harmoni->request->get("search_type") == $typeString)
  121. print " selected='selected'";
  122. print ">".htmlspecialchars($typeString)."</option>";
  123. }
  124. print "\n\t</select>";
  125. print "\n\t<br /><input type='submit' value='"._("Search")."' />";
  126. print "\n\t<a href='".$harmoni->request->quickURL()."'>";
  127. print "\n\t\t<input type='button' value='"._("Clear")."' />\n\t</a>";
  128. print "\n</div>\n</form>";
  129. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK));
  130. ob_end_clean();
  131. /*********************************************************
  132. * Form and Javascript
  133. *********************************************************/
  134. // In order to preserve proper nesting on the HTML output put the form
  135. // around the row layout
  136. ob_start();
  137. $errorString = _("You must select a User or Group.");
  138. $agentFieldName = RequestContext::name("agentId");
  139. print<<<END
  140. <script type='text/javascript'>
  141. //<![CDATA[
  142. // Make sure a selection has been made and submit if it has.
  143. function submitAgentChoice() {
  144. var f;
  145. for (i = 0; i < document.forms.length; i++) {
  146. f = document.forms[i];
  147. if (f.id == 'chooseform') {
  148. var form = f;
  149. break;
  150. }
  151. }
  152. var radioArray = form.agentId;
  153. var isChecked = false;
  154. for (i=0; i<radioArray.length; i++) {
  155. if (radioArray[i].checked) {
  156. isChecked = true;
  157. }
  158. }
  159. if (isChecked) {
  160. form.submit();
  161. } else {
  162. alert("$errorString");
  163. }
  164. }
  165. //]]>
  166. </script>
  167. END;
  168. print "<form id='chooseform' method='post' action='".$harmoni->request->quickURL("authorization","edit_authorizations")."'>\n";
  169. $pageRows->setPreHTML(ob_get_contents());
  170. ob_end_clean();
  171. $pageRows->setPostHTML("</form>");
  172.  
  173. /*********************************************************
  174. * the agent search results
  175. *********************************************************/
  176. $search_criteria = $harmoni->request->get("search_criteria");
  177. $search_type = $harmoni->request->get("search_type");
  178. if ($search_criteria && $search_type) {
  179. $typeParts = explode("::", $search_type);
  180. $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
  181. $agents = new MultiIteratorIterator;
  182. $agents->addIterator(
  183. $agentManager->getGroupsBySearch($search_criteria, $searchType));
  184. $agents->addIterator(
  185. $agentManager->getAgentsBySearch($search_criteria, $searchType));
  186. print <<<END
  187. <table>
  188. <tr>
  189. <td valign='top'>
  190. <div style='
  191. border: 1px solid #000;
  192. width: 15px;
  193. height: 15px;
  194. text-align: center;
  195. text-decoration: none;
  196. font-weight: bold;
  197. '>
  198. -
  199. </div>
  200. </td>
  201. <td>
  202. END;
  203. print "\n\t\t\t"._("Search Results");
  204. print <<<END
  205. </td>
  206. </tr>
  207. </table>
  208. <div style='
  209. margin-left: 13px;
  210. margin-right: 0px;
  211. margin-top:0px;
  212. padding-left: 10px;
  213. border-left: 1px solid #000;
  214. '>
  215. END;
  216. while ($agents->hasNext()) {
  217. $agent =$agents->next();
  218. if ($agent->isGroup())
  219. $this->printGroup($agent);
  220. else
  221. $this->printMember($agent);
  222. print "<br />";
  223. }
  224. print "\n</div>";
  225. $pageRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  226. ob_end_clean();
  227. }
  228. /*********************************************************
  229. * Groups
  230. *********************************************************/
  231. // Users header
  232. $pageRows->add(new Heading(_("Groups"), 2), "100%", null, LEFT, CENTER);
  233. // Loop through all of the Groups
  234. $childGroupIds = array();
  235. $groups =$agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
  236.  
  237. while ($groups->hasNext()) {
  238. $group =$groups->next();
  239. $groupId =$group->getId();
  240. // Create a layout for this group using the GroupPrinter
  241. ob_start();
  242. GroupPrinter::printGroup($group, $harmoni,
  243. 2,
  244. "choose_agentAction::printGroup",
  245. "choose_agentAction::printMember");
  246. $groupLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
  247. ob_end_clean();
  248. $pageRows->add($groupLayout, "100%", null, LEFT, CENTER);
  249. }
  250. $pageRows->add($submit, "100%", null, LEFT, CENTER);
  251. $actionRows->add($pageRows);
  252. $harmoni->request->endNamespace();
  253. textdomain($defaultTextDomain);
  254. }
  255.  
  256.  
  257. /*******************************************************
  258. * Callback functions for printing
  259. *********************************************************/
  260.  
  261. // Functions used for the GroupPrinter
  262. /**
  263. * Callback function for printing a group
  264. *
  265. * @param object Group $group
  266. * @return void
  267. * @access public
  268. * @ignore
  269. */
  270. function printGroup($group) {
  271. $id =$group->getId();
  272. $groupType =$group->getType();
  273. print "<input type='radio' id='agentId' name='".RequestContext::name("agentId")."' value='".$id->getIdString()."' />";
  274. print "<a title='".$id->getIdString()."'>";
  275. print "<span style='text-decoration: underline; font-weight: bold;'>".$group->getDisplayName()."</span></a>";
  276. print " - <em>".$groupType->getDescription()."</em>";
  277. }
  278. /**
  279. * Callback function for printing an agent
  280. *
  281. * @param object Agent $member
  282. * @return void
  283. * @access public
  284. * @ignore
  285. */
  286. function printMember($member) {
  287. $harmoni = Harmoni::instance();
  288. $harmoni->request->forget("expandedGroups");
  289. $harmoni->request->forget("search_criteria");
  290. $harmoni->request->forget("search_type");
  291. $harmoni->request->forget("agentId");
  292. $oldNS = $harmoni->request->endNamespace();
  293. $harmoni->request->startNamespace("polyphony-agents");
  294. $agentId =$member->getId();
  295. $agentIdString= $agentId->getIdString();
  296. $harmoni->history->markReturnURL("polyphony/agents/edit_agent_details");
  297. $link = $harmoni->request->quickURL("agents","edit_agent_details",array("agentId"=>$agentIdString));
  298. $harmoni->request->endNamespace();
  299. $harmoni->request->startNamespace($oldNS);
  300. $id =$member->getId();
  301. $memberType =$member->getType();
  302. print "<input type='radio' id='agentId' name='".RequestContext::name("agentId")."' value='".$id->getIdString()."' />";
  303. print "<a title='".$id->getIdString()."' href='$link'>";
  304. print "<span style='text-decoration: underline;'>".$member->getDisplayName()."</span></a>";
  305. print " - <em>".$memberType->getDescription()."</em>";
  306. // $harmoni->request->endNamespace();
  307. $harmoni->request->passthrough();
  308. // $harmoni->request->startNamespace($oldNS);
  309. }
  310.  
  311. }
  312.  
  313. ?>

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