Commit 0bc935fd authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon

Allow site admins to manage site skins (Bug 1250302)

and allow site pages to use site skins

Change-Id: Idf8a8a761c850ed609f78ed65175ee82c3370e2f
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 4a6903f7
......@@ -4069,14 +4069,24 @@ function escape_css_string($string, $singlequote=true) {
/**
* Indicates whether a particular user can use skins on their pages or not. This is in
* lib/web.php instead of lib/skin.php so that we can use it while generating the main nav.
* @param int $userid The Id of the user to check. Null checks the current user.
* @param bool $managesiteskin = true if admins try to manage the site skin
* @param bool $issiteview = true if admins try to use skins for site views
* @return bool
*/
function can_use_skins($userid = null) {
global $THEME;
function can_use_skins($userid = null, $managesiteskin=false, $issiteview=false) {
global $USER;
if (!get_config('skins')) {
return false;
}
// Site Admins can access site skin
if ($USER->get('admin') && ($managesiteskin || $issiteview)) {
return true;
}
// A user can belong to multiple institutions. If any of their institutions allow it, then
// let them use skins!
$results = get_configs_user_institutions('skins', $userid);
......
......@@ -15,12 +15,13 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once('skin.php');
require_once('pieforms/pieform.php');
if (!can_use_skins()) {
$skinid = param_integer('id');
$siteskin = param_boolean('site', false);
if (!can_use_skins(null, $siteskin)) {
throw new FeatureNotEnabledException();
}
$skinid = param_integer('id');
$siteskin = param_boolean('site', false);
if ($siteskin) {
$goto = 'admin/site/skins.php';
$redirect = '/admin/site/skins.php';
......
......@@ -20,13 +20,13 @@ require_once('skin.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'file');
if (!can_use_skins()) {
$fieldset = param_alpha('fs', 'viewskin');
$designsiteskin = param_boolean('site', false);
if (!can_use_skins(null, $designsiteskin)) {
throw new FeatureNotEnabledException();
}
$fieldset = param_alpha('fs', 'viewskin');
$designsiteskin = param_boolean('site', false);
if ($designsiteskin) {
define('ADMIN', 1);
if (!$USER->get('admin')) {
......@@ -588,7 +588,7 @@ $smarty->display('skin/design.tpl');
function designskinform_validate(Pieform $form, $values) {
global $USER;
if (!$values['viewskin_access'] == 'site') {
if (isset($values['viewskin_access']) && !($values['viewskin_access'] == 'site')) {
$artefactfields = array(
'body_background_image',
'view_background_image'
......@@ -611,7 +611,7 @@ function designskinform_validate(Pieform $form, $values) {
function designskinform_submit(Pieform $form, $values) {
global $USER, $SESSION, $redirect;
$siteskin = ($values['viewskin_access'] == 'site');
$siteskin = (isset($values['viewskin_access']) && ($values['viewskin_access'] == 'site'));
// Only an admin can create a site skin
if ($siteskin && !$USER->get('admin')) {
$values['viewskin_access'] = 'private';
......
......@@ -15,14 +15,13 @@ require_once(dirname(dirname(__FILE__)) . '/init.php');
require_once('skin.php');
require_once(get_config('docroot') . 'artefact/file/lib.php');
if (!can_use_skins()) {
throw new FeatureNotEnabledException();
}
global $USER;
$exportid = param_integer('id', 0); // id(s) of skin(s) to be exported...
$exportsiteskins = param_boolean('site', false);
if (!can_use_skins(null, $exportsiteskins)) {
throw new FeatureNotEnabledException();
}
if ($exportid == 0) {
if ($exportsiteskins) {
// We are exporting site skins...
......
......@@ -22,11 +22,12 @@ require_once('file.php');
require_once('uploadmanager.php');
define('TITLE', get_string('importskins', 'skin'));
if (!can_use_skins()) {
$importsiteskins = param_boolean('site', false);
if (!can_use_skins(null, $importsiteskins)) {
throw new FeatureNotEnabledException();
}
$importsiteskins = param_boolean('site', false);
if ($importsiteskins) {
if (!$USER->get('admin')) {
$SESSION->add_error_msg(get_string('accessforbiddentoadminsection'));
......
......@@ -18,7 +18,7 @@
{str tag=editcontent section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'content'} {str tag=selected}{/if})</span>
</a>
</li>
{if can_use_skins()}
{if can_use_skins(null, false, $issiteview)}
<li {if $selected == 'skin'} class="current-tab"{/if}>
<a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">
{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span>
......
......@@ -2,13 +2,13 @@
{include file="header.tpl"}
<div class="rbuttons">
<form method="post" action="{$WWWROOT}skin/design.php{if $siteskins}?site={$siteskins}{/if}">
<form method="post" action="{$WWWROOT}skin/design.php{if $siteskins}?site=1{/if}">
<input type="submit" class="submit" value="{str tag=createskin section=skin}">
</form>
<form method="post" action="{$WWWROOT}skin/import.php?site={$siteskins}">
<form method="post" action="{$WWWROOT}skin/import.php{if $siteskins}?site=1{/if}">
<input type="submit" class="submit" value="{str tag=importskins section=skin}">
</form>
<form method="post" action="{$WWWROOT}skin/export.php?site={$siteskins}">
<form method="post" action="{$WWWROOT}skin/export.php{if $siteskins}?site=1{/if}">
<input type="submit" class="submit" value="{str tag=exportskins section=skin}">
</form>
</div>
......
......@@ -5,7 +5,7 @@
<h1>{$viewtitle}</h1>
{/if}
{include file="view/editviewtabs.tpl" selected='content' new=$new}
{include file="view/editviewtabs.tpl" selected='content' new=$new issiteview=$issiteview}
<div class="subpage rel cl" id="tabcontent" selected='content'>
<form action="{$formurl}" method="post">
......
......@@ -5,9 +5,9 @@
<h1>{$viewtitle}</h1>
{/if}
{include file="view/editviewtabs.tpl" selected='title' new=$new}
{include file="view/editviewtabs.tpl" selected='title' new=$new issiteview=$issiteview}
<div class="subpage">
{$editview|safe}
{$editview|safe}
</div>
{if $microheaders}{include file="microfooter.tpl"}{else}{include file="footer.tpl"}{/if}
......@@ -3,7 +3,7 @@
{if $edittitle}<li {if $selected == 'title'} class="current-tab"{/if}><a{if $selected == 'title'} class="current-tab"{/if} href="{$WWWROOT}view/edit.php?id={$viewid}{if $new}&new=1{/if}">{str tag=edittitleanddescription section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'title'} {str tag=selected}{/if})</span></a></li>{/if}
<li {if $selected == 'layout'} class="current-tab"{/if}><a{if $selected == 'layout'} class="current-tab"{/if} href="{$WWWROOT}view/layout.php?id={$viewid}{if $new}&new=1{/if}">{str tag=editlayout section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'layout'} {str tag=selected}{/if})</span></a></li>
<li {if $selected == 'content'} class="current-tab"{/if}><a{if $selected == 'content'} class="current-tab"{/if} href="{$WWWROOT}view/blocks.php?id={$viewid}{if $new}&new=1{/if}">{str tag=editcontent section=view}<span class="accessible-hidden">({str tag=tab}{if $selected == 'content'} {str tag=selected}{/if})</span></a></li>
{if can_use_skins()}<li {if $selected == 'skin'} class="current-tab"{/if}><a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span></a></li>{/if}
{if can_use_skins(null, false, $issiteview)}<li {if $selected == 'skin'} class="current-tab"{/if}><a{if $selected == 'skin'} class="current-tab"{/if} href="{$WWWROOT}view/skin.php?id={$viewid}{if $new}&new=1{/if}">{str tag=chooseskin section=skin}<span class="accessible-hidden">({str tag=tab}{if $selected == 'skin'} {str tag=selected}{/if})</span></a></li>{/if}
<li class="displaypage"><a href="{$displaylink}">{str tag=displayview section=view} &raquo;</a></li>
{if $edittitle || $viewtype == 'profile'}<li class="sharepage"><a href="{$WWWROOT}view/access.php?id={$viewid}{if $new}&new=1{/if}">{str tag=shareview section=view} &raquo;</a></li>{/if}
</ul></div>
......@@ -5,9 +5,9 @@
<h1>{$viewtitle}</h1>
{/if}
{include file="view/editviewtabs.tpl" selected='layout' new=$new}
{include file="view/editviewtabs.tpl" selected='layout' new=$new issiteview=$issiteview}
<div class="subpage">
{$form|safe}
{$form|safe}
</div>
{if $microheaders}{include file="microfooter.tpl"}{else}{include file="footer.tpl"}{/if}
......@@ -5,7 +5,7 @@
<h1>{$viewtitle}</h1>
{/if}
{include file="view/editviewtabs.tpl" selected='skin' new=$new}
{include file="view/editviewtabs.tpl" selected='skin' new=$new issiteview=$issiteview}
<div class="subpage">
<div class="rbuttons skinsbtns">
<a class="btn" href="{$WWWROOT}skin/index.php"><span class="btn-config">{str tag=manageskins section=skin}</span></a>
......
......@@ -270,5 +270,6 @@ else {
$columns = $view->build_rows(true);
$smarty->assign('columns', $columns);
}
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
$smarty->display('view/blocks.tpl');
......@@ -234,4 +234,6 @@ if (get_config('viewmicroheaders')) {
$smarty->assign('microheaders', true);
$smarty->assign('microheadertitle', $view->display_title(true, false, false));
}
$smarty->assign('issiteview', isset($institution) && ($institution == 'mahara'));
$smarty->display('view/edit.tpl');
\ No newline at end of file
......@@ -172,6 +172,7 @@ if (get_config('viewmicroheaders')) {
$smarty->assign('microheaders', true);
$smarty->assign('microheadertitle', $view->display_title(true, false));
}
$smarty->assign('issiteview', $view->get('institution') == 'mahara');
$smarty->display('view/layout.tpl');
function viewlayout_validate(Pieform $form, $values) {
......
......@@ -21,7 +21,9 @@ define('TITLE', get_string('chooseviewskin', 'skin'));
$id = param_integer('id');
$new = param_boolean('new');
$view = new View($id);
if (!can_use_skins()) {
$issiteview = $view->get('institution') == 'mahara';
if (!can_use_skins(null, false, $issiteview)) {
throw new FeatureNotEnabledException();
}
$view->set_edit_nav();
......@@ -173,6 +175,7 @@ if (get_config('viewmicroheaders')) {
$smarty->assign('microheaders', true);
$smarty->assign('microheadertitle', $view->display_title(true, false, false));
}
$smarty->assign('issiteview', $issiteview);
$smarty->display('view/skin.tpl');
function viewskin_validate(Pieform $form, $values) {
......
......@@ -194,7 +194,8 @@ $headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('w
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
if ($viewskin && get_config('skins') && can_use_skins($owner) && (!isset($THEME->skins) || $THEME->skins !== false)) {
$issiteview = $view->get('institution') == 'mahara';
if ($viewskin && get_config('skins') && can_use_skins($owner, false, $issiteview) && (!isset($THEME->skins) || $THEME->skins !== false)) {
$skin = array('skinid' => $viewskin, 'viewid' => $view->get('id'));
$skindata = unserialize(get_field('skin', 'viewskin', 'id', $viewskin));
}
......
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