⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfunctions.php

📁 调查问卷系统源码。想下的就下吧。不要条件
💻 PHP
📖 第 1 页 / 共 3 页
字号:
					$message = $phpQlang["InvalidAnswer"];
				}
			}

			$choices = split("\|\|\|", $qanswer);
			for ($k=0; $k<sizeof($choices); $k++) {
				$qparts = split("\|\|", $choices[$k]);
				$subid = "N".$qparts[1];
				if (substr($qparts[2],0,11) == "Textfield:(") {
					$subid = "O".$qparts[1];
					$optiontext = substr($qparts[2],11,-1);
				}
				else {
					$optiontext = $qparts[2];
				}
				if ($qtype == "select") { $optiontext = ProtectHTML($optiontext); }
				$answervar3 = $HTTP_POST_VARS["Q".$qid.$subid];

				if ($uanswer == $subid) {
					if ($qtype == "select" && $qparts[4] == "N") {
						if ($required) {
							$answervalidity = false;
							$message = sprintf($phpQlang["UnselectableOption"], $optiontext);
						}
						else {
							$invalidselect = true;
						}
					}
					else {
						$tempanswer = $uanswer;
						if (substr($subid,0,1) == "O") {
							if ($answervar3 != '') {
								$tempanswer .= "|".$answervar3;
							}
							else {
								$answervalidity = false;
								$message = sprintf($phpQlang["CompleteTextfield"], $optiontext);
							}
						}
					}
				}
				elseif (substr($subid,0,1) == "O" && $answervar3 != '') {
					$answervalidity = false;
					$message = sprintf($phpQlang["SelectTextfield"], $optiontext);
				}
			}

			if ($answervalidity &&!$invalidselect) {
				$contents = $tempanswer;
			}
			break;
	}

	if (!$answervalidity && $message) {
		$contents = "<TR><TD>";
		$contents .= "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0><TR>";
		$contents .= "<TD STYLE=\"$errorstyle\">$message</TD>";
		$contents .= "</TR></TABLE>";
		$contents .= "</TD></TR>";
	}

	return array($answervalidity, $contents);
}

function PrintQuestion ($maquestion, $masurvey) {
	global $phpQlang;
	$question = FreeHTML($maquestion["Question"]);
	$questionstyle = ($maquestion["QuestionStyle"]) ? $maquestion["QuestionStyle"] : $masurvey["QuestionStyle"];
	$required = ($maquestion["Required"]=="n") ? false : true;
	$autonumb = $masurvey["QuestionNumb"];

	$mqqnum = mysql_query("select COUNT(*) as qnum from phpQQuestion WHERE SID=\"".ProtectMySQL($maquestion["SID"])."\" and SortOrder<\"".ProtectMySQL($maquestion["SortOrder"])."\" and Type != 'pagebreak' AND Type != 'htmlcontent'");
	$maqnum = mysql_fetch_array($mqqnum);

	$contents = "<TR><TD>\n";
	if ($maquestion["Instructions"]) {
		$contents .= $maquestion["Instructions"];
	}
	if ($maquestion["Type"] != "htmlcontent") {
		$contents .= "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0><TR>";
		if ($autonumb == 'y') {
			if ($required == 'y') {
				$contents .= "<TD VALIGN=top><B>".$phpQlang['*']."</B></TD>\n";
			} else {
				$contents .= "<TD>&nbsp;</TD>\n";
			}
			$contents .= "<TD STYLE=\"$questionstyle\" ALIGN=right VALIGN=top><B>".($maqnum["qnum"]+1).".</B></TD>\n";
		}
		$contents .= "<TD WIDTH=100% STYLE=\"$questionstyle\">".$question."</TD>\n";
		$contents .= "</TR></TABLE>\n";
	}
	$contents .= "</TD></TR>\n";

	return $contents;
}

