Commit 4e0132ac authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow a theme to specify that it is only available as a view theme to members...


Allow a theme to specify that it is only available as a view theme to members of institutions for which the theme is the default institution theme
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 064d794d
......@@ -257,6 +257,8 @@ $string['noartefactstochoosefrom'] = 'Sorry, no artefacts to choose from';
$string['access'] = 'Access';
$string['noaccesstoview'] = 'You do not have permission to access this view';
$string['changeviewtheme'] = 'The theme you have chosen for this view is no longer available to you. Please select a different theme.';
// Templates
$string['Template'] = 'Template';
$string['allowcopying'] = 'Allow copying';
......
......@@ -525,9 +525,20 @@ function get_language_root($language=null) {
/**
* Return a list of available themes.
*/
function get_themes() {
function get_themes($all=true) {
static $themes = null;
$institutionthemes = array();
if (!$all) {
global $USER;
$institutions = $USER->get('institutions');
foreach ($institutions as &$i) {
if (!empty($i->theme)) {
$institutionthemes[$i->theme] = 1;
}
}
}
if (is_null($themes)) {
$themes = array();
$themebase = get_config('docroot') . 'theme/';
......@@ -539,10 +550,12 @@ function get_themes() {
$config_path = $themebase . $subdir . '/themeconfig.php';
if (is_readable($config_path)) {
require($config_path);
if ($all || empty($theme->institution_only) || isset($institutionthemes[$subdir])) {
$themes[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
}
}
}
}
closedir($themedir);
}
......
{include file="viewmicroheader.tpl"}
<h1>{$PAGEHEADING}</h1>
<div class="center">
<p>{str tag=changeviewtheme section=view}</p>
<form action="{$formurl}" method="post">
<input type="hidden" id="viewid" name="id" value="{$view}">
<label for="viewtheme-select">{str tag=theme}: </label>
<select id="viewtheme-select" name="viewtheme">
<option value="">Choose theme...</option>
{foreach from=$viewthemes key=themeid item=themename}
<option value="{$themeid|escape}"{if $themeid == $viewtheme} selected="selected" style="font-weight: bold;"{/if}>{$themename|escape}</option>
{/foreach}
</select>
<input type="submit" class="submit" value="{str tag=submit}">
</form>
</div>
{include file="microfooter.tpl"}
......@@ -123,6 +123,7 @@ $extraconfig = array(
// Set up theme
$viewtheme = $view->get('theme');
$allowedthemes = get_themes(false);
if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
......@@ -133,6 +134,20 @@ foreach (array_reverse($THEME->get_url('style/style.css', true, 'artefact/file')
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '">';
}
// Tell the user to change the view theme if the current one is no
// longer available to them.
if (!isset($allowedthemes[$viewtheme])) {
$smarty = smarty(array(), $stylesheets, false, $extraconfig);
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
$smarty->assign('view', $view->get('id'));
$smarty->assign('viewtitle', $view->get('title'));
$smarty->assign('viewtheme', $viewtheme);
$smarty->assign('viewthemes', $allowedthemes);
$smarty->display('view/changetheme.tpl');
exit;
}
$smarty = smarty(array('views', 'tinymce', 'paginator', 'tablerenderer', 'artefact/file/js/filebrowser.js', 'lib/pieforms/static/core/pieforms.js', 'blocktype/creativecommons/js/creativecommons.js'), $stylesheets, false, $extraconfig);
// The list of categories for the tabbed interface
......@@ -174,7 +189,7 @@ $smarty->assign('institution', $institution);
$smarty->assign('can_change_layout', (!$USER->get_account_preference('addremovecolumns') || ($view->get('numcolumns') > 1 && $view->get('numcolumns') < 5)));
$smarty->assign('viewtheme', $viewtheme);
$smarty->assign('viewthemes', get_themes());
$smarty->assign('viewthemes', $allowedthemes);
$smarty->assign('viewid', $view->get('id'));
$smarty->assign('viewtitle', $view->get('title'));
......
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