diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index 15339364fe..f4b63f13b8 100755 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -362,6 +362,67 @@ function handle_stylesheets() } } } + + $logoForm = new FormValidator( + 'logo_upload', + 'post', + 'settings.php?category=Stylesheets#tabs-2' + ); + + $logoForm->addHtml(Display::return_message(sprintf(get_lang('TheLogoMustBeSizeXAndFormatY'), '250 x 70', 'PNG'), 'info')); + + $dir = api_get_path(SYS_PUBLIC_PATH).'css/themes/' . $selected . '/images/'; + $url = api_get_path(WEB_CSS_PATH).'themes/' . $selected . '/images/'; + $logoFileName = 'header-logo.png'; + $newLogoFileName = 'header-logo-custom.png'; + + if (is_file($dir.$newLogoFileName)) { + $logoForm->addLabel(get_lang('CurrentLogo'), ''); + } else { + $logoForm->addLabel(get_lang('CurrentLogo'), ''); + } + + $logoForm->addFile('new_logo', get_lang('UpdateLogo')); + $allowedFileTypes = ['png']; + + if (isset($_POST['logo_reset'])) { + if (is_file($dir.$newLogoFileName)) { + unlink($dir.$newLogoFileName); + Display::display_normal_message(get_lang('ResetToTheOriginalLogo')); + echo ''; + } + } elseif (isset($_POST['logo_upload'])) { + + $logoForm->addRule('new_logo', get_lang('InvalidExtension').' ('.implode(',', $allowedFileTypes).')', 'filetype', $allowedFileTypes); + $logoForm->addRule('new_logo', get_lang('ThisFieldIsRequired'), 'required'); + + if ($logoForm->validate()) { + + $imageInfo = getimagesize($_FILES['new_logo']['tmp_name']); + $width = $imageInfo[0]; + $height = $imageInfo[1]; + if ($width <= 250 && $height <= 70 ) { + if (is_file($dir.$newLogoFileName)) { + unlink($dir.$newLogoFileName); + } + + $status = move_uploaded_file($_FILES['new_logo']['tmp_name'], $dir.$newLogoFileName); + + if ($status) { + Display::display_normal_message(get_lang('NewLogoUpdated')); + echo ''; + } else { + Display::display_error_message('Error - '.get_lang('UplNoFileUploaded')); + } + } else { + Display::display_error_message('Error - '.get_lang('InvalidImageDimensions')); + } + } + } if ($is_style_changeable) { $group = [ @@ -385,6 +446,17 @@ function handle_stylesheets() } else { $form_change->display(); } + + //Little hack to update the logo image in update form when submiting + if (isset($_POST['logo_reset'])) { + echo ''; + } elseif (isset($_POST['logo_upload'])) { + echo ''; + } } else { $form_change->freeze(); } diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index e19fd5cc5c..04f195a098 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -152,33 +152,44 @@ function return_logo($theme) $_course = api_get_course_info(); $html = ''; $logoBase = api_get_path(SYS_CSS_PATH).'themes/'.$theme.'/images/header-logo.'; + $customLogoBase = api_get_path(SYS_PUBLIC_PATH).'css/themes/'.$theme.'/images/header-logo-custom.'; - $site_name = api_get_setting('siteName'); + $siteName = api_get_setting('siteName'); $attributes = array( - 'title' => $site_name, + 'title' => $siteName, 'class' => 'img-responsive', + 'id' => 'header-logo' ); $testServer = api_get_setting('server_type'); if ($testServer == 'test' && is_file($logoBase . 'svg')) { $logo = $logoBase . 'svg'; $attributes['width'] = '245'; $attributes['height'] = '68'; - $image_url = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg'; + $imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.svg'; } else { $logo = $logoBase . 'png'; - $image_url = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png'; + $customLogo = $customLogoBase . 'png'; + $imageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo.png'; + $customImageUrl = api_get_path(WEB_CSS_PATH).'themes/'.$theme.'/images/header-logo-custom.png'; } - - if (file_exists($logo)) { - $site_name = api_get_setting('Institution').' - '.$site_name; + if (file_exists($customLogo)) { + $siteName = api_get_setting('Institution').' - '.$siteName; + $customLogo = Display::img( + $customImageUrl, + $siteName, + $attributes + ); + $html .= Display::url($customLogo, api_get_path(WEB_PATH).'index.php'); + } elseif (file_exists($logo)) { + $siteName = api_get_setting('Institution').' - '.$siteName; $logo = Display::img( - $image_url, - $site_name, + $imageUrl, + $siteName, $attributes ); $html .= Display::url($logo, api_get_path(WEB_PATH).'index.php'); } else { - $html .= ''.$site_name.''; + $html .= ''.$siteName.''; $iurl = api_get_setting('InstitutionUrl'); $iname = api_get_setting('Institution');