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

   Engsoc PHP Registry

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

********************/ 
include ('includes/header.inc.php'); 
disp_header("User Administration");
if (!
check_auth()) {
    
disp_not_logged_in();
}
disp_navbar();
include (
'includes/mail_aliases.inc.php'); 


$adminClass $webuser->is_admin();

if (!
$adminClass) {
    
// user isn't supposed to be here ?>
<p>
    This page is for listed administrators only.  If you're part of your
    permanent year exec and think you should be looking after registry
    users in your year, please email the <?php print mailus("maintainers"?>.
</p>
<?php // end the message, boot 'em out
    
include('includes/footer.inc.php');
    exit;
}

if (isset(
$action)) { // do something to some users
    
foreach($action as $handle => $act) {
        switch (
$act) {
        case 
"auth":
            
$names $regdb->getRow("select first_name, last_name from people 
                                     where handle='$handle'"
);
            
$command "/usr/bin/sudo " posix_getcwd() 
                       . 
"/scripts/regauth.sh $handle \""
                       
addslashes($names[0]) . "\" \""
                       
addslashes($names[1]) . "\"";
            
$command stripslashes(escapeshellcmd($command));
            print 
"<p>Executing: <tt>$command</tt></p>\n";
            
$result = `$command`;
            if (
preg_match("/Adding user \`$handle\'/"$result)) {
                print 
"<p>New user <tt>$handle</tt> added successfully</p>\n";
                
$sql "update people set newuser='false'";
                if (
$year_admin[$handle] == 'true') {
                    
$sql .= ", admin='t'";
                }
                
$sql .= " where handle='$handle'";
                
$regdb->query($sql);
                
add_alias($handle);
                
// Send a message to the user so they know
                // they're validated.
                
$valEmail get_preferred_email($handle);
                
$valMsg 
"Congratulations, you've been validated for the Engsoc Registry at
http://$SERVER_NAME/.  Enjoy looking up old friends, and having 
free email as $handle@$reg_domain."
;
                
mail($valEmail"Registry Access"$valMsg);
            } else {
                print 
"<p class=\"error\">Error while trying";
                print 
" to add <tt>$handle</tt>:\n";
                print 
"<pre>$result</pre>";
                print 
"</p>\n";
            }
            break;
        case 
"nuke":
            
// Send a message to the user so they know they're
            // not validated.
            
$valEmail get_preferred_email($handle);
            
$valMsg 
"Sorry, but your application for the Engsoc Registry at 
http://$SERVER_NAME/ has been denied."
;
            
mail($valEmail"Registry Access"$valMsg);
            
// delete their database entries
            
$sql "delete from people where handle='$handle';
                    delete from publish where handle='$handle'"
;
            
$regdb->query($sql);
            
// delete their system account
            
$command =  "/usr/bin/sudo " posix_getcwd() 
                        . 
"/scripts/regnuke.sh $handle";
            
$command escapeshellcmd($command);
            
exec($command);
            
// delete their realname alias
            
del_alias($handle);
            break;
        case 
"wait":
            break;
        }
        
// Flush output, so some progress is visible.
        
flush();
    }
}


// get pending users
if ($adminClass == 'master') {
    
$pending $regdb->query("SELECT * FROM people 
        WHERE newuser='true'"
);
} else {
    
$pending $regdb->query("SELECT * FROM people 
        WHERE newuser='true' AND class='$adminClass'"
);
}

if (isset(
$moreInfo)) {
    include (
'dbform.inc.php');
    
show_dbinfo($moreInfo);
    print 
"<hr />\n";
}

// display a table of pending users and admin options
$rowStyle "inputL";
print 
"<form action=\"" basename($PHP_SELF) . "\" method=\"post\">\n";
print 
"<table cellspacing=\"0\" cellpadding=\"3\" border=\"1\">\n";
print 
"\t<tr class=\"$rowStyle\"><th>Auth</th><th>Nuke</th><th>Wait</th>";
print 
"<th>Year Admin?</th>";
print 
"<th>Name</th><th>Location</th>";
// Show which year people are in to master admins
if ($adminClass == 'master') {
    print 
"<th>Year</th>";
}
print 
"<th>More Info</th></tr>\n";
while (
$info $pending->fetchRow(DB_GETMODE_ASSOC)) {
    switch (
$rowStyle) {
        case 
"inputL":
            
$rowStyle "inputD";
            break;
        case 
"inputD":
            
$rowStyle "inputL";
    }
    print 
"<tr class=\"$rowStyle\">";
    print 
"<td class=\"toggle\"><input type=\"radio\" name=\"action[" 
          
$info['handle'] . "]\" value=\"auth\" /></td>";
    print 
"<td class=\"toggle\"><input type=\"radio\" name=\"action[" 
          
$info['handle'] . "]\" value=\"nuke\" /></td>";
    print 
"<td class=\"toggle\"><input type=\"radio\" name=\"action[" 
          
$info['handle'] . "]\" value=\"wait\" checked /></td>";
    print 
"<td class=\"toggle\"><input type=\"checkbox\" name=\"year_admin["
          
$info['handle'] . "]\" value=\"true\" /></td>";
    print 
"<td>" $info['first_name'] . " " $info['last_name'] . "</td>";
    print 
"<td>" $info['address_city'] . ", ";
    if (!empty(
$info['address_prov'])) 
        print 
$info['address_prov'] . ", ";
    print 
$info['address_country'] . "</td>";
    
// Display class to master admins.
    
if ($adminClass == 'master') {
        print 
"<td>Sci'" $info['class'] . "</td>";
    }
    print 
"<td><a href=\"" basename($PHP_SELF
          . 
"?moreInfo=${info['handle']}\">Details...</a></td></tr>\n";
}
print 
"</table>\n";
print 
"<p>\n\t<input type=\"submit\" value=\"Process Pending Users\" />\n";
print 
"\t<input type=\"reset\" value=\"Wait On All\" />\n</form>\n";

    

?>


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