gT("Browse Responses")); $browseoutput = ""; if (!$database_exists) //DATABASE DOESN'T EXIST OR CAN'T CONNECT { $browseoutput .= "\t
" . $clang->gT("Browse Responses")."
" .$clang->gT("Error")."\t
\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" ."
"; return; } if (!$surveyid && !$subaction) //NO SID OR ACTION PROVIDED { $browseoutput .= "\t" . $clang->gT("Browse Responses")."\n" ."\t\n" ."".$clang->gT("Error")."
\n" . $clang->gT("You have not selected a survey to browse.")."

\n" ."
\n" ."\n"; return; } $js_admin_includes[]='scripts/browse.js'; //CHECK IF SURVEY IS ACTIVATED AND EXISTS $actquery = "SELECT * FROM ".db_table_name('surveys')." as a inner join ".db_table_name('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=$surveyid"; $actresult = db_execute_assoc($actquery); $actcount = $actresult->RecordCount(); if ($actcount > 0) { while ($actrow = $actresult->FetchRow()) { $surveytable = db_table_name("survey_".$actrow['sid']); $tokentable = $dbprefix."tokens_".$actrow['sid']; /* * DO NEVER EVER PUT VARIABLES AND FUNCTIONS WHICH GIVE BACK DIFFERENT QUOTES * IN DOUBLE QUOTED(' and " and \" is used) JAVASCRIPT/HTML CODE!!! (except for: you know what you are doing) * * Used for deleting a record, fix quote bugs.. */ $surveytableNq = db_table_name_nq("survey_".$surveyid); $surveyname = "{$actrow['surveyls_title']}"; if ($actrow['active'] == "N") //SURVEY IS NOT ACTIVE YET { $browseoutput .= "\t" . $clang->gT("Browse Responses").": $surveyname\n" ."\t\n" ."".$clang->gT("Error")."
\n" . $clang->gT("This survey has not been activated. There are no results to browse.")."

\n" ."
\n" ."\n" ."\n"; return; } } } else //SURVEY MATCHING $surveyid DOESN'T EXIST { $browseoutput .= "\t" . $clang->gT("Browse Responses")."\n" ."\t\n" ."".$clang->gT("Error")."
\n" . $clang->gT("There is no matching survey.")." ($surveyid)

\n" ."
\n" ."\n" ."\n"; return; } //OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK. $qulanguage = GetBaseLanguageFromSurveyID($surveyid); if ($subaction == "id") // Looking at a SINGLE entry { $dateformatdetails=getDateFormatData($_SESSION['dateformat']); //SHOW HEADER if (!isset($_POST['sql']) || !$_POST['sql']) {$browseoutput .= $surveyoptions;} // Don't show options if coming from tokens script //FIRST LETS GET THE NAMES OF THE QUESTIONS AND MATCH THEM TO THE FIELD NAMES FOR THE DATABASE $fncount = 0; $fieldmap=createFieldMap($surveyid,'full',false,false,$language); $position=0; foreach ($fieldmap as $field) { $question=$field['question']; if (isset($field['subquestion']) && $field['subquestion']!='') { $question .=' ('.$field['subquestion'].')'; } if (isset($field['subquestion1']) && isset($field['subquestion2'])) { $question .=' ('.$field['subquestion1'].':'.$field['subquestion2'].')'; } if (isset($field['scale_id'])) { $question .='['.$field['scale'].']'; } $fnames[]=array($field['fieldname'],$question); if ($position==1) { $fnames[] = array("completed", $clang->gT("Completed"), "0"); if ($surveyinfo['private'] == "N" && db_tables_exist($tokentable)) //add token to top of list if survey is not private { $fnames[] = array("firstname", $clang->gT("First Name")); $fnames[] = array("lastname", $clang->gT("Last Name")); $fnames[] = array("email", $clang->gT("Email")); } } $position++; } $nfncount = count($fnames)-1; //SHOW INDIVIDUAL RECORD $idquery = "SELECT * FROM $surveytable "; if ($surveyinfo['private'] == "N" && db_tables_exist($tokentable)) $idquery .= "LEFT JOIN $tokentable ON $surveytable.token = $tokentable.token "; if (incompleteAnsFilterstate() == "inc") $idquery .= " WHERE (submitdate = ".$connect->DBDate('1980-01-01'). " OR submitdate IS NULL) AND "; elseif (incompleteAnsFilterstate() == "filter") $idquery .= " WHERE submitdate >= ".$connect->DBDate('1980-01-01'). " AND "; else $idquery .= " WHERE "; if ($id < 1) { $id = 1; } if (isset($_POST['sql']) && $_POST['sql']) { if (get_magic_quotes_gpc()) {$idquery .= stripslashes($_POST['sql']);} else {$idquery .= "{$_POST['sql']}";} } else {$idquery .= "$surveytable.id = $id";} $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get entry
\n$idquery
\n".$connect->ErrorMsg()); while ($idrow = $idresult->FetchRow()) { $id=$idrow['id']; $rlanguage=$idrow['startlanguage']; } $next=$id+1; $last=$id-1; $browseoutput .= "\n"; $browseoutput .= "\n"; $idresult = db_execute_assoc($idquery) or safe_die ("Couldn't get entry
$idquery
".$connect->ErrorMsg()); while ($idrow = $idresult->FetchRow()) { $i=0; $highlight=false; for ($i; $i<$nfncount+1; $i++) { $inserthighlight=''; if ($highlight) { $inserthighlight="class='highlight'"; } $browseoutput .= "\t\n" ."\n" ."\n\t\n"; $highlight=!$highlight; } } $browseoutput .= "
" .strip_tags(strip_javascript($fnames[$i][1])).""; if ($i == 2) { if ($idrow['submitdate'] == NULL || $idrow['submitdate'] == "N") { $browseoutput .= "N"; } else { $browseoutput .= "Y"; } } else { $browseoutput .= htmlspecialchars(strip_tags(strip_javascript(getextendedanswer($fnames[$i][0], $idrow[$fnames[$i][0]], '', $dateformatdetails['phpdate']))), ENT_QUOTES); } $browseoutput .= "
\n"; } elseif ($subaction == "all") { /** * fnames is used as informational array * it containts * $fnames[] = array(, , , , ); */ $browseoutput .= "\n\n"; if (!isset($_POST['sql'])) {$browseoutput .= $surveyoptions;} //don't show options when called from another script with a filter on else { $browseoutput .= "\t".$clang->gT("Browse Responses").": $surveyname\n" ."\n\n" ."\t\n" ."\n" ."\t\n" ."
\n" ."".$clang->gT("Showing Filtered Results")."
\n" ." [".$clang->gT("Close")."]" ."
\n"; } if (isset($_POST['deleteanswer']) && $_POST['deleteanswer']!='' && bHasRight($surveyid,'delete_survey')) { $iResponseID=(int) $_POST['deleteanswer']; // sanitize the value $query="delete FROM $surveytable where id={$iResponseID}"; $connect->execute($query) or safe_die("Could not delete response
$dtquery
".$connect->ErrorMsg()); // checked } if (isset($_POST['markedresponses']) && count($_POST['markedresponses'])>0 && bHasRight($surveyid,'delete_survey')) { foreach ($_POST['markedresponses'] as $iResponseID) { $iResponseID=(int)$iResponseID; // sanitize the value $query="delete FROM {$surveytable} where id={$iResponseID}"; $connect->execute($query) or safe_die("Could not delete response
{$dtquery}
".$connect->ErrorMsg()); // checked } } $fields=createFieldMap($surveyid, 'full', false, false, $language); //add token to top of list if survey is not private if ($surveyinfo['private'] == "N" && db_tables_exist($tokentable)) //add token to top of list if survey is not private { $fnames[] = array("token", "Token", $clang->gT("Token ID"), 0); $fnames[] = array("firstname", "First Name", $clang->gT("First Name"), 0); $fnames[] = array("lastname", "Last Name", $clang->gT("Last Name"), 0); $fnames[] = array("email", "Email", $clang->gT("Email"), 0); } $fnames[] = array("submitdate", $clang->gT("Completed"), $clang->gT("Completed"), "0", 'D'); foreach ($fields as $fielddetails) { if ($fielddetails['fieldname']=='lastpage' || $fielddetails['fieldname'] == 'submitdate' || $fielddetails['fieldname'] == 'token') continue; $question=$fielddetails['question']; if (isset($fielddetails['subquestion']) && $fielddetails['subquestion']!='') $question .=' ('.$fielddetails['subquestion'].')'; if (isset($fielddetails['subquestion1']) && isset($fielddetails['subquestion2'])) $question .=' ('.$fielddetails['subquestion1'].':'.$fielddetails['subquestion2'].')'; if (isset($fielddetails['scale_id'])) $question .='['.$fielddetails['scale'].']'; $fnames[]=array($fielddetails['fieldname'],$question); } $fncount = count($fnames); //NOW LETS CREATE A TABLE WITH THOSE HEADINGS $tableheader = ""; if ($fncount < 10) {$tableheader .= "\n";} else {$tableheader .= "
\n";} $tableheader .= "\t\n" . "\n" . "\n"; foreach ($fnames as $fn) { if (!isset($currentgroup)) {$currentgroup = $fn[1]; $gbc = "oddrow";} if ($currentgroup != $fn[1]) { $currentgroup = $fn[1]; if ($gbc == "oddrow") {$gbc = "evenrow";} else {$gbc = "oddrow";} } $tableheader .= "\n"; } $tableheader .= "\t\n\n"; if (bHasRight($surveyid,'delete_survey')) { $tableheader .= "\t\n\n"; } $start=returnglobal('start'); $limit=returnglobal('limit'); if (!isset($limit) || $limit== '') {$limit = 50;} if (!isset($start) || $start =='') {$start = 0;} //Create the query if ($surveyinfo['private'] == "N" && db_tables_exist($tokentable)) { $sql_from = "$surveytable LEFT JOIN $tokentable ON $surveytable.token = $tokentable.token"; } else { $sql_from = $surveytable; } $sql_where = ""; if (incompleteAnsFilterstate() == "inc") { $sql_where .= "submitdate IS NULL"; } elseif (incompleteAnsFilterstate() == "filter") { $sql_where .= "submitdate IS NOT NULL"; } if (isset($_POST['sql']) && stripcslashes($_POST['sql']) !== "" && $_POST['sql'] !== "NULL") { if (!empty($sql_where)) $sql_where .= " AND "; $sql_where .= stripcslashes($_POST['sql']); } if (!empty($sql_where)) $sql_where = " WHERE " . $sql_where; //LETS COUNT THE DATA $dtquery = "SELECT count(*) FROM $sql_from $sql_where"; $dtresult=db_execute_num($dtquery) or safe_die("Couldn't get response data
$dtquery
".$connect->ErrorMsg()); while ($dtrow=$dtresult->FetchRow()) {$dtcount=$dtrow[0];} if ($limit > $dtcount) {$limit=$dtcount;} //NOW LETS SHOW THE DATA $dtquery = "SELECT * FROM $sql_from $sql_where ORDER BY id"; if ($order == "desc") {$dtquery .= " DESC";} if (isset($limit)) { if (!isset($start)) {$start = 0;} $dtresult = db_select_limit_assoc($dtquery, $limit, $start) or safe_die("Couldn't get surveys
$dtquery
".$connect->ErrorMsg()); } else { $dtresult = db_execute_assoc($dtquery) or safe_die("Couldn't get surveys
$dtquery
".$connect->ErrorMsg()); } $dtcount2 = $dtresult->RecordCount(); $cells = $fncount+1; //CONTROL MENUBAR $last=$start-$limit; $next=$start+$limit; $end=$dtcount-$limit; if ($end < 0) {$end=0;} if ($last <0) {$last=0;} if ($next >= $dtcount) {$next=$dtcount-$limit;} if ($end < 0) {$end=0;} $browseoutput .= "\n"; $browseoutput .= $tableheader; $dateformatdetails=getDateFormatData($_SESSION['dateformat']); while ($dtrow = $dtresult->FetchRow()) { if (!isset($bgcc)) {$bgcc="evenrow";} else { if ($bgcc == "evenrow") {$bgcc = "oddrow";} else {$bgcc = "evenrow";} } $browseoutput .= "\t\n" ."\n" .""; $i = 0; //If not private, display the token info and link to the token screen if ($surveyinfo['private'] == "N" && $dtrow['token'] && db_tables_exist($tokentable)) { if (isset($dtrow['tid']) && !empty($dtrow['tid'])) { //If we have a token, create a link to edit it $browsedatafield = ""; $browsedatafield .= "{$dtrow['token']}"; $browsedatafield .= ""; } else { //No corresponding token in the token tabel, just display the token $browsedatafield .= "{$dtrow['token']}"; } $browseoutput .= "\n"; $i++; //We skip the first record (=token) as we just outputted that one } for ($i; $i<$fncount; $i++) { $browsedatafield=htmlspecialchars($dtrow[$fnames[$i][0]]); if ( isset($fnames[$i][4]) && $fnames[$i][4] == 'D' && $fnames[$i][0] != '') { if ($dtrow[$fnames[$i][0]] == NULL) $browsedatafield = "N"; else $browsedatafield = "Y"; } $browseoutput .= "\n"; } $browseoutput .= "\t\n"; } $browseoutput .= "
".$clang->gT('Actions')."" . strip_javascript("$fn[1]") . "
" ."".$clang->gT(" ."\t
".$clang->gT( ".$clang->gT("; if (bHasRight($surveyid,'delete_survey') && isset($rlanguage)) { $browseoutput .= "".$clang->gT(\n"; } $browseoutput .= "$browsedatafield$browsedatafield
\n
\n"; } else { $browseoutput .= $surveyoptions; $num_total_answers=0; $num_completed_answers=0; $gnquery = "SELECT count(id) FROM $surveytable"; $gnquery2 = "SELECT count(id) FROM $surveytable WHERE submitdate IS NOT NULL"; $gnresult = db_execute_num($gnquery); $gnresult2 = db_execute_num($gnquery2); while ($gnrow=$gnresult->FetchRow()) {$num_total_answers=$gnrow[0];} while ($gnrow2=$gnresult2->FetchRow()) {$num_completed_answers=$gnrow2[0];} $browseoutput .= "
".$clang->gT("Response summary")."
" ."

\n" ."" ."\t" ."" ."" ."
".$clang->gT("Total responses:")."".$num_total_answers."
".$clang->gT("Full responses:")."".$num_completed_answers."
".$clang->gT("Incomplete responses:")."".($num_total_answers-$num_completed_answers)."
"; }