Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	application/controllers/admin/questions.php
  • Loading branch information
olleharstedt committed Jul 19, 2018
2 parents 693dabc + 41e32d5 commit 74f610c
Show file tree
Hide file tree
Showing 37 changed files with 457 additions and 339 deletions.
2 changes: 1 addition & 1 deletion application/config/packages.php
Expand Up @@ -145,7 +145,7 @@
'devBaseUrl' => 'assets/packages/adminpanel/',
'basePath' => 'core.adminpanel',
'js' => array(
'build/lsadminpanel'.(($debug > 0) ? '' : '.min').'.js',
'build/lsadminpanel'.(($debug > 0) ? '.debug' : '.min').'.js',
'build/surveysettings'.$minVersion.'.js',
'build/hammer'.$minVersion.'.js'
),
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/database.php
Expand Up @@ -964,7 +964,7 @@ private function actionUpdateSurveyLocaleSettings($iSurveyID)
if (getGlobalSetting('showqnumcode') === 'choose'){
$oSurvey->showqnumcode = $this->_filterEmptyFields($oSurvey, 'showqnumcode');
}
if (getGlobalSetting('shownoanswer') === '2'){
if (getGlobalSetting('shownoanswer') == 2){ // Don't do exact comparison because the value could be from global settings table (string) or from config (integer)
$oSurvey->shownoanswer = $this->_filterEmptyFields($oSurvey, 'shownoanswer');
}
$oSurvey->showwelcome = $this->_filterEmptyFields($oSurvey, 'showwelcome');
Expand Down
4 changes: 4 additions & 0 deletions application/controllers/admin/questions.php
Expand Up @@ -1055,6 +1055,10 @@ public function newquestion($surveyid)
$aViewUrls = [];
$aViewUrls['editQuestion_view'][] = $aData;
App()->getClientScript()->registerScript("EditQuestionView_question_jsviews_".$surveyid.$oQuestion->gid.'new', "OtherSelection('".$oQuestion->type."');", LSYii_ClientScript::POS_POSTSCRIPT);
if(window.questionFunctions) {
window.questionFunctions.OtherSelection('".$eqrow['type']."');
}
", LSYii_ClientScript::POS_POSTSCRIPT);

$this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData);
}
Expand Down
21 changes: 18 additions & 3 deletions application/core/LSYii_ClientScript.php
Expand Up @@ -562,7 +562,6 @@ public function renderBodyEnd(&$output)
$html .= $this->renderScriptBatch($scripts);
}


