Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-foster-uk committed Oct 27, 2023
2 parents a3e7cbc + 99cdf59 commit 28fc516
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 90 deletions.
6 changes: 6 additions & 0 deletions application/controllers/QuestionAdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,12 @@ public function actionImport()
$iSurveyID = (int) App()->request->getPost('sid', 0);
$gid = (int) App()->request->getPost('gid', 0);

if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'import')) {
App()->session['flashmessage'] = gT("We are sorry but you don't have permissions to do this.");
/* Same redirect than importView */
$this->redirect(['questionAdministration/listquestions/surveyid/' . $iSurveyID]);
}

$jumptoquestion = (bool)App()->request->getPost('jumptoquestion', 1);

$oSurvey = Survey::model()->findByPk($iSurveyID);
Expand Down
15 changes: 8 additions & 7 deletions application/controllers/SurveyAdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,18 +813,19 @@ public function actionChangeMultipleSurveyGroup()

foreach ($aSIDs as $iSurveyID) {
$oSurvey = Survey::model()->findByPk((int)$iSurveyID);
$oSurvey->gsid = $iSurveyGroupId;
$aResults[$iSurveyID]['title'] = $oSurvey->correct_relation_defaultlanguage->surveyls_title;
/* Permission must be checked with current SurveyGroup, SurveyGroup give Surveys Permission, see mantis issue #19169 */
if (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update')) {
$aResults[$iSurveyID]['result'] = false;
$aResults[$iSurveyID]['error'] = gT("User does not have valid permissions");
continue;
}
$oSurvey->gsid = $iSurveyGroupId;
if ($oSurvey->save()) {
$aResults[$iSurveyID]['result'] = true;
} else {
if ($oSurvey->save()) {
$aResults[$iSurveyID]['result'] = true;
} else {
$aResults[$iSurveyID]['result'] = false;
$aResults[$iSurveyID]['error'] = gT("Survey update failed");
}
$aResults[$iSurveyID]['result'] = false;
$aResults[$iSurveyID]['error'] = gT("Survey update failed");
}
}

