本文整理汇总了PHP中XMLImportQuestion函数的典型用法代码示例。如果您正苦于以下问题:PHP XMLImportQuestion函数的具体用法?PHP XMLImportQuestion怎么用?PHP XMLImportQuestion使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了XMLImportQuestion函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
/**
* Function responsible to import a question.
*
* @access public
* @return void
*/
public function import()
{
$action = returnGlobal('action');
$surveyid = returnGlobal('sid');
$gid = returnGlobal('gid');
$clang = $this->getController()->lang;
$aViewUrls = array();
$aData['display']['menu_bars']['surveysummary'] = 'viewquestion';
$aData['display']['menu_bars']['gid_action'] = 'viewgroup';
if ($action == 'importquestion') {
$sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . $_FILES['the_file']['name'];
$aPathInfo = pathinfo($sFullFilepath);
$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."), Yii::app()->getConfig('tempdir'));
}
// validate that we have a SID and GID
if (!$surveyid) {
$fatalerror .= $clang->gT("No SID (Survey) has been provided. Cannot import question.");
}
if (!$gid) {
$fatalerror .= $clang->gT("No GID (Group) has been provided. Cannot import question");
}
if (isset($fatalerror)) {
unlink($sFullFilepath);
$this->getController()->error($fatalerror);
}
// IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
Yii::app()->loadHelper('admin/import');
if (strtolower($sExtension) == 'csv') {
$aImportResults = CSVImportQuestion($sFullFilepath, $surveyid, $gid);
} elseif (strtolower($sExtension) == 'lsq') {
$aImportResults = XMLImportQuestion($sFullFilepath, $surveyid, $gid);
} else {
$this->getController()->error($clang->gT('Unknown file extension'));
}
fixLanguageConsistency($surveyid);
if (isset($aImportResults['fatalerror'])) {
unlink($sFullFilepath);
$this->getController()->error($aImportResults['fatalerror']);
}
unlink($sFullFilepath);
$aData['aImportResults'] = $aImportResults;
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
$aData['sExtension'] = $sExtension;
$aViewUrls[] = 'import_view';
}
$this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData);
}
示例2: import_question
/**
* RPC Routine to import a question - imports lsq,csv.
*
* @access public
* @param string $sSessionKey
* @param int $iSurveyID The id of the survey that the question will belong
* @param int $iGroupID The id of the group that the question will belong
* @param string $sImportData String containing the BASE 64 encoded data of a lsg,csv
* @param string $sImportDataType lsq,csv
* @param string $sMandatory Optional Mandatory question option (default to No)
* @param string $sNewQuestionTitle Optional new title for the question
* @param string $sNewqQuestion An optional new question
* @param string $sNewQuestionHelp An optional new question help text
* @return array|integer iQuestionID - ID of the new question - Or status
*/
public function import_question($sSessionKey, $iSurveyID, $iGroupID, $sImportData, $sImportDataType, $sMandatory = 'N', $sNewQuestionTitle = NULL, $sNewqQuestion = NULL, $sNewQuestionHelp = NULL)
{
if ($this->_checkSessionKey($sSessionKey)) {
$oSurvey = Survey::model()->findByPk($iSurveyID);
if (!isset($oSurvey)) {
return array('status' => 'Error: Invalid survey ID');
}
if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'update')) {
if ($oSurvey->getAttribute('active') == 'Y') {
return array('status' => 'Error:Survey is Active and not editable');
}
$oGroup = QuestionGroup::model()->findByAttributes(array('gid' => $iGroupID));
if (!isset($oGroup)) {
return array('status' => 'Error: Invalid group ID');
}
$sGroupSurveyID = $oGroup['sid'];
if ($sGroupSurveyID != $iSurveyID) {
return array('status' => 'Error: Missmatch in surveyid and groupid');
}
if (!in_array($sImportDataType, array('csv', 'lsq'))) {
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) == 'lsq') {
$sXMLdata = file_get_contents($sFullFilePath);
$xml = @simplexml_load_string($sXMLdata, 'SimpleXMLElement', LIBXML_NONET);
if (!$xml) {
unlink($sFullFilePath);
return array('status' => 'Error: Invalid LimeSurvey question structure XML ');
}
$aImportResults = XMLImportQuestion($sFullFilePath, $iSurveyID, $iGroupID);
} else {
return array('status' => 'Really Invalid extension');
}
//just for symmetry!
unlink($sFullFilePath);
if (isset($aImportResults['fatalerror'])) {
return array('status' => 'Error: ' . $aImportResults['fatalerror']);
} else {
fixLanguageConsistency($iSurveyID);
$iNewqid = $aImportResults['newqid'];
$oQuestion = Question::model()->findByAttributes(array('sid' => $iSurveyID, 'gid' => $iGroupID, 'qid' => $iNewqid));
if ($sNewQuestionTitle != NULL) {
$oQuestion->setAttribute('title', $sNewQuestionTitle);
}
if ($sNewqQuestion != '') {
$oQuestion->setAttribute('question', $sNewqQuestion);
}
if ($sNewQuestionHelp != '') {
$oQuestion->setAttribute('help', $sNewQuestionHelp);
}
if (in_array($sMandatory, array('Y', 'N'))) {
$oQuestion->setAttribute('mandatory', $sMandatory);
} else {
$oQuestion->setAttribute('mandatory', 'N');
}
try {
$oQuestion->save();
} catch (Exception $e) {
// no need to throw exception
}
return (int) $aImportResults['newqid'];
}
} else {
return array('status' => 'No permission');
}
} else {
return array('status' => 'Invalid session key');
}
}
示例3: import
/**
* Function responsible to import a question.
*
* @access public
* @return void
*/
public function import()
{
$action = returnGlobal('action');
$surveyid = $iSurveyID = returnGlobal('sid');
$gid = returnGlobal('gid');
$aViewUrls = array();
$aData['display']['menu_bars']['surveysummary'] = 'viewquestion';
$aData['display']['menu_bars']['gid_action'] = 'viewgroup';
if ($action == 'importquestion') {
$sFullFilepath = Yii::app()->getConfig('tempdir') . DIRECTORY_SEPARATOR . randomChars(20);
$sExtension = pathinfo($_FILES['the_file']['name'], PATHINFO_EXTENSION);
if (!@move_uploaded_file($_FILES['the_file']['tmp_name'], $sFullFilepath)) {
$fatalerror = sprintf(gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."), Yii::app()->getConfig('tempdir'));
}
// validate that we have a SID and GID
if (!$surveyid) {
$fatalerror .= gT("No SID (Survey) has been provided. Cannot import question.");
}
if (!$gid) {
$fatalerror .= gT("No GID (Group) has been provided. Cannot import question");
}
if (isset($fatalerror)) {
unlink($sFullFilepath);
$message = $fatalerror;
$message .= '<p>
<a class="btn btn-default btn-lg"
href="' . $this->getController()->createUrl('admin/survey/sa/listquestions/surveyid/') . '/' . $surveyid . '">' . gT("Return to question list") . '</a></p>';
$this->_renderWrappedTemplate('super', 'messagebox', array('title' => gT('Error'), 'message' => $message));
die;
}
// IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
Yii::app()->loadHelper('admin/import');
if (strtolower($sExtension) == 'lsq') {
$aImportResults = XMLImportQuestion($sFullFilepath, $surveyid, $gid);
} else {
$this->getController()->error(gT('Unknown file extension'));
}
fixLanguageConsistency($surveyid);
if (isset($aImportResults['fatalerror'])) {
//echo htmlentities($aImportResults['fatalerror']); die();
$message = $aImportResults['fatalerror'];
$message .= '<p>
<a class="btn btn-default btn-lg"
href="' . $this->getController()->createUrl('admin/survey/sa/listquestions/surveyid/') . '/' . $surveyid . '">' . gT("Return to question list") . '</a></p>';
$this->_renderWrappedTemplate('super', 'messagebox', array('title' => gT('Error'), 'message' => $message));
die;
}
unlink($sFullFilepath);
$aData['aImportResults'] = $aImportResults;
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
$aData['sExtension'] = $sExtension;
$aViewUrls[] = 'import_view';
}
/////
$aData['sidemenu']['state'] = false;
$aData['surveyid'] = $iSurveyID;
$surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo;
$aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
$this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData);
}
示例4: returnglobal
$postgid = returnglobal('gid');
}
if (isset($fatalerror)) {
$importquestion .= "<div class='warningheader'>" . $clang->gT("Error") . "</div><br />\n";
$importquestion .= $fatalerror . "<br /><br />\n";
$importquestion .= "<input type='submit' value='" . $clang->gT("Main Admin Screen") . "' onclick=\"window.open('{$scriptname}', '_self')\" /><br /><br />\n";
$importquestion .= "</div>\n";
unlink($sFullFilepath);
return;
}
// IF WE GOT THIS FAR, THEN THE FILE HAS BEEN UPLOADED SUCCESFULLY
$importquestion .= "<div class='successheader'>" . $clang->gT("Success") . "</div> <br />\n" . $clang->gT("File upload succeeded.") . "<br /><br />\n" . $clang->gT("Reading file..") . "<br /><br />\n";
if (strtolower($sExtension) == 'csv') {
$aImportResults = CSVImportQuestion($sFullFilepath, $surveyid, $gid);
} elseif (strtolower($sExtension) == 'lsq') {
$aImportResults = XMLImportQuestion($sFullFilepath, $surveyid, $gid);
} else {
die('Unknown file extension');
}
FixLanguageConsistency($surveyid);
if (isset($aImportResults['fatalerror'])) {
$importquestion .= "<div class='warningheader'>" . $clang->gT("Error") . "</div><br />\n";
$importquestion .= $aImportResults['fatalerror'] . "<br /><br />\n";
$importquestion .= "<input type='submit' value='" . $clang->gT("Main Admin Screen") . "' onclick=\"window.open('{$scriptname}', '_self')\" />\n";
$importquestion .= "</div>\n";
unlink($sFullFilepath);
return;
}
$importquestion .= "<div class='successheader'>" . $clang->gT("Success") . "</div><br />\n" . "<strong><u>" . $clang->gT("Question import summary") . "</u></strong><br />\n" . "<ul style=\"text-align:left;\">\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";
if (strtolower($sExtension) == 'csv') {
$importquestion .= "\t<li>" . $clang->gT("Label sets") . ": " . $aImportResults['labelsets'] . " (" . $aImportResults['labels'] . ")</li>\n";