From 49f274396584268e23d03b4fbde42fd9a1f1e5c1 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Mon, 14 Apr 2014 14:54:05 +0200 Subject: [PATCH] New feature #08351: Public registration page resending of already registered user's login details Dev: adding beforeRegister event and beforeRegisterForm event Dev: use beforeTokenEmail / type:register --- .../controllers/RegisterController.php | 493 +++++++++++------- application/helpers/frontend_helper.php | 28 +- application/helpers/replacements_helper.php | 87 ---- application/views/register/display.php | 7 + application/views/register/registerForm.php | 42 ++ 5 files changed, 366 insertions(+), 291 deletions(-) create mode 100644 application/views/register/display.php create mode 100644 application/views/register/registerForm.php diff --git a/application/controllers/RegisterController.php b/application/controllers/RegisterController.php index 1867bfcc6c0..ddfdf4fb139 100644 --- a/application/controllers/RegisterController.php +++ b/application/controllers/RegisterController.php @@ -21,243 +21,356 @@ */ class RegisterController extends LSYii_Controller { + public $layout = 'bare'; + function actionAJAXRegisterForm($surveyid) { Yii::app()->loadHelper('database'); Yii::app()->loadHelper('replacements'); $redata = compact(array_keys(get_defined_vars())); - $iSurveyID = sanitize_int($surveyid); - $oSurvey = Survey::model()->find('sid=:sid',array(':sid' => $iSurveyID)) or show_error("Can't find survey data"); + $iSurveyId = $surveyid; + $oSurvey = Survey::model()->find('sid=:sid',array(':sid' => $iSurveyId)); + if (!$oSurvey){ + throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect."); + } + // Don't test if survey allow registering ..... + $sLanguage = Yii::app()->request->getParam('lang',$oSurvey->language); + Yii::import('application.libraries.Limesurvey_lang'); + Yii::app()->lang = new Limesurvey_lang($sLanguage); + $thistpl=getTemplatePath(validateTemplateDir($oSurvey->template)); - $data['sid'] = $iSurveyID; + $data['sid'] = $iSurveyId; $data['startdate'] = $oSurvey->startdate; $data['enddate'] = $oSurvey->expires; - $data['thissurvey'] = getSurveyInfo($iSurveyID , $oSurvey->language); - Yii::import('application.libraries.Limesurvey_lang'); - Yii::app()->lang = new Limesurvey_lang($oSurvey->language); - echo templatereplace(file_get_contents("$thistpl/register.pstpl"),array(),$data,'register.php',false,NULL,$data); - unset($_SESSION['survey_'.$iSurveyID]['register_errormsg']); - + $data['thissurvey'] = getSurveyInfo($iSurveyId , $oSurvey->language); + echo self::getRegisterForm($iSurveyId); + Yii::app()->end(); } /** - * register::index() + * Default action register * Process register form data and take appropriate action + * @param $sid Survey Id to register + * @param $aRegisterErrors array of errors when try to register * @return */ - function actionIndex($iSurveyID = null) + function actionIndex($sid = null) { - Yii::app()->loadHelper('database'); - Yii::app()->loadHelper('replacements'); - $sLanguage = Yii::app()->request->getParam('lang',''); - if($iSurveyID == null) - { - $iSurveyID = Yii::app()->request->getPost('sid'); - } - if (!$iSurveyID) - { - $this->redirect(Yii::app()->baseUrl); - } - if ($sLanguage=="" ) - { - $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; - } + if(!is_null($sid)) + $iSurveyId=$sid; else - { - $sBaseLanguage = $sLanguage; - } - Yii::import('application.libraries.Limesurvey_lang'); - Yii::app()->lang = new Limesurvey_lang($sBaseLanguage); - $clang = Yii::app()->lang; - $thissurvey=getSurveyInfo($iSurveyID,$sBaseLanguage); + $iSurveyId=Yii::app()->request->getPost('sid'); + $oSurvey=Survey::model()->find("sid=:sid",array(':sid'=>$iSurveyId)); - $register_errormsg = ""; - // Check the security question's answer - if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen',$thissurvey['usecaptcha']) ) + $sLanguage = Yii::app()->request->getParam('lang'); + if (!$sLanguage) { - if (!isset($_POST['loadsecurity']) || - !isset($_SESSION['survey_'.$iSurveyID]['secanswer']) || - Yii::app()->request->getPost('loadsecurity') != $_SESSION['survey_'.$iSurveyID]['secanswer']) - { - $register_errormsg .= $clang->gT("The answer to the security question is incorrect.")."
\n"; - } + $sLanguage = Yii::app()->request->getPost('register_lang',Survey::model()->findByPk($iSurveyId)->language); } - //Check that the email is a valid style address - if (!validateEmailAddress(Yii::app()->request->getPost('register_email'))) - { - $register_errormsg .= $clang->gT("The email you used is not valid. Please try again."); - } - - // Check for additional fields - $attributeinsertdata = array(); - foreach (GetParticipantAttributes($iSurveyID) as $field => $data) - { - if (empty($data['show_register']) || $data['show_register'] != 'Y') - continue; - - $value = sanitize_xss_string(Yii::app()->request->getPost('register_' . $field)); - if (trim($value) == '' && $data['mandatory'] == 'Y') - $register_errormsg .= sprintf($clang->gT("%s cannot be left empty"), $thissurvey['attributecaptions'][$field]); - $attributeinsertdata[$field] = $value; + if (!$oSurvey){ + throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect."); + }elseif($oSurvey->allowregister!='Y' || !tableExists("{{tokens_{$iSurveyId}}}")){ + throw new CHttpException(404,"The survey in which you are trying to register don't accept registration. It may have been updated or the link you were given is outdated or incorrect."); } - if ($register_errormsg != "") - { - $_SESSION['survey_'.$iSurveyID]['register_errormsg']=$register_errormsg; - $this->redirect($this->createUrl("survey/index/sid/{$iSurveyID}",array('lang'=>$sBaseLanguage))); + elseif(!is_null($oSurvey->expires) && $oSurvey->expires < dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'))){ + $this->redirect(array('survey/index','sid'=>$iSurveyId,'lang'=>$sLanguage)); } - //Check if this email already exists in token database - $oToken=TokenDynamic::model($iSurveyID)->find('email=:email',array(':email'=>Yii::app()->request->getPost('register_email'))); - if ($oToken) - { - $register_errormsg=$clang->gT("The email you used has already been registered."); - $_SESSION['survey_'.$iSurveyID]['register_errormsg']=$register_errormsg; - $this->redirect($this->createUrl("survey/index/sid/{$iSurveyID}",array('lang'=>$sBaseLanguage))); - //include "index.php"; - //exit; - } - - $mayinsert = false; + Yii::import('application.libraries.Limesurvey_lang'); + Yii::app()->lang = new Limesurvey_lang($sLanguage); + // Test if we come from register form (and submit) + + $aSended=array('sent'=>false,'message'=>''); + // New event to replace complety register system + $event = new PluginEvent('beforeRegister'); + $event->set('surveyid', $iSurveyId); + $event->set('lang', $sLanguage); + App()->getPluginManager()->dispatchEvent($event); - // Get the survey settings for token length + $bIsSubmited=$event->get('submited',Yii::app()->request->getPost('register_email',false)); + $aSended=$event->get('aSended',array('sent'=>false,'message'=>'')); - $tokenlength = $thissurvey['tokenlength']; - //if tokenlength is not set or there are other problems use the default value (15) - if(!isset($tokenlength) || $tokenlength == '') - { - $tokenlength = 15; + if($bIsSubmited!==false){ + $aRegisterErrors=self::getRegisterErrors($iSurveyId); + if(empty($aRegisterErrors)){ + $aSended=self::sendRegistrationEmail($iSurveyId); + } + }else{ + $aRegisterErrors=null; } - while ($mayinsert != true) - { - $newtoken = randomChars($tokenlength); - $oTokenExist=TokenDynamic::model($iSurveyID)->find('token=:token',array(':token'=>$newtoken)); - if (!$oTokenExist) {$mayinsert = true;} + $aData['surveyid']=$surveyid=$iSurveyId; + $aData['thissurvey']=getSurveyInfo($iSurveyId,$sLanguage); + $sTemplate=getTemplatePath(validateTemplateDir($aData['thissurvey']['template'])); + Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger + $aData['languagechanger']=makeLanguageChangerSurvey($sLanguage); + $aData['sitename']=Yii::app()->getConfig('sitename'); + // Work only with controllers survey : did we fix it and use register url for registering ? + sendCacheHeaders(); + doHeader(); + echo templatereplace(file_get_contents("{$sTemplate}/startpage.pstpl"),array(),$aData); + echo templatereplace(file_get_contents("{$sTemplate}/survey.pstpl"),array(),$aData); + if(!$aSended['sent']){ + echo self::getRegisterForm($iSurveyId,array($aSended['message'])); + }else{ + echo templatereplace($aSended['message']); } + echo templatereplace(file_get_contents("{$sTemplate}/endpage.pstpl"),array(),$aData); + doFooter(); +# $aViewData['sTemplate']=$sTemplate; +# $aViewData['aData']=$aData; +# $aViewData['content']=self::getRegisterForm($iSurveyId); +# $this->render('display',$aViewData);// Need register/display.php view + } - $postfirstname=sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_firstname'))); - $postlastname=sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_lastname'))); - $starttime = sanitize_xss_string(Yii::app()->request->getPost('startdate')); - $endtime = sanitize_xss_string(Yii::app()->request->getPost('enddate')); - /*$postattribute1=sanitize_xss_string(strip_tags(returnGlobal('register_attribute1'))); - $postattribute2=sanitize_xss_string(strip_tags(returnGlobal('register_attribute2'))); */ + /** + * Validate a register form + * @param $iSurveyId Survey Id to register + * @return array of errors when try to register (empty array => no error) + */ + public function getRegisterErrors($iSurveyId){ + $aRegisterErrors=array(); + $clang = Yii::app()->lang; + $aSurveyInfo=getSurveyInfo($iSurveyId,$clang->langcode); - // Insert new entry into tokens db - $oToken = Token::create($thissurvey['sid']); - $oToken->firstname = $postfirstname; - $oToken->lastname = $postlastname; - $oToken->email = Yii::app()->request->getPost('register_email'); - $oToken->emailstatus = 'OK'; - $oToken->token = $newtoken; - if ($starttime && $endtime) + // Check the security question's answer + if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen',$aSurveyInfo['usecaptcha']) ) { - $oToken->validfrom = $starttime; - $oToken->validuntil = $endtime; + $sLoadsecurity=Yii::app()->request->getPost('loadsecurity',''); + $sSecAnswer=(isset($_SESSION['survey_'.$iSurveyId]['secanswer']))?$_SESSION['survey_'.$iSurveyId]['secanswer']:""; + if ($sLoadsecurity!=$sSecAnswer) + { + $aRegisterErrors[] = $clang->gT("The answer to the security question is incorrect."); + } } - $oToken->setAttributes($attributeinsertdata, false); - $result = $oToken->save(); - //$tid = $oToken->tid;// Not needed any more - $fieldsarray["{ADMINNAME}"]=$thissurvey['adminname']; - $fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail']; - $fieldsarray["{SURVEYNAME}"]=$thissurvey['name']; - $fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description']; - $fieldsarray["{FIRSTNAME}"]=$postfirstname; - $fieldsarray["{LASTNAME}"]=$postlastname; - $fieldsarray["{EXPIRY}"]=$thissurvey["expiry"]; - $fieldsarray["{TOKEN}"]=$oToken->token; - $fieldsarray["{EMAIL}"]=$oToken->email; - $token=$oToken->token; - - - $message=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$thissurvey['email_register']); - $subject=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$thissurvey['email_register_subj']); + //Check that the email is a valid style address + $sRegisterEmail=Yii::app()->request->getPost('register_email',''); + if($sRegisterEmail==""){ + $aRegisterErrors[]= $clang->gT("You must enter a valid email. Please try again."); + }elseif (!validateEmailAddress($sRegisterEmail)){ + $aRegisterErrors[]= $clang->gT("The email you used is not valid. Please try again."); + } + //Check and validate attribute + $aRegisterAttributes=$aSurveyInfo['attributedescriptions']; + foreach ($aSurveyInfo['attributedescriptions'] as $key => $aAttribute) + { + if ($aAttribute['show_register'] == 'Y' && $aAttribute['mandatory'] == 'Y') + { + $sRegisterAttribute=Yii::app()->request->getPost('register_'.$key); + if(empty($sRegisterAttribute)){ + $sAttributeCaption=($aSurveyInfo['attributecaptions'][$key]?$aSurveyInfo['attributecaptions'][$key] : ($aAttribute['description']?$aAttribute['description'] : $key)); + $aRegisterErrors[]= sprintf($clang->gT("%s cannot be left empty").".", $sAttributeCaption); + } + } + } + return $aRegisterErrors; + } - $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>"; + public function getRegisterForm($iSurveyId,$aRegisterErrors = null){ + $clang = Yii::app()->lang; + $aSurveyInfo=getSurveyInfo($iSurveyId,$clang->langcode); + $sTemplate=getTemplatePath(validateTemplateDir($aSurveyInfo['template'])); - $surveylink = $this->createAbsoluteUrl("/survey/index/sid/{$iSurveyID}",array('lang'=>$sBaseLanguage,'token'=>$newtoken)); - $optoutlink = $this->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyID}",array('langcode'=>$sBaseLanguage,'token'=>$newtoken)); - $optinlink = $this->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyID}",array('langcode'=>$sBaseLanguage,'token'=>$newtoken)); - if (getEmailFormat($iSurveyID) == 'html') - { - $useHtmlEmail = true; - $fieldsarray["{SURVEYURL}"]="".$surveylink.""; - $fieldsarray["{OPTOUTURL}"]="".$optoutlink.""; - $fieldsarray["{OPTINURL}"]="".$optinlink.""; + // Event to replace register form + $event = new PluginEvent('beforeRegisterForm'); + $event->set('surveyid', $iSurveyId); + $event->set('lang', $clang->langcode); + $event->set('aRegistersErrors', $aRegisterErrors); + App()->getPluginManager()->dispatchEvent($event); + if(!is_null($event->get('registerForm'))) + return $event->get('registerForm'); + // Allways keep the value + $sFirstName=Yii::app()->request->getPost('register_firstname',''); + $sLastName=Yii::app()->request->getPost('register_lastname',''); + $sEmail=Yii::app()->request->getPost('register_email',''); + $aRegisterAttributes=$aSurveyInfo['attributedescriptions']; + foreach($aRegisterAttributes as $key=>$aRegisterAttribute){ + if($aRegisterAttribute['show_register']!='Y'){ + unset($aRegisterAttributes[$key]); + }else{ + $aRegisterAttributes[$key]['caption']=($aSurveyInfo['attributecaptions'][$key]?$aSurveyInfo['attributecaptions'][$key] : ($aRegisterAttribute['description']?$aRegisterAttribute['description'] : $key)); + $aRegisterAttributes[$key]['value']=Yii::app()->request->getPost("register_{$key}",''); + } } + $aData['iSurveyId'] = $iSurveyId; + $aData['sLanguage'] = $clang->langcode; + $aData['clang'] = $clang; + $aData['sFirstName'] = $sFirstName; + $aData['sLastName'] = $sLastName; + $aData['sEmail'] = $sEmail; + $aData['aExtraAttributes']=$aRegisterAttributes; + $aData['urlAction']=App()->createUrl('register/index',array('sid'=>$iSurveyId)); + $aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha']); + $aReplacement['REGISTERFORM']=$this->renderPartial('registerForm',$aData,true); + if(is_array($aRegisterErrors)) + $sRegisterError=implode('
',$aRegisterErrors); else - { - $useHtmlEmail = false; - $fieldsarray["{SURVEYURL}"]= $surveylink; - $fieldsarray["{OPTOUTURL}"]= $optoutlink; - $fieldsarray["{OPTINURL}"]= $optinlink; - } - - $message=ReplaceFields($message, $fieldsarray); - $subject=ReplaceFields($subject, $fieldsarray); + $sRegisterError=''; + $aReplacement['REGISTERERROR'] = $sRegisterError; + $aReplacement['REGISTERMESSAGE1'] = $clang->gT("You must be registered to complete this survey"); + $aReplacement['REGISTERMESSAGE2'] = $clang->gT("You may register for this survey if you wish to take part.")."
\n".$clang->gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately."); + $aData['thissurvey'] = $aSurveyInfo; + Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger + $aData['languagechanger'] = makeLanguageChangerSurvey($clang->langcode); + return templatereplace(file_get_contents("$sTemplate/register.pstpl"),$aReplacement,$aData); + } - $html = ""; //Set variable - $sitename = Yii::app()->getConfig('sitename'); + /** + * Send the register email with $_POST value + * @param $iSurveyId Survey Id to register + * @return array sent: boolean, message :the message to be shown + */ + public function sendRegistrationEmail($iSurveyId){ + + $clang = Yii::app()->lang; + $aSurveyInfo=getSurveyInfo($iSurveyId,$clang->langcode); + $sLanguage=$clang->langcode; - if (SendEmailMessage($message, $subject, Yii::app()->request->getPost('register_email'), $from, $sitename,$useHtmlEmail,getBounceEmail($iSurveyID))) - { - // TLR change to put date into sent - $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust')); - $oToken->sent=$today; - $oToken->save(); - $html="
" - . "

