Gossamer Forum
Home : Products : DBMan : Installation :

Using an alternative to html_record for viewing records

Quote Reply
Using an alternative to html_record for viewing records
Hi,
sub html_record defines how your records are displayed when you view them. I've got it setup pretty much the same way it was in the demo because I like that layout.

However I'd like to have a second layout for viewing records. Why? Because I wana create a web page that I can save localy as a text file, and from that file import the data into excel or access. That's why I wana define a second layout; one that can easily be recognized as a database by excel or access.

I've tryed to do find a way to do the import in only one step but had no luck.
So my next option is to use 2 steps and make them as simple as possible.

I'm hoping someone can put me on the right track for creating a sub that dosn't use html_record for the layout but has it's own layout. And then how do I make calls to that sub?

I already know the layout I will use. The page dosn't have to work with any filtering options, because I only need to use this layout to display all the records.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
Hi,
If you read this JPDeni, I've read your reply about this in the other forum. I know I can just download the file and rename it with a txt extension.

But I'd like to create another html document for this because it will make things a little bit easier. If I'm creating another document I might as well make one that is also easy to read on screen.

The import process is a big factor in how much this system will be appreciated.

Thanks
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
So you just want to print out the raw data in a delimited file format?

You could just load in the .db file, save it to a directory with a .txt extension and have an admin-only link that would call up the file. Then you could save it to your computer and import it into Access.


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





Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
hmmmmmm.....I'm not sure i fully understand your suggestion.

I'd like to put my data in a web page using a one row table so the fields would appear one after the other one and each line would be a record. Nothing else in the page no tags , no other text: just raw data.

I could then "save as txt" to my hard drive trough my browser. This way I download and rename the file in one shot as opposed to downloading and then changing the extension. Plus downloading the file with the browser is easier and faster then with ftp.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
JPDeni,
If you're saying that there is a way within DBMan of making a text copy of the data, that's of great interest for me.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
That's a good way to do it, Adam. Probably the best way.

luc, I can see why you had trouble. I said

Quote:
Instead of

$db_file_name = $db_script_path . "/default.db";

use

$db_file_name = "/path/to/public/directory/default.db";

and you did

Quote:
$db_file_name = $db_script_path . "http://www.wathever.com/tdata/default.db";

That definitely won't work. If you wanted to use my suggestion you have to get rid of

$db_script_path .

and use the path and not the url to the directory.

However, Adam's subroutine is probably a whole lot better to use.


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





Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
luc_a,

If you just want to view your complete database and then download it, there's no need to have db.cgi output it as records, or even to save it as .txt, since unless you've set up a handler on your server for .db files, your browser will just display it as text. Just add the following in sub_html_footer, or wherever your navbar goes:

print qq!| <A HREF="$db_dir_url/default.db">Show DB</A> ! if ($per_admin);

This presumes you have a standard dbMan setup, and your $db_file_name is default.db. If you have a different file name, or added path information in $db_file_name, you'll have to change it accordingly.

If you *need* to make a copy of default.db, you can write a routine to do that, but I don't see any need here.

Cheers,
adam
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
....it dosn't work: i get a message saying I'm not authorized to view that page.

I havn't chaged anything yet in the file names and paths. I also tried $db_script_path because that's how it reads in my cfg and I got the same results. Maybe this is because of the server security?

I realy appreciate the help, if you think of anything else please reply.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
I tried to look directly at a .db file in my cgi-bin, too, but I got the same results as you did, luc. But you can just directly access the file if it's in a regular webpage directory -- the directory where you place your html files.

You'll need to get the server path to the directory where you want to save the file. This is not the URL of the directory, although you'll need that, too.

I don't know if it would work, but you might be able to just change the path in the .cfg file. Instead of

$db_file_name = $db_script_path . "/default.db";

use

$db_file_name = "/path/to/public/directory/default.db";

You would have to make sure you moved your .db file to that directory before you tried running DBMan, and you'd have to change the file permissions so you could write to the file, but I think it would work. (I'm not promising anything! Smile )

If that works, you then could add a link to your sub html_footer

