Skip to content

Commit

Permalink
Fixed issue: Print answers after survey completion not working
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Mar 15, 2012
1 parent 8687ee0 commit 70e7920
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 66 deletions.
Expand Up @@ -21,17 +21,9 @@
* @version $Id$
* @access public
*/
class printanswers extends LSYii_Controller {

/**
* printanswers::__construct()
* Constructor
* @return
*/
function __construct()
{
parent::__construct();
}
class PrintanswersController extends LSYii_Controller {



/**
* printanswers::view()
Expand All @@ -40,34 +32,31 @@ function __construct()
* @param bool $printableexport
* @return
*/
function view($surveyid,$printableexport=FALSE)
function actionView($surveyid,$printableexport=FALSE)
{

global $siteadminname, $siteadminemail;
Yii::app()->loadHelper("frontend");

if(Yii::app()->getConfig('usepdfexport'))
{
Yii::import('application.libraries.admin.pdf');
}

//if (!isset($surveyid)) {$surveyid=returnGlobal('sid');}
//else {
//This next line ensures that the $surveyid value is never anything but a number.
$surveyid = (int)($surveyid);
//}
Yii::app()->loadHelper('database');

if (isset(Yii::app()->session[$surveyid]['sid']))
if (isset($_SESSION['survey_'.$surveyid]['sid']))
{
$surveyid = Yii::app()->session[$surveyid]['sid'];
$surveyid = $_SESSION['survey_'.$surveyid]['sid'];
}
else
{
show_error('Invalid survey/session');
die('Invalid survey/session');
}

//Debut session time out
if (!isset(Yii::app()->session[$surveyid]['finished']) || !isset(Yii::app()->session[$surveyid]['srid']))
if (!isset($_SESSION['survey_'.$surveyid]['finished']) || !isset($_SESSION['survey_'.$surveyid]['srid']))
// Argh ... a session time out! RUN!
//display "sorry but your session has expired"
{
Expand All @@ -93,19 +82,19 @@ function view($surveyid,$printableexport=FALSE)
}
//Fin session time out

$id = Yii::app()->session[$surveyid]['srid']; //I want to see the answers with this id
$clang = Yii::app()->session[$surveyid]['s_lang'];
$id = $_SESSION['survey_'.$surveyid]['srid']; //I want to see the answers with this id
$clang = $_SESSION['survey_'.$surveyid]['s_lang'];

//Ensure script is not run directly, avoid path disclosure
//if (!isset($rootdir) || isset($_REQUEST['$rootdir'])) {die( "browse - Cannot run this script directly");}

// Set the language for dispay
//require_once($rootdir.'/classes/core/language.php'); // has been secured
if (isset(Yii::app()->session[$surveyid]['s_lang']))
if (isset($_SESSION['survey_'.$surveyid]['s_lang']))
{

$clang = SetSurveyLanguage( $surveyid, Yii::app()->session[$surveyid]['s_lang']);
$language = Yii::app()->session[$surveyid]['s_lang'];
$clang = SetSurveyLanguage( $surveyid, $_SESSION['survey_'.$surveyid]['s_lang']);
$language = $_SESSION['survey_'.$surveyid]['s_lang'];
}
else
{
Expand All @@ -132,21 +121,10 @@ function view($surveyid,$printableexport=FALSE)
}

//CHECK IF SURVEY IS ACTIVATED AND EXISTS
$actquery = new CDbCriteria;
$actquery->join = 'INNER JOIN {{surveys_languagesettings}} as b on (b.surveyls_surveyid = t.sid and b.surveyls_language = t.language)';
$actquery->condition = 't.sid = :sid';
$actquery->params(array(':sid' => $surveyid));
$actresult = Surveys::model()->findAll($actquery);
$actcount = count($actresult);
if ($actcount > 0)
{
foreach ($actresult as $actrow)
{
$surveytable = "{{survey_{$actrow->sid}}}";
$surveyname = "{$actrow->surveyls_title}";
$anonymized = $actrow->anonymized;
}
}

$surveytable = "{{survey_{$surveyid}}}";
$surveyname = $thissurvey['surveyls_title'];
$anonymized = $thissurvey['anonymized'];


//OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK.
Expand Down
3 changes: 2 additions & 1 deletion application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -449,8 +449,9 @@ function run($surveyid,$args) {
// Link to Print Answer Preview **********
if ($thissurvey['printanswers'] == 'Y')
{
$url = Yii::app()->getController()->createUrl("printanswers/view/?surveyid={$surveyid}");
$completed .= "<br /><br />"
. "<a class='printlink' href='printanswers.php?sid=$surveyid' target='_blank'>"
. "<a class='printlink' href='$url' target='_blank'>"
. $clang->gT("Print your answers.")
. "</a><br />\n";
}
Expand Down
37 changes: 18 additions & 19 deletions application/helpers/common_helper.php
Expand Up @@ -320,8 +320,6 @@ function getSurveyList($returnarray=false, $returnwithouturl=false, $surveyid=fa
else
$surveyidresult = Survey::model()->with('languagesettings')->findAll();

if (!$surveyidresult) {return array();}

$surveynames = array();
foreach ($surveyidresult as $result)
$surveynames[] = array_merge($result->attributes, $result->languagesettings->attributes);
Expand Down Expand Up @@ -1740,13 +1738,13 @@ function getSIDGIDQIDAIDType($fieldcode)
*/
function getExtendedAnswer($surveyid, $action, $fieldcode, $value, $format='')
{
$clang = Yii::app()->getController()->lang;
$clang = Yii::app()->lang;

// use Survey base language if s_lang isn't set in _SESSION (when browsing answers)
$s_lang = Survey::model()->findByPk($surveyid)->language;
if (!isset($action) || (isset($action) && $action!='browse') || $action == NULL )
{
if (Yii::app()->session[$surveyid]['s_lang']) $s_lang = Yii::app()->session[$surveyid]['s_lang']; //This one does not work in admin mode when you browse a particular answer
if ($_SESSION['survey_'.$surveyid]['s_lang']) $s_lang = $_SESSION['survey_'.$surveyid]['s_lang']; //This one does not work in admin mode when you browse a particular answer
}

//Fieldcode used to determine question, $value used to match against answer code
Expand Down Expand Up @@ -2234,29 +2232,30 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
}
if ($prow['datestamp'] == "Y")
{
$fieldmap["datestamp"]=array("fieldname"=>"datestamp",
'type'=>"datestamp",
$fieldmap["startdate"]=array("fieldname"=>"startdate",
'type'=>"startdate",
'sid'=>$surveyid,
"gid"=>"",
"qid"=>"",
"aid"=>"");
if ($style == "full")
{
$fieldmap["datestamp"]['title']="";
$fieldmap["datestamp"]['question']=$clang->gT("Date last action");
$fieldmap["datestamp"]['group_name']="";
$fieldmap["startdate"]['title']="";
$fieldmap["startdate"]['question']=$clang->gT("Date started");
$fieldmap["startdate"]['group_name']="";
}
$fieldmap["startdate"]=array("fieldname"=>"startdate",
'type'=>"startdate",

$fieldmap["datestamp"]=array("fieldname"=>"datestamp",
'type'=>"datestamp",
'sid'=>$surveyid,
"gid"=>"",
"qid"=>"",
"aid"=>"");
if ($style == "full")
{
$fieldmap["startdate"]['title']="";
$fieldmap["startdate"]['question']=$clang->gT("Date started");
$fieldmap["startdate"]['group_name']="";
$fieldmap["datestamp"]['title']="";
$fieldmap["datestamp"]['question']=$clang->gT("Date last action");
$fieldmap["datestamp"]['group_name']="";
}

}
Expand Down Expand Up @@ -5666,7 +5665,7 @@ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorC
{
$aFieldMap = createFieldMap($iSurveyID,'full',false,false,$sLanguageCode);
//Get response data
$idrow = Surveys_dynamic::model($iSurveyID)->findByAttributes(array('id'=>$iResponseID));
$idrow = Survey_dynamic::model($iSurveyID)->findByAttributes(array('id'=>$iResponseID));

// Create array of non-null values - those are the relevant ones
$aRelevantFields = array();
Expand Down Expand Up @@ -5713,15 +5712,15 @@ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorC
}
else
{
$answer = getExtendedAnswer($fname['fieldname'], $idrow[$fname['fieldname']]);
$answer = getExtendedAnswer($iSurveyID,null,$fname['fieldname'], $idrow[$fname['fieldname']]);
$aResultTable[$fname['fieldname']]=array($question,'',$answer);
continue;
}
}
}
else
{
$answer=getExtendedAnswer($fname['fieldname'], $idrow[$fname['fieldname']]);
$answer=getExtendedAnswer($iSurveyID,null,$fname['fieldname'], $idrow[$fname['fieldname']]);
$aResultTable[$fname['fieldname']]=array($question,'',$answer);
continue;
}
Expand All @@ -5734,7 +5733,7 @@ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorC
if (isset($fname['subquestion2']))
$subquestion .= "[{$fname['subquestion2']}]";

$answer = getExtendedAnswer($fname['fieldname'], $idrow[$fname['fieldname']]);
$answer = getExtendedAnswer($iSurveyID,null,$fname['fieldname'], $idrow[$fname['fieldname']]);
$aResultTable[$fname['fieldname']]=array('',$subquestion,$answer);
}
return $aResultTable;
Expand Down Expand Up @@ -7016,7 +7015,7 @@ function getHeader($meta = false)
{
$languagecode = Yii::app()->getConfig('defaultlang');
}

$js_header = ''; $css_header='';
if(Yii::app()->getConfig("js_admin_includes"))
{
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/surveytranslator_helper.php
Expand Up @@ -635,11 +635,11 @@ function getDateFormatForSID($surveyid, $languagecode='')
{
if (!isset($languagecode) || $languagecode=='')
{
$languagecode=Survey::model()->findByPk($surveyid)->language;;
$languagecode=Survey::model()->findByPk($surveyid)->language;
}
$data = Surveys_languagesettings::model()->getDateFormat($surveyid,$languagecode);

if(empty($dateformat))
if(empty($data))
{
$dateformat = 0;
}
Expand Down
6 changes: 2 additions & 4 deletions application/models/Survey.php
Expand Up @@ -62,10 +62,8 @@ public static function model($class = __CLASS__)
public function relations()
{
return array(
'languagesettings' => array(self::HAS_ONE, 'Surveys_languagesettings', '',
'on' => 't.sid = languagesettings.surveyls_survey_id AND t.language = languagesettings.surveyls_language'
),
'owner' => array(self::BELONGS_TO, 'User', '', 'on' => 't.owner_id = owner.uid'),
'languagesettings' => array(self::HAS_MANY, 'Surveys_languagesettings', 'surveyls_survey_id'),
'owner' => array(self::BELONGS_TO, 'User', '', 'on' => 't.owner_id = owner.uid'),
);
}

Expand Down

0 comments on commit 70e7920

Please sign in to comment.