#!/afs/athena/contrib/perl/p

$user = $ARGV[0];

$hesinfo = `hesinfo $user passwd`;
$zlocate = `zlocate $user`;

($uname, $star, $uid, $grp, $namestr, $homedir, $shell) = split(/:/, $hesinfo);
($name, $nick, $office, $officephone, $homephone) = split(/,/, $namestr);

print("$name <$user>,");
print(" aka \"$nick\"") if $nick;
print("\n");

if($zlocate=~/Hidden/){
print("\tis not logged in.\n");
}
else{
($where, $disp, @rest) = split(' ', $zlocate);
print("\tis logged in at $where on $disp\n");
}

$homephone =~ s/\D//g;
$officephone=~ s/\D//g;

$homephone = &fixphone($homephone);
$officephone = &fixphone($officephone);

print("\tHome Phone: $homephone\n") if $homephone;
print("\tOffice Phone: $officephone\n") if $officephone;

sub fixphone{
	local($pstr) = @_;
	local($l);

	$l = length($pstr);
	if($l == 10){
		$pstr =~ s/(\d\d\d)(\d\d\d)(\d\d\d\d)/\1\-\2\-\3/;
	}
	elsif($l == 7){
		$pstr =~ s/(\d\d\d)(\d\d\d\d)/\1\-\2/;
	}
	elsif($l == 5){
		$pstr =~ s/(\d)(\d\d\d\d)/\1\-\2/;
	}
	$pstr;
}
