Skip to content

Commit

Permalink
Fixed issue #6799: Dummy token generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Nov 2, 2012
1 parent 3691de9 commit 518092d
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 76 deletions.
8 changes: 4 additions & 4 deletions application/controllers/admin/conditionsaction.php
Expand Up @@ -1385,7 +1385,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
$aTokenAttrNames=getTokenFieldsAndNames($iSurveyID);
if (count($aTokenAttrNames) != 0)
{
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])])." [".$clang->gT("From token table")."]";
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description'])." [".$clang->gT("From token table")."]";
}
else
{
Expand Down Expand Up @@ -1458,7 +1458,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
$aTokenAttrNames=getTokenFieldsAndNames($iSurveyID);
if (count($aTokenAttrNames) != 0)
{
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])])." [".$clang->gT("From token table")."]";
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description'])." [".$clang->gT("From token table")."]";
}
else
{
Expand Down Expand Up @@ -1785,7 +1785,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
{
$selectThisSrcTokenAttr = "";
}
$aViewUrls['output'] .= "<option value='{TOKEN:".strtoupper($tokenattr)."}' $selectThisSrcTokenAttr>".HTMLEscape($tokenattrName)."</option>\n";
$aViewUrls['output'] .= "<option value='{TOKEN:".strtoupper($tokenattr)."}' $selectThisSrcTokenAttr>".HTMLEscape($tokenattrName['description'])."</option>\n";
}

$aViewUrls['output'] .= "</select>\n"
Expand Down Expand Up @@ -1904,7 +1904,7 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
."\t\t<select name='tokenAttr' id='tokenAttr' size='7'>\n";
foreach (getTokenFieldsAndNames($iSurveyID) as $tokenattr => $tokenattrName)
{
$aViewUrls['output'] .= "\t\t<option value='{TOKEN:".strtoupper($tokenattr)."}'>".HTMLEscape($tokenattrName)."</option>\n";
$aViewUrls['output'] .= "\t\t<option value='{TOKEN:".strtoupper($tokenattr)."}'>".HTMLEscape($tokenattrName['description'])."</option>\n";
}

