aboutsummaryrefslogtreecommitdiff
path: root/mod/groups/actions
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-04 01:26:36 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-03-04 01:26:36 +0000
commit1bcc2d793704bf43f6ecf9a01259e9cd6f6f8b2a (patch)
tree21bbc06d2e8dec46c6396cfbfd8d1e499f2733d8 /mod/groups/actions
parent1b9a059d96265ddb058be4f73c6989c318181f8d (diff)
downloadelgg-1bcc2d793704bf43f6ecf9a01259e9cd6f6f8b2a.tar.gz
elgg-1bcc2d793704bf43f6ecf9a01259e9cd6f6f8b2a.tar.bz2
updated the group actions - edit group needs more work
git-svn-id: http://code.elgg.org/elgg/trunk@8573 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/groups/actions')
-rw-r--r--mod/groups/actions/addtogroup.php77
-rw-r--r--mod/groups/actions/groups/delete.php (renamed from mod/groups/actions/delete.php)5
-rw-r--r--mod/groups/actions/groups/edit.php (renamed from mod/groups/actions/edit.php)15
-rw-r--r--mod/groups/actions/groups/featured.php (renamed from mod/groups/actions/featured.php)1
-rw-r--r--mod/groups/actions/groups/membership/add.php42
-rw-r--r--mod/groups/actions/groups/membership/delete_invite.php (renamed from mod/groups/actions/groupskillinvitation.php)2
-rw-r--r--mod/groups/actions/groups/membership/delete_request.php (renamed from mod/groups/actions/groupskillrequest.php)2
-rw-r--r--mod/groups/actions/groups/membership/invite.php51
-rw-r--r--mod/groups/actions/groups/membership/join.php70
-rw-r--r--mod/groups/actions/groups/membership/leave.php (renamed from mod/groups/actions/leave.php)0
-rw-r--r--mod/groups/actions/invite.php54
-rw-r--r--mod/groups/actions/join.php50
-rw-r--r--mod/groups/actions/joinrequest.php70
13 files changed, 173 insertions, 266 deletions
diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php
deleted file mode 100644
index d75c5fdb8..000000000
--- a/mod/groups/actions/addtogroup.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-/**
- * Add a user to a group
- *
- * @package ElggGroups
- */
-$logged_in_user = elgg_get_logged_in_user_entity();
-
-$user_guid = get_input('user_guid');
-if (!is_array($user_guid))
- $user_guid = array($user_guid);
-$group_guid = get_input('group_guid');
-
-if (sizeof($user_guid)) {
- foreach ($user_guid as $u_id) {
- $user = get_entity($u_id);
- $group = get_entity($group_guid);
-
- set_page_owner($group->guid);
-
- if ($user && $group) {
-
- //if (elgg_get_logged_in_user_guid() == $group->owner_guid)
- if ($group->canEdit()) {
-
- // If the group is open or the user has requested membership
- if (
- (check_entity_relationship($user->guid, 'membership_request', $group->guid)) ||
- ($group->isPublicMembership())
- ) {
-
- if (!$group->isMember($user)) {
- // Remove relationships
- remove_entity_relationship($group->guid, 'invited', $user->guid);
- remove_entity_relationship($user->guid, 'membership_request', $group->guid);
-
- //add_entity_relationship($user->guid, 'member', $group->guid);
- $group->join($user);
-
- // send welcome email
- notify_user($user->getGUID(), $group->owner_guid,
- elgg_echo('groups:welcome:subject', array($group->name)),
- elgg_echo('groups:welcome:body', array($user->name, $group->name, $group->getURL())),
- NULL);
-
- system_message(elgg_echo('groups:addedtogroup'));
- }
- else
- register_error(elgg_echo("groups:cantjoin"));
- }
- else {
- if ($user->isFriend()) {
-
- // Create relationship
- add_entity_relationship($group->guid, 'invited', $user->guid);
-
- // Send email
- $url = elgg_get_site_url() . "pg/groups/invited?user_guid={$user->guid}&group_guid={$group->guid}";
- if (notify_user($user->getGUID(), $group->owner_guid,
- elgg_echo('groups:invite:subject', array($user->name, $group->name)),
- elgg_echo('groups:invite:body', array($user->name, $logged_in_user->name, $group->name, $url)),
- NULL))
- system_message(elgg_echo("groups:userinvited"));
- else
- register_error(elgg_echo("groups:usernotinvited"));
- }
- else
- register_error(elgg_echo("groups:usernotinvited"));
- }
- }
- else
- register_error(elgg_echo("groups:notowner"));
- }
- }
-}
-
-forward(REFERER);
diff --git a/mod/groups/actions/delete.php b/mod/groups/actions/groups/delete.php
index 6eed12a9c..9ed7954dc 100644
--- a/mod/groups/actions/delete.php
+++ b/mod/groups/actions/groups/delete.php
@@ -6,6 +6,11 @@
$guid = (int) get_input('group_guid');
$entity = get_entity($guid);
+if (!$entity->canEdit()) {
+ register_error(elgg_echo('group:notdeleted'));
+ forward(REFERER);
+}
+
if (($entity) && ($entity instanceof ElggGroup)) {
// delete group icons
$owner_guid = $entity->owner_guid;
diff --git a/mod/groups/actions/edit.php b/mod/groups/actions/groups/edit.php
index baa1a7065..b3c39c461 100644
--- a/mod/groups/actions/edit.php
+++ b/mod/groups/actions/groups/edit.php
@@ -44,7 +44,6 @@ if (($group_guid) && (!$group->canEdit())) {
register_error(elgg_echo("groups:cantedit"));
forward(REFERER);
- exit;
}
// Assume we can edit or this is a new group
@@ -59,7 +58,6 @@ if (!$group->name) {
register_error(elgg_echo("groups:notitle"));
forward(REFERER);
- exit;
}
// Group membership - should these be treated with same constants as access permissions?
@@ -73,7 +71,7 @@ switch (get_input('membership')) {
// Set access - all groups are public from elgg's point of view, unless the override is in place
if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
- $visibility = (int)get_input('vis','',false);
+ $visibility = (int)get_input('vis', '', false);
$group->access_id = $visibility;
} else {
@@ -81,14 +79,9 @@ if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') {
}
// Set group tool options
-//$group->files_enable = get_input('files_enable', 'yes');
-//$group->pages_enable = get_input('pages_enable', 'yes');
-//$group->forum_enable = get_input('forum_enable', 'yes');
-
-// Set group tool options
if (isset($CONFIG->group_tool_options)) {
- foreach($CONFIG->group_tool_options as $group_option) {
- $group_option_toggle_name = $group_option->name."_enable";
+ foreach ($CONFIG->group_tool_options as $group_option) {
+ $group_option_toggle_name = $group_option->name . "_enable";
if ($group_option->default_on) {
$group_option_default_value = 'yes';
} else {
@@ -156,6 +149,4 @@ if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/'))
system_message(elgg_echo("groups:saved"));
-
forward($group->getUrl());
-
diff --git a/mod/groups/actions/featured.php b/mod/groups/actions/groups/featured.php
index 72ca7eebd..2d623b1e4 100644
--- a/mod/groups/actions/featured.php
+++ b/mod/groups/actions/groups/featured.php
@@ -5,7 +5,6 @@
* @package ElggGroups
*/
-
$group_guid = get_input('group_guid');
$action = get_input('action_type');
diff --git a/mod/groups/actions/groups/membership/add.php b/mod/groups/actions/groups/membership/add.php
new file mode 100644
index 000000000..de0cba613
--- /dev/null
+++ b/mod/groups/actions/groups/membership/add.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Add users to a group
+ *
+ * @package ElggGroups
+ */
+$logged_in_user = elgg_get_logged_in_user_entity();
+
+$user_guid = get_input('user_guid');
+if (!is_array($user_guid)) {
+ $user_guid = array($user_guid);
+}
+$group_guid = get_input('group_guid');
+$group = get_entity($group_guid);
+
+if (sizeof($user_guid)) {
+ foreach ($user_guid as $u_id) {
+ $user = get_user($u_id);
+
+ if ($user && $group && $group->canEdit()) {
+ if (!$group->isMember($user)) {
+ if (groups_join_group($group, $user)) {
+
+ // send welcome email to user
+ notify_user($user->getGUID(), $group->owner_guid,
+ elgg_echo('groups:welcome:subject', array($group->name)),
+ elgg_echo('groups:welcome:body', array(
+ $user->name,
+ $group->name,
+ $group->getURL())
+ ));
+
+ system_message(elgg_echo('groups:addedtogroup'));
+ } else {
+ // huh
+ }
+ }
+ }
+ }
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groupskillinvitation.php b/mod/groups/actions/groups/membership/delete_invite.php
index 516490bc9..4b654f0b6 100644
--- a/mod/groups/actions/groupskillinvitation.php
+++ b/mod/groups/actions/groups/membership/delete_invite.php
@@ -1,6 +1,6 @@
<?php
/**
- * Delete an invitation to join a closed group.
+ * Delete an invitation to join a group.
*
* @package ElggGroups
*/
diff --git a/mod/groups/actions/groupskillrequest.php b/mod/groups/actions/groups/membership/delete_request.php
index 9d45bb25f..883c9d748 100644
--- a/mod/groups/actions/groupskillrequest.php
+++ b/mod/groups/actions/groups/membership/delete_request.php
@@ -1,6 +1,6 @@
<?php
/**
- * Delete a user request to join a closed group.
+ * Delete a request to join a closed group.
*
* @package ElggGroups
*/
diff --git a/mod/groups/actions/groups/membership/invite.php b/mod/groups/actions/groups/membership/invite.php
new file mode 100644
index 000000000..b106e4869
--- /dev/null
+++ b/mod/groups/actions/groups/membership/invite.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Invite users to join a group
+ *
+ * @package ElggGroups
+ */
+
+$logged_in_user = elgg_get_logged_in_user_entity();
+
+$user_guid = get_input('user_guid');
+if (!is_array($user_guid)) {
+ $user_guid = array($user_guid);
+}
+$group_guid = get_input('group_guid');
+
+if (sizeof($user_guid)) {
+ foreach ($user_guid as $u_id) {
+ $user = get_entity($u_id);
+ $group = get_entity($group_guid);
+
+ if ($user && $group && ($group instanceof ElggGroup) && $group->canEdit()) {
+
+ if (!check_entity_relationship($group->guid, 'invited', $user->guid)) {
+
+ // Create relationship
+ add_entity_relationship($group->guid, 'invited', $user->guid);
+
+ // Send email
+ $url = elgg_normalize_url("pg/groups/invitations/$user->username");
+ $result = notify_user($user->getGUID(), $group->owner_guid,
+ elgg_echo('groups:invite:subject', array($user->name, $group->name)),
+ elgg_echo('groups:invite:body', array(
+ $user->name,
+ $logged_in_user->name,
+ $group->name,
+ $url,
+ )),
+ NULL);
+ if ($result) {
+ system_message(elgg_echo("groups:userinvited"));
+ } else {
+ register_error(elgg_echo("groups:usernotinvited"));
+ }
+ } else {
+ register_error(elgg_echo("groups:useralreadyinvited"));
+ }
+ }
+ }
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/groups/membership/join.php b/mod/groups/actions/groups/membership/join.php
new file mode 100644
index 000000000..3c4571a59
--- /dev/null
+++ b/mod/groups/actions/groups/membership/join.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Join a group
+ *
+ * Three states:
+ * open group so user joins
+ * closed group so request sent to group owner
+ * closed group with invite so user joins
+ *
+ * @package ElggGroups
+ */
+
+$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
+$group_guid = get_input('group_guid');
+
+$user = get_entity($user_guid);
+
+// @todo investigate if the access bypass is needed
+$ia = elgg_set_ignore_access(true);
+$group = get_entity($group_guid);
+elgg_set_ignore_access($ia);
+
+if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) {
+
+ // join or request
+ $join = false;
+ if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
+ // anyone can join public groups and admins can join any group
+ $join = true;
+ } else {
+ if (check_entity_relationship($user->guid, 'membership_request', $group->guid)) {
+ // user has invite to closed group
+ $join = true;
+ }
+ }
+
+ if ($join) {
+ if (groups_join_group($group, $user)) {
+ system_message(elgg_echo("groups:joined"));
+ forward($group->getURL());
+ } else {
+ register_error(elgg_echo("groups:cantjoin"));
+ }
+ } else {
+ add_entity_relationship($user->guid, 'membership_request', $group->guid);
+
+ // Notify group owner
+ $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}";
+ $subject = elgg_echo('groups:request:subject', array(
+ $user->name,
+ $group->name,
+ ));
+ $body = elgg_echo('groups:request:body', array(
+ $group->getOwnerEntity()->name,
+ $user->name,
+ $group->name,
+ $user->getURL(),
+ $url,
+ ));
+ if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) {
+ system_message(elgg_echo("groups:joinrequestmade"));
+ } else {
+ register_error(elgg_echo("groups:joinrequestnotmade"));
+ }
+ }
+} else {
+ register_error(elgg_echo("groups:cantjoin"));
+}
+
+forward(REFERER);
diff --git a/mod/groups/actions/leave.php b/mod/groups/actions/groups/membership/leave.php
index 390870df1..390870df1 100644
--- a/mod/groups/actions/leave.php
+++ b/mod/groups/actions/groups/membership/leave.php
diff --git a/mod/groups/actions/invite.php b/mod/groups/actions/invite.php
deleted file mode 100644
index 1f8281071..000000000
--- a/mod/groups/actions/invite.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/**
- * Invite a user to join a group
- *
- * @package ElggGroups
- */
-
-$logged_in_user = elgg_get_logged_in_user_entity();
-
-$user_guid = get_input('user_guid');
-if (!is_array($user_guid)) {
- $user_guid = array($user_guid);
-}
-$group_guid = get_input('group_guid');
-
-if (sizeof($user_guid)) {
- foreach ($user_guid as $u_id) {
- $user = get_entity($u_id);
- $group = get_entity($group_guid);
-
- if ( $user && $group) {
-
- if (($group instanceof ElggGroup) && ($group->canEdit())) {
- if (!check_entity_relationship($group->guid, 'invited', $user->guid)) {
- if ($user->isFriend()) {
-
- // Create relationship
- add_entity_relationship($group->guid, 'invited', $user->guid);
-
- // Send email
- $url = elgg_normalize_url("pg/groups/invitations/$user->username");
- $result = notify_user($user->getGUID(), $group->owner_guid,
- elgg_echo('groups:invite:subject', array($user->name, $group->name)),
- elgg_echo('groups:invite:body', array($user->name, $logged_in_user->name, $group->name, $url)),
- NULL);
- if ($result) {
- system_message(elgg_echo("groups:userinvited"));
- } else {
- register_error(elgg_echo("groups:usernotinvited"));
- }
- } else {
- register_error(elgg_echo("groups:usernotinvited"));
- }
- } else {
- register_error(elgg_echo("groups:useralreadyinvited"));
- }
- } else {
- register_error(elgg_echo("groups:notowner"));
- }
- }
- }
-}
-
-forward(REFERER);
diff --git a/mod/groups/actions/join.php b/mod/groups/actions/join.php
deleted file mode 100644
index 72294c3ad..000000000
--- a/mod/groups/actions/join.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
- * Join a group action.
- *
- * @package ElggGroups
- */
-
-$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
-$group_guid = get_input('group_guid');
-
-// @todo fix for #287
-// disable access to get entity.
-$invitations = groups_get_invited_groups($user_guid, TRUE);
-
-if (in_array($group_guid, $invitations)) {
- $ia = elgg_set_ignore_access(TRUE);
-}
-
-$user = get_entity($user_guid);
-$group = get_entity($group_guid);
-
-set_page_owner($group->guid);
-
-if (($user instanceof ElggUser) && ($group instanceof ElggGroup)) {
- if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
- if ($group->join($user)) {
- system_message(elgg_echo("groups:joined"));
-
- // Remove any invite or join request flags
- remove_entity_relationship($group->guid, 'invited', $user->guid);
- remove_entity_relationship($user->guid, 'membership_request', $group->guid);
-
- // add to river
- add_to_river('river/relationship/member/create','join',$user->guid,$group->guid);
-
- forward($group->getURL());
- } else {
- register_error(elgg_echo("groups:cantjoin"));
- }
- } else {
- // Closed group, request membership
- system_message(elgg_echo('groups:privategroup'));
- forward(elgg_add_action_tokens_to_url("action/groups/joinrequest?user_guid=$user_guid&group_guid=$group_guid", FALSE));
- }
-} else {
- register_error(elgg_echo("groups:cantjoin"));
-}
-
-forward(REFERER);
-
diff --git a/mod/groups/actions/joinrequest.php b/mod/groups/actions/joinrequest.php
deleted file mode 100644
index 1631712b6..000000000
--- a/mod/groups/actions/joinrequest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * User requests to join a closed group.
- *
- * @package ElggGroups
- */
-
-$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
-$group_guid = get_input('group_guid');
-
-
-// @todo fix for #287
-// disable access to get entity.
-$invitations = groups_get_invited_groups($user_guid, TRUE);
-
-if (in_array($group_guid, $invitations)) {
- $ia = elgg_set_ignore_access(TRUE);
-}
-
-
-$user = get_entity($user_guid);
-$group = get_entity($group_guid);
-
-set_page_owner($group->guid);
-
-// If not a member of this group
-if (($group) && ($user) && (!$group->isMember($user))) {
- // If open group or invite exists
- if (
- ($group->isPublicMembership()) ||
- (check_entity_relationship($group->guid, 'invited', $user->guid))
- ) {
- //$ia = elgg_set_ignore_access(TRUE);
- if ($group->join($user)) {
- // Remove relationships
- remove_entity_relationship($group->guid, 'invited', $user->guid);
- remove_entity_relationship($user->guid, 'membership_request', $group->guid);
-
- // Group joined
- system_message(elgg_echo('groups:joined'));
- elgg_set_ignore_access($ia);
-
- forward($group->getURL());
- } else {
- elgg_set_ignore_access($ia);
- system_message(elgg_echo('groups:cantjoin'));
- }
- } else {
- // If join request not already made
- if (!check_entity_relationship($user->guid, 'membership_request', $group->guid)) {
- // Add membership requested
- add_entity_relationship($user->guid, 'membership_request', $group->guid);
-
- // Send email
- $url = elgg_normalize_url("mod/groups/membershipreq.php?group_guid={$group->guid}");
- if (notify_user($group->owner_guid, $user->getGUID(),
- elgg_echo('groups:request:subject', array($user->name, $group->name)),
- elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url)),
- NULL)) {
- system_message(elgg_echo("groups:joinrequestmade"));
- } else {
- register_error(elgg_echo("groups:joinrequestnotmade"));
- }
- } else {
- system_message(elgg_echo("groups:joinrequestmade"));
- }
- }
-}
-
-forward(REFERER); \ No newline at end of file