Skip to content

Commit

Permalink
Fixed #7082: Clicking view response in tokens table opens response in…
Browse files Browse the repository at this point in the history
… same window causing search to be lost

dev: ported changes from 2.1 to master now using links instead of onclicks so user can choose where to open
  • Loading branch information
mennodekker committed Dec 20, 2012
1 parent 04f5b1f commit cd06195
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 21 deletions.
40 changes: 19 additions & 21 deletions application/controllers/admin/tokens.php
Expand Up @@ -444,44 +444,42 @@ function getTokens_json($iSurveyId, $search = null)
$aRowToAdd['id'] = $token['tid'];

$action="";
if($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] =="")) {
$action .= '<input type="image" style="float: left" src="' . Yii::app()->getConfig('adminimageurl') . 'do_16.png" title="' . $clang->gT("Do survey") . '" alt="' . $clang->gT("Do survey") . '" onclick=\'window.open("' . Yii::app()->getController()->createUrl("survey/index/sid/{$iSurveyId}/token/{$token['token']}/newtest/Y") . '", "_blank")\'>';
} elseif ($token['completed'] != "N" && $token['completed'] != "" && $aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == 'Y') {
// Get the survey response id of the matching entry, can be optimised into 1 call leaving for now
$id=Survey_dynamic::model($iSurveyId)->findAllByAttributes(array('token'=>$token['token']));
if (count($id)>0)
{
$action .= '<input type="image" style="float: left" src="' . Yii::app()->getConfig('adminimageurl') . 'token_viewanswer.png" title="' . $clang->gT("View response details"). '" alt="' . $clang->gT("View response details"). '" onClick=\'window.open("'. Yii::app()->getController()->createUrl("admin/responses/sa/view/surveyid/{$iSurveyId}/id/{$id[0]['id']}").'", "_top")\'>';
if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "")) {
$action .= viewHelper::getImageLink('do_16.png', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/newtest/Y", $clang->gT("Do survey"), '_blank');
} elseif ($token['completed'] != "N" && $token['completed'] != "" && $aSurveyInfo['anonymized'] == "N") {
//Get the survey response id of the matching entry
$id = Survey_dynamic::model($iSurveyId)->findAllByAttributes(array('token' => $token['token']));
if (count($id) > 0) {
$action .= viewHelper::getImageLink('token_viewanswer.png', "admin/responses/sa/view/surveyid/{$iSurveyId}/id/{$id[0]['id']}", $clang->gT("View response details"), null, '_top');
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
$action .= '<input type="image" style="float: left" src="' . Yii::app()->getConfig('adminimageurl') . 'token_delete.png" title="' . $clang->gT("Delete token entry") . '" alt="' . $clang->gT("Delete token entry") . '" onclick=\'if (confirm("' . $clang->gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}\'>';
if (strtolower($token['emailstatus']) == 'ok')
{
if($token['completed'] == 'N' && $token['usesleft'] > 0)
{
if ($token['sent'] == 'N')
$action .= '<input type="image" style="float: left" src="' . Yii::app()->getConfig('adminimageurl') . 'token_invite.png" name="sendinvitations" id="sendinvitations" title="' . $clang->gT("Send invitation email to this person (if they have not yet been sent an invitation email)") . '" onclick=\'window.open("' . Yii::app()->getController()->createUrl("admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid']) . '")\' />';
else
$action .= '<input type="image" style="float: left" src="' . Yii::app()->getConfig('adminimageurl') . 'token_remind.png" name="sendreminders" id="sendreminders" title="' . $clang->gT("Send reminder email to this person (if they have already received the invitation email)") . '" onclick=\'window.open("' . Yii::app()->getController()->createUrl("admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid']) . '")\' />';
$attribs = array('onclick' => 'if (confirm("' . $clang->gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}');
$action .= viewHelper::getImageLink('token_delete.png', null, $clang->gT("Delete token entry"), null, 'imagelink btnDelete', $attribs);
if (strtolower($token['emailstatus']) == 'ok') {
if ($token['completed'] == 'N' && $token['usesleft'] > 0) {
if ($token['sent'] == 'N') {
$action .= viewHelper::getImageLink('token_invite.png', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "_blank");
} else {
$action .= viewHelper::getImageLink('token_remind.png', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send reminder email to this person (if they have already received the invitation email)"), "_blank");
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
$action .= '<input style="float: left; height: 16; width: 16px; font-size: 8; font-family: verdana" type="image" src="' . Yii::app()->getConfig('adminimageurl') . 'edit_16.png" class="token_edit" title="' . $clang->gT("Edit token entry") . '" alt="' . $clang->gT("Edit token entry") . '">';
$action .= viewHelper::getImageLink('edit_16.png', null, $clang->gT("Edit token entry"), null, 'imagelink token_edit');
if(!empty($token['participant_id']) && $token['participant_id'] != "" && hasGlobalPermission('USER_RIGHT_PARTICIPANT_PANEL')) {
$action .= '<input type="image" style="float: left" src="'.Yii::app()->getConfig('adminimageurl').'cpdb_16.png" name="viewparticipant" id="viewparticipant" title="'.$clang->gT("View this person in the central participants database").'" alt="'.$clang->gT("View this person in the central participants database").'" onClick=\'window.open("'.Yii::app()->getController()->createUrl("admin/participants/sa/displayParticipants/searchurl/participant_id||equal||".$token['participant_id']).'", "_top")\'>';
$action .= viewHelper::getImageLink('cpdb_16.png', "admin/participants/sa/displayParticipants/searchurl/participant_id||equal||" . $token['participant_id'], $clang->gT("View this person in the central participants database"), '_top');
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
$aRowToAdd['cell'] = array($token['tid'], $action, $token['firstname'], $token['lastname'], $token['email'], $token['emailstatus'], $token['token'], $token['language'], $token['sent'], $token['remindersent'], $token['remindercount'], $token['completed'], $token['usesleft'], $token['validfrom'], $token['validuntil']);
foreach ($attributes as $attribute)
{
foreach ($attributes as $attribute) {
$aRowToAdd['cell'][] = $token[$attribute];
}
$aData->rows[] = $aRowToAdd;
Expand Down
7 changes: 7 additions & 0 deletions application/core/Survey_Common_Action.php
Expand Up @@ -25,7 +25,14 @@
*/
class Survey_Common_Action extends CAction
{
public function __construct($controller, $id)
{
parent::__construct($controller, $id);

// Make sure viewHelper can be autoloaded
Yii::import('application.helpers.viewHelper');
}

/**
* Override runWithParams() implementation in CAction to help us parse
* requests with subactions.
Expand Down
56 changes: 56 additions & 0 deletions application/helpers/viewHelper.php
@@ -0,0 +1,56 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/

/**
* General helper class for generating views.
*/
class viewHelper
{
/**
* Returns HTML needed for a link that consists of only an image with alt text.
*
* Usage: getImageLink('test.png', 'controller/action/params', 'Your description', 'optionalClass', '_blank')
*
* @param string $imgName the name of the image to use, adminImageUrl will be added to it
* @param string $linkUrl Url we want to go to, uses CController->createUrl()
* @param string $linkTxt Text to show for the link
* @param string $linkTarget Optional target to use for the link
* @param string $linkclass Optional class to add to the link
* @param array $attribs Optional array of attirbutes to set on the link
*/
public static function getImageLink($imgName, $linkUrl, $linkTxt, $linkTarget = null, $linkClass = 'imagelink', $attribs = array())
{
if (!is_null($linkUrl) && $linkUrl != '#') {
$linkUrl = Yii::app()->getController()->createUrl($linkUrl);
} else {
$linkUrl = "#";
}
$output = '<a href="' . $linkUrl;
if (!empty($linkClass)) {
$output .= '" class="' . $linkClass . '"';
}
if (!empty($linkTarget)) {
$output .= ' target="' . $linkTarget . '"';
}
if (!empty($attribs)) {
foreach($attribs as $attrib => $value) {
$output .= ' ' . $attrib . '="' . str_replace('"', '&quot;', $value) . '"';
}
}
$output .= '><img src="' . Yii::app()->getConfig('adminimageurl') . $imgName . '" alt="' . $linkTxt. '" title="' . $linkTxt. '"></a>';

return $output;
}
}

1 comment on commit cd06195

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.