diff --git a/application/controllers/admin/Themes.php b/application/controllers/admin/Themes.php index e7a852fb62a..2b0ab0a6207 100755 --- a/application/controllers/admin/Themes.php +++ b/application/controllers/admin/Themes.php @@ -174,7 +174,7 @@ public function upload() App()->getController()->forward("/surveyAdministration/uploadimagefile/"); App()->end(); } - $sTemplateName = trim(App()->request->getPost('templatename')); + $sTemplateName = trim(App()->request->getPost('templatename', '')); if (Permission::model()->hasGlobalPermission('templates', 'import') || Permission::model()->hasTemplatePermission($sTemplateName)) { App()->loadHelper('admin/template'); // NB: lid = label id @@ -616,7 +616,7 @@ public function index(string $editfile = '', string $screenname = 'welcome', str public function templatefiledelete() { if (Permission::model()->hasGlobalPermission('templates', 'update')) { - $sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename'))); + $sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename', ''))); $oEditedTemplate = Template::getInstance($sTemplateName); $templatedir = $oEditedTemplate->viewPath; $sPostedFiletype = CHtml::decode(App()->request->getPost('filetype')); @@ -887,7 +887,7 @@ public function templatesavechanges() $action = returnGlobal('action'); $editfile = returnGlobal('editfile'); $relativePathEditfile = returnGlobal('relativePathEditfile'); - $sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename'))); + $sTemplateName = Template::templateNameFilter(trim(App()->request->getPost('templatename', ''))); $screenname = returnGlobal('screenname'); $oEditedTemplate = Template::model()->getTemplateConfiguration($sTemplateName, null, null, true)->prepareTemplateRendering($sTemplateName); diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 660ae376a76..866de956acf 100755 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -982,7 +982,7 @@ public function getOptionPageAttributes() foreach ($fileList as $file) { $imageInfo = $this->getImageInfo($basePath . $file['name'], $pathPrefix); if ($imageInfo) { - $aData['imageFileList'][] = array_merge( + $aData['imageFileList'][$imageInfo['filepath']] = array_merge( [ 'group' => $category->title, ], diff --git a/application/views/themeOptions/options_core.php b/application/views/themeOptions/options_core.php index ab81c154acf..fd1862b4b9d 100644 --- a/application/views/themeOptions/options_core.php +++ b/application/views/themeOptions/options_core.php @@ -6,6 +6,42 @@ "inherited value:" ) . ' ' . (isset($oParentOptions['font']) ? $oParentOptions['font'] : '') . ']' : ''); +/** @var string The html for image file dropdown options */ +$imageOptions = ''; +$optgroup = ''; +foreach ($aTemplateConfiguration['imageFileList'] as $image) { + // If group is different than the previous one, close the previous optgroup and open a new one + if ($image['group'] != $optgroup) { + if ($optgroup != '') { + $imageOptions .= ''; + } + $imageOptions .= ''; + $optgroup = $image['group']; + } + $imageOptions .= ''; +} + +// Add extra info needed for theme options of type "imagefile" (preview path and filename) +foreach ($aOptionAttributes['optionAttributes'] as $attributeName => &$attribute) { + if ($attribute['type'] == 'imagefile') { + if (!isset($oParentOptions[$attributeName])) { + continue; + } + if (isset($aTemplateConfiguration['imageFileList'][$oParentOptions[$attributeName]])) { + $image = $aTemplateConfiguration['imageFileList'][$oParentOptions[$attributeName]]; + $attribute['preview'] = $image['preview']; + $attribute['filename'] = $image['filename']; + } else { + $attribute['preview'] = ''; + $attribute['filename'] = ''; + } + } +} +unset($attribute); + +/** + * @todo: Convert backgroundimagefile and brandlogofile to 'imagefile' type + */ // background file $backgroundImageFile = ''; $backgroundfileInheritPreview = ''; @@ -23,6 +59,7 @@ if (isset($oParentOptions['backgroundimagefile']) && ($oParentOptions['backgroundimagefile'] == $image['filepath'] || $oParentOptions['backgroundimagefile'] == $image['filepathOptions'])) { $backgroundfileInheritPreview = $image['preview']; + $backgroundfileInheritFilename = $image['filename']; } $backgroundImageFile .= ''; @@ -196,6 +233,30 @@ echo $aOptionAttributes['optionAttributes'][$attributeKey]['dropdownoptions']; echo ' '; + } elseif ($attribute['type'] == 'imagefile') { + if (!is_string($sParentOption)) { + // TODO: $aParentOptions is not loaded properly, it seems. + $sParentOption = 'N/A'; + } + echo '
'; + // Fields linked to a parent option (Yes/No switch) need a class and data-parent attribute + if (!empty($attribute['parent'])) { + echo ''; + } + if ($bInherit) { + if (isset($attribute['preview'])) { + $inheritedValue = $attribute['preview']; + } else { + $inheritedValue = isset($sParentOption) ? $sParentOption : ''; + } + echo ''; + } + // Dropdown options for image files + echo $imageOptions; + echo ''; + echo '
'; } elseif ($attribute['type'] == 'icon') { echo '