diff --git a/application/controllers/admin/tokens.php b/application/controllers/admin/tokens.php index 0e1b355a9de..a5ab61cac7e 100644 --- a/application/controllers/admin/tokens.php +++ b/application/controllers/admin/tokens.php @@ -98,6 +98,169 @@ function index($surveyid) self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); } } + + /** + * tokens::bounceprocessing() + * + * @return void + */ + function bounceprocessing($surveyid) + { + + $this->load->helper('globalsettings'); + + $thissurvey=getSurveyInfo($surveyid); + if ($thissurvey['bounceprocessing']!='N' && !($thissurvey['bounceprocessing']=='G' && getGlobalSetting('bounceaccounttype')=='off') && bHasSurveyPermission($surveyid, 'tokens','update')) + { + $bouncetotal=0; + $checktotal=0; + if($thissurvey['bounceprocessing']=='G') + { + $accounttype=getGlobalSetting('bounceaccounttype'); + $hostname=getGlobalSetting('bounceaccounthost'); + $username=getGlobalSetting('bounceaccountuser'); + $pass=getGlobalSetting('bounceaccountpass'); + $hostencryption=getGlobalSetting('bounceencryption'); + + } + else + { + $accounttype=$thissurvey['bounceaccounttype']; + $hostname=$thissurvey['bounceaccounthost']; + $username=$thissurvey['bounceaccountuser']; + $pass=$thissurvey['bounceaccountpass']; + $hostencryption=$thissurvey['bounceaccountencryption']; + + } + @list($hostname,$port) = split(':', $hostname); + if(empty($port)) + { + if($accounttype=="IMAP") + { + switch($hostencryption) + { + case "Off": + $hostname = $hostname.":143"; + break; + case "SSL": + $hostname = $hostname.":993"; + break; + case "TLS": + $hostname = $hostname.":993"; + break; + } + } + else + { + switch($hostencryption) + { + case "Off": + $hostname = $hostname.":110"; + break; + case "SSL": + $hostname = $hostname.":995"; + break; + case "TLS": + $hostname = $hostname.":995"; + break; + } + } + } + $flags=""; + switch($accounttype) + { + case "IMAP": + $flags.="/imap"; + break; + case "POP": + $flags.="/pop3"; + break; + } + switch($hostencryption) // novalidate-cert to have personal CA , maybe option. + { + case "SSL": + $flags.="/ssl/novalidate-cert"; + break; + case "TLS": + $flags.="/tls/novalidate-cert"; + break; + } + if($mbox=imap_open('{'.$hostname.$flags.'}INBOX',$username,$pass)) + { + imap_errors(); + $count=imap_num_msg($mbox); + $lasthinfo=imap_headerinfo($mbox,$count); + $datelcu = strtotime($lasthinfo->date); + $datelastbounce= $datelcu; + $lastbounce = $thissurvey['bouncetime']; + while($datelcu > $lastbounce) + { + @$header = explode("\r\n", imap_body($mbox,$count,FT_PEEK)); // Don't put read + foreach ($header as $item) + { + if (preg_match('/^X-surveyid/',$item)) + { + $surveyidBounce=explode(": ",$item); + } + if (preg_match('/^X-tokenid/',$item)) + { + $tokenBounce=explode(": ",$item); + if($surveyid == $surveyidBounce[1]) + { + $bouncequery = "UPDATE ".db_table_name("tokens_$surveyid")." SET emailstatus='bounced' WHERE token='$tokenBounce[1]';"; + $data = array( + 'emailstatus'=> 'bounced' + + ); + $condn = array('token' => $tokenBounce[1]); + $this->load->model('tokens_dynamic_model'); + + + $anish= $this->tokens_dynamic_model->updateRecords($surveyid,$data,$condn); //$connect->Execute($bouncequery);) + + $readbounce=imap_body($mbox,$count); // Put read + if (isset($thissurvey['bounceremove']) && $thissurvey['bounceremove']) // TODO Y or just true, and a imap_delete + { + $deletebounce=imap_delete($mbox,$count); // Put delete + } + $bouncetotal++; + } + } + } + $count--; + @$lasthinfo=imap_headerinfo($mbox,$count); + @$datelc=$lasthinfo->date; + $datelcu = strtotime($datelc); + $checktotal++; + @imap_close($mbox); + } + $entertimestamp = "update ".db_table_name("surveys")." set bouncetime='$datelastbounce' where sid='$surveyid'"; + $data = array('bouncetime' => $datelastbounce); + $condn = array('sid' => $surveyid); + $this->load->model('surveys_model'); + + $executetimestamp = $this->surveys_model->updateSurvey($data,$condn); //'$connect->Execute($entertimestamp);) + if($bouncetotal>0) + { + echo sprintf($clang->gT("%s messages were scanned out of which %s were marked as bounce by the system."), $checktotal,$bouncetotal); + } + else + { + echo sprintf($clang->gT("%s messages were scanned, none were marked as bounce by the system."),$checktotal); + } + } + else + { + echo $clang->gT("Please check your settings"); + } + } + else + { + echo $clang->gT("We are sorry but you don't have permissions to do this."); + } + exit(0); // if bounceprocessing : javascript : no more todo + + } /** * Browse Tokens diff --git a/application/models/tokens_dynamic_model.php b/application/models/tokens_dynamic_model.php index a2ea8ffe637..5f376c98601 100644 --- a/application/models/tokens_dynamic_model.php +++ b/application/models/tokens_dynamic_model.php @@ -156,4 +156,11 @@ function deleteTokens($surveyid,$tokenids) $dlquery = "DELETE FROM ".$this->db->dbprefix("tokens_$surveyid")." WHERE tid IN (".implode(", ", $tokenids).")"; return $this->db->query($dlquery); } + + function updateRecords($surveyid,$data,$condn) + { + return $this->db->update("tokens_$surveyid", $data, $condn); + } + + } \ No newline at end of file diff --git a/application/views/admin/token/browse.php b/application/views/admin/token/browse.php index 412134d1dc2..c4e3b4f4e91 100644 --- a/application/views/admin/token/browse.php +++ b/application/views/admin/token/browse.php @@ -1,4 +1,8 @@ -