diff --git a/application/helpers/remotecontrol/remotecontrol_handle.php b/application/helpers/remotecontrol/remotecontrol_handle.php index d1a64b7a4b4..a1fcc56d27d 100644 --- a/application/helpers/remotecontrol/remotecontrol_handle.php +++ b/application/helpers/remotecontrol/remotecontrol_handle.php @@ -244,6 +244,73 @@ public function import_survey($sSessionKey, $sImportData, $sImportDataType, $sNe } /** + * RPC Routine to copy a survey. + * + * @access public + * @param string $sSessionKey Auth credentials + * @param int $iSurveyID_org Id of the source survey + * @param string $sNewname name of the new survey + * @return On success: new $iSurveyID in array['newsid']. On failure array with error information + * */ + public function copy_survey($sSessionKey, $iSurveyID_org, $sNewname ) + { + $iSurveyID = (int) $iSurveyID_org; + if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key'); + $aData['bFailed'] = false; // Put a var for continue + if (!$iSurveyID) + { + $aData['sErrorMessage'] = "No survey ID has been provided. Cannot copy survey"; + $aData['bFailed'] = true; + } + elseif(!Survey::model()->findByPk($iSurveyID)) + { + $aData['sErrorMessage'] = "Invalid survey ID"; + $aData['bFailed'] = true; + } + elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export')) + { + $aData['sErrorMessage'] = "You don't have sufficient permissions."; + $aData['bFailed'] = true; + } + else + { + $aExcludes = array(); + $sNewSurveyName = $sNewname; + $aExcludes['dates'] = true; + $btranslinksfields=true; + Yii::app()->loadHelper('export'); + $copysurveydata = surveyGetXMLData($iSurveyID, $aExcludes); + if($copysurveydata) + { + Yii::app()->loadHelper('admin/import'); + $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName,NULL,$btranslinksfields); + if (isset($aExcludes['conditions'])) + { + Question::model()->updateAll(array('relevance'=>'1'),'sid='.$aImportResults['newsid']); + QuestionGroup::model()->updateAll(array('grelevance'=>'1'),'sid='.$aImportResults['newsid']); + } + if (!isset($aExcludes['permissions'])) + { + Permission::model()->copySurveyPermissions($iSurveyID,$aImportResults['newsid']); + } + } + else + { + $aData['bFailed']=true; + } + } + if($aData['bFailed']) + { + return array('status' => 'Copy failed','error'=> $aData['sErrorMessage']); + } + else + { + return array('status' => 'OK','newsid'=>$aImportResults['newsid']); + } + } + + /** + * RPC Routine to get survey properties. * Get properties of a survey * * All internal properties of a survey are available.