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 Mar 12, 2021
2 parents 687a20d + 33f356e commit fd45b98
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 111 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -12,7 +12,7 @@
*/

$config['versionnumber'] = '4.4.12';
$config['dbversionnumber'] = 440;
$config['dbversionnumber'] = 441;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['templateapiversion'] = 3;
Expand Down
22 changes: 18 additions & 4 deletions application/controllers/SurveyAdministrationController.php
Expand Up @@ -366,6 +366,12 @@ public function actionNewSurvey()
'N' => gT('Off', 'unescaped'),
);

$aData['optionsAdmin'] = array(
'default' => gT('Default', 'unescaped'),
'owner' => gT('Current user', 'unescaped'),
'custom' => gT('Custom', 'unescaped'),
);

//Prepare the edition panes
// $aData['edittextdata'] = array_merge($aData, $this->getTextEditData($survey));

Expand Down Expand Up @@ -437,15 +443,23 @@ public function actionInsert($iSurveyID = null)
if ($baseLanguage === null) {
$baseLanguage = 'en'; //shoulb be const somewhere ... or get chosen language from user
}
$simpleSurveyValues->setBaseLanguage($baseLanguage);
$simpleSurveyValues->setSurveyGroupId((int) App()->request->getPost('gsid', '1'));
$simpleSurveyValues->setTitle($surveyTitle);
$simpleSurveyValues->baseLanguage = $baseLanguage;
$simpleSurveyValues->surveyGroupId = (int) App()->request->getPost('gsid', '1');
$simpleSurveyValues->title = $surveyTitle;

$administrator = Yii::app()->request->getPost('administrator');
if ($administrator == 'custom') {
$simpleSurveyValues->admin = Yii::app()->request->getPost('admin');
$simpleSurveyValues->adminEmail = Yii::app()->request->getPost('adminemail');
}
$overrideAdministrator = ($administrator != 'owner');

$surveyCreator = new \LimeSurvey\Models\Services\CreateSurvey(new Survey(), new SurveyLanguageSetting());
$newSurvey = $surveyCreator->createSimple(
$simpleSurveyValues,
(int)Yii::app()->user->getId(),
Permission::model()
Permission::model(),
$overrideAdministrator
);
if (!$newSurvey) {
Yii::app()->setFlashMessage(gT("Survey could not be created."), 'error');
Expand Down
12 changes: 12 additions & 0 deletions application/controllers/admin/export.php
Expand Up @@ -554,6 +554,18 @@ public function exportspss()
}
}

// Add instructions to change variable type and recode 'Other' option.
// This is needed when all answer option codes are numeric but the question has 'Other' enabled,
// because the variable is initialy set as alphanumeric in order to hold the '-oth-' value. See issue #16939
foreach ($fields as $field) {
if (isset($field['needsAlterType'])) {
echo "RECODE {$field['id']} (\"-oth-\" = \"666666\").\n";
echo "EXECUTE.\n";
echo "ADD VALUE LABELS {$field['id']} 666666 \"other\".\n";
echo "ALTER TYPE {$field['id']} (F6.0).\n";
}
}

