Gossamer Forum
Home : Products : DBMan : Customization :

Making DBMan work with Links2: Category.db

Quote Reply
Making DBMan work with Links2: Category.db
Has anyone made a mod (or have a suggestion) for DBMan code that will read in the Category.db (of links2) and replace the current code in DBMan's .cfg file as close as possible to the way Links2 already handles Category.

I am using DBMan's wonderfull features and currently working on a project that will allow DBMan to marry Links2. However, we are still in the "get acquainted stage" of our relationship Smile and could use a little help to get things moving a little faster Smile

TimRyan
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
You want a script to change the .cfg file in DBMan?


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





Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
I am using the current (not changed by me yet) version of DBMan (still getting familiar with it).

First thing that hit me on display was that the category setup is not the same in dbman as Links2 on how it is handled.

I wanted to make dbman show my current categories I use in my Links2 category.db and some how have it auto display in the dbman forms like it does now in links2.

But there might not be a simple answer to this question.

I know I could go into .cfg and just enter all my categories in there (I think that is where I would do it). But I want to make it so dbman uses as much automation on itself for the categories and other areas as Links2 does.

Actually I was posting this question to see how far anyone else has gotten on such a project before I attempt to do this on my own.

At first glance of dbman I see a simple/nicely done package (not as complex as matt's scripts or others I have used and modified to my needs). Also, the dbman code is very similar to Links2.

I have seen other db's elsewhere that have templates. But, I like the idea of using links2 and dbman to share their own features because they are from the same programmer and that makes them similar in coding too.

Maybe make a new (single merged) links.cfg/dbman.cfg seems logical at this point of my research.

I want to have each package try and maintain their own identities and qualities but share and merge into one where required so there is not double entry/maintanance.

It looks like a very doable project to me so far. Smile

This all started with one of my projects a few years ago I did at http://www.ezinesearch.com. On that project (and many) I used (matt's scripts) dbmanager and did some major mods to it to make it work the way I wanted.

Then just a month ago I stumbled on Links2 and it was "love at first site" Smile ; because I had not fully completed the long term project at http://www.ezinesearch.com and http://www.Refer-Me.com (I had 30 other projects going at the same time).

I have always had the idea on all my projects to allow both "on-the-fly" database access on the user side. PLus, allow me to have html pages generated for search engines and speed on the user side. All fully automated/generated.

I have had this idea for the past 5 years but just to busy and also wanted to see how the web technology matured so I would not have to re-invent the wheel.

That about raps up the history of where I am so far. I have search engines all over the place of one form or the other on the web.

Each project contained a matured version of the original "on-the-fly with html" idea.

Another project I have been working on is "ArticleExpress" for writers to get their works online. That also if very similar and will use the "on-the-fly with html" idea.

That is at: http://homeincome.com/magazines/
for the classifieds part of the project that will eventually be merged/married to the "ArticleExpress" project (now writers-connection also) at: http://homeincome.com/article-express/

The whole concept here is a bit complex. But, the bottom line is that all 24 magazines are created/generated html pages on the fly on both the classifieds and Articles projects.

Sorry to take up so much space here. But I wanted to allow you all to get the full picture of this project and what I had in mind with dbman and links2. I have already spent the month of Research & Developement on mods for links2. Which I will eventually share with others who might need them.

TimRyan


[This message has been edited by TimRyan99 (edited August 09, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
You can access the categories.db file from within DBMan. You can split it into fields and use the data however you want.

What it seems you want to do is to make a select list out of the categories.db file. But you don't need to do that. Just copy the build_select_field_from_db subroutine in DBMan (or maybe Links has one, too) and change the file that it opens. You'd have to do a little work with it, but there's no reason it wouldn't work. It would actually be like a question I answered a couple of days ago about building a select field from a second database. You might be able to find it if you did a search here -- or maybe it was in the other DBMan forum. (I can't get people to limit the other one to installation issues. Smile )



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

It was in the other forum. The discussion (and code) is at http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/001373.html


[This message has been edited by JPDeni (edited August 09, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Thanks for this info. Please feel free to add here, any other ideas and/or threads that you or anyone else think might help me in the project. Smile
TimRyan
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
To keep this type of discussion linked with other Threads, here are some other threads that discusses LINKS and DBMAN Integration:

www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000613.html

http://www.gossamer-threads.com/...m12/HTML/000660.html

BTW: The latter thread is a discussion and mod for validation of records before they become "live" in the database.

Smile

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 10, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
JPD, Thanks for the lead Smile
build_select_field_from_db subroutine

hmmmm... just took a look. We seem to have a choice in the DBman.cgi to use either build_select_field routine (which uses hash array %db_select_fileds in dbman.cfg), or to use build_select_field_from_db subroutine which opens the file named in $db_file_name (db.cfg).

If this is a correct assumption Smile now all I have to do is figure out how the sub build_select_field_from_db works.

Does it pick off a record at a time and use each record as a category? If so, it would seem then all I have to do is state category.db (a links2 category file) as the $db_file_name?

I will take a look and do some debug work Smile
Thanks
TimRyan
PS. Thanks Eliot (nice Smile..


[This message has been edited by timryan (edited August 10, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Tim, did you look at the other thread I mentioned? There's code there for another subroutine -- sub build_select_field_from_other_db -- it's something I wrote for someone. Just copy the code from that thread -- http://www.gossamer-threads.com/scripts/forum/resources/Forum5/HTML/001373.html -- and you should be able to figure it out.


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





Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Thanks JPD, you put me on the right track with that thread. I got it working! Smile and will put the code for others below. NOW, all I have to do is figure out how to make modify pick up the current category field/data. I want to show them what they have but still allow them to change it. Have to think that one over Smile
Heres is the code for what I have so far with for this. If anyone uses this and has problems just post them here.

[Test Code removed and better clarified below]

I did this on the rush so hope I got it all for you folks. Smile If you are not a programmer then I would suggest not attempting this till I am done! Smile
If you want to debug then just take out the # in the debug... I left in.
Thats all so far.
Thanks
TimRyan



[This message has been edited by timryan (edited August 11, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Tim, almost all the code you need is in that other thread. You don't have to change much. I've changed some of the variables to match the names you gave them.

This will pull the values from the categories.db, create a select field and select the value that is already in a field when you modify a record. All you need to do is copy and paste the code below into your script.

Define some variables in your .cfg file:

Code:
# Full Path and File name of the other database file.
$links2_script_path = "C:/Program Files/Apache Group/Apache/htdocs/ArticleExpress/cgi-bin/aex/admin";
$db_file_name_category = $links2_script_path . "/data/categories.db";
 
# Field number of the "Category" field in the other database
$links_categories_field_num = "1";

Add the following to db.cgi

Code:
sub build_select_field_from_categories_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.

my ($column, $value) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
open (DB, "<$db_file_name_category") or &cgierr("unable to open $db_file_name_category. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$links_categories_field_num], @selectfields)) {
push (@selectfields, $fields[$links_categories_field_num]);
}
}
close DB;

$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (sort @selectfields) {
($field eq $value) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";

return $output;
}

If you want to write your own html_record_form, use the following to get your select field:

Code:
<tr><td>Category:</td>
<td> |;
print &build_select_field_from_categories_db("Category",$rec{'Category'});
print qq|</td></tr>

(The above assumes that the code is within a "print qq|" statement.)

If you want to use the autogenerate feature, you need to do things a little differently.

In db.cgi, you have to define the category field. (You may have done that, but you didn't give the code here.) Since there are no options defined in the .cfg file, you have to define the category field differently from the way you define other select fields. I would use

Code:
$db_select_fields_category = 'Category';

Then, in sub build_html_record_form, use

Code:
if ($db_select_fields_category eq $field) { $output .= "
<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%>" . &build_select_field_from_categories_db($field,$rec{$field}) .
"</td></tr>";
}
elsif ($db_select_fields{$field}) {
$output .=
"<tr><td align=right valign=top
width=20%><$font>$field:</font></td><td width=80%>" .
&build_select_field($field,
$rec{$field}) . "</td></tr>";
}

I would have tried to edit what you had, but I found it difficult to follow.


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


[This message has been edited by JPDeni (edited August 11, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Thanks JPD,
I removed my code above so we did not have duplicates in this thread that would confuse others. Your code with my variables helped a lot and works fine. However, I did notice on testing that category field printed twice. Once as a select field (as it should) and again as a plain box field (as it should not) Smile SO, I changed the "IF" to "elsif" Smile

___________db.cgi__________

if ($db_select_fields_category eq $field) {$output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field_from_categories_db($field,$rec{$field}) . "</td></tr>"; }

## the below code had "if" so I changed to elsif...
elsif ($db_select_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}) . "</td></tr>"; }

elsif ($db_radio_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_radio_field($field, $rec{$field}) . "</td></tr>"; }

elsif ($db_checkbox_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_checkbox_field ($field, $rec{$field}) . "</td></tr>"; }

elsif ($db_form_len{$field} =~ /(\d+)x(\d+)/) {
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><textarea name="$field" cols="$1" rows="$2">$rec{$field}</textarea></td></tr>~; }

elsif ($db_form_len{$field} == -1) { $output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~; }

elsif ($db_form_len{$field} == -2) { $per_admin ? ($output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$field" value="$rec{$field}" maxlength="$db_lengths{$field}"></td></tr>~) :
($output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~); }

else { $output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$field" value="$rec{$field}" size="$db_form_len{$field}" maxlength="$db_lengths{$field}"></td></tr>~; }
}

_____________________

On testing, for some reason "add" does not pass category (Category (Can not be left blank) I will have to see why that is not getting passed there. Still testing Smile

UPDATE:..
(hehe... you did the same thing I did on my first code attempt). We have to pass the $name (or make it equal to $column like the original routine. I will have to look closer to see just what we should do Smile

$output = qq|<SELECT NAME="$name"><OPTION>---|;

$name is "" Smile

UPDATE:
Had to change/add these lines like they where in the original ...sub build_select_field_from_db

sub build_select_field_from_categories_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
_______________-change this....
my ($column, $value) = @_;


________________to this...___

my ($column, $value, $name) = @_;
$name | | ($name = $column);
_______________________

This works now Smile

Do you know what the "| |" says in the code above? My testing shows the code is setting $name = $column... but not sure what the rest says..

Thanks
TimRyan



[This message has been edited by timryan (edited August 11, 1999).]
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Okay. Smile

I'm not sure I quite followed all that, but if it works, that's fine.

The &#0124; &#0124; (which will have a space in the middle on UBB, but shouldn't have a space in your script) means "or." There's a slight difference between the two, but you can pretty much use them interchangeably. I think the difference has to do with priority of actions, which probably won't come into play.

I tend to use "or" these days (thank you, Eliot for suggesting it!) when I post to the board because otherwise people get syntax errors when they try to copy and paste code.


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





Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Thanks to both of you for working this out. It is appreciated. Now, not to be a thankless imp, but would you mind making a final post with the complete code? Thanks!

------------------
Kevin D
www.greeknet.net
webmaster@greeknet.net



Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
No problem with the "or", JPDeni. It is an easier code to use. Although I have not tested it with earlier versions of Perl (e.g., 4.0). But most ISPs and web servers tend to keep updated modules and software.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Kevin, I've edited the code from my posted 08-10-99 10:06 PM PST post to account for the problems Tim ran into. It should be fine now.

Eliot, I'm not even going to think about any earlier versions of Perl. Smile

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





Quote Reply
Re: Making DBMan work with Links2: Category.db In reply to
Kevin D, and anyone else who cares to try Just go to this thread:

http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000693.html

Hope this helps Smile
TimRyan


[This message has been edited by timryan (edited August 12, 1999).]