📄 question.php
字号:
<?
################################################################################
# phpQuestionnaire Version 2.2 #
# Copyright 2003-2005 chumpsoft, inc. March 28, 2005 #
################################################################################
# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS #
################################################################################
$GLOBALS["inAdmin"] = 1;
#-->> Include Files
require("../inc/init.php");
require("../inc/mysql.php");
require("../inc/functions.php");
require("../inc/pfunctions.php");
#-->> Logging In
IsAdmin(1);
SetLanguage('', 'ADMIN');
$imgurl = $GLOBALS["phpQImageDir"];
#-->> Question Object Frame
class QuestionObj
{
var $property;
function QuestionObj ($questionAsked)
{
$this->setProperty("questionAsked", $questionAsked);
}
function setProperty ($varName, $varValue)
{
$this->property[$varName] = $varValue;
}
function getProperty ($varName, $action)
{
$returnVar;
switch ($action)
{
case "mysql":
$returnVar = ProtectMySQL($this->property[$varName]);
break;
case "html":
$returnVar = ProtectHTML($this->property[$varName]);
break;
case "style":
$returnVar = $this->property[$varName];
$returnVar = preg_replace("/^STYLE=\"?(.*)\"?$/i", "\\1", $returnVar);
$returnVar = preg_replace("/^\"(.*)\"$/", "\\1", $returnVar);
break;
default:
$returnVar = $this->property[$varName];
break;
}
return ($returnVar) ? $returnVar : false;
}
}
#-->> Setting Variables
$varnames = array("cq", "cs", "advance", "questionlist", "action", "next", "qt", "modifyid", "deleteid", "sortorder", "qid", "localadvance", "fsubmit");
SetVars($varnames);
if (!$advance) {
$advance = ($phpQAdmin["AdvanceInterface"] == "y") ? true : false;
}
$qObject = new QuestionObj($HTTP_POST_VARS["questionasked"]);
$qObject->setProperty("questionType", $HTTP_POST_VARS["type"]);
$qObject->setProperty("answerRequired", $HTTP_POST_VARS["required"]);
$qObject->setProperty("selectSize", $HTTP_POST_VARS["mult"]);
$qObject->setProperty("qInstructions", $HTTP_POST_VARS["instructions"]);
$qObject->setProperty("questionStyle", $HTTP_POST_VARS["questionstyle"]);
$qObject->setProperty("defaultAnswer", $HTTP_POST_VARS["defaultanswer"]);
$qObject->setProperty("answerChoices", $HTTP_POST_VARS["answer"]);
$qObject->setProperty("columnNumber", $HTTP_POST_VARS["colnumb"]);
$qObject->setProperty("answerControl", $HTTP_POST_VARS["control"]);
$qObject->setProperty("answerCount", $HTTP_POST_VARS["answercount"]);
$qObject->setProperty("answerIStyle", $HTTP_POST_VARS["answerinputstyle"]);
$qObject->setProperty("answerStyle", $HTTP_POST_VARS["answertextstyle"]);
$qObject->setProperty("inputStyle", $HTTP_POST_VARS["answerstyle"]);
$qObject->setProperty("inputAttributes", $HTTP_POST_VARS["attributes"]);
$qObject->setProperty("summaryDisplay", $HTTP_POST_VARS["summary"]);
$oQAsked = $qObject->getProperty("questionAsked", "mysql");
$oQType = $qObject->getProperty("questionType", "mysql");
$oARequired = $qObject->getProperty("answerRequired", "mysql");
$oSSize = $qObject->getProperty("selectSize", "mysql");
$oQInstructions = $qObject->getProperty("qInstructions", "mysql");
$oQStyle = $qObject->getProperty("questionStyle", "style");
$oDAnswer = $qObject->getProperty("defaultAnswer", "mysql");
$oAChoices = $qObject->getProperty("answerChoices", "mysql");
$oCNumber = $qObject->getProperty("columnNumber", "mysql");
$oAControl = $qObject->getProperty("answerControl", "mysql");
$oACount = $qObject->getProperty("answerCount", "mysql");
$oAIStyle = $qObject->getProperty("answerIStyle", "style");
$oAStyle = $qObject->getProperty("answerStyle", "style");
$oIStyle = $qObject->getProperty("inputStyle", "style");
$oIAttributes = $qObject->getProperty("inputAttributes", "mysql");
$oSDisplay = $qObject->getProperty("summaryDisplay", "mysql");
#-->> Setting Interface in Advance
if ($cs) {
$mqadvance = mysql_query("select AdvanceInterface from phpQSurvey where SID = \"".ProtectMySQL($cs)."\"");
if ($maadvance = mysql_fetch_array($mqadvance)) {
$advance = ($maadvance["AdvanceInterface"]) ? (($maadvance["AdvanceInterface"]=="y") ? true : false) : $advance;
}
}
switch ($localadvance) {
case "y": $advance = true; break;
case "n": $advance = false; break;
default: break;
}
$advanceyn = ($advance) ? "y" : "n";
#->> Find Largest ID for radio, checkbox, select & selectmult when Add/Modifying
if ($oAChoices && ($oQType == "radio" || $oQType == "checkbox" || $oQType == "select" || $oQType == "selectmult")) {
$choicearray = split("\|\|\|", $oAChoices);
$largestid = 0;
for ($i=0; $i<sizeof($choicearray); $i++) {
$parts = split("\|\|", $choicearray[$i]);
if (sizeof($parts) == 5) {
$largestid = ($parts[1] > $largestid) ? $parts[1] : $largestid;
}
}
}
#-->> Add, Modify, Sort or Delete Question
switch ($action) {
case "add":
if (($oQType != "checkbox" && $oQType != "selectmult") ||
($oAControl && CheckACount($oAControl, $oAChoices, $oACount))) {
$choose = $oAControl.":".$oACount;
if ($oQType == "textfield" || $oQType == "textarea" || $oQType == "htmlcontent" || ($oAChoices && ValidateQAnswer($oAChoices))) {
$insertquery = "insert into phpQQuestion (";
$insertquery .= "SID, QID, SortOrder, Question, Type, Mult, DefaultAnswer, ";
$insertquery .= "Attributes, QuestionStyle, Answer, AnswerInputStyle, AnswerTextStyle, AnswerStyle, ";
$insertquery .= "Required, ColNumb, Choose, Summary, Instructions ";
$insertquery .= ($largestid > 0) ? ", LargestAID " : "";
$insertquery .= ") values (";
$insertquery .= "$cs, NULL, $next, \"$oQAsked\", \"$oQType\", \"$oSSize\", \"$oDAnswer\", ";
$insertquery .= "\"$oIAttributes\", \"".ProtectMySQL($oQStyle)."\", \"$oAChoices\", \"".ProtectMySQL($oAIStyle)."\", ";
$insertquery .= "\"".ProtectMySQL($oAStyle)."\", \"".ProtectMySQL($oIStyle)."\", ";
$insertquery .= "\"$oARequired\", \"$oCNumber\", \"$choose\", \"$oSDisplay\", \"$oQInstructions\" ";
$insertquery .= ($largestid > 0) ? ", \"$largestid\" " : "";
$insertquery .= ")";
if (mysql_query($insertquery)) {
$cq = mysql_insert_id();
$message = $phpQlang['AddQuestionSuccess'];
$cq = $oQAsked = $oQType = $oARequired = $oSSize = $oQInstructions = $oQStyle = $oDAnswer = $oAChoices = $oCNumber = $oAControl = $oACount = $oAStyle = $oIStyle = $oIAttributes = $oSDisplay = "";
}
else { $message = $phpQlang['AddQuestionError']; }
}
else { $message = $phpQlang['InvalidAnswerChoices']; }
}
else { $message = $phpQlang['InvalidNumberChoices']; }
$localadvance = ($localadvance=="y" || $localadvance=="n") ? $localadvance : $advanceyn;
$advancequery = "update phpQSurvey set AdvanceInterface = \"$localadvance\" where SID = \"".ProtectMySQL($cs)."\"";
mysql_query($advancequery);
break;
case "modify":
if ($modifyid) {
if (($oQType != "checkbox" && $oQType != "selectmult") ||
($oAControl && CheckACount($oAControl, $oAChoices, $oACount))) {
$choose = $oAControl.":".$oACount;
if ($oQType == "textfield" || $oQType == "textarea" || $oQType == "htmlcontent" || ($oAChoices && ValidateQAnswer($oAChoices))) {
if ($advance) {
$modifyquery = "update phpQQuestion set ";
$modifyquery .= "Mult = \"$oSSize\", Attributes = \"$oIAttributes\", Type = \"$oQType\", ";
$modifyquery .= "Question = \"$oQAsked\", QuestionStyle = \"".ProtectMySQL($oQStyle)."\", ";
$modifyquery .= "Answer = \"$oAChoices\", AnswerInputStyle = \"".ProtectMySQL($oAIStyle)."\", ";
$modifyquery .= "AnswerTextStyle = \"".ProtectMySQL($oAStyle)."\", ";
$modifyquery .= "DefaultAnswer = \"$oDAnswer\", Required = \"$oARequired\", ";
$modifyquery .= "AnswerStyle = \"".ProtectMySQL($oIStyle)."\", Instructions = \"$oQInstructions\", ";
$modifyquery .= "ColNumb = \"$oCNumber\", Choose = \"$choose\", Summary = \"$oSDisplay\" ";
$modifyquery .= ($largestid > 0) ? ", LargestAID = \"$largestid\" " : "";
$modifyquery .= "where QID = \"".ProtectMySQL($modifyid)."\"";
} else {
$modifyquery = "update phpQQuestion set ";
$modifyquery .= "Type = \"$oQType\", Question = \"$oQAsked\", Answer = \"$oAChoices\", ";
$modifyquery .= "Required = \"$oARequired\", Mult = \"$oSSize\", Choose = \"$choose\", ";
$modifyquery .= "Summary = \"$oSDisplay\" ";
if ($oQType == "htmlcontent") {
$modifyquery .= ", Instructions = \"$oQInstructions\" ";
}
$modifyquery .= ($largestid > 0) ? ", LargestAID = \"$largestid\" " : "";
$modifyquery .= "where QID = \"".ProtectMySQL($modifyid)."\"";
}
if (mysql_query($modifyquery)) {
$cq = $modifyid;
$message = $phpQlang['ModifyQuestionSuccess'];
}
else { $message = $phpQlang['ModifyQuestionError']; }
}
else { $message = $phpQlang['InvalidAnswerChoices']; }
}
else { $message = $phpQlang['InvalidNumberChoices']; }
}
$localadvance = ($localadvance=="y" || $localadvance=="n") ? $localadvance : $advanceyn;
$advancequery = "update phpQSurvey set AdvanceInterface = \"$localadvance\" where SID = \"".ProtectMySQL($cs)."\"";
mysql_query($advancequery);
break;
case "delete":
if ($deleteid) {
$question = mysql_fetch_array(mysql_query("select SID,SortOrder from phpQQuestion where QID = \"".ProtectMySQL($deleteid)."\""));
mysql_query("LOCK TABLES phpQAnswer WRITE,phpQQuestion WRITE");
$success = mysql_query("delete from phpQAnswer where QID = \"".ProtectMySQL($deleteid)."\"");
$success = mysql_query("delete from phpQQuestion where QID = \"".ProtectMySQL($deleteid)."\"") ? $success : false;
if ($question["SortOrder"] && $question["SID"]) {
mysql_query("UPDATE phpQQuestion SET SortOrder=(SortOrder-1) WHERE SortOrder > ".ProtectMySQL($question["SortOrder"])." AND SID = ".ProtectMySQL($question["SID"]));
}
mysql_query("UNLOCK TABLES");
$message = $success ? $phpQlang['DeleteQuestionSuccess'] : $phpQlang['DeleteQuestionError'];
}
break;
case "store":
if ($sortorder) {
mysql_query("delete from phpQQuestion where SID = \"".ProtectMySQL($cs)."\" and Type = \"pagebreak\"");
$orderarray = split("\|\|", $sortorder);
for ($i=1; $i<=sizeof($orderarray); $i++) {
if ($orderarray[$i-1] == "pagebreak") {
$pgbreakquery = "insert into phpQQuestion ";
$pgbreakquery .= "(SID, QID, Type, SortOrder, Question) ";
$pgbreakquery .= "values ";
$pgbreakquery .= "(\"".ProtectMySQL($cs)."\", NULL, \"pagebreak\", $i, \"<<----| ".$phpQlang['PageBreak']." |---->>\")";
$success = mysql_query($pgbreakquery);
} else {
$success = mysql_query("update phpQQuestion set SortOrder = $i where QID = ".ProtectMySQL($orderarray[$i-1]));
}
}
$message = $success ? $phpQlang['StoreQuestionSuccess'] : $phpQlang['StoreQuestionError'];
}
break;
default:
break;
}
if ($message) { $message = "<B>".$phpQlang['Status'].":</B> ".$message; }
$types = array(array("radio", $phpQlang['radio']), array("checkbox", $phpQlang['checkbox']), array("textfield", $phpQlang['textfield']), array("textarea", $phpQlang['textarea']), array("select", $phpQlang['select']), array("selectmult", $phpQlang['selectmult']), array("htmlcontent", $phpQlang['htmlcontent']));
$choosearray = array(array($phpQlang['AnyNumber'],"a"), array($phpQlang['Exactly'],"e"), array($phpQlang['AtLeast'],"l"), array($phpQlang['AtMost'], "m"));
$advancearray = array(array($phpQlang['Basic'], "n"), array($phpQlang['Advanced'], "y"));
$required = array(array("y", $phpQlang['Yes']), array("n", $phpQlang['No']));
$tsurveyname = '';
if ($cs) {
$mqsurvey = mysql_query("select Name from phpQSurvey where SID = \"".ProtectMySQL($cs)."\"");
if ($masurvey = mysql_fetch_array($mqsurvey)) {
$tsurveyname = (strlen($masurvey["Name"]) > 65) ? substr($masurvey["Name"],0,65)."..." : $masurvey["Name"];
}
else {
header("Location: survey.php");
exit();
}
} else {
header("Location: survey.php");
exit();
}
$mqquestion = mysql_query("select * from phpQQuestion where SID = \"".ProtectMySQL($cs)."\" order by SortOrder");
$count = 0;
while ($maquestion = mysql_fetch_array($mqquestion)) {
$questionlist[] = $maquestion;
if ($cq == $maquestion["QID"]) {
$cquestion = $maquestion;
$largestid = $maquestion["LargestAID"];
}
$count++;
}
$tcount = $count+1;
$iQAsked = ($oQAsked) ? $qObject->getProperty("questionAsked", "html") : ProtectHTML($cquestion["Question"]);
$iQType = ($oQType) ? $qObject->getProperty("questionType", "html") :
((ProtectHTML($cquestion["Type"])) ? ProtectHTML($cquestion["Type"]) : "radio");
$iARequired = ($oARequired) ? $qObject->getProperty("answerRequired", "html") : ProtectHTML($cquestion["Required"]);
$iSSize = ($oSSize) ? $qObject->getProperty("selectSize", "html") :
((ProtectHTML($cquestion["Mult"])) ? ProtectHTML($cquestion["Mult"]) : 3);
$iQInstructions = ($oQInstructions) ? $qObject->getProperty("qInstructions", "html") : ProtectHTML($cquestion["Instructions"]);
$iQStyle = ($oQStyle) ? ProtectHTML($oQStyle) : ProtectHTML($cquestion["QuestionStyle"]);
$iDAnswer = ($oDAnswer) ? $qObject->getProperty("defaultAnswer", "html") : ProtectHTML($cquestion["DefaultAnswer"]);
$iAChoices = ($oAChoices) ? $qObject->getProperty("answerChoices", "html") : ProtectHTML($cquestion["Answer"]);
$iCNumber = ($oCNumber) ? $qObject->getProperty("columnNumber", "html") :
((ProtectHTML($cquestion["ColNumb"])) ? ProtectHTML($cquestion["ColNumb"]) : 1);
if ($oAControl && $oACount)
{
$iAControl = $qObject->getProperty("answerControl", "html");
$iACount = $qObject->getProperty("answerCount", "html");
}
else
list($iAControl, $iACount) = split(":", $cquestion["Choose"]);
$iAIStyle = ($oAIStyle) ? ProtectHTML($oAIStyle) : ProtectHTML($cquestion["AnswerInputStyle"]);
$iAStyle = ($oAStyle) ? ProtectHTML($oAStyle) : ProtectHTML($cquestion["AnswerTextStyle"]);
$iIStyle = ($oIStyle) ? ProtectHTML($oIStyle) : ProtectHTML($cquestion["AnswerStyle"]);
$iIAttributes = ($oIAttributes) ? $qObject->getProperty("inputAttributes", "html") : ProtectHTML($cquestion["Attributes"]);
$iSDisplay = ($oSDisplay) ? $qObject->getProperty("summaryDisplay", "html") :
((ProtectHTML($cquestion["Summary"])) ? ProtectHTML($cquestion["Summary"]) : "n");
$listalt = $phpQlang['ListofQuestions'];
$cslabel = $phpQlang['CurrentSurvey'];
$qlabel = $phpQlang['Questions'];
$previewalt = $phpQlang['Preview'];
$helpalt = $phpQlang['?'];
$staralt = $phpQlang['*'];
$contents = <<<END
<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>
<FORM NAME=questionlist ACTION="question.php" METHOD=POST>
<TR>
<TD COLSPAN=4><IMG SRC="$imgurl/headingquestion1.gif" WIDTH=115 HEIGHT=18 ALT="$listalt"></TD>
</TR>
<TR>
<TD ALIGN=right><B>$cslabel:</B></TD>
<TD VALIGN=top><A HREF="javascript:phpQHelp('q_survey', 'CurrentSurvey')"><IMG SRC="$imgurl/qmark.gif" WIDTH=13 HEIGHT=13 BORDER=0 ALT="$helpalt"></A></TD>
<TD>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%><TR>
<TD><A HREF="survey.php?cs=$cs" CLASS=link>$tsurveyname</A></TD>
<TD ALIGN=right><A HREF="../fillsurvey.php?sid=$cs&action=preview" TARGET=_blank><IMG SRC="$imgurl/preview.gif" WIDTH=80 HEIGHT=15 BORDER=0 ALT="$previewalt"></A></TD>
</TR></TABLE>
</TD>
<TD></TD>
</TR>
<TR>
<TD ALIGN=right VALIGN=top><B>$qlabel:</B></TD>
<TD VALIGN=top><A HREF="javascript:phpQHelp('q_order', 'Questions')"><IMG SRC="$imgurl/qmark.gif" WIDTH=13 HEIGHT=13 BORDER=0 ALT="$helpalt"></A></TD>
<TD><SELECT NAME=choosequestion CLASS=huge SIZE=10>
END;
if (sizeof($questionlist) > 0) {
for ($i=0; $i<sizeof($questionlist); $i++) {
$listedq = (strlen($questionlist[$i]["Question"]) > 60)
? ProtectHTML(substr($questionlist[$i]["Question"],0,60)."...")
: ProtectHTML($questionlist[$i]["Question"]);
if ($questionlist[$i]["Type"] != "pagebreak") {
$selected = ($questionlist[$i]["QID"] == $cq) ? "SELECTED" : "";
$contents .= "<OPTION $selected VALUE=".$questionlist[$i]["QID"].">".$listedq;
}
else { $contents .= "<OPTION VALUE=\"pagebreak\">".$listedq; }
}
}
else {
$contents .= "<OPTION VALUE=\"-1\">".$phpQlang['NoQuestions'];
}
$upalt = $phpQlang['AltUp'];
$downalt = $phpQlang['AltDown'];
$addmodifyalt = $phpQlang['AddModifyAQuestion'];
$requiredtext = $phpQlang['RequiredField'];
$editbutton = $phpQlang['Edit'];
$deletebutton = $phpQlang['Delete'];
$pagebutton = $phpQlang['AddPageBreak'];
$sobutton = $phpQlang['SaveOrder'];
$previewbutton = $phpQlang['Preview'];
$interface = $phpQlang['Interface'];
$contents .= <<<END
</SELECT></TD>
<TD VALIGN=middle>
<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>
<TR><TD><A HREF="javascript:MoveUp()"><IMG SRC="images/buttonup.gif" WIDTH=15 HEIGHT=30 BORDER=0 ALT="$upalt"></A></TD></TR>
<TR><TD><A HREF="javascript:MoveDown()"><IMG SRC="images/buttondown.gif" WIDTH=15 HEIGHT=30 BORDER=0 ALT="$downalt"></A></TD></TR>
</TABLE>
</TD>
</TR>
<TR>
<TD WIDTH=135 COLSPAN=2></TD>
<TD COLSPAN=2><INPUT TYPE=button ONCLICK="ChangeQuestion()" VALUE="$editbutton">
<INPUT TYPE=button ONCLICK="DeleteQuestion()" VALUE="$deletebutton">
<INPUT TYPE=button ONCLICK="AddPageBreak()" VALUE="$pagebutton">
<INPUT TYPE=button ONCLICK="StoreOrder()" VALUE="$sobutton">
<INPUT TYPE=button ONCLICK="PreviewQuestion($cs)" VALUE="$previewbutton"></TD>
</TR>
<INPUT TYPE=hidden NAME=action VALUE="">
<INPUT TYPE=hidden NAME=deleteid VALUE="">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -