ErrorMsg()); $actsurrows = $actsurresult->FetchRow(); if($_SESSION['USER_RIGHT_SUPERADMIN'] == 1 || $actsurrows['browse_response']) { $surveyoptions = browsemenubar(); if (!$database_exists) { //$dataentryoutput .= "\n"; $dataentryoutput .= "\n" ."\t\n" ."\t
" .$clang->gT("Data Entry")."
\n" ."".$clang->gT("Error")."
\n" .$clang->gT("The defined LimeSurvey database does not exist")."
\n" .$clang->gT("Either your selected database has not yet been created or there is a problem accessing it.")."

\n" ."
\n" ."
\n" ."\n"; return; } if (!$surveyid && !$subaction) { //$dataentryoutput .= "\n"; $dataentryoutput .= "\n" ."\t\n" ."\t
" .$clang->gT("Data Entry")."
\n" ."".$clang->gT("Error")."
\n" .$clang->gT("You have not selected a survey for data-entry.")."

\n" ."
\n" ."
\n"; return; } if ($subaction == "edit" || $subaction == "" || $subaction == "editsaved" || $subaction == "insert") { $language = GetBaseLanguageFromSurveyID($surveyid); } if ($subaction == "insert") { $thissurvey=getSurveyInfo($surveyid); $errormsg=""; $dataentryoutput .= "\n" ."\t\n" ."\t\n" ."
" .$clang->gT("Data Entry")."
\n"; $lastanswfortoken=''; // check if a previous answer has been submitted or saved $rlanguage=''; if (isset($_POST['token']) && $_POST['token']) { $tokencompleted = ""; $tokentable = db_table_name("tokens_".$surveyid); $tcquery = "SELECT completed from $tokentable WHERE token='".$_POST['token']."'"; $tcresult = db_execute_assoc($tcquery); $tccount = $tcresult->RecordCount(); while ($tcrow = $tcresult->FetchRow()) { $tokencompleted = $tcrow['completed']; } if ($tccount < 1) { // token doesn't exist in token table $lastanswfortoken='UnknownToken'; } elseif ($thissurvey['private'] == "Y") { // token exist but survey is anonymous, check completed state if ($tokencompleted != "" && $tokencompleted != "N") { // token is not completed $lastanswfortoken='PrivacyProtected'; } } else { // token is valid, survey not anonymous, try to get last recorded response id $aquery = "SELECT id,startlanguage FROM $surveytable WHERE token='".$_POST['token']."'"; $aresult = db_execute_assoc($aquery); while ($arow = $aresult->FetchRow()) { $lastanswfortoken=$arow['id']; $rlanguage=$arow['startlanguage']; } } } if (bHasSurveyGotTokentable($thissurvey) && (!isset($_POST['token']) || !$_POST['token'])) {// First Check if the survey uses tokens and if a token has been provided $errormsg="".$clang->gT("Error").": ".$clang->gT("This is a closed-access survey, so you must supply a valid token. Please contact the administrator for assistance.")."\n"; } elseif (bHasSurveyGotTokentable($thissurvey) && $lastanswfortoken == 'UnknownToken') { $errormsg="".$clang->gT("Error").": ".$clang->gT("The token you have provided is not valid or has already been used.")."\n"; } elseif (bHasSurveyGotTokentable($thissurvey) && $lastanswfortoken != '') { $errormsg="".$clang->gT("Error").": ".$clang->gT("There is already a recorded answer for this token")."\n"; if ($lastanswfortoken != 'PrivacyProtected') { $errormsg .= "

".$clang->gT("Follow the following link to update it").":\n" . "gT("Edit this entry", "js")."')\">[id:$lastanswfortoken]"; } else { $errormsg .= "

".$clang->gT("This surveys uses anonymous answers, so you can't update your response.")."\n"; } } else { if (isset($_POST['save']) && $_POST['save'] == "on") { $saver['identifier']=returnglobal('save_identifier'); $saver['language']=returnglobal('save_language'); $saver['password']=returnglobal('save_password'); $saver['passwordconfirm']=returnglobal('save_confirmpassword'); $saver['email']=returnglobal('save_email'); if (!returnglobal('redo')) { $password=md5($saver['password']); } else { $password=$saver['password']; } $errormsg=""; if (!$saver['identifier']) {$errormsg .= $clang->gT("Error").": ".$clang->gT("You must supply a name for this saved session.");} if (!$saver['password']) {$errormsg .= $clang->gT("Error").": ".$clang->gT("You must supply a password for this saved session.");} if ($saver['password'] != $saver['passwordconfirm']) {$errormsg .= $clang->gT("Error").": ".$clang->gT("Your passwords do not match.");} if ($errormsg) { $dataentryoutput .= $errormsg; $dataentryoutput .= $clang->gT("Try again").":
"; if (isset($_POST['datestamp'])) { $dataentryoutput .= "\n"; } if (isset($_POST['ipaddr'])) { $dataentryoutput .= "\n"; } $dataentryoutput .= "
".$clang->gT("Identifier:")."
".$clang->gT("Password:")."
".$clang->gT("Confirm Password:")."
".$clang->gT("Email:")."
".$clang->gT("Start Language:")." \n"; foreach ($_POST as $key=>$val) { if (substr($key, 0, 4) != "save" && $key != "action" && $key != "surveytable" && $key !="sid" && $key != "datestamp" && $key !="ipaddr") { $dataentryoutput .= "\n"; } } $dataentryoutput .= "
\n"; } elseif (returnglobal('redo')=="yes") { //Delete all the existing entries TODO WTF IS REDO? //$delete="DELETE FROM ".db_table_name("saved")." WHERE scid=".$saver['scid']; //$result=$connect->Execute($delete) or safe_die("Couldn't delete old record
$delete
".htmlspecialchars($connect->ErrorMsg())); //$delete="DELETE FROM ".db_table_name("saved_control")." WHERE scid=".$surveytable['scid']; //$result=$connect->Execute($delete) or safe_die("Couldn't delete old record
$delete
".htmlspecialchars($connect->ErrorMsg())); } } //BUILD THE SQL TO INSERT RESPONSES $baselang = GetBaseLanguageFromSurveyID($surveyid); $iquery = "SELECT * FROM ".db_table_name("questions").", ".db_table_name("groups")." WHERE ".db_table_name("questions").".gid=".db_table_name("groups").".gid AND ".db_table_name("questions").".language = '{$baselang}' AND ".db_table_name("groups").".language = '{$baselang}' AND ".db_table_name("questions").".sid=$surveyid ORDER BY ".db_table_name("groups").".group_order, title"; $iresult = db_execute_assoc($iquery); $col_name=""; $insertqr=""; while ($irow = $iresult->FetchRow()) { if ($irow['type'] != "M" && $irow['type'] != "A" && $irow['type'] != "B" && $irow['type'] != "C" && $irow['type'] != "E" && $irow['type'] != "F" && $irow['type'] != "H" && $irow['type'] != "P" && $irow['type'] != "O" && $irow['type'] != "R" && $irow['type'] != "Q" && $irow['type'] != "J" && $irow['type'] != "K" && $irow['type'] != "1" ) { $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}"; if (isset($_POST[$fieldname])) { $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST[$fieldname]) . "', \n"; } } elseif ($irow['type'] == "O") { $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}"; $fieldname2 = $fieldname . "comment"; $col_name .= db_quote_id($fieldname).", \n".db_quote_id($fieldname2).", \n"; $insertqr .= "'" . auto_escape($_POST[$fieldname]) . "', \n'" . auto_escape($_POST[$fieldname2]) . "', \n"; } elseif ($irow['type'] == "1") { $i2query = "SELECT ".db_table_name("answers").".*, ".db_table_name("questions").".other FROM ".db_table_name("answers").", ".db_table_name("questions")." WHERE ".db_table_name("answers").".qid=".db_table_name("questions").".qid AND ".db_table_name("questions").".qid={$irow['qid']} AND ".db_table_name("questions").".language = '{$language}' AND ".db_table_name("answers").".language = '{$language}' AND ".db_table_name("questions").".sid=$surveyid ORDER BY ".db_table_name("answers").".sortorder, ".db_table_name("answers").".answer"; $i2result = $connect->Execute($i2query); $i2count = $i2result->RecordCount(); while ($i2answ = $i2result->FetchRow()) { // first scale $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}{$i2answ['code']}#0"; $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST["$fieldname"]) . "', \n"; // second scale $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}{$i2answ['code']}#1"; $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST["$fieldname"]) . "', \n"; } } elseif ($irow['type'] == "R") { $i2query = "SELECT ".db_table_name("answers").".*, ".db_table_name("questions").".other FROM ".db_table_name("answers").", ".db_table_name("questions")." WHERE ".db_table_name("answers").".qid=".db_table_name("questions").".qid AND ".db_table_name("questions").".qid={$irow['qid']} AND ".db_table_name("questions").".language = '{$language}' AND ".db_table_name("answers").".language = '{$language}' AND ".db_table_name("questions").".sid=$surveyid ORDER BY ".db_table_name("answers").".sortorder, ".db_table_name("answers").".answer"; $i2result = $connect->Execute($i2query); $i2count = $i2result->RecordCount(); for ($i=1; $i<=$i2count; $i++) { $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}$i"; $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST["d$fieldname"]) . "', \n"; } } else { $i2query = "SELECT ".db_table_name("answers").".*, ".db_table_name("questions").".other FROM ".db_table_name("answers").", ".db_table_name("questions")." WHERE ".db_table_name("answers").".qid=".db_table_name("questions").".qid AND ".db_table_name("questions").".language = '{$language}' AND ".db_table_name("answers").".language = '{$language}' AND ".db_table_name("questions").".qid={$irow['qid']} AND ".db_table_name("questions").".sid=$surveyid ORDER BY ".db_table_name("answers").".sortorder, ".db_table_name("answers").".answer"; $i2result = db_execute_assoc($i2query); while ($i2row = $i2result->FetchRow()) { $otherexists = ""; if ($i2row['other'] == "Y" and ($irow['type']=="!" or $irow['type']=="L" or $irow['type']=="M" or $irow['type']=="P" or $irow['type'] == "W" or $irow['type'] == "Z")) {$otherexists = "Y";} $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}{$i2row['code']}"; if (isset($_POST[$fieldname])) { $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST[$fieldname]) . "', \n"; if ($irow['type'] == "P") { $fieldname2 = $fieldname."comment"; $col_name .= db_quote_id($fieldname2).", \n"; $insertqr .= "'" . auto_escape($_POST[$fieldname2]) . "', \n"; } } } if (isset($otherexists) && $otherexists == "Y") { $fieldname = "{$irow['sid']}X{$irow['gid']}X{$irow['qid']}other"; $col_name .= db_quote_id($fieldname).", \n"; $insertqr .= "'" . auto_escape($_POST[$fieldname]) . "', \n"; } } } $col_name = substr($col_name, 0, -3); //Strip off the last comma-space $insertqr = substr($insertqr, 0, -3); //Strip off the last comma-space //NOW SHOW SCREEN if (bHasSurveyGotTokentable($thissurvey) && isset($_POST['token']) && $_POST['token'] && $thissurvey['private'] == 'N') //handle tokens if survey needs them { $col_name .= ", token\n"; $insertqr .= ", '{$_POST['token']}'"; } if (isset($_POST['datestamp']) && $_POST['datestamp']) //handle datestamp if needed { $col_name .= ", datestamp\n"; $insertqr .= ", '{$_POST['datestamp']}'"; } if (isset($_POST['ipaddr']) && $_POST['ipaddr']) //handle datestamp if needed { $col_name .= ", ipaddr\n"; $insertqr .= ", '{$_POST['ipaddr']}'"; } if (isset($_POST['language']) && $_POST['language']) // handle language { $col_name .= ", startlanguage\n"; $insertqr .= ", '{$_POST['language']}'"; } if (isset($_POST['closerecord'])) // handle Submidate if required { if ($thissurvey['private'] =="Y" && $thissurvey['datestamp'] =="N") { $col_name .= ", submitdate\n"; $insertqr .= ", '".date("Y-m-d H:i:s",mktime(0,0,0,1,1,1980))."'"; } elseif (isset($_POST['closedate']) && $_POST['closedate'] != '') { $col_name .= ", submitdate\n"; $insertqr .= ", '{$_POST['closedate']}'"; } } // $dataentryoutput .= "\t\t\tInserting data
\n" // ."SID: $surveyid, ($surveytable)

