Skip to content

Commit

Permalink
Dev: use getGlobalSetting('defaulttheme') instead of getConfig('defau…
Browse files Browse the repository at this point in the history
…lttheme')
  • Loading branch information
LouisGac committed Dec 21, 2017
1 parent 3c5e094 commit 0ba6d96
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 60 deletions.
4 changes: 2 additions & 2 deletions application/controllers/SurveysController.php 100644 → 100755
Expand Up @@ -27,7 +27,7 @@ public function actionPublicList($lang = null)
}


$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttheme"));
$oTemplate = Template::model()->getInstance(getGlobalSetting('defaulttheme'));
$this->sTemplate = $oTemplate->sTemplateName;

$aData = array(
Expand Down Expand Up @@ -60,7 +60,7 @@ public function actionPublicList($lang = null)
*/
public function actionError()
{
$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttheme"));
$oTemplate = Template::model()->getInstance(getGlobalSetting('defaulttheme'));

$this->sTemplate = $oTemplate->sTemplateName;

Expand Down
14 changes: 7 additions & 7 deletions application/controllers/admin/themes.php 100644 → 100755
Expand Up @@ -367,14 +367,14 @@ protected function _strip_ext($name)
public function index($editfile = '', $screenname = 'welcome', $templatename = '')
{
if ($templatename == '') {
$templatename = Yii::app()->getConfig("defaulttheme");
$templatename = getGlobalSetting('defaulttheme');
}

// This can happen if the global default template is deleted
if (!Template::checkIfTemplateExists($templatename)) {
// Redirect to the default template
Yii::app()->setFlashMessage(sprintf(gT('Theme %s does not exist.'), htmlspecialchars($templatename, ENT_QUOTES)), 'error');
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=> Yii::app()->getConfig("defaulttheme")));
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=> getGlobalSetting('defaulttheme')));
}

/* Keep Bootstrap Package clean after loading template : because template can update boostrap */
Expand All @@ -384,7 +384,7 @@ public function index($editfile = '', $screenname = 'welcome', $templatename = '
$aViewUrls = $this->_initialise($templatename, $screenname, $editfile, true, true);
} catch (Exception $ex) {
Yii::app()->user->setFlash('error', $ex->getMessage());
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=>Yii::app()->getConfig("defaulttheme")));
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=>getGlobalSetting('defaulttheme')));
}

App()->getClientScript()->reset();
Expand Down Expand Up @@ -550,14 +550,14 @@ public function delete($templatename)
$surveys = Survey::model()->findAllByAttributes(array('template' => $templatename));

// The default template could be the same as the one we're trying to remove
$globalDefaultIsGettingDeleted = Yii::app()->getConfig('defaulttheme') == $templatename;
$globalDefaultIsGettingDeleted = getGlobalSetting('defaulttheme') == $templatename;

if ($globalDefaultIsGettingDeleted) {
setGlobalSetting('defaulttheme', Yii::app()->getConfig("defaulttheme"));
setGlobalSetting('defaulttheme', getGlobalSetting('defaulttheme'));
}

foreach ($surveys as $s) {
$s->template = Yii::app()->getConfig('defaulttheme');
$s->template = getGlobalSetting('defaulttheme');
$s->save();
}

Expand Down Expand Up @@ -861,7 +861,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma
}
$aAllTemplates = getTemplateList();
if (!isset($aAllTemplates[$templatename])) {
$templatename = Yii::app()->getConfig('defaulttheme');
$templatename = getGlobalSetting('defaulttheme');
}

$normalfiles = array("DUMMYENTRY", ".", "..", "preview.png");
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/useraction.php 100644 → 100755
Expand Up @@ -116,7 +116,7 @@ public function adduser()
$new_email = $event->get('newEmail');
$new_full_name = $event->get('newFullName');
// add default template to template rights for user
Permission::model()->insertSomeRecords(array('uid' => $iNewUID, 'permission' => Yii::app()->getConfig("defaulttheme"), 'entity'=>'template', 'read_p' => 1, 'entity_id'=>0));
Permission::model()->insertSomeRecords(array('uid' => $iNewUID, 'permission' => getGlobalSetting('defaulttheme'), 'entity'=>'template', 'read_p' => 1, 'entity_id'=>0));
// add new user to userlist
$sresult = User::model()->getAllRecords(array('uid' => $iNewUID));
$srow = count($sresult);
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/replacements_helper.php 100644 → 100755
Expand Up @@ -98,7 +98,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
if (isset($thissurvey['templatedir'])) {
$templatename = $thissurvey['templatedir'];
} else {
$templatename = Yii::app()->getConfig('defaulttheme');
$templatename = getGlobalSetting('defaulttheme');
}
if (!isset($templateurl)) {
$templateurl = getTemplateURL($templatename)."/";
Expand Down
16 changes: 8 additions & 8 deletions application/models/Survey.php 100644 → 100755
Expand Up @@ -183,7 +183,7 @@ public function init()
}


$this->template = Template::templateNameFilter(Yii::app()->getConfig('defaulttheme'));
$this->template = Template::templateNameFilter(getGlobalSetting('defaulttheme'));
$validator = new LSYii_Validators;
$this->language = $validator->languageFilter(Yii::app()->getConfig('defaultlang'));
$this->attachEventHandler("onAfterFind", array($this, 'fixSurveyAttribute'));
Expand Down Expand Up @@ -224,7 +224,7 @@ public function getCurrentLanguageSettings()
* - the selected language via URL (GET then Session)
* - the survey default language
*
* @return string the correct language
* @return string the correct language
*/
public function getLanguageForSurveyTaking()
{
Expand Down Expand Up @@ -420,10 +420,10 @@ public function filterTemplateSave($sTemplateName)
$oSurvey = self::model()->findByPk($this->sid);
if ($oSurvey->template != $sTemplateName) {
// No need to test !is_null($oSurvey)
$sTemplateName = Yii::app()->getConfig('defaulttheme');
$sTemplateName = getGlobalSetting('defaulttheme');
}
} else {
$sTemplateName = Yii::app()->getConfig('defaulttheme');
$sTemplateName = getGlobalSetting('defaulttheme');
}
}
return Template::templateNameFilter($sTemplateName);
Expand Down Expand Up @@ -669,13 +669,13 @@ private function _createSurveymenuArray($oSurveyMenuObjects)
$aEntry = $menuEntry->attributes;
//Skip menu if no permission
if (
(!empty($entry['permission']) && !empty($entry['permission_grade'])
(!empty($entry['permission']) && !empty($entry['permission_grade'])
&& !Permission::model()->hasSurveyPermission($this->sid, $entry['permission'], $entry['permission_grade']))
) {continue; }
//parse the render part of the data attribute
$oDataAttribute = new SurveymenuEntryData();
$oDataAttribute->apply($menuEntry, $this->sid);

if ($oDataAttribute->isActive !== null) {
if (($oDataAttribute->isActive == true && $this->active == 'N') || ($oDataAttribute->isActive == false && $this->active == 'Y')) {
continue;
Expand Down Expand Up @@ -1467,8 +1467,8 @@ public function search()
$criteria->compare('owner.users_name', $this->searched_value, true, 'OR');
$criteria->compare('correct_relation_defaultlanguage.surveyls_title', $this->searched_value, true, 'OR');
$criteria->compare('surveygroup.title', $this->searched_value, true, 'OR');


$criteria->compare('t.gsid', [$this->gsid], false, 'AND');


Expand Down
27 changes: 2 additions & 25 deletions application/models/Template.php
Expand Up @@ -420,7 +420,7 @@ public static function getInstance($sTemplateName = null, $iSurveyId = null, $iS
{
// The error page from default template can be called when no survey found with a specific ID.
if ($sTemplateName === null && $iSurveyId === null) {
$sTemplateName = Yii::app()->getConfig('defaulttheme');
$sTemplateName = getGlobalSetting('defaulttheme');
}

if ($bForceXML === null) {
Expand Down Expand Up @@ -449,31 +449,8 @@ public static function getInstance($sTemplateName = null, $iSurveyId = null, $iS
public static function getStandardTemplateList()
{

$standardTemplates = array(Yii::app()->getConfig('defaulttheme'), 'vanilla', 'material', 'no_bootstrap', 'bootswatch', 'fruity', 'embedded');
$standardTemplates = array(getGlobalSetting('defaulttheme'), 'vanilla', 'material', 'no_bootstrap', 'bootswatch', 'fruity', 'embedded');
return $standardTemplates;

/*
$standardTemplates=self::$standardTemplates;
if(empty($standardTemplates)){
$standardTemplates = array();
$sStandardTemplateRootDir=Yii::app()->getConfig("standardthemerootdir");
if ($sStandardTemplateRootDir && $handle = opendir($sStandardTemplateRootDir)) {
while (false !== ($sFileName = readdir($handle))) {
// Maybe $file[0] != "." to hide Linux hidden directory
if (!is_file("$sStandardTemplateRootDir/$sFileName") && $sFileName[0] != "." && file_exists("{$sStandardTemplateRootDir}/{$sFileName}/config.xml")) {
$standardTemplates[$sFileName] = $sFileName;
}
}
closedir($handle);
}
ksort($standardTemplates);
if(!in_array(Yii::app()->getConfig('defaulttheme'),$standardTemplates)){
throw new Exception('There are no default template in stantard template root dir.');
}
self::$standardTemplates = $standardTemplates;
}
*/
// return self::$standardTemplates;
}


Expand Down
8 changes: 4 additions & 4 deletions application/models/TemplateConfiguration.php
Expand Up @@ -159,7 +159,7 @@ public static function getInstanceFromTemplateName($sTemplateName)

// If the survey configuration table of the wanted template doesn't exist (eg: manually deleted), then we provide the default one.
if (!is_a($oInstance, 'TemplateConfiguration')) {
$oInstance = self::getInstanceFromTemplateName(Yii::app()->getConfig('defaulttheme'));
$oInstance = self::getInstanceFromTemplateName(getGlobalSetting('defaulttheme'));
}

return $oInstance;
Expand Down Expand Up @@ -490,7 +490,7 @@ class="btn btn-danger">
} else {
$sButtons = $sEditorLink.'<br><br>'.$OptionLink;

if ($this->template_name != Yii::app()->getConfig('defaulttheme')) {
if ($this->template_name != getGlobalSetting('defaulttheme')) {
$sButtons .= '<br><br>'.$sUninstallLink;
}
}
Expand Down Expand Up @@ -550,10 +550,10 @@ public function getOptionPage()
$this->prepareTemplateRendering();

$renderArray = array('templateConfiguration' => $this->getOptionPageAttributes());

$this->setOptions();
$this->setOptionInheritance();

$renderArray['oParentOptions'] = (array) $this->oOptions;

return Yii::app()->twigRenderer->renderOptionPage($this, $renderArray);
Expand Down
4 changes: 2 additions & 2 deletions application/models/TemplateManifest.php 100644 → 100755
Expand Up @@ -580,7 +580,7 @@ private function setPath()
// If the template directory doesn't exist, we just set Default as the template to use
// TODO: create a method "setToDefault"
if (!is_dir($this->path)) {
$this->sTemplateName = Yii::app()->getConfig('defaulttheme');
$this->sTemplateName = getGlobalSetting('defaulttheme');
$this->isStandard = true;
$this->path = Yii::app()->getConfig("standardthemerootdir").DIRECTORY_SEPARATOR.$this->sTemplateName.DIRECTORY_SEPARATOR;
if (!$this->iSurveyId) {
Expand Down Expand Up @@ -613,7 +613,7 @@ private function setTemplateName($sTemplateName = '', $iSurveyId = '')
// If it is called for survey taking, a survey id will be provided
if ($sTemplateName == '' && $iSurveyId == '') {
/* Some controller didn't test completely survey id (PrintAnswersController for example), then set to default here */
$sTemplateName = Yii::app()->getConfig('defaulttheme');
$sTemplateName = getGlobalSetting('defaulttheme');
}

$this->sTemplateName = $sTemplateName;
Expand Down
2 changes: 1 addition & 1 deletion application/views/admin/survey/printablesurvey_view.php 100644 → 100755
@@ -1,6 +1,6 @@
<?php

echo '<link rel="stylesheet" type="text/css" href="' . getTemplateURL(Yii::app()->getConfig('defaulttheme')) . '/print_template.css" />';
echo '<link rel="stylesheet" type="text/css" href="' . getTemplateURL(getGlobalSetting('defaulttheme')) . '/print_template.css" />';

echo $surveydesc . "<br />";
echo $welcome . "<br /><br />";
Expand Down
18 changes: 9 additions & 9 deletions application/views/admin/survey/subview/accordion/_generaloptions_panel.php 100644 → 100755
Expand Up @@ -13,9 +13,9 @@
var sAdminEmailAddressNeeded = '".gT("If you are using token functions or notifications emails you need to set an administrator email address.",'js')."'
var sURLParameters = '';
var sAddParam = '';
";
Yii::app()->getClientScript()->registerScript(
"GeneralOption-variables",
";
Yii::app()->getClientScript()->registerScript(
"GeneralOption-variables",
$scriptVarsNeccessary,
LSYii_ClientScript::POS_BEGIN
);
Expand All @@ -34,15 +34,15 @@
return false;
}
});
function ConfirmLanguageChange(confirmtxt) {
if ($('#oldlanguages').val().trim()=='') {
mylangs= [];
} else {
mylangs=$('#oldlanguages').val().split(' ');
}
if (checkSelect2Languages(mylangs)) {
return true;
} else {
Expand Down Expand Up @@ -272,20 +272,20 @@ function checkSelect2Languages(mylangs) {
</div>
</div>
<!-- Template -->

<div class="form-group">
<label class=" control-label" for='template'><?php eT("Template:"); ?></label>
<div class="">
<select id='template' class="form-control" name='template' data-updateurl='<?php echo App()->createUrl('/admin/themeoptions/sa/getpreviewtag') ?>'>
<?php
<?php
$aTemplateList = Template::getTemplateListWithPreviews();
foreach ($aTemplateList as $templateName => $preview) {

if (Permission::model()->hasGlobalPermission('templates','read') || hasTemplateManageRights(Yii::app()->session["loginID"], $tname) == 1 || $oSurvey->template==htmlspecialchars($tname) ) { ?>
<option value='<?php echo $templateName; ?>'
<?php if ($oSurvey->template && htmlspecialchars($templateName) == $oSurvey->template) { ?>
selected='selected'
<?php } elseif (!$oSurvey->template && $templateName == Yii::app()->getConfig('defaulttheme')) { ?>
<?php } elseif (!$oSurvey->template && $templateName == getGlobalSetting('defaulttheme')) { ?>
selected='selected'
<?php } ?>
><?php echo $templateName; ?></option>
Expand Down

0 comments on commit 0ba6d96

Please sign in to comment.