$aViewUrls['output'] .= "\t\t</select>\n"
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/export.php
Expand Up @@ -250,8 +250,8 @@ public function exportresults()
{
$options->selectedColumns[]="email";
}
$attributeFields = getTokenFieldsAndNames($iSurveyID, TRUE);
foreach ($attributeFields as $attr_name => $attr_desc)
$attributeFields = array_keys(getTokenFieldsAndNames($iSurveyID, TRUE));
foreach ($attributeFields as $attr_name)
{
if ( in_array($attr_name, Yii::app()->request->getPost('attribute_select',array())) )
{
Expand Down
12 changes: 6 additions & 6 deletions application/controllers/admin/limereplacementfields.php
Expand Up @@ -215,7 +215,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array('TOKEN:' . strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array('TOKEN:' . strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('EXPIRY', $clang->gT("Survey expiration date"));
return array($replFields, false);
Expand All @@ -233,7 +233,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('ADMINNAME', $clang->gT("Name of the survey administrator"));
$replFields[] = array('ADMINEMAIL', $clang->gT("Email address of the survey administrator"));
Expand All @@ -253,7 +253,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('ADMINNAME', $clang->gT("Name of the survey administrator"));
$replFields[] = array('ADMINEMAIL', $clang->gT("Email address of the survey administrator"));
Expand All @@ -275,7 +275,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('ADMINNAME', $clang->gT("Name of the survey administrator"));
$replFields[] = array('ADMINEMAIL', $clang->gT("Email address of the survey administrator"));
Expand All @@ -292,7 +292,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('ADMINNAME', $clang->gT("Name of the survey administrator"));
$replFields[] = array('ADMINEMAIL', $clang->gT("Email address of the survey administrator"));
Expand Down Expand Up @@ -325,7 +325,7 @@ private function _getReplacementFields($fieldtype, $surveyid)
$attributes = getTokenFieldsAndNames($surveyid, true);
foreach ($attributes as $attributefield => $attributedescription)
{
$replFields[] = array('TOKEN:' . strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription));
$replFields[] = array('TOKEN:' . strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"), $attributedescription['description']));
}
$replFields[] = array('EXPIRY', $clang->gT("Survey expiration date"));
case 'editanswer':
Expand Down
10 changes: 5 additions & 5 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -1771,7 +1771,7 @@ function shareParticipants()
$time = time();
$aData = array('participant_id' => $iId,
'share_uid' => $iShareUserId,
'date_added' => date(DATE_W3C, $time),
'date_added' => date('Y-m-d H:i:s', $time),
'can_edit' => $bCanEdit);
ParticipantShares::model()->storeParticipantShare($aData);
$i++;
Expand Down Expand Up @@ -1904,7 +1904,7 @@ function attributeMap()
{
if (is_numeric($key[10])) //Assumes that if the 11th character is a number, it must be a token-table created attribute
{
$selectedattribute[$key] = $value;
$selectedattribute[$key] = $value['description'];
$i++;
}
else
Expand Down Expand Up @@ -1961,7 +1961,7 @@ function attributeMapToken()
{
if (is_numeric($key[10]))
{
$selectedattribute[$value] = $key;
$selectedattribute[$value['description']] = $key;
}
else
{
Expand All @@ -1975,9 +1975,9 @@ function attributeMapToken()
if($continue) {
array_push($alreadymappedattid, $attributeid);
array_push($alreadymappedattdisplay, $key);
$alreadymappedattnames[$key]=$value;
$alreadymappedattnames[$key]=$value['description'];
} else {
$selectedattribute[$value]=$key;
$selectedattribute[$value['description']]=$key;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion application/controllers/admin/remotecontrol.php
Expand Up @@ -2137,7 +2137,6 @@ public function remind_participants($sSessionKey, $iSurveyID, $iMinDaysBetween=n
$SQLemailstatuscondition = "emailstatus = 'OK'";
$SQLremindercountcondition = '';
$SQLreminderdelaycondition = '';
$attributes = getTokenFieldsAndNames($iSurveyID);
$iMaxEmails = (int)Yii::app()->getConfig("maxemails");

if(!is_null($iMinDaysBetween))
Expand Down
6 changes: 3 additions & 3 deletions application/controllers/admin/tokens.php
Expand Up @@ -1283,7 +1283,7 @@ function email($iSurveyId, $tokenids = null)
$aData['bEmail'] = $bEmail;
$aData['aSurveyLangs'] = $aData['surveylangs'] = $aSurveyLangs;
$aData['baselang'] = $sBaseLanguage;
$aData['tokenfields'] = $aTokenFields;
$aData['tokenfields'] = array_keys($aTokenFields);
$aData['nrofattributes'] = $iAttributes;
$aData['examplerow'] = $aExampleRow;
$aData['tokenids'] = $aTokenIds;
Expand Down Expand Up @@ -1353,7 +1353,7 @@ function email($iSurveyId, $tokenids = null)
$_POST['message_' . $language] = html_entity_decode(Yii::app()->request->getPost('message_' . $language), ENT_QUOTES, Yii::app()->getConfig("emailcharset"));
}

$attributes = getTokenFieldsAndNames($iSurveyId);
$attributes = array_keys(getTokenFieldsAndNames($iSurveyId));
$tokenoutput = "";

if ($emcount > 0)
Expand All @@ -1372,7 +1372,7 @@ function email($iSurveyId, $tokenids = null)
$fieldsarray["{TOKEN}"] = $emrow['token'];
$fieldsarray["{LANGUAGE}"] = $emrow['language'];

foreach ($attributes as $attributefield => $attributedescription)
foreach ($attributes as $attributefield)
{
$fieldsarray['{' . strtoupper($attributefield) . '}'] = $emrow[$attributefield];
$fieldsarray['{TOKEN:'.strtoupper($attributefield).'}']=$emrow[$attributefield];
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/admin/token_helper.php
Expand Up @@ -74,7 +74,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
else
$bHtml = false;

$attributes = getTokenFieldsAndNames($iSurveyID);
$attributes = array_keys(getTokenFieldsAndNames($iSurveyID));
$oSurveyLocale=Surveys_languagesettings::model()->findAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
$oTokens = Tokens_dynamic::model($iSurveyID);
$aSurveyLangs = $oSurvey->additionalLanguages;
Expand Down Expand Up @@ -127,7 +127,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
if($from == '')
$from = Yii::app()->getConfig('siteadminemail');

foreach ($attributes as $attributefield => $attributedescription)
foreach ($attributes as $attributefield)
{
$fieldsarray['{' . strtoupper($attributefield) . '}'] = $aTokenRow[$attributefield];
$fieldsarray['{TOKEN:'.strtoupper($attributefield).'}']=$aTokenRow[$attributefield];
Expand Down
112 changes: 69 additions & 43 deletions application/helpers/common_helper.php
Expand Up @@ -5376,15 +5376,13 @@ function filterForAttributes ($fieldname)
* @param mixed $iSurveyID The survey ID
* @return array The fieldnames
*/
function GetAttributeFieldNames($iSurveyID,$filter=true)
function GetAttributeFieldNames($iSurveyID)
{
if (!tableExists("{{tokens_{$iSurveyID}}}") || !$table = Yii::app()->db->schema->getTable('{{tokens_'.$iSurveyID.'}}'))
return Array();
if ($filter)
{
return array_filter(array_keys($table->columns), 'filterForAttributes');
}
return array_keys($table->columns);

return array_filter(array_keys($table->columns), 'filterForAttributes');

}

/**
Expand Down Expand Up @@ -5424,57 +5422,85 @@ function getTokenConditionsFieldNames($surveyid)
* Retrieves the attribute names from the related token table
*
* @param mixed $surveyid The survey ID
* @param boolean $onlyAttributes Set this to true if you only want the fieldnames of the additional attribue fields - defaults to false
* @param boolean $bOnlyAttributes Set this to true if you only want the fieldnames of the additional attribue fields - defaults to false
* @return array The fieldnames as key and names as value in an Array
*/
function getTokenFieldsAndNames($surveyid, $onlyAttributes = false)
function getTokenFieldsAndNames($surveyid, $bOnlyAttributes = false)
{
$clang = Yii::app()->lang;

$extra_attrs=getAttributeFieldNames($surveyid);
$basic_attrs=Array('firstname','lastname','email','token','language','sent','remindersent','remindercount','usesleft');
$basic_attrs_names=Array(
$clang->gT('First name'),
$clang->gT('Last name'),
$clang->gT('Email address'),
$clang->gT('Token code'),
$clang->gT('Language code'),
$clang->gT('Invitation sent date'),
$clang->gT('Last Reminder sent date'),
$clang->gT('Total numbers of sent reminders'),
$clang->gT('Uses left')
$aBasicTokenFields=array('firstname'=>array(
'description'=>$clang->gT('First name'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'lastname'=>array(
'description'=>$clang->gT('Last name'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'email'=>array(
'description'=>$clang->gT('Email address'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'token'=>array(
'description'=>$clang->gT('Token'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'language'=>array(
'description'=>$clang->gT('Language code'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'sent'=>array(
'description'=>$clang->gT('Invitation sent date'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'remindersent'=>array(
'description'=>$clang->gT('Last reminder sent date'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'remindercount'=>array(
'description'=>$clang->gT('Total numbers of sent reminders'),
'mandatory'=>'N',
'showregister'=>'Y'
),
'usesleft'=>array(
'description'=>$clang->gT('Uses left'),
'mandatory'=>'N',
'showregister'=>'Y'
),
);
$attdescriptiondata = array();
$attributedescriptions = array();
$basic_attrs_and_names = array();
$extra_attrs_and_names = array();
// !!! This is actually deprecated, use Survey::model()->findByPk($surveyid)->tokenAttributes instead
if ($surveyid)
$attdescriptiondata = Survey::model()->findByPk($surveyid)->tokenAttributes;
if (!is_null($attdescriptiondata))
{
foreach ($attdescriptiondata as $attname => $attdata)
$attributedescriptions[$attname] = $attdata['description'];
}
foreach ($extra_attrs as $fieldname)

$aExtraTokenFields=getAttributeFieldNames($surveyid);
$aSavedExtraTokenFields = Survey::model()->findByPk($surveyid)->tokenAttributes;

// Drop all fields that are in the saved field description but not in the table definition
$aSavedExtraTokenFields=array_intersect_key($aSavedExtraTokenFields,array_flip($aExtraTokenFields));

// Now add all fields that are in the table but not in the field description
foreach ($aExtraTokenFields as $sField)
{
if (isset($attributedescriptions[$fieldname]))
if (!isset($aSavedExtraTokenFields[$sField]))
{
$extra_attrs_and_names[$fieldname] = $attributedescriptions[$fieldname];
}
else
{
$extra_attrs_and_names[$fieldname] = sprintf($clang->gT('Attribute %s'),substr($fieldname,10));
$aSavedExtraTokenFields[$sField]=array(
'description'=>$sField,
'mandatory'=>'N',
'showregister'=>'N'
);
}
}
if ($onlyAttributes===false)
if ($bOnlyAttributes)
{
$basic_attrs_and_names=array_combine($basic_attrs,$basic_attrs_names);
return array_merge($basic_attrs_and_names,$extra_attrs_and_names);
return $aSavedExtraTokenFields;
}
else
{
return $extra_attrs_and_names;
return array_merge($aBasicTokenFields,$aSavedExtraTokenFields);
}
}

Expand Down
10 changes: 5 additions & 5 deletions application/helpers/export_helper.php
Expand Up @@ -354,14 +354,14 @@ function SPSSFieldMap($iSurveyID, $prefix = 'V') {
$fields=array();
if (isset($tokensexist) && $tokensexist == true && $surveyprivate == 'N') {
$tokenattributes=getTokenFieldsAndNames($iSurveyID,false);
foreach ($tokenattributes as $attributefield=>$attributedescription)
foreach ($tokenattributes as $attributefield=>$attributedescription['description'])
{
//Drop the token field, since it is in the survey too
if($attributefield!='token') {
$fieldno++;
$fields[] = array('id'=>"$prefix$fieldno",'name'=>mb_substr($attributefield, 0, 8),
'qid'=>0,'code'=>'','SPSStype'=>'A','LStype'=>'Undef',
'VariableLabel'=>$attributedescription,'sql_name'=>$attributefield,'size'=>'100',
'VariableLabel'=>$attributedescription['description'],'sql_name'=>$attributefield,'size'=>'100',
'title'=>$attributefield,'hide'=>0, 'scale'=>'');
}
}
Expand Down Expand Up @@ -496,8 +496,8 @@ function SPSSGetQuery($iSurveyID) {
#See if tokens are being used
if (isset($tokensexist) && $tokensexist == true && !$bDataAnonymized) {
$query="SELECT ";
$tokenattributes=getTokenFieldsAndNames($iSurveyID,false);
foreach ($tokenattributes as $attributefield=>$attributedescription) {
$tokenattributes=array_keys(getTokenFieldsAndNames($iSurveyID,false));
foreach ($tokenattributes as $attributefield) {
//Drop the token field, since it is in the survey too
if($attributefield!='token') {
$query .= "t.{$attributefield}, ";
Expand Down Expand Up @@ -1689,7 +1689,7 @@ function tokensExport($iSurveyID)
{
$tokenoutput .=", $attr_name";
if (isset($attrfielddescr[$attr_name]))
$tokenoutput .=" <".str_replace(","," ",$attrfielddescr[$attr_name]).">";
$tokenoutput .=" <".str_replace(","," ",$attrfielddescr[$attr_name]['description']).">";
}
$tokenoutput .="\n";

Expand Down

0 comments on commit 518092d

Please sign in to comment.