本文整理汇总了PHP中db_execute_num函数的典型用法代码示例。如果您正苦于以下问题:PHP db_execute_num函数的具体用法?PHP db_execute_num怎么用?PHP db_execute_num使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_execute_num函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importQuestion
/**
*
* Enter description here...
* @param $surveyid
* @param $sMod
* @param $newGroup
* @return unknown_type
*/
function importQuestion($surveyid, $sMod, $newGroup = false)
{
global $connect;
global $dbprefix;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
include "lsrc.config.php";
$newsid = $surveyid;
$this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", START OK {$dbprefix} ");
//$getGidSql = "SELECT gid FROM {$dbprefix} ";
$getGidSql = "SELECT gid\r\n\t FROM {$dbprefix}groups \r\n\t WHERE sid=" . $surveyid . " AND language='" . GetBaseLanguageFromSurveyID($surveyid) . "'\r\n\t ORDER BY gid desc ";
$getGidRs = db_execute_num($getGidSql);
$gidRow = $getGidRs->FetchRow();
$gid = $gidRow[0];
if ($gid == '') {
$this->debugLsrc("No Group for importing the question, available!");
return "No Group for importing the question, available! Import failed.";
}
if ($newGroup === true) {
++$gid;
}
$the_full_file_path = $queDir . $sMod . ".csv";
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK {$the_full_file_path} ");
$handle = fopen($the_full_file_path, "r");
while (!feof($handle)) {
$buffer = fgets($handle, 10240);
//To allow for very long survey welcomes (up to 10k)
$bigarray[] = $buffer;
}
fclose($handle);
// Now we try to determine the dataformat of the survey file.
if (substr($bigarray[1], 0, 24) == "# SURVEYOR QUESTION DUMP" && substr($bigarray[4], 0, 29) == "# http://www.phpsurveyor.org/") {
$importversion = 100;
// version 1.0 file
} elseif (substr($bigarray[1], 0, 24) == "# SURVEYOR QUESTION DUMP" && substr($bigarray[4], 0, 37) == "# http://phpsurveyor.sourceforge.net/") {
$importversion = 99;
// Version 0.99 file or older - carries a different URL
} elseif (substr($bigarray[0], 0, 26) == "# LimeSurvey Question Dump" || substr($bigarray[0], 0, 27) == "# PHPSurveyor Question Dump") {
// Wow.. this seems to be a >1.0 version file - these files carry the version information to read in line two
$importversion = substr($bigarray[1], 12, 3);
} else {
// $importquestion .= "<strong><font color='red'>".("Error")."</font></strong>\n";
// $importquestion .= ("This file is not a LimeSurvey question file. Import failed.")."\n";
// $importquestion .= "</font></td></tr></table>\n";
// $importquestion .= "</body>\n</html>\n";
// unlink($the_full_file_path);
return "This is not a Limesurvey question file. Import failed";
}
// if ($importversion != $dbversionnumber)
// {
//// $importquestion .= "<strong><font color='red'>".("Error")."</font></strong>\n";
//// $importquestion .= ("Sorry, importing questions is limited to the same version. Import failed.")."\n";
//// $importquestion .= "</font></td></tr></table>\n";
//// $importquestion .= "</body>\n</html>\n";
//// unlink($the_full_file_path);
// return;
// }
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
for ($i = 0; $i < 9; $i++) {
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
//QUESTIONS
if (array_search("# ANSWERS TABLE\n", $bigarray)) {
$stoppoint = array_search("# ANSWERS TABLE\n", $bigarray);
} elseif (array_search("# ANSWERS TABLE\r\n", $bigarray)) {
$stoppoint = array_search("# ANSWERS TABLE\r\n", $bigarray);
} else {
$stoppoint = count($bigarray) - 1;
}
for ($i = 0; $i <= $stoppoint + 1; $i++) {
if ($i < $stoppoint - 2) {
$questionarray[] = $bigarray[$i];
}
unset($bigarray[$i]);
}
$bigarray = array_values($bigarray);
$this->debugLsrc("wir sind in " . __FILE__ . " - " . __FUNCTION__ . " Line " . __LINE__ . ", OK ");
//ANSWERS
if (array_search("# LABELSETS TABLE\n", $bigarray)) {
$stoppoint = array_search("# LABELSETS TABLE\n", $bigarray);
} elseif (array_search("# LABELSETS TABLE\r\n", $bigarray)) {
$stoppoint = array_search("# LABELSETS TABLE\r\n", $bigarray);
} else {
$stoppoint = count($bigarray) - 1;
}
for ($i = 0; $i <= $stoppoint + 1; $i++) {
if ($i < $stoppoint - 2) {
$answerarray[] = str_replace("`default`", "`default_value`", $bigarray[$i]);
}
unset($bigarray[$i]);
}
//.........这里部分代码省略.........
示例2: generate_statistics
//.........这里部分代码省略.........
}
}
if($q2show=='all' )
{
$summarySql=" SELECT gid, parent_qid, qid, type "
." FROM {$dbprefix}questions WHERE parent_qid=0"
." AND sid=$surveyid ";
$summaryRs = db_execute_assoc($summarySql);
foreach($summaryRs as $field)
{
$myField = $surveyid."X".$field['gid']."X".$field['qid'];
// Multiple choice get special treatment
if ($field['type'] == "M") {$myField = "M$myField";}
if ($field['type'] == "P") {$myField = "P$myField";}
//numerical input will get special treatment (arihtmetic mean, standard derivation, ...)
if ($field['type'] == "N") {$myField = "N$myField";}
if ($field['type'] == "|") {$myField = "|$myField";}
if ($field['type'] == "Q") {$myField = "Q$myField";}
// textfields get special treatment
if ($field['type'] == "S" || $field['type'] == "T" || $field['type'] == "U"){$myField = "T$myField";}
//statistics for Date questions are not implemented yet.
if ($field['type'] == "D") {$myField = "D$myField";}
if ($field['type'] == "F" || $field['type'] == "H")
{
//Get answers. We always use the answer code because the label might be too long elsewise
$query = "SELECT code, answer FROM ".db_table_name("answers")." WHERE qid='".$field['qid']."' AND scale_id=0 AND language='{$language}' ORDER BY sortorder, answer";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
$counter2=0;
//check all the answers
while ($row=$result->FetchRow())
{
$myField = "$myField{$row[0]}";
}
//$myField = "{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]";
}
if($q2show=='all')
$summary[]=$myField;
//$allfields[]=$myField;
}
}
else
{
// This gets all the 'to be shown questions' from the POST and puts these into an array
if (!is_array($q2show))
$summary=returnglobal('summary');
else
$summary = $q2show;
//print_r($_POST);
//if $summary isn't an array we create one
if (isset($summary) && !is_array($summary))
{
$summary = explode("+", $summary);
}
}
示例3: strlen
$count = $result->RecordCount();
//loop through all answers. if there are 3 items to rate there will be 3 statistics
for ($i=1; $i<=$count; $i++)
{
$myfield2 = "R" . $myfield . $i . "-" . strlen($i);
$allfields[]=$myfield2;
}
break;
//Boilerplate questions are only used to put some text between other questions -> no analysis needed
case "X": //This is a boilerplate question and it has no business in this script
break;
case "1": // MULTI SCALE
//get answers
$query = "SELECT title, question FROM ".db_table_name("questions")." WHERE parent_qid='$flt[0]' AND language='{$language}' ORDER BY question_order";
$result = db_execute_num($query) or safe_die ("Couldn't get answers!<br />$query<br />".$connect->ErrorMsg());
//loop through answers
while ($row=$result->FetchRow())
{
//----------------- LABEL 1 ---------------------
$myfield2 = $myfield . "$row[0]#0";
$allfields[]=$myfield2;
//----------------- LABEL 2 ---------------------
$myfield2 = $myfield . "$row[0]#1";
$allfields[]=$myfield2;
} //end WHILE -> loop through all answers
break;
case "P": //P - Multiple choice with comments
case "M": //M - Multiple choice
示例4: safe_die
."' onclick=\"window.open('{$scriptname}?action=tokens&sid={$surveyid}&subaction=edit&tid=".$brow['tid']."&start={$start}&limit={$limit}&order={$order}', '_top')\" /> ";
}
if (bHasSurveyPermission($surveyid, 'tokens','delete'))
{
$tokenoutput .="<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='{$imageurl}/token_delete.png' title='"
.$clang->gT("Delete token entry")
."' alt='"
.$clang->gT("Delete token entry")
."' onclick=\"if (confirm('".$clang->gT("Are you sure you want to delete this entry?","js")." (".$brow['tid'].")')) {".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=delete&tid=".$brow['tid']."&limit=$limit&start=$start&order=$order")."}\" />";
}
if ($brow['completed'] != "N" && $brow['completed']!="" && $surveyprivate == "N" && $thissurvey['active']=='Y')
{
// Get response Id
$query="SELECT id FROM ".db_table_name('survey_'.$surveyid)." WHERE token='{$brow['token']}' ORDER BY id desc";
$result=db_execute_num($query) or safe_die ("<br />Could not find token!<br />\n" .$connect->ErrorMsg());
list($id) = $result->FetchRow();
// UPDATE button to the tokens display in the MPID Actions column
if ($id)
{
$tokenoutput .= "<input type='image' src='{$imageurl}/token_viewanswer.png' style='height: 16; width: 16px;' onclick=\"window.open('$scriptname?action=browse&sid=$surveyid&subaction=id&id=$id', '_top')\" title='"
.$clang->gT("View/Update last response")
."' alt='"
.$clang->gT("View/Update last response")
."' />\n";
}
}
elseif ($brow['completed'] == "N" && $brow['token'] && $brow['sent'] == "N" && trim($brow['email'])!='' && bHasSurveyPermission($surveyid, 'tokens','update'))
{
$tokenoutput .= "<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='{$imageurl}/token_invite.png' title='"
示例5: elseif
$sec = $median % 60;
$browseoutput .= '<tr><Th>' . $clang->gT('Median: ') . "</th><td>{$min} min. {$sec} sec.</td></tr>";
}
$browseoutput .= '</table>';
} elseif ($subaction == "time") {
$browseoutput .= $surveyoptions;
$browseoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Timings") . "</div>";
$browseoutput .= "Timing saving is disabled or the timing table does not exist. Try to reactivate survey.\n";
} else {
$browseoutput .= $surveyoptions;
$num_total_answers = 0;
$num_completed_answers = 0;
$gnquery = "SELECT count(id) FROM {$surveytable}";
$gnquery2 = "SELECT count(id) FROM {$surveytable} WHERE submitdate IS NOT NULL";
$gnresult = db_execute_num($gnquery);
$gnresult2 = db_execute_num($gnquery2);
while ($gnrow = $gnresult->FetchRow()) {
$num_total_answers = $gnrow[0];
}
while ($gnrow2 = $gnresult2->FetchRow()) {
$num_completed_answers = $gnrow2[0];
}
$browseoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Response summary") . "</div>" . "<p><table class='statisticssummary'>\n" . "<tfoot><tr><th>" . $clang->gT("Total responses:") . "</th><td>" . $num_total_answers . "</td></tr></tfoot>" . "\t<tbody>" . "<tr><th>" . $clang->gT("Full responses:") . "</th><td>" . $num_completed_answers . "</td></tr>" . "<tr><th>" . $clang->gT("Incomplete responses:") . "</th><td>" . ($num_total_answers - $num_completed_answers) . "</td></tr></tbody>" . "</table>";
}
/**
* Supply an array with the responseIds and all files will be added to the zip
* and it will be be spit out on success
*
* @param array $responseIds
* @return ZipArchive
*/
示例6: db_execute_num
{$showQuestion}
});
\$(document).bind('keydown',function(e) {
if (e.keyCode == 9) {
{$showQuestion}
return true;
}
return true;
});
// -->
</script>
EOD;
$answer = $answers[0][1];
//GET HELP
$hquery = "SELECT help FROM {$dbprefix}questions WHERE qid={$ia['0']} AND language='" . $_SESSION['s_lang'] . "'";
$hresult = db_execute_num($hquery) or safe_die($connect->ErrorMsg());
//Checked
$help = "";
while ($hrow = $hresult->FetchRow()) {
$help = $hrow[0];
}
$question = $answers[0][0];
$question['code'] = $answers[0][5];
$question['class'] = question_class($qrows['type']);
$question['essentials'] = 'id="question' . $qrows['qid'] . '"';
$question['sgq'] = $ia[1];
$question['aid'] = 'unknown';
$question['sqid'] = 'unknown';
$question['type'] = $qrows['type'];
if ($qrows['mandatory'] == 'Y') {
$question['man_class'] = ' mandatory';
示例7: datadump
function datadump($table)
{
global $connect;
$result = "#\n";
$result .= "# Table data for {$table}" . "\n";
$result .= "#\n";
$query = db_execute_num("select * from {$table}");
$num_fields = $query->FieldCount();
$aFieldNames = $connect->MetaColumnNames($table, true);
$sFieldNames = implode('`,`', $aFieldNames);
$numrow = $query->RecordCount();
if ($numrow > 0) {
$result .= "INSERT INTO `{$table}` (`{$sFieldNames}`) VALUES";
while ($row = $query->FetchRow()) {
@set_time_limit(5);
$result .= "(";
for ($j = 0; $j < $num_fields; $j++) {
if (isset($row[$j]) && !is_null($row[$j])) {
$row[$j] = addslashes($row[$j]);
$row[$j] = preg_replace("#\n#", "\\n", $row[$j]);
$result .= "\"{$row[$j]}\"";
} else {
$result .= "NULL";
}
if ($j < $num_fields - 1) {
$result .= ",";
}
}
$result .= "),\n";
}
// while
$result = substr($result, 0, -2);
}
return $result . ";\n\n";
}
示例8: GetAttributeValue
/**
* Retrieves the token attribute value from the related token table
*
* @param mixed $surveyid The survey ID
* @param mixed $attrName The token-attribute field name
* @param mixed $token The token code
* @return string The token attribute value (or null on error)
*/
function GetAttributeValue($surveyid, $attrName, $token)
{
global $dbprefix, $connect;
$attrName = strtolower($attrName);
if ($attrName == 'callattempts' || $attrName == 'onappointment' || $attrName == 'perccomplete' || $attrName == 'messagesleft') {
include_once "quexs.php";
$quexs_operator_id = get_operator_id();
$quexs_case_id = get_case_id($quexs_operator_id);
if ($quexs_case_id) {
if ($attrName == 'callattempts') {
return get_call_attempts($quexs_case_id);
} else {
if ($attrName == 'onappointment') {
return is_on_appointment($quexs_case_id, $quexs_operator_id);
} else {
if ($attrName == 'perccomplete') {
return get_percent_complete($quexs_case_id);
} else {
if ($attrName == 'messagesleft') {
return get_messages_left($quexs_case_id);
}
}
}
}
} else {
return 0;
}
} else {
if (!tableExists('tokens_' . $surveyid) || !in_array($attrName, GetTokenConditionsFieldNames($surveyid))) {
return null;
}
}
$sanitized_token = $connect->qstr($token, get_magic_quotes_gpc());
$surveyid = sanitize_int($surveyid);
$query = "SELECT {$attrName} FROM {$dbprefix}tokens_{$surveyid} WHERE token={$sanitized_token}";
$result = db_execute_num($query);
$count = $result->RecordCount();
if ($count != 1) {
return null;
} else {
$row = $result->FetchRow();
return $row[0];
}
}
示例9: buildsurveysession
//.........这里部分代码省略.........
} else {
if (isset($secerror)) {
echo "<span class='error'>" . $secerror . "</span><br />";
}
echo '<div id="wrapper"><p id="tokenmessage">' . $clang->gT("This is a controlled survey. You need a valid token to participate.") . "<br />";
echo $clang->gT("If you have been issued a token, please enter it in the box below and click continue.") . "</p>\n <script type='text/javascript'>var focus_element='#token';</script>\n\t <form id='tokenform' method='get' action='{$publicurl}/index.php'>\n <ul>\n <li>\n <label for='token'>" . $clang->gT("Token") . "</label><input class='text {$kpclass}' id='token' type='text' name='token' />";
echo "<input type='hidden' name='sid' value='" . $surveyid . "' id='sid' />\n\t\t\t\t<input type='hidden' name='lang' value='" . $templang . "' id='lang' />";
if (isset($_GET['newtest']) && $_GET['newtest'] == "Y") {
echo " <input type='hidden' name='newtest' value='Y' id='newtest' />";
}
// If this is a direct Reload previous answers URL, then add hidden fields
if (isset($_GET['loadall']) && isset($_GET['scid']) && isset($_GET['loadname']) && isset($_GET['loadpass'])) {
echo "\n\t\t\t\t\t<input type='hidden' name='loadall' value='" . htmlspecialchars($_GET['loadall']) . "' id='loadall' />\n\t\t\t\t\t<input type='hidden' name='scid' value='" . returnglobal('scid') . "' id='scid' />\n\t\t\t\t\t<input type='hidden' name='loadname' value='" . htmlspecialchars($_GET['loadname']) . "' id='loadname' />\n\t\t\t\t\t<input type='hidden' name='loadpass' value='" . htmlspecialchars($_GET['loadpass']) . "' id='loadpass' />";
}
echo "</li>";
if (function_exists("ImageCreate") && captcha_enabled('surveyaccessscreen', $thissurvey['usecaptcha'])) {
echo "<li>\n\t\t\t <label for='captchaimage'>" . $clang->gT("Security Question") . "</label><img id='captchaimage' src='{$rooturl}/verification.php?sid={$surveyid}' alt='captcha' /><input type='text' size='5' maxlength='3' name='loadsecurity' value='' />\n\t\t </li>";
}
echo "<li>\n <input class='submit' type='submit' value='" . $clang->gT("Continue") . "' />\n </li>\n </ul>\n\t </form></div>";
}
echo templatereplace(file_get_contents("{$thistpl}/endpage.pstpl"));
doFooter();
exit;
} elseif ($tokensexist == 1 && returnglobal('token') && !captcha_enabled('surveyaccessscreen', $thissurvey['usecaptcha'])) {
//check if tokens actually haven't been already used
$areTokensUsed = usedTokens(db_quote(trim(strip_tags(returnglobal('token')))));
//check if token actually does exist
// check also if it is allowed to change survey after completion
if ($thissurvey['alloweditaftercompletion'] == 'Y') {
$tkquery = "SELECT COUNT(*) FROM " . db_table_name('tokens_' . $surveyid) . " WHERE token='" . db_quote(trim(strip_tags(returnglobal('token')))) . "' ";
} else {
$tkquery = "SELECT COUNT(*) FROM " . db_table_name('tokens_' . $surveyid) . " WHERE token='" . db_quote(trim(strip_tags(returnglobal('token')))) . "' AND (completed = 'N' or completed='')";
}
$tkresult = db_execute_num($tkquery);
//Checked
list($tkexist) = $tkresult->FetchRow();
if (!$tkexist || $areTokensUsed && $thissurvey['alloweditaftercompletion'] != 'Y') {
//TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
killSession();
sendcacheheaders();
doHeader();
echo templatereplace(file_get_contents("{$thistpl}/startpage.pstpl"));
echo templatereplace(file_get_contents("{$thistpl}/survey.pstpl"));
echo '<div id="wrapper"><p id="tokenmessage">' . $clang->gT("This is a controlled survey. You need a valid token to participate.") . "<br /><br />\n" . "\t" . $clang->gT("The token you have provided is either not valid, or has already been used.") . "<br />\n" . "\t" . sprintf($clang->gT("For further information please contact %s"), $thissurvey['adminname']) . " (<a href='mailto:{$thissurvey['adminemail']}'>" . "{$thissurvey['adminemail']}</a>)</p></div>\n";
echo templatereplace(file_get_contents("{$thistpl}/endpage.pstpl"));
doFooter();
exit;
}
} elseif ($tokensexist == 1 && returnglobal('token') && captcha_enabled('surveyaccessscreen', $thissurvey['usecaptcha'])) {
// IF CAPTCHA ANSWER IS CORRECT
if (isset($loadsecurity) && isset($_SESSION['secanswer']) && $loadsecurity == $_SESSION['secanswer']) {
//check if tokens actually haven't been already used
$areTokensUsed = usedTokens(db_quote(trim(strip_tags(returnglobal('token')))));
//check if token actually does exist
if ($thissurvey['alloweditaftercompletion'] == 'Y') {
$tkquery = "SELECT COUNT(*) FROM " . db_table_name('tokens_' . $surveyid) . " WHERE token='" . db_quote(trim(sanitize_xss_string(strip_tags(returnglobal('token'))))) . "'";
} else {
$tkquery = "SELECT COUNT(*) FROM " . db_table_name('tokens_' . $surveyid) . " WHERE token='" . db_quote(trim(sanitize_xss_string(strip_tags(returnglobal('token'))))) . "' AND (completed = 'N' or completed='')";
}
$tkresult = db_execute_num($tkquery);
//Checked
list($tkexist) = $tkresult->FetchRow();
if (!$tkexist || $areTokensUsed && $thissurvey['alloweditaftercompletion'] != 'Y') {
sendcacheheaders();
doHeader();
//TOKEN DOESN'T EXIST OR HAS ALREADY BEEN USED. EXPLAIN PROBLEM AND EXIT
示例10: CSVImportQuestion
//.........这里部分代码省略.........
$newlid = $connect->Insert_ID("{$dbprefix}labelsets", 'lid');
if ($labelsarray) {
$count = 0;
foreach ($labelsarray as $la) {
$lfieldorders = convertCSVRowToArray($labelsarray[0], ',', '"');
$lfieldcontents = convertCSVRowToArray($la, ',', '"');
if ($count == 0) {
$count++;
continue;
}
// Combine into one array with keys and values since its easier to handle
$labelrowdata = array_combine($lfieldorders, $lfieldcontents);
$labellid = $labelrowdata['lid'];
if ($importversion <= 132) {
$labelrowdata["assessment_value"] = (int) $labelrowdata["code"];
}
if ($labellid == $oldlid) {
$labelrowdata['lid'] = $newlid;
// translate internal links
$labelrowdata['title'] = translink('label', $oldlid, $newlid, $labelrowdata['title']);
$newvalues = array_values($labelrowdata);
$newvalues = array_map(array(&$connect, "qstr"), $newvalues);
// quote everything accordingly
$lainsert = "INSERT INTO {$dbprefix}labels (" . implode(',', array_keys($labelrowdata)) . ") VALUES (" . implode(',', $newvalues) . ")";
//handle db prefix
$liresult = $connect->Execute($lainsert);
$results['labels']++;
}
}
}
//CHECK FOR DUPLICATE LABELSETS
$thisset = "";
$query2 = "SELECT code, title, sortorder, language, assessment_value\n FROM {$dbprefix}labels\n WHERE lid=" . $newlid . "\n ORDER BY language, sortorder, code";
$result2 = db_execute_num($query2) or safe_die("Died querying labelset {$lid}<br />{$query2}<br />" . $connect->ErrorMsg());
while ($row2 = $result2->FetchRow()) {
$thisset .= implode('.', $row2);
}
// while
$newcs = dechex(crc32($thisset) * 1);
unset($lsmatch);
if (isset($csarray)) {
foreach ($csarray as $key => $val) {
if ($val == $newcs) {
$lsmatch = $key;
}
}
}
if (isset($lsmatch)) {
//There is a matching labelset. So, we will delete this one and refer
//to the matched one.
$query = "DELETE FROM {$dbprefix}labels WHERE lid={$newlid}";
$result = $connect->Execute($query) or safe_die("Couldn't delete labels<br />{$query}<br />" . $connect->ErrorMsg());
$query = "DELETE FROM {$dbprefix}labelsets WHERE lid={$newlid}";
$result = $connect->Execute($query) or safe_die("Couldn't delete labelset<br />{$query}<br />" . $connect->ErrorMsg());
$newlid = $lsmatch;
} else {
//There isn't a matching labelset, add this checksum to the $csarray array
$csarray[$newlid] = $newcs;
}
//END CHECK FOR DUPLICATES
$aLIDReplacements[$oldlid] = $newlid;
}
}
// Import questions
if (isset($questionarray) && $questionarray) {
//Assuming we will only import one question at a time we will now find out the maximum question order in this group
示例11: XMLImportLabelsets
function XMLImportLabelsets($sFullFilepath, $options)
{
global $connect, $dbprefix, $clang;
$xml = simplexml_load_file($sFullFilepath);
if ($xml->LimeSurveyDocType != 'Label set') {
safe_die('This is not a valid LimeSurvey label set structure XML file.');
}
$dbversion = (double) $xml->DBVersion;
$csarray = buildLabelSetCheckSumArray();
$aLSIDReplacements = array();
$results['labelsets'] = 0;
$results['labels'] = 0;
$results['warnings'] = array();
// Import labels table ===================================================================================
$tablename = $dbprefix . 'labelsets';
foreach ($xml->labelsets->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$oldlsid = $insertdata['lid'];
unset($insertdata['lid']);
// save the old qid
// Insert the new question
$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['labelsets']++;
$newlsid = $connect->Insert_ID($tablename, "lid");
// save this for later
$aLSIDReplacements[$oldlsid] = $newlsid;
// add old and new lsid to the mapping array
}
// Import labels table ===================================================================================
$tablename = $dbprefix . 'labels';
if (isset($xml->labels->rows->row)) {
foreach ($xml->labels->rows->row as $row) {
$insertdata = array();
foreach ($row as $key => $value) {
$insertdata[(string) $key] = (string) $value;
}
$insertdata['lid'] = $aLSIDReplacements[$insertdata['lid']];
$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['labels']++;
}
}
//CHECK FOR DUPLICATE LABELSETS
if (isset($_POST['checkforduplicates'])) {
foreach (array_values($aLSIDReplacements) as $newlid) {
$thisset = "";
$query2 = "SELECT code, title, sortorder, language, assessment_value\n FROM " . db_table_name('labels') . "\n WHERE lid=" . $newlid . "\n ORDER BY language, sortorder, code";
$result2 = db_execute_num($query2) or safe_die("Died querying labelset {$lid}<br />{$query2}<br />" . $connect->ErrorMsg());
while ($row2 = $result2->FetchRow()) {
$thisset .= implode('.', $row2);
}
// while
$newcs = dechex(crc32($thisset) * 1);
unset($lsmatch);
if (isset($csarray) && $options['checkforduplicates'] == 'on') {
foreach ($csarray as $key => $val) {
if ($val == $newcs) {
$lsmatch = $key;
}
}
}
if (isset($lsmatch)) {
//There is a matching labelset. So, we will delete this one and refer
//to the matched one.
$query = "DELETE FROM {$dbprefix}labels WHERE lid={$newlid}";
$result = $connect->Execute($query) or safe_die("Couldn't delete labels<br />{$query}<br />" . $connect->ErrorMsg());
$results['labels'] = $results['labels'] - $connect->Affected_Rows();
$query = "DELETE FROM {$dbprefix}labelsets WHERE lid={$newlid}";
$result = $connect->Execute($query) or safe_die("Couldn't delete labelset<br />{$query}<br />" . $connect->ErrorMsg());
$results['labelsets']--;
$newlid = $lsmatch;
$results['warnings'][] = $clang->gT("Label set was not imported because the same label set already exists.") . " " . sprintf($clang->gT("Existing LID: %s"), $newlid);
}
}
//END CHECK FOR DUPLICATES
}
return $results;
}
示例12: activateSurvey
//.........这里部分代码省略.........
case '*':
// Equation
$createsurvey .= " X";
// could be anything, from numeric to a long message, so default to text
break;
default:
$createsurvey .= " C(5)";
}
}
$timingsfieldmap = createTimingsFieldMap($surveyid);
$createsurveytimings .= '`' . implode("` F DEFAULT '0',\n`", array_keys($timingsfieldmap)) . "` F DEFAULT '0'";
// If last question is of type MCABCEFHP^QKJR let's get rid of the ending coma in createsurvey
$createsurvey = rtrim($createsurvey, ",\n") . "\n";
// Does nothing if not ending with a comma
$tabname = "{$dbprefix}survey_{$postsid}";
# not using db_table_name as it quotes the table name (as does CreateTableSQL)
$taboptarray = array('mysql' => 'ENGINE=' . $databasetabletype . ' CHARACTER SET utf8 COLLATE utf8_unicode_ci', 'mysqli' => 'ENGINE=' . $databasetabletype . ' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createsurvey, $taboptarray);
if (isset($savetimings) && $savetimings == "TRUE") {
$tabnametimings = $tabname . '_timings';
$sqlarraytimings = $dict->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray);
}
$execresult = $dict->ExecuteSQLArray($sqlarray, 1);
//queXS Addition - add an index on the token
$createtokenindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token'));
$dict->ExecuteSQLArray($createtokenindex, false) or safe_die("Failed to create token index<br />{$createtokenindex}<br /><br />" . $connect->ErrorMsg());
if ($execresult == 0 || $execresult == 1) {
$activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n" . "<div class='header ui-widget-header'>" . $clang->gT("Activate Survey") . " ({$surveyid})</div>\n" . "<div class='warningheader'>" . $clang->gT("Survey could not be actived.") . "</div>\n" . "<p>" . $clang->gT("Database error:") . "\n <font color='red'>" . $connect->ErrorMsg() . "</font>\n" . "<pre>{$createsurvey}</pre>\n\n <a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>\n</div>";
}
if ($execresult != 0 && $execresult != 1) {
$anquery = "SELECT autonumber_start FROM {$dbprefix}surveys WHERE sid={$postsid}";
if ($anresult = db_execute_assoc($anquery)) {
//if there is an autonumber_start field, start auto numbering here
while ($row = $anresult->FetchRow()) {
if ($row['autonumber_start'] > 0) {
if ($databasetype == 'odbc_mssql' || $databasetype == 'odbtp' || $databasetype == 'mssql_n' || $databasetype == 'mssqlnative') {
mssql_drop_primary_index('survey_' . $postsid);
mssql_drop_constraint('id', 'survey_' . $postsid);
$autonumberquery = "alter table {$dbprefix}survey_{$postsid} drop column id ";
$connect->Execute($autonumberquery);
$autonumberquery = "alter table {$dbprefix}survey_{$postsid} add [id] int identity({$row['autonumber_start']},1)";
$connect->Execute($autonumberquery);
} else {
$autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = " . $row['autonumber_start'];
$result = @$connect->Execute($autonumberquery);
}
}
}
if (isset($savetimings) && $savetimings == "TRUE") {
$dict->ExecuteSQLArray($sqlarraytimings, 1);
// create a timings table for this survey
}
}
$activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n";
$activateoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Activate Survey") . " ({$surveyid})</div>\n";
$activateoutput .= "<div class='successheader'>" . $clang->gT("Survey has been activated. Results table has been successfully created.") . "</div><br /><br />\n";
// create the survey directory where the uploaded files can be saved
if ($createsurveydirectory) {
if (!file_exists($uploaddir . "/surveys/" . $postsid . "/files")) {
if (!mkdir($uploaddir . "/surveys/" . $postsid . "/files", 0777, true)) {
$activateoutput .= "<div class='warningheader'>" . $clang->gT("The required directory for saving the uploaded files couldn't be created. Please check file premissions on the limesurvey/upload/surveys directory.") . "</div>";
} else {
file_put_contents($uploaddir . "/surveys/" . $postsid . "/files/index.html", '<html><head></head><body></body></html>');
}
}
}
$acquery = "UPDATE {$dbprefix}surveys SET active='Y' WHERE sid=" . $surveyid;
$acresult = $connect->Execute($acquery);
$query = db_select_tables_like("{$dbprefix}old\\_tokens\\_" . $surveyid . "\\_%");
$result = db_execute_num($query) or safe_die("Couldn't get old table list<br />" . $query . "<br />" . $connect->ErrorMsg());
$tcount = $result->RecordCount();
if ($tcount == 0) {
$sTokenActivationLink = "{$scriptname}?action=tokens&sid={$postsid}&createtable=Y";
} else {
$sTokenActivationLink = "{$scriptname}?action=tokens&sid={$postsid}";
}
if (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE") {
$activateoutput .= $clang->gT("This survey allows public registration. A token table must also be created.") . "<br /><br />\n";
$activateoutput .= "<input type='submit' value='" . $clang->gT("Initialise tokens") . "' onclick=\"" . get2post($sTokenActivationLink) . "\" />\n";
} else {
$activateoutput .= $clang->gT("This survey is now active, and responses can be recorded.") . "<br /><br />\n";
//queXS Removal
// $activateoutput .= "<strong>".$clang->gT("Open-access mode").":</strong> ".$clang->gT("No invitation code is needed to complete the survey.")."<br />".$clang->gT("You can switch to the closed-access mode by initialising a token table with the button below.")."<br /><br />\n";
// $activateoutput .= "<input type='submit' value='".$clang->gT("Switch to closed-access mode")."' onclick=\"".get2post($sTokenActivationLink)."\" />\n";
// $activateoutput .= "<input type='submit' value='".$clang->gT("No, thanks.")."' onclick=\"".get2post("$scriptname?sid={$postsid}")."\" />\n";
}
$activateoutput .= "</div><br /> \n";
$lsrcOutput = true;
}
if ($scriptname == 'lsrc') {
if ($lsrcOutput == true) {
return true;
} else {
return $activateoutput;
}
} else {
return $activateoutput;
}
}
示例13: db_rename_table
$sOldTable = "survey_{$iSurveyID}";
$sNewTable = "old_survey_{$iSurveyID}_{$date}";
$deactivatequery = db_rename_table(db_table_name_nq($sOldTable), db_table_name_nq($sNewTable));
$deactivateresult = $connect->Execute($deactivatequery) or die("Couldn't make backup of the survey table. Please try again. The database reported the following error:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br />");
if ($databasetype == 'postgres') {
// If you deactivate a postgres table you have to rename the according sequence too and alter the id field to point to the changed sequence
$deactivatequery = db_rename_table($sOldTable . '_id_seq', $sNewTable . '_id_seq');
$deactivateresult = $connect->Execute($deactivatequery) or die("Couldn't make backup of the survey table. Please try again. The database reported the following error:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br /><br />Survey was not deactivated either.<br /><br /><a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>");
$setsequence = "ALTER TABLE {$sNewTable} ALTER COLUMN id SET DEFAULT nextval('{$sNewTable}_id_seq'::regclass);";
$deactivateresult = $connect->Execute($setsequence) or die("Couldn't make backup of the survey table. Please try again. The database reported the following error:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br /><br />Survey was not deactivated either.<br /><br /><a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>");
}
}
}
/***** Check for activate token tables with missing survey entry **/
$sQuery = db_select_tables_like("{$dbprefix}tokens\\_%");
$aResult = db_execute_num($sQuery) or safe_die("Couldn't get list of token tables from database<br />{$query}<br />" . $connect->ErrorMsg());
while ($aRow = $aResult->FetchRow()) {
$tablename = substr($aRow[0], strlen($dbprefix));
$iSurveyID = substr($tablename, strpos($tablename, '_') + 1);
$qquery = "SELECT sid FROM {$dbprefix}surveys WHERE sid='{$iSurveyID}'";
$qresult = $connect->Execute($qquery) or safe_die("Couldn't check survey table for sid<br />{$qquery}<br />" . $connect->ErrorMsg());
$qcount = $qresult->RecordCount();
if ($qcount == 0) {
$date = date('YmdHis') . rand(1, 1000);
$sOldTable = "tokens_{$iSurveyID}";
$sNewTable = "old_tokens_{$iSurveyID}_{$date}";
$deactivatequery = db_rename_table(db_table_name_nq($sOldTable), db_table_name_nq($sNewTable));
if ($databasetype == 'postgres') {
// If you deactivate a postgres table you have to rename the according sequence too and alter the id field to point to the changed sequence
$sOldTableJur = db_table_name_nq($sOldTable);
$deactivatequery = db_rename_table(db_table_name_nq($sOldTable), db_table_name_nq($sNewTable) . '_tid_seq');
示例14: retrieveAnswers
/**
* This function returns an array containing the "question/answer" html display
* and a list of the question/answer fieldnames associated. It is called from
* question.php, group.php or survey.php
*
* @param mixed $ia
* @param mixed $notanswered
* @param mixed $notvalidated
* @param mixed $filenotvalidated
* @return mixed
*/
function retrieveAnswers($ia, $notanswered=null, $notvalidated=null, $filenotvalidated=null)
{
//globalise required config variables
global $dbprefix, $clang; //These are from the config-defaults.php file
global $thissurvey, $gl; //These are set by index.php
global $connect;
//DISPLAY
$display = $ia[7];
//QUESTION NAME
$name = $ia[0];
$qtitle=$ia[3];
//Replace INSERTANS statements with previously provided answers;
$qtitle=dTexts::run($qtitle);
//GET HELP
$hquery="SELECT help FROM {$dbprefix}questions WHERE qid=$ia[0] AND language='".$_SESSION['s_lang']."'";
$hresult=db_execute_num($hquery) or safe_die($connect->ErrorMsg()); //Checked
$help="";
while ($hrow=$hresult->FetchRow()) {$help=$hrow[0];}
//A bit of housekeeping to stop PHP Notices
$answer = "";
if (!isset($_SESSION[$ia[1]])) {$_SESSION[$ia[1]] = "";}
$qidattributes=getQuestionAttributes($ia[0],$ia[4]);
//echo "<pre>";print_r($qidattributes);echo "</pre>";
//Create the question/answer html
// Previously in limesurvey, it was virtually impossible to control how the start of questions were formatted.
// this is an attempt to allow users (or rather system admins) some control over how the starting text is formatted.
$number = isset($ia[9]) ? $ia[9] : '';
$question_text = array(
'all' => '' // All has been added for backwards compatibility with templates that use question_start.pstpl (now redundant)
,'text' => $qtitle
,'code' => $ia[2]
,'number' => $number
,'help' => ''
,'mandatory' => ''
,'man_message' => ''
,'valid_message' => ''
,'file_valid_message' => ''
,'class' => ''
,'man_class' => ''
,'input_error_class' => ''// provides a class.
,'essentials' => ''
);
switch ($ia[4])
{
case 'X': //BOILERPLATE QUESTION
$values = do_boilerplate($ia);
break;
case '5': //5 POINT CHOICE radio-buttons
$values = do_5pointchoice($ia);
break;
case 'D': //DATE
$values = do_date($ia);
break;
case 'L': //LIST drop-down/radio-button list
$values = do_list_radio($ia);
if ($qidattributes['hide_tip']==0)
{
$qtitle .= "<br />\n<span class=\"questionhelp\">"
. $clang->gT('Choose one of the following answers').'</span>';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
case '!': //List - dropdown
$values=do_list_dropdown($ia);
if ($qidattributes['hide_tip']==0)
{
$qtitle .= "<br />\n<span class=\"questionhelp\">"
. $clang->gT('Choose one of the following answers').'</span>';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
case 'O': //LIST WITH COMMENT drop-down/radio-button list + textarea
$values=do_listwithcomment($ia);
if (count($values[1]) > 1 && $qidattributes['hide_tip']==0)
{
$qtitle .= "<br />\n<span class=\"questionhelp\">"
. $clang->gT('Choose one of the following answers').'</span>';
$question_text['help'] = $clang->gT('Choose one of the following answers');
}
break;
//.........这里部分代码省略.........
示例15: fixorder
/**
* Function rewrites the sortorder for a label set
*
* @param mixed $lid Label set ID
*/
function fixorder($lid) {
global $dbprefix, $connect, $labelsoutput;
$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']));
foreach ($lslanguages as $lslanguage)
{
$query = "SELECT lid, code, title, sortorder FROM ".db_table_name('labels')." WHERE lid=? and language=? ORDER BY sortorder, code";
$result = db_execute_num($query, array($lid,$lslanguage)) or safe_die("Can't read labels table: $query // (lid=$lid, language=$lslanguage) ".$connect->ErrorMsg());
$position=0;
while ($row=$result->FetchRow())
{
$position=sprintf("%05d", $position);
$query2="UPDATE ".db_table_name('labels')." SET sortorder='$position' WHERE lid=? AND code=? AND title=? AND language='$lslanguage' ";
$result2=$connect->Execute($query2, array ($row[0], $row[1], $row[2])) or safe_die ("Couldn't update sortorder<br />$query2<br />".$connect->ErrorMsg());
$position++;
}
}
}