831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
if(!defined("PHORUM_CONTROL_CENTER")) return;
|
|
|
21 |
|
|
|
22 |
// if we have a request to join a group, try and do it
|
|
|
23 |
if (isset($_POST["joingroup"]) && $_POST["joingroup"] > 0){
|
|
|
24 |
// get the group, and the group list of the user trying to join
|
|
|
25 |
$group = phorum_db_get_groups($_POST["joingroup"]);
|
|
|
26 |
$usergroup = phorum_user_get_groups($PHORUM["user"]["user_id"]);
|
|
|
27 |
|
|
|
28 |
// the user can't already be a member of the group, and the group must allow join requests
|
|
|
29 |
if (!isset($usergroup[$_POST["joingroup"]])){
|
|
|
30 |
if ($group[$_POST["joingroup"]]["open"] == PHORUM_GROUP_OPEN){
|
|
|
31 |
$usergroup[$_POST["joingroup"]] = PHORUM_USER_GROUP_APPROVED;
|
|
|
32 |
phorum_user_save_groups($PHORUM["user"]["user_id"], $usergroup);
|
|
|
33 |
$PHORUM['DATA']['Message'] = $PHORUM['DATA']['LANG']['GroupJoinSuccess'];
|
|
|
34 |
}
|
|
|
35 |
elseif ($group[$_POST["joingroup"]]["open"] == PHORUM_GROUP_REQUIRE_APPROVAL){
|
|
|
36 |
$usergroup[$_POST["joingroup"]] = PHORUM_USER_GROUP_UNAPPROVED;
|
|
|
37 |
phorum_user_save_groups($PHORUM["user"]["user_id"], $usergroup);
|
|
|
38 |
$PHORUM['DATA']['Message'] = $PHORUM['DATA']['LANG']['GroupJoinSuccessModerated'];
|
|
|
39 |
}
|
|
|
40 |
else
|
|
|
41 |
{
|
|
|
42 |
$PHORUM['DATA']['Message'] = $PHORUM['DATA']['LANG']['GroupJoinFail'];
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
else{
|
|
|
46 |
$PHORUM['DATA']['Message'] = $PHORUM['DATA']['LANG']['GroupJoinFail'];
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
$template = "cc_groups";
|
|
|
51 |
$PHORUM['DATA']['Groups'] = phorum_readable_groups();
|
|
|
52 |
$PHORUM['DATA']['JOINGROUP'] = phorum_joinable_groups();
|
|
|
53 |
$PHORUM["DATA"]["GROUP"]["url"] = phorum_get_url(PHORUM_CONTROLCENTER_ACTION_URL, "panel=" . PHORUM_CC_GROUP_MEMBERSHIP);
|
|
|
54 |
|
|
|
55 |
/* --------------------------------------------------------------- */
|
|
|
56 |
|
|
|
57 |
function phorum_readable_groups()
|
|
|
58 |
{
|
|
|
59 |
$PHORUM=$GLOBALS['PHORUM'];
|
|
|
60 |
$readablegroups = array();
|
|
|
61 |
$groups = phorum_user_get_groups($PHORUM["user"]["user_id"]);
|
|
|
62 |
// print_r(array_keys($groups));
|
|
|
63 |
// print_r(array_values($groups));
|
|
|
64 |
foreach($groups as $groupid => $perm){
|
|
|
65 |
$group = phorum_db_get_groups($groupid);
|
|
|
66 |
switch ($perm){
|
|
|
67 |
case PHORUM_USER_GROUP_SUSPENDED:
|
|
|
68 |
$readablegroups[] = array('groupname' => $group[$groupid]["name"], 'perm' => $PHORUM['DATA']['LANG']['Suspended']);
|
|
|
69 |
break;
|
|
|
70 |
case PHORUM_USER_GROUP_UNAPPROVED:
|
|
|
71 |
$readablegroups[] = array('groupname' => $group[$groupid]["name"], 'perm' => $PHORUM['DATA']['LANG']['Unapproved']);
|
|
|
72 |
break;
|
|
|
73 |
|
|
|
74 |
case PHORUM_USER_GROUP_APPROVED:
|
|
|
75 |
$readablegroups[] = array('groupname' => $group[$groupid]["name"], 'perm' => $PHORUM['DATA']['LANG']['Approved']);
|
|
|
76 |
break;
|
|
|
77 |
|
|
|
78 |
case PHORUM_USER_GROUP_MODERATOR:
|
|
|
79 |
$readablegroups[] = array('groupname' => $group[$groupid]["name"], 'perm' => $PHORUM['DATA']['LANG']['PermGroupModerator']);
|
|
|
80 |
break;
|
|
|
81 |
|
|
|
82 |
// something weird happened
|
|
|
83 |
default:
|
|
|
84 |
$readablegroups[] = array('groupname' => $group[$groupid]["name"], 'perm' => '?');
|
|
|
85 |
break;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
return $readablegroups;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
function phorum_joinable_groups()
|
|
|
92 |
{
|
|
|
93 |
$PHORUM = $GLOBALS["PHORUM"];
|
|
|
94 |
$joinablegroups = array();
|
|
|
95 |
$groups = phorum_db_get_groups();
|
|
|
96 |
$memberof = phorum_user_get_groups($PHORUM["user"]["user_id"]);
|
|
|
97 |
foreach ($groups as $group){
|
|
|
98 |
if (!isset($memberof[$group["group_id"]])){
|
|
|
99 |
if ($group["open"] == PHORUM_GROUP_OPEN){
|
|
|
100 |
$joinablegroups[] = array("group_id" => $group["group_id"], "name" => $group["name"]);
|
|
|
101 |
}
|
|
|
102 |
elseif ($group["open"] == PHORUM_GROUP_REQUIRE_APPROVAL){
|
|
|
103 |
$joinablegroups[] = array("group_id" => $group["group_id"], "name" => $group["name"] . " (*)");
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
return $joinablegroups;
|
|
|
108 |
}
|
|
|
109 |
?>
|