".$clang->gT("Thank you for registering to participate in this survey.")."

\n" - . "

".$clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed.")."

\n" - . "

".$clang->gT("Survey administrator")." {ADMINNAME} ({ADMINEMAIL})

" - . "
\n"; - $html=ReplaceFields($html, $fieldsarray); - } - else - { - $html="Email Error"; + // Fill needed information + $sFirstName=sanitize_xss_string(Yii::app()->request->getPost('register_firstname','')); + $sLastName=sanitize_xss_string(Yii::app()->request->getPost('register_lastname','')); + $sEmail=trim(Yii::app()->request->getPost('register_email','')); + $aRegisterAttributes=$aSurveyInfo['attributedescriptions']; + $aAttribute=array(); + foreach($aRegisterAttributes as $key=>$aRegisterAttribute){ + if($aRegisterAttribute['show_register']=='Y'){ + $aAttribute[$key]= sanitize_xss_string(Yii::app()->request->getPost('register_'.$key,'')); + } } - //PRINT COMPLETED PAGE - if (!$thissurvey['template']) - { - $thistpl=getTemplatePath(validateTemplateDir('default')); + // Now construct the text returned + $sMessage=$sMailSuccess=$sMailError=""; + $oToken=TokenDynamic::model($iSurveyId)->find('email=:email',array(':email'=>$sEmail)); + if ($oToken) + { + if($oToken->usesleft<1 && $aSurveyInfo['alloweditaftercompletion']!='Y') + { + $sMailError=$clang->gt("The mail address you have entered is already registered an the survey has been completed."); + } + elseif(strtolower(substr(trim($oToken->emailstatus),0,6))==="optout")// And global blacklisting ? + { + $sMailError=$clang->gt("This email address is already registered but someone ask to not receive new email again."); + } + elseif(!$oToken->emailstatus && $oToken->emailstatus!="OK") + { + $sMailError=$clang->gt("This email address is already registered but the email adress was bounced."); + } + else + { + $iTokenId=$oToken->tid; + $sMailSuccess=$clang->gt("The address you have entered is already registered. An email has been sent to this address with a link that gives you access to the survey."); + } } else { - $thistpl=getTemplatePath(validateTemplateDir($thissurvey['template'])); + $oToken= Token::create($iSurveyId); + $oToken->firstname = $sFirstName; + $oToken->lastname = $sLastName; + $oToken->email = $sEmail; + $oToken->emailstatus = 'OK'; + $oToken->language = $sLanguage; + $oToken->setAttributes($aAttribute); + if ($aSurveyInfo['startdate']) + { + $oToken->validfrom = $aSurveyInfo['startdate']; + } + if ($aSurveyInfo['expires']) + { + $oToken->validuntil = $aSurveyInfo['expires']; + } + $oToken->save(); + $iTokenId=$oToken->tid; + TokenDynamic::model($iSurveyId)->createToken($iTokenId);// Review if really create a token + $sMailSuccess=$clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed."); } - - // Same fix than http://bugs.limesurvey.org/view.php?id=8441 - ob_start(function($buffer, $phase) { - App()->getClientScript()->render($buffer); - App()->getClientScript()->reset(); - return $buffer; - }); - ob_implicit_flush(false); - sendCacheHeaders(); - doHeader(); - Yii::app()->lang = $clang; - // fetch the defined variables and pass it to the header footer templates. - $redata = compact(array_keys(get_defined_vars())); - $this->_printTemplateContent($thistpl.'/startpage.pstpl', $redata, __LINE__); - $this->_printTemplateContent($thistpl.'/survey.pstpl', $redata, __LINE__); - echo $html; - $this->_printTemplateContent($thistpl.'/endpage.pstpl', $redata, __LINE__); - doFooter(); - ob_flush(); - } - - /** - * function will parse the templates data - * @return displays the requested template - */ - function _printTemplateContent($sTemplateFile, &$redata, $iDebugLine = -1) - { - echo templatereplace(file_get_contents($sTemplateFile),array(),$redata,'survey['.$iDebugLine.']'); + // Now we have a existing token and we can send email (based on sMailSucces) + if($sMailSuccess && $iTokenId){ + $aMail['subject']=$aSurveyInfo['email_register_subj']; + $aMail['message']=$aSurveyInfo['email_register']; + $aReplacementFields=array(); + $aReplacementFields["{ADMINNAME}"]=$aSurveyInfo['adminname']; + $aReplacementFields["{ADMINEMAIL}"]=$aSurveyInfo['adminemail']; + $aReplacementFields["{SURVEYNAME}"]=$aSurveyInfo['name']; + $aReplacementFields["{SURVEYDESCRIPTION}"]=$aSurveyInfo['description']; + $aReplacementFields["{EXPIRY}"]=$aSurveyInfo["expiry"]; + $oToken=TokenDynamic::model($iSurveyId)->findByPk($iTokenId); + foreach($oToken->attributes as $attribute=>$value){ + $aReplacementFields["{".strtoupper($attribute)."}"]=$value; + } + $sToken=$oToken->token; + $aMail['subject']=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$aMail['subject']); + $aMail['message']=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$aMail['message']); + $surveylink = App()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}",array('lang'=>$sLanguage,'token'=>$sToken)); + $optoutlink = App()->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyId}",array('langcode'=>$sLanguage,'token'=>$sToken)); + $optinlink = App()->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyId}",array('langcode'=>$sLanguage,'token'=>$sToken)); + if (getEmailFormat($iSurveyId) == 'html') + { + $useHtmlEmail = true; + $aReplacementFields["{SURVEYURL}"]="".$surveylink.""; + $aReplacementFields["{OPTOUTURL}"]="".$optoutlink.""; + $aReplacementFields["{OPTINURL}"]="".$optinlink.""; + } + else + { + $useHtmlEmail = false; + $aReplacementFields["{SURVEYURL}"]= $surveylink; + $aReplacementFields["{OPTOUTURL}"]= $optoutlink; + $aReplacementFields["{OPTINURL}"]= $optinlink; + } + // Allow barebone link for all URL + $aMail['message'] = str_replace("@@SURVEYURL@@", $surveylink, $aMail['message']); + $aMail['message'] = str_replace("@@OPTOUTURL@@", $optoutlink, $aMail['message']); + $aMail['message'] = str_replace("@@OPTINURL@@", $optinlink, $aMail['message']); + // Replace the fields + $aMail['subject']=ReplaceFields($aMail['subject'], $aReplacementFields); + $aMail['message']=ReplaceFields($aMail['message'], $aReplacementFields); + $sFrom = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>"; + $sBounce=getBounceEmail($iSurveyId); + $sTo=$oToken->email; + $sitename = Yii::app()->getConfig('sitename'); + // Plugin event for email handling (Same than admin token but with register type) + $event = new PluginEvent('beforeTokenEmail'); + $event->set('type', 'register'); + $event->set('subject', $aMail['subject']); + $event->set('to', $sTo); + $event->set('body', $aMail['message']); + $event->set('from', $sFrom); + $event->set('bounce',$sBounce ); + $event->set('token', $oToken->attributes); + $aMail['subject'] = $event->get('subject'); + $aMail['message'] = $event->get('body'); + $sTo = $event->get('to'); + $sFrom = $event->get('from'); + if ($event->get('send', true) == false) + { + $sMessage=$event->get('message', ''); + } + elseif (SendEmailMessage($aMail['message'], $aMail['subject'], $sTo, $sFrom, $sitename,$useHtmlEmail,$sBounce)) + { + // TLR change to put date into sent + $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust')); + $oToken->sent=$today; + $oToken->save(); + $sMessage="
" + . "

".$clang->gT("Thank you for registering to participate in this survey.")."

\n" + . "

{$sMailSuccess}

\n" + . "

".sprintf($clang->gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail'])."

" + . "
\n"; + } + else + { + $sMessage="
" + . "

".$clang->gT("Thank you for registering to participate in this survey.")."

\n" + . "

".$clang->gT("You are registred but an error happen when trying to send the email, please contact the survey administrator.")."

\n" + . "

".sprintf($clang->gT("Survey administrator %s (%s)"),$aSurveyInfo['adminname'],$aSurveyInfo['adminemail'])."

" + . "
\n"; + } + } + return array('sent'=>!empty($sMailSuccess),'message'=>$sMessage.$sMailError); } - } diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index 7ecf919e3ae..468e2a00b3f 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -939,19 +939,20 @@ function buildsurveysession($surveyid,$preview=false) // DISPLAY REGISTER-PAGE if needed // DISPLAY CAPTCHA if needed - sendCacheHeaders(); - doHeader(); - - $redata = compact(array_keys(get_defined_vars())); - echo templatereplace(file_get_contents($sTemplatePath."startpage.pstpl"),array(),$redata,'frontend_helper[1594]'); - //echo makedropdownlist(); - echo templatereplace(file_get_contents($sTemplatePath."survey.pstpl"),array(),$redata,'frontend_helper[1596]'); - if (isset($thissurvey) && $thissurvey['allowregister'] == "Y") - { - echo templatereplace(file_get_contents($sTemplatePath."register.pstpl"),array(),$redata,'frontend_helper[1599]'); + if (isset($thissurvey) && $thissurvey['allowregister'] == "Y") + { + // Add the event and test if done + Yii::app()->runController("register/index/sid/{$surveyid}"); + Yii::app()->end(); } else { + sendCacheHeaders(); + doHeader(); + $redata = compact(array_keys(get_defined_vars())); + echo templatereplace(file_get_contents($sTemplatePath."startpage.pstpl"),array(),$redata,'frontend_helper[1594]'); + //echo makedropdownlist(); + echo templatereplace(file_get_contents($sTemplatePath."survey.pstpl"),array(),$redata,'frontend_helper[1596]'); // ->renderPartial('entertoken_view'); if (isset($secerror)) echo "".$secerror."
"; echo '

