// get submit date if (isset($_POST['closedate'])) { $submitdate = $_POST['closedate']; } else { $submitdate = date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust); } // check how many uses the token has left $usesquery = "SELECT usesleft FROM {$dbprefix}tokens_{$surveyid} WHERE token=" . db_quoteall($_POST['token'], true); $usesresult = db_execute_assoc($usesquery); $usesrow = $usesresult->FetchRow(); if (isset($usesrow)) { $usesleft = $usesrow['usesleft']; } // query for updating tokens $utquery = "UPDATE {$dbprefix}tokens_{$surveyid}\n"; if (bIsTokenCompletedDatestamped($thissurvey)) { if (isset($usesleft) && $usesleft <= 1) { $utquery .= "SET usesleft=usesleft-1, completed='{$submitdate}'\n"; } else { $utquery .= "SET usesleft=usesleft-1\n"; } } else { if (isset($usesleft) && $usesleft <= 1) { $utquery .= "SET usesleft=usesleft-1, completed='Y'\n"; } else { $utquery .= "SET usesleft=usesleft-1\n"; } } $utquery .= "WHERE token=" . db_quoteall($_POST['token'], true); $utresult = $connect->Execute($utquery) or safe_die("Couldn't update tokens table!<br />\n{$utquery}<br />\n" . $connect->ErrorMsg()); // save submitdate into survey table
/** * Marks a tokens as completed and sends a confirmation email to the participiant. * If $quotaexit is set to true then the user exited the survey due to a quota * restriction and the according token is only marked as 'Q' * * @param mixed $quotaexit */ function submittokens($quotaexit = false) { global $thissurvey, $timeadjust, $emailcharset; global $dbprefix, $surveyid, $connect; global $sitename, $thistpl, $clang, $clienttoken; // Shift the date due to global timeadjust setting $today = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust); $utquery = "UPDATE {$dbprefix}tokens_{$surveyid}\n"; if ($quotaexit == true) { $utquery .= "SET completed='Q'\n"; } elseif (bIsTokenCompletedDatestamped($thissurvey)) { $utquery .= "SET completed='{$today}'\n"; } else { $utquery .= "SET completed='Y'\n"; } $utquery .= "WHERE token='" . db_quote($clienttoken) . "'"; $utresult = $connect->Execute($utquery) or safe_die("Couldn't update tokens table!<br />\n{$utquery}<br />\n" . $connect->ErrorMsg()); //Checked if ($quotaexit == false) { // TLR change to put date into sent and completed $cnfquery = "SELECT * FROM " . db_table_name("tokens_{$surveyid}") . " WHERE token='" . db_quote($clienttoken) . "' AND completed!='N' AND completed!=''"; $cnfresult = db_execute_assoc($cnfquery); //Checked $cnfrow = $cnfresult->FetchRow(); if (isset($cnfrow)) { $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>"; $to = $cnfrow['email']; $subject = $thissurvey['email_confirm_subj']; $fieldsarray["{ADMINNAME}"] = $thissurvey['adminname']; $fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail']; $fieldsarray["{SURVEYNAME}"] = $thissurvey['name']; $fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description']; $fieldsarray["{FIRSTNAME}"] = $cnfrow['firstname']; $fieldsarray["{LASTNAME}"] = $cnfrow['lastname']; $fieldsarray["{TOKEN}"] = $clienttoken; $attrfieldnames = GetAttributeFieldnames($surveyid); foreach ($attrfieldnames as $attr_name) { $fieldsarray["{" . strtoupper($attr_name) . "}"] = $cnfrow[$attr_name]; } $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']); $fieldsarray["{EXPIRY}"] = convertDateTimeFormat($thissurvey["expiry"], 'Y-m-d H:i:s', $dateformatdatat['phpdate']); $subject = Replacefields($subject, $fieldsarray); if ($thissurvey['private'] == "N") { // Survey is not anonymous, we can translate insertAns placeholder $subject = insertansReplace($subject); } $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset); if (getEmailFormat($surveyid) == 'html') { $ishtml = true; } else { $ishtml = false; } if (trim(strip_tags($thissurvey['email_confirm'])) != "") { $message = $thissurvey['email_confirm']; $message = Replacefields($message, $fieldsarray); if ($thissurvey['private'] == "N") { // Survey is not anonymous, we can translate insertAns placeholder $message = insertansReplace($message); } if (!$ishtml) { $message = strip_tags(br2nl(html_entity_decode($message, ENT_QUOTES, $emailcharset))); } else { $message = html_entity_decode($message, ENT_QUOTES, $emailcharset); } //Only send confirmation email if there is a valid email address if (validate_email($cnfrow['email'])) { SendEmailMessage($message, $subject, $to, $from, $sitename, $ishtml); } } else { //There is nothing in the message, so don't send a confirmation email //This section only here as placeholder to indicate new feature :-) } } } }