Skip to content

Commit

Permalink
Merge pull request #239 from pradeshc/issue_9207
Browse files Browse the repository at this point in the history
Fixed issue #9207
  • Loading branch information
c-schmitz committed Nov 22, 2014
2 parents bea1842 + 9da046f commit d069091
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
108 changes: 98 additions & 10 deletions application/controllers/admin/responses.php
Expand Up @@ -15,7 +15,18 @@
/**
* Responses Controller
*
* This controller performs browse actions
* This controller performs browse actions.
*
* The browse() action is responsible for rendering the response view, which loads the JQGrid table.
* ...The grid in turns issues a JSON POST request to the getResponses_json() action.
* ...
* ...It is important that the order of fields generated by both actions match.
* ...For the browse() action, the $column_model is built up for each column in the table. The grid
* ...uses the column model to render column headings and search bar.
* ...The getResponses_json() action populated the $aSurveyEntry array with the values that must be
* ...populated for each row and column of the table.
*
*
*
* @package LimeSurvey
* @subpackage Backend
Expand Down Expand Up @@ -324,7 +335,7 @@ function browse($iSurveyID)
// The column model must be built dynamically, since the columns will differ from survey to survey, depending on the questions.
$column_model = array();
// The first few colums are fixed.
$column_model[] = array('name' => 'actions', 'model_name' => 'Actions', 'index' => 'actions', 'sorttype' => 'string', 'sortable' => false, 'width' => '100', 'align' => 'left', 'editable' => false);
$column_model[] = array('name' => 'actions', 'model_name' => 'Actions', 'index' => 'actions', 'sorttype' => 'string', 'sortable' => false, 'width' => '100', 'align' => 'left', 'editable' => false, 'search' => false);

// All other columns are based on the questions.

Expand Down Expand Up @@ -353,6 +364,13 @@ function browse($iSurveyID)
if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate')
continue;

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Issue_9207 - Excluded token to prevent it from being included twice in the table.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
if ($fielddetails['fieldname'] == 'token')
continue;


// no headers for time data
if ($fielddetails['type'] == 'interview_time')
continue;
Expand Down Expand Up @@ -413,9 +431,6 @@ function browse($iSurveyID)

}

// print_r($column_model);


$column_model_txt = ls_json_encode($column_model);
$column_names = array();
foreach ($column_model as $column) {
Expand Down Expand Up @@ -517,7 +532,53 @@ public function getResponses_json($iSurveyID)


// Get the survey responses
$dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray();

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// issue_9207 - added join of survey table with token table.
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////

$oCriteria = new CDbCriteria;
//Create the query
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyID}}}") && Permission::model()->hasSurveyPermission($iSurveyID,'tokens','read'))
{
$oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
}

if (incompleteAnsFilterState() == "incomplete")
{
$oCriteria->addCondition("submitdate IS NULL");
}
elseif (incompleteAnsFilterState() == "complete")
{
$oCriteria->addCondition("submitdate IS NOT NULL");
}

$dtcount = SurveyDynamic::model($iSurveyID)->count($oCriteria);// or die("Couldn't get response data<br />");

if ($limit > $dtcount)
{
$limit = $dtcount;
}

//NOW LETS SHOW THE DATA
if (Yii::app()->request->getPost('sql') && stripcslashes(Yii::app()->request->getPost('sql')) !== "" && Yii::app()->request->getPost('sql') != "NULL")
$oCriteria->addCondition(stripcslashes(Yii::app()->request->getPost('sql')));

if (!is_null($tokenRequest)) {
$oCriteria->addCondition('t.token = ' . Yii::app()->db->quoteValue($tokenRequest));
}

$oCriteria->order = 'id ' . ($order == 'desc' ? 'desc' : 'asc');
$oCriteria->offset = (Yii::app()->request->getPost('page', 1) - 1) * 50;
$oCriteria->limit = Yii::app()->request->getPost('rows', 50);


$dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria);

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Issue_9207 - end
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////


$aSurveyEntries = new stdClass();
$aSurveyEntries->page = 1;
Expand All @@ -538,20 +599,47 @@ public function getResponses_json($iSurveyID)
$action_html .= "<a><img id='deleteresponse_" . $row['id'] . "' src='" . $sImageURL . "/token_delete.png' alt='" . gT('Delete this response') . "' class='deleteresponse'/></a>";
}


$aSurveyEntry = array();

$aSurveyEntry[] = '<!--a-->' . $action_html;

// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// issue_9207 - added token fields for non-anon surveys.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// If the survey is not anonymized, then add the token, firstname, lastname and email fields to the table
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyID}}}") && Permission::model()->hasSurveyPermission($iSurveyID,'tokens','read'))
{
$aSurveyEntry[] = $row['token'];
$aSurveyEntry[] = $row['firstname'];
$aSurveyEntry[] = $row['lastname'];
$aSurveyEntry[] = $row['email'];
}
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// issue_9207 - added token fields for non-anon surveys.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////

// completed
$aSurveyEntry[] = empty($row['submitdate'])?'N':'Y';

// id
$aSurveyEntry[] = $row['id'];

// startlanguage
$aSurveyEntry[] = $row['startlanguage'];
$aSurveyEntry[] = $row[$fnames[2][0]];
$aSurveyEntry[] = $row[$fnames[3][0]];


// $aSurveyEntry[] = $row[$fnames[2][0]];
// $aSurveyEntry[] = $row[$fnames[3][0]];

foreach ($row as $row_index => $row_value) {

// Ignore these fields
if (in_array($row_index, array('id', 'submitdate', 'lastpage', 'startlanguage', 'startdate', 'datestamp'))) {
if (in_array($row_index, array( 'id', 'submitdate', 'lastpage', 'startlanguage', 'startdate',
'datestamp', 'token', 'email', 'firstname', 'lastname', 'tid',
'participant_id', 'emailstatus', 'blacklisted', 'language',
'remindersent', 'remindercount', 'usesleft', 'validfrom',
'validuntil', 'mpid', 'sent', 'completed'
))) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/admin/listresponse.js
Expand Up @@ -220,18 +220,18 @@ $(document)
/* Trigger the inline search when the access list changes */
$('#gs_completed_select').change(
function() {
$("#gs_Completed").val(
$("#gs_completed").val(
$('#gs_completed_select').val());

var e = jQuery.Event("keydown");
$("#gs_Completed").trigger(e);
$("#gs_completed").trigger(e);
});

/* Change the text search above "Status" icons to a dropdown */
var parentDiv = $('#gs_completed').parent();
parentDiv.prepend($('#gs_completed_select'));
$('#gs_completed_select').css("display", "");
$('#gs_Completed').css("display", "none");
$('#gs_completed').css("display", "none");

/* Disable search on the action column */
var parentDiv = $('#gs_actions').parent();
Expand Down

0 comments on commit d069091

Please sign in to comment.