Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:LimeSurvey/LimeSurvey into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	application/helpers/questionHelper.php
  • Loading branch information
Shnoulle committed Oct 15, 2018
2 parents 09af20f + f68a451 commit f3f41fa
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 246 deletions.
201 changes: 3 additions & 198 deletions application/controllers/PluginsController.php
Expand Up @@ -7,143 +7,6 @@
class PluginsController extends LSYii_Controller
{

//public $layout = 'main';

/**
* Stored dynamic properties set and unset via __get and __set.
* @var array of mixed.
*/
protected $properties = array();

public function __get($property)
{
return $this->properties[$property];
}

public function __set($property, $value)
{
$this->properties[$property] = $value;
}

public function _init()
{
parent::_init();
Yii::app()->bootstrap->init(); // Make sure bootstrap css is rendered in time
}

/**
* Activates plugin with $id
*
* @param int $id
* @return void
*/
public function actionActivate($id)
{
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT("Access denied!"), 'error');
$this->redirect($this->createUrl("/admin/plugins"));
}
$oPlugin = Plugin::model()->findByPk($id);
if (!is_null($oPlugin)) {
$iStatus = $oPlugin->active;
if ($iStatus == 0) {
// Load the plugin:
App()->getPluginManager()->loadPlugin($oPlugin->name, $id);
$result = App()->getPluginManager()->dispatchEvent(new PluginEvent('beforeActivate', $this), $oPlugin->name);
if ($result->get('success', true)) {
$iStatus = 1;
} else {
$sMessage = $result->get('message', gT('Failed to activate the plugin.'));
App()->user->setFlash('pluginActivation', $sMessage);
$this->redirect(array('plugins/'));
}
}
$oPlugin->active = $iStatus;
$oPlugin->save();
}
$this->redirect(array('plugins/'));
}

/**
* Show configuration for plugin with $id
*
* @param int $id
* @return void
*/
public function actionConfigure($id)
{
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT("Access denied!"), 'error');
$this->redirect($this->createUrl("/admin/plugins"));
}
$arPlugin = Plugin::model()->findByPk($id)->attributes;
$oPluginObject = App()->getPluginManager()->loadPlugin($arPlugin['name'], $arPlugin['id']);

if ($arPlugin === null) {
Yii::app()->user->setFlash('pluginmanager', gT('Plugin not found'));
$this->redirect(array('plugins/'));
}

// If post handle data, yt0 seems to be the submit button
if (App()->request->isPostRequest) {

$aSettings = $oPluginObject->getPluginSettings(false);
$aSave = array();
foreach ($aSettings as $name => $setting) {
$aSave[$name] = App()->request->getPost($name, null);
}
$oPluginObject->saveSettings($aSave);
Yii::app()->user->setFlash('pluginmanager', gT('Settings saved'));
if (App()->request->getPost('redirect')) {
$this->redirect(App()->request->getPost('redirect'), true);
}
}

// Prepare settings to be send to the view.
$aSettings = $oPluginObject->getPluginSettings();
if (empty($aSettings)) {
// And show a message
Yii::app()->user->setFlash('pluginmanager', gT('This plugin has no settings.'));
$this->redirect('plugins/index', true);
}

// Send to view plugin porperties: name and description
$aPluginProp = App()->getPluginManager()->getPluginInfo($arPlugin['name']);

$this->render('/plugins/configure', array('settings' => $aSettings, 'plugin' => $arPlugin, 'properties' => $aPluginProp));
}

/**
* Deactivates plugin with $id
*
* @param int $id
* @return void
*/
public function actionDeactivate($id)
{
if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT("Access denied!"), 'error');
$this->redirect($this->createUrl("/admin/plugins"));
}
$oPlugin = Plugin::model()->findByPk($id);
if (!is_null($oPlugin)) {
$iStatus = $oPlugin->active;
if ($iStatus == 1) {
$result = App()->getPluginManager()->dispatchEvent(new PluginEvent('beforeDeactivate', $this), $oPlugin->name);
if ($result->get('success', true)) {
$iStatus = 0;
} else {
$message = $result->get('message', gT('Failed to deactivate the plugin.'));
App()->user->setFlash('pluginActivation', $message);
$this->redirect(array('plugins/'));
}
}
$oPlugin->active = $iStatus;
$oPlugin->save();
}
$this->redirect(array('plugins/'));
}

/**
* Launch the event newDirectRequest
* @param $plugin : the target
Expand Down Expand Up @@ -194,71 +57,13 @@ public function actionUnsecure($plugin, $function = null)

/**
* Show list of plugins
*
* @deprecated
* @return void
*/
public function actionIndex()
{
if (!Permission::model()->hasGlobalPermission('settings', 'read')) {
Yii::app()->setFlashMessage(gT("Access denied!"), 'error');
$this->redirect($this->createUrl("/admin"));
}

$oPluginManager = App()->getPluginManager();

// Scan the plugins folder.
$aDiscoveredPlugins = $oPluginManager->scanPlugins();
$aInstalledPlugins = $oPluginManager->getInstalledPlugins();
$aInstalledNames = array_map(function($installedPlugin)
{
return $installedPlugin->name;
}, $aInstalledPlugins);

// Install newly discovered plugins.
foreach ($aDiscoveredPlugins as $discoveredPlugin) {
if (!in_array($discoveredPlugin['pluginClass'], $aInstalledNames)) {
$oPlugin = new Plugin();
$oPlugin->name = $discoveredPlugin['pluginClass'];
$oPlugin->active = 0;
$oPlugin->save();
}
}

$aoPlugins = Plugin::model()->findAll();
$data = array();
foreach ($aoPlugins as $oPlugin) {
/* @var $plugin Plugin */
if (array_key_exists($oPlugin->name, $aDiscoveredPlugins)) {
$aPluginSettings = App()->getPluginManager()->loadPlugin($oPlugin->name, $oPlugin->id)->getPluginSettings(false);
$data[] = array(
'id' => $oPlugin->id,
'name' => $aDiscoveredPlugins[$oPlugin->name]['pluginName'],
'description' => $aDiscoveredPlugins[$oPlugin->name]['description'],
'active' => $oPlugin->active,
'settings' => $aPluginSettings,
'new' => !in_array($oPlugin->name, $aInstalledNames)
);
} else {
// This plugin is missing, maybe the files were deleted but the record was not removed from the database
// Now delete this record. Depending on the plugin the settings will be preserved
App()->user->setFlash('pluginDelete'.$oPlugin->id, sprintf(gT("Plugin '%s' was missing and is removed from the database."), $oPlugin->name));
$oPlugin->delete();
}
}
echo $this->render('/plugins/index', compact('data'));
}

/**
* @todo Doc
*/
public function filters()
{
$aFilters = array(
'accessControl'
);
return array_merge(parent::filters(), $aFilters);
// Or shortcut for actionDirect ?
$this->redirect($this->createUrl("admin/pluginmanager/sa/index"));
}

}

?>
5 changes: 4 additions & 1 deletion application/controllers/admin/themeoptions.php
Expand Up @@ -343,7 +343,10 @@ private function _updateCommon(TemplateConfiguration $model, $sid = null)
Yii::app()->clientScript->registerPackage('bootstrap-switch', LSYii_ClientScript::POS_BEGIN);
$aData = array(
'model'=>$model,
'templateOptionPage' => $templateOptionPage
'templateOptionPage' => $templateOptionPage,
'optionInheritedValues' => $oModelWithInheritReplacement->oOptions,
'optionCssFiles' => $oModelWithInheritReplacement->files_css,
'optionCssFramework' => $oModelWithInheritReplacement->cssframework_css
);

