Skip to content

Commit

Permalink
Updated Save Feature so user must press Save So Far to create saved_c…
Browse files Browse the repository at this point in the history
…ontrol record.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@1847 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shawn Wales committed Jul 31, 2006
1 parent 53a1f28 commit 67342c3
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 130 deletions.
24 changes: 12 additions & 12 deletions common.php
Expand Up @@ -1456,18 +1456,18 @@ function templatereplace($line)
//Set up save/load feature
if ($thissurvey['allowsave'] == "Y")
{
if (!isset($_SESSION['step']) || !$_SESSION['step'])
{
$saveall = "<input type='submit' name='loadall' value='"._("Load unfinished survey")."' class='saveall'>";
}
elseif ($_SESSION['step'] <= $_SESSION['totalsteps']) //Also modified so Save So Far shows up on last page.
{
$saveall = "<input type='submit' name='saveall' value='"._("Save your responses so far")."' class='saveall'>";
}
else
{
$saveall="";
}
if (!isset($_SESSION['step']) || !$_SESSION['step']) //First page, show LOAD
{
$saveall = "<input type='submit' name='loadall' value='"._LOAD_SAVED."' class='saveall'>";
}
elseif (isset($_SESSION['scid']) && (isset($_POST['move']) && $_POST['move'] == " "._LAST." ")) //Already saved and on Submit Page, don't show Save So Far button
{
$saveall="";
}
else
{
$saveall="<input type='submit' name='saveall' value='"._SAVE_AND_RETURN."' class='saveall' onclick=\"javascript:document.phpsurveyor.move.value = this.value;\">"; // Show Save So Far button
}
}
else
{
Expand Down
22 changes: 14 additions & 8 deletions group.php
Expand Up @@ -45,17 +45,23 @@
if (isset($_POST['move']) && $_POST['move'] == " "._("last")." ") {$_SESSION['step'] = $_POST['thisstep']+1;}

// --> START NEW FEATURE - SAVE
// So SAVE YOUR RESPONSES SO FAR stays on same page
if (isset($_POST['saveall']) && $_POST['saveall'] == _("Save your responses so far")) {$_SESSION['step']=$_POST['thisstep'];}
// If on SUBMIT page and select SAVE SO FAR it will return to SUBMIT page
if (isset($_POST['saveprompt']) && $_POST['saveprompt'] == "Y" && $_SESSION['step'] > $_SESSION['totalsteps'])
{
$_POST['move'] = " "._LAST." ";
}
// <-- END NEW FEATURE - SAVE

//CONVERT POSTED ANSWERS TO SESSION VARIABLES #################################################


//CHECK IF ALL MANDATORY QUESTIONS HAVE BEEN ANSWERED ############################################

//First, see if we are moving backwards, and its OK not to check:
if ($allowmandbackwards==1 && isset($_POST['move']) && $_POST['move'] == " << "._("prev")." ") {$backok="Y";} else {$backok="N";}
//First, see if we are moving backwards or doing a Save so far, and its OK not to check:
if ($allowmandbackwards==1 && ((isset($_POST['move']) && $_POST['move'] == " << "._PREV." ") || (isset($_POST['saveall']) && $_POST['saveall'] == _SAVE_AND_RETURN)))
{
$backok="Y";
}
else
{
$backok="N";
}

//Now, we check mandatory questions if necessary
//CHECK IF ALL CONDITIONAL MANDATORY QUESTIONS THAT APPLY HAVE BEEN ANSWERED
Expand Down
65 changes: 40 additions & 25 deletions index.php
Expand Up @@ -305,24 +305,19 @@


// --> START NEW FEATURE - SAVE
// SAVE POSTED ANSWERS TO DATABASE IF NEXT,PREV,LAST OR SUBMIT
if (isset($_POST['move']) && ($_POST['move'] == " << "._("prev")." " || $_POST['move'] == " "._("next")." >> " || $_POST['move'] == " "._("last")." " || $_POST['move'] == " "._("submit")." ")) {
// SAVE POSTED ANSWERS TO DATABASE IF MOVE (NEXT,PREV,LAST, or SUBMIT) or RETURNING FROM SAVE FORM
if (isset($_POST['move']) || isset($_POST['saveprompt']))
{
require_once("save.php");

// RELOAD THE ANSWERS INCASE SOMEONE ELSE CHANGED THEM
if ($thissurvey['active'] == "Y" && $thissurvey['allowsave'] == "Y") {
loadanswers();
}
}

if (isset($_POST['saveprompt'])) //Required when save form returns to save initial record
{
require_once("save.php");
}
// --> END NEW FEATURE - SAVE



sendcacheheaders();
//CALL APPROPRIATE SCRIPT
switch ($thissurvey['format'])
Expand All @@ -346,18 +341,30 @@ function loadanswers()
global $dbprefix,$surveyid,$errormsg;
global $thissurvey;

$query = "SELECT * FROM {$dbprefix}saved_control INNER JOIN {$thissurvey['tablename']}
ON {$dbprefix}saved_control.srid = {$thissurvey['tablename']}.id
WHERE {$dbprefix}saved_control.sid=$surveyid\n";
if (isset($_POST['scid']))
if (!isset($_POST['srid']))
{
return true;
}

if (isset($_POST['scid']))
{
$query = "SELECT * FROM {$dbprefix}saved_control INNER JOIN {$thissurvey['tablename']}
ON {$dbprefix}saved_control.srid = {$thissurvey['tablename']}.id
WHERE {$dbprefix}saved_control.sid=$surveyid\n";
if (isset($_POST['scid']))
{
$query .= "AND {$dbprefix}saved_control.scid=".auto_escape($_POST['scid'])."\n";
}
$query .="AND {$dbprefix}saved_control.identifier='".auto_escape($_SESSION['holdname'])."'
AND {$dbprefix}saved_control.access_code='".md5(auto_unescape($_SESSION['holdpass']))."'\n";
}
else
{
$query .= "AND {$dbprefix}saved_control.scid=".auto_escape($_POST['scid'])."\n";
$query = "SELECT * FROM {$thissurvey['tablename']}
WHERE {$thissurvey['tablename']}.srid=".$_SESSION['srid']."\n";
}
$query .="AND {$dbprefix}saved_control.identifier='".auto_escape($_SESSION['holdname'])."'
AND {$dbprefix}saved_control.access_code='".md5(auto_unescape($_SESSION['holdpass']))."'\n";

$result = mysql_query($query) or die ("Error loading results<br />$query<br />".mysql_error());

if (mysql_num_rows($result) < 1)
{
$errormsg .= _("There is no matching saved survey")."<br />\n";
Expand All @@ -372,24 +379,24 @@ function loadanswers()
$column = mysql_field_name($result,$i);
if ($column == "token")
{
$_POST['token']=$value;
$_POST['token']=$value;
$token=$value;
}
if ($column == "saved_thisstep")
{
$_SESSION['step']=$value;
$_SESSION['step']=$value;
}
if ($column == "scid")
{
$_SESSION['scid']=$value;
$_SESSION['scid']=$value;
}
if ($column == "srid")
{
$_SESSION['srid']=$value;
$_SESSION['srid']=$value;
}
if ($column == "datestamp")
{
$_SESSION['datestamp']=$value;
$_SESSION['datestamp']=$value;
}
else
{
Expand Down Expand Up @@ -883,7 +890,7 @@ function createinsertquery()
// INSERT NEW ROW
// TODO SQL: quote colum name correctly
$query = "INSERT INTO ".db_quote_id($thissurvey['tablename'])."\n"
."(".implode(', ', array_map('db_quote_id',$colnames)).")\n";
."(".implode(', ', array_map('db_quote_id',$colnames));
if ($thissurvey['datestamp'] == "Y")
{
$query .= ",`datestamp`";
Expand All @@ -896,6 +903,10 @@ function createinsertquery()
{
$query .= ",`refurl`";
}
if ((isset($_POST['move']) && $_POST['move'] == " "._SUBMIT." "))
{
$query .= ",'submitdate'";
}
$query .=") ";
$query .="VALUES (".implode(", ", $values);
if ($thissurvey['datestamp'] == "Y")
Expand All @@ -910,6 +921,10 @@ function createinsertquery()
{
$query .= ", '".getenv("HTTP_REFERER")."'";
}
if ((isset($_POST['move']) && $_POST['move'] == " "._SUBMIT." "))
{
$query .= ", '".date("Y-m-d H:i:s")."'";
}
$query .=")";
}
else
Expand Down Expand Up @@ -1033,7 +1048,7 @@ function sendsubmitnotification($sendnotification)
. _("A new response was entered for your survey")."\r\n\r\n";
if ($thissurvey['allowsave'] == "Y")
{
$message .= _CONFIRMATION_MESSAGE6 . "\r\n";
$message .= _("Click the following link to reload the survey:")."\r\n";
$message .= " $publicurl/index.php?sid=$surveyid&loadall=reload&scid=".$_SESSION['scid']."&loadname=".urlencode($_SESSION['holdname'])."&loadpass=".urlencode($_SESSION['holdpass'])."\r\n\r\n";
}

Expand Down Expand Up @@ -1246,7 +1261,7 @@ function buildsurveysession()
$_SESSION['totalsteps']=count($_SESSION['grouplist']);
break;
case "S":
$_SESSION['totalsteps']=$totalquestions;
$_SESSION['totalsteps']=$totalquestions;
}

if ($totalquestions == "0") //break out and crash if there are no questions!
Expand Down
24 changes: 17 additions & 7 deletions question.php
Expand Up @@ -45,27 +45,37 @@
if (isset($_POST['move']) && $_POST['move'] == " "._("last")." ") {$_SESSION['step'] = $_POST['thisstep']+1;}

// --> START NEW FEATURE - SAVE
// So SAVE YOUR RESPONSES SO FAR stays on same page
if (isset($_POST['saveall']) && $_POST['saveall'] == _("Save your responses so far")) {$_SESSION['step']=$_POST['thisstep'];}
// If on SUBMIT page and select SAVE SO FAR it will return to SUBMIT page
if (isset($_POST['saveprompt']) && $_POST['saveprompt'] == "Y" && $_SESSION['step'] > $_SESSION['totalsteps'])
{
$_POST['move'] = " "._LAST." ";
}
// <-- END NEW FEATURE - SAVE

//CHECK IF ALL MANDATORY QUESTIONS HAVE BEEN ANSWERED ############################################
//First, see if we are moving backwards or doing a Save so far, and its OK not to check:
if ($allowmandbackwards==1 && ((isset($_POST['move']) && $_POST['move'] == " << "._PREV." ") || (isset($_POST['saveall']) && $_POST['saveall'] == _SAVE_AND_RETURN)))
{
$backok="Y";
}
else
{
$backok="N";
}

//CHECK IF ALL MANDATORY QUESTIONS HAVE BEEN ANSWERED
if (isset($_POST['move']) && $allowmandbackwards==1 && $_POST['move'] == " << "._("prev")." ") {$backok="Y";} else {$backok="N";}

//Now, we check mandatory questions if necessary
//CHECK IF ALL CONDITIONAL MANDATORY QUESTIONS THAT APPLY HAVE BEEN ANSWERED
$notanswered=addtoarray_single(checkmandatorys($backok),checkconditionalmandatorys($backok));

//CHECK PREGS
$notvalidated=checkpregs($backok);

// --> START BUG FIX
// Check for session timeout
if (session_id()=='')
{
echo "Sorry, your sessions seems to have expired. Please restart the survey. (1)";
die();
}
// --> END BUG FIX

//SUBMIT
if (isset($_POST['move']) && $_POST['move'] == " "._("submit")." ")
Expand Down

0 comments on commit 67342c3

Please sign in to comment.