foreach ($fields as $field) {
if ($field['scale'] !== '') {
switch ($field['scale']) {
Expand Down
18 changes: 7 additions & 11 deletions application/controllers/admin/responses.php
Expand Up @@ -967,11 +967,6 @@ public function time($iSurveyID)
*/
private function _zipFiles($iSurveyID, $responseIds, $zipfilename)
{
/**
* @todo Move this to model.
*/
App()->loadLibrary('admin/pclzip');

$tmpdir = App()->getConfig('uploaddir') . DIRECTORY_SEPARATOR . "surveys" . DIRECTORY_SEPARATOR . $iSurveyID . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR;

$filelist = array();
Expand All @@ -987,19 +982,20 @@ private function _zipFiles($iSurveyID, $responseIds, $zipfilename)
*/
if (file_exists($tmpdir . basename($fileInfo['filename']))) {
$filelist[] = array(
PCLZIP_ATT_FILE_NAME => $tmpdir . basename($fileInfo['filename']),
PCLZIP_ATT_FILE_NEW_FULL_NAME => sprintf("%05s_%02s-%s_%02s-%s", $response->id, $filecount, $fileInfo['question']['title'], $fileInfo['index'], sanitize_filename(rawurldecode($fileInfo['name'])))
$tmpdir . basename($fileInfo['filename']),
sprintf("%05s_%02s-%s_%02s-%s", $response->id, $filecount, $fileInfo['question']['title'], $fileInfo['index'], sanitize_filename(rawurldecode($fileInfo['name'])))
);
}
}
}

if (count($filelist) > 0) {
$zip = new PclZip($tmpdir . $zipfilename);
if ($zip->create($filelist) === 0) {
//Oops something has gone wrong!
$zip = new ZipArchive();
$zip->open($tmpdir.$zipfilename,ZipArchive::CREATE);
foreach($filelist as $aFile) {
$zip->addFile($aFile[0],$aFile[1]);
}

$zip->close();
if (file_exists($tmpdir . '/' . $zipfilename)) {
@ob_clean();
header('Content-Description: File Transfer');
Expand Down
56 changes: 7 additions & 49 deletions application/datavalueobjects/SimpleSurveyValues.php
Expand Up @@ -17,59 +17,17 @@ class SimpleSurveyValues
{

/** @var string language selected by user */
private $baseLanguage;
public $baseLanguage;

/** @var string title of the survey */
private $title;
public $title;

/** @var int the surveygroup from which the new survey will inherit values */
private $surveyGroupId;
public $surveyGroupId;

/**
* @return string
*/
public function getBaseLanguage(): string
{
return $this->baseLanguage;
}
/** @var string administrator name */
public $admin = 'inherit';

/**
* @param string $baseLanguage
*/
public function setBaseLanguage(string $baseLanguage)
{
$this->baseLanguage = $baseLanguage;
}

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @param string $title
*/
public function setTitle(string $title)
{
$this->title = $title;
}

/**
* @return int
*/
public function getSurveyGroupId(): int
{
return $this->surveyGroupId;
}

/**
* @param int $surveyGroupId
*/
public function setSurveyGroupId(int $surveyGroupId)
{
$this->surveyGroupId = $surveyGroupId;
}
/** @var string administrator email */
public $adminEmail = 'inherit';
}
25 changes: 21 additions & 4 deletions application/helpers/export_helper.php
Expand Up @@ -17,12 +17,15 @@
* Strips html tags and replaces new lines
*
* @param $string
* @param $removeOther if 'true', removes '-oth-' from the string.
* @return string
*/
function stripTagsFull($string)
function stripTagsFull($string, $removeOther = true)
{
$string = flattenText($string, false, true); // stripo whole + html_entities
$string = str_replace('-oth', '', $string);// Why ?
if ($removeOther) {
$string = str_replace('-oth-', '', $string);
}
//The backslashes must be escaped twice, once for php, and again for the regexp
$string = str_replace("'|\\\\'", "'", $string);
return $string;
Expand Down Expand Up @@ -252,7 +255,7 @@ function SPSSExportData($iSurveyID, $iLength, $na = '', $sEmptyAnswerValue = '',
break; // Break inside if : comment and other are string to be filtered
} // else do default action
default:
$strTmp = mb_substr(stripTagsFull($row[$fieldno]), 0, $iLength);
$strTmp = mb_substr(stripTagsFull($row[$fieldno], false), 0, $iLength);
if (trim($strTmp) != '') {
echo quoteSPSS($strTmp, $q, $field);
} elseif ($row[$fieldno] === '') {
Expand Down Expand Up @@ -314,7 +317,7 @@ function SPSSGetValues($field = array(), $qidattributes = null, $language)
foreach ($result as $row) {
$answers[] = array(
'code' => $row['code'],
'value' => mb_substr(stripTagsFull($row["answer"]), 0, $length_vallabel),
'value' => mb_substr(stripTagsFull($row["answer"], false), 0, $length_vallabel),
);
}
}
Expand Down Expand Up @@ -408,8 +411,18 @@ function SPSSGetValues($field = array(), $qidattributes = null, $language)
$spsstype = 'A';
}
}
// For questions types with answer options, if all answer codes are numeric but "Other" option is enabled,
// field should be exported as SPSS type 'A', size 6. See issue #16939
if (strpos("!LORFH1", $field['LStype']) !== false && $spsstype == 'F') {
$oQuestion = Question::model()->findByPk($field["qid"]);
if ($oQuestion->other == 'Y') {
$spsstype = 'A';
$size = 6;
}
}
$answers['SPSStype'] = $spsstype;
$answers['size'] = $size;
$answers['needsAlterType'] = true;
return $answers;
} else {
/* Not managed (currently): url, IP, … */
Expand Down Expand Up @@ -649,6 +662,10 @@ function SPSSFieldMap($iSurveyID, $prefix = 'V', $sLanguage = '')
$tempArray['SPSStype'] = $answers['SPSStype'];
unset($answers['SPSStype']);
}
if (isset($answers['needsAlterType'])) {
$tempArray['needsAlterType'] = $answers['needsAlterType'];
unset($answers['needsAlterType']);
}
if (!empty($answers)) {
$tempArray['answers'] = $answers;
}
Expand Down
35 changes: 35 additions & 0 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -3721,6 +3721,41 @@ function ($v) {
$oTransaction->commit();
}

if ($iOldDBVersion < 441) {
$oTransaction = $oDB->beginTransaction();
// Convert old html editor modes if present in global settings
$oDB->createCommand()->update(
'{{settings_global}}',
array(
'stg_value' => 'inline',
),
"stg_name='defaulthtmleditormode' AND stg_value='wysiwyg'"
);
$oDB->createCommand()->update(
'{{settings_global}}',
array(
'stg_value' => 'none',
),
"stg_name='defaulthtmleditormode' AND stg_value='source'"
);
// Convert old html editor modes if present in profile settings
$oDB->createCommand()->update(
'{{users}}',
array(
'htmleditormode' => 'inline',
),
"htmleditormode='wysiwyg'"
);
$oDB->createCommand()->update(
'{{users}}',
array(
'htmleditormode' => 'none',
),
"htmleditormode='source'"
);
$oDB->createCommand()->update('{{settings_global}}', array('stg_value' => 441), "stg_name='DBVersion'");
$oTransaction->commit();
}
} catch (Exception $e) {
Yii::app()->setConfig('Updating', false);
$oTransaction->rollback();
Expand Down
3 changes: 1 addition & 2 deletions application/models/QuestionTheme.php
Expand Up @@ -411,7 +411,6 @@ public static function getQuestionMetaData($pathToXML)
foreach ($questionDirectories as $key => $questionDirectory) {
$questionDirectories[$key] = str_replace('\\', '/', $questionDirectory);
}
$publicurl = App()->getConfig('publicurl');

$pathToXML = str_replace('\\', '/', $pathToXML);
if (\PHP_VERSION_ID < 80000) {
Expand Down Expand Up @@ -459,7 +458,7 @@ public static function getQuestionMetaData($pathToXML)
// get custom previewimage if defined
if (!empty($oQuestionConfig->files->preview->filename)) {
$previewFileName = json_decode(json_encode($oQuestionConfig->files->preview->filename), true)[0];
$questionMetaData['image_path'] = $publicurl . $pathToXML . '/assets/' . $previewFileName;
$questionMetaData['image_path'] = DIRECTORY_SEPARATOR . $pathToXML . '/assets/' . $previewFileName;
}

$questionMetaData['xml_path'] = $pathToXML;
Expand Down
20 changes: 11 additions & 9 deletions application/models/services/CreateSurvey.php
Expand Up @@ -64,15 +64,15 @@ public function __construct($survey, $newLanguageSettings)
*
* @return Survey|bool returns the survey or false if survey could not be created for any reason
*/
public function createSimple($simpleSurveyValues, $userID, $permissionModel)
public function createSimple($simpleSurveyValues, $userID, $permissionModel, $overrideAdministrator = true)
{

$this->simpleSurveyValues = $simpleSurveyValues;
$this->survey->gsid = $simpleSurveyValues->getSurveyGroupId();
$this->survey->gsid = $simpleSurveyValues->surveyGroupId;
try {
$this->createSurveyId();
$this->setBaseLanguage();
$this->initialiseSurveyAttributes();
$this->initialiseSurveyAttributes($overrideAdministrator);

if (!$this->survey->save()) {
// TODO: Localization?
Expand Down Expand Up @@ -102,7 +102,7 @@ public function createSimple($simpleSurveyValues, $userID, $permissionModel)
*/
private function createRelationSurveyLanguageSettings($langsettings)
{
$sTitle = html_entity_decode($this->simpleSurveyValues->getTitle(), ENT_QUOTES, "UTF-8");
$sTitle = html_entity_decode($this->simpleSurveyValues->title, ENT_QUOTES, "UTF-8");

// Fix bug with FCKEditor saving strange BR types
$sTitle = fixCKeditorText($sTitle);
Expand Down Expand Up @@ -146,7 +146,7 @@ private function createRelationSurveyLanguageSettings($langsettings)
*/
private function setBaseLanguage()
{
$baseLang = $this->simpleSurveyValues->getBaseLanguage();
$baseLang = $this->simpleSurveyValues->baseLanguage;

//check if language exists in our language array...
$languageShortNames = getLanguageDataRestricted(true, 'short');
Expand Down Expand Up @@ -183,18 +183,17 @@ private function createSurveyId()
/**
* @return void
*/
private function initialiseSurveyAttributes()
private function initialiseSurveyAttributes($overrideAdministrator = true)
{
$this->survey->expires = null;
$this->survey->startdate = null;
$this->survey->template = 'inherit'; //default template from default group is set to 'fruity'
$this->survey->admin = 'inherit'; //admin name ...
$this->survey->active = self::STRING_VALUE_FOR_NO_FALSE;
$this->survey->anonymized = self::STRING_VALUE_FOR_NO_FALSE;
$this->survey->faxto = null;
$this->survey->format = self::STRING_SHORT_VALUE_INHERIT; //inherits value from survey group
$this->survey->savetimings = self::STRING_SHORT_VALUE_INHERIT; //could also be 'I' for inherit from survey group ...
$this->survey->language = $this->simpleSurveyValues->getBaseLanguage();
$this->survey->language = $this->simpleSurveyValues->baseLanguage;
$this->survey->datestamp = self::STRING_SHORT_VALUE_INHERIT;
$this->survey->ipaddr = self::STRING_SHORT_VALUE_INHERIT;
$this->survey->ipanonymize = self::STRING_SHORT_VALUE_INHERIT;
Expand Down Expand Up @@ -226,7 +225,10 @@ private function initialiseSurveyAttributes()
$this->survey->assessments = self::STRING_SHORT_VALUE_INHERIT;
$this->survey->emailresponseto = 'inherit';
$this->survey->tokenlength = self::INTEGER_VALUE_FOR_INHERIT;
$this->survey->adminemail = 'inherit';
$this->survey->bounce_email = 'inherit';
if ($overrideAdministrator) {
$this->survey->admin = $this->simpleSurveyValues->admin; //admin name ...
$this->survey->adminemail = $this->simpleSurveyValues->adminEmail;
}
}
}

0 comments on commit fd45b98

Please sign in to comment.