From 69ce93d25ec32cb8773d0be1f451a60fcbac3c1e Mon Sep 17 00:00:00 2001 From: octo Date: Sun, 24 Apr 2005 15:20:34 +0000 Subject: [PATCH] Added support for lists. More CSS, esp. printing, fixes. --- book.cgi | 411 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 294 insertions(+), 117 deletions(-) diff --git a/book.cgi b/book.cgi index cf4653e..4af14ad 100755 --- a/book.cgi +++ b/book.cgi @@ -39,6 +39,7 @@ our %Actions = default => [\&html_start, \&action_browse, \&html_end], detail => [\&html_start, \&action_detail, \&html_end], edit => [\&html_start, \&action_edit, \&html_end], + list => [\&html_start, \&action_list, \&html_end], save => [\&html_start, \&action_save, \&html_end], search => [\&html_start, \&action_search, \&html_end], verify => [\&html_start, \&action_verify, \&html_end], @@ -159,7 +160,81 @@ sub action_browse } print qq(\t\t\n\n); - print qq(\t\t\n) if ($group); + print qq(\t\t\n); +} + +sub action_list +{ + my $group = param ('group'); + $group = shift if (@_); + $group ||= ''; + + my $title = $group ? "List of group "$group"" : 'List of all addresses'; + my @fields = (qw(address homephone cellphone officephone fax mail)); + + my @all = (); + if ($group) + { + @all = Person->search ([[group => $group]]); + } + else + { + @all = Person->search (); + } + + print <$title + + + + +EOF + for (@fields) + { + print "\t\t\t\t\n"; + } + print "\t\t\t\n"; + + for (sort { $a->name () cmp $b->name () } (@all)) + { + my $person = $_; + my $sn = $person->lastname (); + my $gn = $person->firstname (); + + print "\t\t\t\n", + "\t\t\t\t\n"; + + for (@fields) + { + my $field = $_; + my @values = $person->get ($field); + print "\t\t\t\t\n"; + } + + print "\t\t\t\n"; + } + print "\t\t
Name" . (defined ($FieldNames{$_}) ? $FieldNames{$_} : $_) . "
$sn, $gn" . join ('
', @values) . "
\n\n"; + + if ($group) + { + my $group_esc = uri_escape ($group); + print qq(\t\t\n); + } + else + { + print qq(\t\t\n); + } } sub action_detail @@ -175,16 +250,16 @@ sub action_detail return; } - print qq(\t

Details for $cn

\n); + print qq(\t\t

Details for $cn

\n); my $cn_esc = uri_escape ($cn); print < - - Name - $cn - + + + + + EOF for (@MultiFields) { @@ -195,14 +270,14 @@ EOF next unless ($num); - print "\t\t\n"; + print "\t\t\t\n"; if ($num > 1) { - 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); } for (my $i = 0; $i < $num; $i++) @@ -225,18 +300,20 @@ EOF $val = qq($val); } - print "\t\t\n" if ($i); - print "\t\t\t\n", - "\t\t\n"; + print "\t\t\t\n" if ($i); + print "\t\t\t\t\n", + "\t\t\t\n"; } } print < +
Name$cn
$print$print$print$print
$val
$val
+ + + EOF } @@ -614,8 +691,10 @@ sub action_verify if ($mail) { - action_verify_send_mail ($person); - $message .= qq( A request for verification has been sent to $mail.); + if (action_verify_send_mail ($person)) + { + $message .= qq( A request for verification has been sent to $mail.); + } } else { @@ -633,6 +712,14 @@ sub action_verify_send_mail my $owner = Person->load ($UserCN); my $smh; + my ($owner_mail) = $owner->get ('mail'); + if (!$owner_mail) + { + my $cn = uri_escape ($UserCN); + print qq(\t\t
You have no email set in your own profile. Edit it now!
\n); + return (0); + } + my $max_width = 0; for (keys %FieldNames) { @@ -645,17 +732,13 @@ sub action_verify_send_mail my $person_gn = $person->firstname (); my $password = $person->password (); - my $owner_name = $owner->name (); - my ($owner_mail) = $owner->get ('mail'); - $owner_mail ||= $ENV{'SERVER_ADMIN'}; - my $host = $ENV{'HTTP_HOST'}; my $url = 'http://' . $host . $MySelf; - open ($smh, '| /usr/sbin/sendmail -t') or die ("open pipe to sendmail: $!"); + open ($smh, "| /usr/sbin/sendmail -t -f $owner_mail") or die ("open pipe to sendmail: $!"); print $smh < -From: $owner_name <$owner_mail> +From: $UserCN <$owner_mail> Subject: Please verify our entry in my address book Hello $person_gn, @@ -681,9 +764,11 @@ If this entry is outdated or incomplete, please take a minute and correct it. Password: $password Thank you very much :) Regards, -$owner_name +$UserCN EOM close ($smh); + + return (1); } sub html_start @@ -699,110 +784,203 @@ Content-Type: text/html; charset=UTF-8 $title @@ -813,7 +991,7 @@ EOF { my $search = param ('search') || ''; print < +
@@ -829,7 +1007,6 @@ EOF
-
EOF } print "\t\t

$title

\n"; -- 2.11.0