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

📄 sfunctions.php

📁 php+mysql做的调查问卷管理系统php+mysql做的调查问卷管理系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?
################################################################################
# phpQuestionnaire                           Version 2.2                       #
# Copyright 2003-2005 chumpsoft, inc.        March 28, 2005                    #
################################################################################
#              SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS              #
################################################################################

function CreateStats ($masurvey, $stattype, $view, $admin) {
	global $phpQlang;
	$imgurl = $GLOBALS["phpQImageDir"];

	switch ($stattype) {
		case "v": $heading = $admin ? "<IMG SRC=\"$imgurl/headingresults2.gif\" WIDTH=157 HEIGHT=22 ALT=\"".$phpQlang["VerifiedSurveyResults"]."\">" : "<H2>".$phpQlang["VerifiedSurveyResults"]."</H2>"; break;
		case "u": $heading = $admin ? "<IMG SRC=\"$imgurl/headingresults3.gif\" WIDTH=171 HEIGHT=22 ALT=\"".$phpQlang["UnverifiedSurveyResults"]."\">" : "<H2>".$phpQlang["UnverifiedSurveyResults"]."</H2>"; break;
		case "a": $heading = $admin ? "<IMG SRC=\"$imgurl/headingresults.gif\" WIDTH=98 HEIGHT=22 ALT=\"".$phpQlang["AllSurveyResults"]."\">" : "<H2>".$phpQlang["AllSurveyResults"]."</H2>"; break;
	}

	$contents = "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>\n";
	$contents .= "<TR><TD>$heading</TD></TR>\n";
	$contents .= "<TR><TD>\n";

	$contents .= TableofContents($masurvey, $stattype, $view, $admin);
	$contents .= GrabQuestions($masurvey, $stattype, $view, $admin);

	$contents .= "</TD></TR>\n";
	$contents .= "</TABLE>\n";

	return $contents;
}

function GrabQuestions ($masurvey, $stattype, $view, $admin) {
	$sid = $masurvey["SID"];
	if ($view == "a" || $view == "p") {
		$qcount = ($GLOBALS["qcount"]) ? $GLOBALS["qcount"] : 1;
		$cq = ($GLOBALS["cq"]) ? $GLOBALS["cq"] : 1;

		$mqquestion = mysql_query("select * from phpQQuestion where SID = \"".ProtectMySQL($sid)."\" and SortOrder >= \"".ProtectMySQL($cq)."\" order by SortOrder");
		$foundq = 0;
		while ($maquestion = mysql_fetch_array($mqquestion)) {
			$cq++;
			if ($maquestion["Type"] == "htmlcontent") { continue; }
			if ($maquestion["Type"] != "pagebreak") {
				$contents .= PrintQuestion($masurvey, $maquestion, $qcount, $stattype, $admin);
				$contents .= PrintBorder($admin, $masurvey["ResultsWidth"]);
				$qcount++;
				$foundq = 1;
			}
			elseif ($view == "p" && $foundq) {
				$contents .= PrintSubmit($masurvey, $qcount, $cq, $sid, $stattype, $view, $admin);
				break;
			}
		}
	}
	elseif (substr($view,0,1) == "q") {
		$qid = substr($view,1);
		$mqquestion = mysql_query("select * from phpQQuestion where SID = \"".ProtectMySQL($sid)."\" and QID = \"".ProtectMySQL($qid)."\" and Type!='htmlcontent' order by SortOrder");
		if ($maquestion = mysql_fetch_array($mqquestion)) {
			if ($maquestion["Type"] != "pagebreak") {
				$mqqnum = mysql_query("select count(*) as num from phpQQuestion where SID = \"".ProtectMySQL($sid)."\" AND Type != 'pagebreak' AND Type != 'htmlcontent' AND SortOrder < ".ProtectMySQL($maquestion["SortOrder"]));
				$maqnum = mysql_fetch_array($mqqnum);
				$contents = PrintQuestion($masurvey, $maquestion, $maqnum["num"]+1, $stattype, $admin);
			}
		}
	}

	return $contents;
}

