Commit 7c18ebf4 authored by Chenu Denis's avatar Chenu Denis

[fix] Better find if need update settings for 3.14.0 and lesser

[fix] Encode user entered answer
parent 9e932c92
......@@ -6,7 +6,7 @@
* @author Denis Chenu <denis@sondages.pro>
* @copyright 2018 Denis Chenu <http://sondages.pro>
* @license AGPL v3
* @version 2.0.0
* @version 2.1.0
*/
class adminNotificationHtmlAnswerTable extends PluginBase {
......@@ -43,26 +43,44 @@ class adminNotificationHtmlAnswerTable extends PluginBase {
$controller = $this->getEvent()->get('controller');
$action = $this->getEvent()->get('action');
$subaction = $this->getEvent()->get('subaction');
if($controller != 'admin') {
$sid = Yii::app()->getRequest()->getParam('surveyid');
if(empty($sid) && Yii::app()->getRequest()->getIsPostRequest()) {
$sid = Yii::app()->getRequest()->getPost('sid');
}
if(empty($sid)) {
return;
}
if(version_compare(Yii::app()->getConfig('versionnumber'),"3.14.1",">") && $action == 'survey') {
$sid = Yii::app()->getRequest()->getParam('surveyid');
if(is_null($this->get('emailhacked','Survey',$sid))) {
return;
/* version up to 3.14.1 : can use real emailnotificationto, delete current plugin settings and reset emailnotificationto */
if(version_compare(Yii::app()->getConfig('versionnumber'),"3.14.1",">") ) {
if( $this->get('emailhacked','Survey',$sid)) { /* old settings active, disable */
$this->unsubscribe('afterFindSurvey');
$oSurvey = Survey::model()->findByPk($sid);
$oSurvey->emailnotificationto = $this->get('emailnotificationto','Survey',$sid,'');
$oSurvey->emailresponseto = $this->get('emailresponseto','Survey',$sid,'');
PluginSetting::model()->deleteAll("plugin_id = :plugin_id and model = :model and survey = :sid",array(":plugin_id"=>$this->id,":model"=>'Survey',":sid"=>$sid));
}
$this->unsubscribe('afterFindSurvey');
$oSurvey = Survey::model()->findByPk($sid);
$oSurvey->emailnotificationto = $this->get('emailnotificationto','Survey',$sid,'');
$oSurvey->emailresponseto = $this->get('emailresponseto','Survey',$sid,'');
PluginSetting::model()->deleteAll("plugin_id = :plugin_id and model = :model and survey = :sid",array(":plugin_id"=>$this->id,":model"=>'Survey',":sid"=>$sid));
return;
}
/* Version before 3.14.2 */
$sid = Yii::app()->getRequest()->getParam('surveyid');
if($action == 'database' && Yii::app()->getRequest()->getIsPostRequest() ) {
$sid = Yii::app()->getRequest()->getPost('sid');
/* version lesser to 3.14.1 : can't use real emailnotificationto, then hack it */
$dataBaseUpdate = ($controller == 'admin' && $action == 'database' && Yii::app()->getRequest()->getIsPostRequest()); // This is when saving notification too
if(!$dataBaseUpdate && empty($this->get('emailhacked','Survey',$sid)) ) {
$oSurvey = Survey::model()->findByPk($sid);
if(!empty($oSurvey->emailnotificationto)) {
$this->set('emailnotificationto',$oSurvey->emailnotificationto,'Survey',$sid);
}
$emailnotificationto = $this->get('emailnotificationto','Survey',$sid,'');
if(!empty($oSurvey->emailresponseto)) {
$this->set('emailresponseto',$oSurvey->emailresponseto,'Survey',$sid);
}
$emailresponseto = $this->get('emailresponseto','Survey',$sid,'');
$this->set('emailhacked',1,'Survey',$sid);
$oSurvey->emailnotificationto = "";
$oSurvey->emailresponseto = "";
$oSurvey->save();
}
/* When saving reponseto */
if($dataBaseUpdate) {
if(Permission::model()->hasSurveyPermission($sid, 'surveysettings', 'update') ) {
if(Yii::app()->getRequest()->getPost('emailnotificationto') !== null) {
$this->set('emailnotificationto',Yii::app()->getRequest()->getPost('emailnotificationto'),'Survey',$sid);
......@@ -76,21 +94,16 @@ class adminNotificationHtmlAnswerTable extends PluginBase {
}
$this->set('emailhacked',1,'Survey',$sid);
}
return;
}
if($action == 'survey' && $subaction == 'rendersidemenulink') {
/* update the input part */
if($controller == 'admin' && $action == 'survey' ) {
$emailnotificationto = $this->get('emailnotificationto','Survey',$sid,'');
Yii::app()->getClientScript()->registerScript('emailnotificationto',"$('#emailnotificationto').val('".$emailnotificationto."');",LSYii_ClientScript::POS_POSTSCRIPT);
$emailresponseto = $this->get('emailresponseto','Survey',$sid,'');
$stringInfo = "<a rel=\"tooltip\" title=\"for adminNotificationHtmlAnswerTable\"> * </a> ";
Yii::app()->getClientScript()->registerScript('emailnotificationto',"$('#emailnotificationto').val('".$emailnotificationto."');",LSYii_ClientScript::POS_POSTSCRIPT);
Yii::app()->getClientScript()->registerScript('emailnotificationtoLabel',"$('label[for=\"emailnotificationto\"]').html('{$stringInfo}'+$('label[for=\"emailnotificationto\"]').text());",LSYii_ClientScript::POS_POSTSCRIPT);
Yii::app()->getClientScript()->registerScript('emailresponseto',"$('#emailresponseto').val('".$emailresponseto."');",LSYii_ClientScript::POS_POSTSCRIPT);
return;
}
if($action == 'survey' && $subaction == 'view' && $sid && empty($this->get('emailhacked','Survey',$sid))) {
static $done;
if(!$done) {
Yii:app()->setFlashMessage($this->_translate("Plugin adminNotificationHtmlAnswerTable are not activated in this survey. Please save Notification & Data management"),'warning');
$done=true;
}
Yii::app()->getClientScript()->registerScript('emailresponsetoLabel',"$('label[for=\"emailresponseto\"]').html('{$stringInfo}'+$('label[for=\"emailresponseto\"]').text());",LSYii_ClientScript::POS_POSTSCRIPT);
}
}
public function afterSurveyComplete() {
......@@ -233,35 +246,41 @@ class adminNotificationHtmlAnswerTable extends PluginBase {
$oldgid = 0;
$oldqid = 0;
Yii::import('application.helpers.viewHelper');
$encodeAnswer = [
$this->get('encodeAnswer',"Survey",$surveyid,$this->get('encodeAnswer',null,null,$this->settings['encodeAnswer']['default'])),
$this->settings['encodeAnswer']['default'],
];
print_r($encodeAnswer);
$encodeAnswer = $this->get('encodeAnswer',"Survey",$surveyid,$this->get('encodeAnswer',null,null,$this->settings['encodeAnswer']['default']));
/* Get DB columns data : string(5) mean answer */
$tableSchemaColumns = SurveyDynamic::model($surveyid)->getTableSchema()->columns;
foreach ($aFullResponseTable as $sFieldname=>$fname) {
$questionHtml=viewHelper::purified($fname[0]);
$questionText=viewHelper::flatEllipsizeText($fname[0],true,0);
$subQuestionHtml=viewHelper::purified($fname[1]);
$subQuestionText=viewHelper::flatEllipsizeText($fname[1],true,0);
$answer = isset($fname[2]) ? $fname[2] : '';
if($this->get('encodeAnswer',"Survey",$surveyid,$this->get('encodeAnswer',null,null,$this->settings['encodeAnswer']['default'])) ) {
$answer = CHtml::encode($answer);
} else {
$answer = viewHelper::purified($answer);
}
if (substr($sFieldname,0,4)=='gid_') {
$ResultTableHTML .= "\t<tr class='printanswersgroup'><td colspan='2'>{$questionHtml}</td></tr>\n";
$ResultTableText .="\n** {$questionText} ** \n";
} elseif (substr($sFieldname,0,4)=='qid_') {
$ResultTableHTML .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$questionHtml}</td></tr>\n";
$ResultTableText .="* {$questionText} \n";
} elseif(empty($fname[1])) {
$ResultTableHTML .= "\t<tr class='printanswersquestion printanswersquestionhead'><td>{$questionHtml}</td><td class='printanswersanswertext'>".$answer."</td></tr>\n";
$ResultTableText .="* {$questionText} \t\t\t : {$fname[2]}\n";
} else {
$ResultTableHTML .= "\t<tr class='printanswersquestion'><td>{$subQuestionHtml}</td><td class='printanswersanswertext'>".$answer."</td></tr>\n";
$ResultTableText .="- \t {$subQuestionText} \t\t : {$fname[2]}\n";
if($showUnrelevantQuestion || LimeExpressionManager::ProcessStepString("{".$sFieldname.".relevanceStatus}") ) {
if( $encodeAnswer ) {
$answer = CHtml::encode($answer);
} else {
/* Update by DB type */
if(isset($tableSchemaColumns[$sFieldname]->dbType) && in_array($tableSchemaColumns[$sFieldname]->dbType,array('varchar(5)')) ) {
$answer = viewHelper::purified($answer);
}
}
if(empty($fname[1])) {
$ResultTableHTML .= "\t<tr class='printanswersquestion printanswersquestionhead'><td>{$questionHtml}</td><td class='printanswersanswertext'>".$answer."</td></tr>\n";
$ResultTableText .="* {$questionText} \t\t\t : {$fname[2]}\n";
} else {
$ResultTableHTML .= "\t<tr class='printanswersquestion'><td>{$subQuestionHtml}</td><td class='printanswersanswertext'>".$answer."</td></tr>\n";
$ResultTableText .="- \t {$subQuestionText} \t\t : {$fname[2]}\n";
}
}
}
}
$ResultTableHTML .= "</table>\n";
$ResultTableText .= "\n\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment