Gossamer Forum
Home : Products : DBMan : Customization :

Export added record to file (web-page)

Quote Reply
Export added record to file (web-page)
Here's another one ..

How would one, when a record is being inserted/added, export the 'result' of that addition to an HTML page. Or in other words how can teh output of sub html_add_success be written to a file.

TIA
Michael

------------------
Michael De Coninck
C-Ware IT Consultants
http://www.c-ware.net
Quote Reply
Re: Export added record to file (web-page) In reply to
Well, the record is written to a file already -- the .db file. You want to create a separate file for every record that is added?

I suppose you could do that. This would be the process:

1-- Open the file for writing.
2-- Set up the format for the file, using variables for the field values.
3-- Close the file.

I guess the first thing to ask is how do you want to name the file? And then, what is the format of the file that you want to write?


------------------
JPD





Quote Reply
Re: Export added record to file (web-page) In reply to
Dear JPD,

Thanks for the fast response ... how would we manage without you :-)

I know the data is in the DB but what I would like to do is generate an individual html file called index_001.html where 001 is the ID of the record. The format would be html.

I am fiddling with it as I write so what I have come up with is to insert the following code in the sub html_add_success.

open (DB, ">testfile.html");
flock(DB, 2);
print DB &html_print_headers;
print DB "<HTML>";
print DB "<HEAD>";
print DB "<title>$html_title: Record added.</title>";
print DB "</head>";
print DB "<body bgcolor=\"white\">";
print DB "<center>";
close DB;

Is this somewhere in the right direction ?

TIA

Michael

------------------
Michael De Coninck
C-Ware IT Consultants
http://www.c-ware.net
Quote Reply
Re: Export added record to file (web-page) In reply to
Yep. You're on the right track.

Personally, I would use the print qq| structure so I wouldn't have to escape the quotation marks, but it's perfectly fine to do it the way you are.

You can use the %in hash to print out your fields -- $in{'fieldname'}[/b].

So, if your key value is going to be used as the name of the file, you can use

open (DB, ">/path/to/directory/$in{$db_key}.html");

You might want to use a different handle for your file. Instead of DB, use something else. I don't know if it will make a difference, but it might.


------------------
JPD





Quote Reply
Re: Export added record to file (web-page) In reply to
What I did was create a different html.pl, .cfg file etc and link it to the same database as the one I wanted to publish. I used the list all facility to create a 'view' of all the records hence submitting everything in one go without rewriting a whole program around it ... That did the trick for me ... I guess with a little bit of work one could make a self contained script which would do that but I'm off the hook for the moment :-)

Originally I placed the subroutine in the modify_success and add_success subroutines so each time something was changed the page would be recreated and resubmitted. This way you don't get an overload on the server or the chance of being kicked out of the index for oversubmitting.

Mike
Quote Reply
Re: Export added record to file (web-page) In reply to
In the sub_add_success I added

&file_export($db_key);

where the sub file export refers to the following code

Code:

sub file_export {
# --------------------------------------------------------
# Create the file for indexing
%rec = &get_record($in{$db_key});

#create html on server as file
open (export, ">/www/miniprix/jobpages/index_$in{$db_key}.html");
text/html\n\n|;
print export qq|
<HTML>
<HEAD>
<title>Jobs in $rec{'Cou'} $rec{'Cit'} $rec{'Pos'}</title>
<META NAME="Keywords" CONTENT="$rec{'Pos'}">
<META NAME="Description" CONTENT="$rec{'Des'}">

</head>
<body bgcolor="white">
<center>
<TABLE bgcolor="white" cellspacing=3
....
</center>
</body>
</html>
|;

close export;

}

Now this works fine when using an add record.
What I would like to do too is to be able to trigger the subroutine when a record is viewed in html record. But somehow (and it is confusing me the function always returns an empty record.

Probably the problem is in how the
&file_export([param]);
has to be called but I can't figure out what it should be.

Any help would be greatly appreciated.

TIA

Michael

------------------
Michael De Coninck
C-Ware IT Consultants
http://www.c-ware.net
Quote Reply
Re: Export added record to file (web-page) In reply to
MichaelDC,

I am very interested in this concept, but I am having trouble identifying the real benefits of doing this. How do you apply this to your use of DBman....?
Quote Reply
Re: Export added record to file (web-page) In reply to
Hi WebDog

The reason for this is that pages run from db.cgi can not be submitted to a search engine like e.g. altavista.

I wanted to generate the pages as html so that I could submit them.

Which BTW is working since let's say 10 minutes.
Quote Reply
Re: Export added record to file (web-page) In reply to
Michael,

Ok,...I suppose this would apply also if you have a search engine on your site.
Hmmmm....
I wonder if you could write a subroutine to dump every record in an existing database to HTML files......?
Quote Reply
Re: Export added record to file (web-page) In reply to
I have that up and running after a looong day's work :-) ... it is dumping (500+ pages in a few minutes

[This message has been edited by MichaelDC (edited October 05, 1999).]
Quote Reply
Re: Export added record to file (web-page) In reply to
Michael,

Would you care to post the sub you used ... as soon as you have recovered .. ? Smile
Quote Reply
Re: Export added record to file (web-page) In reply to
Here it is .... have I recovered ? :-)

Code:
sub file_export {
# --------------------------------------------------------
# Create the file for indexing
my %rec = @_;

#create html on server as file
open (export, ">/path/to/your/server/location/index_$rec{'ID'}.html");
#print export qq|Content-type: text/html\n\n|;
print export qq|
<HTML>
<HEAD>
<title>Jobs in $rec{'Cou'} $rec{'Cit'} $rec{'Pos'}</title>
<META NAME="Keywords" CONTENT="$rec{'Pos'}">
<META NAME="Description" CONTENT="$rec{'Des'}">

</head>
<body bgcolor="white">
............
</body>
</html>
|;

close export;

}

The sub itself is called from the html_view sub. I put it at the end but you can put it anywhere you like in there. just check that the %rec is filled with data.

&file_export(%rec);

Greetz

------------------
Michael De Coninck
C-Ware IT Consultants
http://www.c-ware.net
Quote Reply
Re: Export added record to file (web-page) In reply to
I actually wanted a sub that would go through the database and dump each record to a html file.....one process; not everytime a record is added or viewed.

Have you done a routine like this as well...?
Quote Reply
Re: Export added record to file (web-page) In reply to
Hello,
I saw your dbman sub add-on : DBMAN to HTML Files.
I use this, but your sub doesn't export any data.
In fact, i would to export every record in an existing database to HTML files (with ID values like files names.)

have you tips about this problem ?

your add-on with my config :

sub file_export {
# --------------------------------------------------------
# Create the file for indexing
my %rec = @_;
#create html on server as file
open (export, ">index_$rec{'ID'}.html");

#print export qq|Content-type: text/html\n\n|;
print export qq|

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>$rec{'ID'}</title>
<meta http-equiv="KEYWORDS" content="$rec{'ID'}">
</head>
<body>
$rec{'ID'}
</body>
</html>
|;
close export;
}

and in html_view_success :

for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
&file_export(%rec);
}

thanks,

Stephane


---------------------------------------------------------------------
Stéphane Pouyllau

UMR AUSONIUS - Institut de Recherche sur l'Antiquité et le Moyen Age
Centre de Compétence Thématique du CNRS :
"Stratégie d'informatisation des données en Archéologie"

Maison de l'archéologie
Université Michel de Montaigne - Bordeaux 3
33607 Pessac Cedex
France

WWW : http://www-sira.montaigne.u-bordeaux.fr
Recherche : http://www-sira.montaigne.u-bordeaux.fr/boisset/
Webcam : http://www-sira.montaigne.u-bordeaux.fr/webcams

E-mail : Stephane.Pouyllau@montaigne.u-bordeaux.fr
Tél. : +33 (0) 557 124 452
Fax : +33 (0) 557 124 550
ICQ : 57532564
----------------------------------------------------------------------



-----
Stephane Pouyllau
AUSONIUS (Archaeology labs)
33607 Pessac
France