diff --git a/application/controllers/admin/tokens.php b/application/controllers/admin/tokens.php index fff75930ea1..a318738fd7d 100644 --- a/application/controllers/admin/tokens.php +++ b/application/controllers/admin/tokens.php @@ -444,44 +444,42 @@ function getTokens_json($iSurveyId, $search = null) $aRowToAdd['id'] = $token['tid']; $action=""; - if($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] =="")) { - $action .= '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 .= '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 .= '
'; } } else { $action .= '
'; } - $action .= '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 .= 'getController()->createUrl("admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid']) . '")\' />'; - else - $action .= '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 .= '
'; } } else { $action .= '
'; } - $action .= ''; + $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 .= '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 .= '
'; } $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; diff --git a/application/core/Survey_Common_Action.php b/application/core/Survey_Common_Action.php index 616a26eb29f..d6c64d15155 100644 --- a/application/core/Survey_Common_Action.php +++ b/application/core/Survey_Common_Action.php @@ -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. diff --git a/application/helpers/viewHelper.php b/application/helpers/viewHelper.php new file mode 100644 index 00000000000..e24a56441c8 --- /dev/null +++ b/application/helpers/viewHelper.php @@ -0,0 +1,56 @@ +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 = ' $value) { + $output .= ' ' . $attrib . '="' . str_replace('"', '"', $value) . '"'; + } + } + $output .= '>' . $linkTxt. ''; + + return $output; + } +} \ No newline at end of file