Hello ALL,
I just made a field called "News" where i dispay it under the normal desciption field.
Only now i allowed people thought modification.cgi to only change the News!
Only there are 2 buts....
(It works only i would like it to be user-friendlyer)
1)I would the following code to be 1 <ul> listing, but i dont have a clue.
!$in{'ID'} and &site_html_modify_failure ("<ul><li>ID (Required Field)</ul>") and return;
!$in{'News'} and &site_html_modify_failure ("<ul><li>News (Required Field)</ul>") and return;
($in{'Password'} =~ /.+@.+\..+/) or &site_html_modify_failure ("<ul><li>Password (Invalid format)</ul>") and return;
2) But %new is just a copy of %original (out of the database), the only new field he has to check is News ($new{$db_cols[$db_news]})!
BUT Just IF the data in the database was already wrong, now this will flag an error without giving the user possiblity's to correct them!
Like: Title (Too long. Max lenght: 75)
[/code]
# --------------------------------------------------------
my ($key, $status, @values, $found);
local (%original);
local (%new);
# Make sure we have a link to modify.
!$in{'ID'} and &site_html_modify_failure ("<ul><li>ID (Required Field)</ul>") and return;
!$in{'News'} and &site_html_modify_failure ("<ul><li>News (Required Field)</ul>") and return;
($in{'Password'} =~ /.+@.+\..+/) or &site_html_modify_failure ("<ul><li>Password (Invalid format)</ul>") 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[0] eq $in{'ID'}) and ($data[$db_contact_email] eq $in{'Password'})) {
$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
!$found and &site_html_modify_failure ("<ul><li>Password or ID is not identical to what is recorded in our database.</ul>") and return;
# Since we have a valid link, let's make sure all fields are set to their
# proper values. We will simply copy over the original field values.
foreach $key (keys %original) {
$new{$key} = $original{$key};
}
# Set date variable to today's date.
$new{$db_cols[$db_modified]} = &get_date;
# Set new variable to input news.
$new{$db_cols[$db_news]} = $in{'News'};
# Validate the form input..
$status = &validate_record(%new);
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("<ul><li>A request to modify this record has already been received. Please try again later.<ul>");
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(%new);
close MOD; # automatically removes file lock
I just made a field called "News" where i dispay it under the normal desciption field.
Only now i allowed people thought modification.cgi to only change the News!
Only there are 2 buts....
(It works only i would like it to be user-friendlyer)
1)I would the following code to be 1 <ul> listing, but i dont have a clue.
Code:
# Make sure we have a link to modify. !$in{'ID'} and &site_html_modify_failure ("<ul><li>ID (Required Field)</ul>") and return;
!$in{'News'} and &site_html_modify_failure ("<ul><li>News (Required Field)</ul>") and return;
($in{'Password'} =~ /.+@.+\..+/) or &site_html_modify_failure ("<ul><li>Password (Invalid format)</ul>") and return;
2) But %new is just a copy of %original (out of the database), the only new field he has to check is News ($new{$db_cols[$db_news]})!
BUT Just IF the data in the database was already wrong, now this will flag an error without giving the user possiblity's to correct them!
Like: Title (Too long. Max lenght: 75)
Code:
$status = &validate_record(%new);Code:
sub process_form { # --------------------------------------------------------
my ($key, $status, @values, $found);
local (%original);
local (%new);
# Make sure we have a link to modify.
!$in{'ID'} and &site_html_modify_failure ("<ul><li>ID (Required Field)</ul>") and return;
!$in{'News'} and &site_html_modify_failure ("<ul><li>News (Required Field)</ul>") and return;
($in{'Password'} =~ /.+@.+\..+/) or &site_html_modify_failure ("<ul><li>Password (Invalid format)</ul>") 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[0] eq $in{'ID'}) and ($data[$db_contact_email] eq $in{'Password'})) {
$in{$db_key} = $data[0];
$found = 1;
%original = &array_to_hash (0, @data);
last LINE;
}
}
close DB;
!$found and &site_html_modify_failure ("<ul><li>Password or ID is not identical to what is recorded in our database.</ul>") and return;
# Since we have a valid link, let's make sure all fields are set to their
# proper values. We will simply copy over the original field values.
foreach $key (keys %original) {
$new{$key} = $original{$key};
}
# Set date variable to today's date.
$new{$db_cols[$db_modified]} = &get_date;
# Set new variable to input news.
$new{$db_cols[$db_news]} = $in{'News'};
# Validate the form input..
$status = &validate_record(%new);
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("<ul><li>A request to modify this record has already been received. Please try again later.<ul>");
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(%new);
close MOD; # automatically removes file lock