From: octo Date: Fri, 22 Apr 2005 22:56:45 +0000 (+0000) Subject: More fixed/additions.. X-Git-Tag: Release-0.1~12 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=25446d838c43fad3372999393afd65d07ce895d1;p=licom.git More fixed/additions.. --- diff --git a/book.cgi b/book.cgi index bebf6d1..461815b 100755 --- a/book.cgi +++ b/book.cgi @@ -122,6 +122,10 @@ sub action_browse print qq(\t\t
  • $group
  • \n); } + if (!%groups) + { + print qq(\t\t
  • There are no groups yet.
  • \n); + } print qq(\t\n); } else @@ -284,20 +288,22 @@ sub action_edit $lastname = $person->lastname (); $firstname = $person->firstname (); - $contacts->{'address'} = $person->address (); - $contacts->{'homephone'} = $person->homephone (); - $contacts->{'cellphone'} = $person->cellphone (); - $contacts->{'officephone'} = $person->officephone (); - $contacts->{'fax'} = $person->fax (); - $contacts->{'mail'} = $person->mail (); - $contacts->{'uri'} = $person->uri (); - $contacts->{'group'} = $person->group (); + + for (@MultiFields) + { + $contacts->{$_} = $person->get ($_); + } } $lastname = param ('lastname') if (param ('lastname') and $UserID); $firstname = param ('firstname') if (param ('firstname') and $UserID); - get_contacts ($contacts); + for (@MultiFields) + { + my $field = $_; + my @values = grep { $_ } (param ($field)); + $contacts->{$field} = [@values] if (@values); + } $lastname = $opts{'lastname'} if (defined ($opts{'lastname'})); $firstname = $opts{'firstname'} if (defined ($opts{'firstname'})); @@ -309,99 +315,77 @@ sub action_edit if ($cn) { - print "\t

    Edit contact $cn

    \n"; + print "\t\t

    Edit contact $cn

    \n"; } else { - print "\t

    Create new contact

    \n"; + print "\t\t

    Create new contact

    \n"; } - my $selector = sub - { - my $selected = @_ ? shift : ''; - - my @options = ([none => '-- Contact --']); - - for (@MultiFields) - { - my $field = $_; - my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field; - push (@options, [$field, $print]); - } - - print qq(); - }; - print < - - - - - + + + +
    Lastname
    + + EOF if ($UserID) { - print qq(\t\t\t\n); + print qq(\t\t\t\t\n); } else { - print qq(\t\t\t\n); + print qq(\t\t\t\t\n); } print < - - + + + EOF if ($UserID) { - print qq(\t\t\t\n); + print qq(\t\t\t\t\n); } else { - print qq(\t\t\t\n); + print qq(\t\t\t\t\n); } - print "\t\t\n"; + print "\t\t\t\n"; for (@MultiFields) { my $field = $_; + my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field; my @values = @{$contacts->{$field}}; - @values = ('') unless (@values); + push (@values, ''); for (@values) { my $value = $_; - print "\t\t\n", - "\t\t\t\n", < - + + print < + + + EOF } } - print "\t\t\n", - "\t\t\t\n", < - - - - -
    Lastname$lastname$lastname
    Firstname
    Firstname$firstname$firstname
    "; - $selector->($field); - print "
    $print
    "; - $selector->(); - print "
    - + print < + +EOF + print qq(\t\t\t\t\t\n) if ($UserID); + print < + + + + EOF } @@ -427,7 +411,13 @@ sub action_save my $lastname = param ('lastname'); my $firstname = param ('firstname'); - my $contacts = get_contacts (); + my $contacts = {}; + for (@MultiFields) + { + my $field = $_; + my @values = grep { $_ } (param ($field)); + $contacts->{$field} = [@values] if (@values); + } my $person = Person->create (lastname => $lastname, firstname => $firstname, %$contacts); @@ -439,7 +429,14 @@ sub action_save $cn = $person->name (); - action_detail ($cn); + if (param ('button') eq 'Update') + { + action_edit (cn => $cn); + } + else + { + action_detail ($cn); + } } sub action_update @@ -460,7 +457,13 @@ sub action_update $cn = $person->name (); } - my $contacts = get_contacts (); + my $contacts = {}; + for (@MultiFields) + { + my $field = $_; + my @values = grep { $_ } (param ($field)); + $contacts->{$field} = [@values] if (@values); + } for (@MultiFields) { @@ -477,13 +480,13 @@ sub action_update } } - if ($UserID) + if (param ('button') eq 'Update' or !$UserID) { - action_detail ($cn); + action_edit (cn => $cn); } else { - action_edit (cn => $cn); + action_detail ($cn); } } @@ -675,35 +678,3 @@ sub read_config die ("Not defined: $_") unless (defined ($Config{$_})); } } - -sub get_contacts -{ - my $contacts = @_ ? shift : {}; - - if (param ('c_value')) - { - my @c_values = param ('c_value'); - my @c_types = param ('c_type'); - - my %cts = (); - - die if (scalar (@c_values) != scalar (@c_types)); - - for (my $i = 0; $i < scalar (@c_values); $i++) - { - my $type = $c_types[$i]; - my $value = $c_values[$i]; - - $cts{$type} = [] unless (defined ($cts{$type})); - push (@{$cts{$type}}, $value) if ($value); - } - - for (@MultiFields) - { - my $type = $_; - @{$contacts->{$type}} = @{$cts{$type}} if (defined ($cts{$type})); - } - } - - return ($contacts); -}