📄 fillsurvey.php
字号:
<?
################################################################################
# phpQuestionnaire Version 2.2 #
# Copyright 2003-2005 chumpsoft, inc. March 28, 2005 #
################################################################################
# SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS #
################################################################################
#-->> Include Files
require("inc/init.php");
require("inc/mysql.php");
require("inc/functions.php");
require("inc/pfunctions.php");
require("inc/qfunctions.php");
require("inc/vfunctions.php");
#-->> Setting Variables
$varnames = array("action", "sid", "cq");
SetVars($varnames);
#-->> Admin Preview Only
$admin = 0;
if ($action == "preview") {
if (!IsAdmin()) {
header("Location: admin/index.php?errormsg=AdminPreview");
exit();
}
$admin = 1;
}
#-->> State Variables
$cq = ($cq) ? $cq : 1;
#-->> Checking for SID Validity
$qstring = "select *, UNIX_TIMESTAMP(StartDate) as starttime, UNIX_TIMESTAMP(EndDate) as endtime, UNIX_TIMESTAMP(NOW()) as nowtime from phpQSurvey where SID = \"".ProtectMySQL($sid)."\"";
if (!($masurvey = mysql_fetch_array(mysql_query($qstring)))) {
header("Location: index.php");
exit();
}
if ($masurvey["SurveyResults"] == 2 && (isset($HTTP_POST_VARS["results"]) || isset($HTTP_POST_VARS["results_x"]))) {
header("Location: stats.php?sid=".ProtectHTML($masurvey["SID"]));
exit();
}
#-->> Set Language...
SetLanguage($masurvey['Language']);
#-->> Cookie Test
$cookiedomain = ($phpQAdmin['CookieDomain'] != '') ? $phpQAdmin['CookieDomain'] : '';
setcookie("phpQTest", "true", 0, '/', $cookiedomain);
#-->> Checking Activation
if ($masurvey["Active"] == "n" && $action != "preview") {
$errormsg = sprintf($phpQlang["SurveyNotActive"], $masurvey["Name"]);
}
elseif ($action != "preview") {
if (substr($masurvey["StartDate"],0,10) != "0000-00-00" &&
$masurvey["starttime"] > $masurvey["nowtime"]) {
$errormsg = sprintf($phpQlang["SurveyPending"], $masurvey["Name"]);
}
if (substr($masurvey["EndDate"],0,10) != "0000-00-00" &&
$masurvey["endtime"] < $masurvey["nowtime"]) {
$errormsg = sprintf($phpQlang["SurveyExpired"], $masurvey["Name"]);
}
}
#-->> Question Counting
$mqqcount = mysql_query("select count(*) as ct from phpQQuestion where SID = \"".ProtectMySQL($sid)."\"");
$surveyqcount = ($maqcount = mysql_fetch_array($mqqcount)) ? $maqcount["ct"] : 0;
#-->> Simplifying Variables
$tablewidth = $masurvey["Width"];
#-->> Checking for Survey Completion
$questionresult = GetQuestions($admin, $cq, $surveyqcount, $masurvey);
if ($cq == "done" && $questionresult[1] == "complete" && $action != "preview") {
if ($surveyqcount > 0) {
$storesurvey = true;
# Different Methods of Marking Completion
# Make sure a user is not submitting a second results set using same form.
$ufid = $HTTP_POST_VARS["ufid"];
if ($ufid != '') {
$mqbdtest = mysql_query("select UID,Email,EmailConfirm from phpQUser where BlockDupe = \"".ProtectMySQL($HTTP_POST_VARS["ufid"])."\" and SID = \"".ProtectMySQL($sid)."\" LIMIT 1");
if ($storeddata = mysql_fetch_array($mqbdtest)) {
$storesurvey = false;
}
}
else {
$storesurvey = false;
}
$ip = $REMOTE_ADDR ? $REMOTE_ADDR : $HTTP_SERVER_VARS["REMOTE_ADDR"];
$suarray = ParseSurveyUsers($masurvey["SurveyUsers"]);
if ($suarray[0]) { # Unique IP
$mqiptest = mysql_query("select UID,Email,EmailConfirm from phpQUser where IPAddr = \"".ProtectMySQL($ip)."\" and SID = \"".ProtectMySQL($sid)."\" LIMIT 1");
if ($storeddata = mysql_fetch_array($mqiptest)) {
$storesurvey = false;
}
}
if ($suarray[1]) { # Cookies
$cookiename = "phpQ".$phpQAdmin["phpQID"].$sid;
if ($HTTP_COOKIE_VARS[$cookiename] || !$HTTP_COOKIE_VARS["phpQTest"]) {
$storesurvey = false;
$cuid = $HTTP_COOKIE_VARS[$cookiename];
if ($cuid != '' && is_numeric($cuid)) {
$mcquery = mysql_query("select UID,Email,EmailConfirm from phpQUser where SID = \"".ProtectMySQL($sid)."\" and UID = \"".ProtectMySQL($cuid)."\" limit 1");
$storeddata = mysql_fetch_array($mcquery);
}
else { $storereason = 'cookies'; }
}
}
if ($storesurvey) {
$uid = GenerateUID();
$cryptuid = mt_rand(100000, 999999);
if ($suarray[1]) { # Cookies
setcookie($cookiename, $uid, time()+60*60*24*365, '/', $cookiedomain);
}
mysql_query("insert into phpQUser (UID, SID, IPAddr, BlockDupe, CheckType, CompleteDate, Confirm) values (\"".ProtectMySQL($uid)."\", \"".ProtectMySQL($sid)."\", \"".ProtectMySQL($ip)."\", \"".ProtectMySQL($ufid)."\", \"".ProtectMySQL($masurvey["SurveyUsers"])."\", now(), \"".ProtectMySQL($cryptuid)."\")");
$mqqlist = mysql_query("select * from phpQQuestion where SID = \"".ProtectMySQL($sid)."\" and Type != 'htmlcontent' order by SortOrder");
while ($maqlist = mysql_fetch_array($mqqlist)) {
if ($maqlist["Type"] != "pagebreak") {
$storeanswer = StoreAnswer($maqlist, $masurvey);
if ($storeanswer[0]) {
mysql_query("insert into phpQAnswer (UID, SID, QID, Answer) values (\"".ProtectMySQL($uid)."\", \"".ProtectMySQL($sid)."\", \"".ProtectMySQL($maqlist["QID"])."\", \"".ProtectMySQL($storeanswer[1])."\")");
}
}
}
# If a response notice should be emailed to administrators, do so.
if ($masurvey["ResponseNotice"] && $masurvey["ResponseEmail"] != '') {
$surveydata = '';
$headers = '';
if ($masurvey["ResponseNotice"] == '2') {
$surveydata = RecreateSurvey($sid, $uid, '100%', $masurvey, 1);
$headers .= "Content-type: text/html\n";
}
else {
$scriptloc = '';
if ($HTTP_HOST != '') {
$scriptloc .= "http://$HTTP_HOST";
}
elseif ($HTTP_SERVER_VARS["HTTP_HOST"] != '') {
$scriptloc .= 'http://'.$HTTP_SERVER_VARS["HTTP_HOST"];
}
$php_self = $PHP_SELF ? $PHP_SELF : $HTTP_SERVER_VARS["PHP_SELF"];
if (!$php_self && $HTTP_SERVER_VARS['REQUEST_URI']) {
$php_self = $HTTP_SERVER_VARS['REQUEST_URI'];
}
$scriptloc .= $php_self;
$scriptloc = preg_replace("/(.*)\/.*/", "\\1", $scriptloc);
$scriptloc = "$scriptloc/view.php?sid=$sid&uid=$uid";
$surveydata = $phpQlang['RNEmailLinkText'];
$surveydata = str_replace('::SurveyName::', $masurvey["Name"], $surveydata);
$surveydata = str_replace('::ResultsLink::', $scriptloc, $surveydata);
$mqinfo = mysql_query("select * from phpQUser where SID = \"".ProtectMySQL($sid)."\" and UID = \"".ProtectMySQL($uid)."\"");
if ($mainfo = mysql_fetch_array($mqinfo)) {
$ipaddr = ($mainfo["IPAddr"]) ? $mainfo["IPAddr"] : $phpQlang['unavailable'];
$surveydata = str_replace('::CompleteDate::', $mainfo["CompleteDate"], $surveydata);
$surveydata = str_replace('::IPAddress::', $ipaddr, $surveydata);
}
}
$headers .= 'From: ' . ($masurvey["EmailFrom"] != '' ? $masurvey["EmailFrom"] : $phpQlang["EmailDefaultFrom"]) . "\n";
mail($masurvey["ResponseEmail"],sprintf($phpQlang["ViewSurvey"], $masurvey["Name"]),$surveydata, $headers);
}
if ($suarray[2] && (ini_get("sendmail_path") || ini_get("SMTP"))) { # Verified Email
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=verify.php?uid=$uid&sid=$sid\"></head></html>";
exit();
}
# Complete Notice
if ($masurvey["OnComplete"] == '1' && $masurvey["SurveyResults"]) {
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=stats.php?sid=$sid\"></head></html>";
exit();
}
elseif ($masurvey["OnComplete"] == '2' && $masurvey["RedirectURL"]) {
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; URL=".ProtectHTML($masurvey["RedirectURL"])."\"></head></html>";
exit();
}
elseif ($masurvey["OnComplete"] == '3') {
$contents = $phpQlang["YourResponse"].'<BR><BR>';
$contents .= RecreateSurvey($sid, $uid, $masurvey["Width"], $masurvey, 1);
}
elseif ($masurvey["Completed"]) { $contents = $masurvey["Completed"]; }
else {
$defmesg = sprintf($phpQlang["SurveyCompleted"], $masurvey["Name"]);
$contents = PrintMessage($defmesg, $tablewidth);
}
}
else {
if ($storereason == 'cookies') {
$errormsg = sprintf($phpQlang["SurveyCookieError"], $masurvey["Name"]);
}
# If the storage failed for another reason, we will try to
else {
if ($storeddata) {
$uid = $storeddata["UID"];
# Verified Email
if ($suarray[2] && (ini_get("sendmail_path") || ini_get("SMTP"))) {
if ($storeddata["Email"] == '') {
header("Location: verify.php?uid=$uid&sid=$sid");
exit();
}
elseif ($storeddata["EmailConfirm"] == 'n') {
header("Location: confirm.php?uid=$uid&sid=$sid");
exit();
}
}
# Complete Notice
if ($masurvey["OnComplete"] == '1' && $masurvey["SurveyResults"]) {
header("Location: stats.php?sid=$sid");
exit();
}
elseif ($masurvey["OnComplete"] == '2' && $masurvey["RedirectURL"]) {
header("Location: ".ProtectHTML($masurvey["RedirectURL"]));
exit();
}
elseif ($masurvey["OnComplete"] == '3') {
$contents = $phpQlang["YourResponse"].'<BR><BR>';
$contents .= RecreateSurvey($sid, $uid, $masurvey["Width"], $masurvey, 1);
}
elseif ($masurvey["Completed"]) { $contents = $masurvey["Completed"]; }
else {
$errormsg = sprintf($phpQlang["SurveyCompletedAlready"], $masurvey["Name"]);
}
}
else {
$errormsg = sprintf($phpQlang["SurveyCompletedAlready"], $masurvey["Name"]);
}
}
}
}
}
elseif ($cq == "done" && $questionresult[1] == "complete" && $action == "preview") {
$prevcompmesg = sprintf($phpQlang["SurveyPreviewCompleted"], $masurvey["Name"]);
$contents = "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%>\n";
$contents .= "<FORM>\n";
$contents .= "<TR><TD ALIGN=center STYLE=\"".$masurvey["ErrorStyle"]."\">";
$contents .= "$prevcompmesg</TD></TR>\n";
$contents .= "<TR><TD>".$masurvey["Completed"]."</TD></TR>\n";;
$contents .= "<TR><TD ALIGN=center><INPUT TYPE=button ONCLICK=\"window.close();\" VALUE=\"".$phpQlang["Close"]."\"></TD></TR>\n";
$contents .= "</FORM>\n";
$contents .= "</TABLE>\n";
}
else {
$contents .= CreateSurvey($sid, $cq, $tablewidth, $questionresult[2], $admin);
}
#-->> Checking for Questions in Survey
if ($surveyqcount == 0) {
$errormsg = sprintf($phpQlang["SurveyEmpty"], $masurvey["Name"]);
}
#-->> Overwriting Contents if Deactivated
$contents = ($errormsg) ? PrintMessage($errormsg, $tablewidth) : $contents;
#-->> Output Page
CreatePage($sid, $masurvey["Name"], $contents, false, "");
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -