Skip to content

Commit

Permalink
Fixed issue: Incorporated token_return functionality into get_token_list
Browse files Browse the repository at this point in the history
  • Loading branch information
trougakoss committed Jul 26, 2012
1 parent 87429e0 commit f2a0bb2
Showing 1 changed file with 9 additions and 45 deletions.
54 changes: 9 additions & 45 deletions application/controllers/admin/remotecontrol.php
Expand Up @@ -1182,71 +1182,35 @@ public function add_participants($sSessionKey, $iSurveyID, $aParticipantData, $b
return array('status' => 'No permission');
}


/**
* RPC routing to to return unused Tokens.
* Returns the unused tokens in an Array.
*
* @access public
* @param string $sSessionKey
* @param int $iSurveyID
* @return array
*/
public function token_return($sSessionKey, $iSurveyID)
{
if ($this->_checkSessionKey($sSessionKey))
{
$surveyidExists = Survey::model()->findByPk($iSurveyID);
if (!isset($surveyidExists))
return array('status' => 'Error: Invalid survey ID');

if(!tableExists("{{tokens_$iSurveyID}}"))
return array('status' => 'Error: No token table');

if (hasSurveyPermission($iSurveyID, 'tokens', 'read'))
{
$oTokens = Tokens_dynamic::model($iSurveyID)->findAll("completed = 'N'");
if(count($oTokens)==0)
return array('status' => 'No unused Tokens found');

foreach ($oTokens as $token)
{
$aData[] = $token->attributes['token'];
}
return $aData;
}
else
return array('status' => 'No permission');
}
else
return array('status' => 'Invalid Session Key');
}

/**
* RPC routine to return the ids and info of tokens of a survey
* Returns array of ids and info
* if $bUnused is true, user will get the list of not completed tokens (old token_return functionality)
*
* @access public
* @param string $sSessionKey
* @param int $iSurveyID
* @param bool $bUnused
* @return array
*/
public function get_token_list($sSessionKey, $iSurveyID)
public function get_token_list($sSessionKey, $iSurveyID, $bUnused=false)
{
if ($this->_checkSessionKey($sSessionKey))
{
$surveyidExists = Survey::model()->findByPk($iSurveyID);
if (!isset($surveyidExists))
return array('status' => 'Error: Invalid survey ID');


if(!tableExists("{{tokens_$iSurveyID}}"))
return array('status' => 'Error: No token table');



if (hasSurveyPermission($iSurveyID, 'tokens', 'read'))
{
$oTokens = Tokens_dynamic::model($iSurveyID)->findAll();
if($bUnused)
$oTokens = Tokens_dynamic::model($iSurveyID)->findAll("completed = 'N'");
else
$oTokens = Tokens_dynamic::model($iSurveyID)->findAll();

if(count($oTokens)==0)
return array('status' => 'No Tokens found');

Expand Down

0 comments on commit f2a0bb2

Please sign in to comment.