From 3af89f9a3db0d7244961fa6cc2164b22612aa37c Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Fri, 2 Dec 2016 17:52:17 +0100 Subject: [PATCH] New feature : default template use a boostrap dialog for clearall Dev: 2 step without js is done too Dev: core use confirm, related to feature #11970 --- application/controllers/survey/index.php | 61 ---------------- .../core/packages/limesurvey/survey.js | 42 ++++++----- application/helpers/SurveyRuntimeHelper.php | 71 ++++++++++++++++--- .../helpers/expressions/em_manager_helper.php | 1 - application/helpers/frontend_helper.php | 4 -- application/helpers/replacements_helper.php | 4 +- .../survey/frontpage/clearallForm/form.php | 18 +++++ .../survey/frontpage/clearallForm/heading.php | 7 ++ .../survey/frontpage/clearallForm/message.php | 7 ++ .../survey/system/actionButton/clearAll.php | 9 ++- .../survey/system/actionLink/clearAll.php | 2 +- .../system/surveyIndex/groupIndexMenuLink.php | 2 +- .../surveyIndex/questionIndexMenuLink.php | 2 +- templates/default/css/template.css | 1 + templates/default/scripts/template.js | 21 ++++++ templates/default/views/endpage.pstpl | 2 +- templates/default/views/navigator.pstpl | 2 +- templates/default/views/survey.pstpl | 1 + templates/default/views/welcome.pstpl | 1 + 19 files changed, 154 insertions(+), 104 deletions(-) create mode 100644 application/views/survey/frontpage/clearallForm/form.php create mode 100644 application/views/survey/frontpage/clearallForm/heading.php create mode 100644 application/views/survey/frontpage/clearallForm/message.php diff --git a/application/controllers/survey/index.php b/application/controllers/survey/index.php index 78f27926fa7..aebc646fa89 100644 --- a/application/controllers/survey/index.php +++ b/application/controllers/survey/index.php @@ -502,67 +502,6 @@ function action() } } - - //Clear session and remove the incomplete response if requested. - if (isset($move) && $move == "clearall") - { - // delete the response but only if not already completed - $s_lang = $_SESSION['survey_'.$surveyid]['s_lang']; - if (isset($_SESSION['survey_'.$surveyid]['srid']) && !SurveyDynamic::model($surveyid)->isCompleted($_SESSION['survey_'.$surveyid]['srid'])) - { - // delete the response but only if not already completed - $result= dbExecuteAssoc('DELETE FROM {{survey_'.$surveyid.'}} WHERE id='.$_SESSION['survey_'.$surveyid]['srid']." AND submitdate IS NULL"); - if($result->count()>0){ // Using count() here *should* be okay for MSSQL because it is a delete statement - // find out if there are any fuqt questions - checked - $fieldmap = createFieldMap($surveyid,'short',false,false,$s_lang); - foreach ($fieldmap as $field) - { - if ($field['type'] == "|" && !strpos($field['fieldname'], "_filecount")) - { - if (!isset($qid)) { $qid = array(); } - $qid[] = $field['fieldname']; - } - } - - // if yes, extract the response json to those questions - if (isset($qid)) - { - $query = "SELECT * FROM {{survey_".$surveyid."}} WHERE id=".$_SESSION['survey_'.$surveyid]['srid']; - $result = dbExecuteAssoc($query); - foreach($result->readAll() as $row) - { - foreach ($qid as $question) - { - $json = $row[$question]; - if ($json == "" || $json == NULL) - continue; - - // decode them - $phparray = json_decode($json); - - foreach ($phparray as $metadata) - { - $target = Yii::app()->getConfig("uploaddir")."/surveys/".$surveyid."/files/"; - // delete those files - unlink($target.$metadata->filename); - } - } - } - } - // done deleting uploaded files - } - - // also delete a record from saved_control when there is one - dbExecuteAssoc('DELETE FROM {{saved_control}} WHERE srid='.$_SESSION['survey_'.$surveyid]['srid'].' AND sid='.$surveyid); - } - killSurveySession($surveyid); - $content=templatereplace(file_get_contents($oTemplate->pstplPath."clearall.pstpl"),array()); - $this->getController()->layout='survey'; - $this->getController()->render("/survey/system/display",array('content'=>$content)); - App()->end(); - } - - //Check to see if a refering URL has been captured. if (!isset($_SESSION['survey_'.$surveyid]['refurl'])) { diff --git a/application/core/packages/limesurvey/survey.js b/application/core/packages/limesurvey/survey.js index eeaa7516bbf..f488aee1c0c 100644 --- a/application/core/packages/limesurvey/survey.js +++ b/application/core/packages/limesurvey/survey.js @@ -189,8 +189,7 @@ function activateActionLink(){ event.preventDefault(); var submit=$(this).data('limesurvey-submit'); var confirmedby=$(this).data('confirmedby'); - if(!confirmedby || confirm($(this).data('confirmlabel'))) - { + if(!confirmedby){ $.each(submit, function(name, value) { $("",{ 'type':"hidden", @@ -198,34 +197,43 @@ function activateActionLink(){ 'value':value, }).appendTo('form#limesurvey'); }); - $.each(confirmedby, function(name, value) { - $("",{ - 'type':"hidden", - 'name':name, - 'value':value, - }).appendTo('form#limesurvey'); - }); $('form#limesurvey').submit(); + }else{ + var submits=$.extend(submit,confirmedby); + confirmSurveyDialog($(this).data('confirmlabel'),$(this).text(),submits) } }); } } - +/** + * function for replacing submit after confirm + */ +function confirmSurveyDialog(text,title,submits){ + if(confirm(text)){ + $.each(submits, function(name, value) { + $("",{ + 'type':"hidden", + 'name':name, + 'value':value, + }).appendTo('form#limesurvey'); + }); + $('form#limesurvey').submit(); + } +} /** * Ask confirmation on click on .needconfirm */ function activateConfirmButton(){ $(document).on('click',"button[data-confirmedby]", function(event){ - // @todo : allow multiple here : remove extra + var btnConfirm=$(this); var cbConfirm=$(this).parent().find("[name='"+$(this).data('confirmedby')+"']"); if(!$(cbConfirm).is(":checked")) { - text=$(cbConfirm).parent("label").text(); - if (confirm(text)) { - $(cbConfirm).clone().addClass('ls-js-hidden').appendTo('#limesurvey').prop('checked',true); - return true; - } - return false; + event.preventDefault(); + var submits = { }; + submits[$(btnConfirm).attr('name')]=$(btnConfirm).val(); + submits[$(cbConfirm).attr('name')]=$(cbConfirm).val(); + confirmSurveyDialog($(cbConfirm).parent("label").text(),$(btnConfirm).text(),submits) } }); } diff --git a/application/helpers/SurveyRuntimeHelper.php b/application/helpers/SurveyRuntimeHelper.php index 7d1a09f6bdf..24a2a5be1fc 100644 --- a/application/helpers/SurveyRuntimeHelper.php +++ b/application/helpers/SurveyRuntimeHelper.php @@ -361,9 +361,9 @@ public function run($surveyid,$args) \n"; // <-- END FEATURE - SAVE - // The default submit button echo CHtml::htmlButton("default",array('type'=>'submit','id'=>"defaultbtn",'value'=>"default",'name'=>'move','class'=>"submit hidden",'style'=>'display:none')); + // <-- START THE SURVEY --> if ($surveyMode == 'survey') { if (isset($thissurvey['showwelcome']) && $thissurvey['showwelcome'] == 'N') @@ -379,13 +379,9 @@ public function run($surveyid,$args) { echo templatereplace(file_get_contents($sTemplateViewPath."privacy.pstpl"), array(), $redata) . "\n"; } - } - - // <-- START THE SURVEY --> - if ($surveyMode != 'survey') - { - /* Why survey.pstpl is not included in all in one mode ?*/ + }else{/* survey.pstpl is not included in all in one mode : welcome replace needed functionnality inside form for default template */ echo templatereplace(file_get_contents($sTemplateViewPath."survey.pstpl"), array(), $redata); + } // runonce element has been changed from a hidden to a text/display:none one. In order to workaround an not-reproduced issue #4453 (lemeur) @@ -865,7 +861,7 @@ private function moveFirstChecks() $LEMsessid = $this->LEMsessid; if ( $move=="clearcancel"){ - $moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, true, false, true); + $moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, false); } /* quota submitted */ @@ -914,6 +910,7 @@ private function setMoveResult() } $moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'],false,false); // if late in the survey, will re-validate contents, which may be overkill + unset($_SESSION[$LEMsessid]['LEMtokenResume']); }else if (!$LEMskipReprocessing){ @@ -944,7 +941,9 @@ private function setMoveResult() $moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['totalsteps'] + 1, false); } } - + if ( $move=='clearall'){ + $this->manageClearAll(); + } if ( $move=='changelang'){ // jump to current step using new language, processing POST values $moveResult = $this->moveResult = LimeExpressionManager::JumpTo($_SESSION[$LEMsessid]['step'], false, true, true, true); // do process the POST data @@ -1631,4 +1630,58 @@ private function getErrorHtmlMessage() return ""; } } + + /** + * clear all system (no js or broken js) + * @uses $this->surveyid + * @uses $this->sTemplateViewPath + * @return void + */ + private function manageClearAll() + { + /* Maybe nest is ro move this in SurveyController */ + $sessionSurvey=Yii::app()->session["survey_{$this->surveyid}"]; + if(App()->request->getPost('confirm-clearall')=='confirm'){ // Previous behaviour (and javascript behaviour) + // delete the existing response but only if not already completed + if ( + isset($sessionSurvey['srid']) + && !SurveyDynamic::model($this->surveyid)->isCompleted($sessionSurvey['srid']) // see bug https://bugs.limesurvey.org/view.php?id=11978 + ){ + $oResponse=Response::model($this->surveyid)->find("id=:srid",array(":srid"=>$sessionSurvey['srid'])); + if($oResponse){ + $oResponse->delete(true);/* delete response line + files uploaded , warninbg : beforeDelete don't happen with deleteAll */ + } + if(Survey::model()->findByPk($this->surveyid)->savetimings=="Y"){ + SurveyTimingDynamic::model($this->surveyid)->deleteAll("id=:srid",array(":srid"=>$sessionSurvey['srid'])); /* delete timings ( @todo must move it to Response )*/ + } + SavedControl::model()->deleteAll("sid=:sid and srid=:srid",array(":sid"=>$this->surveyid,":srid"=>$sessionSurvey['srid']));/* saved controls (think we can have only one , but maybe ....)( @todo must move it to Response )*/ + } + killSurveySession($this->surveyid); + $content=templatereplace(file_get_contents($this->sTemplateViewPath."clearall.pstpl"),array()); + App()->getController()->layout='survey'; + App()->getController()->render("/survey/system/display",array('content'=>$content)); + App()->end(); + }elseif(App()->request->getPost('confirm-clearall')!='cancel'){ + LimeExpressionManager::JumpTo($sessionSurvey['step'], false, true, true, false); // do process the POST data + App()->getController()->layout="survey"; + App()->getController()->bStartSurvey=true; + + $aReplacements=array(); + $aReplacements['FORMID'] = 'clearall'; + $aReplacements['FORMHEADING'] = App()->getController()->renderPartial("/survey/frontpage/clearallForm/heading",array(),true); + $aReplacements['FORMMESSAGE'] = App()->getController()->renderPartial("/survey/frontpage/clearallForm/message",array(),true); + $aReplacements['FORMERROR'] = ""; + $aReplacements['FORM'] = CHtml::beginForm(array("/survey/index","sid"=>$this->surveyid), 'post',array('id'=>'form-'.$aReplacements['FORMID'],'class'=>'ls-form')); + $aReplacements['FORM'].= CHtml::hiddenField('move','clearall',array()); + $aReplacements['FORM'].= App()->getController()->renderPartial("/survey/frontpage/clearallForm/form",array(),true); + $aReplacements['FORM'].= CHtml::hiddenField('thisstep',$sessionSurvey['step']); + $aReplacements['FORM'].= CHtml::hiddenField('sid',$this->surveyid); + $aReplacements['FORM'].= CHtml::endForm(); + $content = templatereplace(file_get_contents($this->sTemplateViewPath."form.pstpl"),$aReplacements); + App()->getController()->render("/survey/system/display",array( + 'content'=>$content, + )); + Yii::app()->end(); + } + } } diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index b4812938452..1d5acca3c03 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -5574,7 +5574,6 @@ static function JumpTo($seq,$preview=false,$processPOST=true,$force=false,$chang $updatedValues = array(); } $message = ''; - $LEM->currentQset = array(); // reset active list of questions $result = $LEM->_ValidateSurvey($force); $message .= $result['message']; diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index ebb2366c638..c3b276a9656 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -2454,10 +2454,6 @@ function getMove() if(Yii::app()->request->getParam($sAccepteMove)) $move=$sAccepteMove; } - /* Good idea, but used ? */ - if($move=='clearall' && App()->request->getPost('confirm-clearall')!='confirm'){ - $move="clearcancel"; - } /* default move (user don't click on a button, but use enter in a input:text or a select */ if($move=='default') { diff --git a/application/helpers/replacements_helper.php b/application/helpers/replacements_helper.php index ee1b30022df..7d00f271de4 100644 --- a/application/helpers/replacements_helper.php +++ b/application/helpers/replacements_helper.php @@ -847,7 +847,7 @@ function doHtmlClearAll(){ if(empty($aClearAll)){ $aClearAll['button']=App()->getController()->renderPartial("/survey/system/actionButton/clearAll",array( 'value'=>'clearall', - 'name'=>'clearall', + 'name'=>'move', 'class'=>'ls-clearaction ls-clearall', 'confirmedby'=>'confirm-clearall', 'confirmvalue'=>'confirm', @@ -865,7 +865,7 @@ function doHtmlClearAll(){ ),true); // To replace javascript confirm : https://ethaizone.github.io/Bootstrap-Confirmation/ or http://bootboxjs.com/documentation.html#bb-confirm-dialog or https://nakupanda.github.io/bootstrap3-dialog/ or .... /* Don't do it in core actually, but put some language*/ - App()->getClientScript()->registerScript("activateConfirmLanguage","LSvar.confirmLang=".ls_json_encode(array('yes'=>gT("Yes"),'no'=>gT("No"))),CClientScript::POS_BEGIN); + App()->getClientScript()->registerScript("activateConfirmLanguage","$.extend(LSvar.lang,".ls_json_encode(array('yes'=>gT("Yes"),'no'=>gT("No"))).")",CClientScript::POS_BEGIN); App()->getClientScript()->registerScript("activateActionLink","activateActionLink();\n",CClientScript::POS_END); App()->getClientScript()->registerScript("activateConfirmButton","activateConfirmButton();\n",CClientScript::POS_END); } diff --git a/application/views/survey/frontpage/clearallForm/form.php b/application/views/survey/frontpage/clearallForm/form.php new file mode 100644 index 00000000000..39fbb67ad70 --- /dev/null +++ b/application/views/survey/frontpage/clearallForm/form.php @@ -0,0 +1,18 @@ + +
+
+
+
+ +
+
+ +
+
+
+
diff --git a/application/views/survey/frontpage/clearallForm/heading.php b/application/views/survey/frontpage/clearallForm/heading.php new file mode 100644 index 00000000000..c0fc4c4b0e9 --- /dev/null +++ b/application/views/survey/frontpage/clearallForm/heading.php @@ -0,0 +1,7 @@ + + diff --git a/application/views/survey/frontpage/clearallForm/message.php b/application/views/survey/frontpage/clearallForm/message.php new file mode 100644 index 00000000000..6ec17cccfa8 --- /dev/null +++ b/application/views/survey/frontpage/clearallForm/message.php @@ -0,0 +1,7 @@ + +

diff --git a/application/views/survey/system/actionButton/clearAll.php b/application/views/survey/system/actionButton/clearAll.php index 8543d093e59..bd8cc5724fe 100644 --- a/application/views/survey/system/actionButton/clearAll.php +++ b/application/views/survey/system/actionButton/clearAll.php @@ -9,6 +9,10 @@ "form-inline ls-{$name}-form")); + echo CHtml::openTag("label",array("class"=>"form-group hidden")); + echo CHtml::checkBox($confirmedby,false,array('id'=>false,'value'=>$confirmvalue)); + echo CHtml::tag("span",array('class'=>'control-label'),gT("Please confirm you want to clear your response?")); + echo CHtml::closeTag("label"); echo CHtml::htmlButton(gT("Exit and clear survey"),array( 'type'=>'submit', 'id'=>null, @@ -17,12 +21,7 @@ 'class'=>"$class btn btn-link", 'data-confirmedby'=>$confirmedby, 'title'=>gT("This action need confirmation."), - 'aria-label'=>gT("This action need confirmation with the next checkbox."), /* ? must be reviewed */ )); - echo CHtml::openTag("label",array("class"=>"form-group ls-js-hidden")); - echo CHtml::checkBox($confirmedby,false,array('id'=>null,'value'=>$confirmvalue)); - echo CHtml::tag("span",array('class'=>'control-label'),gT("Are you sure you want to clear all your responses?")); - echo CHtml::closeTag("label"); echo CHtml::closeTag("div"); ?> diff --git a/application/views/survey/system/actionLink/clearAll.php b/application/views/survey/system/actionLink/clearAll.php index 54b2758e35a..f351395efc8 100644 --- a/application/views/survey/system/actionLink/clearAll.php +++ b/application/views/survey/system/actionLink/clearAll.php @@ -7,7 +7,7 @@ */ ?>
  • - + diff --git a/application/views/survey/system/surveyIndex/groupIndexMenuLink.php b/application/views/survey/system/surveyIndex/groupIndexMenuLink.php index 5867bb731da..6c5d629f6a2 100644 --- a/application/views/survey/system/surveyIndex/groupIndexMenuLink.php +++ b/application/views/survey/system/surveyIndex/groupIndexMenuLink.php @@ -5,7 +5,7 @@ * */ ?> -