diff --git a/application/models/Template.php b/application/models/Template.php index 97417b5e503..e5376e5e53a 100755 --- a/application/models/Template.php +++ b/application/models/Template.php @@ -156,7 +156,7 @@ public static function templateNameFilter($sTemplateName) /* Validate if template is OK in user dir, DIRECTORY_SEPARATOR not needed "/" is OK */ $oTemplate = self::model()->findByPk($sTemplateName); - if (is_object($oTemplate) && (self::checkTemplateXML($oTemplate->folder))) { + if ($oTemplate->checkTemplate() && (self::checkTemplateXML($oTemplate->folder))) { self::$aNamesFiltered[$sTemplateName] = $sTemplateName; return self::$aNamesFiltered[$sTemplateName]; } @@ -168,7 +168,15 @@ public static function templateNameFilter($sTemplateName) /* If we're here, then the default survey theme is not installed and must be changed */ $aTemplateList = self::model()->search()->getData(); - $sTemplateName = $aTemplateList[0]->name; + $i = 0; + while ($sTemplateName == $sRequestedTemplate) { + if (!empty($aTemplateList[$i])) { + $sTemplateName = $aTemplateList[$i]->name; + } else { + throw new Exception('Could not find a working installed template'); + } + $i++; + } if (!empty($sTemplateName)) { setGlobalSetting('defaulttheme', $sTemplateName); @@ -181,6 +189,39 @@ public static function templateNameFilter($sTemplateName) } } + /** + * @return boolean + * @throws Exception if extended template is not installed. + */ + public function checkTemplate() + { + // Check that extended template is installed. + $this->checkTemplateExtends(); + + return true; + } + + /** + * Returns false if any of the extended templates are not installed; otherwise true. + * @return boolean + * @throws Exception if extended template is not installed. + */ + public function checkTemplateExtends() + { + if (!empty($this->extends)) { + $oRTemplate = self::model()->findByPk($this->extends); + if (empty($oRTemplate)) { + throw new Exception( + sprintf( + 'Extended template "%s" is not installed.', + $this->extends + ) + ); + } + } + return true; + } + /** * Check if a given Template has a valid XML File * @TODO: check api version diff --git a/application/models/TemplateConfiguration.php b/application/models/TemplateConfiguration.php index 8bc39c3fe67..4d8aea3074e 100755 --- a/application/models/TemplateConfiguration.php +++ b/application/models/TemplateConfiguration.php @@ -523,6 +523,7 @@ class='btn btn-default btn-block'> // + $OptionLink = ''; if ($this->hasOptionPage) { @@ -535,7 +536,6 @@ class='btn btn-default btn-block'> "; } - $sUninstallLink = 'prepareTemplateRendering($this->template->name); + $filteredName = Template::templateNameFilter($this->template->name); + $oRTemplate = $this->prepareTemplateRendering($filteredName); $sOptionFile = 'options'.DIRECTORY_SEPARATOR.'options.twig'; while (!file_exists($oRTemplate->path.$sOptionFile)) {