本文整理汇总了PHP中db_switchIDInsert函数的典型用法代码示例。如果您正苦于以下问题:PHP db_switchIDInsert函数的具体用法?PHP db_switchIDInsert怎么用?PHP db_switchIDInsert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_switchIDInsert函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade_tables143
function upgrade_tables143()
{
global $modifyoutput, $dbprefix, $connect;
$aQIDReplacements = array();
$answerquery = "select a.*, q.sid, q.gid from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and q.type in ('L','O','!') and a.default_value='Y'";
$answerresult = db_execute_assoc($answerquery);
if (!$answerresult) {
return "Database Error";
} else {
while ($row = $answerresult->FetchRow()) {
modify_database("", "INSERT INTO {$dbprefix}defaultvalues (qid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},0," . db_quoteall($row['language']) . ",''," . db_quoteall($row['code']) . ")");
echo $modifyoutput;
flush();
ob_flush();
}
}
// Convert answers to subquestions
$answerquery = "select a.*, q.sid, q.gid, q.type from {$dbprefix}answers a,{$dbprefix}questions q where a.qid=q.qid and a.language=q.language and q.type in ('1','A','B','C','E','F','H','K',';',':','M','P','Q')";
$answerresult = db_execute_assoc($answerquery);
if (!$answerresult) {
return "Database Error";
} else {
while ($row = $answerresult->FetchRow()) {
$insertarray = array();
if (isset($aQIDReplacements[$row['qid'] . '_' . $row['code']])) {
$insertarray['qid'] = $aQIDReplacements[$row['qid'] . '_' . $row['code']];
db_switchIDInsert('questions', true);
}
$insertarray['sid'] = $row['sid'];
$insertarray['gid'] = $row['gid'];
$insertarray['parent_qid'] = $row['qid'];
$insertarray['type'] = $row['type'];
$insertarray['title'] = $row['code'];
$insertarray['question'] = $row['answer'];
$insertarray['question_order'] = $row['sortorder'];
$insertarray['language'] = $row['language'];
$tablename = "{$dbprefix}questions";
$query = $connect->GetInsertSQL($tablename, $insertarray);
modify_database("", $query);
echo $modifyoutput;
flush();
ob_flush();
if (!isset($insertarray['qid'])) {
$aQIDReplacements[$row['qid'] . '_' . $row['code']] = $connect->Insert_ID("{$dbprefix}questions", "qid");
$iSaveSQID = $aQIDReplacements[$row['qid'] . '_' . $row['code']];
} else {
$iSaveSQID = $insertarray['qid'];
db_switchIDInsert('questions', false);
}
if (($row['type'] == 'M' || $row['type'] == 'P') && $row['default_value'] == 'Y') {
modify_database("", "INSERT INTO {$dbprefix}defaultvalues (qid, sqid, scale_id,language,specialtype,defaultvalue) VALUES ({$row['qid']},{$iSaveSQID},0," . db_quoteall($row['language']) . ",'','Y')");
echo $modifyoutput;
flush();
ob_flush();
}
}
}
modify_database("", "delete {$dbprefix}answers from {$dbprefix}answers LEFT join {$dbprefix}questions ON {$dbprefix}answers.qid={$dbprefix}questions.qid where {$dbprefix}questions.type in ('1','F','H','M','P','W','Z')");
echo $modifyoutput;
flush();
ob_flush();
// Convert labels to answers
$answerquery = "select qid ,type ,lid ,lid1, language from {$dbprefix}questions where parent_qid=0 and type in ('1','F','H','M','P','W','Z')";
$answerresult = db_execute_assoc($answerquery);
if (!$answerresult) {
return "Database Error";
} else {
while ($row = $answerresult->FetchRow()) {
$labelquery = "Select * from {$dbprefix}labels where lid={$row['lid']} and language=" . db_quoteall($row['language']);
$labelresult = db_execute_assoc($labelquery);
while ($lrow = $labelresult->FetchRow()) {
modify_database("", "INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, assessment_value) VALUES ({$row['qid']}," . db_quoteall($lrow['code']) . "," . db_quoteall($lrow['title']) . ",{$lrow['sortorder']}," . db_quoteall($lrow['language']) . ",{$lrow['assessment_value']})");
echo $modifyoutput;
flush();
ob_flush();
//$labelids[]
}
if ($row['type'] == '1') {
$labelquery = "Select * from {$dbprefix}labels where lid={$row['lid1']} and language=" . db_quoteall($row['language']);
$labelresult = db_execute_assoc($labelquery);
while ($lrow = $labelresult->FetchRow()) {
modify_database("", "INSERT INTO {$dbprefix}answers (qid, code, answer, sortorder, language, scale_id, assessment_value) VALUES ({$row['qid']}," . db_quoteall($lrow['code']) . "," . db_quoteall($lrow['title']) . ",{$lrow['sortorder']}," . db_quoteall($lrow['language']) . ",1,{$lrow['assessment_value']})");
echo $modifyoutput;
flush();
ob_flush();
}
}
}
}
// Convert labels to subquestions
$answerquery = "select * from {$dbprefix}questions where parent_qid=0 and type in (';',':')";
$answerresult = db_execute_assoc($answerquery);
if (!$answerresult) {
return "Database Error";
} else {
while ($row = $answerresult->FetchRow()) {
$labelquery = "Select * from {$dbprefix}labels where lid={$row['lid']} and language=" . db_quoteall($row['language']);
$labelresult = db_execute_assoc($labelquery);
while ($lrow = $labelresult->FetchRow()) {
$insertarray = array();
//.........这里部分代码省略.........
示例2: unset
}
}
if ($insertstyle == "renumber") {
unset($fielddata['id']);
}
if (isset($fielddata['id'])) {
db_switchIDInsert("survey_{$surveyid}", true);
}
// try again, without the 'id' field.
$insert = "INSERT INTO {$surveytable}\n";
$insert .= "(" . implode(", ", array_keys($fielddata)) . ")\n";
$insert .= "VALUES\n";
$insert .= "(" . implode(", ", array_values($fielddata)) . ")";
$result = $connect->Execute($insert);
if (isset($fielddata['id'])) {
db_switchIDInsert("survey_{$surveyid}", false);
}
if (!$result) {
$vvoutput .= "<div class='warningheader'>\n{$insert}" . "<br />" . sprintf($clang->gT("Import Failed on Record %d because [%s]"), $recordcount, htmlspecialchars(utf8_encode($connect->ErrorMsg()))) . "</div>\n";
} else {
$importcount++;
}
}
}
if ($noid == "noid" || $insertstyle == "renumber") {
$vvoutput .= "<br /><i><strong><font color='red'>" . $clang->gT("Important Note:") . "<br />" . $clang->gT("Do NOT refresh this page, as this will import the file again and produce duplicates") . "</font></strong></i><br /><br />";
}
$vvoutput .= $clang->gT("Total records imported:") . " " . $importcount . "<br /><br />";
$vvoutput .= "[<a href='admin.php?action=browse&sid={$surveyid}'>" . $clang->gT("Browse Responses") . "</a>]";
$vvoutput .= "</div><br /> ";
}
示例3: modlabelsetanswers
function modlabelsetanswers($lid)
{
global $dbprefix, $connect, $clang, $labelsoutput, $databasetype, $filterxsshtml,$postsortorder;
$qulabelset = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid='$lid'";
$rslabelset = db_execute_assoc($qulabelset) or safe_die($connect->ErrorMsg());
$rwlabelset=$rslabelset->FetchRow();
$lslanguages=explode(" ", trim($rwlabelset['languages']));
if (!isset($_POST['method'])) {
$_POST['method'] = $clang->gT("Save");
}
switch($_POST['method'])
{
case $clang->gT("Add new label", "unescaped"):
if (isset($_POST['insertcode']) && $_POST['insertcode']!='')
{
$_SESSION['nextlabelcode']=getNextCode($_POST['insertcode']);
$_POST['insertcode'] = db_quoteall($_POST['insertcode'],true);
// check that the code doesn't exist yet
$query = "SELECT code FROM ".db_table_name('labels')." WHERE lid='$lid' AND code=".$_POST['insertcode'];
$result = $connect->Execute($query);
$codeoccurences=$result->RecordCount();
if ($codeoccurences == 0)
{
$query = "select max(sortorder) as maxorder from ".db_table_name('labels')." where lid='$lid'";
$result = $connect->Execute($query);
$newsortorder=sprintf("%05d", $result->fields['maxorder']+1);
if ($filterxsshtml)
{
require_once("../classes/inputfilter/class.inputfilter_clean.php");
$myFilter = new InputFilter('','',1,1,1);
$_POST['inserttitle']=$myFilter->process($_POST['inserttitle']);
}
else
{
$_POST['inserttitle'] = html_entity_decode($_POST['inserttitle'], ENT_QUOTES, "UTF-8");
}
// Fix bug with FCKEditor saving strange BR types
$_POST['inserttitle']=fix_FCKeditor_text($_POST['inserttitle']);
$_POST['inserttitle'] = db_quoteall($_POST['inserttitle'],true);
$_POST['insertassessmentvalue']=(int)$_POST['insertassessmentvalue'];
foreach ($lslanguages as $lslanguage)
{
db_switchIDInsert('labels',true);
$query = "INSERT INTO ".db_table_name('labels')." (lid, code, title, sortorder,language, assessment_value) VALUES ($lid, {$_POST['insertcode']}, {$_POST['inserttitle']}, '$newsortorder','$lslanguage',{$_POST['insertassessmentvalue']})";
if (!$result = $connect->Execute($query))
{
$labelsoutput.= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Failed to insert label", "js")." - ".$query." - ".$connect->ErrorMsg()."\")\n //-->\n</script>\n";
}
db_switchIDInsert('labels',false);
}
}
else
{
$labelsoutput.= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("This label code is already used in this labelset. Please choose another code or rename the existing one.", "js")."\")\n //-->\n</script>\n";
}
}
break;
// Save all labels with one button
case $clang->gT("Save Changes", "unescaped"):
//Determine autoids by evaluating the hidden field
$sortorderids=explode(' ', trim($_POST['sortorderids']));
$codeids=explode(' ', trim($_POST['codeids']));
$count=0;
// Quote each code_codeid first
foreach ($codeids as $codeid)
{
$_POST['code_'.$codeid] = db_quoteall($_POST['code_'.$codeid],true);
if (isset($_POST['oldcode_'.$codeid])) $_POST['oldcode_'.$codeid] = db_quoteall($_POST['oldcode_'.$codeid],true);
// Get the code values to check for duplicates
$codevalues[] = $_POST['code_'.$codeid];
}
// Check that there is no code duplicate
if (count(array_unique($codevalues)) == count($codevalues))
{
if ($filterxsshtml)
{
require_once("../classes/inputfilter/class.inputfilter_clean.php");
$myFilter = new InputFilter('','',1,1,1);
}
foreach ($sortorderids as $sortorderid)
{
$orderid=substr($sortorderid,strrpos($sortorderid,'_')+1,20);
foreach ($lslanguages as $langid)
{
$sortorderid = $langid . '_' . $orderid;
if ($filterxsshtml)
{
$_POST['title_'.$sortorderid]=$myFilter->process($_POST['title_'.$sortorderid]);
}
else
{
$_POST['title_'.$sortorderid] = html_entity_decode($_POST['title_'.$sortorderid], ENT_QUOTES, "UTF-8");
//.........这里部分代码省略.........
示例4: updateset
function updateset($lid)
{
global $dbprefix, $connect, $labelsoutput, $databasetype;
// Get added and deleted languagesid arrays
if (isset($_POST['languageids'])) {
$postlanguageids = sanitize_languagecodeS($_POST['languageids']);
}
if (isset($_POST['label_name'])) {
$postlabel_name = sanitize_labelname($_POST['label_name']);
}
$newlanidarray = explode(" ", trim($postlanguageids));
$postlanguageids = db_quoteall($postlanguageids, true);
$postlabel_name = db_quoteall($postlabel_name, true);
$oldlangidsarray = array();
$query = "SELECT languages FROM " . db_table_name('labelsets') . " WHERE lid=" . $lid;
$result = db_execute_assoc($query);
if ($result) {
while ($row = $result->FetchRow()) {
$oldlangids = $row['languages'];
}
$oldlangidsarray = explode(" ", trim($oldlangids));
}
$addlangidsarray = array_diff($newlanidarray, $oldlangidsarray);
$dellangidsarray = array_diff($oldlangidsarray, $newlanidarray);
// If new languages are added, create labels' codes and sortorder for the new languages
$query = "SELECT code,sortorder,assessment_value FROM " . db_table_name('labels') . " WHERE lid=" . $lid . " GROUP BY code,sortorder,assessment_value";
$result = db_execute_assoc($query);
if ($result) {
while ($row = $result->FetchRow()) {
$oldcodesarray[$row['code']] = array('sortorder' => $row['sortorder'], 'assessment_value' => $row['assessment_value']);
}
}
if (isset($oldcodesarray) && count($oldcodesarray) > 0) {
foreach ($addlangidsarray as $addedlangid) {
foreach ($oldcodesarray as $oldcode => $olddata) {
$sqlvalues[] = " ({$lid}, '{$oldcode}', '{$olddata['sortorder']}', '{$addedlangid}', '{$olddata['assessment_value']}' )";
}
}
}
if (isset($sqlvalues)) {
db_switchIDInsert('labels', true);
foreach ($sqlvalues as $sqlline) {
$query = "INSERT INTO " . db_table_name('labels') . " (lid,code,sortorder,language,assessment_value) VALUES " . $sqlline;
$result = db_execute_assoc($query);
if (!$result) {
$labelsoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"" . $clang->gT("Failed to Copy already defined labels to added languages", "js") . " - " . $query . " - " . $connect->ErrorMsg() . "\")\n //-->\n</script>\n";
}
}
db_switchIDInsert('labels', false);
}
// If languages are removed, delete labels for these languages
$sqlwherelang = '';
foreach ($dellangidsarray as $dellangid) {
$sqlwherelang .= " OR language='" . $dellangid . "'";
}
if ($sqlwherelang) {
$query = "DELETE FROM " . db_table_name('labels') . " WHERE lid={$lid} AND (" . trim($sqlwherelang, ' OR') . ")";
$result = db_execute_assoc($query);
if (!$result) {
$labelsoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"" . $clang->gT("Failed to delete labels for removed languages", "js") . " - " . $query . " - " . $connect->ErrorMsg() . "\")\n //-->\n</script>\n";
}
}
// Update the label set itself
$query = "UPDATE " . db_table_name('labelsets') . " SET label_name={$postlabel_name}, languages={$postlanguageids} WHERE lid={$lid}";
if (!($result = $connect->Execute($query))) {
$labelsoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"" . $clang->gT("Update of Label Set failed", "js") . " - " . $query . " - " . $connect->ErrorMsg() . "\")\n //-->\n</script>\n";
}
}
示例5: db_table_name
if (isset($oldcodes[$scale_id][$position]) && $codes[$scale_id][$position] !== $oldcodes[$scale_id][$position]) {
$query = 'UPDATE ' . db_table_name('conditions') . ' SET cfieldname="+' . $surveyid . 'X' . $gid . 'X' . $qid . db_quote($codes[$scale_id][$position]) . '" WHERE cqid=' . $qid . ' AND cfieldname="+' . $surveyid . 'X' . $gid . 'X' . $qid . db_quote($oldcodes[$scale_id][$position]) . '"';
$connect->execute($query);
$query = 'UPDATE ' . db_table_name('conditions') . ' SET value="' . db_quote($codes[$scale_id][$position]) . '" WHERE cqid=' . $qid . ' AND cfieldname="' . $surveyid . 'X' . $gid . 'X' . $qid . '" AND value="' . $oldcodes[$scale_id][$position] . '"';
$connect->execute($query);
}
} else {
if (!isset($insertqid[$scale_id][$position])) {
$query = 'INSERT into ' . db_table_name('questions') . ' (sid, gid, question_order, title, question, parent_qid, language, scale_id) values (' . $surveyid . ',' . $gid . ',' . ($position + 1) . ',' . db_quoteall($codes[$scale_id][$position]) . ',' . db_quoteall($subquestionvalue) . ',' . $qid . ',' . db_quoteall($language) . ',' . $scale_id . ')';
$connect->execute($query);
$insertqid[$scale_id][$position] = $connect->Insert_Id(db_table_name_nq('questions'), "qid");
} else {
db_switchIDInsert('questions', true);
$query = 'INSERT into ' . db_table_name('questions') . ' (qid, sid, gid, question_order, title, question, parent_qid, language, scale_id) values (' . $insertqid[$scale_id][$position] . ',' . $surveyid . ',' . $gid . ',' . ($position + 1) . ',' . db_quoteall($codes[$scale_id][$position]) . ',' . db_quoteall($subquestionvalue) . ',' . $qid . ',' . db_quoteall($language) . ',' . $scale_id . ')';
$connect->execute($query);
db_switchIDInsert('questions', false);
}
}
$position++;
}
}
}
LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
//include("surveytable_functions.php");
//surveyFixColumns($surveyid);
$_SESSION['flashmessage'] = $clang->gT("Subquestions were successfully saved.");
$action = 'editsubquestions';
} elseif (($action == "updatesurveysettingsandeditlocalesettings" || $action == "updatesurveysettings") && bHasSurveyPermission($surveyid, 'surveysettings', 'update')) {
$formatdata = getDateFormatData($_SESSION['dateformat']);
if (trim($_POST['expires']) == "") {
$_POST['expires'] = null;
示例6: XMLImportSurvey
/**
* This function imports a LimeSurvey .lss survey XML file
*
* @param mixed $sFullFilepath The full filepath of the uploaded file
*/
function XMLImportSurvey($sFullFilepath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDesiredSurveyId=NULL, $bTranslateInsertansTags=true)
{
global $connect, $dbprefix, $clang, $timeadjust;
$results['error']=false;
if ($sXMLdata == NULL)
{
$xml = simplexml_load_file($sFullFilepath);
} else
{
$xml = simplexml_load_string($sXMLdata);
}
if ($xml->LimeSurveyDocType!='Survey')
{
$results['error'] = $clang->gT("This is not a valid LimeSurvey survey structure XML file.");
return $results;
}
else
{
//$results['error'] = $clang->gT("This is VALID LimeSurvey survey structure XML file.");
//echo $clang->gT("This is VALID LimeSurvey survey structure XML file.");
//return $results;
}
$dbversion = (int) $xml->DBVersion;
$aQIDReplacements=array();
$aQuotaReplacements=array();
$results['defaultvalues']=0;
$results['answers']=0;
$results['surveys']=0;
$results['questions']=0;
$results['subquestions']=0;
$results['question_attributes']=0;
$results['groups']=0;
$results['assessments']=0;
$results['quota']=0;
$results['quotals']=0;
$results['quotamembers']=0;
$results['importwarnings']=array();
$aLanguagesSupported=array();
foreach ($xml->languages->language as $language)
{
$aLanguagesSupported[]=(string)$language;
}
$results['languages']=count($aLanguagesSupported);
// First get an overview of fieldnames - it's not useful for the moment but might be with newer versions
/*
$fieldnames=array();
foreach ($xml->questions->fields->fieldname as $fieldname )
{
$fieldnames[]=(string)$fieldname;
};*/
// Import surveys table ===================================================================================
$tablename=$dbprefix.'surveys';
foreach ($xml->surveys->rows->row as $row)
{
$insertdata=array();
foreach ($row as $key=>$value)
{
$insertdata[(string)$key]=(string)$value;
}
$oldsid=$insertdata['sid'];
if($iDesiredSurveyId!=NULL)
{
$newsid=GetNewSurveyID($iDesiredSurveyId);
}
else
{
$newsid=GetNewSurveyID($oldsid);
}
if ($dbversion<=143)
{
$insertdata['anonymized']=$insertdata['private'];
unset($insertdata['private']);
unset($insertdata['notification']);
}
$insertdata['startdate']=NULL;
//Now insert the new SID and change some values
$insertdata['sid']=$newsid;
//Make sure it is not set active
$insertdata['active']='N';
//Set current user to be the owner
$insertdata['owner_id']=$_SESSION['loginID'];
//Change creation date to import date
$insertdata['datecreated']=$connect->BindTimeStamp(date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust));
db_switchIDInsert('surveys',true);
$query=$connect->GetInsertSQL($tablename,$insertdata);
//.........这里部分代码省略.........
示例7: FixLanguageConsistency
/**
* FixLanguageConsistency() fixes missing groups,questions,answers & assessments for languages on a survey
* @param string $sid - the currently selected survey
* @param string $availlangs - space seperated list of additional languages in survey - if empty all additional languages of a survey are checked against the base language
* @return bool - always returns true
*/
function FixLanguageConsistency($sid, $availlangs = '')
{
global $connect, $databasetype;
if (trim($availlangs) != '') {
$availlangs = sanitize_languagecodeS($availlangs);
$langs = explode(" ", $availlangs);
if ($langs[count($langs) - 1] == "") {
array_pop($langs);
}
} else {
$langs = GetAdditionalLanguagesFromSurveyID($sid);
}
$baselang = GetBaseLanguageFromSurveyID($sid);
$sid = sanitize_int($sid);
$query = "SELECT * FROM " . db_table_name('groups') . " WHERE sid='{$sid}' AND language='{$baselang}' ORDER BY group_order";
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($result->RecordCount() > 0) {
while ($group = $result->FetchRow()) {
foreach ($langs as $lang) {
$query = "SELECT gid FROM " . db_table_name('groups') . " WHERE sid='{$sid}' AND gid='{$group['gid']}' AND language='{$lang}'";
$gresult = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($gresult->RecordCount() < 1) {
db_switchIDInsert('groups', true);
$query = "INSERT INTO " . db_table_name('groups') . " (gid,sid,group_name,group_order,description,language) VALUES('{$group['gid']}','{$group['sid']}'," . db_quoteall($group['group_name']) . ",'{$group['group_order']}'," . db_quoteall($group['description']) . ",'{$lang}')";
$connect->Execute($query) or safe_die($connect->ErrorMsg());
//Checked
db_switchIDInsert('groups', false);
}
}
reset($langs);
}
}
$quests = array();
$query = "SELECT * FROM " . db_table_name('questions') . " WHERE sid='{$sid}' AND language='{$baselang}' ORDER BY question_order";
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($result->RecordCount() > 0) {
while ($question = $result->FetchRow()) {
array_push($quests, $question['qid']);
foreach ($langs as $lang) {
$query = "SELECT qid FROM " . db_table_name('questions') . " WHERE sid='{$sid}' AND qid='{$question['qid']}' AND language='{$lang}'";
$gresult = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($gresult->RecordCount() < 1) {
db_switchIDInsert('questions', true);
$query = "INSERT INTO " . db_table_name('questions') . " (qid,sid,gid,type,title,question,preg,help,other,mandatory,question_order,language, scale_id,parent_qid) VALUES('{$question['qid']}','{$question['sid']}','{$question['gid']}','{$question['type']}'," . db_quoteall($question['title']) . "," . db_quoteall($question['question']) . "," . db_quoteall($question['preg']) . "," . db_quoteall($question['help']) . ",'{$question['other']}','{$question['mandatory']}','{$question['question_order']}','{$lang}',{$question['scale_id']},{$question['parent_qid']})";
$connect->Execute($query) or safe_die($query . "<br />" . $connect->ErrorMsg());
//Checked
db_switchIDInsert('questions', false);
}
}
reset($langs);
}
$sqlans = "";
foreach ($quests as $quest) {
$sqlans .= " OR qid = '" . $quest . "' ";
}
$query = "SELECT * FROM " . db_table_name('answers') . " WHERE language='{$baselang}' and (" . trim($sqlans, ' OR') . ") ORDER BY qid, code";
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($result->RecordCount() > 0) {
while ($answer = $result->FetchRow()) {
foreach ($langs as $lang) {
$query = "SELECT qid FROM " . db_table_name('answers') . " WHERE code='{$answer['code']}' AND qid='{$answer['qid']}' AND language='{$lang}'";
$gresult = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($gresult->RecordCount() < 1) {
db_switchIDInsert('answers', true);
$query = "INSERT INTO " . db_table_name('answers') . " (qid,code,answer,scale_id,sortorder,language,assessment_value) VALUES('{$answer['qid']}'," . db_quoteall($answer['code']) . "," . db_quoteall($answer['answer']) . ",{$answer['scale_id']},'{$answer['sortorder']}','{$lang}',{$answer['assessment_value']})";
$connect->Execute($query) or safe_die($connect->ErrorMsg());
//Checked
db_switchIDInsert('answers', false);
}
}
reset($langs);
}
}
}
$query = "SELECT * FROM " . db_table_name('assessments') . " WHERE sid='{$sid}' AND language='{$baselang}'";
$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($result->RecordCount() > 0) {
while ($assessment = $result->FetchRow()) {
foreach ($langs as $lang) {
$query = "SELECT id FROM " . db_table_name('assessments') . " WHERE sid='{$sid}' AND id='{$assessment['id']}' AND language='{$lang}'";
$gresult = db_execute_assoc($query) or safe_die($connect->ErrorMsg());
//Checked
if ($gresult->RecordCount() < 1) {
db_switchIDInsert('assessments', true);
$query = "INSERT INTO " . db_table_name('assessments') . " (id,sid,scope,gid,name,minimum,maximum,message,language) " . "VALUES('{$assessment['id']}','{$assessment['sid']}'," . db_quoteall($assessment['scope']) . "," . db_quoteall($assessment['gid']) . "," . db_quoteall($assessment['name']) . "," . db_quoteall($assessment['minimum']) . "," . db_quoteall($assessment['maximum']) . "," . db_quoteall($assessment['message']) . ",'{$lang}')";
$connect->Execute($query) or safe_die($connect->ErrorMsg());
//Checked
//.........这里部分代码省略.........
示例8: XMLImportGroup
/**
* This function imports a LimeSurvey .lsg question group XML file
*
* @param mixed $sFullFilepath The full filepath of the uploaded file
* @param mixed $newsid The new survey id - the group will always be added after the last group in the survey
*/
function XMLImportGroup($sFullFilepath, $newsid)
{
global $connect, $dbprefix, $clang;
$aLanguagesSupported = array();
// this array will keep all the languages supported for the survey
$sBaseLanguage = GetBaseLanguageFromSurveyID($newsid);
$aLanguagesSupported[] = $sBaseLanguage;
// adds the base language to the list of supported languages
$aLanguagesSupported = array_merge($aLanguagesSupported, GetAdditionalLanguagesFromSurveyID($newsid));
$xml = @simplexml_load_file($sFullFilepath);
if ($xml == false || $xml->LimeSurveyDocType != 'Group') {
safe_die('This is not a valid LimeSurvey group structure XML file.');
}
$dbversion = (double) $xml->DBVersion;
$aQIDReplacements = array();
$results['defaultvalues'] = 0;
$results['answers'] = 0;
$results['question_attributes'] = 0;
$results['subquestions'] = 0;
$results['conditions'] = 0;
$results['groups'] = 0;
$importlanguages = array();
foreach ($xml->languages->language as $language) {
$importlanguages[] = (string) $language;
}
if (!in_array($sBaseLanguage, $importlanguages)) {
$results['fatalerror'] = $clang->gT("The languages of the imported group file must at least include the base language of this survey.");
return $results;
}
// First get an overview of fieldnames - it's not useful for the moment but might be with newer versions
/*
$fieldnames=array();
foreach ($xml->questions->fields->fieldname as $fieldname )
{
$fieldnames[]=(string)$fieldname;
};*/
// Import group table ===================================================================================
$tablename = $dbprefix . 'groups';
$newgrouporder = $connect->GetOne("SELECT MAX(group_order) AS maxqo FROM " . db_table_name('groups') . " WHERE sid={$newsid}");
if (is_null($newgrouporder)) {
$newgrouporder = 0;
} else {
$newgrouporder++;
}
foreach ($xml->groups->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$oldsid = $insertdata['sid'];
$insertdata['sid'] = $newsid;
$insertdata['group_order'] = $newgrouporder;
$oldgid = $insertdata['gid'];
unset($insertdata['gid']);
// save the old qid
// now translate any links
$insertdata['group_name'] = translink('survey', $oldsid, $newsid, $insertdata['group_name']);
$insertdata['description'] = translink('survey', $oldsid, $newsid, $insertdata['description']);
// Insert the new question
if (isset($aGIDReplacements[$oldgid])) {
$insertdata['gid'] = $aGIDReplacements[$oldgid];
db_switchIDInsert('groups', true);
}
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
$results['groups']++;
if (!isset($aGIDReplacements[$oldgid])) {
$newgid = $connect->Insert_ID($tablename, "gid");
// save this for later
$aGIDReplacements[$oldgid] = $newgid;
// add old and new qid to the mapping array
} else {
db_switchIDInsert('groups', false);
}
}
// Import questions table ===================================================================================
// We have to run the question table data two times - first to find all main questions
// then for subquestions (because we need to determine the new qids for the main questions first)
$tablename = $dbprefix . 'questions';
$results['questions'] = 0;
if (isset($xml->questions)) {
foreach ($xml->questions->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$oldsid = $insertdata['sid'];
$insertdata['sid'] = $newsid;
if (!isset($aGIDReplacements[$insertdata['gid']]) || trim($insertdata['title']) == '') {
continue;
}
// Skip questions with invalid group id
$insertdata['gid'] = $aGIDReplacements[$insertdata['gid']];
$oldqid = $insertdata['qid'];
//.........这里部分代码省略.........
示例9: db_table_name
if (isset($oldcodes[$scale_id][$position]) && $codes[$scale_id][$position] !== $oldcodes[$scale_id][$position]) {
$query = 'UPDATE ' . db_table_name('conditions') . ' SET cfieldname="+' . $surveyid . 'X' . $gid . 'X' . $qid . db_quote($codes[$scale_id][$position]) . '" WHERE cqid=' . $qid . ' AND cfieldname="+' . $surveyid . 'X' . $gid . 'X' . $qid . db_quote($oldcodes[$scale_id][$position]) . '"';
$connect->execute($query);
$query = 'UPDATE ' . db_table_name('conditions') . ' SET value="' . db_quote($codes[$scale_id][$position]) . '" WHERE cqid=' . $qid . ' AND cfieldname="' . $surveyid . 'X' . $gid . 'X' . $qid . '" AND value="' . $oldcodes[$scale_id][$position] . '"';
$connect->execute($query);
}
} else {
if (!isset($insertqid[$scale_id][$position])) {
$query = 'INSERT into ' . db_table_name('questions') . ' (sid, gid, question_order, title, question, parent_qid, language, scale_id) values (' . $surveyid . ',' . $gid . ',' . ($position + 1) . ',' . db_quoteall($codes[$scale_id][$position]) . ',' . db_quoteall($subquestionvalue) . ',' . $qid . ',' . db_quoteall($language) . ',' . $scale_id . ')';
$connect->execute($query);
$insertqid[$scale_id][$position] = $connect->Insert_Id(db_table_name_nq('questions'), "qid");
} else {
db_switchIDInsert('questions', true);
$query = 'INSERT into ' . db_table_name('questions') . ' (qid, sid, gid, question_order, title, question, parent_qid, language, scale_id) values (' . $insertqid[$scale_id][$position] . ',' . $surveyid . ',' . $gid . ',' . ($position + 1) . ',' . db_quoteall($codes[$scale_id][$position]) . ',' . db_quoteall($subquestionvalue) . ',' . $qid . ',' . db_quoteall($language) . ',' . $scale_id . ')';
$connect->execute($query);
db_switchIDInsert('questions', true);
}
}
$position++;
}
}
}
LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
//include("surveytable_functions.php");
//surveyFixColumns($surveyid);
$_SESSION['flashmessage'] = $clang->gT("Subquestions were successfully saved.");
$action = 'editsubquestions';
} elseif (($action == "updatesurveysettingsandeditlocalesettings" || $action == "updatesurveysettings") && bHasSurveyPermission($surveyid, 'surveysettings', 'update')) {
$formatdata = getDateFormatData($_SESSION['dateformat']);
if (trim($_POST['expires']) == "") {
$_POST['expires'] = null;
示例10: XMLImportQuestion
/**
* This function imports a LimeSurvey .lsq question XML file
*
* @param mixed $sFullFilepath The full filepath of the uploaded file
* @param mixed $newsid The new survey id
* @param mixed $newgid The new question group id -the question will always be added after the last question in the group
*/
function XMLImportQuestion($sFullFilepath, $newsid, $newgid)
{
global $connect, $dbprefix, $clang;
$aLanguagesSupported = array();
// this array will keep all the languages supported for the survey
$sBaseLanguage = GetBaseLanguageFromSurveyID($newsid);
$aLanguagesSupported[] = $sBaseLanguage;
// adds the base language to the list of supported languages
$aLanguagesSupported = array_merge($aLanguagesSupported, GetAdditionalLanguagesFromSurveyID($newsid));
$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType != 'Question') {
safe_die('This is not a valid LimeSurvey question structure XML file.');
}
$dbversion = (double) $xml->DBVersion;
$aQIDReplacements = array();
$aSQIDReplacements = array(0 => 0);
$results['defaultvalues'] = 0;
$results['answers'] = 0;
$results['question_attributes'] = 0;
$results['subquestions'] = 0;
$importlanguages = array();
foreach ($xml->languages->language as $language) {
$importlanguages[] = (string) $language;
}
if (!in_array($sBaseLanguage, $importlanguages)) {
$results['fatalerror'] = $clang->gT("The languages of the imported question file must at least include the base language of this survey.");
return $results;
}
// First get an overview of fieldnames - it's not useful for the moment but might be with newer versions
/*
$fieldnames=array();
foreach ($xml->questions->fields->fieldname as $fieldname )
{
$fieldnames[]=(string)$fieldname;
};*/
// Import questions table ===================================================================================
// We have to run the question table data two times - first to find all main questions
// then for subquestions (because we need to determine the new qids for the main questions first)
$tablename = $dbprefix . 'questions';
$newquestionorder = $connect->GetOne("SELECT MAX(question_order) AS maxqo FROM " . db_table_name('questions') . " WHERE sid={$newsid} AND gid={$newgid}") + 1;
if (is_null($newquestionorder)) {
$newquestionorder = 0;
} else {
$newquestionorder++;
}
foreach ($xml->questions->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$oldsid = $insertdata['sid'];
$insertdata['sid'] = $newsid;
$insertdata['gid'] = $newgid;
$insertdata['question_order'] = $newquestionorder;
$oldqid = $insertdata['qid'];
unset($insertdata['qid']);
// save the old qid
// now translate any links
$insertdata['title'] = translink('survey', $oldsid, $newsid, $insertdata['title']);
$insertdata['question'] = translink('survey', $oldsid, $newsid, $insertdata['question']);
$insertdata['help'] = translink('survey', $oldsid, $newsid, $insertdata['help']);
// Insert the new question
if (isset($aQIDReplacements[$oldqid])) {
$insertdata['qid'] = $aQIDReplacements[$oldqid];
db_switchIDInsert('questions', true);
}
$query = $connect->GetInsertSQL($tablename, $insertdata);
$result = $connect->Execute($query) or safe_die($clang->gT("Error") . ": Failed to insert data<br />{$query}<br />\n" . $connect->ErrorMsg());
if (!isset($aQIDReplacements[$oldqid])) {
$newqid = $connect->Insert_ID($tablename, "qid");
// save this for later
$aQIDReplacements[$oldqid] = $newqid;
// add old and new qid to the mapping array
} else {
db_switchIDInsert('questions', false);
}
}
// Import subquestions --------------------------------------------------------------
if (isset($xml->subquestions)) {
foreach ($xml->subquestions->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['sid'] = $newsid;
$insertdata['gid'] = $newgid;
$oldsqid = (int) $insertdata['qid'];
unset($insertdata['qid']);
// save the old qid
$insertdata['parent_qid'] = $aQIDReplacements[(int) $insertdata['parent_qid']];
// remap the parent_qid
// now translate any links
$insertdata['title'] = translink('survey', $oldsid, $newsid, $insertdata['title']);
//.........这里部分代码省略.........