\n"; $SQL = "INSERT INTO $surveytable ($col_name) VALUES ($insertqr)"; //$dataentryoutput .= $SQL; //Debugging line $iinsert = $connect->Execute($SQL) or safe_die ("Could not insert your data:
$SQL
\n" .$connect->ErrorMsg()); /*if (returnglobal('redo')=="yes") { //This submission of data came from a saved session. Must delete the //saved session now that it has been recorded in the responses table $dquery = "DELETE FROM ".db_table_name("saved_control")." WHERE scid=".$saver['scid']; if ($dresult=$connect->Execute($dquery)) { $dquery = "DELETE FROM ".db_table_name("saved")." WHERE scid=".$saver['scid']; $dresult=$connect->Execute($dquery) or safe_die("Couldn't delete saved data
$dquery
".htmlspecialchars($connect->ErrorMsg())); } else { $dataentryoutput .= "Couldn't delete saved data
$dquery
".htmlspecialchars($connect->ErrorMsg()); } }*/ if (isset($_POST['closerecord']) && isset($_POST['token']) && $_POST['token'] != '') // submittoken { $today = date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust); $utquery = "UPDATE {$dbprefix}tokens_$surveyid\n"; if (bIsTokenCompletedDatestamped($thissurvey)) { $utquery .= "SET completed='$today'\n"; } else { $utquery .= "SET completed='Y'\n"; } $utquery .= "WHERE token='{$_POST['token']}'"; $utresult = $connect->Execute($utquery) or safe_die ("Couldn't update tokens table!
\n$utquery
\n".$connect->ErrorMsg()); } if (isset($_POST['save']) && $_POST['save'] == "on") { $srid = $connect->Insert_ID(); //CREATE ENTRY INTO "saved_control" $scdata = array("sid"=>$surveyid, "srid"=>$srid, "identifier"=>$saver['identifier'], "access_code"=>$password, "email"=>$saver['email'], "ip"=>$_SERVER['REMOTE_ADDR'], "refurl"=>getenv("HTTP_REFERER"), 'saved_thisstep' => 0, "status"=>"S", "saved_date"=>date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust)); if ($connect->AutoExecute("{$dbprefix}saved_control", $scdata,'INSERT')) { $scid = $connect->Insert_ID("{$dbprefix}saved_control","scid"); $dataentryoutput .= "".$clang->gT("Your survey responses have been saved successfully. You will be sent a confirmation e-mail. Please make sure to save your password, since we will not be able to retrieve it for you.")."
\n"; $tkquery = "SELECT * FROM ".db_table_name("tokens_$surveyid"); if ($tkresult = $connect->Execute($tkquery)) //If the query fails, assume no tokens table exists { $tokendata = array ( "firstname"=> $saver['identifier'], "lastname"=> $saver['identifier'], "email"=>$saver['email'], "token"=>randomkey(15), "language"=>$saver['language'], "sent"=>date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust), "completed"=>"N"); $connect->AutoExecute(db_table_name("tokens_".$surveyid), $tokendata,'INSERT'); $dataentryoutput .= "".$clang->gT("A token entry for the saved survey has been created too.")."
\n"; } if ($saver['email']) { //Send email if (validate_email($saver['email']) && !returnglobal('redo')) { $subject=$clang->gT("Saved Survey Details"); $message=$clang->gT("Thank you for saving your survey in progress. The following details can be used to return to this survey and continue where you left off. Please keep this e-mail for your reference - we cannot retrieve the password for you."); $message.="\n\n".$thissurvey['name']."\n\n"; $message.=$clang->gT("Name").": ".$saver['identifier']."\n"; $message.=$clang->gT("Password").": ".$saver['password']."\n\n"; $message.=$clang->gT("Reload your survey by clicking on the following link (or pasting it into your browser):").":\n"; $message.=$publicurl."/index.php?sid=$surveyid&loadall=reload&scid=".$scid."&lang=".urlencode($saver['language'])."&loadname=".urlencode($saver['identifier'])."&loadpass=".urlencode($saver['password']); if (isset($tokendata['token'])) {$message.="&token=".$tokendata['token'];} $from = $thissurvey['adminemail']; if (MailTextMessage($message, $subject, $saver['email'], $from, $sitename, false, getBounceEmail($surveyid))) { $emailsent="Y"; $dataentryoutput .= "".$clang->gT("An email has been sent with details about your saved survey")."
\n"; } } } } else { safe_die("Unable to insert record into saved_control table.

".$connect->ErrorMsg()); } } $dataentryoutput .= "\t\t\t".$clang->gT("Success")."
\n"; $thisid=$connect->Insert_ID(); $dataentryoutput .= "\t\t\t".$clang->gT("The entry was assigned the following record id: ")." {$thisid}
\n"; } $dataentryoutput .= $errormsg; $dataentryoutput .= "\t\t\t
[".$clang->gT("Add Another Record")."]
\n"; $dataentryoutput .= "[".$clang->gT("Return to Survey Administration")."
\n"; if (isset($thisid)) { $dataentryoutput .= "\t\t\t[".$clang->gT("View This Record")."]
\n"; } if (isset($_POST['save']) && $_POST['save'] == "on") { $dataentryoutput .= "\t\t\t[".$clang->gT("Browse Saved Responses")."]
\n"; } $dataentryoutput .= "\t\t\t[".$clang->gT("Browse Responses")."]
\n" ."\t
\n" ."\n"; } elseif ($subaction == "edit" || $subaction == "editsaved") { $dataentryoutput .= "\n" ."\t\n"; if (isset($surveyheader)) {$dataentryoutput .= $surveyheader;} $dataentryoutput .= $surveyoptions ."\n"; if (!isset($_GET['language'])) $_GET['language'] = GetBaseLanguageFromSurveyID($surveyid); //FIRST LETS GET THE NAMES OF THE QUESTIONS AND MATCH THEM TO THE FIELD NAMES FOR THE DATABASE $fnquery = "SELECT * FROM ".db_table_name("questions").", ".db_table_name("groups").", ".db_table_name("surveys")." WHERE ".db_table_name("questions").".gid=".db_table_name("groups").".gid AND ".db_table_name("questions").".language = '{$language}' AND ".db_table_name("groups").".language = '{$language}' AND ".db_table_name("questions").".sid=".db_table_name("surveys").".sid AND ".db_table_name("questions").".sid='$surveyid'"; $fnresult = db_execute_assoc($fnquery); $fncount = $fnresult->RecordCount(); //$dataentryoutput .= "$fnquery

\n"; $fnrows = array(); //Create an empty array in case FetchRow does not return any rows while ($fnrow = $fnresult->FetchRow()) { $fnrows[] = $fnrow; $private=$fnrow['private']; $datestamp=$fnrow['datestamp']; $ipaddr=$fnrow['ipaddr']; } // Get table output into array // Perform a case insensitive natural sort on group name then question title of a multidimensional array usort($fnrows, 'CompareGroupThenTitle'); // $fnames = (Field Name in Survey Table, Short Title of Question, Question Type, Field Name, Question Code, Predetermined Answers if exist) $fnames[] = array("id", "id", "id", "id", "id", "id", "id", ""); if ($private == "N") //show token info if survey not private { $fnames[] = array ("token", $clang->gT("Token ID"), $clang->gT("Token"), "token", "TID", "", ""); } if ($datestamp == "Y") { $fnames[] = array ("datestamp", $clang->gT("Date Stamp"), $clang->gT("Date Stamp"), "datestamp", "datestamp", "", ""); } if ($ipaddr == "Y") { $fnames[] = array ("ipaddr", $clang->gT("IP Address"), $clang->gT("IP Address"), "ipaddr", "ipaddr", "", ""); } $fcount=0; foreach ($fnrows as $fnrow) { $fcount++; $field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}"; $ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}"; $fquestion = $fnrow['question']; if ($fnrow['type'] == "M" || $fnrow['type'] == "A" || $fnrow['type'] == "B" || $fnrow['type'] == "C" || $fnrow['type'] == "E" || $fnrow['type'] == "F" || $fnrow['type'] == "H" || $fnrow['type'] == "P" || $fnrow['type'] == "Q" || $fnrow['type'] == "^" || $fnrow['type'] == "J" || $fnrow['type'] == "K") { $fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} and language='{$language}' ORDER BY sortorder, answer"; $fnrresult = db_execute_assoc($fnrquery); while ($fnrrow = $fnrresult->FetchRow()) { $fnames[] = array("$field{$fnrrow['code']}", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); if ($fnrow['type'] == "P") { $fnames[] = array("$field{$fnrrow['code']}"."comment", "$ftitle"."comment", "{$fnrow['question']}(comment)", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); } } if ($fnrow['other'] == "Y") { $fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(other)", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); if ($fnrow['type'] == "P") { $fnames[] = array("$field"."othercomment", "$ftitle"."othercomment", "{$fnrow['question']}(other comment)", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); } } } elseif ($fnrow['type'] == "R") { $fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} and language='{$language}' ORDER BY sortorder, answer"; $fnrresult = $connect->Execute($fnrquery); $fnrcount = $fnrresult->RecordCount(); for ($j=1; $j<=$fnrcount; $j++) { $fnames[] = array("$field$j", "$ftitle ($j)", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "$j", "{$fnrow['qid']}", "{$fnrow['lid']}"); } } elseif ($fnrow['type'] == "1") { $fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} and language='{$language}' ORDER BY sortorder, answer"; $fnrresult = $connect->Execute($fnrquery); while ($fnrrow = $fnrresult->FetchRow()) { $fnames[] = array("$field{$fnrrow['code']}#0", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']} (1)", "{$fnrow['qid']}", "{$fnrow['lid']}"); $fnames[] = array("$field{$fnrrow['code']}#1", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']} (2)", "{$fnrow['qid']}", "{$fnrow['lid1']}"); } } elseif ($fnrow['type'] == "O") { if (!isset($fnrrow)) {$fnrrow=array("code"=>"", "answer"=>"");} $fnames[] = array("$field", "$ftitle", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); $field2 = $field."comment"; $ftitle2 = $ftitle."[Comment]"; $longtitle = "{$fnrow['question']}
(Comment)"; $fnames[] = array("$field2", "$ftitle", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); } else { if (!isset($fnrrow)) {$fnrrow=array("code"=>"", "answer"=>"");} $fnames[] = array("$field", "$ftitle", "{$fnrow['question']}", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); if (($fnrow['type'] == "L" || $fnrow['type'] == "!" || $fnrow['type'] == "Z" || $fnrow['type'] == "W") && $fnrow['other'] =="Y") { $fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(other)", "{$fnrow['type']}", "$field", "{$fnrrow['code']}", "{$fnrrow['answer']}", "{$fnrow['qid']}", "{$fnrow['lid']}"); } } } $nfncount = count($fnames)-1; //SHOW INDIVIDUAL RECORD if ($subaction == "edit") { $idquery = "SELECT * FROM $surveytable WHERE id=$id"; $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get individual record
$idquery
".$connect->ErrorMsg()); while ($idrow = $idresult->FetchRow()) { $results[]=$idrow; } } elseif ($subaction == "editsaved") { if (isset($_GET['public']) && $_GET['public']=="true") { $password=md5($_GET['accesscode']); } else { $password=$_GET['accesscode']; } $svquery = "SELECT * FROM ".db_table_name("saved_control")." WHERE sid=$surveyid AND identifier='".$_GET['identifier']."' AND access_code='".$password."'"; $svresult=db_execute_assoc($svquery) or safe_die("Error getting save
$svquery
".$connect->ErrorMsg()); while($svrow=$svresult->FetchRow()) { $saver['email']=$svrow['email']; $saver['scid']=$svrow['scid']; $saver['ip']=$svrow['ip']; } $svquery = "SELECT * FROM ".db_table_name("saved_control")." WHERE scid=".$saver['scid']; $svresult=db_execute_assoc($svquery) or safe_die("Error getting saved info
$svquery
".$connect->ErrorMsg()); while($svrow=$svresult->FetchRow()) { $responses[$svrow['fieldname']]=$svrow['value']; } // while $fieldmap = createFieldMap($surveyid); foreach($fieldmap as $fm) { if (isset($responses[$fm['fieldname']])) { $results1[$fm['fieldname']]=$responses[$fm['fieldname']]; } else { $results1[$fm['fieldname']]=""; } } $results1['id']=""; $results1['datestamp']=date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", $timeadjust); $results1['ipaddr']=$saver['ip']; $results[]=$results1; } // $dataentryoutput .= "
";print_r($results);$dataentryoutput .= "
"; $dataentryoutput .= "
\n" ."\n" ."\t\n" ."\t\n" ."\t\n"; foreach ($results as $idrow) { //$dataentryoutput .= "
"; print_r($idrow);$dataentryoutput .= "
"; for ($i=0; $i<$nfncount+1; $i++) { //$dataentryoutput .= "
"; print_r($fnames[$i]);$dataentryoutput .= "
"; $answer = $idrow[$fnames[$i][0]]; $question=$fnames[$i][2]; $dataentryoutput .= "\t\n" ."\t\t\n" ."\t\t\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "
" .$clang->gT("Data Entry")."
" .$clang->gT("Editing Response")." (ID $id)
" ."\n"; $dataentryoutput .= "\t\t\t{$fnames[$i][2]}\n"; $dataentryoutput .= "\t\t\n"; //$dataentryoutput .= "\t\t\t-={$fnames[$i][3]}=-"; //Debugging info switch ($fnames[$i][3]) { case "X": //Boilerplate question $dataentryoutput .= ""; break; case "Q": case "K": $dataentryoutput .= "\t\t\t{$fnames[$i][6]} \n"; break; case "id": $dataentryoutput .= "\t\t\t {$idrow[$fnames[$i][0]]} ".$clang->gT("Cannot be modified")."\n"; break; case "5": //5 POINT CHOICE radio-buttons for ($x=1; $x<=5; $x++) { $dataentryoutput .= "\t\t\tgT("Please choose")."..\n" ."\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\n"; break; case "W": case "Z": if (substr($fnames[$i][0], -5) == "other") { $dataentryoutput .= "\t\t\t\n"; } else { $lquery = "SELECT * FROM ".db_table_name("labels") ." WHERE lid={$fnames[$i][8]} AND ".db_table_name("labels").".language = '{$language}' ORDER BY sortorder, code"; $lresult = db_execute_assoc($lquery); $dataentryoutput .= "\t\t\t\n"; } break; case "L": //LIST drop-down case "!": //List (Radio) if (substr($fnames[$i][0], -5) == "other") { $dataentryoutput .= "\t\t\t\n"; } else { $lquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnames[$i][7]} AND ".db_table_name("answers").".language = '{$language}' ORDER BY sortorder, answer"; $lresult = db_execute_assoc($lquery); $dataentryoutput .= "\t\t\t\n"; } break; case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea $lquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnames[$i][7]} AND ".db_table_name("answers").".language = '{$language}' ORDER BY sortorder, answer"; $lresult = db_execute_assoc($lquery); $dataentryoutput .= "\t\t\t\n"; break; case "R": //RANKING TYPE QUESTION $l=$i; $thisqid=$fnames[$l][7]; $myfname=substr($fnames[$i][0], 0, -1); while (isset($fnames[$i][3]) && $fnames[$i][3] == "R") { //Let's get all the existing values into an array if ($idrow[$fnames[$i][0]]) { $currentvalues[] = $idrow[$fnames[$i][0]]; } $i++; } $ansquery = "SELECT * FROM ".db_table_name("answers")." WHERE ".db_table_name("answers").".language = '{$language}' AND qid=$thisqid ORDER BY sortorder, answer"; $ansresult = db_execute_assoc($ansquery); $anscount = $ansresult->RecordCount(); $dataentryoutput .= "\t\t\t\n"; while ($ansrow = $ansresult->FetchRow()) //Now we're getting the codes and answers { $answers[] = array($ansrow['code'], $ansrow['answer']); } //now find out how many existing values there are $chosen[]=""; //create array if (!isset($ranklist)) {$ranklist="";} if (isset($currentvalues)) { $existing = count($currentvalues); } else {$existing=0;} for ($j=1; $j<=$anscount; $j++) //go through each ranking and check for matching answer { $k=$j-1; if (isset($currentvalues) && $currentvalues[$k]) { foreach ($answers as $ans) { if ($ans[0] == $currentvalues[$k]) { $thiscode=$ans[0]; $thistext=$ans[1]; } } } $ranklist .= "\t\t\t\t\t\t$j: \n" . "\t\t\t\t\t\t\n" . "\t\t\t\t\t\t".$clang->gT("Remove this item")."
\n\n"; } if (!isset($choicelist)) {$choicelist="";} $choicelist .= "\t\t\t\t\t\t\n"; $dataentryoutput .= "\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t
\n" ."\t\t\t\t\t\t" .$clang->gT("Your Choices").":
\n" .$choicelist ."\t\t\t\t\t
\n" ."\t\t\t\t\t\t" .$clang->gT("Your Ranking").":
\n" .$ranklist ."\t\t\t\t\t
\n" ."\t\t\t\n" ."\t\t\t\n"; $choicelist=""; $ranklist=""; unset($answers); $i--; break; case "M": //MULTIPLE OPTIONS checkbox $qidattributes=getQuestionAttributes($fnames[$i][7]); if ($displaycols=arraySearchByKey("display_columns", $qidattributes, "attribute", 1)) { $dcols=$displaycols['value']; } else { $dcols=0; } // while ($fnames[$i][3] == "M" && $question != "" && $question == $fnames[$i][2]) while ($fnames[$i][3] == "M" && $question == $fnames[$i][2]) { $fieldn = substr($fnames[$i][0], 0, strlen($fnames[$i][0])); //$dataentryoutput .= substr($fnames[$i][0], strlen($fnames[$i][0])-5, 5)."
\n"; if (substr($fnames[$i][0], -5) == "other") { $dataentryoutput .= "\t\t\t\n"; } else { $dataentryoutput .= "\t\t\tgT("Please choose")."..\n"; foreach ($slangs as $lang) { $dataentryoutput.="
\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "\t\n"; $dataentryoutput .= "\t
\n"; $dataentryoutput .= "\t\n"; } $dataentryoutput .= " "; } else { $action = "browse_response"; include("access_denied.php"); include("admin.php"); } function array_in_array($needle, $haystack) { foreach ($haystack as $value) { if ($needle == $value) return true; } return false; } ?>