Gossamer Forum
Home : Products : DBMan : Customization :

Pleassse Help - Autodelete Mod Error

Quote Reply
Pleassse Help - Autodelete Mod Error
I have installed all the required mod and tested to be successful. I decided to add the autodelete mod and immediately after uploading Error 500 came out. I tried to figure out the problem for two days but was no avail. Anybody can help ?

I am using User-friendly html with format.pl. I have only done exactly what was mention in autodelm.text only. Could I missed out something else ?

ERROR 500
----------------------------------------------------
syntax error at conf.cgi line 277, near "next"
BEGIN not safe after errors--compilation aborted at conf.cgi line 1312.

-----------------------------------------------------

This is what I have added

AUTH.pl
-----------------------------------------------------
if (($in{'userid'} eq $userid) && (crypt($in{'pw'}, $pw) eq $pw)) { srand( time() ^ ($$ + ($$ << 15)) ); # Seed Random Number
$db_uid = "$userid." . time() . (int(rand(100000)) + 1);# Build User Id
open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
print AUTH "$uid: $ENV{'REMOTE_HOST'}\n";
close AUTH;
&auto_delete; #### added for autodelete mod

foreach (0 .. 3) { $permissions[$_] = int($permissions[$_]); }
&auth_logging('logged on', $userid) if ($auth_logging);
return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}
}


CONFIG FILE (AUTOS.CFG)
-----------------------------------
Validated => [18, 'alpha', 0, 3, 1,'No', 'Yes|No'],
Modified => [19, 'alpha', 0, 3, 1,'No', 'Yes|No'],
Expires => [20, 'date',15, 15, 0, &get_date,'\d{2}\/\d{2}\/\d{4}'],
ADStart => [21,'date',15,15,0, &get_date, '\d{2}\/\d{2}\/\d{4}'],
Remove_by => [22,'date',20,15,0, &get_date(time + 172800), '\d{2}\/\d{2}\/\d{4}'] ## set for 1 day after expires date.

);


DB.CGI
-----------------------
sub main
--------------
elsif ($in{'forward_email'}){ &forward_email; }
elsif ($in{'auto_delete'}) { if ($per_admin) { &auto_delete; } else { &html_unauth; } } ### autodelete
elsif ($in{'logoff'}) { &auth_logging('logged off') if ($auth_logging);

------------and-------------
sub validate_records
--------------------------
print MAIL $email_message;
close (MAIL);
$rec{'Validated'} = "Yes";
$rec{'ADStart'} = &get_date(); ## change start date to date validated
$output .= &join_encode(%rec);}
else { $output .= $line . "\n" } }
foreach $key (keys %delete_list) {

------------and-----------
sub add_record
--------------------
(!$per_admin) and ($in{$db_validated_field} = "No");
$status = &validate_record;
&calc_expire_date; #### increment expires field
&calc_remove_date; #### increment removeby field

while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);

---------and---------
sub modify_record
-----------------
if ($auth_user_field >= 0 and (!$per_admin or !$in{$db_cols[$auth_user_field]})) {
$in{$db_cols[$auth_user_field]} = $data[$auth_user_field];
}
&calc_expire_date; #### increment expires field
&calc_remove_date; #### increment removeby field

$output .= &join_encode(%in);
$found = 1; }
else { $output .= $line . "\n"; # else print regular line.
}}

------------and---------
ADDED new sub

sub calc_expire_date {
#---------------------------
# 24 hours =86400 30days=2592000
my ($temp_date);
$temp_date = &date_to_unix($in{'ADStart'});
$temp_date = $temp_date + ($in{'duration'}*86400);
$in{'Expires'} = &get_date($temp_date);
}

sub calc_remove_date {
#------------------------
my ($temp_date);
$temp_date = &date_to_unix($in{'Expires'});
$temp_date = $temp_date + ($in{'Expires'}+86400);
$in{'Remove_by'} = &get_date($temp_date);
}

