📄 sfunctions.php
字号:
<?php
function createstats( $masurvey, $stattype, $view, $admin )
{
global $phpQlang;
$imgurl = $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 ? "调查表问题列表" : "<H2>".$phpQlang['AllSurveyResults']."</H2>";
}
$contents = "<TABLE CELLPADDING=0 CELLSPACING=0 width=100% BORDER=0>\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 = $qcount ? $qcount : 1;
$cq = $cq ? $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" )
{
}
else if ( $maquestion['Type'] != "pagebreak" )
{
$contents .= printquestion( $masurvey, $maquestion, $qcount, $stattype, $admin );
$contents .= printborder( $admin, $masurvey['ResultsWidth'] );
++$qcount;
$foundq = 1;
}
else if ( $view == "p" && $foundq )
{
$contents .= printsubmit( $masurvey, $qcount, $cq, $sid, $stattype, $view, $admin );
}
}
}
else if ( 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 ) ) && $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> " : $phpQlang['*']." ";
}
$tablewidth = $masurvey['ResultsWidth'] ? $masurvey['ResultsWidth'] : 500;
$tablewidth = $admin ? 500 : $tablewidth;
$contents = "<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0 WIDTH=100%>\n";
$contents .= "<TR><TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>";
$contents .= "<TD VALIGN=top><NOBR><B>{$required}".$phpQlang['Question']." {$qcount}:</B> </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 = $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% class=small>\n";
$tcolspan = $admin ? 3 : 4;
$tcolspan -= $type == "textfield" || $type == "textarea" ? 1 : 0;
if ( $admin )
{
$contents .= "<TR class=tablehead2><TD HEIGHT=17 COLSPAN={$tcolspan}>{$typeheader}</TD><TD WIDTH=7 ALIGN=right VALIGN=top></TD></TR>";
}
else
{
$contents .= "<TR class=tablehead2><TD HEIGHT=17 COLSPAN={$tcolspan} >{$typeheader}</TD></TR>";
}
$bordercol = "<TD HEIGHT=16></TD>";
if ( !$admin )
{
$bordercol = "<TD HEIGHT=16 STYLE=\"".$masurvey['ResultsBorder']."\"></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;
$i = 0;
for ( ; $i < sizeof( $temparray ); ++$i )
{
$tempsplit = split( "\\|\\|", $temparray[$i] );
if ( $tempsplit[4] != "Y" && ( $type == "select" || $type == "selectmult" ) )
{
}
else
{
$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 COLSPAN=2 WIDTH=100%>";
$temptext .= "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%>";
$temptext .= ( "<TR><TD><B>".( $count + 1 ) ).".</B> {$ochoice} </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> {$ochoice} </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 COLSPAN=2 WIDTH=100%><B>".( $count + 1 ) ).".</B> {$ochoice}</TD>";
}
else
{
$temptext = ( "<TD COLSPAN=2 WIDTH=100% STYLE=\"padding-left: 5px; padding-right: 5px; ".$masurvey['ResultsAnswer']."\"><B>".( $count + 1 ) ).".</B> {$ochoice}</TD>";
}
}
$answertext[] = "<TR class=TableLine1>".$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 );
$j = 0;
for ( ; $j < mysql_num_rows( $mqanswercount ); ++$j )
{
$maanswercount = mysql_fetch_array( $mqanswercount );
$qanswers = split( "\\|\\|", $maanswercount['Answer'] );
$x = 0;
for ( ; $x < count( $qanswers ); ++$x )
{
if ( preg_match( "/^O/", $qanswers[$x] ) )
{
$oanswers = split( "\\|", $qanswers[$x] );
if ( isset( $answerid[$oanswers[0]] ) )
{
++$countarray[$answerid[$oanswers[0]]];
}
}
else if ( isset( $answerid[$qanswers[$x]] ) )
{
++$countarray[$answerid[$qanswers[$x]]];
}
}
}
$largestcount = 0;
$x = 0;
for ( ; $x < count( $countarray ); ++$x )
{
$largestcount = $largestcount < $countarray[$x] ? $countarray[$x] : $largestcount;
$totalcount += $countarray[$x];
}
$k = 0;
for ( ; $k < sizeof( $answerarray ); ++$k )
{
$percent = 0 < $totalcount ? number_format( $countarray[$k] / $totalcount * 100, 1 ) : 0;
$barwidth = 0 < $largestcount ? round( $countarray[$k] / $largestcount * $barsize ) : 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -