aboutsummaryrefslogtreecommitdiff
path: root/mod/groups/actions
diff options
context:
space:
mode:
Diffstat (limited to 'mod/groups/actions')
-rw-r--r--mod/groups/actions/addtogroup.php79
-rw-r--r--mod/groups/actions/edit.php60
-rw-r--r--mod/groups/actions/join.php54
-rw-r--r--mod/groups/actions/joinrequest.php73
-rw-r--r--mod/groups/actions/leave.php39
5 files changed, 305 insertions, 0 deletions
diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php
new file mode 100644
index 000000000..db697d573
--- /dev/null
+++ b/mod/groups/actions/addtogroup.php
@@ -0,0 +1,79 @@
+<?php
+
+ /**
+ * Add a user to a group
+ *
+ * @package ElggGroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Load configuration
+ global $CONFIG;
+
+ gatekeeper();
+
+ $user_guid = get_input('user_guid');
+ $group_guid = get_input('group_guid');
+
+ $user = get_entity($user_guid);
+ $group = get_entity($group);
+
+ if ($_SESSION['user']->getGUID() == $group->getGUID())
+ {
+ $requests = $user->group_join_request;
+ if ($requests)
+ {
+ foreach ($requests as $request)
+ {
+ if ($request == $group->getGUID())
+ {
+ // User has requested to join this group previously, so we can safely add them
+
+ // add them
+ if ($group->join($user))
+ {
+
+ // send welcome email
+ notify_user($user->getGUID(), "",
+ sprintf(elgg_echo('groups:welcome:subject'), $group->title),
+ sprintf(elgg_echo('groups:welcome:body'), $user->name, $group->title, $group->getURL()),
+ NULL, "email");
+
+ system_message(elgg_echo('groups:addedtogroup'));
+
+ }
+ else
+ system_message(elgg_echo("groups:cantjoin"));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+ }
+ }
+
+ // Not found in request array, so send an invite and set invite flag
+
+ // Set invite flag
+ if (!$user->setMetaData('group_invite', $group->getGUID(), "", true))
+ system_message(elgg_echo("groups:usernotinvited"));
+ else
+ {
+ // Send email
+ if (notify_user($user->getGUID(), "",
+ sprintf(elgg_echo('groups:invite:subject'), $user->name, $group->title),
+ sprintf(elgg_echo('groups:invite:body'), $user->name, $group->title, "http://{$CONFIG->url}action/groups/join?user_guid={$user->guid}&group_guid={$group->guid}"),
+ NULL, "email"))
+ system_message(elgg_echo("groups:userinvited"));
+ else
+ system_message(elgg_echo("groups:usernotinvited"));
+ }
+ }
+ }
+ else
+ system_message(elgg_echo("groups:notowner"));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+?> \ No newline at end of file
diff --git a/mod/groups/actions/edit.php b/mod/groups/actions/edit.php
new file mode 100644
index 000000000..4e9cdf99e
--- /dev/null
+++ b/mod/groups/actions/edit.php
@@ -0,0 +1,60 @@
+<?php
+ /**
+ * Elgg groups plugin edit action.
+ *
+ * @package ElggGroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Load configuration
+ global $CONFIG;
+
+ // Get group fields
+ $input = array();
+ foreach($CONFIG->group as $shortname => $valuetype) {
+ $input[$shortname] = get_input($shortname);
+ if ($valuetype == 'tags')
+ $input[$shortname] = string_to_tag_array($input[$shortname]);
+ }
+
+ $user_guid = get_input('user_guid');
+ $user = NULL;
+ if (!$user_guid) $user = $_SESSION['user'];
+ else
+ $user = get_entity($user_guid);
+
+ $group_guid = get_input('group_guid');
+
+ $group = new ElggGroup($group_guid); // load if present, if not create a new group
+ if (($group_guid) && (!$group->canEdit()))
+ {
+ system_message(elgg_echo("groups:cantedit"));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+ }
+
+ // Assume we can edit or this is a new group
+ if (sizeof($input) > 0)
+ {
+ foreach($input as $shortname => $value) {
+ $group->$shortname = $value;
+ }
+ }
+
+ // Get access
+ $group->access_id = get_input('access_id', 0);
+
+ $group->save();
+
+ $group->join($user); // Creator always a member
+
+ system_message(elgg_echo("groups:saved"));
+
+ // Forward to the user's profile
+ forward($group->getUrl());
+ exit;
+?> \ No newline at end of file
diff --git a/mod/groups/actions/join.php b/mod/groups/actions/join.php
new file mode 100644
index 000000000..77d2e3021
--- /dev/null
+++ b/mod/groups/actions/join.php
@@ -0,0 +1,54 @@
+<?php
+ /**
+ * Join a group action.
+ *
+ * @package ElggGroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Load configuration
+ global $CONFIG;
+
+ gatekeeper();
+
+ $user_guid = get_input('user_guid');
+ $group_guid = get_input('group_guid');
+
+ $user = NULL;
+ if (!$user_guid) $user = $_SESSION['user'];
+ else
+ $user = get_entity($user_guid);
+
+ $group = get_entity($group_guid);
+
+ if (($user instanceof ElggUser) && ($group instanceof ElggGroup))
+ {
+ if ($group->access_id == 2)
+ {
+ if ($group->join($user))
+ {
+ system_message(elgg_echo("groups:joined"));
+
+ forward($group->getURL());
+ exit;
+ }
+ else
+ system_message(elgg_echo("groups:cantjoin"));
+ }
+ else
+ {
+ // Closed group, request membership
+ system_message(elgg_echo('groups:privategroup'));
+ forward($CONFIG->url . "actions/groups/joinrequest?user_guid=$user_guid&group_guid=$group_guid");
+ exit;
+ }
+ }
+ else
+ system_message(elgg_echo("groups:cantjoin"));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+?> \ No newline at end of file
diff --git a/mod/groups/actions/joinrequest.php b/mod/groups/actions/joinrequest.php
new file mode 100644
index 000000000..6288e0e76
--- /dev/null
+++ b/mod/groups/actions/joinrequest.php
@@ -0,0 +1,73 @@
+<?php
+ /**
+ * User requests to join a closed group.
+ *
+ * @package ElggGroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Load configuration
+ global $CONFIG;
+
+ gatekeeper();
+
+ $user_guid = get_input('user_guid');
+ $group_guid = get_input('group_guid');
+
+ $user = get_entity($user_guid);
+ $group = get_entity($group);
+
+ if (!$group->isMember($user))
+ {
+ $invites = $user->group_invite;
+
+ if ($invites)
+ {
+ foreach ($invites as $invite)
+ {
+ if ($invite = $group->getGUID())
+ {
+ if ($group->join($user))
+ {
+ system_message(elgg_echo('groups:joined'));
+
+ forward($group->getURL());
+ exit;
+ }
+ else
+ system_message(elgg_echo('groups:cantjoin'));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+ }
+
+ }
+
+ // else email membership requiest
+ // set flag
+
+ if (!$user->setMetaData('group_join_request', $group->getGUID(), "", true))
+ system_message(elgg_echo("groups:joinrequestnotmade"));
+ else
+ {
+ // Send email
+ if (notify_user($group->owner_guid, "",
+ sprintf(elgg_echo('groups:request:subject'), $user->name, $group->title),
+ sprintf(elgg_echo('groups:request:body'), $group->getOwner()->name, $user->name, $group->title, $user->getURL(), "http://{$CONFIG->url}action/groups/addtogroup?user_guid={$user->guid}&group_guid={$group->guid}"),
+ NULL, "email"))
+ system_message(elgg_echo("groups:joinrequestmade"));
+ else
+ system_message(elgg_echo("groups:joinrequestnotmade"));
+ }
+ }
+
+ }
+ else
+ system_message(elgg_echo('groups:alreadymember'));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+?> \ No newline at end of file
diff --git a/mod/groups/actions/leave.php b/mod/groups/actions/leave.php
new file mode 100644
index 000000000..87f976b3e
--- /dev/null
+++ b/mod/groups/actions/leave.php
@@ -0,0 +1,39 @@
+<?php
+ /**
+ * Leave a group action.
+ *
+ * @package ElggGroups
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Marcus Povey
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.com/
+ */
+
+ // Load configuration
+ global $CONFIG;
+
+ gatekeeper();
+
+ $user_guid = get_input('user_guid');
+ $group_guid = get_input('group_guid');
+
+ $user = NULL;
+ if (!$user_guid) $user = $_SESSION['user'];
+ else
+ $user = get_entity($user_guid);
+
+ $group = get_entity($group_guid);
+
+ if (($user instanceof ElggUser) && ($group instanceof ElggGroup))
+ {
+ if ($group->leave($user))
+ system_message(elgg_echo("groups:left"));
+ else
+ system_message(elgg_echo("groups:cantleave"));
+ }
+ else
+ system_message(elgg_echo("groups:cantleave"));
+
+ forward($_SERVER['HTTP_REFERER']);
+ exit;
+?> \ No newline at end of file