Source for file group_membership.act.php

Documentation is available at group_membership.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: group_membership.act.php,v 1.38 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.  
  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: group_membership.act.php,v 1.38 2007/09/19 14:04:52 adamfranco Exp $
  26. */
  27. class group_membershipAction
  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. if ($authZManager->isUserAuthorized(
  42. $idManager->getId("edu.middlebury.authorization.modify"),
  43. $idManager->getId("edu.middlebury.agents.all_groups")))
  44. {
  45. return TRUE;
  46. } else
  47. return FALSE;
  48. }
  49. /**
  50. * Return the heading text for this action, or an empty string.
  51. *
  52. * @return string
  53. * @access public
  54. * @since 4/26/05
  55. */
  56. function getHeadingText () {
  57. return dgettext("polyphony", "Manage Group Membership");
  58. }
  59. /**
  60. * Build the content for this action
  61. *
  62. * @return void
  63. * @access public
  64. * @since 4/26/05
  65. */
  66. function buildContent () {
  67. $defaultTextDomain = textdomain("polyphony");
  68. $actionRows =$this->getActionRows();
  69. $pageRows = new Container(new YLayout(), OTHER, 1);
  70. $harmoni = Harmoni::instance();
  71. $harmoni->request->startNamespace("polyphony-agents");
  72. $harmoni->request->passthrough();
  73.  
  74. // register this action as the return-point for the following operations:
  75. $harmoni->history->markReturnURL("polyphony/agents/add_to_group");
  76. $harmoni->history->markReturnURL("polyphony/agents/remove_from_group");
  77.  
  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. $allGroupsId =$idManager->getId("edu.middlebury.agents.all_groups");
  83. /*********************************************************
  84. * the agent search form
  85. *********************************************************/
  86. // Users header
  87. $actionRows->add(new Heading(_("Users"), 2), "100%", null, LEFT, CENTER);
  88. ob_start();
  89. $self = $harmoni->request->quickURL();
  90. $lastCriteria = $harmoni->request->get("search_criteria");
  91. $search_criteria_name = RequestContext::name("search_criteria");
  92. $search_type_name = RequestContext::name("search_type");
  93. print _("Search For Users").": ";
  94. print <<<END
  95. <form action='$self' method='post'>
  96. <div>
  97. <input type='text' name='$search_criteria_name' value='$lastCriteria' />
  98. <br /><select name='$search_type_name'>
  99. END;
  100. $searchTypes =$agentManager->getAgentSearchTypes();
  101. while ($searchTypes->hasNext()) {
  102. $type =$searchTypes->next();
  103. $typeString = htmlspecialchars($type->getDomain()
  104. ."::".$type->getAuthority()
  105. ."::".$type->getKeyword());
  106. print "\n\t\t<option value='$typeString'";
  107. if ($harmoni->request->get("search_type") == $typeString)
  108. print " selected='selected'";
  109. print ">$typeString</option>";
  110. }
  111. print "\n\t</select>";
  112. print "\n\t<br /><input type='submit' value='"._("Search")."' />";
  113. print "\n\t<a href='".$harmoni->request->quickURL()."'>";
  114. print "<input type='button' value='"._("Clear")."' /></a>";
  115. print "\n</div>\n</form>";
  116. $actionRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  117. ob_end_clean();
  118. /*********************************************************
  119. * the agent search results
  120. *********************************************************/
  121. ob_start();
  122. if (($search_criteria = $harmoni->request->get('search_criteria')) && ($search_type = $harmoni->request->get('search_type'))) {
  123. $typeParts = explode("::", @html_entity_decode($search_type, ENT_COMPAT, 'UTF-8'));
  124. $searchType = new HarmoniType($typeParts[0], $typeParts[1], $typeParts[2]);
  125. $agents =$agentManager->getAgentsBySearch($search_criteria, $searchType);
  126. print "search: " . $search_criteria;
  127. print <<<END
  128. <table>
  129. <tr>
  130. <td valign='top'>
  131. <div style='
  132. border: 1px solid #000;
  133. width: 15px;
  134. height: 15px;
  135. text-align: center;
  136. text-decoration: none;
  137. font-weight: bold;
  138. '>
  139. -
  140. </div>
  141. </td>
  142. <td>
  143. END;
  144. print "\n\t\t\t"._("Search Results");
  145. print <<<END
  146. </td>
  147. </tr>
  148. </table>
  149. <div style='
  150. margin-left: 13px;
  151. margin-right: 0px;
  152. margin-top:0px;
  153. padding-left: 10px;
  154. border-left: 1px solid #000;
  155. '>
  156. END;
  157. while ($agents->hasNext()) {
  158. $agent =$agents->next();
  159. group_membershipAction::printMember($agent);
  160. print "<br />";
  161. }
  162. print "\n</div>";
  163. $pageRows->add(new Block(ob_get_contents(), STANDARD_BLOCK), "100%", null, LEFT, CENTER);
  164. ob_end_clean();
  165. }
  166. /*********************************************************
  167. * Groups
  168. *********************************************************/
  169. $pageRows->add(new Heading(_("Groups"), 2), "100%", null, LEFT, CENTER);
  170.  
  171. // Define some global variables to store javascript array definitions
  172. // for validating adding/removing inputs.
  173. $GLOBALS['child_groups_string'] = "";
  174. $GLOBALS['child_agents_string'] = "";
  175. // Loop through all of the Root Groups
  176. $groups =$agentManager->getGroupsBySearch($null = null, new Type("Agent & Group Search", "edu.middlebury.harmoni", "RootGroups"));
  177. while ($groups->hasNext()) {
  178. $group =$groups->next();
  179. $groupId =$group->getId();
  180. // Create a layout for this group using the GroupPrinter
  181. ob_start();
  182. GroupPrinter::printGroup($group, $harmoni,
  183. 2,
  184. "group_membershipAction::printGroup",
  185. "group_membershipAction::printMember");
  186. $groupLayout = new Block(ob_get_contents(), STANDARD_BLOCK);
  187. ob_end_clean();
  188. $pageRows->add($groupLayout, "100%", null, LEFT, CENTER);
  189. }
  190. /*********************************************************
  191. * Javascript for validating checkboxes,
  192. * Form Definition.
  193. *********************************************************/
  194. ob_start();
  195. // Create translated errorstrings
  196. $cannotAddGroup = _("Cannot add group");
  197. $toItsself = _("to itself");
  198. $deselecting = _("Deselecting");
  199. $toOwnDesc = _("to its own descendent");
  200. $groupString = _("Group");
  201. $isAlreadyInGroup = _("is alread in this group");
  202. $agentString = _("Agent");
  203. $fromItsself = _("from itself");
  204. $cannotRemoveGroup = _("Cannot remove group");
  205. $notInGroup = _("is not in this group");
  206. $confirmAdd = _("Are you sure that you wish to add the selected Groups and Agents to Group");
  207. $confirmRemove = _("Are you sure that you wish to remove the selected Groups and Agents from Group");
  208. $destinationgroup_name = RequestContext::name("destinationgroup");
  209. $operation_name = RequestContext::name("operation");
  210. $actionURL = $harmoni->request->quickURL("agents","add_to_group");
  211. // Print out a Javascript function for submitting our groups choices
  212. $decendentGroups = $GLOBALS['decendent_groups_string'];
  213. $childGroups = $GLOBALS['child_groups_string'];
  214. $childAgents = $GLOBALS['child_agents_string'];
  215. print <<<END
  216. <script type='text/javascript'>
  217. //<![CDATA[
  218. // Validate ancestory and submit to add checked to the group
  219. function submitCheckedToGroup ( destGroupId ) {
  220. var f;
  221. var form;
  222. for (i = 0; i < document.forms.length; i++) {
  223. f = document.forms[i];
  224. if (f.id == 'memberform') {
  225. form = f;
  226. break;
  227. }
  228. }
  229. var elements = form.elements;
  230. var i;
  231. var numToAdd = 0;
  232. for (i = 0; i < elements.length; i++) {
  233. var element = elements[i];
  234. if (element.type == 'checkbox' && element.checked == true) {
  235. if (element.value == 'group') {
  236. // Check that the destination is not the new member
  237. if ( element.id == destGroupId ) {
  238. alert ("$cannotAddGroup " + element.id + " $toItsself. $deselecting...");
  239. element.checked = false;
  240. continue;
  241. }
  242. // Check that the destination is not a decendent of the new member
  243. if ( in_array(destGroupId, decendentGroups[element.id]) ) {
  244. alert ("$cannotAddGroup " + element.id + " $toOwnDesc. $deselecting...");
  245. element.checked = false;
  246. continue;
  247. }
  248. // Check that the new member is not already a child of the destination
  249. if ( in_array(element.id, childGroups[destGroupId]) ) {
  250. alert ("$groupString " + element.id + " $isAlreadyInGroup. $deselecting...");
  251. element.checked = false;
  252. continue;
  253. }
  254. } else {
  255. // Check that the new member is not already a child of the destination
  256. if ( in_array(element.id, childAgents[destGroupId]) ) {
  257. alert ("$agentString " + element.id + " $isAlreadyInGroup. $deselecting...");
  258. element.checked = false;
  259. continue;
  260. }
  261. }
  262. // If we haven't skipped back to the top of the loop yet, increment our ticker.
  263. numToAdd++;
  264. }
  265. }
  266. if (numToAdd && confirm("$confirmAdd " + destGroupId + "?")) {
  267. form.destinationgroup.value = destGroupId;
  268. form.submit();
  269. }
  270. }
  271. // Validate that the check are children and submit to remove them from the group
  272. function submitCheckedFromGroup ( destGroupId ) {
  273. var f;
  274. var form;
  275. for (i = 0; i < document.forms.length; i++) {
  276. f = document.forms[i];
  277. if (f.id == 'memberform') {
  278. form = f;
  279. break;
  280. }
  281. }
  282. var elements = form.elements;
  283. var i;
  284. var numToAdd = 0;
  285. for (i = 0; i < elements.length; i++) {
  286. var element = elements[i];
  287. if (element.type == 'checkbox' && element.checked == true) {
  288. // Check that the destination is not the new member
  289. if ( element.id == destGroupId ) {
  290. alert ("$cannotRemoveGroup " + element.id + " $fromItsself. $deselecting...");
  291. element.checked = false;
  292. continue;
  293. }
  294. if (element.value == 'group') {
  295. // Check that the new member is not already a child of the destination
  296. if ( !in_array(element.id, childGroups[destGroupId]) ) {
  297. alert ("$groupString " + element.id + " $notInGroup. $deselecting...");
  298. element.checked = false;
  299. continue;
  300. }
  301. } else {
  302. // Check that the new member is not already a child of the destination
  303. if ( !in_array(element.id, childAgents[destGroupId]) ) {
  304. alert ("$agentString " + element.id + " $notInGroup. $deselecting...");
  305. element.checked = false;
  306. continue;
  307. }
  308. }
  309. // If we haven't skipped back to the top of the loop yet, increment our ticker.
  310. numToAdd++;
  311. }
  312. }
  313. if (numToAdd && confirm("$confirmRemove " + destGroupId + "?")) {
  314. form.destinationgroup.value = destGroupId;
  315. form.action = form.action.replace('add_to_group','remove_from_group');
  316. form.submit();
  317. }
  318. }
  319. function in_array( aValue, anArray) {
  320. for (i = 0; i < anArray.length; i++) {
  321. if (anArray[i] == aValue)
  322. return true;
  323. }
  324. return false;
  325. }
  326. // Decendent Groups
  327. var decendentGroups = new Array ();
  328. $decendentGroups
  329. // Child Groups
  330. var childGroups = new Array ();
  331. $childGroups
  332. // Child Agents
  333. var childAgents = new Array ();
  334. $childAgents
  335. //]]>
  336. </script>
  337. <form id='memberform' method='post' action='$actionURL'>
  338. <input type='hidden' id='destinationgroup' name='$destinationgroup_name' value=''/>
  339. END;
  340. $pageRows->setPreHTML(ob_get_contents());
  341. ob_end_clean();
  342. $pageRows->setPostHTML("</form>");
  343. // In order to preserve proper nesting on the HTML output, the checkboxes
  344. // are all in the pagerows layout instead of actionrows.
  345. $actionRows->add($pageRows, null, null,CENTER, CENTER);
  346. textdomain($defaultTextDomain);
  347. }
  348. /*******************************************************
  349. * Functions used for the GroupPrinter
  350. *********************************************************/
  351.  
  352. /**
  353. * Callback function for printing a group
  354. *
  355. * @param object Group $group
  356. * @return void
  357. * @access public
  358. * @ignore
  359. */
  360. function printGroup($group) {
  361. $idManager = Services::getService("Id");
  362. $everyoneId =$idManager->getId("edu.middlebury.agents.everyone");
  363. $usersId =$idManager->getId("edu.middlebury.agents.users");
  364. $allGroupsId =$idManager->getId("edu.middlebury.agents.all_groups");
  365. $id =$group->getId();
  366. $groupType =$group->getType();
  367. if ($id->isEqual($everyoneId) || $id->isEqual($usersId))
  368. print "\n&nbsp; &nbsp; &nbsp;";
  369. else
  370. print "\n<input type='checkbox' id='".$id->getIdString()."' name='".RequestContext::name($id->getIdString())."' value='group' />";
  371. print "\n<a title='".htmlspecialchars($groupType->getAuthority()." :: ".$groupType->getDomain()." :: ".$groupType->getKeyword()." - ".$groupType->getDescription())."'>";
  372. print "\n<span style='text-decoration: underline; font-weight: bold;'>".$id->getIdString()." - ".htmlspecialchars($group->getDisplayName())."</span></a>";
  373. if (!$id->isEqual($everyoneId) && !$id->isEqual($usersId)) {
  374. print "\n <input type='button' value='"._("Add checked")."'";
  375. print " onclick='Javascript:submitCheckedToGroup(\"".$id->getIdString()."\")'";
  376. print " />";
  377. print "\n <input type='button' value='"._("Remove checked")."'";
  378. print " onclick='Javascript:submitCheckedFromGroup(\"".$id->getIdString()."\")'";
  379. print " />";
  380. }
  381. print "\n - <em>".htmlspecialchars($group->getDescription())."</em>";
  382. // print out the properties of the Agent
  383. print "\n<em>";
  384. $propertiesIterator =$group->getProperties();
  385. while($propertiesIterator->hasNext()) {
  386. $properties =$propertiesIterator->next();
  387. $propertiesType =$properties->getType();
  388. print "\n\t(<a title='".htmlspecialchars($propertiesType->getDomain()." :: ".$propertiesType->getAuthority()." :: ".$propertiesType->getKeyword()." - ".$propertiesType->getDescription())."'>";
  389. $keys =$properties->getKeys();
  390. $i = 0;
  391. while ($keys->hasNext()) {
  392. $key =$keys->next();
  393. print htmlspecialchars("\n\t\t".(($i)?", ":"").$key.": ".$properties->getProperty($key));
  394. $i++;
  395. }
  396. print "\n\t</a>)";
  397. }
  398. print "\n</em>";
  399. //-------------------------------------------------
  400. // put the decendent-groups into a javascript array element
  401. ob_start();
  402. $idString = $id->getIdString();
  403. print <<<END
  404. decendentGroups['$idString'] = new Array (
  405.  
  406. END;
  407. $groups =$group->getGroups(false);
  408. $i = 0;
  409. while($groups->hasNext()) {
  410. $child =$groups->next();
  411. $childId =$child->getId();
  412. print (($i)?",\n\t\t\t\t":"\t\t\t\t")."'".$childId->getIdString()."'";
  413. $i++;
  414. }
  415. print "\n\t\t\t\t);";
  416. $GLOBALS['decendent_groups_string'] .= ob_get_contents();
  417. ob_end_clean();
  418. //-------------------------------------------------
  419. // put the decendent-groups into a javascript array element
  420. ob_start();
  421. $idString = $id->getIdString();
  422. print <<<END
  423. childGroups['$idString'] = new Array (
  424.  
  425. END;
  426. $groups =$group->getGroups(FALSE);
  427. $i = 0;
  428. while($groups->hasNext()) {
  429. $child =$groups->next();
  430. $childId =$child->getId();
  431. print (($i)?",\n\t\t\t\t":"\t\t\t\t")."'".$childId->getIdString()."'";
  432. $i++;
  433. }
  434. print "\n\t\t\t\t);";
  435. $GLOBALS['child_groups_string'] .= ob_get_contents();
  436. ob_end_clean();
  437. //-------------------------------------------------
  438. // put the decendent-groups into a javascript array element
  439. ob_start();
  440. $idString = $id->getIdString();
  441. print <<<END
  442. childAgents['$idString'] = new Array (
  443.  
  444. END;
  445. $agents =$group->getMembers(FALSE);
  446. $i = 0;
  447. while($agents->hasNext()) {
  448. $child =$agents->next();
  449. $childId =$child->getId();
  450. print (($i)?",\n\t\t\t\t":"\t\t\t\t")."'".$childId->getIdString()."'";
  451. $i++;
  452. }
  453. print "\n\t\t\t\t);";
  454. $GLOBALS['child_agents_string'] .= ob_get_contents();
  455. ob_end_clean();
  456. }
  457. /**
  458. * Callback function for printing an agent
  459. *
  460. * @param object Agent $member
  461. * @return void
  462. * @access public
  463. * @ignore
  464. */
  465. function printMember($member) {
  466. $harmoni = Harmoni::instance();
  467. $id =$member->getId();
  468. $memberType =$member->getType();
  469. print "\n<input type='checkbox' id='".$id->getIdString()."' name='".RequestContext::name($id->getIdString())."' value='agent' />";
  470. $harmoni->history->markReturnURL("polyphony/agents/edit_agent_details");
  471. print "\n<a href='".$harmoni->request->quickURL("agents","edit_agent_details", array("agentId"=>$id->getIdString()))."' title='".htmlspecialchars($memberType->getDomain()." :: ".$memberType->getAuthority()." :: ".$memberType->getKeyword()." - ".$memberType->getDescription())."'>";
  472. print "\n<span style='text-decoration: none;'>".$id->getIdString()." - ".htmlspecialchars($member->getDisplayName())."</span></a>";
  473. // print out the properties of the Agent
  474. print "\n<em>";
  475. $propertiesIterator = NULL;
  476. $propertiesIterator =$member->getProperties();
  477. while($propertiesIterator->hasNext()) {
  478. $properties = NULL;
  479. $properties =$propertiesIterator->next();
  480. $propertiesType =$properties->getType();
  481. print "\n\t(<a title='".htmlspecialchars($propertiesType->getDomain()." :: ".$propertiesType->getAuthority()." :: ".$propertiesType->getKeyword()." - ".$propertiesType->getDescription())."'>";
  482. $keys =$properties->getKeys();
  483. $i = 0;
  484. while ($keys->hasNext()) {
  485. $key =$keys->next();
  486. print htmlspecialchars("\n\t\t".(($i)?", ":"").$key.": ".$properties->getProperty($key));
  487. $i++;
  488. }
  489. print "\n\t</a>)";
  490. }
  491. print "\n</em>";
  492. }
  493. }

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