From: octo Date: Fri, 22 Apr 2005 22:26:44 +0000 (+0000) Subject: Many more fixes and additions.. X-Git-Tag: Release-0.1~13 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=03f669abd5a8e26847f01c845cf61a7bbf033a7c;p=licom.git Many more fixes and additions.. --- diff --git a/book.cgi b/book.cgi index 8a616b1..bebf6d1 100755 --- a/book.cgi +++ b/book.cgi @@ -20,7 +20,7 @@ our %FieldNames = ( address => 'Address', homephone => 'Home Phone', - cellphone => 'Cellphone', + cellphone => 'Cell Phone', officephone => 'Office Phone', fax => 'FAX', mail => 'E-Mail', @@ -35,11 +35,13 @@ $Action ||= 'default'; our %Actions = ( - default => \&action_default, - detail => \&action_detail, - edit => \&action_edit, - save => \&action_save, - search => \&action_search + browse => [\&html_start, \&action_browse, \&html_end], + default => [\&html_start, \&action_browse, \&html_end], + detail => [\&html_start, \&action_detail, \&html_end], + edit => [\&html_start, \&action_edit, \&html_end], + save => [\&html_start, \&action_save, \&html_end], + search => [\&html_start, \&action_search, \&html_end], + vcard => \&action_vcard ); read_config (); @@ -63,13 +65,6 @@ if (!$UserID and $Action ne 'save') $Action = 'edit'; } -print <(); +if (ref ($Actions{$Action}) eq 'CODE') +{ + $Actions{$Action}->(); +} +elsif (ref ($Actions{$Action}) eq 'ARRAY') +{ + for (@{$Actions{$Action}}) + { + $_->(); + } +} #print qq#
Authenticated as ($UserCN, $UserID, #, $Config{'base_dn'}, qq#)
\n#; -print_html_end (); - Person->disconnect (); exit (0); ### -sub action_default +sub action_browse { - print "action_default\n"; + my $group = param ('group'); + $group = shift if (@_); + $group ||= '*'; + + my @all = Person->search ([[group => $group]]); + + if ($group eq '*') + { + my %groups = (); + for (@all) + { + my $person = $_; + my @g = $person->get ('group'); + + $groups{$_} = 1 for (@g); + } + + print qq(\t

Contact Groups

\n\t\n); + } + else + { + print qq(\t

Contact Group "$group"

\n\t\n); + } } sub action_detail { my $cn = param ('cn'); + $cn = shift if (@_); die unless ($cn); my $person = Person->load ($cn); @@ -109,6 +152,8 @@ sub action_detail return; } + print qq(\t

Details for $cn

\n); + my $cn_esc = uri_escape ($cn); print < EOF } @@ -184,6 +230,14 @@ sub action_search return; } + if (scalar (@matches) == 1) + { + my $person = shift (@matches); + my $cn = $person->name (); + action_detail ($cn); + return; + } + print qq(\t
    \n); for (@matches) { @@ -255,29 +309,25 @@ sub action_edit if ($cn) { - print "

    Edit contact $cn

    \n"; + print "\t

    Edit contact $cn

    \n"; } else { - print "

    Create new contact

    \n"; + print "\t

    Create new contact

    \n"; } my $selector = sub { my $selected = @_ ? shift : ''; - my @options = - ( - [none => '-- Contact --'], - [address => 'Address'], - [homephone => 'Home Phone'], - [cellphone => 'Cellphone'], - [officephone => 'Office Phone'], - [fax => 'FAX'], - [mail => 'E-Mail'], - [uri => 'URI (Homepage)'], - [group => 'Group'] - ); + my @options = ([none => '-- Contact --']); + + for (@MultiFields) + { + my $field = $_; + my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field; + push (@options, [$field, $print]); + } print qq( - - - -
    - - - -
    - -
    + +
    EOF } - print "\t

    octo's Lightweight Address Book

    \n"; + print "\t\t

    octo's Lightweight Address Book

    \n"; } -sub print_html_end +sub html_end { print <octo's Lightweight Address Book <octo at verplant.org> diff --git a/lib/Person.pm b/lib/Person.pm index 96a5977..c692e96 100644 --- a/lib/Person.pm +++ b/lib/Person.pm @@ -179,11 +179,11 @@ sub create { if (ref ($val) eq 'ARRAY') { - $entry->add ($field => [@$val]); + $entry->add ($field => [@$val]) if (@$val); } elsif (!ref ($val)) { - $entry->add ($field => [$val]); + $entry->add ($field => [$val]) if ($val); } else { @@ -364,8 +364,11 @@ sub _update_dn $obj->{'cn'} = $cn; + print STDERR "This is _update_dn, trying to set dn=$dn"; + $entry->changetype ('modify'); $entry->replace (sn => $sn, givenName => $gn, cn => $cn); + $entry->update ($Ldap); $entry->dn ($dn); $entry->update ($Ldap); } @@ -528,8 +531,6 @@ sub get_user my ($t_cn) = $e->get_value ('cn', asref => 0); my ($t_id) = $e->get_value ('uid', asref => 0); - print STDERR "LDAP result: $t_cn, $t_id"; - if (!$id or $t_id) { $cn = $t_cn;