view.php 6.25 KB
Newer Older
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
5
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
6
 *
Francois Marier's avatar
Francois Marier committed
7
8
9
10
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
11
 *
Francois Marier's avatar
Francois Marier committed
12
13
14
15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
16
 *
Francois Marier's avatar
Francois Marier committed
17
18
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21
 *
 * @package    mahara
 * @subpackage core
22
 * @author     Catalyst IT Ltd
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
24
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
25
26
27
28
 *
 */

define('INTERNAL', 1);
29
define('PUBLIC', 1);
30
define('MENUITEM', 'groups/info');
31
require(dirname(dirname(__FILE__)) . '/init.php');
32
require_once('group.php');
33
require_once('searchlib.php');
34
require_once(get_config('docroot') . 'interaction/lib.php');
35
require_once(get_config('libroot') . 'view.php');
36
safe_require('artefact', 'file');
37

38
define('GROUP', param_integer('id'));
39
$group = group_current_group();
40
41
42
if (!is_logged_in() && !$group->public) {
    throw new AccessDeniedException();
}
43

Nigel McNie's avatar
Nigel McNie committed
44
define('TITLE', $group->name);
45
$group->ctime = strftime(get_string('strftimedate'), $group->ctime);
46

47
48
49
$group->admins = get_column_sql("SELECT member
    FROM {group_member}
    WHERE \"group\" = ?
50
    AND role = 'admin'", array($group->id));
51

52
$role = group_user_access($group->id);
53
$group->role = $role;
54
55

if (is_logged_in()) {
56
    $afterjoin = param_variable('next', 'view');
57
58
59
60
    if ($role) {
        if ($role == 'admin') {
            $group->membershiptype = 'admin';
            $group->requests = count_records('group_member_request', 'group', $group->id);
61
        }
62
63
64
65
        else {
            $group->membershiptype = 'member';
        }
        $group->canleave = group_user_can_leave($group->id);
66
    }
67
68
69
    else if ($group->jointype == 'invite'
             and $invite = get_record('group_member_invite', 'group', $group->id, 'member', $USER->get('id'))) {
        $group->membershiptype = 'invite';
70
        $group->invite = group_get_accept_form('invite', $group->id, $afterjoin);
71
72
73
74
75
76
    }
    else if ($group->jointype == 'request'
             and $request = get_record('group_member_request', 'group', $group->id, 'member', $USER->get('id'))) {
        $group->membershiptype = 'request';
    }
    else if ($group->jointype == 'open') {
77
        $group->groupjoin = group_get_join_form('joingroup', $group->id, $afterjoin);
78
79
    }
}
80

81
82
$group->grouptypedescription = get_string('grouptypedescription', 'group', get_string('name', 'grouptype.' . $group->grouptype), get_string('membershiptype.'.$group->jointype, 'group'));

83
$filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null);
84

85
86
87
88
// Latest forums posts
// NOTE: it would be nicer if there was some generic way to get information 
// from any installed interaction. But the only interaction plugin is forum, 
// and group info pages might be replaced with views anyway...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
$foruminfo = null;
if ($role || $group->public) {
    $foruminfo = get_records_sql_array('
        SELECT
            p.id, p.subject, p.body, p.poster, p.topic, t.forum, pt.subject AS topicname
        FROM
            {interaction_forum_post} p
            INNER JOIN {interaction_forum_topic} t ON (t.id = p.topic)
            INNER JOIN {interaction_instance} i ON (i.id = t.forum)
            INNER JOIN {interaction_forum_post} pt ON (pt.topic = p.topic AND pt.parent IS NULL)
        WHERE
            i.group = ?
            AND i.deleted = 0
            AND t.deleted = 0
            AND p.deleted = 0
        ORDER BY
            p.ctime DESC
        LIMIT 5;
        ', array($group->id));
}

110
111
112
if ($role) {
    // For group members, display a list of views that others have
    // shared to the group
113
    $sharedviews = View::get_sharedviews_data(null, 0, $group->id);
114
115
    if (group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
        // Display a list of views submitted to the group
116
        $allsubmittedviews = View::get_submitted_views($group->id);
117
118
    }
}
119

120
if (group_allows_submission($group->grouptype) && ($userviewdata = View::get_user_views())) {
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    // A user can submit more than one view to the same group, but no view can be
    // submitted to more than one group.

    // Display a list of views this user has submitted to this group, and a submission
    // form containing drop-down of their unsubmitted views.

    $mysubmittedviews = View::get_submitted_views($group->id, $USER->get('id'));

    if (!empty($mysubmittedviews)) {
        foreach ($mysubmittedviews as &$v) {
            $url = get_config('wwwroot') . 'view/view.php?id=' . $v['id'];
            if ($v['submittedtime']) {
                $v['strsubmitted'] = get_string('youhavesubmittedon', 'view', $url, $v['title'], format_date($v['submittedtime']));
            }
            else {
                $v['strsubmitted'] = get_string('youhavesubmitted', 'view', $url, $v['title']);
            }
138
        }
139
    }
140
141

    $group_view_submission_form = group_view_submission_form($group->id, $userviewdata);
142
143
144
145
146
147
148
149
150
151
152
153
154
155
}

$smarty = smarty();
$smarty->assign('group', $group);
$smarty->assign('groupid', $group->id);
$smarty->assign('foruminfo', $foruminfo);
$smarty->assign('membercount', count_records('group_member', 'group', $group->id));
$smarty->assign('viewcount', count_records('view', 'group', $group->id));
$smarty->assign('filecount', $filecounts->files);
$smarty->assign('foldercount', $filecounts->folders);

if (isset($sharedviews)) {
    $smarty->assign('sharedviews', $sharedviews->data);
}
156
157
158
159
160
if (isset($allsubmittedviews)) {
    $smarty->assign('allsubmittedviews', $allsubmittedviews);
}
if (isset($mysubmittedviews)) {
    $smarty->assign('mysubmittedviews', $mysubmittedviews);
161
162
}
if (isset($group_view_submission_form)) {
163
    $smarty->assign('group_view_submission_form', $group_view_submission_form);
164
165
}

166
$smarty->assign('role', $role);
167
$smarty->display('group/view.tpl');
168

169
?>