function PrintQuestion ($masurvey, $maquestion, $qcount, $stattype, $admin) {
	global $phpQlang;
	$required = '';
	if ($maquestion["Required"]!="n") {
		$required = $admin ? "<SPAN STYLE=\"color: red;\">".$phpQlang['*']."</SPAN>&nbsp;" : $phpQlang['*'].'&nbsp;';
	}

	$tablewidth = $masurvey["ResultsWidth"] ? $masurvey["ResultsWidth"] : 500;
	$tablewidth = $admin ? 500 : $tablewidth;
	$contents = "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0 WIDTH=$tablewidth>\n";
	$contents .= "<TR><TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>";
	$contents .= "<TD VALIGN=top><NOBR><B>$required".$phpQlang['Question']."&nbsp;$qcount:</B>&nbsp;</NOBR></TD>";
	$contents .= "<TD>".$maquestion["Question"]."</TD>";
	$contents .= "</TR></TABLE></TD></TR>\n";
	$contents .= "<TR><TD ALIGN=center>\n";
	$contents .= GrabAnswers($masurvey, $maquestion, $stattype, $admin);
	$contents .= "</TD></TR>\n";
	$contents .= "</TABLE>\n";

	return $contents;
}

function GrabAnswers ($masurvey, $maquestion, $stattype, $admin) {
	global $phpQlang;
	$imgurl = $GLOBALS["phpQImageDir"];
	$sid = $masurvey["SID"];
	$qid = $maquestion["QID"];

	$tablewidth = $masurvey["ResultsWidth"] ? $masurvey["ResultsWidth"] : 500;
	$tablewidth = $admin ? 500 : $tablewidth;
	$barsize = $tablewidth - 110;
	$type = $maquestion["Type"];
	$textfieldlimit = GrabTLimit();
	$typeheader = sprintf($phpQlang["QuestionTypeLabel"], $phpQlang[$type]);

	$contents = "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%>\n";
	$tcolspan = $admin ? 3 : 4;
	$tcolspan -= ($type == 'textfield' || $type == 'textarea') ? 1 : 0;
	if ($admin) {
		$contents .= "<TR BGCOLOR=#333366><TD HEIGHT=17 COLSPAN=$tcolspan ALIGN=center STYLE=\"color: #FFFFFF;\">$typeheader</TD><TD WIDTH=7 ALIGN=right VALIGN=top><IMG SRC=\"admin/images/bound1.gif\" WIDTH=7 HEIGHT=17 ALT=\"\"></TD></TR>";
	}
	else {
		$contents .= "<TR><TD HEIGHT=17 COLSPAN=$tcolspan ALIGN=center STYLE=\"".$masurvey["ResultsBorder"]."\">$typeheader</TD></TR>";
	}

	$bordercol = "<TD HEIGHT=16 BGCOLOR=#333366 BACKGROUND=\"admin/images/%bound%\"><IMG SRC=\"admin/images/invdot.gif\" WIDTH=2 HEIGHT=1 ALT=\"\"></TD>";
	if (!$admin) {
		$bordercol = "<TD HEIGHT=16 STYLE=\"".$masurvey["ResultsBorder"]."\"><IMG SRC=\"admin/images/invdot.gif\" WIDTH=2 HEIGHT=1 ALT=\"\"></TD>";
	}

	$leftbordera = $bordercol;
	$leftborderr = $bordercol;
	$rightbordera = $bordercol;
	$rightborderr = $bordercol;
	if ($admin) {
		$leftbordera = str_replace('%bound%', 'bound2.gif', $bordercol);
		$rightbordera = str_replace('%bound%', 'bound3.gif', $bordercol);
		$leftborderr = str_replace('%bound%', 'bound7.gif', $bordercol);
		$rightborderr = str_replace('%bound%', 'bound8.gif', $bordercol);
	}

	$totalcount = 0;
	$seemore = '';
	switch ($type) {
		case "select":
		case "selectmult":
		case "checkbox":
		case "radio":
			$answerarray = array();

			$temparray = split("\|\|\|", $maquestion["Answer"]);
			$count = 0;
			for ($i=0; $i<sizeof($temparray); $i++) {
				$tempsplit = split("\|\|", $temparray[$i]);
				
				if ($tempsplit[4] != "Y" && ($type == "select" || $type == "selectmult")) { continue; }
				$answerarray[] = $tempsplit;
				$countarray[] = 0;

				if (substr($answerarray[$count][2],0,11) == "Textfield:(") {
					$aid = "O".$answerarray[$count][1];
				 	$answerid[$aid] = $count;
				 	$ochoice = substr(substr($answerarray[$count][2],11),0,-1);
					if ($type != 'radio' && $type != 'checkbox') {
						$ochoice = ProtectHTML($ochoice);
					}
					if ($admin) {
				 		$temptext = "<TD BGCOLOR=#FFFFFF COLSPAN=2 WIDTH=100%>";
				 		$temptext .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%>";
				 		$temptext .= "<TR><TD><B>".($count+1).".</B>&nbsp;$ochoice&nbsp;</TD>";
				 		$temptext .= "<TD ALIGN=right><!--javascript:ViewOptions($sid,$qid,'$aid','$stattype','$admin')--></TD>";
				 		$temptext .= "</TR></TABLE></TD>";
					}
					else {
				 		$temptext = "<TD COLSPAN=2 WIDTH=100% STYLE=\"padding-left: 5px; padding-right: 5px; ".$masurvey["ResultsAnswer"]."\">";
				 		$temptext .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%>";
				 		$temptext .= "<TR><TD STYLE=\"".$masurvey["ResultsAnswer"]."\"><B>".($count+1).".</B>&nbsp;$ochoice&nbsp;</TD>";
				 		$temptext .= "<TD ALIGN=right STYLE=\"".$masurvey["ResultsAnswer"]."\"><!--javascript:ViewOptions($sid,$qid,'$aid','$stattype','$admin')--></TD>";
				 		$temptext .= "</TR></TABLE></TD>";
					}
				}
				else {
					$ochoice = $answerarray[$count][2];
					if ($type != 'radio' && $type != 'checkbox') {
						$ochoice = ProtectHTML($ochoice);
					}
				 	$answerid["N".$answerarray[$count][1]] = $count;
					if ($admin) {
						$temptext = "<TD BGCOLOR=#FFFFFF COLSPAN=2 WIDTH=100%><B>".($count+1).".</B>&nbsp;$ochoice</TD>";
					}
					else {
						$temptext = "<TD COLSPAN=2 WIDTH=100% STYLE=\"padding-left: 5px; padding-right: 5px; ".$masurvey["ResultsAnswer"]."\"><B>".($count+1).".</B>&nbsp;$ochoice</TD>";
					}
				}
				$answertext[] = "<TR>".$leftbordera.$temptext.$rightbordera."</TR>";
				$count++;
			}

			$qstring = "select Answer from phpQAnswer where SID = \"".ProtectMySQL($sid)."\" and QID = \"".ProtectMySQL($qid)."\"";
			if ($stattype == 'u' || $stattype == 'v') {
				$cletter = ($stattype == 'u') ? 'n' : 'y';
				$qstring = "select phpQAnswer.Answer from phpQAnswer,phpQUser where phpQAnswer.SID = \"".ProtectMySQL($sid)."\" and phpQAnswer.QID = \"".ProtectMySQL($qid)."\" AND phpQAnswer.UID=phpQUser.UID AND phpQUser.EmailConfirm = \"$cletter\"";
			}
			$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]]]++;
						}
					}
					elseif (isset($answerid[$qanswers[$x]])) {
						$countarray[$answerid[$qanswers[$x]]]++;
					}
				}
			}

			$largestcount = 0;
			for ($x=0; $x<count($countarray); $x++) {
				$largestcount = ($countarray[$x] > $largestcount) ? $countarray[$x] : $largestcount;
				$totalcount += $countarray[$x];
			}

			for ($k=0; $k<sizeof($answerarray); $k++) {
				$percent = ($totalcount > 0) ? number_format((($countarray[$k] / $totalcount) * 100), 1) : 0;
				$barwidth = ($largestcount > 0) ? round(($countarray[$k] / $largestcount) * $barsize) : 0;
				if (!$barwidth) { $barwidth = 1; }

				// Only show tresultbutton if there were textfield results.
				if ($countarray[$k]) {
					if ($admin) {
						$answertext[$k] = preg_replace("/<!--javascript:([^\-]+)-->/", "<A HREF=\"javascript:$1\"><IMG SRC=\"$imgurl/tresultbutton.gif\" WIDTH=108 HEIGHT=12 BORDER=0 ALT=\"".$phpQlang["TextfieldResultsLink"]."\"></A>", $answertext[$k]);
					}
					else {
						$answertext[$k] = preg_replace("/<!--javascript:([^\-]+)-->/", "<A HREF=\"javascript:$1\"  STYLE=\"".$masurvey["ResultsAnswer"]."\"><NOBR>".$phpQlang["TextfieldResultsLink"]."</NOBR></A>", $answertext[$k]);
					}
				}

⌨️ 快捷键说明

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