Skip to content

Commit

Permalink
Fixed issue #9266: Chinese and Japanese characters not suppoerted whe…
Browse files Browse the repository at this point in the history
…n using MS SQL Server
  • Loading branch information
c-schmitz committed Oct 13, 2014
1 parent 42513f5 commit 1e883c5
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 106 deletions.
19 changes: 16 additions & 3 deletions application/helpers/admin/activate_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function activateSurvey($iSurveyID, $simulate = false)

//Get list of questions for the base language
$fieldmap = createFieldMap($iSurveyID,'full',true,false,getBaseLanguageFromSurveyID($iSurveyID));

$createsurvey = array();

foreach ($fieldmap as $j=>$arow) //With each question, create the appropriate field(s)
Expand Down Expand Up @@ -289,7 +289,12 @@ function activateSurvey($iSurveyID, $simulate = false)
$createsurvey[$arow['fieldname']] = "decimal (30,10)";
break;
case "S": //SHORT TEXT

if (Yii::app()->db->driverName == 'mysql' || Yii::app()->db->driverName == 'mysqli') {$createsurvey[$arow['fieldname']] = "text";}
elseif (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib')
{
$createsurvey[$arow['fieldname']] = "nvarchar(255)";
}
else {$createsurvey[$arow['fieldname']] = "string";}
break;
case "L": //LIST (RADIO)
Expand Down Expand Up @@ -363,6 +368,14 @@ function activateSurvey($iSurveyID, $simulate = false)
}
$arrSim[] = array($type);
}
if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib')
{
if ($createsurvey[$arow['fieldname']] == "text")
{
$createsurvey[$arow['fieldname']] = "ntext";
}
}


}

Expand Down Expand Up @@ -392,12 +405,12 @@ function activateSurvey($iSurveyID, $simulate = false)
catch (CDbException $e)
{
}

