Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jul 4, 2018
2 parents 816ee1f + 3f3a63b commit c46ccd5
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 35 deletions.
4 changes: 3 additions & 1 deletion application/config/config-defaults.php
Expand Up @@ -94,7 +94,9 @@
$config['memory_limit'] = '256'; // This sets how much memory LimeSurvey can access in megabytes. 256 MB is the minimum recommended - if you are using PDF functions up to 512 MB may be needed

$config['showpopups'] = 1; // Show popup messages if mandatory or conditional questions have not been answered correctly.
// 1=Show popup message, 0=Show message on page instead.
// 1 = Show popup message (default)
// 0 = Show message on page instead;
// -1 = Do not show the message at all (in this case, users will still see the question-specific tips indicating which questions must be answered).

$config['maxemails'] = 50; // The maximum number of emails to send in one go (this is to prevent your mail server or script from timeouting when sending mass mail)

Expand Down
54 changes: 50 additions & 4 deletions application/controllers/admin/themes.php
Expand Up @@ -75,7 +75,6 @@ public function templatezip($templatename)
}
}


/**
* Exports a deprecated template
*
Expand All @@ -89,10 +88,39 @@ public function deprecatedtemplatezip($templatename)
$templatename = sanitize_dirname($templatename);
$usertemplaterootdir = Yii::app()->getConfig("uploaddir").DIRECTORY_SEPARATOR."templates";
$templatePath = $usertemplaterootdir.DIRECTORY_SEPARATOR.$templatename;
$this->folderzip($templatename, $templatePath);
}

/**
* Exports a broken theme
*
* @access public
* @param string $templatename
* @return void
*/
public function brokentemplatezip($templatename)
{
//$oEditedTemplate = Template::model()->getTemplateConfiguration($templatename);
$templatename = sanitize_dirname($templatename);
$templatePath = Yii::app()->getConfig("userthemerootdir").DIRECTORY_SEPARATOR.$templatename;
$this->folderzip($templatename, $templatePath);
}

/**
* Exports a theme folder
* NOTE: This function must remain private !!! it doesn't sanitize the $templatePath
* This should be done by the proxy function (eg: deprecatedtemplatezip(), brokentemplatezip() )
*
* @access public
* @param string $templatename
* @return void
*/
private function folderzip($templatename, $templatePath)
{

if (!Permission::model()->hasGlobalPermission('templates','export')){
die('No permission');
Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error');
$this->getController()->redirect(array("admin/themeoptions"));
}

$tempdir = Yii::app()->getConfig('tempdir');
Expand All @@ -116,8 +144,8 @@ public function deprecatedtemplatezip($templatename)
// Delete the temporary file
unlink($zipfile);
}
}

}

