Skip to content

Commit

Permalink
DEV: inheritance when creating new survey, new selectbox in before ac…
Browse files Browse the repository at this point in the history
…tivating a survey (setting for "Anonymize IP"),changes in em_manager for anonymizing ip
  • Loading branch information
Trischi80 committed Apr 15, 2020
1 parent c4716cf commit 997fa18
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
2 changes: 2 additions & 0 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand Down
9 changes: 9 additions & 0 deletions application/models/Survey.php
Expand Up @@ -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
Expand Down Expand Up @@ -1232,6 +1233,14 @@ public function getIsIpAddr()
{
return ($this->oOptions->ipaddr === 'Y');
}

/**
* @return bool
*/
public function getIsIpAnonymize()
{
return ($this->oOptions->ipanonymize === 'Y');
}
/**
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion application/models/SurveysGroupsettings.php
Expand Up @@ -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');
Expand Down
43 changes: 29 additions & 14 deletions application/models/services/IpAddressAnonymizer.php
Expand Up @@ -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)
{
Expand All @@ -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();
}

Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions application/views/admin/survey/activateSurvey_view.php
Expand Up @@ -185,6 +185,25 @@ function alertPrivacy()
</div>
</div>

<div class="col-sm-4 ">
<div class='form-group'>
<label for='ipaddr' class='control-label col-sm-7'>
<?php eT("Anonymize IP address?"); ?>
</label>

<div class='col-sm-5'>
<select name='ipanonymize' id='ipanonymize' class='form-control'>
<option value='Y' <?php if ($aSurveysettings['ipanonymize'] == "Y") {echo "selected='selected'";} ?>>
<?php eT("Yes"); ?>
</option>
<option value='N' <?php if ($aSurveysettings['ipanonymize'] != "Y") { echo "selected='selected'";} ?>>
<?php eT("No"); ?>
</option>
</select>
</div>
</div>
</div>

<div class="col-sm-4">
<div class='form-group'>
<label class='control-label col-sm-7' for='refurl'><?php eT("Save referrer URL?"); ?></label>
Expand Down

0 comments on commit 997fa18

Please sign in to comment.