Skip to content

Commit

Permalink
changed: group mail form to support member selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Sep 28, 2011
1 parent 6bfcfbe commit c64e611
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 10 deletions.
10 changes: 6 additions & 4 deletions actions/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
gatekeeper();

$group_guid = (int) get_input("group_guid", 0);
$user_guids = get_input("user_guids");
$subject = get_input("title");
$body = get_input("description");

$forward_url = REFERER;
$user_guids = group_tools_verify_group_members($group_guid, $user_guids);

if(!empty($group_guid) && !empty($body)){
if(!empty($group_guid) && !empty($body) && !empty($user_guids)){

if(($group = get_entity($group_guid)) && ($group instanceof ElggGroup)){
if($group->canEdit()){
set_time_limit(0);
Expand All @@ -19,8 +21,8 @@
" . elgg_echo("group_tools:mail:message:from") . ": <a href='" . $group->getURL() . "'>" . $group->name . "</a>";

foreach($group->getMembers(false) as $member){
notify_user($member->getGUID(), $group->getGUID(), $subject, $body, NULL, "email");
foreach($user_guids as $guid){
notify_user($guid, $group->getGUID(), $subject, $body, NULL, "email");
}

system_message(elgg_echo("group_tools:action:mail:success"));
Expand Down
9 changes: 8 additions & 1 deletion languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
'group_tools:add_users' => "Add users",
'group_tools:in' => "in",
'group_tools:remove' => "Remove",
'group_tools:clear_selection' => "Clear selection",
'group_tools:all_members' => "All members",

// menu
'group_tools:menu:mail' => "Mail Members",
Expand Down Expand Up @@ -99,11 +101,16 @@
// group mail
'group_tools:mail:message:from' => "From group",

'group_tools:mail:title' => "Send a mail to all group members",
'group_tools:mail:title' => "Send a mail to the group members",
'group_tools:mail:form:recipients' => "Number of recipients",
'group_tools:mail:form:members:selection' => "Select individual members",

'group_tools:mail:form:title' => "Subject",
'group_tools:mail:form:description' => "Body",

'group_tools:mail:form:js:members' => "Please select at least one member to send the message to",
'group_tools:mail:form:js:description' => "Please enter a message",

// group invite
'group_tools:groups:invite' => "Invite users",

Expand Down
8 changes: 7 additions & 1 deletion languages/nl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php
$language = array (
'group_tools:clear_selection' => 'Selectie wissen',
'group_tools:all_members' => 'Alle leden',
'group_tools:mail:form:recipients' => 'Aantal geselecteerde ontvangers',
'group_tools:mail:form:members:selection' => 'Selecteer individuele leden',
'group_tools:mail:form:js:members' => 'Selecteer minstens één lid om het bericht aan te versturen',
'group_tools:mail:form:js:description' => 'Geef een bericht op',
'group_tools:remove' => 'Verwijder',
'group_tools:settings:auto_join' => 'Automatisch groepslidmaatschap',
'group_tools:settings:auto_join:description' => 'Nieuwe gebruikers worden automatisch lid van de volgende groepen',
Expand Down Expand Up @@ -84,7 +90,7 @@
'group_tools:multiple_admin:group_tool_option' => 'Mogen groep beheerders andere groep beheerder aanmaken',
'group_tools:group_kick:profile_actions:kick' => 'Verwijder uit de groep',
'group_tools:mail:message:from' => 'Van groep',
'group_tools:mail:title' => 'Stuur een e-mail naar alle groep leden',
'group_tools:mail:title' => 'Stuur een e-mail naar de groepsleden',
'group_tools:mail:form:title' => 'Onderwerp',
'group_tools:mail:form:description' => 'Bericht',
'group_tools:groups:invite' => 'Nodig gebruikers uit',
Expand Down
37 changes: 36 additions & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,39 @@ function group_tools_invite_email(ElggGroup $group, $email, $text = ""){
return $result;
}

?>
function group_tools_verify_group_members($group_guid, $user_guids){
$result = false;

if(!empty($group_guid) && !empty($user_guids)){
if(!is_array($user_guids)){
$user_guids = array($user_guids);
}

if(($group = get_entity($group_guid)) && ($group instanceof ElggGroup)){
$options = array(
"type" => "user",
"limit" => false,
"relationship" => "member",
"relationship_guid" => $group->getGUID(),
"inverse_relationship" => true,
"callback" => "group_tools_guid_only_callback"
);

if($member_guids = elgg_get_entities_from_relationship($options)){
$result = array();

foreach($user_guids as $user_guid){
if(in_array($user_guid, $member_guids)){
$result[] = $user_guid;
}
}
}
}
}

return $result;
}

function group_tools_guid_only_callback($row){
return $row->guid;
}
3 changes: 3 additions & 0 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ToDo
====================
Version History
====================
x.x:
- changed: group mail form to support member selection
1.5 (2011-09-23):
- added: admin option to manage if closed groups are indexed by search engines (default no)
- added: admin option to automaticly enable group notifications on group join
Expand Down
6 changes: 5 additions & 1 deletion pages/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
set_page_owner($group->getGUID());
set_context("groups");

// get members
$members = $group->getMembers(false);

// build page elements
$title_text = elgg_echo("group_tools:mail:title");
$title = elgg_view_title($title_text);

$form = elgg_view("group_tools/forms/mail", array("entity" => $group));
$form = elgg_view("group_tools/forms/mail", array("entity" => $group, "members" => $members));

$page_data = $title . $form;

Expand Down
8 changes: 8 additions & 0 deletions views/default/group_tools/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@
#group_tools_group_invite_autocomplete_autocomplete_results,
#group_tools_group_invite_autocomplete_email_autocomplete_results {
margin-top: 10px;
}

#group_tools_mail_member_options input[type=button] {
margin-right: 5px;
}

#group_tools_mail_member_selection {
display: none;
}
79 changes: 77 additions & 2 deletions views/default/group_tools/forms/mail.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
<?php

$group = $vars["entity"];
$members = $vars["members"];

$friendpicker_value = array();
if(!empty($members)){
foreach($members as $member){
$friendpicker_value[] = $member->getGUID();
}
}

$form_data = elgg_view("input/hidden", array("internalname" => "group_guid", "value" => $group->getGUID()));

$form_data .= "<label>" . elgg_echo("group_tools:mail:form:recipients") . ": <span id='group_tools_mail_recipients_count'>" . count($friendpicker_value) . "</span></label>";
$form_data .= "<br />";
$form_data .= "<a href='javascript:void(0);' onclick='$(\"#group_tools_mail_member_selection\").toggle();'>" . elgg_echo("group_tools:mail:form:members:selection") . "</a>";

$form_data .= "<div id='group_tools_mail_member_selection'>";
$form_data .= elgg_view("friends/picker", array("entities" => $members, "value" => $friendpicker_value, "highlight" => "all", "internalname" => "user_guids"));
$form_data .= "</div>";

$form_data .= "<div id='group_tools_mail_member_options'>";
$form_data .= elgg_view("input/button", array("type" => "button", "value" => elgg_echo("group_tools:clear_selection"), "js" => "onclick='group_tools_mail_clear_members();'"));
$form_data .= elgg_view("input/button", array("type" => "button", "value" => elgg_echo("group_tools:all_members"), "js" => "onclick='group_tools_mail_all_members();'"));
$form_data .= "<br />";
$form_data .= "</div>";


$form_data .= "<label>" . elgg_echo("group_tools:mail:form:title") . "</label>";
$form_data .= elgg_view("input/text", array("internalname" => "title"));

Expand All @@ -15,8 +38,60 @@
$form_data .= "</div>";

$form = elgg_view("input/form", array("body" => $form_data,
"action" => $vars["url"] . "action/group_tools/mail"));
"action" => $vars["url"] . "action/group_tools/mail",
"internalid" => "group_tools_mail_form"));

echo elgg_view("page_elements/contentwrapper", array("body" => $form));

?>
?>
<script type="text/javascript">
$(document).ready(function(){
$('#group_tools_mail_form').submit(function(){
var result = false;
var error_msg = "";
var error_count = 0;

if($('#group_tools_mail_member_selection input[name="user_guids[]"]:checked').length == 0){
error_msg += "<?php echo elgg_echo("group_tools:mail:form:js:members"); ?>\n";
error_count++;
}

if($(this).find('input[name="description"]').val() == ""){
error_msg += "<?php echo elgg_echo("group_tools:mail:form:js:description"); ?>\n";
error_count++;
}

if(error_count > 0){
alert(error_msg);
} else {
result = true;
}

return result;
});

$('#group_tools_mail_member_selection input[type=checkbox]').live("change", group_tools_mail_update_recipients);
});

function group_tools_mail_clear_members(){
$('#group_tools_mail_member_selection input[name="user_guids[]"]:checked').each(function(){
$(this).removeAttr('checked');
});

group_tools_mail_update_recipients();
}

function group_tools_mail_all_members(){
$('#group_tools_mail_member_selection input[name="user_guids[]"]').each(function(){
$(this).attr('checked', 'checked');
});

group_tools_mail_update_recipients();
}

function group_tools_mail_update_recipients(){
var count = $('#group_tools_mail_member_selection input[name="user_guids[]"]:checked').length;

$('#group_tools_mail_recipients_count').html(count);
}
</script>

0 comments on commit c64e611

Please sign in to comment.