Commit 1f8712d1 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1676214: Added institution small logo upload

behatnotneeded

Change-Id: Ic74144a55e7e3f8e82380b6d5394e258787e0471
parent 0ef6920b
......@@ -401,7 +401,7 @@ if ($institution || $add) {
$elements['logo'] = array(
'type' => 'file',
'title' => get_string('Logo', 'admin'),
'description' => get_string('logodescription', 'admin'),
'description' => get_string('logodescription1', 'admin'),
'maxfilesize' => get_max_upload_size(false),
);
if (!empty($data->logo)) {
......@@ -416,6 +416,27 @@ if ($institution || $add) {
'description' => get_string('deletelogodescription2', 'admin'),
);
}
// logo-xs
$elements['logoxs'] = array(
'type' => 'file',
'title' => get_string('Logosmall', 'admin'),
'description' => get_string('logoxsdescription', 'admin'),
'maxfilesize' => get_max_upload_size(false),
);
if (!empty($data->logoxs)) {
$logoxsurl = get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $data->logoxs;
$elements['logoxshtml'] = array(
'type' => 'html',
'value' => '<img src="' . $logoxsurl . '" alt="' . get_string('Logosmall', 'admin') . '">',
);
$elements['deletelogoxs'] = array(
'type' => 'switchbox',
'title' => get_string('deletelogoxs', 'admin'),
'description' => get_string('deletelogoxsdescription2', 'admin'),
);
}
if (empty($data->name) || $data->name != 'mahara') {
if (!empty($data->style)) {
$customtheme = get_records_menu('style_property', 'style', $data->style, '', 'field,value');
......@@ -731,6 +752,38 @@ function institution_validate(Pieform $form, $values) {
}
}
// Check uploaded small logo
if (!empty($values['logoxs'])) {
require_once('file.php');
require_once('uploadmanager.php');
$um = new upload_manager('logoxs');
if ($error = $um->preprocess_file()) {
$form->set_error('logoxs', $error);
return false;
}
$imageinfo = getimagesize($values['logoxs']['tmp_name']);
if (!$imageinfo || !is_image_type($imageinfo[2])) {
$form->set_error('logoxs', get_string('filenotimage'));
return false;
}
// Check the file isn't greater than the max allowable size
$width = $imageinfo[0];
$height = $imageinfo[1];
$imagemaxwidth = get_config('imagemaxwidth');
$imagemaxheight = get_config('imagemaxheight');
if ($width > $imagemaxwidth || $height > $imagemaxheight) {
$form->set_error('logoxs', get_string('profileiconimagetoobig', 'artefact.file', $width, $height, $imagemaxwidth, $imagemaxheight));
}
else {
$ratio = $width / $height;
if ($ratio != 1) {
$form->set_error('logoxs', get_string('profileiconxsnotsquare', 'artefact.file'));
}
}
}
if (!empty($values['lang']) && $values['lang'] != 'sitedefault' && !array_key_exists($values['lang'], get_languages())) {
$form->set_error('lang', get_string('institutionlanginvalid', 'admin'));
}
......@@ -966,7 +1019,7 @@ function institution_submit(Pieform $form, $values) {
delete_records('style', 'id', $oldinstitution->style);
}
// Set the logo after updating the institution, because the institution
// Set the logos after updating the institution, because the institution
// needs to exist before it can own the logo artefact.
if (!empty($values['logo'])) {
safe_require('artefact', 'file');
......@@ -1010,6 +1063,49 @@ function institution_submit(Pieform $form, $values) {
execute_sql("UPDATE {institution} SET logo = NULL WHERE name = ?", array($institution));
}
//small logo
if (!empty($values['logoxs'])) {
safe_require('artefact', 'file');
// Entry in artefact table
$data = (object) array(
'institution' => $institution,
'title' => 'logoxs',
'description' => 'Institution small logo',
'note' => $values['logoxs']['name'],
'size' => $values['logoxs']['size'],
);
$imageinfo = getimagesize($values['logoxs']['tmp_name']);
$data->width = $imageinfo[0];
$data->height = $imageinfo[1];
$data->filetype = $imageinfo['mime'];
$artefact = new ArtefactTypeProfileIcon(0, $data);
if (preg_match("/\.([^\.]+)$/", $values['logoxs']['name'], $saved)) {
$artefact->set('oldextension', $saved[1]);
}
$artefact->commit();
$id = $artefact->get('id');
// Move the file into the correct place.
$directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . ($id % 256) . '/';
check_dir_exists($directory);
move_uploaded_file($values['logoxs']['tmp_name'], $directory . $id);
// Delete the old small logo
if (!empty($oldinstitution->logoxs)) {
$oldlogo = new ArtefactTypeProfileIcon($oldinstitution->logoxs);
$oldlogo->delete();
}
set_field('institution', 'logoxs', $id, 'name', $institution);
}
if (!empty($values['deletelogoxs'])) {
execute_sql("UPDATE {institution} SET logoxs = NULL WHERE name = ?", array($institution));
}
delete_records('institution_locked_profile_field', 'name', $institution);
foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) {
if ($values[$field]) {
......
......@@ -283,6 +283,7 @@ $string['onlyfiveprofileicons'] = 'You may upload only five profile pictures.';
$string['or'] = 'or';
$string['profileiconuploadexceedsquota'] = 'Uploading this profile picture would exceed your disk quota. Try deleting some files you have uploaded.';
$string['profileiconimagetoobig'] = 'The picture you uploaded was too big (%sx%s pixels). It must not be larger than %sx%s pixels.';
$string['profileiconxsnotsquare'] = 'The picture you uploaded for the small logo does not have the correct dimensions. Please upload a square logo.';
$string['uploadingfile'] = 'uploading file...';
$string['uploadprofileicon'] = 'Upload profile picture';
$string['uploadedprofileicon'] = 'Uploaded profile picture';
......
......@@ -871,6 +871,7 @@ class User {
$staffinstitutions = array();
$themename = get_config('theme');
$headerlogo = null;
$headerlogosmall = null;
$stylesheets = array();
$themeinstitution = null;
foreach ($institutions as $name => $i) {
......@@ -895,6 +896,7 @@ class User {
if (!is_null($themeinstitution)) {
$themename = $institutions[$themeinstitution]->theme;
$headerlogo = $institutions[$themeinstitution]->logo;
$headerlogosmall = $institutions[$themeinstitution]->logoxs;
if ($institutions[$themeinstitution]->style) {
$stylesheet = get_config('wwwroot') . 'style.php?id=' . $institutions[$themeinstitution]->style;
if ($nocachecss) {
......@@ -906,6 +908,7 @@ class User {
$this->institutiontheme = (object) array(
'basename' => $themename,
'headerlogo' => $headerlogo,
'headerlogosmall' => $headerlogosmall,
'stylesheets' => $stylesheets,
'institutionname' => $themeinstitution,
);
......@@ -932,6 +935,7 @@ class User {
return (object) array(
'basename' => $institution->theme,
'headerlogo' => $institution->logo,
'headerlogosmall' => $institution->logoxs,
'stylesheets' => array_unique($stylesheets),
'institutionname' => $iid,
);
......
......@@ -936,9 +936,13 @@ $string['licensedefaultdescription'] = 'The default license for content created
$string['licensedefaultmandatory'] = 'If users are required to choose a license, you need to choose a default license here. If you do not want to choose a default license, do not make it required for users.';
$string['Logo'] = 'Logo';
$string['logodescription'] = 'You can upload an image here that will be displayed to your institution\'s members in place of the standard header logo. For best results, this image should have the same dimensions as the site logo in your institution\'s theme. As each theme can have a different header height, no exact dimensions can be provided.';
$string['Logosmall'] = 'Small logo';
$string['logodescription1'] = 'You can upload an image here that will be displayed to your institution\'s members as logo for your theme. The logo will be resized to fit the space available.';
$string['logoxsdescription'] = 'You can upload a second logo that is to be used on small devices when there is not much space. The logo should be square for best results.';
$string['deletelogo'] = 'Delete logo';
$string['deletelogoxs'] = 'Delete small logo';
$string['deletelogodescription2'] = 'Revert to the standard header logo for your institution\'s theme.';
$string['deletelogoxsdescription2'] = 'Revert to the standard header small logo for your institution\'s theme.';
$string['customtheme'] = 'Custom theme configuration';
$string['customtheme.background'] = 'Header background';
$string['customtheme.backgroundfg'] = 'Text on header background';
......
......@@ -77,6 +77,7 @@
to create the tables first, then the keys. The foreign key will be created
during the postinst phase. -->
<FIELD NAME="logo" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="logoxs" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="style" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="licensemandatory" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="licensedefault" TYPE="char" LENGTH="255" NOTNULL="false"/>
......
......@@ -5005,5 +5005,15 @@ function xmldb_core_upgrade($oldversion=0) {
clear_menu_cache();
}
if ($oldversion < 2017061200) {
log_debug('Add new logoxs column in institution table for small logos');
$table = new XMLDBTable('institution');
$field = new XMLDBField('logoxs');
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_INTEGER, 10);
add_field($table, $field);
}
}
return $status;
}
......@@ -1801,7 +1801,7 @@ function load_user_institutions($userid) {
throw new InvalidArgumentException("couldn't load institutions, no user id specified");
}
if ($institutions = get_records_sql_assoc('
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.displayname,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo, i.style, i.licensemandatory, i.licensedefault, i.dropdownmenu, i.skins, i.suspended
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.displayname,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo, i.logoxs, i.style, i.licensemandatory, i.licensedefault, i.dropdownmenu, i.skins, i.suspended
FROM {usr_institution} u INNER JOIN {institution} i ON u.institution = i.name
WHERE u.usr = ? ORDER BY i.priority DESC', array($userid))) {
return $institutions;
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2017052900;
$config->version = 2017061200;
$config->series = '17.10';
$config->release = '17.10dev';
$config->minupgradefrom = 2012080604;
......
......@@ -628,7 +628,10 @@ EOF;
$smarty->assign('sitelogocustom', $sitelogocustom);
$sitelogo = $THEME->header_logo();
$sitelogo = append_version_number($sitelogo);
$sitelogosmall = $THEME->header_logo_small();
$sitelogosmall = ($sitelogosmall ? append_version_number($sitelogosmall) : null);
$smarty->assign('sitelogo', $sitelogo);
$smarty->assign('sitelogosmall', $sitelogosmall);
$smarty->assign('sitelogo4facebook', $THEME->facebook_logo());
$smarty->assign('sitedescription4facebook', get_string('facebookdescription', 'mahara'));
......@@ -932,6 +935,11 @@ class Theme {
*/
public $headerlogo;
/**
* A user may have had the small header logo added by an institution
*/
public $headerlogosmall;
/**
* Additional stylesheets to display after the basename theme's stylesheets
*/
......@@ -1143,6 +1151,9 @@ class Theme {
if (!empty($themedata->headerlogo)) {
$this->headerlogo = $themedata->headerlogo;
}
if (!empty($themedata->headerlogosmall)) {
$this->headerlogosmall = $themedata->headerlogosmall;
}
if (!empty($themedata->stylesheets)) {
$this->addedstylesheets = $themedata->stylesheets;
}
......@@ -1292,6 +1303,25 @@ class Theme {
return $this->get_image_url('site-logo');
}
/**
* Displaying of the small header logo of an institution
* false will be returned if no small logo for the institution or site small logo is found
*/
public function header_logo_small() {
if (!empty($this->headerlogosmall)) {
return get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $this->headerlogosmall;
}
else {
require_once('ddl.php');
$table = new XMLDBTable('institution');
$field = new XMLDBField('logoxs');
if (field_exists($table, $field) && $sitelogosmallid = get_field('institution', 'logoxs', 'name', 'mahara')) {
return get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $sitelogosmallid;
}
}
return false;
}
public function facebook_logo() {
return $this->get_image_url('site-logo-facebook');
}
......
......@@ -6,6 +6,7 @@
.logo-area,
.logo,
.logoxs,
.admin-title,
.loading-box {
float: left;
......@@ -18,6 +19,27 @@
height: 45px;
}
}
.logo.change-to-small {
img {
@media (max-width: 415px) {
display: none;
}
}
}
.logoxs {
padding: 6px 0;
margin-right: 15px;
img {
display: none;
@media (max-width: 415px) {
display: inherit;
height: 48px;
}
}
}
.admin-title {
@extend .sr-only;
@media (min-width: $screen-sm-min) {
......
......@@ -41,6 +41,22 @@
<header class="header navbar-fixed-top no-site-messages">
<div class="navbar navbar-default navbar-main">
<div class="container">
<div id="logo-area" class="logo-area">
<a href="{$WWWROOT}" class="logo {if $sitelogosmall}change-to-small{/if} ">
<img src="{$sitelogo}" alt="{$sitename}" data-customlogo="{$sitelogocustom}">
</a>
{if $sitelogosmall}
<a href="{$WWWROOT}" class="logoxs">
<img src="{$sitelogosmall}" alt="{$sitename}">
</a>
{/if}
{if $ADMIN || $INSTITUTIONALADMIN || $STAFF || $INSTITUTIONALSTAFF}
<div class="admin-title">
<a href="{$WWWROOT}admin/" accesskey="a" class="admin-site">{str tag="administration"}</a>
</div>
{/if}
<div id="loading-box" class="loading-box" style='display:none'></div>
</div>
<div class="nav-toggle-area">
{if $MAINNAV}
<button class="main-nav-toggle navbar-toggle collapsed" role="button" data-toggle="collapse" data-target=".nav-main" aria-expanded="false" aria-controls="nav-main" title='{str tag="mainmenu"}'>
......@@ -71,17 +87,7 @@
</button>
{/if}
</div>
<div id="logo-area" class="logo-area">
<a href="{$WWWROOT}" class="logo">
<img src="{$sitelogo}" alt="{$sitename}" data-customlogo="{$sitelogocustom}">
</a>
{if $ADMIN || $INSTITUTIONALADMIN || $STAFF || $INSTITUTIONALSTAFF}
<div class="admin-title">
<a href="{$WWWROOT}admin/" accesskey="a" class="admin-site">{str tag="administration"}</a>
</div>
{/if}
<div id="loading-box" class="loading-box" style='display:none'></div>
</div>
{include file="header/topright.tpl"}
{include file="header/navigation.tpl"}
</div>
......
......@@ -6,6 +6,7 @@
.logo-area,
.logo,
.logoxs,
.admin-title,
.loading-box {
float: left;
......@@ -17,6 +18,27 @@
height: 45px;
}
}
.logo.change-to-small {
img {
@media (max-width: 415px) {
display: none;
}
}
}
.logoxs {
padding: 6px 0;
margin-right: 15px;
img {
display: none;
@media (max-width: 415px) {
display: inherit;
height: 48px;
}
}
}
.admin-title {
margin: 15px 10px 5px 0;
@media (max-width: $screen-sm-min - 1) {
......
......@@ -40,6 +40,17 @@
{/if}
<header class="header navbar navbar-default navbar-fixed-top no-site-messages">
<div class="container">
<div id="logo-area" class="logo-area">
<a href="{$WWWROOT}" class="logo {if $sitelogosmall}change-to-small{/if} ">
<img src="{$sitelogo}" alt="{$sitename}">
</a>
{if $sitelogosmall}
<a href="{$WWWROOT}" class="logoxs">
<img src="{$sitelogosmall}" alt="{$sitename}">
</a>
{/if}
<div id="loading-box" class="loading-box" style='display:none'></div>
</div>
{if $MAINNAV}
<!-- Brand and toggle get grouped for better mobile display -->
<button type="button" class="menu-toggle navbar-toggle collapsed" data-toggle="collapse" data-target=".nav-main">
......@@ -55,12 +66,7 @@
<span class="nav-title sr-only">{str tag="showsearch"}</span>
</button>
{/if}
<div id="logo-area" class="logo-area">
<a href="{$WWWROOT}" class="logo">
<img src="{$sitelogo}" alt="{$sitename}">
</a>
<div id="loading-box" class="loading-box" style='display:none'></div>
</div>
{include file="header/topright.tpl"}
</div>
......
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