if ($fullPage) {
$output = preg_replace('/<###end###>/', $html, $output, 1);
} else {
Expand All @@ -579,14 +578,30 @@ public function renderBodyEnd(&$output)
*/
public function render(&$output)
{
/**
* beforeCloseHtml event @see https://manual.limesurvey.org/BeforeCloseHtml
* Set it before all other action allow registerScript by plugin
* Whitelisting available controller (public plugin not happen for PluginsController using actionDirect, actionUnsecure event)
*/
$publicControllers = array('option','optout','printanswers','register','statistics_user','survey','surveys','uploader');
if(Yii::app()->getController() && in_array(Yii::app()->getController()->getId(),$publicControllers) && strpos($output, '</body>')) {
$event = new PluginEvent('beforeCloseHtml');
$surveyId = Yii::app()->getRequest()->getParam('surveyid',Yii::app()->getRequest()->getParam('sid',Yii::app()->getConfig('surveyid')));
$event->set('surveyId', $surveyId); // Set to null if not set by param
App()->getPluginManager()->dispatchEvent($event);
$pluginHtml = $event->get('html');
if (!empty($pluginHtml) && is_string($pluginHtml)) {
$output = preg_replace('/(<\\/body\s*>)/is', "{$pluginHtml}$1", $output, 1);
}
}
if (!$this->hasScripts) {
return;
return;
}

$this->renderCoreScripts();

if (!empty($this->scriptMap)) {
$this->remapScripts();
$this->remapScripts();
}

$this->unifyScripts();
Expand Down
Expand Up @@ -35,7 +35,6 @@ public function run()
}

$this->model->active = null;
$this->model->gsid = null;

// Filter state
if (isset($_GET['active']) && !empty($_GET['active'])){
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/admin/import_helper.php
Expand Up @@ -2865,8 +2865,8 @@ function TSVImportSurvey($sFullFilePath)
}
}
} else {
$insertdata = array();
$scale_id = (isset($row['type/scale']) ? $row['type/scale'] : 0);
$insertdata = array();
$insertdata['sid'] = $iNewSID;
$insertdata['gid'] = $gid;
$insertdata['parent_qid'] = $qid;
Expand All @@ -2891,7 +2891,7 @@ function TSVImportSurvey($sFullFilePath)
}
// Insert sub question and keep the sqid for multi language survey
$question = new Question();
$question->attributes = $insertdata;
$question->setAttributes($insertdata,false); //$question->attributes = $insertdata; : this broke call of $this when test rules when save : PLEASE : don't use
if (!$question->save()) {
$results['error'][] = gT("Error")." : ".gT("Could not insert subquestion").". ".gT("Text file row number ").$rownumber." (".$sqname.")";
break;
Expand Down
4 changes: 0 additions & 4 deletions application/helpers/admin/template_helper.php
Expand Up @@ -132,10 +132,6 @@ function templateExtractFilter($p_event, &$p_header)
$aAllowExtensions = explode(',', Yii::app()->getConfig('allowedthemeuploads'));
$aAllowExtensions[] = 'twig';
$info = pathinfo($p_header['filename']);
// Deny files with multiple extensions in general
if (substr_count($info['basename'], '.') > 1) {
return 0;
}

if ($p_header['folder'] || !isset($info['extension']) || in_array($info['extension'], $aAllowExtensions)) {
return 1;
Expand Down
11 changes: 1 addition & 10 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -10282,16 +10282,7 @@ static public function &TSVSurveyExport($sid)
$row = array();
$row['class'] = 'SQ';
$row['type/scale'] = 0;

$subqName = substr($varName,strlen($rootVarName)+1);
// it breaks TSV survey import process if first character for name is numeric
// in such case, characters 'SQ' are added to the front of name, so validation can pass
if (preg_match('/^\d/', subqName) === 1){
$row['name'] = 'SQ'.subqName;
} else {
$row['name'] = subqName;
}

$row['name'] = substr($varName,strlen($rootVarName)+1);
$row['relevance'] = $SQrelevance;
$row['text'] = $subqText;
$row['language'] = $lang;
Expand Down
6 changes: 3 additions & 3 deletions application/models/Survey.php
Expand Up @@ -1916,12 +1916,12 @@ public static function replacePolicyLink($dataSecurityNoticeLabel, $surveyId) {
if(self::model()->findByPk($surveyId)->showsurveypolicynotice == 2){
$STARTPOLICYLINK = "<a href='#data-security-modal-".$surveyId."' data-toggle='collapse'>";
$ENDPOLICYLINK = "</a>";
if(!preg_match('/(\{STARTPOLICYLINK\}|\{ENDPOLICYLINK\})/', $dataSecurityNoticeLabel)){
$dataSecurityNoticeLabel.= "<br/> {STARTPOLICYLINK}".gT("Show policy")."{ENDPOLICYLINK}";
}
}


if(!preg_match('/(\{STARTPOLICYLINK\}|\{ENDPOLICYLINK\})/', $dataSecurityNoticeLabel)){
$dataSecurityNoticeLabel.= "<br/> {STARTPOLICYLINK}".gT("Show policy")."{ENDPOLICYLINK}";
}

$dataSecurityNoticeLabel = preg_replace('/\{STARTPOLICYLINK\}/', $STARTPOLICYLINK ,$dataSecurityNoticeLabel);

Expand Down
10 changes: 7 additions & 3 deletions application/models/Template.php
Expand Up @@ -312,14 +312,14 @@ public static function getTemplatePath($sTemplateName = "")
* @param boolean $bForceXML the id of the survey.
* @return TemplateConfiguration
*/
public static function getTemplateConfiguration($sTemplateName = null, $iSurveyId = null, $iSurveyGroupId = null, $bForceXML = false)
public static function getTemplateConfiguration($sTemplateName = null, $iSurveyId = null, $iSurveyGroupId = null, $bForceXML = false, $abstractInstance = false)
{

// First we try to get a confifuration row from DB
if (!$bForceXML) {
// The name need to be filtred only for DB version. From TemplateEditor, the template is not installed.
$sTemplateName = (empty($sTemplateName)) ? null : self::templateNameFilter($sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstance($sTemplateName, $iSurveyGroupId, $iSurveyId);
$oTemplateConfigurationModel = TemplateConfiguration::getInstance($sTemplateName, $iSurveyGroupId, $iSurveyId, $abstractInstance);
}


Expand Down Expand Up @@ -480,7 +480,7 @@ public static function isStandardTemplate($sTemplateName)
* @param boolean $bForceXML
* @return TemplateConfiguration
*/
public static function getInstance($sTemplateName = null, $iSurveyId = null, $iSurveyGroupId = null, $bForceXML = null)
public static function getInstance($sTemplateName = null, $iSurveyId = null, $iSurveyGroupId = null, $bForceXML = null, $abstractInstance = false)
{
// The error page from default template can be called when no survey found with a specific ID.
if ($sTemplateName === null && $iSurveyId === null) {
Expand All @@ -495,6 +495,10 @@ public static function getInstance($sTemplateName = null, $iSurveyId = null, $iS
$bForceXML = false;
}
}

if($abstractInstance === true) {
return self::getTemplateConfiguration($sTemplateName, $iSurveyId, $iSurveyGroupId, $bForceXML, true);
}

if (empty(self::$instance)) {
self::$instance = self::getTemplateConfiguration($sTemplateName, $iSurveyId, $iSurveyGroupId, $bForceXML);
Expand Down
55 changes: 34 additions & 21 deletions application/models/TemplateConfiguration.php
Expand Up @@ -151,9 +151,9 @@ public function attributeLabels()
* @param string $sTemplateName
* @return TemplateConfiguration
*/
public static function getInstanceFromTemplateName($sTemplateName)
public static function getInstanceFromTemplateName($sTemplateName, $abstractInstance = false)
{
if (!empty(self::$aInstancesFromTemplateName[$sTemplateName])) {
if (!empty(self::$aInstancesFromTemplateName[$sTemplateName]) && !$abstractInstance) {
return self::$aInstancesFromTemplateName[$sTemplateName];
}

Expand All @@ -167,6 +167,10 @@ public static function getInstanceFromTemplateName($sTemplateName)
$oInstance = self::getInstanceFromTemplateName(getGlobalSetting('defaulttheme'));
}

if($abstractInstance === true) {
return $oInstance;
}

self::$aInstancesFromTemplateName[$sTemplateName] = $oInstance;

return $oInstance;
Expand All @@ -180,7 +184,7 @@ public static function getInstanceFromTemplateName($sTemplateName)
* @param string $sTemplateName
* @return TemplateConfiguration
*/
public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName = null)
public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName = null, $abstractInstance = false)
{
//if a template name is given also check against that
$sTemplateName = $sTemplateName != null ? $sTemplateName : SurveysGroups::model()->findByPk($iSurveyGroupId)->template;
Expand All @@ -194,7 +198,7 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam
// No specific template configuration for this surveygroup => create one
// TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok.
if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName, $abstractInstance);
$oTemplateConfigurationModel->bUseMagicInherit = false;
$oTemplateConfigurationModel->id = null;
$oTemplateConfigurationModel->isNewRecord = true;
Expand All @@ -217,7 +221,7 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam
* @param string $sTemplateName
* @return TemplateConfiguration
*/
public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName = null)
public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName = null, $abstractInstance = false)
{

//if a template name is given also check against that
Expand All @@ -234,7 +238,7 @@ public static function getInstanceFromSurveyId($iSurveyId, $sTemplateName = null
// No specific template configuration for this surveygroup => create one
// TODO: Move to SurveyGroup creation, right now the 'lazy loading' approach is ok.
if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration') && $sTemplateName != null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName, $abstractInstance);
$oTemplateConfigurationModel->bUseMagicInherit = false;
$oTemplateConfigurationModel->id = null;
$oTemplateConfigurationModel->isNewRecord = true;
Expand Down Expand Up @@ -308,21 +312,21 @@ public static function checkAndcreateSurveyConfig($iSurveyId)
* @param integer $iSurveyId
* @return TemplateConfiguration
*/
public static function getInstance($sTemplateName = null, $iSurveyGroupId = null, $iSurveyId = null)
public static function getInstance($sTemplateName = null, $iSurveyGroupId = null, $iSurveyId = null, $abstractInstance = false)
{

$oTemplateConfigurationModel = new TemplateConfiguration();

if ($sTemplateName != null && $iSurveyGroupId == null && $iSurveyId == null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromTemplateName($sTemplateName, $abstractInstance);
}

if ($iSurveyGroupId != null && $iSurveyId == null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName, $abstractInstance);
}

if ($iSurveyId != null) {
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyId($iSurveyId, $sTemplateName);
$oTemplateConfigurationModel = TemplateConfiguration::getInstanceFromSurveyId($iSurveyId, $sTemplateName, $abstractInstance);
}

return $oTemplateConfigurationModel;
Expand Down Expand Up @@ -621,7 +625,7 @@ public function getHasOptionPage()

/**
* Set a value on a given option at global setting level (survey level not affected).
* Will be used to turn ON ajax mode on update.
* Will be used to turn ON ajax mode on update.
*
* @param string $name
* @param mixed $value
Expand All @@ -642,23 +646,23 @@ public function setGlobalOption($name, $value)
}

/**
* Apply options from XML configuration for all missing template options
* Apply options from XML configuration for all missing template options
*
* @return void
*/
public function addOptionFromXMLToLiveTheme()
{
{
if ($this->options != 'inherit') {
$oOptions = get_object_vars(json_decode($this->options));
$oTemplateConfigurationModel = new TemplateManifest;
$oTemplateConfigurationModel->setBasics();
$oXmlOptions = get_object_vars($oTemplateConfigurationModel->config->options);
$oXmlOptions = get_object_vars($oTemplateConfigurationModel->config->options);

// compare template options to options from the XML and add if missing
foreach ($oXmlOptions as $key=>$value){
if (!array_key_exists($key, $oOptions)){
$this->addOptionToLiveTheme($key, $value);
}
}
}
}
}
Expand Down Expand Up @@ -705,7 +709,7 @@ public function setOption($name, $value)

private function _filterImages($file)
{
$imagePath = (file_exists($this->filesPath.$file['name']))
$imagePath = (file_exists($this->filesPath.$file['name']))
? $this->filesPath.'/'.$file['name']
: $this->generalFilesPath.$file['name'] ;

Expand Down Expand Up @@ -736,15 +740,24 @@ protected function getOptionPageAttributes()

public function getOptionPage()
{
$oSimpleInheritance = Template::getInstance($this->template->name, $this->sid, $this->gsid, null, true);
$oSimpleInheritance->options = 'inherit';
$oSimpleInheritanceTemplate = $oSimpleInheritance->prepareTemplateRendering($this->template->name);

$oTemplate = $this->prepareTemplateRendering($this->template->name);

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

$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) $oTemplate->oOptions), array('packages_to_load' => $oTemplate->packages_to_load, 'files_css' => $oTemplate->files_css));
$renderArray['oParentOptions'] = array_merge(
((array) $oSimpleInheritanceTemplate->oOptions),
array('packages_to_load' => $oTemplate->packages_to_load,
'files_css' => $oTemplate->files_css)
);

return Yii::app()->twigRenderer->renderOptionPage($oTemplate, $renderArray);
}
Expand Down Expand Up @@ -1061,7 +1074,7 @@ public function getParentConfiguration()
//check for surveygroup id if a survey is given
if ($this->sid != null) {
$oSurvey = Survey::model()->findByPk($this->sid);
$oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName, null, $oSurvey->gsid);
$oParentTemplate = Template::getTemplateConfiguration($this->template->name, null, $oSurvey->gsid);
if (is_a($oParentTemplate, 'TemplateConfiguration')) {
$this->oParentTemplate = $oParentTemplate;
$this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit;
Expand All @@ -1074,7 +1087,7 @@ public function getParentConfiguration()
$oSurveyGroup = SurveysGroups::model()->findByPk($this->gsid);
//Switch if the surveygroup inherits from a parent surveygroup
if ($oSurveyGroup != null && $oSurveyGroup->parent_id != 0) {
$oParentTemplate = Template::getTemplateConfiguration($this->sTemplateName, null, $oSurveyGroup->parent_id);
$oParentTemplate = Template::getTemplateConfiguration($this->template->name, null, $oSurveyGroup->parent_id);
if (is_a($oParentTemplate, 'TemplateConfiguration')) {
$this->oParentTemplate = $oParentTemplate;
$this->oParentTemplate->bUseMagicInherit = $this->bUseMagicInherit;
Expand Down Expand Up @@ -1173,12 +1186,12 @@ public function getshowpopups(){
$config = (int)Yii::app()->getConfig('showpopups');
if ($config == 2){
if (isset($this->oOptions->showpopups)){
$this->showpopups = (int)$this->oOptions->showpopups;
$this->showpopups = (int)$this->oOptions->showpopups;
} else {
$this->showpopups = 1;
}
} else {
$this->showpopups = $config;
}
}
}
}

0 comments on commit 74f610c

Please sign in to comment.