#!/usr/bin/perl -w # Dump address book as a web page # # Dobrica Pavlinusic 2002-01-18 # # http://www.rot13.org/~dpavlin/palm.html # # based on palm_lsaddr - Palm address database helper utility for lbdb # Copyright (C) 2000 Dave Pearson # # license: GPL2 # # 2003-04-02 DbP: rewrote module to use PDA::Pilot use strict; use CGI; use CGI::Pretty; use Data::Dumper; use PDA::Pilot; use CGI qw/:standard *table :html3/; use CGI::Carp qw(fatalsToBrowser); my $db_file="/home/dpavlin/.jpilot/AddressDB.pdb"; my $pdb = PDA::Pilot::File::open( $db_file ); my $app = $pdb->getAppBlock; my $ab = PDA::Pilot::Address::UnpackAppBlock($app); print header({-charset=>'ISO-8859-2'}),start_html("View Palm's address book"), start_form, "Name or number:",textfield('s'),submit({-value=>'Find'}), end_form,hr, start_table; my $s=param('s') || '.'; $s=~tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; if ( $pdb ) { my $record = 0; my $found = 0; while(defined(my $rec = $pdb->getRecord($record++))) { my $r = PDA::Pilot::Address::Unpack($rec); my $name; # first name $name .= $r->{entry}[0] . " " if ($r->{entry}[0]); # last name $name .= $r->{entry}[1] if ($r->{entry}[1]); if ($name && length($name) > 0) { # Remove leading and trailing whitespace. $name =~ s/\s+$//; $name =~ s/^\s+//; if ($r->{entry}[2]) { $name .= "
".$r->{entry}[2].""; } } else { # If the name is empty, use the company name instead. $name = $r->{entry}[2] || 'no name'; } $name =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 my $name_czs=$name; $name_czs =~ tr/¹©ðÐèÈæƾ®/sSdDcCcCzZ/; my @phone = (); my @phone_find = (); for (my $i=3; $i<=7; $i++) { if (my $tmp = $r->{entry}[$i]) { $tmp=~s/\+385[-\s]*/0/; # add label push @phone, $ab->{label}[$i].": ".$tmp; $tmp=~s,[/-],,g; push @phone_find,$tmp; } } if ( ($name && $name_czs =~ m/$s/i) || grep(/$s/,@phone_find) ) { if ($found % 2 == 0) { print Tr({-valign=>'top'}, td($name), td(join("
",@phone)), ); } else { print Tr({-valign=>'top', -bgcolor=>'lightgrey'}, td($name), td(join("
",@phone)), ); } $found++; } } } print end_table,end_html;