Skip to content

Commit

Permalink
Fixed issue #6816 : browse individual response navigation buttons don…
Browse files Browse the repository at this point in the history
…'t test if srid exist

Dev: maybe the incompleteAnsFilterState can be better included
Dev : test if actual srid exist, and get next and previous existing srid acoding to incompleteAnsFilterState
  • Loading branch information
Shnoulle committed Nov 3, 2012
1 parent 7f71d1d commit ffd6edc
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 91 deletions.
144 changes: 78 additions & 66 deletions application/controllers/admin/responses.php
Expand Up @@ -179,97 +179,109 @@ public function view($iSurveyID, $iId, $sBrowseLang = '')
}

$nfncount = count($fnames) - 1;
//SHOW INDIVIDUAL RECORD
$oCriteria = new CDbCriteria();
if ($aData['surveyinfo']['anonymized'] == 'N' && tableExists("{{tokens_$iSurveyID}}}"))
{
$oCriteria = Survey_dynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
}
if (incompleteAnsFilterState() == 'incomplete')
$oCriteria->addCondition('submitdate = ' . mktime(0, 0, 0, 1, 1, 1980) . ' OR submitdate IS NULL');
elseif (incompleteAnsFilterState() == 'complete')
$oCriteria->addCondition('submitdate >= ' . mktime(0, 0, 0, 1, 1, 1980));
if ($iId < 1)
{
$iId = 1;
}
$oCriteria->addCondition("id = {$iId}");

$iIdresult = Survey_dynamic::model($iSurveyID)->findAllAsArray($oCriteria) or die("Couldn't get entry");
foreach ($iIdresult as $iIdrow)
{
$iId = $iIdrow['id'];
$rlanguage = $iIdrow['startlanguage'];
}
$next = $iId + 1;
$last = $iId - 1;

$aData['id'] = $iId;
if (isset($rlanguage))
{
$aData['rlanguage'] = $rlanguage;
}
$exist = Survey_dynamic::model($iSurveyID)->exist($iId);
$next = Survey_dynamic::model($iSurveyID)->next($iId,true);
$previous = Survey_dynamic::model($iSurveyID)->previous($iId,true);
$aData['exist'] = $exist;
$aData['next'] = $next;
$aData['last'] = $last;
$aData['previous'] = $previous;
$aData['id'] = $iId;

$aViewUrls[] = 'browseidheader_view';

foreach ($iIdresult as $iIdrow)
if($exist)
{
$highlight = false;
for ($i = 0; $i < $nfncount + 1; $i++)
//SHOW INDIVIDUAL RECORD
$oCriteria = new CDbCriteria();
if ($aData['surveyinfo']['anonymized'] == 'N' && tableExists("{{tokens_$iSurveyID}}}"))
{
if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]]))
{
continue; // irrelevant, so don't show
}
$inserthighlight = '';
if ($highlight)
$inserthighlight = "class='highlight'";
$oCriteria = Survey_dynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
}
// If admin ask an specific response, then show it
// Don't add incompleteAnsFilterState
# if (incompleteAnsFilterState() == 'incomplete')
# $oCriteria->addCondition('submitdate = ' . mktime(0, 0, 0, 1, 1, 1980) . ' OR submitdate IS NULL');
# elseif (incompleteAnsFilterState() == 'complete')
# $oCriteria->addCondition('submitdate >= ' . mktime(0, 0, 0, 1, 1, 1980));
$oCriteria->addCondition("id = {$iId}");
$iIdresult = Survey_dynamic::model($iSurveyID)->findAllAsArray($oCriteria);
foreach ($iIdresult as $iIdrow)
{
$iId = $iIdrow['id'];
$rlanguage = $iIdrow['startlanguage'];
}
$next = Survey_dynamic::model($iSurveyID)->next($iId);
$previous = Survey_dynamic::model($iSurveyID)->previous($iId);

if ($fnames[$i][0] == 'completed')
if (isset($rlanguage))
{
$aData['rlanguage'] = $rlanguage;
}
foreach ($iIdresult as $iIdrow)
{
$highlight = false;
for ($i = 0; $i < $nfncount + 1; $i++)
{
if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N")
if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]]))
{
$answervalue = "N";
continue; // irrelevant, so don't show
}
else
{
$answervalue = "Y";
}
}
else
{
if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|")
{
$index = $fnames[$i]['index'];
$metadata = $fnames[$i]['metadata'];
$phparray = json_decode_ls($iIdrow[$fnames[$i][0]]);
$inserthighlight = '';
if ($highlight)
$inserthighlight = "class='highlight'";

if (isset($phparray[$index]))
if ($fnames[$i][0] == 'completed')
{
if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N")
{
if ($metadata === "size")
$answervalue = rawurldecode(((int) ($phparray[$index][$metadata])) . " KB");
else if ($metadata === "name")
$answervalue = CHtml::link(rawurldecode($phparray[$index][$metadata]), $this->getController()->createUrl("/admin/responses/index/downloadindividualfile/{$phparray[$index][$metadata]}/fieldname/{$fnames[$i][0]}/id/{$iId}/surveyid/{$iSurveyID}"));
else
$answervalue = rawurldecode($phparray[$index][$metadata]);
$answervalue = "N";
}
else
$answervalue = "";
{
$answervalue = "Y";
}
}
else
{
$answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES);
if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|")
{
$index = $fnames[$i]['index'];
$metadata = $fnames[$i]['metadata'];
$phparray = json_decode_ls($iIdrow[$fnames[$i][0]]);

if (isset($phparray[$index]))
{
if ($metadata === "size")
$answervalue = rawurldecode(((int) ($phparray[$index][$metadata])) . " KB");
else if ($metadata === "name")
$answervalue = CHtml::link(rawurldecode($phparray[$index][$metadata]), $this->getController()->createUrl("/admin/responses/index/downloadindividualfile/{$phparray[$index][$metadata]}/fieldname/{$fnames[$i][0]}/id/{$iId}/surveyid/{$iSurveyID}"));
else
$answervalue = rawurldecode($phparray[$index][$metadata]);
}
else
$answervalue = "";
}
else
{
$answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES);
}
}
$aData['answervalue'] = $answervalue;
$aData['inserthighlight'] = $inserthighlight;
$aData['fnames'] = $fnames;
$aData['i'] = $i;
$aViewUrls['browseidrow_view'][] = $aData;
}
$aData['answervalue'] = $answervalue;
$aData['inserthighlight'] = $inserthighlight;
$aData['fnames'] = $fnames;
$aData['i'] = $i;
$aViewUrls['browseidrow_view'][] = $aData;
}
}
else
{
Yii::app()->session['flashmessage'] = $clang->gT("This answer doesn't exist.");
}

$aViewUrls[] = 'browseidfooter_view';

Expand Down
93 changes: 93 additions & 0 deletions application/models/Survey_dynamic.php
Expand Up @@ -205,5 +205,98 @@ public function isCompleted($srid)
return $completed;
}

/**
* Return true if actual respnse exist in database
*
* @param $srid : actual save survey id
*
* @return boolean
*/
public function exist($srid)
{
$sid = self::$sid;
$exist=false;

if(Yii::app()->db->schema->getTable($this->tableName())){
$data=Yii::app()->db->createCommand()
->select("id")
->from($this->tableName())
->where('id=:id', array(':id'=>$srid))
->queryRow();
if($data)
{
$exist=true;
}
}
return $exist;
}

/**
* Return next id if next response exist in database
*
* @param integer $srid : actual save survey id
* @param boolean $usefilterstate
*
* @return integer
*/
public function next($srid,$usefilterstate=false)
{
$sid = self::$sid;
$next=false;
if ($usefilterstate && incompleteAnsFilterState() == 'incomplete')
$wherefilterstate='submitdate IS NULL';
elseif ($usefilterstate && incompleteAnsFilterState() == 'complete')
$wherefilterstate='submitdate IS NOT NULL';
else
$wherefilterstate='true';

if(Yii::app()->db->schema->getTable($this->tableName())){
$data=Yii::app()->db->createCommand()
->select("id")
->from($this->tableName())
->where(array('and',$wherefilterstate,'id > :id'), array(':id'=>$srid))
->order('id ASC')
->queryRow();
if($data)
{
$next=$data['id'];
}
}
return $next;
}

