Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:LimeSurvey/LimeSurvey.git int…
Browse files Browse the repository at this point in the history
…o develop

Dev: hope i didn't broke existing fix
# Conflicts:
#	application/config/version.php
#	application/controllers/admin/themeoptions.php
#	application/core/plugins/extendedStartPage/views/publicSurveyList_extended.php
#	application/helpers/qanda_helper.php
#	application/libraries/PluginManager/PluginBase.php
#	application/models/Question.php
#	application/models/Survey.php
#	application/models/behaviors/PluginEventBehavior.php
#	application/views/admin/survey/Question/answerOptionsEdit_view.twig
#	framework/db/ar/CActiveRecord.php
#	themes/survey/bootswatch/options/options.twig
#	themes/survey/fruity/options/options.twig
#	themes/survey/vanilla/options/options.twig
  • Loading branch information
Shnoulle committed Nov 26, 2018
2 parents c882d82 + 6dca4e6 commit 00596cf
Show file tree
Hide file tree
Showing 130 changed files with 8,171 additions and 7,648 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -16,5 +16,5 @@
$config['dbversionnumber'] = 403;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30066';
$config['assetsversionnumber'] = '30069';
return $config;
2 changes: 1 addition & 1 deletion application/controllers/RegisterController.php
Expand Up @@ -178,7 +178,7 @@ public function getRegisterErrors($iSurveyId)
//Check and validate attribute
foreach ($aRegisterAttributes as $key => $aAttribute) {
if ($aAttribute['show_register'] == 'Y' && $aAttribute['mandatory'] == 'Y' && empty($aFieldValue['aAttribute'][$key])) {
$this->aRegisterErrors[] = sprintf(gT("%s cannot be left empty").".", $aAttribute['caption']);
$this->aRegisterErrors[] = sprintf(gT("%s cannot be left empty."), $aAttribute['caption']);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -282,7 +282,7 @@ public function displayParticipants()
$surveys = Survey::model();
//!!! Is this even possible to execute?
if (!Permission::model()->hasGlobalPermission('superadmin', 'read')) {
$surveys->permission(Yii::app()->user->getId());
$surveys->permission(Yii::app()->user->getId());
}

/** @var Survey[] $aSurveyNames */
Expand All @@ -300,24 +300,24 @@ public function displayParticipants()
// if superadmin all the records in the cpdb will be displayed
if (Permission::model()->hasGlobalPermission('superadmin', 'read')) {
$iTotalRecords = Participant::model()->count();
}
// if not only the participants on which he has right on (shared and owned)
else {
} else {// if not only the participants on which he has right on (shared and owned)
$iUserId = Yii::app()->user->getId();
$iTotalRecords = Participant::model()->getParticipantsOwnerCount($iUserId);
}
$model = new Participant();
$request = Yii::app()->request;
$participantParam = $request->getPost('Participant');
$participantParam = $request->getParam('Participant');
if ($participantParam) {
$model->setAttributes($participantParam, false);
}
$searchcondition = $request->getPost('searchcondition');
/* @todo : See when/where it's used */
$searchcondition = $request->getParam('searchcondition');
$searchparams = array();
if ($searchcondition) {
$searchparams = explode('||', $searchcondition);
$model->addSurveyFilter($searchparams);
}

// data to be passed to view
$aData = array(
'names' => User::model()->findAll(),
Expand Down Expand Up @@ -407,7 +407,7 @@ public function deleteParticipant()
*/
public function openEditParticipant()
{
$participant_id = Yii::app()->request->getPost('participant_id');
$participant_id = Yii::app()->request->getParam('participant_id');
if ($participant_id) {
$model = Participant::model()->findByPk($participant_id);
$operationType = "edit";
Expand Down
148 changes: 82 additions & 66 deletions application/controllers/admin/responses.php
Expand Up @@ -518,60 +518,68 @@ public function actionResponses($iSurveyId)
*/
public function actionDelete($surveyid)
{
if(!Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete')) {
throw new CHttpException(403, gT("You do not have permission to access this page."));
}
if(!Yii::app()->getRequest()->isPostRequest) {
throw new CHttpException(405, gT("Invalid action"));
}
Yii::import('application.helpers.admin.ajax_helper', true);

$iSurveyId = (int) $surveyid;
if (Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'delete')) {

$ResponseId = (Yii::app()->request->getPost('sItems') != '') ? json_decode(Yii::app()->request->getPost('sItems')) : json_decode(Yii::app()->request->getPost('sResponseId'), true);
$ResponseId = (Yii::app()->request->getPost('sItems') != '') ? json_decode(Yii::app()->request->getPost('sItems')) : json_decode(Yii::app()->request->getParam('sResponseId'), true);
if ( Yii::app()->request->getPost('modalTextArea') != '' ){
$ResponseId = explode(',', Yii::app()->request->getPost('modalTextArea'));
foreach($ResponseId as $key => $sResponseId){
$ResponseId[$key] = str_replace(' ', '', $sResponseId);
}
}

$aResponseId = (is_array($ResponseId)) ? $ResponseId : array($ResponseId);

if ( Yii::app()->request->getPost('modalTextArea') != '' ){
$ResponseId = explode(',', Yii::app()->request->getPost('modalTextArea'));
$errors = 0;
$timingErrors = 0;

foreach($ResponseId as $key => $sResponseId){
$ResponseId[$key] = str_replace(' ', '', $sResponseId);
}
}
foreach ($aResponseId as $iResponseId) {
$beforeDataEntryDelete = new PluginEvent('beforeDataEntryDelete');
$beforeDataEntryDelete->set('iSurveyID', $iSurveyId);
$beforeDataEntryDelete->set('iResponseID', $iResponseId);
App()->getPluginManager()->dispatchEvent($beforeDataEntryDelete);

$aResponseId = (is_array($ResponseId)) ? $ResponseId : array($ResponseId);

$errors = 0;
$timingErrors = 0;

foreach ($aResponseId as $iResponseId) {
$beforeDataEntryDelete = new PluginEvent('beforeDataEntryDelete');
$beforeDataEntryDelete->set('iSurveyID', $iSurveyId);
$beforeDataEntryDelete->set('iResponseID', $iResponseId);
App()->getPluginManager()->dispatchEvent($beforeDataEntryDelete);

$response = Response::model($iSurveyId)->findByPk($iResponseId);
if ($response) {
$result = $response->delete(true);
if (!$result) {
$errors++;
} else {
$oSurvey = Survey::model()->findByPk($iSurveyId);
// TODO : add it to response delete (maybe test if timing table exist)
if ($oSurvey->savetimings == "Y") {
$result = SurveyTimingDynamic::model($iSurveyId)->deleteByPk($iResponseId);
if (!$result) {
$timingErrors++;
}
$response = Response::model($iSurveyId)->findByPk($iResponseId);
if ($response) {
$result = $response->delete(true);
if (!$result) {
$errors++;
} else {
$oSurvey = Survey::model()->findByPk($iSurveyId);
// TODO : add it to response->delete and response->afterDelete
if ($oSurvey->savetimings == "Y") {
$result = SurveyTimingDynamic::model($iSurveyId)->deleteByPk($iResponseId);
if (!$result) {
$timingErrors++;
}
}
} else {
$errors++;
}
} else {
$errors++;
}
}

if ($errors == 0 && $timingErrors == 0) {
ls\ajax\AjaxHelper::outputSuccess(gT('Response(s) deleted.'));
if ($errors || $timingErrors) {
$message = ($errors) ? ngT("A response was not deleted.|{n} responses were not deleted.",$errors) : "";
$message.= ($timingErrors) ? ngT("A timing record was not deleted.|{n} timing records were not deleted.",$errors) : "";
if(Yii::app()->getRequest()->isAjaxRequest) {
ls\ajax\AjaxHelper::outputError($message);
} else {
ls\ajax\AjaxHelper::outputError(gT('Error during response deletion.'));
Yii::app()->setFlashMessage($message,'error');
$this->getController()->redirect(array("admin/responses", "sa"=>"browse", "surveyid"=>$iSurveyId));
}

}
if(Yii::app()->getRequest()->isAjaxRequest) {
ls\ajax\AjaxHelper::outputSuccess(gT('Response(s) deleted.'));
}
Yii::app()->setFlashMessage(gT('Response(s) deleted.'),'success');
$this->getController()->redirect(array("admin/responses", "sa"=>"browse", "surveyid"=>$iSurveyId));
}

Expand Down Expand Up @@ -631,6 +639,7 @@ public function actionDownloadfile($iSurveyId, $iResponseId, $iQID, $iIndex)
*/
public function actionDownloadfiles($iSurveyId, $sResponseId)
{

if (Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read')) {
if (!$sResponseId) {
// No response id : get all survey files
Expand Down Expand Up @@ -666,13 +675,11 @@ public function actionDownloadfiles($iSurveyId, $sResponseId)
*/
public function actionDeleteAttachments()
{
Yii::import('application.helpers.admin.ajax_helper', true);

$request = Yii::app()->request;
$surveyid = (int) $request->getPost('surveyid');
$sid = (int) $request->getPost('sid');
$surveyid = (int) $request->getParam('surveyid');
$sid = (int) $request->getParam('sid');
$surveyId = $sid ? $sid : $surveyid;
$responseId = (int) $request->getPost('sResponseId');
$responseId = (int) $request->getParam('sResponseId');
$stringItems = json_decode($request->getPost('sItems'));
// Cast all ids to int.
$items = array_map(
Expand All @@ -683,38 +690,47 @@ function($id)
is_array($stringItems) ? $stringItems : array()
);
$responseIds = $responseId ? array($responseId) : $items;

if(!Permission::model()->hasSurveyPermission($surveyId, 'responses', 'update')) {
throw new CHttpException(403, gT("You do not have permission to access this page."));
}
if(!$request->isPostRequest) {
throw new CHttpException(405, gT("Invalid action"));
}
Yii::import('application.helpers.admin.ajax_helper', true);
$allErrors = array();
$allSuccess = 0;

if (Permission::model()->hasSurveyPermission($surveyId, 'responses', 'delete')) {
foreach ($responseIds as $responseId) {
$response = Response::model($surveyId)->findByPk($responseId);
if (!empty($response)) {
list($success, $errors) = $response->deleteFilesAndFilename();
if (empty($errors)) {
$allSuccess += $success;
} else {
// Could not delete all files.
$allErrors = array_merge($allErrors, $errors);
}
foreach ($responseIds as $responseId) {
$response = Response::model($surveyId)->findByPk($responseId);
if (!empty($response)) {
list($success, $errors) = $response->deleteFilesAndFilename();
if (empty($errors)) {
$allSuccess += $success;
} else {
$allErrors[] = sprintf(gT('Found no response with ID %d'), $responseId);
// Could not delete all files.
$allErrors = array_merge($allErrors, $errors);
}
} else {
$allErrors[] = sprintf(gT('Found no response with ID %d'), $responseId);
}

if ($allErrors) {
}
if (!empty($allErrors)) {
$message = gT('Error: Could not delete some files: ').implode(', ', $allErrors);
if($request->isAjaxRequest) {
ls\ajax\AjaxHelper::outputError(
gT('Error: Could not delete some files: ').implode(', ', $allErrors)
$message
);
} else {
// All is OK.
ls\ajax\AjaxHelper::outputSuccess(sprintf(ngT('%d file deleted.|%d files deleted.', $allSuccess), $allSuccess));
Yii::app()->end();
}
} else {
// No permission.
ls\ajax\AjaxHelper::outputNoPermission();
Yii::app()->setFlashMessage($message,'error');
$this->getController()->redirect(array("admin/responses", "sa"=>"browse", "surveyid"=>$surveyId));
}
$message = sprintf(ngT('%d file deleted.|%d files deleted.', $allSuccess), $allSuccess);
if($request->isAjaxRequest) {
ls\ajax\AjaxHelper::outputSuccess($message);
Yii::app()->end();
}
Yii::app()->setFlashMessage($message,'success');
$this->getController()->redirect(array("admin/responses", "sa"=>"browse", "surveyid"=>$surveyId));
}

Expand Down
108 changes: 107 additions & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -297,6 +297,27 @@ public function changeMultipleTheme()
Yii::app()->getController()->renderPartial('ext.admin.survey.ListSurveysWidget.views.massive_actions._action_results', array('aResults'=>$aResults,'successLabel'=>$sTemplate));
}

/**
* Change survey group for multiple survey at once.
* Called from survey list massive actions
*/
public function changeMultipleSurveyGroup()
{
$sSurveys = $_POST['sItems'];
$aSIDs = json_decode($sSurveys);
$aResults = array();

$iSurveyGroupId = sanitize_int(App()->request->getPost('surveygroupid'));

foreach ($aSIDs as $iSurveyID){
$oSurvey = Survey::model()->findByPk($iSurveyID);
$oSurvey->gsid = $iSurveyGroupId;
$aResults[$iSurveyID] = $oSurvey->save();
}

Yii::app()->getController()->renderPartial('ext.admin.survey.ListSurveysWidget.views.massive_actions._action_results', array('aResults'=>$aResults,'successLabel'=>gT("Success")));
}

/**
* Update the theme of a survey
*
Expand Down Expand Up @@ -1148,7 +1169,7 @@ public function copy()
LimeExpressionManager::SetSurveyId($aImportResults['newsid']);
LimeExpressionManager::RevertUpgradeConditionsToRelevance($aImportResults['newsid']);
LimeExpressionManager::UpgradeConditionsToRelevance($aImportResults['newsid']);
LimeExpressionManager::StartSurvey($oSurvey->sid, 'survey', $oSurvey->attributes, true);
@LimeExpressionManager::StartSurvey($oSurvey->sid, 'survey', $oSurvey->attributes, true);
LimeExpressionManager::StartProcessingPage(true, true);
$aGrouplist = QuestionGroup::model()->findAllByAttributes(['sid'=>$aImportResults['newsid']]);
foreach ($aGrouplist as $aGroup) {
Expand Down Expand Up @@ -2051,4 +2072,89 @@ public function applythemeoptions($iSurveyID = 0)
}
$this->getController()->redirect(array('admin/survey/sa/view/surveyid/'.$iSurveyID));
}

/**
* Upload an image in directory
* @return json
*/
public function uploadimagefile()
{
$iSurveyID = Yii::app()->request->getPost('surveyid');
$success = false;
$debug = [];
if(!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'update')) {
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => gT("You don't have sufficient permissions to upload images in this survey"), 'debug' => $debug]),
false,
false
);
}
$debug[] = $_FILES;
if(empty($_FILES)) {
$uploadresult = gT("No file was uploaded.");
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => $uploadresult, 'debug' => $debug]),
false,
false
);
}
if ($_FILES['file']['error'] == 1 || $_FILES['file']['error'] == 2) {
$uploadresult = sprintf(gT("Sorry, this file is too large. Only files up to %01.2f MB are allowed."), getMaximumFileUploadSize() / 1024 / 1024);
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => $uploadresult, 'debug' => $debug]),
false,
false
);
}
$checkImage = LSYii_ImageValidator::validateImage($_FILES["file"]["tmp_name"]);
if ($checkImage['check'] === false) {
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => $checkImage['uploadresult'], 'debug' => $checkImage['debug']]),
false,
false
);
}
$surveyDir = Yii::app()->getConfig('uploaddir')."/surveys/".$iSurveyID;
if (!is_dir($surveyDir)) {
@mkdir($surveyDir);
}
if (!is_dir($surveyDir."/images")) {
@mkdir($surveyDir."/images");
}
$destdir = $surveyDir."/images/";
if (!is_writeable($destdir)) {
$uploadresult = sprintf(gT("Incorrect permissions in your %s folder."), $destdir);
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => $uploadresult, 'debug' => $debug]),
false,
false
);
}

$filename = sanitize_filename($_FILES['file']['name'], false, false, false); // Don't force lowercase or alphanumeric
$fullfilepath = $destdir.$filename;
$debug[] = $destdir;
$debug[] = $filename;
$debug[] = $fullfilepath;
if (!@move_uploaded_file($_FILES['file']['tmp_name'], $fullfilepath)) {
$uploadresult = gT("An error occurred uploading your file. This may be caused by incorrect permissions for the application /tmp folder.");
} else {
$uploadresult = sprintf(gT("File %s uploaded"), $filename);
$success = true;
};
return Yii::app()->getController()->renderPartial(
'/admin/super/_renderJson',
array('data' => ['success' => $success, 'message' => $uploadresult, 'debug' => $debug]),
false,
false
);



}
}

0 comments on commit 00596cf

Please sign in to comment.