function PrintAnswers ($maquestion, $masurvey, $uidanswer, $print = 0) {
	global $HTTP_POST_VARS;
	$qid = $maquestion["QID"];
	$type = $maquestion["Type"];
	$indent = $masurvey["Indent"];
	$questionstyle = ($maquestion["QuestionStyle"]) ? $maquestion["QuestionStyle"] : $masurvey["QuestionStyle"];
	$answerinputstyle = ($maquestion["AnswerInputStyle"]) ? $maquestion["AnswerInputStyle"] : $masurvey["AnswerInputStyle"];
	$answertextstyle = ($maquestion["AnswerTextStyle"]) ? $maquestion["AnswerTextStyle"] : $masurvey["AnswerTextStyle"];
	$answerstyle = ($maquestion["AnswerStyle"]) ? $maquestion["AnswerStyle"] : $masurvey["AnswerStyle"];
	$attributes = $maquestion["Attributes"];
	$answer = ProtectHTML($maquestion["Answer"]);
	$defaultanswer = $maquestion["DefaultAnswer"];
	$colnumb = $maquestion["ColNumb"];
	$mult = $maquestion["Mult"];
	$sortorder = $maquestion["SortOrder"];
	$required = ($maquestion["Required"]=="n") ? false : true;
	$contents .= "<TR><TD>\n";

	switch ($type) {
		case "radio":
			$contents .= "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>\n";
			$contents .= "<TR><TD WIDTH=$indent></TD><TD>\n";
			$contents .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR>\n";
			$choices = split("\|\|\|", $answer);
			$count = 0;
			for ($i=0; $i<sizeof($choices); $i++) {
				$tfanswer = '';
				$parts = split("\|\|", $choices[$i]);
				$subqid = $parts[1];

				# Checking for previous input by user else default answer

				if ($HTTP_POST_VARS["Q".$qid."Answered"]) {
					$checked = "";
					$checked = (substr($HTTP_POST_VARS["Q".$qid],1) == $subqid) ? "CHECKED" : "";
					$tfanswer = $HTTP_POST_VARS["Q".$qid."O".$subqid];
				}
				else {
					$checked = ($parts[3] == "D") ? "CHECKED" : "";
				}

				# Grabbing answer (uidanswer) from database

				if ($uidanswer) {
					if (substr($uidanswer,0,1) == "O") {
						$radiochoice = split("\|", $uidanswer);
						$checked = (substr($radiochoice[0],1) == $subqid) ? "CHECKED" : "";
						$tfanswer = ($radiochoice[0] == "O".$subqid && $radiochoice[1]) ? $radiochoice[1] : '';
					}
					else {
						$checked = (substr($uidanswer,1) == $subqid) ? "CHECKED" : "";
					}
				}

				# Displaying answer choices

				$radioid = 'Q'.$qid.'_'.$subqid;
				if (substr($parts[2],0,11) == "Textfield:(") {
					$tfanswer = ProtectHTML($tfanswer);
					$choicetext = substr($parts[2],11,strlen($parts[2])-12);
					if ($print) {
						$contents .= $checked ? "<TD STYLE=\"$answertextstyle\">".FreeHTML($choicetext)."&nbsp;[$tfanswer]</TD>" : '';
					}
					else {
						$contents .= "<TD STYLE=\"$answerinputstyle\"><INPUT TYPE=radio NAME=Q$qid $checked ID=\"$radioid\" VALUE=\"O$subqid\"></TD>";
						$contents .= "<TD STYLE=\"$answertextstyle\"><LABEL FOR=\"$radioid\">".FreeHTML($choicetext)."</LABEL>&nbsp;</TD>";
						$contents .= "<TD STYLE=\"$answerinputstyle\"><INPUT TYPE=text STYLE=\"$answerstyle\" $attributes ";
						$contents .= "NAME=Q".$qid."O$subqid VALUE=\"$tfanswer\"></TD>\n";
					}
				}
				else {
					if ($print) {
						$contents .= $checked ? "<TD STYLE=\"$answertextstyle\">".FreeHTML($parts[2])."</TD>\n" : '';
					}
					else {
						$contents .= "<TD STYLE=\"$answerinputstyle\"><INPUT TYPE=radio NAME=Q$qid $checked ID=\"$radioid\" VALUE=\"N$subqid\"></TD>";
						$contents .= "<TD STYLE=\"$answertextstyle\" COLSPAN=2><LABEL FOR=\"$radioid\">".FreeHTML($parts[2])."</LABEL>&nbsp;</TD>\n";
					}
				}

				# Correct columns when printing results...
				if ($print) { $count += $checked ? 1 : 0; }
				else { $count = $i; }

				if (($count+1) % $colnumb == 0 && $count != sizeof($choices)) {
					$contents .= "</TR><TR>\n";
				}
			}
			$contents .= "</TR></TABLE>\n";
			$contents .= "</TD></TR></TABLE>\n";
			break;
		case "select":
			$contents .= "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>\n";
			if ($print) {
				$contents .= "<TR><TD WIDTH=$indent></TD><TD>\n";
				$contents .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR>\n";
			}
			else {
				$contents .= "<TR><TD WIDTH=$indent></TD><TD STYLE=\"$answerinputstyle\">\n";
				$contents .= "<SELECT NAME=Q$qid STYLE=\"$answertextstyle\">";
			}
			$choices = split("\|\|\|", $answer);
			$seltextfield = 0;

			# Traversing through each Select choice

			$tfanswer = '';
			for ($i=0; $i<sizeof($choices); $i++) {
				$parts = split("\|\|", $choices[$i]);
				$subqid = $parts[1];
				# Checking for previous input by user else default answer
				if ($HTTP_POST_VARS["Q".$qid."Answered"]) {
					$selected = "";
					$selected = (substr($HTTP_POST_VARS["Q".$qid],1) == $subqid) ? "SELECTED" : "";
					$tfanswer = ($HTTP_POST_VARS["Q".$qid."O".$subqid] != '') ? $HTTP_POST_VARS["Q".$qid."O".$subqid] : $tfanswer;
				}
				else {
					$selected = ($parts[3] == "D") ? "SELECTED" : "";
				}

				# Grabbing answer (uidanswer) from database

				if ($uidanswer) {
					if (substr($uidanswer,0,1) == "O") {
						$radiochoice = split("\|", $uidanswer);
						$selected = (substr($radiochoice[0],1) == $subqid) ? "SELECTED" : "";
						$tfanswer = (substr($radiochoice[0],1) == $subqid && $radiochoice[1] != '') ? $radiochoice[1] : '';
					}
					else {
						$selected = (substr($uidanswer,1) == $subqid) ? "SELECTED" : "";
					}
				}

				# Determining if there is a textfield

				if (substr($parts[2],0,11) == "Textfield:(") {
					$seltextfield = $subqid;
					$choicetext = substr($parts[2],11,-1);
					if ($print) {
						$tfanswer = $html->protectHTML($tfanswer);
						$contents .= $selected ? "<TD STYLE=\"$answertextstyle\">$choicetext&nbsp;[$tfanswer]</TD>" : '';
					}
					else {
						$contents .= "<OPTION $selected VALUE=\"O$subqid\">".$choicetext."</OPTION>";
					}
				}
				else {
					if ($print) {
						$contents .= $selected ? "<TD STYLE=\"$answertextstyle\">".$parts[2]."</TD>" : '';
					}
					else {
						$contents .= "<OPTION $selected VALUE=\"N$subqid\">".$parts[2]."</OPTION>";
					}
				}
			}

			if ($print) { $contents .= "</TR></TABLE></TD></TR>\n"; }
			else { $contents .= "</SELECT></TD></TR>\n"; }

			# Printing the textfield if there is one

			if ($seltextfield && !$print) {
				$tfanswer = ProtectHTML($tfanswer);
				$contents .= "<TR><TD></TD><TD STYLE=\"$answerinputstyle\"><INPUT TYPE=text STYLE=\"$answerstyle\" $attributes ";
				$contents .= "NAME=Q".$qid."O".$seltextfield." VALUE=\"$tfanswer\"></TD></TR>\n";
			}
			$contents .= "</TABLE>\n";
			break;
		case "checkbox":
			$contents .= "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>\n";
			$contents .= "<TR><TD WIDTH=$indent></TD><TD>\n";
			$contents .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0><TR>\n";
			$choices = split("\|\|\|", $answer);
			$count = 0;
			for ($i=0; $i<sizeof($choices); $i++) {
				$parts = split("\|\|", $choices[$i]);
				$subqid = $parts[1];

				# Checking for previous input by user else default answer
				
				$tfanswer = '';
				if ($HTTP_POST_VARS["Q".$qid."Answered"]) {
					$checked = "";
					for ($j=0; $j<sizeof($HTTP_POST_VARS["Q".$qid]); $j++) {
						$checked = (substr($HTTP_POST_VARS["Q".$qid][$j],1) == $subqid) ? "CHECKED" : $checked;
					}
					$tfanswer = $HTTP_POST_VARS["Q".$qid."O".$subqid];
				}
				else {
					$checked = ($parts[3] == "D") ? "CHECKED" : "";
				}
			 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -