Commit 81f9f076 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Set GROUP in smarty constructor when GROUP is defined; change some templates to use it

parent 51e9db1f
......@@ -33,11 +33,10 @@ safe_require('artefact', 'file');
$javascript = ArtefactTypeFileBase::get_my_files_js(param_integer('folder', null));
$groupid = param_integer('group');
define('INGROUP', $groupid);
define('GROUP', param_integer('group'));
$group = group_current_group();
if (!group_user_access($groupid)) {
if (!group_user_access($group->id)) {
throw new AccessDeniedException();
}
define('TITLE', $group->name . ' - ' . get_string('groupfiles', 'artefact.file'));
......@@ -45,13 +44,13 @@ define('TITLE', $group->name . ' - ' . get_string('groupfiles', 'artefact.file')
require_once(get_config('docroot') . 'interaction/lib.php');
$groupdata = json_encode($group);
$grouproles = json_encode(array_values(group_get_role_info($groupid)));
$grouproles = json_encode(array_values(group_get_role_info($group->id)));
$javascript .= <<<GROUPJS
var group = {$groupdata};
group.roles = {$grouproles};
browser.setgroup({$groupid});
uploader.setgroup({$groupid});
browser.setgroup({$group->id});
uploader.setgroup({$group->id});
GROUPJS;
$smarty = smarty(
......@@ -60,12 +59,11 @@ $smarty = smarty(
array(),
array(
'sideblocks' => array(
interaction_sideblock($groupid),
interaction_sideblock($group->id),
),
)
);
$smarty->assign('heading', $group->name . ' - ' . get_string('Files', 'artefact.file'));
$smarty->assign('groupid', $groupid);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('artefact:file:index.tpl');
......
......@@ -2,7 +2,7 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
{if $groupid}
{if $GROUP}
<h2>{$heading}</h2>
{elseif $institution}
<h2>{$heading}</h2>
......
......@@ -30,28 +30,28 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('group.php');
require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
define('GROUP', param_integer('group'));
$group = group_current_group();
$userid = param_integer('user');
$newrole = param_alpha('role', null);
define('INGROUP', $groupid);
$group = group_current_group();
if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
throw new UserNotFoundException("Couldn't find user with id $userid");
}
$currentrole = group_user_access($groupid, $userid);
$currentrole = group_user_access($group->id, $userid);
if (!$currentrole) {
throw new UserNotFoundException("Couldn't find user with id $userid in group $groupid");
throw new UserNotFoundException("Couldn't find user with id $userid in group $group->id");
}
$role = group_user_access($groupid);
$role = group_user_access($group->id);
if ($role != 'admin') {
throw new AccessDeniedException();
}
$roles = group_get_role_info($groupid);
$roles = group_get_role_info($group->id);
$rolechange_available = false;
foreach ($roles as &$r) {
$disabled = ($r->role == $currentrole) || (!group_can_change_role($groupid, $userid, $r->role));
$disabled = ($r->role == $currentrole) || (!group_can_change_role($group->id, $userid, $r->role));
if (!$disabled) {
$rolechange_available = true;
}
......@@ -63,7 +63,7 @@ foreach ($roles as &$r) {
if (!$rolechange_available) {
$SESSION->add_info_msg('This user has no roles they can change to');
redirect('/group/members.php?id=' . $groupid);
redirect('/group/members.php?id=' . $group->id);
}
$changeform = pieform(array(
......@@ -100,9 +100,7 @@ function changerole_submit(Pieform $form, $values) {
define('TITLE', $group->name . ' - ' . get_string('changerole', 'group'));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid, $role))));
$smarty->assign('group', $group);
$smarty->assign('groupid', $groupid);
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($group->id, $role))));
$smarty->assign('subtitle', get_string('changeroleofuseringroup', 'group', display_name($user), $group->name));
$smarty->assign('changeform', $changeform);
......
......@@ -31,15 +31,14 @@ require_once('group.php');
require_once('searchlib.php');
require_once(get_config('docroot') . 'interaction/lib.php');
$id = param_integer('id');
define('GROUP', param_integer('id'));
$membershiptype = param_alpha('membershiptype', null);
define('INGROUP', $id);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('Members', 'group'));
$role = group_user_access($id);
$role = group_user_access($group->id);
if (!empty($membershiptype) && $role != 'admin') {
throw new AccessDeniedException();
......@@ -49,13 +48,11 @@ if (!empty($membershiptype) && $role != 'admin') {
$query = trim(param_variable('query', ''));
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($id, $query, $offset, $limit, $membershiptype);
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($group->id, $query, $offset, $limit, $membershiptype);
$smarty = smarty(array('groupmembersearch'), array(), array(), array(
'sideblocks' => array(interaction_sideblock($id, $role)),
'sideblocks' => array(interaction_sideblock($group->id, $role)),
));
$smarty->assign('group', $group);
$smarty->assign('groupid', $id);
$smarty->assign('query', $query);
$smarty->assign('results', $html);
$smarty->assign('pagination', $pagination['html']);
......
......@@ -33,9 +33,7 @@ require_once(get_config('docroot') . 'interaction/lib.php');
require_once(get_config('libroot') . 'view.php');
safe_require('artefact', 'file');
$id = param_integer('id');
define('INGROUP', $id);
define('GROUP', param_integer('id'));
$group = group_current_group();
define('TITLE', $group->name);
......@@ -44,9 +42,9 @@ $group->ctime = strftime(get_string('strftimedate'), $group->ctime);
$group->admins = get_column_sql("SELECT member
FROM {group_member}
WHERE \"group\" = ?
AND role = 'admin'", array($id));
AND role = 'admin'", array($group->id));
$role = group_user_access($id);
$role = group_user_access($group->id);
if ($role) {
if ($role == 'admin') {
$group->membershiptype = 'admin';
......@@ -95,10 +93,10 @@ $foruminfo = get_records_sql_array('
ORDER BY
p.ctime DESC
LIMIT 5;
', array($id));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($id, $role))));
', array($group->id));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($group->id, $role))));
$smarty->assign('group', $group);
$smarty->assign('groupid', $id);
$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));
......
......@@ -48,7 +48,7 @@ else {
$groupid = param_integer('group');
define('TITLE', get_string('addtitle', 'interaction.' . $plugin));
}
define('INGROUP', $groupid);
define('GROUP', $groupid);
safe_require('interaction', $plugin);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
......
......@@ -54,7 +54,7 @@ $post = get_record_sql(
array(0, $postid)
);
define('INGROUP', $post->group);
define('GROUP', $post->group);
if (!$post) {
......
......@@ -78,7 +78,7 @@ if (!$parent) {
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $parentid));
}
define('INGROUP', $parent->group);
define('GROUP', $parent->group);
$breadcrumbs = array(
array(
......
......@@ -33,7 +33,7 @@ require_once('pieforms/pieform.php');
require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
define('INGROUP', $groupid);
define('GROUP', $groupid);
$group = group_current_group();
$membership = group_user_access($groupid);
......
......@@ -47,7 +47,7 @@ $topic = get_record_sql(
array(0, $USER->get('id'), $USER->get('id'), $topicid)
);
define('INGROUP', $topic->groupid);
define('GROUP', $topic->groupid);
if (!$topic) {
throw new NotFoundException(get_string('cantfindtopic', 'interaction.forum', $topicid));
......
......@@ -52,7 +52,7 @@ $forum = get_record_sql(
array(0, $userid, $forumid)
);
define('INGROUP', $forum->groupid);
define('GROUP', $forum->groupid);
if (!$forum) {
throw new InteractionInstanceNotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
......
......@@ -865,10 +865,10 @@ function group_param_userid($userid) {
function group_current_group() {
static $group;
if (defined('INGROUP')) {
$group = get_record_select('group', 'id = ? AND deleted = 0', array(INGROUP), '*, ' . db_format_tsfield('ctime'));
if (defined('GROUP')) {
$group = get_record_select('group', 'id = ? AND deleted = 0', array(GROUP), '*, ' . db_format_tsfield('ctime'));
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', INGROUP));
throw new GroupNotFoundException(get_string('groupnotfound', 'group', GROUP));
}
}
else {
......
......@@ -1800,7 +1800,7 @@ class View {
public static function set_nav($group, $institution) {
if ($group) {
define('MENUITEM', 'groups/views');
define('INGROUP', $group);
define('GROUP', $group);
}
else if ($institution) {
define('INSTITUTIONALADMIN', 1);
......
......@@ -374,8 +374,8 @@ EOF;
$smarty->assign('PAGEHELPNAME', $help[0]);
$smarty->assign('PAGEHELPICON', $help[1]);
}
if (defined('INGROUP')) {
$smarty->assign('INGROUP', INGROUP);
if (defined('GROUP')) {
$smarty->assign('GROUP', group_current_group());
}
// ---------- sideblock stuff ----------
......@@ -1679,7 +1679,7 @@ function main_nav() {
),
);
if (defined('INGROUP')) {
if (defined('GROUP')) {
require_once('group.php');
foreach (group_get_menu_tabs() as $k => $v) {
$menu[] = $v;
......
......@@ -2,7 +2,7 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape}</h2>
<h2>{$GROUP->name|escape}</h2>
<h3>{$subtitle|escape}</h3>
{$changeform}
......
......@@ -2,10 +2,10 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape} - {str tag='Members' section='group'}</h2>
<h2>{$GROUP->name|escape} - {str tag='Members' section='group'}</h2>
<form action="{$WWWROOT}group/members.php" method="post">
<input type="hidden" id="groupid" name="id" value="{$group->id|escape}">
<input type="hidden" id="groupid" name="id" value="{$GROUP->id|escape}">
<div class="searchform center" style="margin-bottom: .5em;">
<label>{str tag='Query' section='admin'}:
<input type="text" name="query" id="query" value="{$query|escape}">
......
......@@ -2,9 +2,9 @@
{include file="sidebar.tpl"}
{include file="columnleftstart.tpl"}
<h2>{$group->name|escape}</h2>
<h2>{$GROUP->name|escape}</h2>
{if $group->description}<p id="group-description">{$group->description}</p> {/if}
{if $GROUP->description}<p id="group-description">{$GROUP->description}</p> {/if}
<ul id="group-info">
<li><strong>{str tag=groupadmins section=group}:</strong> {foreach name=admins from=$group->admins item=id}
......
......@@ -82,10 +82,10 @@
</ul>
</div>
</div>
<div id="subnav"{if $INGROUP} class="group"{/if}>
<div id="subnav"{if $GROUP} class="group"{/if}>
{if $MAINNAVSELECTED.submenu}
<ul>
{if $INGROUP}<li class="groupname">{str tag="Group" section="group"}: </li>{/if}
{if $GROUP}<li class="groupname">{str tag="Group" section="group"}: </li>{/if}
{foreach from=$MAINNAVSELECTED.submenu item=item}<li{if $item.selected} class="selected"{/if}><a href="{$WWWROOT}{$item.url|escape}">{$item.title|escape}</a></li>{/foreach}
</ul>
{/if}
......
......@@ -6,8 +6,8 @@
{$createviewform}
<form method="post" action="{$WWWROOT}view/choosetemplate.php">
<input type="submit" class="submit" value="{str tag="copyaview" section="view"}">
{if $groupid}
<input type="hidden" name="group" value="{$groupid}" />
{if $GROUP}
<input type="hidden" name="group" value="{$GROUP->id}" />
{elseif $institution}
<input type="hidden" name="institution" value="{$institution}">
{/if}
......@@ -89,7 +89,7 @@
{else}
<table id="myviewstable"{if $member} class="groupviews"{/if}>
<tr>
<td>{if $groupid}{str tag="noviewstosee" section="group"}{elseif $institution}{str tag="noviews"}{else}{str tag="noviews" section="view"}{/if}</td>
<td>{if $GROUP}{str tag="noviewstosee" section="group"}{elseif $institution}{str tag="noviews"}{else}{str tag="noviews" section="view"}{/if}</td>
</tr>
</table>
{/if}
......
......@@ -40,23 +40,23 @@ require_once('pieforms/pieform.php');
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$groupid = param_integer('group');
define('INGROUP', $groupid);
define('GROUP', param_integer('group'));
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('groupviews', 'view'));
$member = group_user_access($groupid);
$member = group_user_access($group->id);
$shared = param_boolean('shared', 0) && $member;
$can_edit = group_user_can_edit_views($groupid);
$can_edit = group_user_can_edit_views($group->id);
$smarty = smarty();
$smarty->assign('heading', $group->name . ' - ' . get_string('views'));
if ($can_edit) {
$data = View::get_myviews_data($limit, $offset, $groupid);
$data = View::get_myviews_data($limit, $offset, $group->id);
}
else {
$data = View::view_search(null, $groupid, null, null, $limit, $offset);
$data = View::view_search(null, $group->id, null, null, $limit, $offset);
}
$userid = $USER->get('id');
......@@ -70,13 +70,11 @@ $pagination = build_pagination(array(
'resultcounttextplural' => get_string('views', 'view')
));
$smarty->assign('groupid', $groupid);
$smarty->assign('groupviews', 1);
$smarty->assign('groupname', $group->name);
$smarty->assign('member', $member);
$smarty->assign('views', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('createviewform', pieform(create_view_form($groupid)));
$smarty->assign('createviewform', pieform(create_view_form($group->id)));
if ($can_edit) { // && !$shared) {
$smarty->display('view/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