Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to response/browse() to render results using gqGrid. Old browse ... #69

Merged
merged 1 commit into from Mar 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
276 changes: 276 additions & 0 deletions application/controllers/admin/responses.php
Expand Up @@ -318,7 +318,283 @@ public function index($iSurveyID)
}



function browse($iSurveyID)
{

$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/i18n/grid.locale-en.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/js/jquery.jqGrid.min.js");
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jquery.coookie.js");
// PC. Added this new file.
$this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . "listresponse.js");

$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'jquery.multiselect.filter.css');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl') . "displayParticipants.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/ui.jqgrid.css");
$this->getController()->_css_admin_includes(Yii::app()->getConfig('generalscripts') . "jquery/jqGrid/css/jquery.ui.datepicker.css");

$aData = $this->_getData($iSurveyID);
extract($aData);
$aViewUrls = array();
$oBrowseLanguage = new Limesurvey_lang($aData['language']);


// 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);

// All other columns are based on the questions.

//add token to top of list if survey is not private
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) //add token to top of list if survey is not private
{
$column_model[] = array('name' => 'Token', 'index' => 'token', 'sorttype' => 'string', 'sortable' => false, 'width' => '100', 'align' => 'left', 'editable' => false);
$column_model[] = array('name' => 'First name', 'index' => 'firstname', 'sorttype' => 'string', 'sortable' => true, 'width' => '100', 'align' => 'left', 'editable' => false);
$column_model[] = array('name' => 'Last Name', 'index' => 'lastname', 'sorttype' => 'string', 'sortable' => true, 'width' => '100', 'align' => 'left', 'editable' => false);
$column_model[] = array('name' => 'Email', 'index' => 'email', 'sorttype' => 'string', 'sortable' => true, 'width' => '100', 'align' => 'left', 'editable' => false);
}

$column_model[] = array('name' => 'completed', 'model_name' => 'Completed', 'index' => 'completed', 'sorttype' => 'string', 'sortable' => true, 'width' => '100', 'align' => 'left', 'editable' => false);


// $fields = createFieldMap($iSurveyID, 'full', false, false, $aData['language']);
$fields = createFieldMap($iSurveyID, true, false, $aData['language']);


// foreach ($fields as $fielddetails)
foreach ($fields as $fielddetails)
{

// print_r($fielddetails);


// Note that in LS 2,00, $fielddetails is an array, in 2.1 it is an object

if ($fielddetails->fieldname == 'lastpage' || $fielddetails->fieldname == 'submitdate')
continue;

// no headers for time data
if ($fielddetails->type == 'interview_time')
continue;
if ($fielddetails->type == 'page_time')
continue;
if ($fielddetails->type == 'answer_time')
continue;


/*
$question = $fielddetails['question'];
if ($fielddetails['type'] != "|")
{
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'] . ']';
$column_model[] = array('name' => $question, 'index' => $fielddetails['fieldname'], 'sorttype' => 'string', 'sortable' => true, 'width' => '25', 'align' => 'left', 'editable' => false);
}
else
{
if ($fielddetails['aid'] !== 'filecount')
{
$qidattributes = getQuestionAttributeValues($fielddetails['qid']);

for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++)
{
if ($qidattributes['show_title'] == 1)
$fnames[] = array($fielddetails['fieldname'], "File " . ($i + 1) . " - " . $fielddetails['question'] . "(Title)", "type" => "|", "metadata" => "title", "index" => $i);

if ($qidattributes['show_comment'] == 1)
$fnames[] = array($fielddetails['fieldname'], "File " . ($i + 1) . " - " . $fielddetails['question'] . "(Comment)", "type" => "|", "metadata" => "comment", "index" => $i);

$fnames[] = array($fielddetails['fieldname'], "File " . ($i + 1) . " - " . $fielddetails['question'] . "(File name)", "type" => "|", "metadata" => "name", "index" => $i);
$fnames[] = array($fielddetails['fieldname'], "File " . ($i + 1) . " - " . $fielddetails['question'] . "(File size)", "type" => "|", "metadata" => "size", "index" => $i);
//$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(extension)", "type"=>"|", "metadata"=>"ext", "index"=>$i);
}
}
else
$fnames[] = array($fielddetails['fieldname'], "File count");
}
*/

// if ( ($fielddetails['fieldname'] == 'id') || ($fielddetails['fieldname'] == 'startlanguage') ) {
// Combine title and aid to provide a unique column header.
if ( empty($fielddetails->title) ) {
$fielddetails->title = $fielddetails->fieldname;
}
if ( !empty($fielddetails->aid) ) {
$fielddetails->title = $fielddetails->title . '_' . $fielddetails->aid;
}

$fnames[] = array($fielddetails->fieldname, $fielddetails->title);

$column_model[] = array('name' => $fielddetails->title, 'model_name' => strip_tags(FlattenText(substr($fielddetails->text, 0, 32), true)), 'index' => $fielddetails->title, 'sorttype' => 'string', 'sortable' => true, 'width' => '100', 'align' => 'left', 'editable' => false, 'title' => strip_tags(FlattenText($fielddetails->text)) );

}

// print_r($column_model);


$column_model_txt = ls_json_encode($column_model);

$column_names = array();
foreach ($column_model as $column) {
// $column_name = stripTagsFull($column['model_name']);
// $column_name = substr($column['model_name'], 0, 32);
// $column_names[] = FlattenText($column['model_name'],true) ;
$column_names[] = $column['model_name'];
}

$column_names_txt = ls_json_encode($column_names);


Yii::app()->loadHelper('surveytranslator');

$aData['issuperadmin'] = false;
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
$aData['issuperadmin'] = true;
}
$aData['surveyid'] = $iSurveyID;
$aData['column_model_txt'] = $column_model_txt;
$aData['column_names_txt'] = $column_names_txt;


$this->_renderWrappedTemplate('responses', 'listResponses_view', $aData);

}

/**
* Returns survey responses in json format for a given survey
*
* @access public
* @return void
*/
public function getResponses_json($iSurveyID)
{

$aData = $this->_getData($iSurveyID);

extract($aData);
$aViewUrls = array();
$oBrowseLanguage = new Limesurvey_lang($aData['language']);


$sImageURL = Yii::app()->getConfig('adminimageurl');


$fnames = array();
//add token to top of list if survey is not private
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) //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);
}

$fields = createFieldMap($iSurveyID, true, false, $aData['language']);

foreach ($fields as $q)
{
if ($q->fieldname == 'lastpage' ||
$q->fieldname == 'submitdate' ||
$q->fieldname == 'token')
continue;

$question = $q->text;
if (!is_a($q, 'QuestionModule') || !$q->fileUpload())
{
if (isset($q->sq) && $q->sq != '')
$question .=' (' . $q->sq . ')';
if (isset($q->sq1) && isset($q->sq2))
$question .=' (' . $q->sq1 . ':' . $q->sq2 . ')';
if (isset($q->scale))
$question .='[' . $q->scale . ']';
$fnames[] = array($q->fieldname, $question);
}
else
{
if ($q->aid !== 'filecount')
{
$qidattributes = $q->getAttributeValues();

for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++)
{
if ($qidattributes['show_title'] == 1)
$fnames[] = array($q->fieldname, "File " . ($i + 1) . " - " . $q->text . "(Title)", "title", $i);

if ($qidattributes['show_comment'] == 1)
$fnames[] = array($q->fieldname, "File " . ($i + 1) . " - " . $q->text . "(Comment)", "comment", $i);

$fnames[] = array($q->fieldname, "File " . ($i + 1) . " - " . $q->text . "(File name)", "name", $i);
$fnames[] = array($q->fieldname, "File " . ($i + 1) . " - " . $q->text . "(File size)", "size", $i);
}
}
else
$fnames[] = array($q->fieldname, "File count");
}
}


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

$aSurveyEntries = new stdClass();
$aSurveyEntries->page = 1;

$all_rows = array();
foreach ($dtresult as $row) {

// BUG: For some reason, the $action_html is placed outside the json string! //
$action_html = "<a href='" . Yii::app()->createUrl("admin/responses/view/surveyid/$surveyid/id/{$row['id']}") . "'><img src='" . $sImageURL . "/token_viewanswer.png' alt='" . $clang->gT('View response details') . "'/></a>";
if (hasSurveyPermission($surveyid, 'responses', 'update')) {
$action_html .= "<a href='" . Yii::app()->createUrl("admin/dataentry/editdata/subaction/edit/surveyid/{$surveyid}/id/{$row['id']}") . "'><img src='" . $sImageURL . "/edit_16.png' alt='" . $clang->gT('Edit this response') . "'/></a>";
}
if (hasFileUploadQuestion($surveyid)) {
$action_html .= "<a><img id='downloadfile_" . $row['id'] . "' src='" . $sImageURL . "/down.png' alt='" . $clang->gT('Download all files in this response as a zip file') . "' class='downloadfile'/></a>";
}
if (hasSurveyPermission($surveyid, 'responses', 'delete')) {
$action_html .= "<a><img id='deleteresponse_" . $row['id'] . "' src='" . $sImageURL . "/token_delete.png' alt='" . $clang->gT('Delete this response') . "' class='deleteresponse'/></a>";
}


$aSurveyEntry = array();

$aSurveyEntry[] = '<!--a-->' . $action_html;
$aSurveyEntry[] = empty($row['submitdate'])?'N':'Y';
$aSurveyEntry[] = $row['id'];
$aSurveyEntry[] = $row['startlanguage'];
$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'))) {
continue;
}

$aSurveyEntry[] = $row_value;

}


$all_rows[] = array('id' => $row['id'], 'cell' => $aSurveyEntry);

}

$aSurveyEntries->rows = $all_rows;

echo ls_json_encode($aSurveyEntries);

}


function oldbrowse($iSurveyID)
{
$aData = $this->_getData($iSurveyID);
extract($aData);
Expand Down
67 changes: 67 additions & 0 deletions application/views/admin/responses/listResponses_view.php
@@ -0,0 +1,67 @@
<script type='text/javascript'>
var strdeleteconfirm='<?php $clang->eT('Do you really want to delete this response?', 'js'); ?>';
var strDeleteAllConfirm='<?php $clang->eT('Do you really want to delete all marked responses?', 'js'); ?>';
var noFilesSelectedForDeletion = '<?php $clang->eT('Please select at least one file for deletion', 'js'); ?>';
var noFilesSelectedForDnld = '<?php $clang->eT('Please select at least one file for download', 'js'); ?>';
</script>

<br />
<script type='text/javascript'>
var getuserurl = '<?php echo $this->createUrl('admin/survey/ajaxgetusers'); ?>';
var ownerediturl = '<?php echo $this->createUrl('admin/survey/ajaxowneredit'); ?>';
var delmsg ='<?php $clang->eT("Are you sure you want to delete these surveys?",'js');?>';
var sCaption ='<?php $clang->eT("Survey Respones",'js');?>';
var sSelectColumns ='<?php $clang->eT("Select columns",'js');?>';
var sRecordText = '<?php $clang->eT("View {0} - {1} of {2}",'js');?>';
var sPageText = '<?php $clang->eT("Page {0} of {1}",'js');?>';
var sLoadText = '<?php $clang->eT("Loading...",'js');?>';
var sDelTitle = '<?php $clang->eT("Delete selected response(s)",'js');?>';
var sDelCaption = '<?php $clang->eT("Delete",'js');?>';
var sSearchCaption = '<?php $clang->eT("Filter...",'js');?>';
var sOperator1= '<?php $clang->eT("equal",'js');?>';
var sOperator2= '<?php $clang->eT("not equal",'js');?>';
var sOperator3= '<?php $clang->eT("less",'js');?>';
var sOperator4= '<?php $clang->eT("less or equal",'js');?>';
var sOperator5= '<?php $clang->eT("greater",'js');?>';
var sOperator6= '<?php $clang->eT("greater or equal",'js');?>';
var sOperator7= '<?php $clang->eT("begins with",'js');?>';
var sOperator8= '<?php $clang->eT("does not begin with",'js');?>';
var sOperator9= '<?php $clang->eT("is in",'js');?>';
var sOperator10= '<?php $clang->eT("is not in",'js');?>';
var sOperator11= '<?php $clang->eT("ends with",'js');?>';
var sOperator12= '<?php $clang->eT("does not end with",'js');?>';
var sOperator13= '<?php $clang->eT("contains",'js');?>';
var sOperator14= '<?php $clang->eT("does not contain",'js');?>';
var sFind= '<?php $clang->eT("Filter",'js');?>';
var sReset= '<?php $clang->eT("Reset",'js');?>';
var sSelectColumns= '<?php $clang->eT("Select columns",'js');?>';
var sSubmit= '<?php $clang->eT("Save",'js');?>';

var sCancel = '<?php $clang->eT("Cancel",'js');?>';
var sSearchTitle ='<?php $clang->eT("Filter responses",'js');?>';
var sRefreshTitle ='<?php $clang->eT("Reload responses list",'js');?>';
var delBtnCaption ='<?php $clang->eT("Save",'js');?>';
var sEmptyRecords ='<?php $clang->eT("There are currently no responses.",'js');?>';
var jsonUrl = "<?php echo Yii::app()->getController()->createUrl('/admin/responses/getResponses_json/surveyid/'.$surveyid); ?>";
//var sConfirmationExpireMessage='<?php $clang->eT("Are you sure you want to expire these surveys?",'js');?>';
//var sConfirmationArchiveMessage='<?php $clang->eT("This function creates a ZIP archive of several survey archives and can take some time - please be patient! Do you want to continue?",'js');?>';
// var editUrl = "<?php echo $this->createUrl('/admin/survey/editSurvey_json'); ?>";
var colNames = <?php echo $column_names_txt; ?>;
var colModels = <?php echo $column_model_txt; ?>;


</script>
<br/>

<table id="displayresponses"></table> <div id="pager"></div>

<select id='gs_completed_select' style='display: none'>
<option value=''><?php $clang->eT("Any") ?></option>
<option value='Y'><?php $clang->eT("Yes") ?></option>
<option value='N'><?php $clang->eT("No") ?></option>
</select>

<div id='gs_no_filter'>&nbsp;</div>

<br />