/** * 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); }
/** * 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); }
/** * RPC Routine to import a survey - imports lss,csv,xls or survey zip archive. * * @access public * @param string $sSessionKey Auth Credentials * @param string $sImportData String containing the BASE 64 encoded data of a lss,csv,xls or survey zip archive * @param string $sImportDataType lss,csv,txt or zip * @param string $sNewSurveyName The optional new name of the survey * @param integer $DestSurveyID This is the new ID of the survey - if already used a random one will be taken instead * @return array|integer iSurveyID - ID of the new survey */ public function import_survey($sSessionKey, $sImportData, $sImportDataType, $sNewSurveyName = NULL, $DestSurveyID = NULL) { if ($this->_checkSessionKey($sSessionKey)) { if (Permission::model()->hasGlobalPermission('surveys', 'create')) { if (!in_array($sImportDataType, array('zip', 'csv', 'txt', 'lss'))) { return array('status' => 'Invalid extension'); } Yii::app()->loadHelper('admin/import'); // First save the data to a temporary file $sFullFilePath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(40) . '.' . $sImportDataType; file_put_contents($sFullFilePath, base64_decode(chunk_split($sImportData))); $aImportResults = importSurveyFile($sFullFilePath, true, $sNewSurveyName, $DestSurveyID); unlink($sFullFilePath); if (isset($aImportResults['error'])) { return array('status' => 'Error: ' . $aImportResults['error']); } else { return (int) $aImportResults['newsid']; } } else { return array('status' => 'No permission'); } } else { return array('status' => 'Invalid session key'); } }
/** * 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); }