sub auto_delete {
# ------------------------------------------
# Automatically removes entries older than a predetermined date
foreach $db (@autodelete) {
my ($removeby_field,$dateadded_field,$db_file_name) = split /\|/, $db;
my $today = &date_to_unix(&get_date);
my (@lines, @values);
print "Content-type: text/html\n\n <PRE>"; # Print headers.
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
print "Comparing: '$today' vs '$values[$removeby_field]' ... \n";
if ($today > (&date_to_unix($values[$dateadded_field]) + (86400 * $values[$removeby_field]))) {
if ($today > ($today -(86400 * $values[$removeby_field])) {
print "Deleting\n";
next; #line 277
}
print DB $_, "\n"; }
close DB; }
}

----------------------END-------------
CHANGES
sub get_date {
# --------------------------------------------------------
my ($time1) = $_[0];
($time1) or ($time1 = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
++$mon;
($mon < 10) and ($mon = "0$mon");
($day < 10) and ($day = "0$day");
$year = $year + 1900;
return "$mon/$day/$year"; }

sub date_to_unix {
# --------------------------------------------------------
my ($date) = $_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($min and $day and $year) { return undef; }
use Time::Local; #line 1312
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}


LASTLT I've add

FORMAT.PL
--------------------
# Autodelete Time
@autodelete[0] = '22|20|autos.db';


Please advise whether I've missed out anything ? I have search the forum and visited the require forum reference in http://gossamer-threads.com/perl/forum/showflat.pl?ubb=002837:Forum12
but I still can't solve the problem.

Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
This line could be a problem (in autos.cfg):

Remove_by => [22,'date',20,15,0, &get_date(time + 172800), '\d{2}\/\d{2}\/\d{4}'] ## set for 1 day after expires date.

It's probobly not a good idea to have comments in a hash like that... try removing it, see if that helps.

I'm too sure about that &get_date(time + 172800) bit either... but I'm not positive... try leaving the default value blank if you're desperate.

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Thanks Mark,

I will try it out and inform you whether it works.

Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Hi Mark,

I just tested it out. I even tried changing all &get_date in the default to '' to test thing out. Doesn't work neither. Error still the same message.
---------------
After modification of cfg file

Expires => [20, 'date', 15, 15, 0, '', '\d{2}\/\d{2}\/\d{4}'],
ADStart => [21,'date', 15, 15, 0, '', '\d{2}\/\d{2}\/\d{4}'],
Remove_by => [22,'date', 20, 15, 0, '', '\d{2}\/\d{2}\/\d{4}']


In this case I am quite possitive that there are problems in the db.cgi autodelete new sub. Any new advise ?

Thanks. It's quite late now 8.00pm. I am going home. Continue tommorrow.


Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Keep the comments lines in tact .. they should never make a difference and help you to keep track of what is doing what.

Also your dates were fine as originally posted as i use them exactly as stated in the mod.

I noticed in my database I'm using the following for the auto delete sub, try changing to this one, and let me know if everything then works okay. If so, I'll change the autodelm.txt file to show the change.


sub auto_delete {
############ Automatically removes entries older than a predetermined date.#

foreach $db (@autodelete) {
my ($removeby_field,$dateadded_field,$db_file_name) = split /\|/, $db;
my $today = &date_to_unix(&get_date);

my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
if ($today > (&date_to_unix($values[$dateadded_field]) + (86400 * $values[$removeby_field]))) {
next;
}
print DB $_, "\n";
}
close DB;
}
}


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Hi LouisC,

Thanks a lot. There is no Error 500 but I've been receiving the following errors trying to add information to the databse. Date (Invalid format).

In addition : There were also the following: Expires (Invalid date format), ADStart (Invalid date format) and Remove_by (Invalid date format).

Please correct me if I am wrong: does it mean I have to include the following hidden field in the add form and &get records as I do not want these dates to be seen by visitors.
sub record_form
my (%rec) = @_;
if ($in{'add_form'}) {
......
$rec{'Remove_by'} = &get_date(time + 172800);
$rec{'ADStart'} = &get_date;
$rec{'Date'} = &get_date;
$rec{'Expires'} = &get_date; }


<input type=hidden name="Expires" value="$rec{'Expires'}">
<input type=hidden name="ADStart" value="$rec{'ADStart'}">
<input type=hidden name="Remove_by" value="$rec{'Remove_by'}">


If this is correct does it mean I have to add these fields in the modify form as well ?

To my suprise when I uploaded it to my server, there were the following results.

1. Add form, I viewed the source code for the hidden field and it prints as follows: ADStart 12/31/1969 (I was not born yet) Expires 12/31/1969 Removed_by 09/10/2000 and Date 12/31/1999
2. I just click on Submit information to see the error message and it prints all invalid date format and the source code were as follows : ADStart 12/31/1969 Remove_by 01/01/1970 Expires 09/08/2000 and Date 12/31/1969

What's happening to all these dates ? Isn't it \d{2}\/\d{2}\/\d{4} means 2 digits, 2 digits and 4 digits. How can it be invalid ?

Thanx in advance.

p.s. My sub get_time is as follows:

sub get_time {
# --------------------------------------------------------
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
return "$hour:$min:$sec";}


I think the problem could be because of the ":". How to correct it ?
Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
My name is Lois not Louis :)

Whenever you use mods you have to keep in mind that they are written at times for a specific database. You may have your dates setup to use a different format from my examples.

I have modified my date subs to allow for the date format I used in the autodelete mod. Below is a copy of how I have these mods configured:

sub get_date {
# --------------------------------------------------------

my ($time1) = $_[0];
($time1) or ($time1 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
## my (@months) = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
($day < 10) and ($day = "0$day");
++$mon;
($mon < 10) and ($mon = "0$mon");
$year = $year + 1900;

return "$mon/$day/$year";
}

sub date_to_unix {
# --------------------------------------------------------

my ($date) = $_[0];
my ($time);

my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($mon and $day and $year) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$day, $mon, $year);
};

if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

And yes you do need to add these fields as hidden fields in your sub html_record_form. Which is the same form that displays for modifying a record, unless you setup another form just for making modifications.

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Hi Lois,

Oops ! Sorry for the spelling mistake.

I'll test things out in a minute and keep you inform of the outcome.

Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
The year column in the date still shows 1969. However, there's no error with the Remove-by field only. The rest of the date column still invalid date.

Let me try and figure things a bit and keep you posted with the latest news.

Quote Reply
Re: Pleassse Help - Autodelete Mod Error In reply to
Everything just work like charm.

I set the &get_date to &get_date() and the duration to a numeric number. That's it.

As a novice I am more confident being backup by an expert.

Thank you so so much. You are marvelous, Lois.