📄 efunctions.php
字号:
<?
################################################################################
# phpQuestionnaire Version 2.2 #
# Copyright 2003-2005 chumpsoft, inc. March 28, 2005 #
################################################################################
# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS #
################################################################################
function GrabStats ($sid, $stattype, $type) {
$mqquestion = mysql_query("select * from phpQQuestion where SID = \"".ProtectMySQL($sid)."\" order by SortOrder");
$maxcolumn = 1;
while ($maquestion = mysql_fetch_array($mqquestion)) {
$answerarray = ($maquestion["Answer"]) ? split("\|\|\|", $maquestion["Answer"]) : array();
$maxcolumn = (sizeof($answerarray)+1 > $maxcolumn) ? sizeof($answerarray)+1 : $maxcolumn;
if ($maquestion["Type"] != "pagebreak" && $maquestion["Type"] != "htmlcontent") { $qarray[] = $maquestion; }
}
$contents .= "<TABLE BORDER=1>";
for ($i=0; $i<sizeof($qarray); $i++) {
if ($qarray[$i]["Type"] == 'textfield' || $qarray[$i]["Type"] == 'textarea') {
$colspan = $maxcolumn;
$totcolumn = '';
}
else if ($qarray[$i]["Type"] == 'select' || $qarray[$i]["Type"] == 'selectmult') {
$answers = split("\|\|\|",$qarray[$i]["Answer"]);
$colspan = 0;
for ($j=0; $j<sizeof($answers); $j++) {
$tempsplit = split("\|\|", $answers[$j]);
if ($tempsplit[4] != "Y") { continue; }
$colspan++;
}
$totcolumn = "<TD BGCOLOR=#333366> </TD></TR>";
}
else {
$colspan = sizeof(split("\|\|\|",$qarray[$i]["Answer"]));
$totcolumn = "<TD BGCOLOR=#333366> </TD></TR>";
}
$contents .= "<TR><TD COLSPAN=$colspan BGCOLOR=#333366><FONT COLOR=#FFFFFF><B>Question ".($i+1).":</B> ".$qarray[$i]["Question"]."</FONT></TD>$totcolumn</TR>";
$contents .= GrabAnswersEX($sid, $qarray[$i], $stattype, $maxcolumn);
$contents .= "<TR><TD COLSPAN=$maxcolumn BGCOLOR=#EEEEEE> </TD></TR>";
}
$contents .= "</TABLE>";
return $contents;
}
function GrabAnswersEX ($sid, $maquestion, $stattype, $colsize) {
global $phpQlang;
$qid = $maquestion["QID"];
switch ($maquestion["Type"]) {
case "select":
case "selectmult":
case "checkbox":
case "radio":
$totalcount = 0;
$largestcount = 0;
$answerarray = array();
$countarray = array();
$answerid = array();
$temparray = split("\|\|\|", $maquestion["Answer"]);
$diffcolsize = $colsize - sizeof($temparray) - 1;
$contents .= "<TR>";
$icount = 0;
for ($i=0; $i<sizeof($temparray); $i++) {
$tempsplit = split("\|\|", $temparray[$i]);
if ($tempsplit[4] != "Y" && ($maquestion["Type"] == "select" || $maquestion["Type"] == "selectmult")) { continue; }
$answerarray[] = $tempsplit;
$countarray[] = 0;
$bgcolor = ($icount % 2 == 0) ? "#999999" : "#DDDDDD";
if (substr($answerarray[$icount][2],0,11) == "Textfield:(") {
$answerid["O".$answerarray[$icount][1]] = $icount;
$ochoice = substr(substr($answerarray[$icount][2],11),0,-1);
$contents .= "<TD BGCOLOR=$bgcolor>".$ochoice."</TD>";
}
else {
$answerid["N".$answerarray[$icount][1]] = $icount;
$contents .= "<TD BGCOLOR=$bgcolor>".$answerarray[$icount][2]."</TD>";
}
$icount++;
}
$contents .= "<TD BGCOLOR=#336699><FONT COLOR=#FFFFFF><B>".$phpQlang['Total']."</B></FONT></TD></TR>";
$qstring = "select Answer, COUNT(*) as total from phpQAnswer where SID = \"".ProtectMySQL($sid)."\" and QID = \"".ProtectMySQL($qid)."\" GROUP BY Answer";
if ($stattype == 'u' || $stattype == 'v') {
$cletter = ($stattype == 'u') ? 'n' : 'y';
$qstring = "select phpQAnswer.Answer, COUNT(*) as total from phpQAnswer,phpQUser where phpQAnswer.SID = \"".ProtectMySQL($sid)."\" and phpQAnswer.QID = \"".ProtectMySQL($qid)."\" AND phpQAnswer.UID=phpQUser.UID AND phpQUser.EmailConfirm = \"$cletter\" GROUP BY phpQAnswer.Answer";
}
$mqanswercount = mysql_query($qstring);
for ($j=0; $j<mysql_num_rows($mqanswercount); $j++) {
$maanswercount = mysql_fetch_array($mqanswercount);
$qanswers = split("\|\|",$maanswercount['Answer']);
for ($x=0; $x<count($qanswers); $x++) {
if (preg_match("/^O/", $qanswers[$x])) {
$oanswers = split("\|",$qanswers[$x]);
if (isset($answerid[$oanswers[0]])) {
$countarray[$answerid[$oanswers[0]]] += $maanswercount['total'];
}
}
elseif (isset($answerid[$qanswers[$x]])) {
$countarray[$answerid[$qanswers[$x]]] += $maanswercount['total'];
}
}
}
$largestcount = $totalcount = 0;
for ($x=0; $x<count($countarray); $x++) {
$largestcount = ($countarray[$x] > $largestcount) ? $countarray[$x] : $largestcount;
$totalcount += $countarray[$x];
}
$contents .= "<TR>";
for ($k=0; $k<sizeof($countarray); $k++) {
$bgcolor = ($k % 2 == 0) ? "#DDDDDD" : "#FFFFFF";
$contents .= "<TD ALIGN=LEFT BGCOLOR=$bgcolor>".$countarray[$k]."</TD>";
}
$contents .= "<TD ALIGN=LEFT BGCOLOR=#99CCFF>$totalcount</TD></TR>";
$contents .= "<TR>";
for ($k=0; $k<sizeof($answerarray); $k++) {
$bgcolor = ($k % 2 == 0) ? "#DDDDDD" : "#FFFFFF";
$percent = ($totalcount > 0) ? number_format((($countarray[$k] / $totalcount) * 100), 1) : 0;
$contents .= "<TD ALIGN=LEFT BGCOLOR=$bgcolor>".$percent."%</TD>";
}
$contents .= "<TD ALIGN=LEFT BGCOLOR=#99CCFF>100%</TD></TR>";
break;
case "textfield":
case "textarea":
$contents .= "<TR><TD COLSPAN=$colsize BGCOLOR=#DDDDDD>".$phpQlang['PEXNoText']."</TD></TR>";
break;
}
return $contents;
}
function Str2CSV ($mystring) {
$mystring = str_replace("\r", "", $mystring);
$mystring = str_replace("\n", " ", $mystring);
if (strstr($mystring, '"')) {
$mystring = str_replace("\"", "\"\"", $mystring);
}
if (strstr($mystring, '"') || strstr($mystring, ',') || strstr($mystring, "\n")) {
return "\"".$mystring."\",";
}
return $mystring.",";
}
function Str2XML ($mystring) {
$mystring = str_replace("\r", "", $mystring);
$mystring = str_replace("&", "&", $mystring);
$mystring = str_replace("<", "<", $mystring);
$mystring = str_replace(">", ">", $mystring);
$mystring = str_replace('"', """, $mystring);
return $mystring;
}
function Str2SQL ($mystring) {
# is_null() was not around until PHP 4.0.4, so we only use it if we can.
if (function_exists('is_null') && is_null($mystring)) { return 'NULL'; }
return '"'.ProtectMySQL($mystring).'"';
}
function Str2PHPQ ($mystring) {
# is_null() was not around until PHP 4.0.4, so we only use it if we can.
if (function_exists('is_null') && is_null($mystring)) { return '=NULL='; }
return urlencode($mystring);
}
function Terminate ($mystring) {
$mystring = substr($mystring, 0, -1)."\n";
return $mystring;
}
# bit 0 - Unique IP Address
# bit 1 - Cookies
# bit 2 - Verified Email
function VerificationBits ($mystring) {
if (strlen($mystring) != 3) return array(0,0,0);
$bits[0] = substr($mystring, 0, 1);
$bits[1] = substr($mystring, 1, 1);
$bits[2] = substr($mystring, 2, 1);
$sumcheck = $bits[0]+$bits[1]+$bits[2];
if ($sumcheck < 0 || $subcheck > 3)
return array(0,0,0);
else
return $bits;
}
# $answerchoices - list of all answer choices
# 0 - sort order
# 1 - ID without 'N' or 'O'
# 2 - actual answer
# 3 - default 'D' or 'N'
# 4 - selectable 'Y' or 'N'
function FindValue ($key, $answerchoices) {
for ($i=0; $i<sizeof($answerchoices); $i++) {
$value = (substr($answerchoices[$i][2], 0, 11) == "Textfield:(") ? substr($answerchoices[$i][2], 11, -1) : $answerchoices[$i][2];
if (substr($key, 1) == $answerchoices[$i][1])
return $value;
}
return "";
}
function BackupAllData ($sid, $swap) {
$sid = ($sid && is_numeric($sid)) ? (int)$sid : 0;
global $phpQAdmin;
$swap = $swap ? 1 : 0;
$phpQF['Admin'] = array('phpQID','Version','Template','Language','AdminLanguage','SummaryLimit','TextareaLimit','PopupLimit','AdvanceInterface','ListSurvey','TimeOut','CookieDomain');
$phpQF['Answer'] = array('UID','SID','QID','Answer');
$phpQF['Question'] = array('SID','QID','SortOrder','Question','Type','Mult','QuestionStyle','Instructions','Answer','Choose','DefaultAnswer','LargestAID','ColNumb','AnswerInputStyle','AnswerTextStyle','AnswerStyle','Attributes','Required','Summary');
$phpQF['Survey'] = array('SID','AddDate','Name','SurveyUsers','SurveyResults','Width','Indent','QuestionNumb','QuestionStyle','AnswerInputStyle','AnswerTextStyle','AnswerStyle','ErrorStyle','VerifyEmail','EmailFrom','EmailSubject','Template','Language','OnComplete','RedirectURL','Completed','Description','AdminNotes','Active','StartDate','EndDate','AdvanceInterface','ResultsWidth','ResultsBorder','ResultsAnswer','ResultsStats','ResultsGraph','SubmitImageSrc','SubmitImageWidth','SubmitImageHeight','SubmitImageText','ResultImageSrc','ResultImageWidth','ResultImageHeight','ResultImageText','NextImageSrc','NextImageWidth','NextImageHeight','NextImageText','ResponseNotice','ResponseEmail');
$phpQF['User'] = array('UID','SID','IPAddr','BlockDupe','CheckType','Email','Confirm','EmailConfirm','CompleteDate');
$version = (float)$phpQAdmin["Version"];
if ($version < 2.2) {
array_splice($phpQF['Survey'], 44, 2);
}
if ($version < 2.1) {
array_splice($phpQF['Survey'], 32, 12);
}
if ($version < 2.0) {
$version = '1.2';
array_splice($phpQF['Admin'], 11, 1);
array_splice($phpQF['Admin'], 3, 2);
array_splice($phpQF['Survey'], 27, 5);
array_splice($phpQF['Survey'], 17, 1);
array_splice($phpQF['Survey'], 9, 1);
array_splice($phpQF['Question'], 13, 1);
array_splice($phpQF['User'], 3, 1);
}
$id = 'PHPQBACKUP';
if ($sid) {
$id = "SURVEYBACKUP";
if ($swap) {
$id = "SURVEYSWAP";
array_splice($phpQF['Survey'], 0, 2);
array_splice($phpQF['Question'], 0, 2);
}
}
echo "<!--PHPQBACKUP ".$phpQAdmin["Version"]." $id-->\n";
if (!$sid) {
echo "TABLE|phpQAdmin|COLUMNS|" . join(',', $phpQF['Admin']) . "\n";
}
echo "TABLE|phpQSurvey|COLUMNS|" . join(',', $phpQF['Survey']) . "\n";
echo "TABLE|phpQQuestion|COLUMNS|" . join(',', $phpQF['Question']) . "\n";
if (!$swap) {
echo "TABLE|phpQUser|COLUMNS|" . join(',', $phpQF['User']) . "\n";
echo "TABLE|phpQAnswer|COLUMNS|" . join(',', $phpQF['Answer']) . "\n";
}
if (!$sid) {
$values = array();
for ($m=0; $m<sizeof($phpQF['Admin']); $m++) {
$values[] = Str2PHPQ($phpQAdmin[$phpQF['Admin'][$m]]);
}
echo "TABLE|phpQAdmin|VALUES|" . join('&', $values) . "\n";
}
$where = $sid ? ' WHERE SID='.ProtectMySQL($sid) : '';
$tables = $swap ? array('Survey','Question') : array('Survey','Question','User','Answer');
foreach ($tables as $table) {
if (function_exists('mysql_unbuffered_query')) {
$mqquery = mysql_unbuffered_query("select * from phpQ$table$where");
}
else {
$mqquery = mysql_query("select * from phpQ$table$where");
}
while ($maquery = mysql_fetch_array($mqquery)) {
$values = array();
for ($m=0; $m<count($phpQF[$table]); $m++) {
$values[] = Str2PHPQ($maquery[$phpQF[$table][$m]]);
}
echo "TABLE|phpQ".$table."|VALUES|" . join('&', $values) . "\n";
}
}
}
function FormatSurveyData ($sid, $stattype, $format) {
global $phpQlang;
$format = $format ? $format : 'csv';
$charset = $phpQlang['CHARSET'];
# Retrieve the survey verification limits.
$mqsurvey = mysql_query("select * from phpQSurvey where SID = \"".ProtectMySQL($sid)."\"");
if ($masurvey = mysql_fetch_array($mqsurvey)) {
$bits = VerificationBits($masurvey["SurveyUsers"]);
}
else { return ""; }
$contents = '';
$phpQSfields = array('SID','Name','AddDate','SurveyUsers','SurveyResults','Width','Indent','QuestionNumb','QuestionStyle','AnswerInputStyle','AnswerTextStyle','AnswerStyle','ErrorStyle','VerifyEmail','EmailFrom','EmailSubject','Template','Language','OnComplete','RedirectURL','Completed','Description','AdminNotes','Active','StartDate','EndDate','AdvanceInterface','ResultsWidth','ResultsBorder','ResultsAnswer','ResultsStats','ResultsGraph','SubmitImageSrc','SubmitImageWidth','SubmitImageHeight','SubmitImageText','ResultImageSrc','ResultImageWidth','ResultImageHeight','ResultImageText','NextImageSrc','NextImageWidth','NextImageHeight','NextImageText','ResponseNotice','ResponseEmail');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -