Пример #1
0
 /**
  * questiongroup::import()
  * Function responsible to import a question group.
  *
  * @access public
  * @return void
  */
 function import()
 {
     $action = $_POST['action'];
     $surveyid = $_POST['sid'];
     $clang = $this->getController()->lang;
     if ($action == 'importgroup') {
         $importgroup = "\n";
         $importgroup .= "\n";
         $sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(20);
         $aPathInfo = pathinfo($_FILES['the_file']['name']);
         $sExtension = $aPathInfo['extension'];
         if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $sFullFilepath)) {
             $fatalerror = sprintf($clang->gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."), $this->config->item('tempdir'));
         }
         // validate that we have a SID
         if (!returnGlobal('sid')) {
             $fatalerror .= $clang->gT("No SID (Survey) has been provided. Cannot import question.");
         }
         if (isset($fatalerror)) {
             @unlink($sFullFilepath);
             $this->getController()->error($fatalerror);
         }
         Yii::app()->loadHelper('admin/import');
         // IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
         if (strtolower($sExtension) == 'csv') {
             $aImportResults = CSVImportGroup($sFullFilepath, $surveyid);
         } elseif (strtolower($sExtension) == 'lsg') {
             $aImportResults = XMLImportGroup($sFullFilepath, $surveyid);
         } else {
             $this->getController()->error('Unknown file extension');
         }
         LimeExpressionManager::SetDirtyFlag();
         // so refreshes syntax highlighting
         fixLanguageConsistency($surveyid);
         if (isset($aImportResults['fatalerror'])) {
             unlink($sFullFilepath);
             $this->getController()->error($aImportResults['fatalerror']);
         }
         unlink($sFullFilepath);
         $aData['display'] = $importgroup;
         $aData['surveyid'] = $surveyid;
         $aData['aImportResults'] = $aImportResults;
         $aData['sExtension'] = $sExtension;
         //$aData['display']['menu_bars']['surveysummary'] = 'importgroup';
         $this->_renderWrappedTemplate('survey/QuestionGroups', 'import_view', $aData);
         // TMSW Condition->Relevance:  call LEM->ConvertConditionsToRelevance() after import
     }
 }
Пример #2
0
 /**
  * RPC Routine to import a group - imports lsg,csv
  *
  * @access public
  * @param string $sSessionKey Auth credentials
  * @param int $iSurveyID The id of the survey that the group will belong
  * @param string $sImportData String containing the BASE 64 encoded data of a lsg,csv
  * @param string $sImportDataType  lsg,csv
  * @param string $sNewGroupName  Optional new name for the group
  * @param string $sNewGroupDescription  Optional new description for the group
  * @return array|integer iGroupID  - ID of the new group or status
  */
 public function import_group($sSessionKey, $iSurveyID, $sImportData, $sImportDataType, $sNewGroupName = NULL, $sNewGroupDescription = NULL)
 {
     if ($this->_checkSessionKey($sSessionKey)) {
         $oSurvey = Survey::model()->findByPk($iSurveyID);
         if (!isset($oSurvey)) {
             return array('status' => 'Error: Invalid survey ID');
         }
         if (hasSurveyPermission($iSurveyID, 'survey', 'update')) {
             if ($oSurvey->getAttribute('active') == 'Y') {
                 return array('status' => 'Error:Survey is active and not editable');
             }
             if (!in_array($sImportDataType, array('csv', 'lsg'))) {
                 return array('status' => 'Invalid extension');
             }
             libxml_use_internal_errors(true);
             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)));
             if (strtolower($sImportDataType) == 'csv') {
                 $aImportResults = CSVImportGroup($sFullFilePath, $iSurveyID);
             } elseif (strtolower($sImportDataType) == 'lsg') {
                 $xml = simplexml_load_file($sFullFilePath);
                 if (!$xml) {
                     unlink($sFullFilePath);
                     return array('status' => 'Error: Invalid LimeSurvey group structure XML ');
                 }
                 $aImportResults = XMLImportGroup($sFullFilePath, $iSurveyID);
             } else {
                 return array('status' => 'Invalid extension');
             }
             //just for symmetry!
             unlink($sFullFilePath);
             if (isset($aImportResults['fatalerror'])) {
                 return array('status' => 'Error: ' . $aImportResults['fatalerror']);
             } else {
                 $iNewgid = $aImportResults['newgid'];
                 $oGroup = Groups::model()->findByAttributes(array('gid' => $iNewgid));
                 $slang = $oGroup['language'];
                 if ($sNewGroupName != '') {
                     $oGroup->setAttribute('group_name', $sNewGroupName);
                 }
                 if ($sNewGroupDescription != '') {
                     $oGroup->setAttribute('description', $sNewGroupDescription);
                 }
                 try {
                     $oGroup->save();
                 } catch (Exception $e) {
                     // no need to throw exception
                 }
                 return (int) $aImportResults['newgid'];
             }
         } else {
             return array('status' => 'No permission');
         }
     } else {
         return array('status' => 'Invalid session key');
     }
 }
Пример #3
0
    $fatalerror .= $clang->gT("No SID (Survey) has been provided. Cannot import question.");
} else {
    $surveyid = returnglobal('sid');
}
if (isset($fatalerror)) {
    $importgroup .= "<div class='warningheader'>" . $clang->gT("Error") . "</div><br />\n";
    $importgroup .= $fatalerror . "<br /><br />\n";
    $importgroup .= "<input type='submit' value='" . $clang->gT("Main Admin Screen") . "' onclick=\"window.open('{$scriptname}', '_self')\" /><br /><br />\n";
    $importgroup .= "</div>\n";
    @unlink($sFullFilepath);
    return;
}
// IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
$importgroup .= "<div class='successheader'>" . $clang->gT("Success") . "</div>&nbsp;<br />\n" . $clang->gT("File upload succeeded.") . "<br /><br />\n" . $clang->gT("Reading file..") . "<br /><br />\n";
if (strtolower($sExtension) == 'csv') {
    $aImportResults = CSVImportGroup($sFullFilepath, $surveyid);
} elseif (strtolower($sExtension) == 'lsg') {
    $aImportResults = XMLImportGroup($sFullFilepath, $surveyid);
} else {
    die('Unknown file extension');
}
FixLanguageConsistency($surveyid);
if (isset($aImportResults['fatalerror'])) {
    $importgroup .= "<div class='warningheader'>" . $clang->gT("Error") . "</div><br />\n";
    $importgroup .= $aImportResults['fatalerror'] . "<br /><br />\n";
    $importgroup .= "<input type='submit' value='" . $clang->gT("Main Admin Screen") . "' onclick=\"window.open('{$scriptname}', '_self')\" />\n";
    $importgroup .= "</div>\n";
    unlink($sFullFilepath);
    return;
}
$importgroup .= "<div class='successheader'>" . $clang->gT("Success") . "</div><br />\n" . "<strong><u>" . $clang->gT("Question group import summary") . "</u></strong><br />\n" . "<ul style=\"text-align:left;\">\n" . "\t<li>" . $clang->gT("Groups") . ": " . $aImportResults['groups'] . "</li>\n" . "\t<li>" . $clang->gT("Questions") . ": " . $aImportResults['questions'] . "</li>\n" . "\t<li>" . $clang->gT("Subquestions") . ": " . $aImportResults['subquestions'] . "</li>\n" . "\t<li>" . $clang->gT("Answers") . ": " . $aImportResults['answers'] . "</li>\n" . "\t<li>" . $clang->gT("Conditions") . ": " . $aImportResults['conditions'] . "</li>\n";