diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index 7c971cca0d4..fb9b06194a0 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -907,6 +907,7 @@ public function activate($iSurveyID) $survey->anonymized = Yii::app()->request->getPost('anonymized'); $survey->datestamp = Yii::app()->request->getPost('datestamp'); $survey->ipaddr = Yii::app()->request->getPost('ipaddr'); + $survey->ipanonymize = Yii::app()->request->getPost('ipanonymize'); $survey->refurl = Yii::app()->request->getPost('refurl'); $survey->savetimings = Yii::app()->request->getPost('savetimings'); $survey->save(); @@ -2002,6 +2003,7 @@ public function insert($iSurveyID = null) 'language' => App()->request->getPost('language', Yii::app()->session['adminlang']), 'datestamp' => App()->request->getPost('datestamp'), 'ipaddr' => App()->request->getPost('ipaddr'), + 'ipanonymize' => App()->request->getPost('ipanonymize'), 'refurl' => App()->request->getPost('refurl'), 'usecookie' => App()->request->getPost('usecookie'), 'emailnotificationto' => App()->request->getPost('emailnotificationto'), diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 00f6a9fadfe..208b7afaa6c 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -5000,7 +5000,7 @@ public static function StartSurvey($surveyid,$surveyMode='group',$aSurveyOptions $LEM->surveyOptions['deletenonvalues'] = (isset($aSurveyOptions['deletenonvalues']) ? ($aSurveyOptions['deletenonvalues']=='1') : true); $LEM->surveyOptions['hyperlinkSyntaxHighlighting'] = (isset($aSurveyOptions['hyperlinkSyntaxHighlighting']) ? $aSurveyOptions['hyperlinkSyntaxHighlighting'] : false); $LEM->surveyOptions['ipaddr'] = $survey->isIpAddr; - $LEM->surveyOptions['ipAnonymize'] = ($survey->ipanonymize === 'Y'); + $LEM->surveyOptions['ipAnonymize'] = $survey->isIpAnonymize; $LEM->surveyOptions['radix'] = (isset($aSurveyOptions['radix']) ? $aSurveyOptions['radix'] : '.'); $LEM->surveyOptions['refurl'] = (isset($aSurveyOptions['refurl']) ? $aSurveyOptions['refurl'] : NULL); $LEM->surveyOptions['savetimings'] = $survey->isSaveTimings; @@ -5512,7 +5512,7 @@ private function _UpdateValuesInDatabase($finished=false) if ($this->surveyOptions['ipaddr'] == true) { $sdata['ipaddr'] = getIPAddress(); - if($this->surveyOptions['ipAnonymize']){ + if($this->surveyOptions['ipAnonymize'] == true){ $ipAddressAnonymizer = new LimeSurvey\Models\Services\IpAddressAnonymizer($sdata['ipaddr']); $result = $ipAddressAnonymizer->anonymizeIpAddress(); if($result){ diff --git a/application/models/Survey.php b/application/models/Survey.php index be2fe5f5f3d..2e45f88dad3 100755 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -129,6 +129,7 @@ * @property bool $isAllowPrev Allow backwards navigation * @property bool $isPrintAnswers Participants may print answers * @property bool $isIpAddr Whether Participants IP address will be saved + * @property bool $isIpAnonymize Whether Participants IP address will be saved * @property bool $isRefUrl Save referrer URL * @property bool $isPublicStatistics Public statistics * @property bool $isPublicGraphs Show graphs in public statistics @@ -1232,6 +1233,14 @@ public function getIsIpAddr() { return ($this->oOptions->ipaddr === 'Y'); } + + /** + * @return bool + */ + public function getIsIpAnonymize() + { + return ($this->oOptions->ipanonymize === 'Y'); + } /** * @return bool */ diff --git a/application/models/SurveysGroupsettings.php b/application/models/SurveysGroupsettings.php index 2b7a747dc3d..6228d512548 100644 --- a/application/models/SurveysGroupsettings.php +++ b/application/models/SurveysGroupsettings.php @@ -65,7 +65,7 @@ class SurveysGroupsettings extends LSActiveRecord // attributes separated by column datatype, used by setToInherit method protected $optionAttributesInteger = array('owner_id', 'tokenlength', 'questionindex', 'navigationdelay'); protected $optionAttributesChar = array('anonymized', 'savetimings', 'datestamp', 'usecookie', 'allowregister', 'allowsave', 'autoredirect', 'allowprev', 'printanswers', - 'ipaddr', 'refurl', 'publicstatistics', 'publicgraphs', 'listpublic', 'htmlemail', 'sendconfirmation', 'tokenanswerspersistence', + 'ipaddr','ipanonymize', 'refurl', 'publicstatistics', 'publicgraphs', 'listpublic', 'htmlemail', 'sendconfirmation', 'tokenanswerspersistence', 'assessments', 'showxquestions', 'showgroupinfo', 'shownoanswer', 'showqnumcode', 'showwelcome', 'showprogress', 'nokeyboard', 'alloweditaftercompletion'); protected $optionAttributesText = array('admin', 'adminemail', 'template', 'bounce_email', 'emailresponseto', 'emailnotificationto'); diff --git a/application/models/services/IpAddressAnonymizer.php b/application/models/services/IpAddressAnonymizer.php index d9e500c96b0..a472883f3c4 100644 --- a/application/models/services/IpAddressAnonymizer.php +++ b/application/models/services/IpAddressAnonymizer.php @@ -12,13 +12,13 @@ class IpAddressAnonymizer { - /** @var string the original ip address*/ + /** @var string the original ip address */ private $ipAddress; /** * IpAddressAnonymizer constructor. * - * @param $ipAddress + * @param string $ipAddress */ public function __construct($ipAddress) { @@ -28,27 +28,41 @@ public function __construct($ipAddress) /** * Checks if ip is a valid ipv4 * - * @return mixed + * @return boolean */ - public function isIpv4(){ - return filter_var($this->ipAddress,FILTER_VALIDATE_IP,FILTER_FLAG_IPV4); + public function isIpv4() + { + if($this->ipAddress === ''){ + $result = false; + }else{ + $result = (boolean)filter_var($this->ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + } + + return $result; } /** * Checks if ip is a valid ipv6 * - * @return mixed|boolean false if not valid, otherwise the filtered ip address + * @return boolean false if not valid, otherwise the filtered ip address */ - public function isIpv6(){ - return filter_var($this->ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + public function isIpv6() + { + if($this->ipAddress === ''){ + $result = false; + }else{ + $result = (boolean)filter_var($this->ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + } + return $result; } /** * Checks if ip is a valid ipAddress * - * @return bool + * @return boolean */ - public function isValidIp(){ + public function isValidIp() + { return $this->isIpv4() || $this->isIpv6(); } @@ -63,15 +77,16 @@ public function isValidIp(){ * @return string|boolean if ip is not anonymized false will be returned (in case of not a valid ip or ip has already been * anonymized), else the anonymize ip will be returned as a string */ - public function anonymizeIpAddress(){ + public function anonymizeIpAddress() + { $anonymizedIp = false; - if($this->isIpv4()){ //check if it is valid ipv4 + if ($this->isIpv4()) { //check if it is valid ipv4 $ipArray = explode('.', $this->ipAddress); $last_digit = array_pop($ipArray); - if($last_digit!=0){ //check if it has already been anonymized + if ($last_digit != 0) { //check if it has already been anonymized //set last number to 0 - $anonymizedIp = implode('.',$ipArray); //without last digit ?!? + $anonymizedIp = implode('.', $ipArray); //without last digit ?!? $anonymizedIp .= '.0'; } } elseif ($this->isIpv6()) { //check if it is valid ipv6 diff --git a/application/views/admin/survey/activateSurvey_view.php b/application/views/admin/survey/activateSurvey_view.php index 8add4b2f461..c3abe05ff3d 100644 --- a/application/views/admin/survey/activateSurvey_view.php +++ b/application/views/admin/survey/activateSurvey_view.php @@ -185,6 +185,25 @@ function alertPrivacy() +
+
+ + +
+ +
+
+
+