<?php
/**********
 * mail_aliases.php
 *
 * This file contains the functions necessary to add and delete realname
 * aliases to the system for each user.
 **********/


/*****
 * add_alias()
 *
 * Adds an alias to the registry aliases file to allow the user to receive
 * email to firstname.lastname@domain.bla
 *****/
function add_alias ($handle) {
    global 
$regdb$reg_domain;
    list(
$fname$lname$dupnum) = $regdb->getRow(
        
"SELECT first_name, last_name, dupnum FROM people 
             WHERE handle='$handle'"
);
    
$alias "$fname $lname";
    if (
$dupnum$alias .= $dupnum;
    
$alias preg_replace("/ /""."$alias);
    
$alias strtolower($alias);
    
$data file('/etc/aliases.registry');
    
$data[] = "$alias: $handle\n";
    
sort($data);
    
$fp fopen('/etc/aliases.registry''w');
    foreach(
$data as $line) {
        
fwrite($fp$line);
    }
    
fclose($fp);
    echo 
"<p>You may now receive mail as both ";
    echo 
"<tt>$handle@$reg_domain</tt> and <tt>$alias@$reg_domain</tt></p>\n";
}

/*****
 * del_alias()
 *
 * Given a handle, will remove the real-name alias for that person from the
 * aliases.registry file.
 *****/
function del_alias ($handle) {
    
$data file('/etc/aliases.registry');
    
$fp fopen('/etc/aliases.registry''w');
    foreach(
$data as $line) {
        if (!
ereg("$handle$"$line))
            
fwrite($fp$line);
    }
    
fclose($fp);
}
?>