print qq!| <A HREF="http://URL/to/default.db">DB File</A> ! if ($per_admin);

Clicking on the link would display the raw data which you could save from your browser or right-clicking the link (assuming you're using a PC and not a Mac) would let you save the file with any name you want.

If, for some reason that doesn't work, you can still accomplish the same thing by adding some lines to the db.cgi file. Every time there is a change to the .db file, you'd save it to both your cgi-bin and your public directory.

But try the above first. (Make sure you have backups of everything on your site, just to be safe! Smile ) If it doesn't work, let me know and I'll show you the places where you'd need to add lines in the db.cgi file.



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





Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
It dosn't work. I edited the cfg file as such:

$db_file_name = $db_script_path . "http://www.wathever.com/tdata/default.db";

I gave the tdata directory and the db file 777 permission.

I get a CGI error message:

Error Message : error in search. unable to open database: .http://www.wathever.com/tdata/default.db.
Reason: No such file or directory

I've been trying a few different ways of relocating my files this morning and it seams that the only thing that works is putting everything in the root of my bin directory.

Note: I've used a fake the domaine name for this post because i'm doing this work for a company.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
*heh heh heh* We'll get there eventually! First off, the reason Carol's suggestion didn't work is because you used a URL. You should have used a path.

And I'm sorry about my previous post, my server lets me view files in the cgi-bin.

Now, here's another way of doing it, without having to create a file. Open db.cgi and up the top, just above "# If we are using benchmarking", add this line:

Code:
if ($ENV{'QUERY_STRING'} eq "viewdb") { &viewdb; }

Now, right down the bottom, after the error subroutine, add this subroutine:

Code:
sub viewdb {
open (DBFILE,"$db_file_name") | | &cgierror("Can't access database file - $db_file_name");
@dblines = <DBFILE>;
close(DBFILE);
print "Content-type: text/plain\n\n";
foreach $dbline (@dblines) {
print "$dbline";
}
exit;
}

And in html.pl, change the line I previously posted to:

print qq!| <A HREF="$db_script_url?viewdb">View DB</A> ! if ($per_admin);

What this will do is print your database as text to your browser, which you can then save as a .txt file. I've tested it on a local database and it works, but if you have any problems gimme a shout. I've also created a script that will copy the database file to a web accessible directory, but you shouldn't be needing that now.

Cheers,
adam

[This message has been edited by dahamsta (edited April 30, 1999).]
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
maybe I should mention how I setup the directory of dbman in my cfg:

$db_dir_url = "http://www.wathever.com/bin/";
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
Yeeeeeaaaaaaaahhhhhhh!!!!!!

I tried Adams suggestion but the program wouldn't work anymore. Perhaps i did something wrong. I'll retry that way to see what it looks like.

Paths are still a bit confusing for me. When I retried Carols suggestion I got a CGI error message but this time I bothered looking at the whole page. Bellow the message was a list of "environment variables". The first one was called DOCUMENT_ROOT. I used the path it indicated and it finally worked.

One last question : should I leave the permissions to the directory and data file set to 777?

This is realy great! Having my data accessible trough a web page means I'll probably be able to import the data to Access in only one step! I'll keep you posted on that.

.....now i can post my next topic hehehe =)
Thanks Carol and Adam and anyone else who followed the saga.
Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
You can probably set the permissions to 666, since you won't be doing any executing of the .db file, just reading and writing to it.

I think the reason Adam's script didn't work is the &#0124; &#0124; in the script. For some reason, UBB adds a space between them. If you just copied the script, you would have gotten the space -- and a CGI Error. Smile If you'd like to use it, just take out the space between the two | characters.

I set up a macro for someone to be able to import the file into Access. It's not hard once you get the specs for the file structure set up.

I'm glad it worked for you. This thread just goes to show there's more than one way to do a lot of things in DBMan. Smile

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





Quote Reply
Re: Using an alternative to html_record for viewing records In reply to
One final point on this topic, that I forgot to mention. If you use my mod, you can have the browser automatically pop a "Save As..." box by changing the line:

print "Content-type: text/plain\n\n";

to:

print "Content-type: text/save\n\n";

*gone*