index.php 4.28 KB
Newer Older
Clare Lenihan's avatar
Clare Lenihan committed
1
2
3
4
5
<?php
/**
 *
 * @package    mahara
 * @subpackage interaction-forum
6
 * @author     Catalyst IT Ltd
7
8
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
Clare Lenihan's avatar
Clare Lenihan committed
9
10
11
 *
 */

12
define('PUBLIC', 1);
Clare Lenihan's avatar
Clare Lenihan committed
13
define('INTERNAL', 1);
14
define('MENUITEM', 'groups/forums');
15
16
17
18
define('SECTION_PLUGINTYPE', 'interaction');
define('SECTION_PLUGINNAME', 'forum');
define('SECTION_PAGE', 'index');

Clare Lenihan's avatar
Clare Lenihan committed
19
20
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('group.php');
21
safe_require('interaction', 'forum');
22
23
require_once('pieforms/pieform.php');
require_once(get_config('docroot') . 'interaction/lib.php');
Clare Lenihan's avatar
Clare Lenihan committed
24

Clare Lenihan's avatar
Clare Lenihan committed
25
$groupid = param_integer('group');
26
define('GROUP', $groupid);
27
$group = group_current_group();
Clare Lenihan's avatar
Clare Lenihan committed
28

29
$membership = group_user_access($groupid);
Clare Lenihan's avatar
Clare Lenihan committed
30

31
if (!$membership && !$group->public) {
32
    throw new GroupAccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
Clare Lenihan's avatar
Clare Lenihan committed
33
34
}

35
define('TITLE', $group->name . ' - ' . get_string('nameplural', 'interaction.forum'));
36

37
$forums = get_forum_list($group->id, $USER->get('id'));
38
if ($forums) {
39
40
    // query gets a new forum object for every moderator of that forum
    // this combines all moderators together into one object per forum
41
42
43
44
45
46
47
48
49
50
51
52
    $count = count($forums);
    for ($i = 0; $i < $count; $i++) {
        $forums[$i]->moderators = array();
        if ($forums[$i]->moderator) {
            $forums[$i]->moderators[] = $forums[$i]->moderator;
        }
        $temp = $i;
        while (isset($forums[$i+1]) && $forums[$i+1]->id == $forums[$temp]->id) {
            $i++;
            $forums[$temp]->moderators[] = $forums[$i]->moderator;
            unset($forums[$i]);
        }
53
    }
Evan Goldenberg's avatar
Evan Goldenberg committed
54

Ruslan Kabalin's avatar
Ruslan Kabalin committed
55
    $i = 0;
Clare Lenihan's avatar
Clare Lenihan committed
56
    foreach ($forums as $forum) {
Ruslan Kabalin's avatar
Ruslan Kabalin committed
57
58
59
60
61
62
63
64
65
66
        $forum->feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=f&id=' . $forum->id;

        if ($membership) {
            $forum->subscribe = pieform(array(
                'name'     => 'subscribe_forum' . ($i == 0 ? '' : $i),
                'plugintype' => 'interaction',
                'pluginname' => 'forum',
                'validatecallback' => 'subscribe_forum_validate',
                'successcallback' => 'subscribe_forum_submit',
                'autofocus' => false,
67
                'renderer' => 'oneline',
Ruslan Kabalin's avatar
Ruslan Kabalin committed
68
69
                'elements' => array(
                    'submit' => array(
Clare Lenihan's avatar
Clare Lenihan committed
70
                    'type'  => 'submit',
71
                        'class' => $forum->subscribed ? 'btn btn-default btn-xs' : 'btn btn-primary btn-xs',
Ruslan Kabalin's avatar
Ruslan Kabalin committed
72
                        'value' => $forum->subscribed ? get_string('Unsubscribe', 'interaction.forum') : get_string('Subscribe', 'interaction.forum'),
73
74
                        // 'help' => $i == 0 ? true : false
                        'help' => false
Ruslan Kabalin's avatar
Ruslan Kabalin committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
                    ),
                    'forum' => array(
                        'type' => 'hidden',
                        'value' => $forum->id
                    ),
                    'redirect' => array(
                        'type' => 'hidden',
                        'value' => 'index'
                    ),
                    'group' => array(
                        'type' => 'hidden',
                        'value' => $groupid
                    ),
                    'type' => array(
                        'type' => 'hidden',
                        'value' => $forum->subscribed ? 'unsubscribe' : 'subscribe'
                    ),
Clare Lenihan's avatar
Clare Lenihan committed
92
                )
Ruslan Kabalin's avatar
Ruslan Kabalin committed
93
94
95
            ));
            $i++;
        }
Clare Lenihan's avatar
Clare Lenihan committed
96
    }
Clare Lenihan's avatar
Clare Lenihan committed
97
98
}

Evan Goldenberg's avatar
Evan Goldenberg committed
99
100
$feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=g&id=' . $group->id;
$headers = array();
Evan Goldenberg's avatar
Evan Goldenberg committed
101
if ($group->public) {
102
    $headers[] ='<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '">';
Evan Goldenberg's avatar
Evan Goldenberg committed
103
104
105
}

$smarty = smarty(array(), $headers, array(), array());
Clare Lenihan's avatar
Clare Lenihan committed
106
$smarty->assign('groupid', $groupid);
Evan Goldenberg's avatar
Evan Goldenberg committed
107
108
$smarty->assign('publicgroup', $group->public);
$smarty->assign('feedlink', $feedlink);
109
$smarty->assign('heading', $group->name);
110
$smarty->assign('headingclass', 'page-header');
111
112
$smarty->assign('subsectionheading', get_string('nameplural', 'interaction.forum'));
$smarty->assign('rsswithtitle', true);
113
$smarty->assign('admin', $membership == 'admin');
114
$smarty->assign('groupadmins', group_get_admins(array($groupid)));
Clare Lenihan's avatar
Clare Lenihan committed
115
116
$smarty->assign('forums', $forums);
$smarty->display('interaction:forum:index.tpl');