Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/Yii' into Yii
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Mar 16, 2012
2 parents 7b8553a + b4e3af7 commit fa84c02
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 80 deletions.
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,13 @@ public function getSurveys_json()
//!!! Is this even possible to execute?
if (empty(Yii::app()->session['USER_RIGHT_SUPERADMIN']))
$surveys->permission(Yii::app()->user->getId());
$surveys = $surveys->with('languagesettings', 'owner')->findAll();
$surveys = $surveys->with(array('languagesettings'=>array('condition'=>'surveyls_language=language'), 'owner'))->findAll();
$aSurveyEntries = new stdClass();
$aSurveyEntries->page = 1;
foreach ($surveys as $rows)
{
$aSurveyEntry = array();
$rows = array_merge($rows->attributes, $rows->languagesettings->attributes, $rows->owner->attributes);
$rows = array_merge($rows->attributes, $rows->languagesettings[0]->attributes, $rows->owner->attributes);

// Set status
if ($rows['active'] == "Y" && $rows['expires'] != '' && $rows['expires'] < dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')))
Expand Down
12 changes: 6 additions & 6 deletions application/core/Survey_Common_Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ function _questiongroupbar($iSurveyId, $gid, $qid=null, $action = null)
. "<div class='menubar-title ui-widget-header'>\n";

//$sumquery1 = "SELECT * FROM ".db_table_name('surveys')." inner join ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=sid and surveyls_language=language) WHERE sid=$iSurveyId"; //Getting data for this survey
$sumresult1 = Survey::model()->with('languagesettings')->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked // if surveyid is invalid then die to prevent errors at a later time
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings->attributes);
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings[0]->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
//$surveyinfo = array_map('htmlspecialchars', $surveyinfo);
$aData['activated'] = $activated = $surveyinfo['active'];
Expand Down Expand Up @@ -487,13 +487,13 @@ function _surveybar($iSurveyId, $gid=null)
$condition = array('sid' => $iSurveyId, 'language' => $baselang);

//$sumquery1 = "SELECT * FROM ".db_table_name('surveys')." inner join ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=sid and surveyls_language=language) WHERE sid=$iSurveyId"; //Getting data for this survey
$sumresult1 = Survey::model()->with('languagesettings')->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked
if (is_null($sumresult1))
{
die('Invalid survey id');
} // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings->attributes);
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings[0]->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
//$surveyinfo = array_map('htmlspecialchars', $surveyinfo);
$activated = ($surveyinfo['active'] == 'Y');
Expand Down Expand Up @@ -629,13 +629,13 @@ function _surveysummary($iSurveyId, $action=null, $gid=null)
$baselang = Survey::model()->findByPk($iSurveyId)->language;
$condition = array('sid' => $iSurveyId, 'language' => $baselang);

$sumresult1 = Survey::model()->with('languagesettings')->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findByPk($iSurveyId); //$sumquery1, 1) ; //Checked
if (is_null($sumresult1))
{
die('Invalid survey id');
} // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings->attributes);
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings[0]->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
//$surveyinfo = array_map('htmlspecialchars', $surveyinfo);
$activated = $surveyinfo['active'];
Expand Down
3 changes: 2 additions & 1 deletion application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
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
58 changes: 35 additions & 23 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,23 @@ function isStandardTemplate($sTemplateName)
*/
function getSurveyList($returnarray=false, $returnwithouturl=false, $surveyid=false)
{
static $cached = null;
$cached = null;

$timeadjust = getGlobalSetting('timeadjust');
$clang = new Limesurvey_lang(Yii::app()->session['adminlang']);

if(is_null($cached)) {
if (!hasGlobalPermission('USER_RIGHT_SUPERADMIN'))
$surveyidresult = Survey::model()->permission(Yii::app()->user->getId())->with('languagesettings')->findAll();
$surveyidresult = Survey::model()->permission(Yii::app()->user->getId())->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findAll();
else
$surveyidresult = Survey::model()->with('languagesettings')->findAll();

if (!$surveyidresult) {return array();}
$surveyidresult = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findAll();

$surveynames = array();
foreach ($surveyidresult as $result)
$surveynames[] = array_merge($result->attributes, $result->languagesettings->attributes);
{
$surveynames[] = array_merge($result->attributes, $result->languagesettings[0]->attributes);

}

$cached = $surveynames;
} else {
Expand Down Expand Up @@ -1740,13 +1741,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 @@ -1868,6 +1869,16 @@ function getExtendedAnswer($surveyid, $action, $fieldcode, $value, $format='')
;
} // switch
}
switch($fieldcode)
{
case 'submitdate':
if (trim($value)!='')
{
$dateformatdetails = getDateFormatDataForQID(array('date_format'=>''), $surveyid);
$value=convertDateTimeFormat($value,"Y-m-d H:i:s",$dateformatdetails['phpdate'].' H:i:s');
}
break;
}
if (isset($this_answer))
{
if ($format != 'INSERTANS')
Expand Down Expand Up @@ -2234,29 +2245,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 +5678,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 +5725,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 +5746,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 +7028,7 @@ function getHeader($meta = false)
{
$languagecode = Yii::app()->getConfig('defaultlang');
}

$js_header = ''; $css_header='';
if(Yii::app()->getConfig("js_admin_includes"))
{
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/surveytranslator_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,17 +635,17 @@ 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;
}
else
{
$dateformat = $data->read();
$dateformat = (int) $data;
}
return (int) $dateformat;
}
Expand Down
6 changes: 2 additions & 4 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion application/models/Surveys_languagesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function getDateFormat($surveyid,$languagecode)
->where('surveyls_language = :langcode')
->bindParam(":langcode", $languagecode, PDO::PARAM_STR)
->bindParam(":surveyid", $surveyid, PDO::PARAM_INT)
->query();
->queryScalar();
}

function getAllSurveys($hasPermission = FALSE)
Expand Down

0 comments on commit fa84c02

Please sign in to comment.