/**
* Retrieves a temporary template file from disk
Expand Down Expand Up @@ -616,10 +644,28 @@ public function delete($templatename)
} else {
Yii::app()->setFlashMessage(gT("We are sorry but you don't have permissions to do this."), 'error');
}


// Redirect with default templatename, editfile and screenname
$this->getController()->redirect(array("admin/themeoptions"));
}

public function deleteBrokenTheme($templatename)
{
// First we check that the theme is really broken
$aBrokenThemes = Template::getBrokenThemes();
$templatename = sanitize_dirname($templatename);
if (array_key_exists($templatename, $aBrokenThemes)) {
if (rmdirr(Yii::app()->getConfig('userthemerootdir')."/".$templatename)){
Yii::app()->setFlashMessage(sprintf(gT("Theme '%s' was successfully deleted."), $templatename));
}
}else{
Yii::app()->setFlashMessage(gT("Not a broken theme!"), 'error');
}

$this->getController()->redirect(array("admin/themeoptions"));
}

/**
* Function responsible to save the changes made in CodemMirror editor.
*
Expand Down Expand Up @@ -1185,7 +1231,7 @@ protected function _initialise($templatename, $screenname, $editfile, $showsumma

$thissurvey['include_content'] = $sContentFile;


try {
$myoutput = Yii::app()->twigRenderer->renderTemplateForTemplateEditor(
$sLayoutFile,
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -391,8 +391,8 @@ public function run($surveyid, $args)

$bShowpopups = Yii::app()->getConfig('showpopups');
$aErrorHtmlMessage = $this->getErrorHtmlMessage();
$this->aSurveyInfo['errorHtml']['show'] = !empty($aErrorHtmlMessage);
$this->aSurveyInfo['errorHtml']['hiddenClass'] = $bShowpopups ? "ls-js-hidden " : "";
$this->aSurveyInfo['errorHtml']['show'] = !empty($aErrorHtmlMessage) && $bShowpopups==0;
$this->aSurveyInfo['errorHtml']['hiddenClass'] = $bShowpopups==1 ? "ls-js-hidden " : "";
$this->aSurveyInfo['errorHtml']['messages'] = $aErrorHtmlMessage;

$_gseq = -1;
Expand Down Expand Up @@ -1420,7 +1420,7 @@ private function getErrorHtmlMessage()
}

// Question(s) with not valid answer(s)
if ($this->aStepInfo['valid'] && $this->okToShowErrors) {
if (!$this->aStepInfo['valid'] && $this->okToShowErrors) {
$aErrorsMandatory[] = gT("One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid.");
}

Expand Down
39 changes: 20 additions & 19 deletions application/models/Assessment.php
Expand Up @@ -92,30 +92,31 @@ public function getButtons()
{
$buttons = "<div style='white-space: nowrap'>";
$raw_button_template = ""
. "<button class='btn btn-default btn-xs %s %s' role='button' data-toggle='tooltip' title='%s' onclick='return false;'>" //extra class //title
. "<i class='fa fa-%s' ></i>" //icon class
. "<button class='btn btn-default btn-xs %s %s' role='button' title='%s' type='button'>" //extra class //title
. "<i class='fa fa-%s' aria-hidden='true' ></i><span class='sr-only'>%s</span>" //icon class
. "</button>";
if (Permission::model()->hasGlobalPermission('assessments', 'update')) {
$editData = array(
'action_assessments_editModal',
'text-danger',
gT("Edit this assessment rule"),
'edit'
);
$deleteData = array(
'action_assessments_deleteModal',
'text-danger',
gT("Delete this assessment rule"),
'trash text-danger'
);

$editData = array(
'action_assessments_editModal',
'text-info',
gT("Edit this assessment rule"),
'edit',
gT("Edit")
);
$deleteData = array(
'action_assessments_deleteModal',
'text-danger',
gT("Delete this assessment rule"),
'trash text-danger',
gT("Delete")
);
if (Permission::model()->hasSurveyPermission($this->sid,'assessments', 'delete')) {
$buttons .= vsprintf($raw_button_template, $deleteData);
}
if (Permission::model()->hasSurveyPermission($this->sid,'assessments', 'update')) {
$buttons .= vsprintf($raw_button_template, $editData);
}

$buttons .= '</div>';

return $buttons;
}

Expand Down
28 changes: 27 additions & 1 deletion application/models/Template.php
Expand Up @@ -221,7 +221,7 @@ public function checkTemplateExtends()
if (empty($oRTemplate)) {

// Why? it blocks the user at login screen....
// It should return false and show a nice warning message.
// It should return false and show a nice warning message.

/*throw new Exception(
sprintf(
Expand Down Expand Up @@ -677,6 +677,32 @@ static public function getDeprecatedTemplates()
return $aTemplateList;
}

/**
* Retrieves a list of broken themes
*/
public static function getBrokenThemes($sFolder=null)
{
$aBrokenTemplateList = array();
$sFolder = (empty($sFolder))?Yii::app()->getConfig("userthemerootdir"):$sFolder;

if ($sFolder && $handle = opendir($sFolder)) {
while (false !== ($sFileName = readdir($handle))) {
if (!is_file("$sFolder/$sFileName") && $sFileName != "." && $sFileName != ".." && $sFileName != ".svn" && $sFileName != 'generalfiles' ) {

try {
$oTheme = Template::getTemplateConfiguration($sFileName, null, null, true); // Get the manifest;
}catch (Exception $e) {
$aBrokenTemplateList[$sFileName] = $e;
}
}
}
closedir($handle);
}
ksort($aBrokenTemplateList);
return $aBrokenTemplateList;
}


