diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index 20a7570c19e..0a673861a31 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -307,26 +307,26 @@ public function deactivate($iSurveyID = null) $iSurveyID = Yii::app()->request->getPost('sid', $iSurveyID); $iSurveyID = sanitize_int($iSurveyID); $clang = $this->getController()->lang; - if (!tableExists('survey_'.$iSurveyID)) - { - $_SESSION['flashmessage'] = $clang->gT("Error: Response table does not exist. Survey cannot be deactivated."); - $this->getController()->redirect($this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}")); - } $date = date('YmdHis'); //'His' adds 24hours+minutes to name to allow multiple deactiviations in a day if (empty($_POST['ok'])) { + if (!tableExists('survey_'.$iSurveyID)) + { + $_SESSION['flashmessage'] = $clang->gT("Error: Response table does not exist. Survey cannot be deactivated."); + $this->getController()->redirect($this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}")); + } $aData['surveyid'] = $iSurveyID; $aData['date'] = $date; $aData['dbprefix'] = Yii::app()->db->tablePrefix; $aData['step1'] = true; } else - { + { //See if there is a tokens table for this survey if (tableExists("{{tokens_{$iSurveyID}}}")) { - if (Yii::app()->db->getDriverName() == 'postgre') + if (Yii::app()->db->getDriverName() == 'pgsql') { $deactivateresult = Yii::app()->db->createCommand()->renameTable($toldtable . '_tid_seq', $tnewtable . '_tid_seq'); $setsequence = "ALTER TABLE ".Yii::app()->db->quoteTableName($tnewtable)." ALTER COLUMN tid SET DEFAULT nextval('{{{$tnewtable}}}_tid_seq'::regclass);"; @@ -362,13 +362,7 @@ public function deactivate($iSurveyID = null) $survey = Survey::model()->findByAttributes(array('sid' => $iSurveyID)); $survey->autonumber_start = $new_autonumber_start; $survey->save(); - if (Yii::app()->db->getDrivername() == 'postgre') - { - $deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName . '_id_seq', $sNewSurveyTableName . '_id_seq'); - $setsequence = "ALTER TABLE $newtable ALTER COLUMN id SET DEFAULT nextval('{$sNewSurveyTableName}_id_seq'::regclass);"; - $deactivateresult = Yii::app()->db->createCommand($setsequence)->execute(); - } - + $deactivateresult = Yii::app()->db->createCommand()->renameTable($sOldSurveyTableName, $sNewSurveyTableName); $insertdata = array('active' => 'N'); diff --git a/application/helpers/admin/activate_helper.php b/application/helpers/admin/activate_helper.php index 7b77d1b40a5..b6a88917b8f 100644 --- a/application/helpers/admin/activate_helper.php +++ b/application/helpers/admin/activate_helper.php @@ -394,31 +394,27 @@ function activateSurvey($iSurveyID, $simulate = false) } $anquery = "SELECT autonumber_start FROM {{surveys}} WHERE sid={$iSurveyID}"; - if ($anresult=Yii::app()->db->createCommand($anquery)->query()->readAll()) - { - //if there is an autonumber_start field, start auto numbering here - foreach($anresult as $row) + $iAutoNumberStart=Yii::app()->db->createCommand($anquery)->queryScalar(); + //if there is an autonumber_start field, start auto numbering here + if ($iAutoNumberStart!==false && $iAutoNumberStart>0) + { + if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') { + mssql_drop_primary_index('survey_'.$iSurveyID); + mssql_drop_constraint('id','survey_'.$iSurveyID); + $sQuery = "alter table {{survey_{$iSurveyID}}} drop column id "; + Yii::app()->db->createCommand($sQuery)->execute(); + $sQuery = "alter table {{survey_{$iSurveyID}}} add [id] int identity({$iAutoNumberStart},1)"; + Yii::app()->db->createCommand($sQuery)->execute(); + } + elseif (Yii::app()->db->driverName=='pgsql') { - if ($row['autonumber_start'] > 0) - { - if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') { - mssql_drop_primary_index('survey_'.$iSurveyID); - mssql_drop_constraint('id','survey_'.$iSurveyID); - $autonumberquery = "alter table {{survey_{$iSurveyID}}} drop column id "; - Yii::app()->db->createCommand($autonumberquery)->execute(); - $autonumberquery = "alter table {{survey_{$iSurveyID}}} add [id] int identity({$row['autonumber_start']},1)"; - Yii::app()->db->createCommand($autonumberquery)->execute(); - } - elseif (Yii::app()->db->driverName=='pgsql') - { - - } - else - { - $autonumberquery = "ALTER TABLE {{survey_{$iSurveyID}}} AUTO_INCREMENT = ".$row['autonumber_start']; - $result = @Yii::app()->db->createCommand($autonumberquery)->execute(); - } - } + $sQuery = "SELECT setval(pg_get_serial_sequence('{{survey_{$iSurveyID}}}', 'id'),{$iAutoNumberStart},false);"; + $result = @Yii::app()->db->createCommand($sQuery)->execute(); + } + else + { + $sQuery = "ALTER TABLE {{survey_{$iSurveyID}}} AUTO_INCREMENT = {$iAutoNumberStart}"; + $result = @Yii::app()->db->createCommand($sQuery)->execute(); } } diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 60927f06305..f2067b69dfe 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -5205,6 +5205,8 @@ private function _UpdateValuesInDatabase($updatedValues, $finished=false) else { $message .= $this->gT("Unable to insert record into survey table"); // TODO - add SQL error? + echo submitfailed(''); // TODO - report SQL error? + } //Insert Row for Timings, if needed if ($this->surveyOptions['savetimings']) { diff --git a/application/views/admin/survey/deactivateSurvey_view.php b/application/views/admin/survey/deactivateSurvey_view.php index 419cf2803e8..77a15229fff 100644 --- a/application/views/admin/survey/deactivateSurvey_view.php +++ b/application/views/admin/survey/deactivateSurvey_view.php @@ -34,7 +34,7 @@ -

" />

+

@@ -51,7 +51,7 @@

eT("The responses to this survey are no longer available using LimeSurvey."); ?>

- gT("The responses table has been renamed to: ")." ".$sNewSurveyTableName; ?>
+ gT("The responses table has been renamed to: ")." ".$sNewSurveyTableName; ?>
gT("The tokens table associated with this survey has been renamed to: ")." $tnewtable
";