diff --git a/application/controllers/RegisterController.php b/application/controllers/RegisterController.php index f45f473766b..0d0d245fd1c 100644 --- a/application/controllers/RegisterController.php +++ b/application/controllers/RegisterController.php @@ -73,7 +73,7 @@ public function actionAJAXRegisterForm($surveyid) $data['startdate'] = $oSurvey->startdate; $data['enddate'] = $oSurvey->expires; $data['thissurvey'] = getSurveyInfo($iSurveyId , $oSurvey->language); - echo self::getRegisterForm($iSurveyId); + echo self::ajaxGetRegisterForm($iSurveyId); Yii::app()->end(); } @@ -177,7 +177,7 @@ public function getRegisterErrors($iSurveyId){ public function getRegisterForm($iSurveyId) { - $aSurveyInfo=getSurveyInfo($iSurveyId,App()->language); + $oSurvey=Survey::model()->findByPk($iSurveyId); // Event to replace register form $event = new PluginEvent('beforeRegisterForm'); @@ -195,6 +195,7 @@ public function getRegisterForm($iSurveyId) } $aFieldValue=$this->getFieldValue($iSurveyId); $aRegisterAttributes=$this->getExtraAttributeInfo($iSurveyId); + $aData['iSurveyId'] = $iSurveyId; $aData['sLanguage'] = App()->language; $aData['sFirstName'] = $aFieldValue['sFirstName']; @@ -202,29 +203,28 @@ public function getRegisterForm($iSurveyId) $aData['sEmail'] = $aFieldValue['sEmail']; $aData['aAttribute'] = $aFieldValue['aAttribute']; $aData['aExtraAttributes']=$aRegisterAttributes; - $aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha']); - $aReplacement['REGISTERFORM'] = CHtml::form(App()->createUrl('register/index',array('sid'=>$iSurveyId)),'post',array('id'=>'limesurvey', 'role' => 'form', 'class' => 'ls-form')); - $aReplacement['REGISTERFORM'].= $this->renderPartial('/survey/frontpage/registerForm/form',$aData,true); - $aReplacement['REGISTERFORM'].= CHtml::endForm(); + $aData['bCaptcha'] = function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $oSurvey->usecaptcha); + $aData['sRegisterFormUrl'] = App()->createUrl('register/index',array('sid'=>$iSurveyId)); + + $aData['formAdditions'] = 'Blablablabla'; if(!empty($registerFormEvent)){ - $aReplacement['REGISTERFORM'].= $registerFormEvent['formAppend']; + $aData['formAdditions'] = $registerFormEvent['formAppend']; } if(is_array($this->aRegisterErrors)) { - $aReplacement['REGISTERERROR']=$this->renderPartial("/survey/frontpage/registerForm/error",array('aErrors'=>$this->aRegisterErrors),true); + $aData['aErrors'] = $this->aRegisterErrors; } else { - $aReplacement['REGISTERERROR']=''; + $aData['aErrors'] = array(); } - $aReplacement['REGISTERMESSAGE1']=$this->renderPartial("/survey/frontpage/registerForm/heading",array(),true); - $aReplacement['REGISTERMESSAGE2']=$this->renderPartial("/survey/frontpage/registerForm/message",array('sStartDate'=>$this->getStartDate($iSurveyId)),true); - $aData['thissurvey'] = $aSurveyInfo; - Yii::app()->setConfig('surveyID',$iSurveyId);//Needed for languagechanger - // $aData['languagechanger'] = frontend_helper::makeLanguageChangerSurvey(App()->language); - $oTemplate = Template::model()->getInstance(null, $iSurveyId); - return templatereplace(file_get_contents($oTemplate->pstplPath . "/register.pstpl"),$aReplacement,$aData); + + $aData['sStartDate'] = $this->getStartDate($iSurveyId ,true); + + $aData['thissurvey'] = $oSurvey->attributes; + + return $aData; } /** @@ -476,38 +476,39 @@ private function display($iSurveyId) $this->aReplacementData['sMessage']=$this->sMessage; $oTemplate = Template::model()->getInstance('', $iSurveyId); - Yii::app()->clientScript->registerPackage( 'survey-template' ); - - $this->sTemplate=$oTemplate->sTemplateName; - if(!$this->sMessage){ - // $this->aGlobalData['languagechanger']=frontend_helper::makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission - $this->aReplacementData['content']=self::getRegisterForm($iSurveyId); - }else{ - // Must use message.pstpl - $this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->pstplPath . "/message.pstpl"), - array( - 'MESSAGEID'=>'register-message', - 'ERROR'=>'', - 'MESSAGE'=>$this->sMessage, - ) - ,$this->aGlobalData - ); - - } - // Test if we come from index or from register - if(empty(App()->clientScript->scripts)){ - /* This surely can be moved to layout , but remove iot from surveyController before */ - $oTemplate = Template::model()->getInstance('', $iSurveyId); - Yii::app()->clientScript->registerPackage( 'survey-template' ); - App()->getClientScript()->registerPackage('jqueryui'); - App()->getClientScript()->registerPackage('jquery-touch-punch'); - App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js"); - useFirebug(); - $this->layout='survey'; - $this->render('/survey/system/display',$this->aReplacementData); - }else{ - // Survey/index need renderPartial - echo $this->render('/survey/system/display',$this->aReplacementData, true, true); - } + //Yii::app()->clientScript->registerPackage( 'survey-template' ); + + // $this->sTemplate=$oTemplate->sTemplateName; + // if(!$this->sMessage){ + // // $this->aGlobalData['languagechanger']=frontend_helper::makeLanguageChangerSurvey($sLanguage); // Only show language changer shown the form is shown, not after submission + // }else{ + // // Must use message.pstpl + // $this->aReplacementData['content']=templatereplace(file_get_contents($oTemplate->pstplPath . "/message.pstpl"), + // array( + // 'MESSAGEID'=>'register-message', + // 'ERROR'=>'', + // 'MESSAGE'=>$this->sMessage, + // ) + // ,$this->aGlobalData + // ); + + // } + + $aData['aSurveyInfo'] = self::getRegisterForm($iSurveyId); + Yii::app()->twigRenderer->renderTemplateFromFile('layout_register.twig',$aData, false); + + // // Test if we come from index or from register + // if(empty(App()->clientScript->scripts)){ + // /* This surely can be moved to layout , but remove iot from surveyController before */ + // $oTemplate = Template::model()->getInstance('', $iSurveyId); + // Yii::app()->clientScript->registerPackage( 'survey-template' ); + // App()->getClientScript()->registerPackage('jqueryui'); + // App()->getClientScript()->registerPackage('jquery-touch-punch'); + // App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts')."survey_runtime.js"); + + // }else{ + // // Survey/index need renderPartial + // Yii::app()->twigRenderer->renderTemplateFromFile('layout_register.twig',$aData, false); + // } } } diff --git a/application/core/plugins/SocialMediaRegistration b/application/core/plugins/SocialMediaRegistration new file mode 160000 index 00000000000..1ed34fb874a --- /dev/null +++ b/application/core/plugins/SocialMediaRegistration @@ -0,0 +1 @@ +Subproject commit 1ed34fb874a3f5d4ff7eaae7b67dd1d60c8738b9 diff --git a/application/models/Surveymenu.php b/application/models/Surveymenu.php index e9f2b85705a..197a1ffa9e6 100644 --- a/application/models/Surveymenu.php +++ b/application/models/Surveymenu.php @@ -63,6 +63,25 @@ public function relations() ); } + + public static function staticAddMenu($menuArray) + { + $oSurveymenu = new Surveymenu(); + $oSurveymenu->parent_id = $menuArray['parent_id']; + $oSurveymenu->title = $menuArray['title']; + $oSurveymenu->position = $menuArray['position']; + $oSurveymenu->description = $menuArray['description']; + + $oSurveymenu->changed_at = date('Y-m-d H:i:s'); + $oSurveymenu->changed_by = Yii::app()->user->getId(); + $oSurveymenu->created_at = date('Y-m-d H:i:s'); + $oSurveymenu->created_by = Yii::app()->user->getId(); + + $oSurveymenu->save(); + return $oSurveymenu->getPrimaryKey(); + } + + public function getMenuIdOptions (){ $oSurveymenus = Surveymenu::model()->findAll(); $options = [ diff --git a/application/models/SurveymenuEntries.php b/application/models/SurveymenuEntries.php index 5cdf52d2bfa..fd40dcc65f9 100644 --- a/application/models/SurveymenuEntries.php +++ b/application/models/SurveymenuEntries.php @@ -73,6 +73,39 @@ public function relations() ); } + public static function staticAddMenuEntry($menuEntryArray) + { + $oSurveymenuEntries = new SurveymenuEntries(); + + + $oSurveymenuEntries->name = $menuEntryArray['name']; + $oSurveymenuEntries->title = $menuEntryArray['title']; + $oSurveymenuEntries->menu_title = $menuEntryArray['menu_title']; + $oSurveymenuEntries->menu_description = $menuEntryArray['menu_description']; + $oSurveymenuEntries->menu_icon = $menuEntryArray['menu_icon']; + $oSurveymenuEntries->menu_icon_type = $menuEntryArray['menu_icon_type']; + $oSurveymenuEntries->menu_link = $menuEntryArray['menu_link']; + + //set data + $oMenuEntryData = new SurveymenuEntryData(); + $oMenuEntryData->linkExternal = $menuEntryArray['linkExternal']; + $oMenuEntryData->isActive = $menuEntryArray['hideOnSurveyState'] == 'active' ? true : ($menuEntryArray['hideOnSurveyState'] == 'inactive' ? false : null); + + if($menuEntryArray['manualParams'] != '') + $oMenuEntryData->linkData = json_parse($menuEntryArray['manualParams']); + + $oSurveymenuEntries->data = $oMenuEntryData->createOptionJson($menuEntryArray['addSurveyId'], $menuEntryArray['addQuestionGroupId'], $menuEntryArray['addQuestionId']); + + $oSurveymenuEntries->changed_at = date('Y-m-d H:i:s'); + $oSurveymenuEntries->changed_by = Yii::app()->user->getId(); + $oSurveymenuEntries->created_at = date('Y-m-d H:i:s'); + $oSurveymenuEntries->created_by = Yii::app()->user->getId(); + + $oSurveymenuEntries->save(); + return $oSurveymenuEntries->getPrimaryKey(); + } + + public static function reorderMenu($menuId){ $criteriaItems = new CDbCriteria(); $criteriaItems->addCondition(['menu_id = :menu_id']); diff --git a/application/models/SurveymenuEntryData.php b/application/models/SurveymenuEntryData.php index b4b268697fb..0eaa377dc26 100644 --- a/application/models/SurveymenuEntryData.php +++ b/application/models/SurveymenuEntryData.php @@ -26,6 +26,33 @@ public function apply($menuEntry, $surveyid){ } $this->_parseLink(); } + + public function createOptionJson($addSurveyID=false, $addQuestionGroupId=false, $addQuestionId=false){ + + $dataArray = array(); + if($addSurveyID) + $dataArray['surveyid'] = ['survey', 'sid']; + if($addQuestionGroupId) + $dataArray['gid'] = ['questiongroup', 'gid']; + if($addQuestionId) + $dataArray['qid'] = ['question', 'qid']; + + + $baseArray = array( + 'link' => array( + 'external' => $this->linkExternal, + 'pjaxed' => $this->pjaxed, + 'data' => $dataArray + ) + ); + + if($this->isActive === true || $this->isActive === false) + $baseArray['isActive'] = $this->isActive; + + $baseArray = array_merge($baseArray, $this->linkData); + + return json_encode(array('render' => $baseArray)); + } public function linkCreator(){ $returnLink = Yii::app()->getController()->createUrl($this->link, $this->linkData); @@ -47,6 +74,7 @@ private function _parseDataAttribute(){ } } + private function _parseLink(){ if(empty($this->menuEntry->menu_link)){ @@ -105,4 +133,4 @@ private function _getValueForLinkData($getDataPair) } -?> \ No newline at end of file +?> diff --git a/application/models/Template.php b/application/models/Template.php index 1c6c888f2d9..eca03c82415 100644 --- a/application/models/Template.php +++ b/application/models/Template.php @@ -216,7 +216,6 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId= if (!is_a($oTemplateConfigurationModel, 'TemplateConfiguration')){ $sTemplateName = SurveysGroups::model()->findByPk($iSurveyGroupId)->template; $oTemplateConfigurationModel = TemplateConfiguration::model()->find('templates_name=:templates_name AND sid IS NULL AND gsid IS NULL', array(':templates_name'=>$sTemplateName)); - $oTemplateConfigurationModel->setToInherit(); } } @@ -242,6 +241,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId= $oTemplateConfigurationModel->isNewRecord = true; $oTemplateConfigurationModel->gsid = $iSurveyGroupId; $oTemplateConfigurationModel->setToInherit(); + $oTemplateConfigurationModel->setThisTemplate(); $oTemplateConfigurationModel->save(); return $oTemplateConfigurationModel; } @@ -252,6 +252,7 @@ public static function getTemplateConfiguration($sTemplateName=null, $iSurveyId= $oTemplateConfigurationModel->isNewRecord = true; $oTemplateConfigurationModel->sid = $iSurveyId; $oTemplateConfigurationModel->setToInherit(); + $oTemplateConfigurationModel->setThisTemplate(); $oTemplateConfigurationModel->save(); return $oTemplateConfigurationModel; } diff --git a/templates/default/scripts/template.js b/templates/default/scripts/template.js index 5ac4dcf793b..d8cb1d914b1 100644 --- a/templates/default/scripts/template.js +++ b/templates/default/scripts/template.js @@ -73,7 +73,7 @@ $(document).on('ready pjax:complete',function() } $(function () { - $('[data-toggle="tooltip"]').tooltip() + //$('[data-toggle="tooltip"]').tooltip() }) }); /** diff --git a/templates/default/views/layout_register.twig b/templates/default/views/layout_register.twig new file mode 100644 index 00000000000..558aaec3b04 --- /dev/null +++ b/templates/default/views/layout_register.twig @@ -0,0 +1,29 @@ +{# Call the global layout #} +{% extends "./layout_global.twig" %} + +{# Replace the content block #} +{% block content %} + + {# render the layout_global content block #} + {{ parent() }} + +
+ {# This will display the script and the hidden inputs needed for Expression Manager #} + {{ aSurveyInfo.EM.ScriptsAndHiddenInputs }} + +
+
+ {{ include('./subviews/registration/register_head.twig') }} +
+ {{ include('./subviews/registration/register_message.twig') }} +
+
+
+ {{ include('./subviews/registration/register_error.twig') }} +
+ {{ include('./subviews/registration/register_form.twig') }} +
+
+ + +{% endblock %} diff --git a/templates/default/views/subviews/registration/register_error.twig b/templates/default/views/subviews/registration/register_error.twig new file mode 100644 index 00000000000..126bf6fcfc3 --- /dev/null +++ b/templates/default/views/subviews/registration/register_error.twig @@ -0,0 +1,9 @@ +{% if aSurveyInfo.errors is not empty %} + +{% endif %} diff --git a/templates/default/views/subviews/registration/register_form.twig b/templates/default/views/subviews/registration/register_form.twig new file mode 100644 index 00000000000..fd7cad6ace7 --- /dev/null +++ b/templates/default/views/subviews/registration/register_form.twig @@ -0,0 +1,65 @@ + +{{ C.Html.form(aSurveyInfo.sRegisterFormUrl,'post',({'id' : 'limesurvey', 'role' : 'form', 'class' : 'form'})) }} + + +
+
+ +
+ {{ C.Html.textField('register_firstname', aSurveyInfo.sFirstName, ({'id' : 'register_firstname','class' : 'form-control'})) }} +
+
+ +
+ +
+ {{ C.Html.textField('register_lastname', aSurveyInfo.sLastName, ({'id' : 'register_lastname', 'class' : 'form-control'})) }} +
+
+
+ +
+ {{ C.Html.textField('register_email', aSurveyInfo.sEmail, ({'id' : 'register_email','class' : 'form-control input-sm','required' : true})) }} +
+
+ {% for key, aExtraAttribute in aSurveyInfo.aExtraAttributes %} +
+ {% set registerKey = "register_" ~ key %} + +
+ {{ C.Html.textField(registerKey, aAttribute[key],({'id' : "register_{$key}",'class' : 'form-control input-sm'})) }} +
+
+ {% endfor %} + {% if aSurveyInfo.bCaptcha %} +
+ +
+
+
+ {{ renderCaptcha }} +
+ +
+
+
+ {% endif %} + + + +
+
+ {% set continue = gT("Continue",'unescaped') %} + +
+
+
+ {{ aSurveyInfo.formAdditions | raw }} +
+
+ +{{ C.Html.endForm }} diff --git a/templates/default/views/subviews/registration/register_head.twig b/templates/default/views/subviews/registration/register_head.twig new file mode 100644 index 00000000000..b38b75654c5 --- /dev/null +++ b/templates/default/views/subviews/registration/register_head.twig @@ -0,0 +1,3 @@ +
+ {{aSurveyInfo.registration.head}} +
diff --git a/templates/default/views/subviews/registration/register_message.twig b/templates/default/views/subviews/registration/register_message.twig new file mode 100644 index 00000000000..7347c089eb5 --- /dev/null +++ b/templates/default/views/subviews/registration/register_message.twig @@ -0,0 +1,6 @@ +{% if sStartDate %} +

{{ gT("You may register for this survey but you have to wait for the {{sStartDate}} before starting the survey.") }}

+{% else %} +

{{ gT("You may register for this survey if you wish to take part.") }}

+{% endif %} +

{{ gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately.") }}

diff --git a/templates/default/views/subviews/required.twig b/templates/default/views/subviews/required.twig new file mode 100644 index 00000000000..1046472e285 --- /dev/null +++ b/templates/default/views/subviews/required.twig @@ -0,0 +1 @@ + ({{ gT("Mandatory")}})