Gossamer Forum
Home : Products : Links 2.0 : Discussions :

No links in top categories

Quote Reply
No links in top categories
Hi, Im currently trying to stop sites being added to my top level categories, I have got this working by using this code in add.cgi from a previous forum thread :

Code:
if ($in{'Category'} !~ "/") {
&html_add_failure ("You must choose a more specific topic!");
return;
}


My problem is I need to get the same check to occur in modify.cgi and am not sure how to amend the code and where to place it, any ideas please? Below is my Sub Process_Form from modify.cgi (I am also using a modify password mod) :

Code:
sub process_form {
# --------------------------------------------------------
my ($key, $status, @values, $found);
local (%original);

# Make sure we have a link to modify.
!$in{'Current URL'} and &site_html_modify_failure ("did not specify link to modify") and return;

# Let's check to make sure the link we want to update is actually
# in the database.
open (DB, "<$db_file_name") or &cgierr("error in validate_records. unable to open db file: $db_file_name. Reason: $!");
$found = 0;
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[$db_url] eq $in{'Current URL'}) {
$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
!$found and &site_html_modify_failure ("link was not found in the database") and return;

# Since we have a valid link, let's make sure the system fields are set to their
# proper values. We will simply copy over the original field values. This is to stop
# people from trying to modify system fields like number of hits, etc.
foreach $key (keys %add_system_fields) {
$in{$key} = $original{$key};
}
# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;

# Validate the form input..
$status = &validate_record(%in);
if ($status eq "ok") {
# First make sure the link isn't already in there.
open (MOD, "<$db_modified_name") or &cgierr ("error opening modified database: $db_modified_name. Reason: $!");
while (<MOD>) {
chomp;
@values = split /\|/;
if ($values[0] eq $in{$db_key}) {
close MOD;
&site_html_modify_failure("A request to modify this record has already been received. Please try again later.");
return;
}
}
close MOD;




# Print out the modified record to a "modified database" where it is stored until
# the admin decides to add it into the real database.
open (MOD, ">>$db_modified_name") or &cgierr("error in modify.cgi. unable to open modification database: $db_modified_name. Reason: $!");
flock(MOD, $LOCK_EX) unless (!$db_use_flock);
print MOD &join_encode(%in);
close MOD; # automatically removes file lock




# Send the admin an email message notifying of new addition.
&send_email;
# Send the visitor to the success page.
&site_html_modify_success;
}
else {
# Let's change that error message from a comma delimted list to an html
# bulleted list.
&site_html_modify_failure($status);
}
}


Any help greatly appreciated,

grant
Quote Reply
Re: [grantw] No links in top categories In reply to
Just below:

>>
# Make sure we have a link to modify.
<<

..should be ok.

I would change the code to:

Code:
if (index($in{'Category'}, '/') > -1) {
return &html_add_failure ("You must choose a more specific topic!");
}

...usign index() will be quicker than a regex.
Quote Reply
Re: [Paul] No links in top categories In reply to
Cheers Paul, much appreciated, here is the final code I put into add.cgi and modify.cgi for anyone else wishing to do this :

if (index($in{'Category'}, '/') < 1) {
return &site_html_add_failure ("You must choose a more specific category!");
}

You will also need to amend site_html_templates (sub site_html_add_failure) to enable the submitter to rechoose the category.
Quote Reply
Re: [grantw] No links in top categories In reply to
That's a -1 not 1 and a > not a < :)

Last edited by:

Paul: Mar 17, 2003, 6:41 AM
Quote Reply
Re: [Paul] No links in top categories In reply to
There is a mod out there (somewhere...) which changes the dropdown list, and the top-level categories will not be listed, so cannot be selected. You have to enter the top-level cat names in a list (cat1, cat2, etc) as part of the mod, but it works fine...


Leonard
aka PerlFlunkie