Expand Down
7 changes: 7 additions & 0 deletions application/controllers/admin/ParticipantsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,13 @@ public function blacklistControl()
*/
public function storeBlacklistValues()
{
$this->requirePostRequest();

if (!Permission::model()->hasGlobalPermission('settings', 'update')) {
Yii::app()->setFlashMessage(gT('Access denied!'), 'error');
Yii::app()->getController()->redirect(array('admin/participants/sa/blacklistControl'));
}

$values = array('blacklistallsurveys', 'blacklistnewsurveys', 'blockaddingtosurveys', 'hideblacklisted', 'deleteblacklisted', 'allowunblacklist');
foreach ($values as $value) {
if (SettingGlobal::model()->findByPk($value)) {
Expand Down
11 changes: 3 additions & 8 deletions application/helpers/admin/statistics_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2251,14 +2251,9 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi
$query .= ($sDatabaseType == "mysql") ? Yii::app()->db->quoteColumnName($al[2])." <> '')" : " (".Yii::app()->db->quoteColumnName($al[2])." NOT LIKE ''))";
// all other question types
} else {
$query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ".Yii::app()->db->quoteColumnName($al[2])." =";

//ranking question?
if (substr((string) $rt, 0, 1) == "R") {
$query .= " '$al[0]'";
} else {
$query .= " 'Y'";
}
$value = (substr((string) $rt, 0, 1) == "R") ? $al[0] : 'Y';
$encryptedValue = getEncryptedCondition($responseModel, $al[2], $value);
$query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ".Yii::app()->db->quoteColumnName($al[2])." = '$encryptedValue'";
}
} //end if -> alist set

Expand Down
18 changes: 14 additions & 4 deletions application/helpers/admin/token_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function emailTokens($iSurveyID, $aResultTokens, $sType, $continueOnError = fals
'name' => $aTokenRow["firstname"] . " " . $aTokenRow["lastname"],
'email' => $aTokenRow["email"],
'status' => 'fail',
'warning' => null,
'error' => 'Token not valid yet'
);
if ($continueOnError) {
Expand All @@ -55,6 +56,7 @@ function emailTokens($iSurveyID, $aResultTokens, $sType, $continueOnError = fals
'name' => $aTokenRow["firstname"] . " " . $aTokenRow["lastname"],
'email' => $aTokenRow["email"],
'status' => 'fail',
'warning' => null,
'error' => 'Token not valid anymore'
);
if ($continueOnError) {
Expand All @@ -64,27 +66,35 @@ function emailTokens($iSurveyID, $aResultTokens, $sType, $continueOnError = fals
}
}
if ($mail->sendMessage()) {
$warnings = null;
$oToken = Token::model($iSurveyID)->findByPk($aTokenRow['tid']);
if ($sType == 'invite' || $sType == 'register') {
$oToken->sent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$oToken->save();
if (!$oToken->save(true, ['sent'])) {
$warnings = $oToken->getErrors();
}
}
if ($sType == 'remind') {
$oToken->remindersent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$oToken->remindercount++;
$oToken->save();
if (!$oToken->save(true, ['remindersent', 'remindercount'])) {
$warnings = $oToken->getErrors();
}
}
$aResult[$aTokenRow['tid']] = array(
'name' => $aTokenRow["firstname"] . " " . $aTokenRow["lastname"],
'email' => $aTokenRow["email"],
'status' => 'OK'
'status' => 'OK',
'warning' => $warnings,
'error' => null
);
} else {
$aResult[$aTokenRow['tid']] = array(
'name' => $aTokenRow["firstname"] . " " . $aTokenRow["lastname"],
'email' => $aTokenRow["email"],
'status' => 'fail',
'error' => $mail->getError(),
'warning' => null,
'error' => $mail->getError()
);
}
}
Expand Down
9 changes: 5 additions & 4 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -2968,17 +2968,17 @@ public function mail_registered_participants($sSessionKey, $iSurveyID, $override
{
Yii::app()->loadHelper('admin/token');
if (!$this->_checkSessionKey($sSessionKey)) {
return array('status' => self::INVALID_SESSION_KEY);
return array('status' => self::INVALID_SESSION_KEY);
}
$iSurveyID = (int) $iSurveyID;
$oSurvey = Survey::model()->findByPk($iSurveyID);
if (!isset($oSurvey)) {
return array('status' => 'Error: Invalid survey ID');
return array('status' => 'Error: Invalid survey ID');
}

if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'update')) {
if (!tableExists("{{tokens_$iSurveyID}}")) {
return array('status' => 'Error: No survey participants table');
return array('status' => 'Error: No survey participants table');
}

$command = new CDbCriteria();
Expand Down Expand Up @@ -3008,12 +3008,13 @@ public function mail_registered_participants($sSessionKey, $iSurveyID, $override
$aResultTokens = Token::model($iSurveyID)->findAll($command);

if (empty($aResultTokens)) {
return array('status' => 'Error: No candidate tokens');
return array('status' => 'Error: No candidate tokens');
}

foreach ($aResultTokens as $key => $oToken) {
$oToken->decrypt();
//pattern taken from php_filter_validate_email PHP_5_4/ext/filter/logical_filters.c
/* @todo : use LimeMailer::validateAddresses */
$pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';

//pattern to split in case of multiple emails for a participant
Expand Down
84 changes: 45 additions & 39 deletions application/helpers/update/updates/Update_614.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,57 @@ public function up()
foreach ($templateConfigurations as $templateConfiguration) {
if ($templateConfiguration['options'] !== 'inherit') {
if ($templateConfiguration['template_name'] == 'vanilla') {
$sOptionsJson = $templateConfiguration['options'];
$oOldOptions = json_decode($sOptionsJson);
if (empty($oOldOptions->animatebody)) {
$oOldOptions->animatebody = 'off';
$optionsJson = $templateConfiguration['options'];
$oldOptions = json_decode($optionsJson);
if (is_object($oldOptions)) {
if (empty($oldOptions->animatebody)) {
$oldOptions->animatebody = 'off';
}
if (empty($oldOptions->fixnumauto)) {
$oldOptions->fixnumauto = 'enable';
}
$newOptionsJson = json_encode($oldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $newOptionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
}
if (empty($oOldOptions->fixnumauto)) {
$oOldOptions->fixnumauto = 'enable';
}
$oNewOtionsJson = json_encode($oOldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $oNewOtionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
} elseif ($templateConfiguration['template_name'] == 'fruity') {
$sOptionsJson = $templateConfiguration['options'];
$optionsJson = $templateConfiguration['options'];
// fixnumauto is not guaranteed to exist in older version of fruity, so rather decode as array, not as object
$oldOptions = json_decode($sOptionsJson, true);
if (!isset($oldOptions['fixnumauto']) || empty($oldOptions['fixnumauto'])) {
$oldOptions['fixnumauto'] = 'enable';
$oldOptions = json_decode($optionsJson);
if (is_object($oldOptions)) {
if (empty($oldOptions->fixnumauto)) {
$oldOptions->fixnumauto = 'enable';
}
$newOptionsJson = json_encode($oldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $newOptionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
}
$oNewOtionsJson = json_encode($oldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $oNewOtionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
} elseif ($templateConfiguration['template_name'] == 'bootswatch') {
$sOptionsJson = $templateConfiguration['options'];
$oOldOptions = json_decode($sOptionsJson);
if (empty($oOldOptions->hideprivacyinfo)) {
$oOldOptions->hideprivacyinfo = 'off';
}
if (empty($oOldOptions->fixnumauto)) {
$oOldOptions->fixnumauto = 'enable';
$optionsJson = $templateConfiguration['options'];
$oldOptions = json_decode($optionsJson);
if (is_object($oldOptions)) {
if (empty($oldOptions->hideprivacyinfo)) {
$oldOptions->hideprivacyinfo = 'off';
}
if (empty($oldOptions->fixnumauto)) {
$oldOptions->fixnumauto = 'enable';
}
$newOptionsJson = json_encode($oldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $newOptionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
}
$oNewOtionsJson = json_encode($oOldOptions);
$this->db->createCommand()->update(
'{{template_configuration}}',
['options' => $oNewOtionsJson],
'id = :id',
[':id' => $templateConfiguration['id']]
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions application/views/surveyPermissions/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<?= gT("User") ?>:
</label>
<div class='col-4'>
<select id='uidselect' name='uid' class='form-select activate-search'>
<select style="width:100%;" id='uidselect' name='uid' class='form-select activate-search'>
<?php
if (count($userList) > 0) {
echo "<option value='-1' selected='selected'>" . gT("Please choose...") . "</option>";
Expand Down Expand Up @@ -59,7 +59,7 @@
<?= gT("User group") ?>:
</label>
<div class='col-4'>
<select id='ugidselect' name='ugid' class='form-select activate-search'>
<select style="width:100%;" id='ugidselect' name='ugid' class='form-select activate-search'>
<?php
if (count($userGroupList) > 0) {
echo "<option value='-1' selected='selected'>" . gT("Please choose...") . "</option>";
Expand Down
2 changes: 1 addition & 1 deletion application/views/themeOptions/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class="btn btn-danger btn-sm selector--ConfirmModal">
<?php if ($oTheme->name === App()->getConfig('admintheme')) : ?>
<h3><strong class="text-info"><?php eT("Selected") ?></strong></h3>
<?php else : ?>
<a href="<?= $this->createUrl("themeOptions/setAdminTheme/", ['sAdminThemeName' => $oTheme->path]) ?>"
<a href="<?= $this->createUrl("themeOptions/setAdminTheme/", ['sAdminThemeName' => $oTheme->name]) ?>"
class="btn btn-outline-secondary btn-sm">
<?= gT("Select") ?>
</a>
Expand Down
64 changes: 48 additions & 16 deletions assets/packages/themeoptions-core/themeoptions-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,58 @@ var ThemeOptions = function () {

};

// updates the disabled status of a child field
// based on the parent element
// NOTE:
// for font and variations dropdowns, the childfield
// class is added and the data-parent attr exists,
// but no parent element exists in the markup
// so if we actually have a parent element, enable/disable
// based on that, otherwise we enable by default
const updateChild = function(parentEl, childEl) {

let enabled = true;

if(parentEl.length) {
const parentOn = $(parentEl).val() === 'on';
const parentChecked = $(parentEl).prop('checked') === true;
enabled = parentOn && parentChecked;
}

$(childEl).prop('disabled', !enabled);
}

// grab the parent for a given child field
const getParent = function(childEl) {
const parentName = $(childEl).data('parent');
const parentEl = $(`input[name=${parentName}]`);
return parentEl;
}

// go through each child field, grab parent, and update disabled status
const updateAllChildren = function() {
$('.selector_radio_childfield').each(function (i, childEl) {
const parentEl = getParent(childEl);
updateChild(parentEl, childEl);
});
}

///////////////
// HotSwap methods
// -- These methods connect an input directly to the value in the optionsObject

// Disable dependent inputs when their parents are set to off, or inherit
var hotSwapParentRadioButtons = function () {
// hotswapping the select fields to the radiobuttons
// If an option is set to off, the attached selectors are disabled
$('.selector_radio_childfield').each(function (i, selectorItem) {
$('input[name=' + $(selectorItem).data('parent') + ']').on('change', function () {
if ($(this).val() == 'on' && $(this).prop('checked') == true) {
$(selectorItem).prop('disabled', false);
} else {
$(selectorItem).prop('disabled', true);
}
const hotSwapParentRadioButtons = function () {

// disabled this part to always be able to click on "Preview image" button
/*
if ($(selectorItem).hasClass('selector_image_selector')) {
$('button[data-target="#' + $(selectorItem).attr('id') + '"]').prop('disabled', $(selectorItem).val() == 'inherit');
}
*/
// for each child field, add a listener for the
// parent's change and update the child's disabled
// status accordingly
// i = element index in list of matches, unused
$('.selector_radio_childfield').each(function (i, childEl) {
const parentEl = getParent(childEl);

parentEl.on('change', function () {
updateChild(parentEl, childEl);
});
});
};
Expand Down Expand Up @@ -456,6 +485,9 @@ var ThemeOptions = function () {
showInheritedValue();

bind();

// set initial disabled status of child fields
updateAllChildren();
};

return run;
Expand Down

0 comments on commit 28fc516

Please sign in to comment.