Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Phonenumber

Quote Reply
Phonenumber
Hi,

what a cool new site. Three thumbs up.

I've a problem I hope one of you guys can help me with.

In a danish database I would like to have a phonenumber
presented e.g. as +45 44 44 44 44.

So what I need is a field which contains a number
in the example that would be 44444444. And on the detailed
page it's showed as +45 44 44 44 44 (with spaces, + and danish local code).

I could just do this in a textbox, but then in a search on
phonenumbers you would have to search on the phonenumber with spaces.

Martin



Quote Reply
Re: Phonenumber In reply to
I'm going to pass on this, because I think there should be a way to do it with a pattern match, and I don't have a clue how to do that :)

Someone might be able to, and it would mean putting a line of perl code in before you sent the link to the template to re-format the phone number into the display format.



Quote Reply
Re: Phonenumber In reply to
Hi

try it with:

$AreaCode="+49 ";
$PhoneNumber=$AreaCode . join(" ",unpack("A2A2A2A2A2A2A2",$PhoneNumber));

$PhoneNumber=~ s/\s+$//;

regards, alexander

Quote Reply
Re: Phonenumber In reply to
Thanks for the help.

Where should I include that code?

Quote Reply
Re: Phonenumber In reply to
Put it right before the call to the link formatting routine (or detail.html) in your source files. You might get the most bang for the buck if you do the first modification in the HTML_Templates.pm file in the

sub site_html_link {

routine.

Put it right before the &load_template call.


This will probably do it (I haven't tested it obviously).

You'd need to change the code to reflect the variable names. If your database field was called "PhoneNumber":

Code:
my $AreaCode="+49 ";
my $PhoneNumber=$AreaCode . join(" ",unpack("A2A2A2A2A2A2A2",$rec->{'PhoneNumber'}));
$PhoneNumber=~ s/\s+$//;
$rec->{'PhoneNumber'} = $PhoneNumber;
The tag <%PhoneNumber%> would then be available in the links.html templates template, and the detailed.html template.




Quote Reply
Re: Phonenumber In reply to
Thanks for the help, but I'm still experiecing some
problems. I've inserted the code in HTML_Templates.pm in site_html_link:

my $AreaCode="+45 ";
my $Telefon=$AreaCode . join(" ",unpack("A2A2A2A2A2A2A2",$rec->{'Telefon'}));
$Telefon=~ s/\s+$//;
$rec->{'Telefon'} = $Telefon;

my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('link.html', {
detailed_url => "$LINKS{db_detailed_url}/${$rec}{'ID'}$LINKS{build_extension}",
%$rec,
%$user,
%GLOBALS
}, undef, $template);

But that doesn't work (my Phonenumber field is called Telefon). Also I've tried to change $rec->{'Telefon'} = $Telefon; to $rec->{'Telefoner'} = $Telefon; and then
to insert the tag <%Telefoner%> in my detailed.html template.
But that results in a error: Unknown tag: Telefoner.

What's wrong?

Quote Reply
Re: Phonenumber In reply to
Hi,

If you want your formatted phonenumber in the detailed page, you should insert the code (which works fine) in the :

sub site_html_detailed

regards, alexander

Quote Reply
Re: Phonenumber In reply to
It's actually pretty embarrassing okay
I had to make changes to the sub site_html_detailed
routine if I wanted to use the tag in detailed.html.

Thanks for the help.

Quote Reply
Re: Phonenumber In reply to
I left that line out of my last post... you had to make the changes to two areas -- the site_html_links and site_html_detailed. If you want those available in any other template (I don't think any other template calls for a "link" without using a formatted link via site_html_links) you'd have to do the same before you called that template.

One thing you might consider doing, and it would save a HECK of a lot of time, is to modify the admin-add routine to format the phone number when a link is added, so you have two fields -- Telefon and Telefon_Display. The Telefon would be for searching, and the Telefon_Display would be for for displaying in the links and templates.

It would be available anywhere any of the links would be, and for the "cost" of one more 20 character database field, you save many, many lines of processing and cpu cycles on each build/display.

You could probably even add it to the nph-build.cgi routine, such that each time a link is updated it checks to see if a Telefon field is non-blank, and if so, if Telefon_Display is non-blank, and if so, it ignores it, and if not, it converts the Telefon to Telefon_Display. If you do this in the "new" routine, you'd only have a few "penalties" during a build, and you'd catch all new links as they were added.