<?php
/********************

   Engsoc PHP Registry

   This file allows a user to edit their information.

 Copyright 2000 Philip Steinke and Kevin Everets
 Licensed under the GNU General Public License

********************/ 
include ('includes/header.inc.php'); 
disp_header("Update Registry Entry");
if (!
check_auth()) {
    
disp_not_logged_in();
}
disp_navbar();
include (
'dbform.inc.php'); 

// Define the "required" image so it appears properly in the form.
$reqimg "<img src=\"images/checkmark.png\" alt=\"->\" />";

if (!isset(
$addStep)) { 
    
// no info passed in, so display the edit form
?>
<p>
    Go <a href="chg_passwd.php">here</a> to change your password.
</p>
<p>
    Make any changes to your information in the form below.  When everything
    is as you'd like it, press the 'Submit Info' button at the bottom of the
    form.
</p>
<?php
    $curInfo 
$regdb->getRow("select * from people where handle='$webuser->handle'"DB_GETMODE_ASSOC);
    foreach(
$curInfo as $varname => $value) {
        $
$varname $value;
    }
    
build_dbform();
} else { 
    
// they submitted their new info, so step through and update the database
    
check_info();
    if (isset(
$need)) {
        
// some required fields are missing; prompt them for info ?>
<p>
    Some required information is missing.  Please complete all shown
    sections:
</p>
<?php    // display form
        
$curInfo $regdb->getRow("select * from people where handle='$webuser->handle'"DB_GETMODE_ASSOC);
        foreach(
$curInfo as $varname => $value) {
            $
$varname $value;
        }
        
build_dbform('req');
    } else {
        
// put info in db and show closing message
        
$addsql "UPDATE people SET ";
        foreach(
$form_field as $field => $info) {
            
$addsql .= "$field = '${$field}', ";
        }
        
$listlen strlen($addsql) - 2;
        
$addsql substr($addsql 0$listlen);
        
$addsql .= " WHERE handle='$webuser->handle'";
        
$fieldList "handle, ";
        
$values "'$handle', ";
        foreach(
$publish as $field) {
            
$fieldList .= "$field, ";
            
$values .= "'true', ";
        }
        
$listlen strlen($fieldList) - 2;
        
$fieldList substr($fieldList0$listlen);
        
$listlen strlen($values) - 2;
        
$values substr($values0$listlen);
        
$pubsql "DELETE FROM publish WHERE handle='$webuser->handle';
                    INSERT INTO publish
                    ($fieldList) 
                    VALUES ($values)"
;
        
$insResult $regdb->query($addsql);
        if (!
DB::isError($insResult)) {
            
$addok true;
        }
        
$insResult $regdb->query($pubsql);
        if (!
DB::isError($insResult)) {
            
$pubok true;
        }
        
// if first or last name changed, update finger information and mail aliases as well
        
if (($first_name != $webuser->first_name) || ($last_name != $webuser->last_name)) {
            include (
'mail_aliases.inc.php');
            
$dupnum 0;
            
$query "SELECT dupnum FROM people 
                         WHERE lower(first_name)='"
.strtolower($first_name)."' 
                      AND lower(last_name)='"
.strtolower($last_name)."'
                      AND handle != '$handle'"
;
            
$dupresults $regdb->query($query);
            while (
$row $dupresults->fetchRow()) {
                
$dupnum++;
            }
            
$dupresults->free();
            
$regdb->query("UPDATE people SET dupnum='$dupnum'
                           WHERE handle='$handle'"
);
            
del_alias($handle);
            
add_alias($handle);
            
$webuser->first_name $first_name;
            
$webuser->last_name $last_name;
            
$command "/usr/bin/sudo " posix_getcwd() .  "/scripts/regrename.sh $handle $first_name $last_name";
            
$command escapeshellcmd($command);
            
$result = `$command`;
            if (
$result) {
                echo 
"<p class=\"error\">System Error: <tt>$result</tt></p>\n";
            }
        }
        
// spit out a congrats message ?>
<p>
    Congratulations, your information has been updated.
</p>
<?        // close off the if statement
    
}  // done inserting info
}

include (
'includes/footer.inc.php'); ?>