<pre>
------ Nightly Emails ------
<?PHP

// Include the config
require_once('../include/config.inc.php');

// get every user who has at least 1 thing tracked
$sql "SELECT user_p, count(*) cnt FROM user, user_tracking WHERE user_f = user_p GROUP BY user_p";
$results mysql_query($sql) or die(mysql_error());
while(
$row mysql_fetch_assoc($results)){
    
$user = new user($row['user_p']);
    if(isset(
$user->preferences['send_email']) && $user->preferences['send_email'] == 'checked'){
        
        
$keyword '';
        if(isset(
$user->preferences['homepage_keyword']) && $user->preferences['homepage_keyword'] != '' && $user->preferences['homepage_keyword'] != 'Any')
            
$keyword $user->preferences['homepage_keyword'];
        
        
        
$listing = new latest_ebuilds(mktime(0,0,0,date('m'), date('d') -1date('Y')), $keyword01true,$user->get_tracked_packages());
        
        if(
count($listing->data) > 0){
            
$mail = new email();
            
$mail->Subject "Gentoo-Portage.com Package Update: ".parse_date();
        
            switch(
$user->preferences['email_type']){
                case 
'html':
                    
$mail->Body html_email_contents($listing->data);
                    
$mail->AltBody text_email_contents($listing->data);
                    break;
                case 
'text':
                    
$mail->Body text_email_contents($listing->data);
                    break;
            }
        
        
            
$mail->AddAddress($user->email);
            @
$mail->send();
            
            echo 
"Emailed: ".$user->email."\n";
        }
    }
}

function 
html_email_contents($data){
    
$text '<h2>Your package update for: '.parse_date().'</h2>'."\n";
    
    
$text .= '<p>You have requested to be informed about package updates on your tracked package listing, if you with to change this please visit your <a href="http://gentoo-portage.com/User/Preferences">preferences</a> page on gentoo-portage.com</p><br/>'."\n";
    
    foreach(
$data as $value){
        
$text .= '<a href="http://gentoo-portage.com/'.$value['category_title'].'/'.$value['package_title'].'">'.$value['category_title'].'/'.$value['ebuild_display'].'</a>  <i>'.$value['ebuild_description'].'</i><br/>'."\n";
    }
    
    return 
$text;
}

function 
text_email_contents($data){
    
$text 'Your package update for: '.parse_date()."\n\n";
    
    
$text .= 'You have requested to be informed about package updates on your tracked package listing, if you with to change this please visit your preferences page on gentoo-portage.com'."\n\n";
    
    foreach(
$data as $value){
        
$text .= $value['category_title'].'/'.$value['ebuild_display'].' - '.$value['ebuild_description']."\n";
    }
    
    return 
$text;
}

?>
</pre>