Commit a185ceed authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I710d6ff7,I7ea50f75,I30ce39b4

* changes:
  Override the header logo with institution logo for members
  Allow institution admin to upload a replacement site logo
  Add logo column to institution table
parents f30ba8b8 5ec1e1ff
......@@ -298,6 +298,19 @@ if ($institution || $add) {
'defaultvalue' => $data->defaultmembershipperiod,
'help' => true,
);
$elements['logo'] = array(
'type' => 'file',
'title' => get_string('Logo', 'admin'),
'description' => get_string('logodescription', 'admin'),
'maxfilesize' => get_max_upload_size(false),
);
if (!empty($data->logo)) {
$logourl = get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $data->logo;
$elements['logohtml'] = array(
'type' => 'html',
'value' => '<img src="' . $logourl . '" alt="' . get_string('Logo', 'admin') . '">',
);
}
$elements['theme'] = array(
'type' => 'select',
'title' => get_string('theme'),
......@@ -461,6 +474,32 @@ function institution_validate(Pieform $form, $values) {
$form->set_error('defaultquota', get_string('maxquotatoolow', 'artefact.file'));
}
}
// Check uploaded logo
if (!empty($values['logo'])) {
require_once('file.php');
require_once('uploadmanager.php');
$um = new upload_manager('logo');
if ($error = $um->preprocess_file()) {
$form->set_error('logo', $error);
return false;
}
$imageinfo = getimagesize($values['logo']['tmp_name']);
if (!$imageinfo || !is_image_type($imageinfo[2])) {
$form->set_error('logo', 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('logo', get_string('profileiconimagetoobig', 'artefact.file', $width, $height, $imagemaxwidth, $imagemaxheight));
}
}
}
function institution_submit(Pieform $form, $values) {
......@@ -472,6 +511,9 @@ function institution_submit(Pieform $form, $values) {
if ($add) {
$institution = $newinstitution->name = strtolower($values['name']);
}
else {
$oldinstitution = get_record('institution', 'name', $institution);
}
$newinstitution->displayname = $values['displayname'];
$newinstitution->authplugin = empty($values['authplugin']) ? null : $values['authplugin'];
......@@ -562,10 +604,49 @@ function institution_submit(Pieform $form, $values) {
else {
$where = new StdClass;
$where->name = $institution;
$oldtheme = get_field('institution', 'theme', 'name', $institution);
update_record('institution', $newinstitution, $where);
}
// Set the logo after updating the institution, because the institution
// needs to exist before it can own the logo artefact.
if ($values['logo']) {
safe_require('artefact', 'file');
// Entry in artefact table
$data = (object) array(
'institution' => $institution,
'title' => 'logo',
'description' => 'Institution logo',
'note' => $values['logo']['name'],
'size' => $values['logo']['size'],
);
$imageinfo = getimagesize($values['logo']['tmp_name']);
$data->width = $imageinfo[0];
$data->height = $imageinfo[1];
$data->filetype = $imageinfo['mime'];
$artefact = new ArtefactTypeProfileIcon(0, $data);
if (preg_match("/\.([^\.]+)$/", $values['logo']['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['logo']['tmp_name'], $directory . $id);
// Delete the old logo
if (!empty($oldinstitution->logo)) {
$oldlogo = new ArtefactTypeProfileIcon($oldinstitution->logo);
$oldlogo->delete();
}
set_field('institution', 'logo', $id, 'name', $institution);
}
delete_records('institution_locked_profile_field', 'name', $institution);
foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) {
if ($values[$field]) {
......@@ -588,8 +669,8 @@ function institution_submit(Pieform $form, $values) {
}
else {
$message = get_string('institutionupdatedsuccessfully', 'admin');
if (isset($values['theme']) && $oldtheme != $values['theme']
&& (!empty($oldtheme) || $values['theme'] != 'sitedefault')) {
if (isset($values['theme']) && $oldinstitution->theme != $values['theme']
&& (!empty($oldinstitution->theme) || $values['theme'] != 'sitedefault')) {
$USER->update_theme();
$message .= ' ' . get_string('usersseenewthemeonlogin', 'admin');
}
......
......@@ -628,6 +628,7 @@ abstract class ArtefactType {
delete_records_select('artefact_access_role', "artefact IN $idstr");
delete_records_select('artefact_access_usr', "artefact IN $idstr");
execute_sql("UPDATE {usr} SET profileicon = NULL WHERE profileicon IN $idstr");
execute_sql("UPDATE {institution} SET logo = NULL WHERE logo IN $idstr");
delete_records_select('artefact', "id IN $idstr");
......
......@@ -86,6 +86,7 @@ class User {
'institutions' => array(),
'grouproles' => array(),
'theme' => null,
'headerlogo' => null,
'admininstitutions' => array(),
'staffinstitutions' => array(),
'parentuser' => null,
......@@ -820,30 +821,43 @@ class User {
$admininstitutions = array();
$staffinstitutions = array();
$this->theme = get_config('theme');
foreach ($institutions as $i) {
$this->headerlogo = null;
$themeinstitution = null;
foreach ($institutions as $name => $i) {
if ($i->admin) {
$admininstitutions[$i->institution] = $i->institution;
}
if ($i->staff) {
$staffinstitutions[$i->institution] = $i->institution;
}
if (!empty($i->theme) && $this->theme == get_config('theme') && $i->theme != $this->theme) {
$this->theme = $i->theme;
if (is_null($themeinstitution)) {
$themeinstitution = $name;
}
}
if ($this->authinstance) {
$authobj = AuthFactory::create($this->authinstance);
if (isset($institutions[$authobj->institution])) {
if ($t = $institutions[$authobj->institution]->theme) {
$this->theme = $t;
if ($institutions[$authobj->institution]->theme) {
$themeinstitution = $authobj->institution;
}
}
}
if (!is_null($themeinstitution)) {
$this->theme = $institutions[$themeinstitution]->theme;
$this->headerlogo = $institutions[$themeinstitution]->logo;
}
$this->institutions = $institutions;
$this->admininstitutions = $admininstitutions;
$this->staffinstitutions = $staffinstitutions;
}
public function get_themedata() {
return (object) array(
'basename' => $this->theme,
'headerlogo' => $this->headerlogo,
);
}
public function reset_grouproles() {
$memberships = get_records_array('group_member', 'member', $this->get('id'));
$roles = array();
......@@ -1310,8 +1324,8 @@ class LiveUser extends User {
public function reset_institutions() {
global $THEME;
parent::reset_institutions();
if (isset($THEME->basename) && $this->theme != $THEME->basename && !defined('INSTALLER')) {
$THEME = new Theme($this->theme);
if (!defined('INSTALLER')) {
$THEME = new Theme($this);
}
}
......
......@@ -671,6 +671,9 @@ $string['defaultmembershipperioddescription'] = 'How long new members remain ass
$string['showonlineusers'] = 'Show online users';
$string['showonlineusersdesc'] = 'The online users to show to members of this institution. With different settings the most permissive institution settings will be used.';
$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.';
$string['authenticatedby'] = 'Authentication Method';
$string['authenticatedbydescription'] = 'How this user authenticates to Mahara';
$string['remoteusername'] = 'Username for external authentication';
......
......@@ -50,6 +50,11 @@
<FIELD NAME="showonlineusers" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="2"/>
<FIELD NAME="allowinstitutionpublicviews" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="registerconfirm" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1"/>
<!-- This field should be foreign keyed to the artefact table, however the
artefact table already has a key to this table, and XMLDB isn't smart enough
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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
......
......@@ -2483,5 +2483,17 @@ function xmldb_core_upgrade($oldversion=0) {
add_key($table, $key);
}
if ($oldversion < 2011070501) {
// Add logo to institution table
$table = new XMLDBTable('institution');
$field = new XMLDBField('logo');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10');
add_field($table, $field);
$key = new XMLDBKey('logofk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('logo'), 'artefact', array('id'));
add_key($table, $key);
}
return $status;
}
......@@ -589,6 +589,11 @@ function core_postinst() {
$key->setAttributes(XMLDB_KEY_FOREIGN, array('profileicon'), 'artefact', array('id'));
add_key($table, $key);
$table = new XMLDBTable('institution');
$key = new XMLDBKey('logofk');
$key->setAttributes(XMLDB_KEY_FOREIGN, array('logo'), 'artefact', array('id'));
add_key($table, $key);
// PostgreSQL supports indexes over functions of columns, MySQL does not.
// We make use if this if we can
if (is_postgres()) {
......
......@@ -1262,7 +1262,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.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo
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;
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011070500;
$config->version = 2011070501;
$config->release = '1.5.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -375,6 +375,7 @@ EOF;
$sitename = 'Mahara';
}
$smarty->assign('sitename', $sitename);
$smarty->assign('sitelogo', $THEME->header_logo());
if (defined('TITLE')) {
$smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
......@@ -567,6 +568,11 @@ class Theme {
*/
public $basename = '';
/**
* A user may have had the header logo overridden by an institution
*/
public $headerlogo;
/**
* A human-readable version of the theme name
*/
......@@ -636,17 +642,21 @@ class Theme {
$themename = $arg;
}
else if ($arg instanceof User) {
$themename = $arg->get('theme');
$themedata = $arg->get_themedata();
}
else if (is_int($arg)) {
$user = new User();
$user->find_by_id($arg);
$themename = $user->get('theme');
$themedata = $user->get_themedata();
}
else {
throw new SystemException("Argument to Theme::__construct was not a theme name, user object or user ID");
}
if (isset($themedata)) {
$themename = $themedata->basename;
}
if (!$themename) {
// Theme to show to when no theme has been suggested
if (!$themename = get_config('theme')) {
......@@ -655,11 +665,11 @@ class Theme {
}
// check the validity of the name
if ($this->name_is_valid($themename)) {
$this->init_theme($themename);
} else {
if (!$this->name_is_valid($themename)) {
throw new SystemException("Theme name is in invalid form: '$themename'");
}
$this->init_theme($themename, $themedata);
}
/**
......@@ -673,7 +683,7 @@ class Theme {
/**
* Given a theme name, reads in all config and sets fields on this object
*/
private function init_theme($themename) {
private function init_theme($themename, $themedata) {
$this->basename = $themename;
$themeconfigfile = get_config('docroot') . 'theme/' . $this->basename . '/themeconfig.php';
......@@ -715,6 +725,10 @@ class Theme {
$this->templatedirs[] = get_config('docroot') . 'theme/' . $currenttheme . '/templates/';
$this->inheritance[] = $currenttheme;
}
if (!empty($themedata->headerlogo)) {
$this->headerlogo = $themedata->headerlogo;
}
}
/**
......@@ -754,6 +768,12 @@ class Theme {
return $returnprefix . $plugindirectory . 'theme/' . $themedir . '/static/' . $filename;
}
public function header_logo() {
if (!empty($this->headerlogo)) {
return get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $this->headerlogo;
}
return $this->get_url('images/site-logo.png');
}
}
......
......@@ -7,7 +7,7 @@
<div id="container">
{if $SITETOP}{$SITETOP|safe}{/if}
<div id="loading-box"></div>
<div id="top-wrapper"><h1 id="site-logo"><a href="{$WWWROOT}"><img src="{theme_url filename='images/site-logo.png'}" alt="{$sitename}"></a></h1>
<div id="top-wrapper"><h1 id="site-logo"><a href="{$WWWROOT}"><img src="{$sitelogo}" alt="{$sitename}"></a></h1>
{include file="header/topright.tpl"}
{if $DROPDOWNMENU}
{include file="header/dropdown.tpl"}
......
......@@ -137,6 +137,24 @@ switch ($type) {
header('Content-type: ' . 'image/png');
readfile_exit($THEME->get_path('images/no_userphoto.png'));
case 'logobyid':
$filedata = get_record('artefact_file_files', 'artefact', param_integer('id'));
if ($path = get_dataroot_image_path('artefact/file/profileicons', $filedata->fileid, get_imagesize_parameters())) {
if ($filedata->filetype) {
header('Content-type: ' . $filedata->filetype);
$maxage = 604800;
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $maxage) .' GMT');
header('Cache-Control: max-age=' . $maxage);
header('Pragma: public');
readfile_exit($path);
}
}
// Nothing found, use the site logo.
header('Content-type: ' . 'image/png');
readfile_exit($THEME->get_path('images/site-logo.png'));
case 'blocktype':
$bt = param_alpha('bt'); // blocktype
$ap = param_alpha('ap', null); // artefact plugin (optional)
......
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