START NEW FEATURE - SAVE) How it used to work ------------------- 1. The old save method would save answers to the "survey_x" table only when the submit button was clicked. 2. If "allow saves" was turned on then answers were temporarily recorded in the "saved" table. Why change this feature? ------------------------ If a user did not complete a survey, ALL their answers were lost since no submit (database insert) was performed. Save Feature redesign --------------------- Benefits Partial survey answers are saved (provided at least Next/Prev/Last/Submit/Save so far clicked at least once). Details. 1. The answers are saved in the "survey_x" table only. The "saved" table is no longer used. 2. The "saved_control" table has new column (srid) that points to the "survey_x" record it corresponds to. 3. Answers are saved every time you move between pages (Next,Prev,Last,Submit, or Save so far). 4. Only the fields modified on the page are updated. A new hidden field "modfields" store which fields have changed. - REVERTED 5. Answered are reloaded from the database after the save so that if some other answers were modified by someone else the updates would be picked up for the current page. There is still an issue if two people modify the same answer at the same time.. the 'last one to save' wins. 6. The survey_x datestamp field is updated every time the record is updated. 7. Template can now contain {DATESTAMP} to show the last modified date/time. 8. A new field 'submitdate' has been added to the survey_x table and is written when the submit button is clicked. 9. Save So Far now displays on Submit page. This allows the user one last chance to create a saved_control record so they can return later. Notes ----- 1. A new column SRID has been added to saved_control. 2. saved table no longer exists. */ if (!isset($homedir) || isset($_REQUEST['$homedir'])) {die("Cannot run this script directly");} global $connect; //First, save the posted data to session //Doing this ensures that answers on the current page are saved as well. //CONVERT POSTED ANSWERS TO SESSION VARIABLES if (isset($_POST['fieldnames']) && $_POST['fieldnames']) { $postedfieldnames=explode("|", $_POST['fieldnames']); // Remove invalid fieldnames from fieldnames array for($x=count($postedfieldnames)-1;$x>=0;$x--) { if (strpos($postedfieldnames[$x],$surveyid.'X')===false) { array_remval($postedfieldnames[$x],$postedfieldnames); } } $_POST['fieldnames']=implode("|",$postedfieldnames); foreach ($postedfieldnames as $pf) { if (isset($_POST[$pf])) {$_SESSION[$pf] = $_POST[$pf];} if (!isset($_POST[$pf])) {$_SESSION[$pf] = "";} } } //Check to see if we should set a submitdate or not // this depends on the move, and on quesitons checks if (isset($move) && $move == "movesubmit") { $backok=null; $notanswered=addtoarray_single(checkmandatorys($move,$backok),checkconditionalmandatorys($move,$backok)); $notvalidated=checkpregs($move,$backok); if ( (!is_array($notanswered) || count($notanswered)==0) && (!is_array($notvalidated) || count($notvalidated)==0) ) { $bFinalizeThisAnswer = true; } else { $bFinalizeThisAnswer = false; } } else { $bFinalizeThisAnswer = false; } //SAVE if on page with questions or on submit page if ((isset($_POST['fieldnames']) && $_POST['fieldnames']) || (isset($_POST['move']) && $_POST['move'] == "movesubmit")) { if ($thissurvey['active'] == "Y" && !isset($_SESSION['finished'])) // Only save if active and the survey wasn't already submitted { // SAVE DATA TO SURVEY_X RECORD $subquery = createinsertquery(); if ($subquery) { if ($result=$connect->Execute($subquery)) // Checked { if (substr($subquery,0,6)=='INSERT') { $tempID=$connect->Insert_ID($thissurvey['tablename'],"id"); // Find out id immediately if inserted $_SESSION['srid'] = $tempID; $saved_id = $tempID; } //queXS addition include_once('quexs.php'); global $surveyid; quexs_update_sample($surveyid,$saved_id,$postedfieldnames); if ($bFinalizeThisAnswer === true) { $connect->Execute("DELETE FROM ".db_table_name("saved_control")." where srid=".$_SESSION['srid'].' and sid='.$surveyid); // Checked } } else { echo submitfailed($connect->ErrorMsg()); } } } } // CREATE SAVED CONTROL RECORD USING SAVE FORM INFORMATION if (isset($_POST['saveprompt']) || ($thissurvey['allowsave'] == "Y" && isset($_POST['saveall']) && !isset($_SESSION['scid'])) ) //Value submitted when clicking on 'Save Now' button on SAVE FORM { if ($thissurvey['active'] == "Y") // Only save if active { $saveresult=savedcontrol(); if (isset($errormsg) && $errormsg != "") { showsaveform(); } echo $saveresult; } else { $_SESSION['scid'] = 0; // If not active set to a dummy value to save form does not continue to show. } } // DISPLAY SAVE FORM // Displays even if not active just to show how it would look when active (for testing purposes) // Show 'SAVE FORM' only when click the 'Save so far' button the first time if ($thissurvey['allowsave'] == "Y" && isset($_POST['saveall']) && !isset($_SESSION['scid'])) { //showsaveform(); } elseif ($thissurvey['allowsave'] == "Y" && isset($_POST['saveall']) && isset($_SESSION['scid']) ) //update the saved step only { $connect->Execute("update ".db_table_name("saved_control")." set saved_thisstep={$thisstep} where scid=".$_SESSION['scid']); // Checked } function showsaveform() { //Show 'SAVE FORM' only when click the 'Save so far' button the first time, or when duplicate is found on SAVE FORM. global $thistpl, $errormsg, $thissurvey, $surveyid, $clang, $clienttoken, $relativeurl, $thisstep; sendcacheheaders(); doHeader(); foreach(file("$thistpl/startpage.pstpl") as $op) { echo templatereplace($op); } echo "\n\n\n" ."\t\n\n"; echo "
"; foreach(file("$thistpl/endpage.pstpl") as $op) { echo templatereplace($op); } echo "