gT('Iterate survey')); $iteratesurveyoutput .= "
".$clang->gT("Iterate survey")."
\n"; $iteratesurveyoutput .= "
".$clang->gT("Important instructions")."
" . "
".$clang->gT("Click on the following button if you want to").":
\n" . "
    " . "
  1. ".$clang->gT("Delete all incomplete answers that correspond to a token for which a completed answers is already recorded")."
  2. " . "
  3. ".$clang->gT("Reset the completed answers to the incomplete state")."
  4. " . "
  5. ".$clang->gT("Reset all your tokens to the 'not used' state")."
  6. " . "

\n" . "gT("Are you really sure you want to *delete* some incomplete answers and reset the completed state of both answers and tokens?","js")."')){".get2post("$scriptname?action=iteratesurvey&sid=$surveyid&subaction=unfinalizeanswers")."}\" value='".$clang->gT("Reset answers and token completed state")."' />" . "
"; } if ($subaction=='unfinalizeanswers') { $iteratesurveyoutput = browsemenubar($clang->gT('Iterate survey')); $baselang = GetBaseLanguageFromSurveyID($surveyid); $surveytable = db_table_name("survey_$surveyid"); // First delete incomplete answers that correspond to a token for which a completed answers is already recorded // subquery in delete or update are tricky things when using the same table for delete and Select // see http://www.developpez.net/forums/d494961/bases-donnees/mysql/requetes/cant-specify-target-in-from-clause/ $updateqr = "DELETE from $surveytable WHERE submitdate IS NULL AND token in (SELECT * FROM ( SELECT answ2.token from $surveytable AS answ2 WHERE answ2.submitdate IS NOT NULL) tmp );\n"; // $updateqr = "DELETE from $surveytable WHERE submitdate IS NULL AND token in (SELECT b.token from $surveytable AS b WHERE b.submitdate IS NOT NULL);\n"; //error_log("TIBO query = $updateqr"); $updateres = $connect->Execute($updateqr) or safe_die("Delete incomplete answers with duplicate tokens failed:
\n" . $connect->ErrorMsg() . "
$updateqr"); // Then set all remaining answers to incomplete state $updateqr = "UPDATE $surveytable SET submitdate=NULL, lastpage=NULL;\n"; $updateres = $connect->Execute($updateqr) or safe_die("UnFinilize answers failed:
\n" . $connect->ErrorMsg() . "
$updateqr"); // Finally, reset the token completed and sent status $updateqr="UPDATE ".db_table_name("tokens_$surveyid")." SET sent='N', remindersent='N', remindercount=0, completed='N', usesleft=1 where usesleft=0"; $updateres=$connect->Execute($updateqr) or safe_die ("Couldn't reset token completed state
$updateqr
".$connect->ErrorMsg()); $iteratesurveyoutput .= "
\n"; $iteratesurveyoutput .= "
".$clang->gT("Iterate survey")."
\n"; $iteratesurveyoutput .= "

\n" . "".$clang->gT("Success")."
\n" . $clang->gT("Answers and tokens have been re-opened.")."
\n" . "

\n"; }