Gossamer Forum
Home : Products : DBMan : Installation :

Categorical and Record Number Mod Needed: For Classified Ads

Quote Reply
Categorical and Record Number Mod Needed: For Classified Ads
(Note: Per JPDeni's request, I am starting a new Topic. Sorry if this seems redundant.)

I tried installing the mod located in the Classifieds Topic into my Classified Ad program. It is not working that well. I am able to get a listing of categories.

I am using the following codes:

1) In default.cgi - (sub main)

Code:
elsif ($in{'list_categories'}) { if ($per_view) { &html_list_c
ategories; } else { &html_unauth; } }
elsif ($in{'browse_cat'}) { if ($per_view) { &html_br
owse_cat; } else { &html_unauth; } }

New sub-routine:

Code:
sub urlencode {
# --------------------------------------------------------
my($toencode) = @_;
$toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$toencode=~s/\%2F/\//g;
return $toencode;

}

2) In html.pl file:

New Sub-Routine:

Code:
sub html_list_categories {
# --------------------------------------------------------
# This sub-routine lists categories.

for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Category field defined");
}
if ($in{'Category'}) {
$page_title = "$in{'Category'} sub-category listing";
&html_print_headers;
&html_top_header;
$found = 0;
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Subcategory" ) {
$fieldnum2 = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Subcategory field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_
file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum] eq $in{'Category'}) {
if (!(grep $_ eq $fields[$fieldnum2], @selectfields))
{
push (@selectfields, $fields[$fieldnum2]);
}
}
}
close DB;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&Category=$in
{'Category'}
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}
}
else {
$page_title = "Category Listing";
&html_print_headers;
&html_top_header;
open (DB, "<$db_file_name") or &cgierr("unable to open $db_
file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum] eq $in{'Category'}) {
if (!(grep $_ eq $fields[$fieldnum2], @selectfields))
{
push (@selectfields, $fields[$fieldnum2]);
}
}
}
close DB;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&Category=$in
{'Category'}
&Subcategory=$sfield&view_records=1">$field</a></font><BR>|;
}
}
else {
&html_print_headers;
&html_top_header;
open (DB, "<$db_file_name") or &cgierr("unable to open $db_
file_name. 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[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;
foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categor
ies=1&Category=$sfield">$field</a></font><BR>|;
}
}
&html_footer;
&html_bottom_footer;
}

Link in html_home:

Code:
<A HREF="$db_script_link_url&browse_cat=1">Browse Categories</A>

New Sub-Routine: sub html_browse_cat

* Same as html_home with following additional codes:

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierror("No Category field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. 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[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&list_categories=1&Category=$sfield">$field</a></font><BR>|;
}

However, when I click on a category, I get the following error message:

Code:
CGI ERROR
==========================================
Error Message : fatal error: Undefined subroutine &main::cgierror called at /mnt/web/guide/anthrotech/cgibin/classifieds/ads/html.pl line 414, chunk 4.

Script Location : /mnt/web/guide/anthrotech/cgibin/classifieds/ads/index.cgi
Perl Version : 5.00404
Setup File : default.cfg
User ID : default
Session ID : default

Form Variables
-------------------------------------------
Category : Business
db : default
list_categories : 1
uid : default

I know that the problem could be attributed to the lack of "sub-categories". How do I create a simple category listing that will only include "Category" with no sub-categories? Also what are the codes to add number of records next to each category. I am using more complex codes in another database program. But it would be nice to install this mod and have it work with numbers of records added to each Category.

To see an example, go to:

anthrotech.com/cgibin/classifieds/ads/index.cgi?db=default&uid=default&browse_cat=1

TIA.

Smile

------------------
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 04, 1999).]

[This message has been edited by Eliot (edited August 04, 1999).]
Quote Reply
Re: Categorical and Record Number Mod Needed: For Classified Ads In reply to
It isn't redundant at all. It saves me a lot of time in waiting for the whole thread to load and scrolling to the bottom of the page. It also keeps me from getting *too* confused! Smile

There are two reasons you're getting the error. One is my fault. You need to change the lines that refer to

&cgierror

to

&cgierr

Typo. Sorry.

The other reason is that you don't have a subcategory defined. If you did, you wouldn't be getting the call to the error subroutine in the first place.

Looks like you can delete the entire sub html_list_categories subroutine and the reference to it in db.cgi, sub main. It would make sense to just go with sub html_browse_cat.

Here's the code I would try:

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_cols[$i] eq "Category" ) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
&cgierr("No Category field defined");
}
open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. 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[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
++$count{$fields[$fieldnum])};
}
close DB;

foreach $field (sort @selectfields) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&view_records=1&
Category=$sfield">$field</a>: $count{$field}</font><BR>|;
}

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





Quote Reply
Re: Categorical and Record Number Mod Needed: For Classified Ads In reply to
Thanks, Carol. I will try that tonight when I get home...I know it is confusing. See, I use DBMAN and LINKS for a variety of projects at home and office. This issue relates to a side project at home, so I have to wait until I get home to test it. Frown

Side Note:

Quote:
It saves me a lot of time in waiting for the whole thread to load and scrolling to the bottom of the page.

With regards to scrolling...I really think Alex should consider upgrading to the recent versions of BBS. I have version 5.31 (soon to upgrade to 5.35) running on my site. It provides better navigation options, including spanning responses within Topics. Also, it allows moderators to post announcements in their forums.

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: Categorical and Record Number Mod Needed: For Classified Ads In reply to
Okay, Carol...Making progress! Smile

I am know able to get a categorical listing with record numbers. (Part of my problem was that I recently shortened arguments to make the URL shorter. For instance, I changed view_records to vr.) But it works great.

Thanks for your assistance.

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: Categorical and Record Number Mod Needed: For Classified Ads In reply to
Hi there.

Just wanted to let y'all know that there is a minor syntax error in this particular mod.

In the linking portion (foreach loop), the current codes does create a categorical listing, however, if there is a null field in the "Category" variable, then it will print the number of null fields and associated record count.

Example:

Code:
: (12)

So, I have edited the foreach loop to the following:

Code:
|;
foreach $field (sort @selectfields) {
if ($sfield eq "") {
print qq| |;
}
if ($sfield = &urlencode($field)) {
$sfield = &urlencode($field);
print qq|<$font><a href="$db_script_link_url&view_records=1&ID=*&Category=$sfield&Status=Yes&sb=1&so=descend">
$field</a>:</font> <$smfont>(<font color="ff0000">$count{$field}</font> )</font><BR>|;
}
}
print qq|

Hope this helps anyone who may read this Thread in the future! 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 17, 1999).]

[This message has been edited by Eliot (edited August 17, 1999).]

[This message has been edited by Eliot (edited August 17, 1999).]