Commit 36b041b8 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

now lists forums

parent a49d05fe
Viewing all forums in a group go here
<?php
/**
* This program is part of Mahara
*
* 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 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage interaction-forum
* @author Clare Lenihan <clare@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('group.php');
define('TITLE', get_string('nameplural', 'interaction.forum'));
$group = param_integer('group');
$membership = user_can_access_group($group);
if (!$membership) {
throw new AccessDeniedException();
}
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$forums = get_records_sql_array(
'SELECT f.id, f.title, f.description, COUNT(t.*), s.forum as subscribed
FROM {interaction_instance} f
LEFT JOIN {interaction_forum_topic} t
ON (t.forum = f.id AND t.deleted != 1)
INNER JOIN {interaction_forum_instance_config} c
ON (c.forum = f.id AND c.field = \'weight\')
LEFT JOIN {interaction_forum_subscription_forum} s
ON (s.forum = f.id AND s."user" = ?)
WHERE f.group=?
AND f.deleted!=1
GROUP BY 1, 2, 3, 5, c.value
ORDER BY c.value',
array($USER->get('id'), $group)
);
require_once('pieforms/pieform.php');
$i = 0;
foreach ($forums as $forum) {
$forum->subscribe = pieform(array(
'name' => 'subscribe'.$i++,
'successcallback' => 'subscribe_submit',
'elements' => array(
'submit' => array(
'type' => 'submit',
'value' => $forum->subscribed ? get_string('unsubscribe', 'interaction.forum') : get_string('subscribe', 'interaction.forum')
),
'forum' => array(
'type' => 'hidden',
'value' => $forum->id
)
)
));
}
function subscribe_submit(Pieform $form, $values) {
global $USER;
$groupid = param_integer('group');
if ($values['submit'] == get_string('subscribe', 'interaction.forum')) {
insert_record(
'interaction_forum_subscription_forum',
(object)array(
'forum' => $values['forum'],
'user' => $USER->get('id')
)
);
}
else {
delete_records(
'interaction_forum_subscription_forum',
'forum', $values['forum'],
'user', $USER->get('id')
);
delete_records_sql(
'DELETE FROM {interaction_forum_subscription_topic}
WHERE topic IN (
SELECT id
FROM {interaction_forum_topic}
WHERE forum = ?
)',
array($values['forum'])
);
}
redirect('/interaction/forum/index.php?group=' . $groupid);
}
$smarty = smarty();
$smarty->assign('group', $group);
$smarty->assign('admin', $admin);
$smarty->assign('forums', $forums);
$smarty->display('interaction:forum:index.tpl');
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment