Welcome, Guest
Username: Password: Remember me

TOPIC: print responses in pdf like the html filling survey

print responses in pdf like the html filling survey 2 years 9 months ago #63516

  • dsp77
  • dsp77's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Hello,

I have a nice design for the surveys, now all surveys are completed and i want to printout the responses in the front design template how can i achieve this?

i saw if the survey is not completed i can access it from admin tokens actions. It would be great if i can access the survey after completion. I tried to make a completed survey not completed but all the responses are gone. any advise please?
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 9 months ago #63519

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 933
  • Thank you received: 193
  • Karma: 62
Browse the answers by individual responses and you'll see that you can switch completed/not completed

completed.gif
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 2 years 9 months ago by Ben_V.
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 9 months ago #63548

  • dsp77
  • dsp77's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
still cannot view the data even if i mark it not completed, i think it doesn't take the info from the db
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 9 months ago #63550

  • mdekker
  • mdekker's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 340
  • Thank you received: 68
  • Karma: 38
There is no feature to see a completed survey in the browser layout. I know a lot of people would love to have that but at the moment it is impossible.

When using tokens and token based answer persistence you could set a response to not completed and view the answers but when there are no tokens i think it is impossible.
---
Menno Dekker
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 4 months ago #70751

  • dataguru
  • dataguru's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Karma: 0
Hmmm, so can I jerry rig it to let me print the survey screens of a completed survey by
changing completed from Y to N in the survey table
and then
using that survey's URL for that token to get back into that survey

/index.php?lang=en&sid=49636&token=ThatSurveysTokenValue
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 4 months ago #70765

  • snathan99
  • snathan99's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
I had the same question and here is what I did to get the PDF output.

(1) Take the "printanswers.php" file and make a copy (pa.php for example)
(2) Modify the new pa.php as below:
(3) Use code.google.com/p/wkhtmltopdf/ to convert to PDF

Code below:

<?php
/*
* MODIFIED - NON-WORKING CODE!!! NEED TO TWEAK TO WORK!!!
*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: NEW printanswers.php 10922 2011-09-02 14:02:28Z c_schmitz $
*
*/

$surveyid = $_GET["surveyid"];
$id = $_GET["id"];
$token = $_GET["token"];
if (is_null($surveyid))
{
echo "No Survey Id Passed in URL";
//header('Location: www.example.com/');
exit();
}

if ((is_null($id) && is_null($token)))
{
echo "Neither id nor token passed in URL";
//header('Location: www.example.com/');
exit();
}

//Security Checked: POST, GET, SESSION, REQUEST, returnglobal, DB
require_once(dirname(__FILE__).'/classes/core/startup.php');
require_once(dirname(__FILE__).'/config-defaults.php');
require_once(dirname(__FILE__).'/common.php');

$valquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE sid=$surveyid";
$dtresult=db_execute_num($valquery);
if ($dtresult->RecordCount()==0)
{
echo "Invalid Survey id";
exit();
}

$valquery = "SELECT id,submitdate FROM ".db_table_name('survey_'.$surveyid)." WHERE ";
if (is_null($id))
$valquery .= "token='".db_quote($token)."'";
else
$valquery .= "id=$id";
$dtresult=db_execute_num($valquery);
if ($dtresult->RecordCount()==0)
{
echo "Survey Not Started or Invalid survey token / id";
exit();
}
$dtresult=db_execute_assoc($valquery);
$dtdata=$dtresult->FetchRow();
if (is_null($id))
{
$id = $dtdata;
}
if (is_null($dtdata))
{
echo "Survey Incomplete";
exit();
}

$language = GetBaseLanguageFromSurveyID($surveyid);
$clang = SetSurveyLanguage( $surveyid, $language);
// Get the survey inforamtion
$thissurvey = getSurveyInfo($surveyid,$language);

//SET THE TEMPLATE DIRECTORY
if (!isset($thissurvey) || !$thissurvey)
{
$thistpl=validate_templatedir("default");
}
else
{
$thistpl=validate_templatedir($thissurvey);
}

//if ($thissurvey=='N') die(); //Die quietly if print answers is not permitted

//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); //Checked
$actcount = $actresult->RecordCount();
if ($actcount > 0)
{
while ($actrow = $actresult->FetchRow())
{
$surveytable = db_table_name("survey_".$actrow);
$surveyname = "{$actrow}";
}
}

//OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK.
//SHOW HEADER

//***********************************************************************


$printoutput = '';

$aFullResponseTable=aGetFullResponseTable($surveyid,$id,$language);



//Get the fieldmap @TODO: do we need to filter out some fields?
unset ($aFullResponseTable);
//unset ($aFullResponseTable);
unset ($aFullResponseTable);
unset ($aFullResponseTable);
unset ($aFullResponseTable);
//unset ($aFullResponseTable);
unset ($aFullResponseTable);
//unset Feedback Answers
$gid = $assessments;
$grpid = "gid_" . $gid;
unset ($aFullResponseTable[$grpid]);

// Below this is the rest of the original printanswers.php code
// modified to suit your needs of output
// It should mostly work as is but I customized it for my output
// by creating a new css, etc.
// The format of print is as follows
// Start with this
$printoutput1 = '';
$printoutput1 .= "<div class='printouttitle'> Output Heading here - $surveyname ?</div><p> \n";
$printoutput .= "<table class='printouttable' >\n";
// This is for heading
$printoutput .= "<tr class='printanswersgroup'><td colspan='3'>Submission core details</td></tr>\n";
// Question and Answer
// $printoutput .= "<tr class='printanswersquestionhead'><td>Item</td><td>Question here</td><td>Answer here</td></tr>\n";


// Anywhere here is some more sample that is modified from the original on the actual output:

// I CUT AND PASTED THIS FROM A WORKING CODE, BUT DID NOT TEST IT AS I REMOVED SOME SECTIONS THAT WERE VERY SPECIFIC TO MY NEEDS
// PLEASE MODIFY AND TEST BEFORE USE - USE AT OWN RISK!
//
// ALSO NOTICE I TOOK OUT THE PDF PART COMPLETELY. WHY? BECAUSE I USE
// code.google.com/p/wkhtmltopdf/ to then take the output to PDF from HTML
// wkhtmltopdf works great!
// YOU can call this new URL directly from wkhtmltopdf - Or do a wrapper
//
foreach ($aFullResponseTable as $sFieldname=>$fname)
{
//The two lines below remove the answer codes from the answer (if any) - this is customized by me!
$ans=explode("[",$fname[2]);
$fname[2]=$ans[0];

if (substr($sFieldname,0,4)=='gid_')
{
$printoutput1 .= "</table>\n";
// This is page break between groups
$printoutput1 .= "<div style=\"page-break-before: always\"> </div>";
$printoutput1 .= "<table class='printouttable' >\n";
$printoutput1 .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
elseif (substr($sFieldname,0,4)=='qid_')
{
$printoutput1 .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n";
}
else
{
// This is customized to avoid repeating questions in dual scale
//$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
if($dfname0==$fname[0] && $dfname1==$fname[1])
{
$dfname0=' ';
$dfname1=$dfname0;
}
else
{
$dfname0=$fname[0];
$dfname1=$fname[1];
}
//$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td>{$fname[2]}</td></tr>";
$printoutput1 .= "\t<tr class='printanswersquestion'><td>{$dfname0} {$dfname1}</td><td>{$fname[2]}</td></tr>";
$dfname0=$fname[0];
$dfname1=$fname[1];
}
}

$printoutput1 .= "</table>\n";

//Display the page with user answers
sendcacheheaders();
doHeader();

echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/startpage.pstpl'));
echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/printanswers.pstpl'),array('ANSWERTABLE'=>$printoutput1));
echo templatereplace(file_get_contents(sGetTemplatePath($thistpl).'/endpage.pstpl'));
echo "</body></html>";


?>
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 2 years 4 months ago #70778

  • dataguru
  • dataguru's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 36
  • Karma: 0
Cool. Thanks!
I'll let you know how it goes.
The administrator has disabled public write access.

Re: print responses in pdf like the html filling survey 1 year 5 months ago #87683

  • zunch2000
  • zunch2000's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 7
  • Karma: 0
Hi,

Can you further help me in implementing your solution to the PDF problem?
I did as you mentioned.
I don't know how to call the wkhtmltopdf?

Best regards
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.149 seconds
Donation Image