diff --git a/group.php b/group.php index e89bd65d092..ffea3de3e2a 100644 --- a/group.php +++ b/group.php @@ -173,11 +173,6 @@ //SUBMIT if ($_POST['move'] == " "._SUBMIT." ") { - foreach(file("$thistpl/startpage.pstpl") as $op) - { - echo templatereplace($op); - } - //If survey has datestamp turned on, add $localtimedate to sessions if ($surveydatestamp == "Y") { @@ -214,6 +209,11 @@ } else { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } echo "
"._ERROR."

\n"; echo _BADSUBMIT1."

\n"; echo ""._BADSUBMIT2."
\n"; @@ -223,6 +223,11 @@ //COMMIT CHANGES TO DATABASE if ($surveyactive != "Y") { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _NOTACTIVE1."

\n"; $completed .= ""._CLEARRESP."

\n"; @@ -230,8 +235,20 @@ } else { - if (mysql_query($subquery)) + if (mysql_query($subquery)) //submit of responses was successful { + //UPDATE COOKIE IF REQUIRED + if ($surveyusecookie == "Y" && $tokensexist != 1) + { + $cookiename="PHPSID".returnglobal('sid')."STATUS"; + $cookie_life = time() + 31536000; // 1 year life + setcookie($cookiename, "COMPLETE", $cookielife); + } + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._THANKS."

\n\n"; $completed .= _SURVEYREC."
\n"; $completed .= ""._CLOSEWIN."


\n"; @@ -275,6 +292,11 @@ } else { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _DIDNOTSAVE2."

\n"; if ($adminemail) @@ -377,14 +399,6 @@ exit; } -//SEE IF THERE ARE TOKENS FOR THIS SURVEY -$i = 0; $tokensexist = 0; -$tresult = @mysql_list_tables($databasename) or die ("Error getting tokens
".mysql_error()); -while($tbl = @mysql_tablename($tresult, $i++)) - { - if ($tbl == "tokens_$sid") {$tokensexist = 1;} - } - //RUN THIS IF THIS IS THE FIRST TIME if (!$_SESSION['step']) { diff --git a/index.php b/index.php index c572fc83e63..4b655f3a5d6 100644 --- a/index.php +++ b/index.php @@ -39,12 +39,6 @@ include("./admin/config.php"); -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past -header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified -header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); // HTTP/1.0 - //DEFAULT SETTINGS FOR TEMPLATES if (!$publicdir) {$publicdir=".";} $tpldir="$publicdir/templates"; @@ -53,6 +47,7 @@ if (!$_GET['sid'] && !$_POST['sid']) { //A nice crashout + sendcacheheaders(); echo "\n"; $output=file("$tpldir/default/startpage.pstpl"); foreach($output as $op) @@ -60,7 +55,7 @@ echo templatereplace($op); } echo "\t\t

\n"; - echo "\t\t\tERROR:
\n"; + echo "\t\t\tERROR
\n"; echo "\t\t\tYou have not provided a survey identification number.

\n"; echo "\t\t\tPlease contact $siteadminname at $siteadminemail for further assistance.

\n"; $output=file("$tpldir/default/endpage.pstpl"); @@ -73,15 +68,17 @@ } //GET BASIC INFORMATION ABOUT THIS SURVEY -$sid=$_GET['sid']; if (!$sid) {$sid=$_POST['sid'];} -if (!$token) - { - $token=$_GET['token']; - if (!$token) - { - $token=$_POST['token']; - } - } +if (!isset($sid)) {$sid=returnglobal('sid');} +if (!isset($token)) {$token=returnglobal('token');} +//$sid=$_GET['sid']; if (!$sid) {$sid=$_POST['sid'];} +//if (!$token) +// { +// $token=$_GET['token']; +// if (!$token) +// { +// $token=$_POST['token']; +// } +// } $query="SELECT * FROM surveys WHERE sid=$sid"; $result=mysql_query($query) or die ("Couldn't access surveys
$query
".mysql_error()); $surveyexists=mysql_num_rows($result); @@ -102,6 +99,15 @@ $surveyformat = $row['format']; $surveylanguage = $row['language']; $surveydatestamp = $row['datestamp']; + $surveyusecookie = $row['usecookie']; + } + +//SEE IF SURVEY USES TOKENS +$i = 0; $tokensexist = 0; +$tresult = @mysql_list_tables($databasename) or die ("Error getting tokens
".mysql_error()); +while($tbl = @mysql_tablename($tresult, $i++)) + { + if ($tbl == "tokens_$sid") {$tokensexist = 1;} } //SET THE TEMPLATE DIRECTORY @@ -115,9 +121,35 @@ if (!is_file($langfilename)) {$langfilename="$langdir/$defaultlang.lang.php";} require($langfilename); +//CHECK FOR PREVIOUSLY COMPLETED COOKIE +//If cookies are being used, and this survey has been completed, a cookie called "PHPSID[sid]STATUS" will exist (ie: SID6STATUS) and will have a value of "COMPLETE" +$cookiename="PHPSID".returnglobal('sid')."STATUS"; +if ($_COOKIE[$cookiename] == "COMPLETE" && $surveyusecookie == "Y" && $tokensexist != 1) + { + sendcacheheaders(); + echo "\n"; + $output=file("$tpldir/default/startpage.pstpl"); + foreach($output as $op) + { + echo templatereplace($op); + } + echo "\t\t

\n"; + echo "\t\t\t"._ERROR."
\n"; + echo "\t\t\tYou have already completed this survey.

\n"; + echo "\t\t\tPlease contact $siteadminname at $siteadminemail for further assistance.

\n"; + $output=file("$tpldir/default/endpage.pstpl"); + foreach($output as $op) + { + echo templatereplace($op); + } + echo "\n"; + exit; + } + //CLEAR SESSION IF REQUESTED if ($_GET['move'] == "clearall") { + sendcacheheaders(); echo "\n"; foreach(file("$thistpl/startpage.pstpl") as $op) { @@ -157,10 +189,9 @@ { session_unset(); } - //session_unset(); - //session_destroy(); } +sendcacheheaders(); //CALL APPROPRIATE SCRIPT switch ($surveyformat) { diff --git a/question.php b/question.php index a1c41ede099..123adbfa365 100644 --- a/question.php +++ b/question.php @@ -154,12 +154,6 @@ //SUBMIT if ($_POST['move'] == " "._SUBMIT." ") { - echo "\n"; - foreach(file("$thistpl/startpage.pstpl") as $op) - { - echo templatereplace($op); - } - //If survey has datestamp turned on, add $localtimedate to sessions if ($surveydatestamp == "Y") { @@ -194,8 +188,13 @@ $values = substr($values, 2); //Strip off first comma & space $subquery .= "\n($col_name) \nVALUES \n($values)"; } - else + else //there is no insertarray { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } echo "
"._ERROR."

\n"; echo _BADSUBMIT1."

\n"; echo ""._BADSUBMIT2."
\n"; @@ -205,15 +204,32 @@ //COMMIT CHANGES TO DATABASE if ($surveyactive != "Y") { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _NOTACTIVE1."

\n"; $completed .= ""._CLEARRESP."

\n"; $completed .= "$subquery\n"; } - else + else //submit the responses { - if (mysql_query($subquery)) + if (mysql_query($subquery)) //submit was successful { + //UPDATE COOKIE IF REQUIRED + if ($surveyusecookie == "Y" && $tokensexist != 1) //don't use cookies if tokens are being used + { + $cookiename="PHPSID".returnglobal('sid')."STATUS"; + $cookie_life = time() + 31536000; // 1 year life + setcookie($cookiename, "COMPLETE", $cookielife); + } + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._THANKS."

\n\n"; $completed .= _SURVEYREC."
\n"; $completed .= ""._CLOSEWIN."


\n"; @@ -255,8 +271,13 @@ session_unset(); session_destroy(); } - else + else //submit failed { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _DIDNOTSAVE2."

\n"; if ($adminemail) @@ -318,14 +339,6 @@ exit; } -//SEE IF THERE ARE TOKENS FOR THIS SURVEY -$i = 0; $tokensexist = 0; -$tresult = @mysql_list_tables($databasename) or die ("Error getting tokens
".mysql_error()); -while($tbl = @mysql_tablename($tresult, $i++)) - { - if ($tbl == "tokens_$sid") {$tokensexist = 1;} - } - //RUN THIS IF THIS IS THE FIRST TIME if (!$_SESSION['step']) { diff --git a/survey.php b/survey.php index 100b506a913..f795da64466 100644 --- a/survey.php +++ b/survey.php @@ -182,12 +182,6 @@ $privacy .= $op; } } - echo "\n"; - foreach(file("$thistpl/startpage.pstpl") as $op) - { - echo templatereplace($op); - } - //If survey has datestamp turned on, add $localtimedate to sessions if ($surveydatestamp == "Y") { @@ -224,6 +218,11 @@ } else { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } echo "
"._ERROR."

\n"; echo _BADSUBMIT1."

\n"; echo ""._BADSUBMIT2."
\n"; @@ -233,6 +232,11 @@ //COMMIT CHANGES TO DATABASE if ($surveyactive != "Y") { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _NOTACTIVE1."

\n"; $completed .= ""._CLEARRESP."

\n"; @@ -240,8 +244,20 @@ } else { - if (mysql_query($subquery)) + if (mysql_query($subquery)) //save responses was succesful { + //UPDATE COOKIE IF REQUIRED + if ($surveyusecookie == "Y" && $tokensexist != 1) + { + $cookiename="PHPSID".returnglobal('sid')."STATUS"; + $cookie_life = time() + 31536000; // 1 year life + setcookie($cookiename, "COMPLETE", $cookielife); + } + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._THANKS."

\n\n"; $completed .= _SURVEYREC."
\n"; $completed .= ""._CLOSEWIN."


\n"; @@ -285,6 +301,11 @@ } else { + echo "\n"; + foreach(file("$thistpl/startpage.pstpl") as $op) + { + echo templatereplace($op); + } $completed = "
"._DIDNOTSAVE."

\n\n"; $completed .= _DIDNOTSAVE2."

\n"; if ($adminemail) @@ -381,14 +402,6 @@ exit; } -//SEE IF THERE ARE TOKENS FOR THIS SURVEY -$i = 0; $tokensexist = 0; -$tresult = @mysql_list_tables($databasename) or die ("Error getting tokens
".mysql_error()); -while($tbl = @mysql_tablename($tresult, $i++)) - { - if ($tbl == "tokens_$sid") {$tokensexist = 1;} - } - //RUN THIS IF THIS IS THE FIRST TIME if (!$_SESSION['step']) {