Skip to content

Commit

Permalink
Bounceprocessing subaction basic code. Not fully implemented yet!
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11126 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Oct 8, 2011
1 parent bebbbcb commit 1e5c81f
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 4 deletions.
163 changes: 163 additions & 0 deletions application/controllers/admin/tokens.php
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions application/models/tokens_dynamic_model.php
Expand Up @@ -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);
}


}
9 changes: 8 additions & 1 deletion application/views/admin/token/browse.php
@@ -1,4 +1,8 @@
<div class='menubar'><div class='menubar-title ui-widget-header'><span style='font-weight:bold;'>
<script language='javascript' type='text/javascript'> surveyid = '<?php echo $surveyid; ?>'; </script>
<script language='javascript' type='text/javascript'> var imgurl = '<?php echo $this->config->item('imageurl'); ?>';
var controllerurl = '<?php echo site_url("admin/tokens/bounceprocessing/$surveyid"); ?>'; </script>

<div class='menubar'><div class='menubar-title ui-widget-header'><span style='font-weight:bold;'>
<?php $clang->eT("Data view control");?></span></div>
<div class='menubar-main'>
<div class='menubar-left'>
Expand Down Expand Up @@ -279,6 +283,9 @@
//End multiple item actions
?>
</table>

<div id='dialog-modal'></div>

<!-- Code for central Participants database -->
<p><input type='button' name='addtocpdb' id='addtocpdb' value='<?php $clang->eT("Add participants to central database");?>'/><br />
<!-- End of Code for central Participants database -->
Expand Down
6 changes: 3 additions & 3 deletions scripts/admin/tokens.js
Expand Up @@ -49,9 +49,9 @@ $(document).ready(function(){
});
function checkbounces(surveyid) {
$("#dialog-modal").dialog('open');
var url = 'admin.php?action=tokens&subaction=bounceprocessing&sid='+surveyid
$('#dialog-modal').html('<p><img style="margin-top:42px" src="../images/ajax-loader.gif" width="200" height="25" /></p>');
$('#dialog-modal').load(url);
var url = controllerurl;
$('#dialog-modal').html('<p><img style="margin-top:42px" src="'+ imgurl + '/ajax-loader.gif" width="200" height="25" /></p>');
$('#dialog-modal').load(controllerurl);
}

function turnoff(ui,evt)
Expand Down

0 comments on commit 1e5c81f

Please sign in to comment.