/**
* Return previous id if previous response exist in database
*
* @param integer $srid : actual save survey id
* @param boolean $usefilterstate
*
* @return integer
*/
public function previous($srid,$usefilterstate=false)
{
$sid = self::$sid;
$previous=false;
if ($usefilterstate && incompleteAnsFilterState() == 'incomplete')
$wherefilterstate='submitdate IS NULL';
elseif ($usefilterstate && incompleteAnsFilterState() == 'complete')
$wherefilterstate='submitdate IS NOT NULL';
else
$wherefilterstate='true';

if(Yii::app()->db->schema->getTable($this->tableName())){
$data=Yii::app()->db->createCommand()
->select("id")
->from($this->tableName())
->where(array('and',$wherefilterstate,'id < :id'), array(':id'=>$srid))
->order('id DESC')
->queryRow();
if($data)
{
$previous=$data['id'];
}
}
return $previous;
}
}
?>
56 changes: 31 additions & 25 deletions application/views/admin/responses/browseidheader_view.php
Expand Up @@ -4,34 +4,40 @@
<div class='menubar-left'>
<img src='<?php echo $sImageURL; ?>/blank.gif' width='31' height='16' alt='' />
<img src='<?php echo $sImageURL; ?>/separator.gif' class='separator' alt='' />
<?php if (isset($rlanguage))
{ ?>
<a href='<?php echo $this->createUrl("admin/dataentry/editdata/subaction/edit/surveyid/{$surveyid}/id/{$id}/lang/$rlanguage"); ?>' title='<?php $clang->eT("Edit this entry"); ?>'>
<img src='<?php echo $sImageURL; ?>edit.png' alt='<?php $clang->gT("Edit this entry"); ?>' /></a>
<?php }
if (hasSurveyPermission($surveyid, 'responses', 'delete') && isset($rlanguage))
{ ?>
<a href='#' title='<?php $clang->eT("Delete this entry"); ?>' onclick="if (confirm('<?php $clang->eT("Are you sure you want to delete this entry?", "js"); ?>')) { <?php echo convertGETtoPOST($this->createUrl("admin/dataentry/delete/id/$id/sid/$surveyid")); ?>}">
<img src='<?php echo $sImageURL; ?>delete.png' alt='<?php $clang->eT("Delete this entry"); ?>' /></a>
<?php }
else
{ ?>
<img src='<?php echo $sImageURL; ?>delete_disabled.png' alt='<?php $clang->eT("You don't have permission to delete this entry."); ?>'/>
<?php }
if (hasFileUploadQuestion($surveyid))
{ ?>
<a href='#' title='<?php $clang->eT("Download files for this entry"); ?>' onclick="<?php echo convertGETtoPOST('?action=browse&amp;subaction=all&amp;downloadfile=' . $id . '&amp;sid=' . $surveyid); ?>" >
<img src='<?php echo $sImageURL; ?>download.png' alt='<?php $clang->eT("Download files for this entry"); ?>' /></a>
<?php } ?>
<?php if($exist) { ?>
<?php if (isset($rlanguage))
{ ?>
<a href='<?php echo $this->createUrl("admin/dataentry/editdata/subaction/edit/surveyid/{$surveyid}/id/{$id}/lang/$rlanguage"); ?>' title='<?php $clang->eT("Edit this entry"); ?>'>
<img src='<?php echo $sImageURL; ?>edit.png' alt='<?php $clang->gT("Edit this entry"); ?>' /></a>
<?php }
if (hasSurveyPermission($surveyid, 'responses', 'delete') && isset($rlanguage))
{ ?>
<a href='#' title='<?php $clang->eT("Delete this entry"); ?>' onclick="if (confirm('<?php $clang->eT("Are you sure you want to delete this entry?", "js"); ?>')) { <?php echo convertGETtoPOST($this->createUrl("admin/dataentry/delete/id/$id/sid/$surveyid")); ?>}">
<img src='<?php echo $sImageURL; ?>delete.png' alt='<?php $clang->eT("Delete this entry"); ?>' /></a>
<?php }
else
{ ?>
<img src='<?php echo $sImageURL; ?>delete_disabled.png' alt='<?php $clang->eT("You don't have permission to delete this entry."); ?>'/>
<?php }
if (hasFileUploadQuestion($surveyid))
{ ?>
<a href='#' title='<?php $clang->eT("Download files for this entry"); ?>' onclick="<?php echo convertGETtoPOST('?action=browse&amp;subaction=all&amp;downloadfile=' . $id . '&amp;sid=' . $surveyid); ?>" >
<img src='<?php echo $sImageURL; ?>download.png' alt='<?php $clang->eT("Download files for this entry"); ?>' /></a>
<?php } ?>

<a href='<?php echo $this->createUrl("admin/export/exportresults/surveyid/$surveyid/id/$id"); ?>' title='<?php $clang->eT("Export this Response"); ?>' >
<img src='<?php echo $sImageURL; ?>/export.png' alt='<?php $clang->eT("Export this Response"); ?>'/></a>
<img src='<?php echo $sImageURL; ?>/separator.gif' class='separator' alt='' />
<a href='<?php echo $this->createUrl("admin/export/exportresults/surveyid/$surveyid/id/$id"); ?>' title='<?php $clang->eT("Export this Response"); ?>' >
<img src='<?php echo $sImageURL; ?>/export.png' alt='<?php $clang->eT("Export this Response"); ?>'/></a>
<img src='<?php echo $sImageURL; ?>/separator.gif' class='separator' alt='' />
<?php } ?>
<img src='<?php echo $sImageURL; ?>/blank.gif' width='20' height='20' alt='' />
<a href='<?php echo $this->createUrl("admin/responses/view/surveyid/$surveyid/id/$last"); ?>' title='<?php $clang->eT("Show previous..."); ?>' >
<?php if($previous) { ?>
<a href='<?php echo $this->createUrl("admin/responses/view/surveyid/$surveyid/id/$previous"); ?>' title='<?php $clang->eT("Show previous..."); ?>' >
<img src='<?php echo $sImageURL; ?>databack.png' alt='<?php $clang->eT("Show previous..."); ?>' /></a>
<a href='<?php echo $this->createUrl("admin/responses/view/surveyid/$surveyid/id/$next"); ?>' title='<?php $clang->eT("Show next..."); ?>'>
<img src='<?php echo $sImageURL; ?>dataforward.png' alt='<?php $clang->eT("Show next..."); ?>' /></a>
<?php } ?>
<?php if($next) { ?>
<a href='<?php echo $this->createUrl("admin/responses/view/surveyid/$surveyid/id/$next"); ?>' title='<?php $clang->eT("Show next..."); ?>'>
<img src='<?php echo $sImageURL; ?>dataforward.png' alt='<?php $clang->eT("Show next..."); ?>' /></a>
<?php } ?>
</div>
</div>
</div>
Expand Down

0 comments on commit ffd6edc

Please sign in to comment.