/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
Expand Down
4 changes: 2 additions & 2 deletions application/models/TemplateConfig.php
Expand Up @@ -112,7 +112,7 @@ public function getTemplateURL()
/**
* Get the template for a given file. It checks if a file exist in the current template or in one of its mother templates
* Can return a 302 redirect (this is not really a throw …
*
*
* @param string $sFile the file to look for (must contain relative path, unless it's a view file)
* @param TemplateConfig $oRTemplate template from which the recurrence should start
* @param boolean $force file to be in template or mother template
Expand Down Expand Up @@ -730,7 +730,7 @@ public function getClassAndAttributes()
$aClassAndAttributes['attr']['clearalllinks'] = $aClassAndAttributes['attr']['clearalllink'] = ' ';
// Clearall Buttons
$aClassAndAttributes['class']['clearallwrapper'] = $aClassAndAttributes['class']['clearallconfirm'] = ""; // No need, adding it if need something after
$aClassAndAttributes['class']['clearalllabel'] = "ls-js-hidden";
$aClassAndAttributes['class']['clearalllabel'] = "ls-js-hidden";
$aClassAndAttributes['attr']['clearallconfirm'] = 'value="confirm" name="confirm-clearall" type="checkbox"';
$aClassAndAttributes['attr']['clearallbutton'] = 'type="submit" value="clearall" name="move" data-confirmedby="confirm-clearall"';
$aClassAndAttributes['class']['clearallbutton'] = "ls-clearaction ls-clearall"; // Not needed, keep it (and adding to twig to be most compatible in future)
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/conditions/conditionshead_view.php
Expand Up @@ -24,13 +24,13 @@ class='btn btn-warning pull-right condition-header-button'
class="btn btn-default pull-right condition-header-button"
data-toggle='modal'
data-target='#confirmation-modal'
data-message='<?php eT('Are you sure you want to renumber the scenarios with incremented numbers beginning from 1?', 'js'); ?>'
data-message='<?php eT('Are you sure you want to renumber the scenarios with incrementing numbers beginning from 1?', 'js'); ?>'
data-onclick='(function() { document.getElementById("toplevelsubaction").value="renumberscenarios"; document.getElementById("deleteallconditions").submit();})'
onclick='return false;'
>
<span class="icon-renumber"></span>
&nbsp;
<?php eT("Renumber scenario automatically");?>
<?php eT("Renumber scenarios");?>
</button>
<?php endif; ?>

Expand Down
58 changes: 58 additions & 0 deletions application/views/admin/themeoptions/index.php
Expand Up @@ -35,6 +35,7 @@
<?php $this->renderPartial('themeoptions/surveythememenu',['canImport'=>$canImport,'importErrorMessage'=>$importErrorMessage]); ?>
<?php $this->renderPartial('themeoptions/surveythemelist', array( 'oSurveyTheme'=> $oSurveyTheme )); ?>

<!-- Available Themes -->
<?php if (count($oSurveyTheme->templatesWithNoDb) > 0 ):?>
<h3><?php eT('Available survey themes:'); ?></h3>
<div class="row">
Expand Down Expand Up @@ -69,6 +70,63 @@
</div>
<?php endif;?>

<!-- Broken Themes -->
<?php $aBrokenThemes = Template::getBrokenThemes(); if (count($aBrokenThemes) > 0 ):?>

<div class="alert alert-danger" role="alert">
<?php eT('Broken survey themes:'); ?>
</div>

<div class="row" >
<div class="col-sm-12 content-right">

<div id="thembes_broken" class="grid-view">
<table class="items table">
<thead>
<tr>
<th><?php eT('Name'); ?></th><th><?php eT('Error message'); ?></th><th></th>
</tr>
</thead>

<tbody>
<?php foreach ($aBrokenThemes as $sName => $oBrokenTheme):?>
<?php // echo $oTemplate; ?>
<tr class="odd">
<td class="col-md-1 text-danger"><?php echo $sName; ?></td>
<td class="col-md-10 "><blockquote><?php echo $oBrokenTheme->getMessage(); ?></blockquote></td>
<td class="col-md-1">

<!-- Export -->
<?php if(Permission::model()->hasGlobalPermission('templates','export') && function_exists("zip_open")):?>
<a class="btn btn-default btn-block" id="button-export" href="<?php echo $this->createUrl('admin/themes/sa/brokentemplatezip/templatename/' . $sName) ?>" role="button">
<span class="icon-export text-success"></span>
<?php eT("Export"); ?>
</a>
<?php endif;?>

<!-- Delete -->
<?php if(Permission::model()->hasGlobalPermission('templates','delete')):?>
<a class="btn btn-default btn-block" id="button-delete" href="#" role="button" onclick='if (confirm("<?php eT("Are you sure you want to delete this broken theme?", "js"); ?>")) window.open("<?php echo $this->createUrl('admin/themes/sa/deleteBrokenTheme/templatename/'.$sName); ?>", "_top")'>
<span class="fa fa-trash text-warning"></span>
<?php eT("Delete"); ?>
</a>
<?php endif;?>

</td>
</tr>
<?php endforeach;?>
</tbody>
</table>

</div>

</div>
</div>
<?php endif;?>


<!-- Broken Themes -->

<!-- Deprecated Themes -->
<?php $aDeprecatedThemes = Template::getDeprecatedTemplates(); ?>
<?php if (count( $aDeprecatedThemes ) > 0 ):?>
Expand Down
8 changes: 5 additions & 3 deletions assets/packages/template-core/template-core.js
Expand Up @@ -21,9 +21,11 @@ var TemplateCoreClass = function () {
},
/* alertSurveyDialog @see application/core/package/limesurvey */
alertSurveyDialog: function (text, title) {
$("#bootstrap-alert-box-modal .modal-header .modal-title").text(title || "");
$("#bootstrap-alert-box-modal .modal-body").html("<p>" + text + "</p>" || "");
$("#bootstrap-alert-box-modal").modal('show');
if (LSvar.showpopup===1) {
$("#bootstrap-alert-box-modal .modal-header .modal-title").text(title || "");
$("#bootstrap-alert-box-modal .modal-body").html("<p>" + text + "</p>" || "");
$("#bootstrap-alert-box-modal").modal('show');
}
},
/* confirmSurveyDialog @see application/core/package/limesurvey */
confirmSurveyDialog: function (text, title, submits) {
Expand Down

0 comments on commit c46ccd5

Please sign in to comment.