$tousers=$this->db->query("SELECT `$column`-(`$column` % 86400) AS `day`, `to`, COUNT(*) AS `count`, SUM(`size`) AS `size` FROM ".VIEW_MESSAGES." WHERE `$column` >= ? AND `$column` < ? GROUP BY FROM_UNIXTIME(`day`, '%Y.%m.%d.'), `to`",array($start,$stop));
$fromusers=$this->db->query("SELECT `$column`-(`$column` % 86400) AS `day`, `from`, COUNT(*) AS `count`, SUM(`size`) AS `size` FROM ".VIEW_MESSAGES." WHERE `$column` >= ? AND `$column` < ? GROUP BY FROM_UNIXTIME(`day`, '%Y.%m.%d.'), `from`",array($start,$stop));
$addusers=$this->db->query("INSERT INTO ".TABLE_STAT_COUNTER." (`date`,`email`,`domain`,`sent`,`recd`,`sentsize`,`recdsize`) VALUES(?,?,?,?,?,?,?)",array($date,$username,$parts[1],$sent,$recd,$sizesent,$sizerecd));
if(LOG_LEVEL>=NORMAL){syslog(LOG_INFO,sprintf("processed %s to %s: %d records deleted, %d records added",date(DATE_TEMPLATE,$data['starttimestamp']),date(DATE_TEMPLATE,$data['stoptimestamp']),$data['deletedstats'],$data['addedstats']));}
// item can be either email or domain, maybe folder in the future??
$_order=0;
$_order="";
$limit="";
$account_for_emails=$this->__getEmails();
$account_for_domains=$this->__getDomains();
$search=preg_replace("/\s{1,}/","",$search);
if($item=='email'){
$account_for_emails=$this->__getEmails();
$account_for_domains=$this->__getDomains();
$query="SELECT `email` AS `item`,MIN(`date`) as `oldest`,MAX(`date`) as `newest`,sum(`sent`) as `sent`,sum(`recd`) as `recd`,SUM(`sentsize`) as `sentsize`,AVG(`sentsize`) as `sentavg`,SUM(`recdsize`) as `recdsize`,AVG(`recdsize`) as `recdavg` FROM ".TABLE_STAT_COUNTER;
$where="WHERE ( `email` IN ('".implode("','",$account_for_emails)."') OR `domain` IN ('".implode("','",$account_for_domains)."') )";
if($search){
$where.=" AND ( `email` like '%".$search."%' OR `domain` like '%".$search."%' )";
}
$group="GROUP BY `email`";
}elseif($item=='domain'){
$account_for_domains=$this->__getDomains();
$query="SELECT `domain` AS `item`,MIN(`date`) as `oldest`,MAX(`date`) as `newest`,sum(`sent`) as `sent`,sum(`recd`) as `recd`,SUM(`sentsize`) as `sentsize`,AVG(`sentsize`) as `sentavg`,SUM(`recdsize`) as `recdsize`,AVG(`recdsize`) as `recdavg` FROM ".TABLE_STAT_COUNTER;
$where="WHERE ( `domain` IN ('".implode("','",$account_for_domains)."') )";
$search_cond.=" AND ( `email` LIKE '%".$search."%' OR `domain` LIKE '%".$search."%' )";
}
$query="SELECT `email` AS `item`, MIN(`date`) AS `oldest`, MAX(`date`) AS `newest`, SUM(`sent`) AS `sent`, SUM(`recd`) AS `recd`, SUM(`sentsize`) AS `sentsize`, SUM(`recdsize`) AS `recdsize` FROM ".TABLE_STAT_COUNTER;
if($item=='email'){
$where="WHERE `email` IN ('".implode("','",$account_for_emails)."') OR `domain` IN ('".implode("','",$account_for_domains)."')";
if($search){
$where.=" AND ( `email` LIKE '%".$search."%' OR `domain` LIKE '%".$search."%' )";
}
$group="GROUP BY `email`";
}elseif($item=='domain'){
$where="WHERE `domain` IN ('".implode("','",$account_for_domains)."')";