private function _surveyexport($action, $iSurveyID) { if ($action == "exportstructurexml") { $fn = "limesurvey_survey_{$iSurveyID}.lss"; $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT"); echo surveyGetXMLData($iSurveyID); exit; } elseif ($action == "exportstructurequexml") { if (isset($surveyprintlang) && !empty($surveyprintlang)) { $quexmllang = $surveyprintlang; } else { $quexmllang = Survey::model()->findByPk($iSurveyID)->language; } if (!(isset($noheader) && $noheader == TRUE)) { $fn = "survey_{$iSurveyID}_{$quexmllang}.xml"; $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT"); echo quexml_export($iSurveyID, $quexmllang); exit; } } elseif ($action == 'exportstructuretsv') { $this->_exporttsv($iSurveyID); } elseif ($action == "exportarchive") { $this->_exportarchive($iSurveyID); } }
/** * Function responsible to import/copy a survey based on $action. * * @access public * @return void */ public function copy() { $importsurvey = ""; $action = Yii::app()->request->getParam('action'); $iSurveyID = sanitize_int(Yii::app()->request->getParam('sid')); if ($action == "importsurvey" || $action == "copysurvey") { // Start the HTML if ($action == 'importsurvey') { $aData['sHeader'] = gT("Import survey data"); $aData['sSummaryHeader'] = gT("Survey structure import summary"); $importingfrom = "http"; $aPathInfo = pathinfo($_FILES['the_file']['name']); if (isset($aPathInfo['extension'])) { $sExtension = $aPathInfo['extension']; } else { $sExtension = ""; } } elseif ($action == 'copysurvey') { $aData['sHeader'] = gT("Copy survey"); $aData['sSummaryHeader'] = gT("Survey copy summary"); } // Start traitment and messagebox $aData['bFailed'] = false; // Put a var for continue if ($action == 'importsurvey') { $sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(20) . '.' . $sExtension; if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $sFullFilepath)) { $aData['sErrorMessage'] = sprintf(gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."), Yii::app()->getConfig('tempdir')); $aData['bFailed'] = true; } if (!$aData['bFailed'] && (strtolower($sExtension) != 'csv' && strtolower($sExtension) != 'lss' && strtolower($sExtension) != 'txt' && strtolower($sExtension) != 'lsa')) { $aData['sErrorMessage'] = sprintf(gT("Import failed. You specified an invalid file type '%s'."), $sExtension); $aData['bFailed'] = true; } } elseif ($action == 'copysurvey') { $iSurveyID = sanitize_int(Yii::app()->request->getParam('copysurveylist')); $aExcludes = array(); $sNewSurveyName = Yii::app()->request->getPost('copysurveyname'); if (Yii::app()->request->getPost('copysurveyexcludequotas') == "on") { $aExcludes['quotas'] = true; } if (Yii::app()->request->getPost('copysurveyexcludepermissions') == "on") { $aExcludes['permissions'] = true; } if (Yii::app()->request->getPost('copysurveyexcludeanswers') == "on") { $aExcludes['answers'] = true; } if (Yii::app()->request->getPost('copysurveyresetconditions') == "on") { $aExcludes['conditions'] = true; } if (Yii::app()->request->getPost('copysurveyresetstartenddate') == "on") { $aExcludes['dates'] = true; } if (!$iSurveyID) { $aData['sErrorMessage'] = gT("No survey ID has been provided. Cannot copy survey"); $aData['bFailed'] = true; } elseif (!Survey::model()->findByPk($iSurveyID)) { $aData['sErrorMessage'] = gT("Invalid survey ID"); $aData['bFailed'] = true; } elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export')) { $aData['sErrorMessage'] = gT("You don't have sufficient permissions."); $aData['bFailed'] = true; } else { Yii::app()->loadHelper('export'); $copysurveydata = surveyGetXMLData($iSurveyID, $aExcludes); } } // Now, we have the survey : start importing Yii::app()->loadHelper('admin/import'); if ($action == 'importsurvey' && !$aData['bFailed']) { $aImportResults = importSurveyFile($sFullFilepath, isset($_POST['translinksfields'])); if (is_null($aImportResults) || !empty($aImportResults['error'])) { $aData['sErrorMessage'] = isset($aImportResults['error']) ? $aImportResults['error'] : gt("Unknow error."); $aData['bFailed'] = true; } } elseif ($action == 'copysurvey' && !$aData['bFailed']) { $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName, sanitize_int(App()->request->getParam('copysurveyid')), isset($_POST['translinksfields'])); 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 ($action == 'importsurvey' && isset($sFullFilepath)) { unlink($sFullFilepath); } if (!$aData['bFailed']) { $aData['action'] = $action; $aData['sLink'] = $this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $aImportResults['newsid']); $aData['aImportResults'] = $aImportResults; } } $this->_renderWrappedTemplate('survey', 'importSurvey_view', $aData); }
private function _surveyexport($action, $iSurveyID) { viewHelper::disableHtmlLogging(); if ($action == "exportstructurexml") { $fn = "limesurvey_survey_{$iSurveyID}.lss"; $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT"); echo surveyGetXMLData($iSurveyID); exit; } elseif ($action == "exportstructurejson") { $fn = "limesurvey_survey_{$iSurveyID}.json"; $this->_addHeaders($fn, "application/json", "Mon, 26 Jul 1997 05:00:00 GMT"); $surveyInXmlFormat = surveyGetXMLData($iSurveyID); // now convert this xml into json format and then return echo _xmlToJson($surveyInXmlFormat); exit; } elseif ($action == "exportstructurequexml") { if (isset($surveyprintlang) && !empty($surveyprintlang)) { $quexmllang = $surveyprintlang; } else { $quexmllang = Survey::model()->findByPk($iSurveyID)->language; } if (!(isset($noheader) && $noheader == TRUE)) { $fn = "survey_{$iSurveyID}_{$quexmllang}.xml"; $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT"); echo quexml_export($iSurveyID, $quexmllang); exit; } } elseif ($action == 'exportstructuretsv') { $this->_exporttsv($iSurveyID); } elseif ($action == "exportarchive") { $this->_exportarchive($iSurveyID); } }
/** * RPC Routine to duplicate a survey * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyXML The XML of the survey to import * @return int The key of the new survey created * */ public function duplicate_survey($sSessionKey, $iSurveyID) { // Check sessionkey if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } // import getSurveyList function Yii::app()->loadHelper('common'); // NOTE: for one language surveys only $surveys = getSurveyList(TRUE, $iSurveyID); // set a defualt name for the new survey if (count($surveys) > 0) { $new_survey_name = $surveys[0]['surveyls_title'] . ' (copy)'; } else { $new_survey_name = 'New Duplicate Survey'; } // now get the actual name foreach ($surveys as $survey) { if ($survey['sid'] == $iSurveyID) { $new_survey_name = $survey['surveyls_title'] . ' (copy)'; } } // you can use this to get the language code if you want //$sLanguageCode = getBaseLanguageFromSurveyID($iSurveyID); // check to make sure there isn't another survey with the same name foreach ($surveys as $survey) { if ($survey['surveyls_title'] == $new_survey_name) { return array('status' => 'Error: A survey with that name already exists'); } } // export functions //Yii::app()->loadHelper('admin/exportresults'); $aExcludes = array(); // $aExcludes['quotas'] = true; // $aExcludes['permissions'] = true; // $aExcludes['answers'] = true; // $aExcludes['conditions'] = true; // $aExcludes['dates'] = true; if (!Survey::model()->findByPk($iSurveyID)) { return array('status' => 'Error: Invalid survey ID'); } elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export')) { return array('status' => 'No permissions'); } else { Yii::app()->loadHelper('export'); $copy_survey_data = surveyGetXMLData($iSurveyID, $aExcludes); } // Now, we have the survey lets start importing Yii::app()->loadHelper('admin/import'); // XMLImportSurvey(fileName,data,newName,translateInsertansTags,convertInvalidQuestionCodes) $result = XMLImportSurvey('', $copy_survey_data, $new_survey_name, NULL, TRUE); // (might get used one day) // 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']); // } // the error is set in the XMLImportSurvey function if (isset($result['error'])) { return FALSE; } else { return TRUE; } }
/** * Function responsible to import/copy a survey based on $action. * * @access public * @return void */ public function copy() { $importsurvey = ""; $action = $_POST['action']; @($iSurveyID = $_POST['sid']); if ($action == "importsurvey" || $action == "copysurvey") { if (@$_POST['copysurveytranslinksfields'] == "on" || @$_POST['translinksfields'] == "on") { $sTransLinks = true; } $clang = $this->getController()->lang; // Start the HTML if ($action == 'importsurvey') { $aData['sHeader'] = $clang->gT("Import survey data"); $aData['sSummaryHeader'] = $clang->gT("Survey structure import summary"); $importingfrom = "http"; } elseif ($action == 'copysurvey') { $aData['sHeader'] = $clang->gT("Copy survey"); $aData['sSummaryHeader'] = $clang->gT("Survey copy summary"); } // Start traitment and messagebox $aData['bFailed'] = false; // Put a var for continue if ($action == 'importsurvey') { $the_full_file_path = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(20) . '_' . $_FILES['the_file']['name']; if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $the_full_file_path)) { $aData['sErrorMessage'] = sprintf($clang->gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."), Yii::app()->getConfig('tempdir')); $aData['bFailed'] = true; } else { $sFullFilepath = $the_full_file_path; $aPathInfo = pathinfo($sFullFilepath); if (isset($aPathInfo['extension'])) { $sExtension = $aPathInfo['extension']; } else { $sExtension = ""; } } if (!$aData['bFailed'] && (strtolower($sExtension) != 'csv' && strtolower($sExtension) != 'lss' && strtolower($sExtension) != 'txt' && strtolower($sExtension) != 'lsa')) { $aData['sErrorMessage'] = sprintf($clang->gT("Import failed. You specified an invalid file type '%s'."), $sExtension); $aData['bFailed'] = true; } } elseif ($action == 'copysurvey') { $iSurveyID = sanitize_int($_POST['copysurveylist']); $exclude = array(); if (get_magic_quotes_gpc()) { $sNewSurveyName = stripslashes($_POST['copysurveyname']); } else { $sNewSurveyName = Yii::app()->request->getPost('copysurveyname'); } if (Yii::app()->request->getPost('copysurveyexcludequotas') == "on") { $exclude['quotas'] = true; } if (Yii::app()->request->getPost('copysurveyexcludepermissions') == "on") { $exclude['permissions'] = true; } if (Yii::app()->request->getPost('copysurveyexcludeanswers') == "on") { $exclude['answers'] = true; } if (Yii::app()->request->getPost('copysurveyresetconditions') == "on") { $exclude['conditions'] = true; } if (!$iSurveyID) { $aData['sErrorMessage'] = $clang->gT("No survey ID has been provided. Cannot copy survey"); $aData['bFailed'] = true; } Yii::app()->loadHelper('export'); $copysurveydata = surveyGetXMLData($iSurveyID, $exclude); } // Now, we have the survey : start importing Yii::app()->loadHelper('admin/import'); if ($action == 'importsurvey' && !$aData['bFailed']) { $aImportResults = importSurveyFile($sFullFilepath, isset($_POST['translinksfields'])); if (is_null($aImportResults)) { $importerror = true; } } elseif ($action == 'copysurvey' && (empty($importerror) || !$importerror)) { $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName); if (!isset($exclude['permissions'])) { Survey_permissions::model()->copySurveyPermissions($iSurveyID, $aImportResults['newsid']); } } else { $importerror = true; } if ($action == 'importsurvey' && isset($sFullFilepath)) { unlink($sFullFilepath); } // if (isset($aImportResults['error']) && $aImportResults['error']) safeDie($aImportResults['error']); if (!$aData['bFailed']) { $aData['action'] = $action; $aData['sLink'] = $this->getController()->createUrl('admin/survey/view/surveyid/' . $aImportResults['newsid']); $aData['aImportResults'] = $aImportResults; } } $this->_renderWrappedTemplate('survey', 'importSurvey_view', $aData); }
/** * Function responsible to import/copy a survey based on $action. * * @access public * @return void */ public function copy() { $action = Yii::app()->request->getParam('action'); $iSurveyID = sanitize_int(Yii::app()->request->getParam('sid')); if ($action == "importsurvey" || $action == "copysurvey") { // Start the HTML $sExtension = ""; if ($action == 'importsurvey') { $aData = array(); $aData['sHeader'] = gT("Import survey data"); $aData['sSummaryHeader'] = gT("Survey structure import summary"); $aPathInfo = pathinfo($_FILES['the_file']['name']); if (isset($aPathInfo['extension'])) { $sExtension = $aPathInfo['extension']; } } elseif ($action == 'copysurvey') { $aData = array(); $aData['sHeader'] = gT("Copy survey"); $aData['sSummaryHeader'] = gT("Survey copy summary"); } // Start traitment and messagebox $aData['bFailed'] = false; // Put a var for continue $sFullFilepath = ''; if ($action == 'importsurvey') { $sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(30) . '.' . $sExtension; if ($_FILES['the_file']['error'] == 1 || $_FILES['the_file']['error'] == 2) { $aData['sErrorMessage'] = sprintf(gT("Sorry, this file is too large. Only files up to %01.2f MB are allowed."), getMaximumFileUploadSize() / 1024 / 1024) . '<br>'; $aData['bFailed'] = true; } elseif (!in_array(strtolower($sExtension), array('lss', 'txt', 'tsv', 'lsa'))) { $aData['sErrorMessage'] = sprintf(gT("Import failed. You specified an invalid file type '%s'."), $sExtension); $aData['bFailed'] = true; } elseif ($aData['bFailed'] || !@move_uploaded_file($_FILES['the_file']['tmp_name'], $sFullFilepath)) { $aData['sErrorMessage'] = gT("An error occurred uploading your file. This may be caused by incorrect permissions for the application /tmp folder."); $aData['bFailed'] = true; } } elseif ($action == 'copysurvey') { $iSurveyID = sanitize_int(Yii::app()->request->getParam('copysurveylist')); $aExcludes = array(); $sNewSurveyName = Yii::app()->request->getPost('copysurveyname'); if (Yii::app()->request->getPost('copysurveyexcludequotas') == "1") { $aExcludes['quotas'] = true; } if (Yii::app()->request->getPost('copysurveyexcludepermissions') == "1") { $aExcludes['permissions'] = true; } if (Yii::app()->request->getPost('copysurveyexcludeanswers') == "1") { $aExcludes['answers'] = true; } if (Yii::app()->request->getPost('copysurveyresetconditions') == "1") { $aExcludes['conditions'] = true; } if (Yii::app()->request->getPost('copysurveyresetstartenddate') == "1") { $aExcludes['dates'] = true; } if (!$iSurveyID) { $aData['sErrorMessage'] = gT("No survey ID has been provided. Cannot copy survey"); $aData['bFailed'] = true; } elseif (!Survey::model()->findByPk($iSurveyID)) { $aData['sErrorMessage'] = gT("Invalid survey ID"); $aData['bFailed'] = true; } elseif (!Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent', 'export')) { $aData['sErrorMessage'] = gT("We are sorry but you don't have permissions to do this."); $aData['bFailed'] = true; } else { Yii::app()->loadHelper('export'); $copysurveydata = surveyGetXMLData($iSurveyID, $aExcludes); } } // Now, we have the survey : start importing Yii::app()->loadHelper('admin/import'); if ($action == 'importsurvey' && !$aData['bFailed']) { $aImportResults = importSurveyFile($sFullFilepath, Yii::app()->request->getPost('translinksfields') == '1'); if (is_null($aImportResults)) { $aImportResults = array('error' => gT("Unknown error while reading the file, no survey created.")); } } elseif ($action == 'copysurvey' && !$aData['bFailed']) { $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName, sanitize_int(App()->request->getParam('copysurveyid')), Yii::app()->request->getPost('copysurveytranslinksfields') == '1'); 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 ($action == 'importsurvey' && isset($sFullFilepath) && file_exists($sFullFilepath)) { unlink($sFullFilepath); } if (!$aData['bFailed']) { $aData['aImportResults'] = $aImportResults; $aData['action'] = $action; if (isset($aImportResults['newsid'])) { $aData['sLink'] = $this->getController()->createUrl('admin/survey/sa/view/surveyid/' . $aImportResults['newsid']); } } } $this->_renderWrappedTemplate('survey', 'importSurvey_view', $aData); }