Skip to content

Commit

Permalink
Dev: Remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 19, 2016
1 parent 9b05fcb commit 5da5ac9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 276 deletions.
211 changes: 0 additions & 211 deletions application/controllers/admin/tokens.php
Expand Up @@ -411,217 +411,6 @@ public function browse($iSurveyId, $limit = 50, $start = 0, $order = false, $sea
$this->_renderWrappedTemplate('token', array('browse'), $aData);
}

/**
* This function sends the shared participant info to the share panel using JSON encoding
* This function is called after the share panel grid is loaded
* This function returns the json depending on the user logged in by checking it from the session
* @param it takes the session user data loginID
* @return JSON encoded string containg sharing information
*/
public function getTokens_json($iSurveyId, $search = null)
{
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
eT("No token table.");// return json ? error not treated in js.
return;
}
if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'read'))
{
eT("We are sorry but you don't have permissions to do this.");// return json ? error not treated in js.
return;
}
$page = (int)Yii::app()->request->getPost('page', 1);
$limit = (int)Yii::app()->request->getPost('rows', 25);
$sidx = Yii::app()->request->getPost('sidx', 'lastname');
$sord = Yii::app()->request->getPost('sord', 'asc');
if (strtolower($sord)!='desc') {
$sord='asc';
}
$aData = new stdClass;
$aData->page = $page;

$aSearchArray=Yii::app()->request->getPost('searcharray');
if(empty($search) && !empty($aSearchArray)){
$search=$aSearchArray;
}
if (!empty($search)) {
$condition = TokenDynamic::model($iSurveyId)->getSearchMultipleCondition($search);
}else{
$condition = new CDbCriteria();
}

$condition->order = Yii::app()->db->quoteColumnName($sidx). " ". $sord;
$condition->offset = ($page - 1) * $limit;
$condition->limit = $limit;
$tokens = Token::model($iSurveyId)->findAll($condition);

$condition->offset=0;
$condition->limit=0;
$aData->records = Token::model($iSurveyId)->count($condition);

if ($limit>$aData->records)
{
$limit=$aData->records;
}
if ($limit!=0)
{
$aData->total = ceil($aData->records / $limit);
}
else
{
$aData->total = 0;
}

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

$format = getDateFormatData(Yii::app()->session['dateformat']);

$aSurveyInfo = Survey::model()->findByPk($iSurveyId)->getAttributes(); //Get survey settings
$attributes = getAttributeFieldNames($iSurveyId);

// Now find all responses for the visible tokens
$visibleTokens = array();
$answeredTokens = array();
if ($aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == "Y") {
foreach ($tokens as $token) {
if(isset($token['token']) && $token['token'])
$visibleTokens[] = $token['token'];
}
$answers = SurveyDynamic::model($iSurveyId)->findAllByAttributes(array('token'=>$visibleTokens));
foreach($answers as $answer) {
$answeredTokens[$answer['token']] = $answer['token'];
}
}

$bReadPermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read');
$bCreatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'create');
$bTokenUpdatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update');
$bTokenDeletePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'delete');
$bGlobalPanelReadPermission = Permission::model()->hasGlobalPermission('participantpanel','read');
foreach ($tokens as $token)
{
$aRowToAdd = array();
if ((int) $token['validfrom']) {
$token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom'])));
} else {
$token['validfrom'] = '';
}
if ((int) $token['validuntil']) {
$token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil'])));
} else {
$token['validuntil'] = '';
}

$aRowToAdd['id'] = $token['tid'];

$action="";
$action .= "<div class='inputbuttons'>"; // so we can hide this when edit is clicked

// Check is we have an answer
if (in_array($token['token'], $answeredTokens) && $bReadPermission) {
// @@TODO change link
$url = $this->getController()->createUrl("admin/responses/sa/viewbytoken/surveyid/{$iSurveyId}", array('token'=>$token['token']));
$title = gT("View response details");
$action .= CHtml::link(
'<span class="inputbuttons-square glyphicon glyphicon-list-alt text-success" title="'.$title.'"></span>',
$url,
array('class'=>'imagelink'));
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}

// Check if the token can be taken
if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "" || $aSurveyInfo['alloweditaftercompletion']=="Y") && $bCreatePermission) {
$action .= viewHelper::getIconLink('inputbuttons-square icon-do text-success', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/lang/{$token['language']}/newtest/Y", gT("Do survey"), '_blank');
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}

// Add delete icon
if($bTokenDeletePermission){
$attribs = array('onclick' => 'if (confirm("' . gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}');
$action .= viewHelper::getIconLink('inputbuttons-square glyphicon glyphicon-trash text-warning', null, gT("Delete survey participant"), null, 'imagelink btnDelete', $attribs);
}

// Add email button
if (strtolower($token['emailstatus']) == 'ok' && $token['email'] && $bTokenUpdatePermission) {
if ($token['completed'] == 'N' && $token['usesleft'] > 0) {
if ($token['sent'] == 'N') {
$action .= viewHelper::getIconLink('inputbuttons-square icon-invite text-success', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "");
} else {
$action .= viewHelper::getIconLink('inputbuttons-square icon-remind text-success', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], gT("Send reminder email to this person (if they have already received the invitation email)"), "");
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}

// Add edit button
if($bTokenUpdatePermission) {
$action .= viewHelper::getIconLink('inputbuttons-square glyphicon glyphicon-pencil text-success', null, gT("Edit survey participant"), null, 'imagelink token_edit');
}

// Add view button?
if(!empty($token['participant_id']) && $token['participant_id'] != "" && $bGlobalPanelReadPermission) {
$action .= viewHelper::getIconLink('inputbuttons-square icon-cpdb text-success', null, gT("View this person in the central participants database"), null, 'imagelink cpdb',array('onclick'=>"sendPost('".$this->getController()->createUrl('admin/participants/sa/displayParticipants')."','',['searchcondition'],['participant_id||equal||{$token['participant_id']}']);"));
} else {
$action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
}

$action .= '</div>';

$sReminderSent = $token['remindersent'];
$sCompleted = $token['completed'];

if($sReminderSent!='N')
{
$sReminderSent = convertToGlobalSettingFormat($sReminderSent );
}

if($sCompleted!='N')
{
$sCompleted = convertToGlobalSettingFormat( $sCompleted );
}


$aRowToAdd['cell'] = array($token['tid'],
$action,
htmlspecialchars($token['firstname'],ENT_QUOTES),
htmlspecialchars($token['lastname'],ENT_QUOTES),
htmlspecialchars($token['email'],ENT_QUOTES),
htmlspecialchars($token['emailstatus'],ENT_QUOTES),
htmlspecialchars($token['token'],ENT_QUOTES),
htmlspecialchars($token['language'],ENT_QUOTES),
htmlspecialchars($token['sent'],ENT_QUOTES),
htmlspecialchars($sReminderSent,ENT_QUOTES),
htmlspecialchars($token['remindercount'],ENT_QUOTES),
htmlspecialchars($sCompleted,ENT_QUOTES),
htmlspecialchars($token['usesleft'],ENT_QUOTES),
htmlspecialchars($token['validfrom'],ENT_QUOTES),
htmlspecialchars($token['validuntil'],ENT_QUOTES));
foreach ($attributes as $attribute) {
$aRowToAdd['cell'][] = htmlspecialchars($token[$attribute],ENT_QUOTES);
}
$aData->rows[] = $aRowToAdd;
}
viewHelper::disableHtmlLogging();
header("Content-type: application/json");
echo ls_json_encode($aData);
}

public function getSearch_json($iSurveyId)
{
$searchcondition = Yii::app()->request->getQuery('search');
$searchcondition = urldecode($searchcondition);
$finalcondition = array();
$condition = explode("||", $searchcondition);
return $this->getTokens_json($iSurveyId, $condition);
}

/**
* Called by jqGrid if a token is saved after editing
*
Expand Down
65 changes: 0 additions & 65 deletions application/models/TokenDynamic.php
Expand Up @@ -397,71 +397,6 @@ public function beforeSave()
return parent::beforeSave();
}

/**
* Get CDbCriteria for a json search string
*
* @param array $condition
* @return \CDbCriteria
*/
function getSearchMultipleCondition($condition)
{
$i=0;
$j=1;
$command = new CDbCriteria;
$command->condition = '';
$iNumberOfConditions = (count($condition)+1)/4;
$sConnectingOperator = 'AND';
$aParams=array();
while($i < $iNumberOfConditions){
$sFieldname=$condition[$i*4];
$sOperator=$condition[($i*4)+1];
$sValue=$condition[($i*4)+2];
switch ($sOperator)
{
case 'equal':
$command->addCondition($sFieldname.' = :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = $sValue;
break;
case 'contains':
$command->addCondition($sFieldname.' LIKE :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = '%'.$sValue.'%';
break;
case 'notequal':
$command->addCondition($sFieldname.' <> :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = $sValue;
break;
case 'notcontains':
$command->addCondition($sFieldname.' NOT LIKE :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = '%'.$sValue.'%';
break;
case 'greaterthan':
$command->addCondition($sFieldname.' > :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = $sValue;
break;
case 'lessthan':
$command->addCondition($sFieldname.' < :condition_'.$i, $sConnectingOperator);
$aParams[':condition_'.$i] = $sValue;
break;
}
if (isset($condition[($i*4)+3]))
{
$sConnectingOperator=$condition[($i*4)+3];
}
else
{
$sConnectingOperator='AND';
}
$i++;

}
if (count($aParams)>0)
{
$command->params = $aParams;
}

return $command;
}

function deleteToken($tokenid)
{
$dlquery = "DELETE FROM ".TokenDynamic::tableName()." WHERE tid=:tokenid";
Expand Down

0 comments on commit 5da5ac9

Please sign in to comment.