Skip to content

Commit

Permalink
Merge branch '2.5' of https://github.com/LimeSurvey/LimeSurvey into 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 17, 2015
2 parents 8a6f003 + d9adc97 commit c4e272c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions application/controllers/AdminController.php
Expand Up @@ -54,6 +54,7 @@ protected function _init()
*/
public function error($message, $sURL = array())
{
define('IMAGE_BASE_URL', Yii::app()->getConfig('adminimagebaseurl'));

$this->_getAdminHeader();
$sOutput = "<div class='messagebox ui-corner-all'>\n";
Expand Down
11 changes: 10 additions & 1 deletion application/controllers/admin/database.php
Expand Up @@ -393,7 +393,16 @@ function index($sa = null)

if (in_array($sAction, array('insertquestion', 'copyquestion')) && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent','create'))
{
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
$survey = Survey::model()->findByPk($iSurveyID);
$sBaseLanguage = $survey->language;

// Abort if survey is active
if ($survey->active !== 'N')
{
Yii::app()->setFlashMessage(gT("Can't insert new question when the survey is active"),'error');
$this->getController()->redirect(array("/admin/survey/sa/view/surveyid/" . $survey->sid), "refresh");
}

if (strlen(Yii::app()->request->getPost('title')) < 1)
{
Yii::app()->setFlashMessage(gT("The question could not be added. You must enter at least a question code."),'error');
Expand Down
11 changes: 7 additions & 4 deletions application/controllers/admin/index.php
Expand Up @@ -26,11 +26,12 @@ public function run()
// We get the last survey visited by user
$setting_entry = 'last_survey_'.Yii::app()->user->getId();
$lastsurvey = getGlobalSetting($setting_entry);
if( $lastsurvey != null)
$survey = Survey::model()->findByPk($lastsurvey);
if( $lastsurvey != null && $survey)
{
$aData['showLastSurvey'] = true;
$iSurveyID = $lastsurvey;
$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
$surveyinfo = $survey->surveyinfo;
$aData['surveyTitle'] = $surveyinfo['surveyls_title']."(".gT("ID").":".$iSurveyID.")";
$aData['surveyUrl'] = $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}");
}
Expand All @@ -51,9 +52,9 @@ public function run()
$setting_entry = 'last_question_sid_'.Yii::app()->user->getId();
$lastquestionsid = getGlobalSetting($setting_entry);

if( $lastquestion != null && $lastquestiongroup != null)
if( $lastquestion != null && $lastquestiongroup != null && $survey)
{
$baselang = Survey::model()->findByPk($iSurveyID)->language;
$baselang = $survey->language;
$aData['showLastQuestion'] = true;
$qid = $lastquestion;
$gid = $lastquestiongroup;
Expand All @@ -62,7 +63,9 @@ public function run()

$aData['last_question_name'] = $qrrow['title'];
if($qrrow['question'])
{
$aData['last_question_name'] .= ' : '.$qrrow['question'];
}

$aData['last_question_link'] = $this->getController()->createUrl("admin/questions/sa/view/surveyid/$iSurveyID/gid/$gid/qid/$qid");
}
Expand Down
9 changes: 4 additions & 5 deletions application/controllers/admin/questions.php
Expand Up @@ -53,13 +53,13 @@ public function view($surveyid, $gid, $qid)
// Check if other questions in the Survey are dependent upon this question
$condarray = getQuestDepsForConditions($iSurveyID, "all", "all", $qid, "by-targqid", "outsidegroup");

$sumresult1 = Survey::model()->findByPk($iSurveyID);
if (is_null($sumresult1))
$survey = Survey::model()->findByPk($iSurveyID);
if (is_null($survey))
{
Yii::app()->session['flashmessage'] = gT("Invalid survey ID");
$this->getController()->redirect(array("admin/index"));
} // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = $survey->attributes;

$surveyinfo = array_map('flattenText', $surveyinfo);
$aData['activated'] = $surveyinfo['active'];
Expand Down Expand Up @@ -133,8 +133,7 @@ public function view($surveyid, $gid, $qid)
$setting_entry = 'last_questiongroup_'.Yii::app()->user->getId();
setGlobalSetting($setting_entry, $gid);
*/


$aData['surveyIsActive'] = $survey->active !== 'N';

$this->_renderWrappedTemplate('survey/Question', 'question_view', $aData);
}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/surveyadmin.php
Expand Up @@ -934,7 +934,7 @@ public function delete($iSurveyID)
$lastQuestionGidUser = 'last_question_gid_'.Yii::app()->user->getId();
$lastQuestionUser = 'last_question_'.Yii::app()->user->getId();
SettingGlobal::model()->deleteAll(
"stg_name LIKE :stg_name OR stg_name = :last_question_gid_user OR stg_name = :last_question_user OR stg_value = :stg_value",
"stg_name LIKE ':stg_name' OR stg_name = ':last_question_gid_user' OR stg_name = ':last_question_user' OR stg_value = ':stg_value'",
array(':stg_name' => $lastLikeSurvey, ':last_question_gid_user' => $lastQuestionGidUser, ':last_question_user' => $lastQuestionUser , ':stg_value' => $iSurveyID )
);

Expand Down
6 changes: 4 additions & 2 deletions application/core/Survey_Common_Action.php
Expand Up @@ -66,11 +66,13 @@ public function runWithParams($params)
{
if(!Survey::model()->findByPk($params['iSurveyId']))
{
$this->getController()->error('Invalid A survey id');
Yii::app()->setFlashMessage(gT("Invalid survey id"),'error');
$this->getController()->redirect(array("admin/index"));
}
elseif (!Permission::model()->hasSurveyPermission($params['iSurveyId'], 'survey', 'read'))
{
$this->getController()->error('No permission');
Yii::app()->setFlashMessage(gT("No permission"), 'error');
$this->getController()->redirect(array("admin/index"));
}
else
{
Expand Down
24 changes: 24 additions & 0 deletions application/models/Question.php
Expand Up @@ -837,4 +837,28 @@ public function search()
));
return $dataProvider;
}

/**
* Make sure we don't save a new question group
* while the survey is active.
*
* @return bool
*/
protected function beforeSave()
{
if (parent::beforeSave())
{
$surveyIsActive = Survey::model()->findByPk($this->sid)->active !== 'N';

if ($surveyIsActive && $this->getIsNewRecord())
{
return false;
}
return true;
}
else
{
return false;
}
}
}
11 changes: 4 additions & 7 deletions application/views/admin/survey/Question/question_view.php
Expand Up @@ -121,17 +121,14 @@
<div class="col-lg-12 content-right">
<!-- create new question in this group -->
<div class="col-lg-3">
<div class="panel panel-primary panel-clickable" id="pannel-1" aria-data-url="<?php echo $this->createUrl('admin/questions/sa/newquestion/surveyid/'.$surveyid.'/gid/'.$gid); ?>">
<div class="panel panel-primary <?php if ($surveyIsActive) { echo 'disabled'; } else { echo 'panel-clickable'; } ?>" id="pannel-1" aria-data-url="<?php echo $this->createUrl('admin/questions/sa/newquestion/surveyid/'.$surveyid.'/gid/'.$gid); ?>">
<div class="panel-heading">
<h4 class="panel-title"><?php eT("Add new question to group");?></h4>
</div>
<div class="panel-body">
<a href="<?php echo $this->createUrl('admin/questions/sa/newquestion/surveyid/'.$surveyid.'/gid/'.$gid); ?>" >
<span class="icon-add text-success" style="font-size: 3em;"></span>
</a>
<p> <a href="<?php echo $this->createUrl('admin/questions/sa/newquestion/surveyid/'.$surveyid.'/gid/'.$gid); ?>">
<?php eT("Add new question to group");?>
</a>
<span class="icon-add text-success" style="font-size: 3em;"></span>
<p class='btn-link'>
<?php eT("Add new question to group");?>
</p>
</div>
</div>
Expand Down

0 comments on commit c4e272c

Please sign in to comment.