invite.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * Elgg groups plugin
  4. *
  5. * @package ElggGroups
  6. */
  7. $comment = elgg_get_sticky_value('group_invite', 'comment');
  8. elgg_clear_sticky_form('group_invite');
  9. $group = elgg_extract("entity", $vars, elgg_get_page_owner_entity());
  10. $invite_site_members = elgg_extract("invite", $vars, "no");
  11. $invite_email = elgg_extract("invite_email", $vars, "no");;
  12. $invite_csv = elgg_extract("invite_csv", $vars, "no");;
  13. $owner = $group->getOwnerEntity();
  14. $forward_url = $group->getURL();
  15. $tabs = false;
  16. $friends = elgg_get_logged_in_user_entity()->getFriends(array("limit" => false));
  17. if (!empty($friends)) {
  18. $toggle_content = "<span>" . elgg_echo("group_tools:group:invite:friends:select_all") . "</span>";
  19. $toggle_content .= "<span class='hidden'>" . elgg_echo("group_tools:group:invite:friends:deselect_all") . "</span>";
  20. $friendspicker = elgg_view("output/url", array("text" => $toggle_content, "href" => "javascript:void(0);", "onclick" => "group_tools_toggle_all_friends();", "id" => "friends_toggle", "class" => "float-alt elgg-button elgg-button-action"));
  21. $friendspicker .= elgg_view('input/friendspicker', array('entities' => $friends, 'name' => 'user_guid', 'highlight' => 'all'));
  22. } else {
  23. $friendspicker = elgg_echo('groups:nofriendsatall');
  24. }
  25. // which options to show
  26. if (in_array("yes", array($invite_site_members, $invite_email, $invite_csv))) {
  27. $tabs = array(
  28. "friends" => array(
  29. "text" => elgg_echo("friends"),
  30. "href" => "#",
  31. "rel" => "friends",
  32. "priority" => 200,
  33. "onclick" => "group_tools_group_invite_switch_tab(\"friends\");",
  34. "selected" => true
  35. )
  36. );
  37. // invite friends
  38. $form_data = "<div id='group_tools_group_invite_friends'>";
  39. $form_data .= $friendspicker;
  40. $form_data .= "</div>";
  41. //invite all site members
  42. if ($invite_site_members == "yes") {
  43. $tabs["users"] = array(
  44. "text" => elgg_echo("group_tools:group:invite:users"),
  45. "href" => "#",
  46. "rel" => "users",
  47. "priority" => 300,
  48. "onclick" => "group_tools_group_invite_switch_tab(\"users\");"
  49. );
  50. $form_data .= "<div id='group_tools_group_invite_users' class='hidden mbm'>";
  51. $form_data .= "<div>" . elgg_echo("group_tools:group:invite:users:description") . "</div>";
  52. $form_data .= elgg_view("input/group_invite_autocomplete", array("name" => "user_guid",
  53. "id" => "group_tools_group_invite_autocomplete",
  54. "group_guid" => $group->getGUID(),
  55. "relationship" => "site"));
  56. if (elgg_is_admin_logged_in()) {
  57. $form_data .= elgg_view("input/checkbox", array("name" => "all_users", "value" => "yes"));
  58. $form_data .= elgg_echo("group_tools:group:invite:users:all");
  59. }
  60. $form_data .= "</div>";
  61. }
  62. // invite by email
  63. if ($invite_email == "yes") {
  64. $tabs["email"] = array(
  65. "text" => elgg_echo("group_tools:group:invite:email"),
  66. "href" => "#",
  67. "rel" => "users",
  68. "priority" => 400,
  69. "onclick" => "group_tools_group_invite_switch_tab(\"email\");"
  70. );
  71. $form_data .= "<div id='group_tools_group_invite_email' class='hidden mbm'>";
  72. $form_data .= "<div>" . elgg_echo("group_tools:group:invite:email:description") . "</div>";
  73. $form_data .= elgg_view("input/group_invite_autocomplete", array("name" => "user_guid",
  74. "id" => "group_tools_group_invite_autocomplete_email",
  75. "group_guid" => $group->getGUID(),
  76. "relationship" => "email"));
  77. $form_data .= "</div>";
  78. }
  79. //invite by cvs upload
  80. if ($invite_csv == "yes") {
  81. $tabs["csv"] = array(
  82. "text" => elgg_echo("group_tools:group:invite:csv"),
  83. "href" => "#",
  84. "rel" => "users",
  85. "priority" => 500,
  86. "onclick" => "group_tools_group_invite_switch_tab(\"csv\");"
  87. );
  88. $form_data .= "<div id='group_tools_group_invite_csv' class='hidden mbm'>";
  89. $form_data .= "<div>" . elgg_echo("group_tools:group:invite:csv:description") . "</div>";
  90. $form_data .= elgg_view("input/file", array("name" => "csv"));
  91. $form_data .= "</div>";
  92. }
  93. } else {
  94. // only friends
  95. $form_data = $friendspicker;
  96. }
  97. // optional text
  98. $form_data .= elgg_view_module("aside", elgg_echo("group_tools:group:invite:text"), elgg_view("input/longtext", array("name" => "comment", 'value' => $comment)));
  99. // renotify existing invites
  100. if ($group->canEdit()) {
  101. $form_data .= "<div>";
  102. $form_data .= "<input type='checkbox' name='resend' value='yes' />";
  103. $form_data .= "&nbsp;" . elgg_echo("group_tools:group:invite:resend");
  104. $form_data .= "</div>";
  105. }
  106. // build tabs
  107. if (!empty($tabs)) {
  108. foreach ($tabs as $name => $tab) {
  109. $tab["name"] = $name;
  110. elgg_register_menu_item("filter", $tab);
  111. }
  112. echo elgg_view_menu("filter", array("sort_by" => "priority"));
  113. }
  114. // show form
  115. echo $form_data;
  116. // show buttons
  117. echo '<div class="elgg-foot">';
  118. echo elgg_view('input/hidden', array('name' => 'forward_url', 'value' => $forward_url));
  119. echo elgg_view('input/hidden', array('name' => 'group_guid', 'value' => $group->guid));
  120. echo elgg_view('input/submit', array('name' => 'submit', 'value' => elgg_echo('invite')));
  121. if (elgg_is_admin_logged_in()) {
  122. echo elgg_view("input/submit", array('name' => 'submit', "value" => elgg_echo("group_tools:add_users"), "onclick" => "return confirm(\"" . elgg_echo("group_tools:group:invite:add:confirm") . "\");"));
  123. }
  124. echo '</div>';
  125. ?>
  126. <script type="text/javascript">
  127. function group_tools_group_invite_switch_tab(tab) {
  128. $('#invite_to_group li').removeClass('elgg-state-selected');
  129. $('#invite_to_group li.elgg-menu-item-' + tab).addClass('elgg-state-selected');
  130. switch (tab) {
  131. case "users":
  132. $('#group_tools_group_invite_friends').hide();
  133. $('#group_tools_group_invite_email').hide();
  134. $('#group_tools_group_invite_csv').hide();
  135. $('#group_tools_group_invite_users').show();
  136. break;
  137. case "email":
  138. $('#group_tools_group_invite_friends').hide();
  139. $('#group_tools_group_invite_users').hide();
  140. $('#group_tools_group_invite_csv').hide();
  141. $('#group_tools_group_invite_email').show();
  142. break;
  143. case "csv":
  144. $('#group_tools_group_invite_friends').hide();
  145. $('#group_tools_group_invite_users').hide();
  146. $('#group_tools_group_invite_email').hide();
  147. $('#group_tools_group_invite_csv').show();
  148. break;
  149. default:
  150. $('#group_tools_group_invite_users').hide();
  151. $('#group_tools_group_invite_email').hide();
  152. $('#group_tools_group_invite_csv').hide();
  153. $('#group_tools_group_invite_friends').show();
  154. break;
  155. }
  156. }
  157. function group_tools_toggle_all_friends() {
  158. if ($('#friends_toggle span:first').is(':visible')) {
  159. $('#friends-picker1 input[type="checkbox"]').attr("checked", "checked");
  160. } else {
  161. $('#friends-picker1 input[type="checkbox"]').removeAttr("checked");
  162. }
  163. $('#friends_toggle span').toggle();
  164. }
  165. </script>