$anquery = "SELECT autonumber_start FROM {{surveys}} WHERE sid={$iSurveyID}";
$iAutoNumberStart=Yii::app()->db->createCommand($anquery)->queryScalar();
//if there is an autonumber_start field, start auto numbering here
if ($iAutoNumberStart!==false && $iAutoNumberStart>0)
{
{
if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') {
mssql_drop_primary_index('survey_'.$iSurveyID);
mssql_drop_constraint('id','survey_'.$iSurveyID);
Expand Down
90 changes: 59 additions & 31 deletions application/helpers/admin/token_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ function createTokenTable($iSurveyID, $aAttributeFields=array())
{
$fields[$sAttributeField]='string';
}

if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib')
{
$fields = array(
'tid' => 'pk',
'participant_id' => 'varchar(50)',
'firstname' => 'nvarchar(40)',
'lastname' => 'nvarchar(40)',
'email' => 'ntext',
'emailstatus' => 'ntext',
'token' => 'varchar(35)',
'language' => 'varchar(25)',
'blacklisted' => 'varchar(17)',
'sent' => "varchar(17) DEFAULT 'N'",
'remindersent' => "varchar(17) DEFAULT 'N'",
'remindercount' => 'integer DEFAULT 0',
'completed' => "varchar(17) DEFAULT 'N'",
'usesleft' => 'integer DEFAULT 1',
'validfrom' => 'datetime',
'validuntil' => 'datetime',
'mpid' => 'integer'
);
foreach ($aAttributeFields as $sAttributeField)
{
$fields[$sAttributeField]='nvarchar(255)';
}
}

try{
$sTableName="{{tokens_".intval($iSurveyID)."}}";
createTable($sTableName, $fields);
Expand Down Expand Up @@ -84,14 +112,14 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
$bHtml = true;
else
$bHtml = false;
$attributes = array_keys(getTokenFieldsAndNames($iSurveyID));

$attributes = array_keys(getTokenFieldsAndNames($iSurveyID));
$oSurveyLocale=SurveyLanguageSetting::model()->findAllByAttributes(array('surveyls_survey_id' => $iSurveyID));
$oTokens = Token::model($iSurveyID);
$aSurveyLangs = $oSurvey->additionalLanguages;
array_unshift($aSurveyLangs, $oSurvey->language);
//Convert result to associative array to minimize SurveyLocale access attempts

//Convert result to associative array to minimize SurveyLocale access attempts
foreach($oSurveyLocale as $rows)
{
$oTempObject=array();
Expand All @@ -103,7 +131,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
}

foreach ($aResultTokens as $aTokenRow)
{
{
//Select language
$aTokenRow['language'] = trim($aTokenRow['language']);
$found = array_search($aTokenRow['language'], $aSurveyLangs);
Expand All @@ -112,7 +140,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
$aTokenRow['language'] = $oSurvey['language'];
}
$sTokenLanguage = $aTokenRow['language'];


//Build recipient
$to = array();
Expand All @@ -121,34 +149,34 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
{
$to[] = ($aTokenRow['firstname'] . " " . $aTokenRow['lastname'] . " <{$sEmailaddress}>");
}


//Populate attributes

//Populate attributes
$fieldsarray["{SURVEYNAME}"] = $aSurveyLocaleData[$sTokenLanguage]['surveyls_title'];
if ($fieldsarray["{SURVEYNAME}"] == '')
$fieldsarray["{SURVEYNAME}"] = $aSurveyLocaleData[$oSurvey['language']]['surveyls_title'];

$fieldsarray["{SURVEYDESCRIPTION}"] = $aSurveyLocaleData[$sTokenLanguage]['surveyls_description'];
if ($fieldsarray["{SURVEYDESCRIPTION}"] == '')
$fieldsarray["{SURVEYDESCRIPTION}"] = $aSurveyLocaleData[$oSurvey['language']]['surveyls_description'];
$fieldsarray["{SURVEYDESCRIPTION}"] = $aSurveyLocaleData[$oSurvey['language']]['surveyls_description'];

$fieldsarray["{ADMINNAME}"] = $oSurvey['admin'];
$fieldsarray["{ADMINEMAIL}"] = $oSurvey['adminemail'];
$from = $fieldsarray["{ADMINEMAIL}"];
if($from == '')
$from = Yii::app()->getConfig('siteadminemail');
$from = Yii::app()->getConfig('siteadminemail');

foreach ($attributes as $attributefield)
{
$fieldsarray['{' . strtoupper($attributefield) . '}'] = $aTokenRow[$attributefield];
$fieldsarray['{TOKEN:'.strtoupper($attributefield).'}']=$aTokenRow[$attributefield];
}

//create urls
$fieldsarray["{OPTOUTURL}"] = Yii::app()->getController()->createAbsoluteUrl("/optout/tokens/langcode/" . trim($aTokenRow['language']) . "/surveyid/{$iSurveyID}/token/{$aTokenRow['token']}");
$fieldsarray["{OPTINURL}"] = Yii::app()->getController()->createAbsoluteUrl("/optin/tokens/langcode/" . trim($aTokenRow['language']) . "/surveyid/{$iSurveyID}/token/{$aTokenRow['token']}");
$fieldsarray["{SURVEYURL}"] = Yii::app()->getController()->createAbsoluteUrl("/survey/index/sid/{$iSurveyID}/token/{$aTokenRow['token']}/lang/" . trim($aTokenRow['language']) . "/");

if($bHtml)
{
foreach(array('OPTOUT', 'OPTIN', 'SURVEY') as $key)
Expand All @@ -161,12 +189,12 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
}
}
}

//mail headers
$customheaders = array('1' => "X-surveyid: " . $iSurveyID,'2' => "X-tokenid: " . $fieldsarray["{TOKEN}"]);

global $maildebug;

//choose appriopriate email message
if($sType == 'invite')
{
Expand All @@ -178,7 +206,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
$sSubject = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_remind_subj'];
$sMessage = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_remind'];
}

$modsubject = Replacefields($sSubject, $fieldsarray);
$modmessage = Replacefields($sMessage, $fieldsarray);

Expand All @@ -188,45 +216,45 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
$modmessage = str_replace("@@SURVEYURL@@", $barebone_link, $modmessage);
}




if (isset($aTokenRow['validfrom']) && trim($aTokenRow['validfrom']) != '' && convertDateTimeFormat($aTokenRow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1)
{
$aResult[$aTokenRow['tid']] = array('name'=>$fieldsarray["{FIRSTNAME}"]." ".$fieldsarray["{LASTNAME}"],
'email'=>$fieldsarray["{EMAIL}"],
'status'=>'fail',
'error'=>'Token not valid yet');

}
elseif (isset($aTokenRow['validuntil']) && trim($aTokenRow['validuntil']) != '' && convertDateTimeFormat($aTokenRow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1)
{
$aResult[$aTokenRow['tid']] = array('name'=>$fieldsarray["{FIRSTNAME}"]." ".$fieldsarray["{LASTNAME}"],
'email'=>$fieldsarray["{EMAIL}"],
'status'=>'fail',
'error'=>'Token not valid anymore');
'error'=>'Token not valid anymore');

}
else
{
{
if (SendEmailMessage($modmessage, $modsubject, $to, $from, Yii::app()->getConfig("sitename"), $bHtml, getBounceEmail($iSurveyID), null, $customheaders))
{
$aResult[$aTokenRow['tid']] = array('name'=>$fieldsarray["{FIRSTNAME}"]." ".$fieldsarray["{LASTNAME}"],
'email'=>$fieldsarray["{EMAIL}"],
'status'=>'OK');

if($sType == 'invite')
$oTokens->updateByPk($aTokenRow['tid'], array('sent' => dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"))));
if($sType == 'remind')

if($sType == 'remind')
{
$iRCount = $oTokens->findByPk($aTokenRow['tid'])->remindercount +1;
$oTokens->updateByPk($aTokenRow['tid'], array('remindersent' => dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"))));
$oTokens->updateByPk($aTokenRow['tid'],array('remindercount' => $iRCount));
}

}
else
else
{

$aResult[$aTokenRow['tid']] = array('name'=>$fieldsarray["{FIRSTNAME}"]." ".$fieldsarray["{LASTNAME}"],
Expand All @@ -235,7 +263,7 @@ function emailTokens($iSurveyID,$aResultTokens,$sType)
'error'=>$maildebug);
}
}

unset($fieldsarray);
}

Expand Down
Loading

0 comments on commit 1e883c5

Please sign in to comment.