(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)
ategories; } else { &html_unauth; } }
elsif ($in{'browse_cat'}) { if ($per_view) { &html_br
owse_cat; } else { &html_unauth; } }
New sub-routine:
# --------------------------------------------------------
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:
# --------------------------------------------------------
# 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:
New Sub-Routine: sub html_browse_cat
* Same as html_home with following additional codes:
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:
==========================================
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.
------------------
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).]
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.
------------------
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).]