if ($sid !== null) {
Expand Down
1 change: 1 addition & 0 deletions application/helpers/questionHelper.php
Expand Up @@ -1607,6 +1607,7 @@ public static function getQuestionThemeAttributeValues($sQuestionThemeName = nul
// Create array of attribute with name as key
foreach($custom_attributes['attribute'] as $customAttribute) {
if(!empty($customAttribute['name'])) {
// inputtype is text by default
$additionalAttributes[$customAttribute['name']] = array_merge($defaultQuestionAttributeValues,$customAttribute);
}
}
Expand Down
19 changes: 15 additions & 4 deletions application/models/TemplateConfiguration.php
Expand Up @@ -437,9 +437,17 @@ public function searchGrid()
$criteria->together = true;
//Don't show surveyspecifi settings on the overview
$criteria->addCondition('t.sid IS NULL');
$criteria->addCondition('t.gsid IS NULL');
$criteria->addCondition('template.name IS NOT NULL');

// check if survey group id is present
$gsid = Yii::app()->request->getQuery('id', null);
if ($gsid !== null){
$criteria->addCondition('t.gsid = ' . $gsid);
} else {
$criteria->addCondition('t.gsid IS NULL');
}


$criteria->compare('id', $this->id);
$criteria->compare('template_name', $this->template_name, true);
$criteria->compare('files_css', $this->files_css, true);
Expand Down Expand Up @@ -828,15 +836,18 @@ public function getOptionPage()

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

$oTemplate->setToInherit();
$oTemplate->setOptions();
$oTemplate->setOptionInheritance();

//We add some extra values to the option page
//This is just a dirty hack, and somewhere in the future we will correct it
$renderArray['oParentOptions'] = array_merge(
((array) $oSimpleInheritanceTemplate->oOptions),
array('packages_to_load' => $oTemplate->packages_to_load,
'files_css' => $oTemplate->files_css)
((array) $oTemplate->oOptions),
array(
'packages_to_load' => $oTemplate->packages_to_load,
'files_css' => $oTemplate->files_css
)
);

return Yii::app()->twigRenderer->renderOptionPage($oTemplate, $renderArray);
Expand Down
5 changes: 5 additions & 0 deletions application/views/admin/themeoptions/update.php
Expand Up @@ -186,6 +186,11 @@
<?php echo $form->hiddenField($model,'gsid'); ?>
<?php echo $form->hiddenField($model,'uid'); ?>

<?php echo CHtml::hiddenField('optionInheritedValues' , json_encode($optionInheritedValues)); ?>
<?php echo CHtml::hiddenField('optionCssFiles' , json_encode($optionCssFiles)); ?>
<?php echo CHtml::hiddenField('optionCssFramework' , json_encode($optionCssFramework)); ?>
<?php echo CHtml::hiddenField('translationInheritedValue' , gT("Inherited value:").' '); ?>

<div class="row">
<div class="form-group">
<?php echo $form->labelEx($model,'files_css'); ?>
Expand Down
25 changes: 24 additions & 1 deletion themes/survey/bootswatch/options/options.js
Expand Up @@ -5,7 +5,9 @@ var prepare = function(){
$('.action_activate_bootstrapswitch').bootstrapSwitch();
var inheritPossible = ($('#general_inherit_active').length > 0 ) ;
//get option Object from Template configuration options
var optionObject = {"general_inherit" : 1}
var optionObject = {"general_inherit" : 1};
var optionObjectInheritedValues = null;
var optionCssFramework = null;
var generalInherit = function(){return $('#TemplateConfiguration_options').val() === 'inherit'; };
var updateFieldSettings = function(){
$('.action_update_options_string_form').find('.selector_option_value_field').each(function(i,item){
Expand All @@ -17,6 +19,18 @@ var prepare = function(){
});
};

optionObjectInheritedValues = JSON.parse($('#optionInheritedValues').val());
optionCssFramework = JSON.parse(JSON.parse($('#optionCssFramework').val())).replace[0];

// display inherited option values in dropdown list
$.each($("#simple_edit_cssframework > option"), function (i, option) {
$.each(optionCssFramework, function (i, item) {
if (option.value == item && $("#simple_edit_cssframework option:first").val() == 'inherit'){
$("#simple_edit_cssframework option:first").text($("#simple_edit_cssframework option:first").text()+' '+option.text+' )');
}
});
});

if(generalInherit()){
$('#general_inherit_on').prop('checked',true).trigger('change').closest('label').addClass('active');
$('.action_hide_on_inherit').addClass('hidden');
Expand Down Expand Up @@ -83,6 +97,15 @@ var prepare = function(){
$(item).prop('checked', true).trigger('change');
$(item).closest('label').addClass('active');
}

// display inherited option values for tooltip
if ($(item).val() == 'inherit'){
var element = $(item).parent();
var elementPrefix = $('#translationInheritedValue').val();
var elementTitle = elementPrefix + optionObjectInheritedValues[$(item).attr('name')];
element.attr('title', elementTitle);
element.tooltip();
}
});

//if the save button is clicked write everything into the template option field and send the form
Expand Down
10 changes: 5 additions & 5 deletions themes/survey/bootswatch/options/options.twig
Expand Up @@ -24,7 +24,7 @@
{% set bootswatchOption = '' %}
{# For surveyspecific settings add an inherit option #}
{% if templateConfiguration.sid is not empty or templateConfiguration.gsid is not empty %}
{% set bootswatchOption = bootswatchOption ~ '<option value = "inherit" > Inherit</option>' %}
{% set bootswatchOption = bootswatchOption ~ '<option value="inherit">'~ gT("Inherit") ~' ( '~ gT("Inherited value:") ~'</option>' %}
{% endif %}
{# List of Bootswatch styles #}
{% set bootswatchOption %}
Expand Down Expand Up @@ -122,7 +122,7 @@
</label>
{# If this is a root template setting, don't show the inherit button #}
{% if templateConfiguration.sid is not empty or templateConfiguration.gsid is not empty %}
<label class="btn btn-default">
<label class="btn btn-default" title="{{ gT("Inherited value:") }} ">
<input name='ajaxmode' type='radio' value='inherit' class='selector_option_radio_field ' data-id='simple_edit_options_ajaxmode'/>
{{ gT("Inherit") }}
</label>
Expand Down Expand Up @@ -152,7 +152,7 @@
</label>
{# If this is a root template setting, don't show the inherit button #}
{% if templateConfiguration.sid is not empty or templateConfiguration.gsid is not empty %}
<label class="btn btn-default" {{ showpopups_disabled }}>
<label class="btn btn-default" title="{{ gT("Inherited value:") }} " {{ showpopups_disabled }}>
<input type='radio' name='showpopups' value='inherit' class='selector_option_radio_field simple_edit_options_showpopups ' data-id='showpopups'/>
{{ gT("Inherit") }}
</label>
Expand Down Expand Up @@ -186,7 +186,7 @@
</label>
{# If this is a root template setting, don't show the inherit button #}
{% if templateConfiguration.sid is not empty or templateConfiguration.gsid is not empty %}
<label class="btn btn-default">
<label class="btn btn-default" title="{{ gT("Inherited value:") }} ">
<input type='radio' name='brandlogo' value='inherit' class='selector_option_radio_field ' data-id='simple_edit_options_brandlogo'/>
{{ gT("Inherit") }}
</label>
Expand All @@ -202,7 +202,7 @@
<div class='col-sm-12'>
<select class='form-control selector_option_value_field selector_radio_childfield selector_image_selector' data-parent="brandlogo" id='simple_edit_options_brandlogofile' name='brandlogofile'>
{% if templateConfiguration.sid is not empty or templateConfiguration.gsid is not empty %}
<option value="inherit">Inherit</option>
<option value="inherit">{{ gT("Inherit") }} ( {{ gT("Inherited value:") }} {{ oParentOptions.brandlogofile }} )</option>
{% endif %}

{% for image in templateConfiguration.imageFileList %}
Expand Down

0 comments on commit f3f41fa

Please sign in to comment.