'.$clang->gT("This is a controlled survey. You need a valid token to participate.")."
"; @@ -993,11 +994,10 @@ function buildsurveysession($surveyid,$preview=false)

"; + echo templatereplace(file_get_contents($sTemplatePath."endpage.pstpl"),array(),$redata,'frontend_helper[1645]'); + doFooter(); + exit; } - - echo templatereplace(file_get_contents($sTemplatePath."endpage.pstpl"),array(),$redata,'frontend_helper[1645]'); - doFooter(); - exit; } // TOKENS REQUIRED, A TOKEN PROVIDED // SURVEY WITH NO NEED TO USE CAPTCHA diff --git a/application/helpers/replacements_helper.php b/application/helpers/replacements_helper.php index e9dff83ae84..5e1d91292ae 100644 --- a/application/helpers/replacements_helper.php +++ b/application/helpers/replacements_helper.php @@ -524,84 +524,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de } $_loadform .="\n"; - // Registration Form - if (isset($surveyid) || (isset($registerdata) && $debugSrc == 'register.php')) - { - if (isset($surveyid)) - $tokensid = $surveyid; - else - $tokensid = $registerdata['sid']; - - $_registerform = CHtml::form(array("/register/index/surveyid/{$tokensid}"), 'post'); - - if (!isset($_REQUEST['lang'])) - { - $_reglang = Survey::model()->findByPk($tokensid)->language; - } - else - { - $_reglang = returnGlobal('lang'); - } - - $_registerform .= "\n\n"; - $_registerform .= "\n"; - - $_registerform.="\n" - . "" - . "\n" - . "\n" - . " - - - '; - } - if ((count($registerdata) > 1 || isset($thissurvey['usecaptcha'])) && function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $thissurvey['usecaptcha'])) - { - $_registerform .="\n"; - } - $_registerform .= "\n" - . "
::: $attribute) - { - if (empty($attribute['show_register']) || $attribute['show_register'] != 'Y') - continue; - - $_registerform .= ' -
:
:
" - . "
\n"; - - if (count($registerdata) > 1 && $registerdata['sid'] != NULL && $debugSrc == 'register.php') - { - $_registerform .= ""; - $_registerform .= ""; - } - - - $_registerform .= "\n"; - } - else - { - $_registerform = ""; - } - // Assessments $assessmenthtml=""; if (isset($surveyid) && !is_null($surveyid) && function_exists('doAssessment')) @@ -693,11 +615,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de { $_endtext = $thissurvey['surveyls_endtext']; } - if (isset($surveyid) && isset($_SESSION['survey_'.$surveyid]) && isset($_SESSION['survey_'.$surveyid]['register_errormsg'])) - { - $register_errormsg=$_SESSION['survey_'.$surveyid]['register_errormsg']; - } - // Set the array of replacement variables here - don't include curly braces $coreReplacements = array(); @@ -748,10 +665,6 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de $coreReplacements['QUESTION_NUMBER'] = $_question_number; $coreReplacements['QUESTION_TEXT'] = $_question_text; $coreReplacements['QUESTION_VALID_MESSAGE'] = $_question_valid_message; - $coreReplacements['REGISTERERROR'] = isset($register_errormsg) ? $register_errormsg : ''; // global - $coreReplacements['REGISTERFORM'] = $_registerform; - $coreReplacements['REGISTERMESSAGE1'] = $clang->gT("You must be registered to complete this survey"); - $coreReplacements['REGISTERMESSAGE2'] = $clang->gT("You may register for this survey if you wish to take part.")."
\n".$clang->gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately."); $coreReplacements['RESTART'] = $_restart; $coreReplacements['RETURNTOSURVEY'] = $_return_to_survey; $coreReplacements['SAVE'] = $_saveall; diff --git a/application/views/register/display.php b/application/views/register/display.php new file mode 100644 index 00000000000..df040fd269e --- /dev/null +++ b/application/views/register/display.php @@ -0,0 +1,7 @@ + diff --git a/application/views/register/registerForm.php b/application/views/register/registerForm.php new file mode 100644 index 00000000000..4722ae27799 --- /dev/null +++ b/application/views/register/registerForm.php @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + $aExtraAttribute){ ?> + + + + + + + + + + + + + +
+ 'register_firstname','class'=>'text')); ?> +
+ 'register_lastname','class'=>'text')); ?> +
+ "register_{$key}",'class'=>'text')); ?> +
+ 'loadsecurity','class'=>'text','size'=>'5','maxlength'=>'3')); ?> +
gT("Continue"),array('class'=>'button submit','id'=>'register')); ?>
+