Gossamer Forum
Home : Products : DBMan : Customization :

deleting records

(Page 1 of 2)
> >
Quote Reply
deleting records
I have been having trouble with deleting records. DBMan is running several iterations of the delete sub routine and posting them to the same page.

The error message that appears is (for example)
ID 8 not deleted
ID 8 deleted
ID 88 deleted
ID 888 deleted
ID 8888 deleted
They all have the standard footer attached to them.

I have added a few mods, but if I remember correctly, the only one affecting the delete sub program in db.cgi was the file upload mod. I have changed the .pl file quite a bit, but nothing in the delete sub programs.

If anyone could help, I would greatly appreciate it.
To see the db.cgi file: http://www.pchorseworld.com/db.cgi
To see the .pl file: http://www.pchorseworld.com/barns.htm

P.S. If you would like to test dbman, I am using the secure password mod and all registered users have access to add/delete/modify own
Go To: http://www.pchorseworld.com/cgi-bin/dbman/db.cgi?db=barns

Any help would be greatly appreciated.

Zack

P.S. one other little quirck, it does not do this when only one record is available to delete (and I think only one to delete per user)
Quote Reply
Re: deleting records In reply to
I'm having a heck of a time trying to figure out how to tell folks to change the delete subroutine when they install the upload mod. There have been several folks with "bracket" problems, but they're not all the same problems.

Anyway, you need to replace code in sub delete records. I've included an extra line above and below what needs to be changed for reference.

Code:

($restricted = 1) if ($auth_modify_own and !$per_admin);

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
($output .= "$line\n" and next LINE) if ($restricted and ($db_userid ne $data[$auth_user_field]));

if ($delete_list{$data[$db_key_pos]}) { # if this id is one we want to delete
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.
if ($db_upload) {
opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $data[$db_key_pos];
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
unlink ("$SAVE_DIRECTORY/$file");
}
}
}
}
else { $output .= $line . "\n"; }
}

foreach $key (keys % delete_list) {
(Don't copy the last line above. I had to put an extra space between % and delete_list so it would show up correctly on the forum.)

It appears that you added an extra } at the end of your file, probably because you got a syntax error. You'll need to delete that, too.

In the future, if you install a mod and you get a syntax error, ask about it. I have tested the mods for errors, so the problem is not within the mod itself. It could be that the error is within my instructions for how to install it.

Adding a random } is a guaranteed path to disaster! Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
Rather than starting a new thread I thought I would post this here.

I have a database that I would like to be able to delete (i.e. in bulk) duplicate records.

Here is an example of the records.

Kingdom Number: 12345
Kingdom Name: TEST
Guild:
Date: 19-Jun-2000 22:7:22
Description:
Scummer: No
Dead: No
Validated: Yes
Userid: xyz

Ok now what I would like to be able to do is to run a program, preferably accessible (but not essential) through admin that will

1 look at all the "Kingdom Number" fields and hightlight the ones that are duplicated
2 compare the "Date" field of the records that are duplicated and delete the oldest.

I hope and would appreciate it if someone could help me.

Thanks


Quote Reply
Re: deleting records In reply to
I think previous posts regarding this was a check for duplication before adding a record to the database, but those threads may give you some ideas.

Please look at the FAQ I'm working on under the category of fields and you will find at least 3 references for duplicate records/fields.


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: deleting records In reply to
Thank you LoisC for your reply.

I would be very disappointed if my users did not add duplicate records to the database. I encourage it, in fact it is the essential. The database is used to keep information in it as to the grow/strength of the many opponents.

I have done searches on both customisation and installation for 1000 posts or more and sadly I found nothing that would help me. I have also looked at the auto delete mod, but that works on deleting from certain date.

You mention looking in the "FAQ I'm working on under the category of fields and you will find at least 3 references for duplicate records/fields".

I'm sorry, I have looked under the FAQ link at the top of the page and can not see what you are referring to.

Quote Reply
Re: deleting records In reply to
Lois is referring to the URL that's at the end of her post. She has created a FAQ out of questions that have been asked on the forum.

In Reply To:
I would be very disappointed if my users did not add duplicate records to the database. I encourage it, in fact it is the essential. The database is used to keep information in it as to the grow/strength of the many opponents.
Couldn't you just have your users modify their records to indicate their growth and strength, rather than adding new records?

I'm sure that what you want could be done. The thing is that every time you add a modification to the script, you're increasing the chance of something going wrong. If the database can be used as-is, you are really much better off.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
Thank you for the clarification re the link.

Yes my users could do that ...
I am trying to make things easier for my users and myself and eliminate errors that is why I have choosen this method.

Again thank you for your response

Quote Reply
Re: deleting records In reply to
Okay. If this is what you want to do, I can help you with it.

What is your $db_key field?


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
Many thanks for your assistance.

I have to advise you now that I can generally install a script, I cannot write them. I had hoped that maybe I might have missed something that you may have done for someone else in the past.

I think this is the info that you requested.

$db_key = 'ID'

The is the entire definition, the field with the asterix is the only one that I want to look for duplication of
'ID' => [ 0, 'numer', -1, 3, 1, '', ''],
'Kingdom Number' => [ 1, 'numer', 5, 5, 1, '', ''], #*
'Kingdom Name' => [ 2, 'alpha', 20, 20, 1, '', ''],
'Guild' => [ 3, 'alpha', 20, 20, 1, '', ''],
'Date' => [ 4, 'date', 20, 20, 1, &get_date(), ''],
'Description' => [ 5, 'alpha', '40x10', 700, 1, '', ''],
'Scummer' => [ 6, 'alpha', 0, 3, 1, 'No', ''],
'Dead' => [ 7, 'alpha', 0, 3, 1, 'No', ''],
'Validated' => [ 8, 'alpha', 0, 4, 1, 'Yes', ''],
'Userid' => [ 9, 'alpha', 20, 20, 1, '', '']


Oh by the way I have changed the date field to display $hour, $min and $sec

Again many thanks.

Quote Reply
Re: deleting records In reply to
I've never written anything like this before. I still advise against it. Nevertheless...

You say that you changed the date field. Is it just the time or is it the date and time? Did you also change sub date_to_unix to match the change? The data in the date field will have to be converted to "unix" time in order to be able to do a comparison.

I'm still trying to think of how to do this. It's not going to be a simple task. I probably won't try to tackle it tonight, but I'll wait until tomorrow to see if my brain is better. Smile


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
OMG, I feel silly. Though the change I made shows the time when the record is added and displayed, so at this time it is sufficient. I have copied that part of the db.cgi pertaining to time, here it is

sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
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";
}

sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yy".
# Warning: If you change the default format, you must also modify the &date_to_unix
# subroutine below which converts your date format into a unix time in seconds for sorting
# purposes.

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;

return "$day-$months[$mon]-$year $hour:$min:$sec";
}

sub date_to_unix {
# --------------------------------------------------------
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
unless ($day and $mon and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

and as for an immediate response, I understand that you need time to cogitate. I appreciate your assistance.

Quote Reply
Re: deleting records In reply to
You will have to change sub date_to_unix so it can read and parse your date and time.

First, let me tell you what I've come up with so far. These are the steps that will be necessary to do what you want:


Open the .db file
Read the records into an array.
Close the file.
Go through each record and put all of the data into a "hash of a hash" -- in the form of

$variable name{value from Kingdom field}{value from ID field} = converted value from Date field

Taking each Kingdom in turn, sort the value from the date field in descending order.
Push all but the first one into an array for deleting.

Then go through the delete array and delete the records that with the ID values that are in the array.


The part I don't know how to do (but could probably figure out from looking at my Perl books) is the "taking each Kingdom in turn..." part.

I really think it would be better for you to have your users just modify their records. Have the Kingdom field as your $db_key field.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
I had thought of using the Kingdom Number as the record number and doing away with the ID.

I will go away and try it and come back with any questions or issues I find.

Thanks

Quote Reply
Re: deleting records In reply to
Whew! Smile

If you have any problems at all, don't hesitate to ask.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
Boy that took awhile to redo everything and include new mods. So far so good .. almost.

I made a mistake back at the beginning and because of all the work I have put in all ready am too lazy start from the beginning and redo it. I'm hoping you might be able to point me in the right direction.

To set up my cfg and html, I used your wonderful configurator. One of the last questions asks about not displaying blank lines. I responded that I didn't want them displayed ... when in actual fact I do.

Aesthetically it doesn't look good having the Modified date displayed beside the Modifiers ID, before the record is modified

I figure the code to amend is either in the html or the cfg file ... I have looked, but cannot detect it.

Thanks.

By the way I'm not finished yet either *grin*

Quote Reply
Re: deleting records In reply to
Ok heres another.

I have a number of Admin fields that are not to be edited. I currently have them set up so that they are invisible to non admin.

What I would like though is for everyone to see them, just that no-one apart from the program is able to edit them ... (what I mean by that is that two of the fields are Userid of Modifier and Date Modified these need to be updated as appropriate by dbman)

I also want these fields to be available fro searching on and they currently are not for users who are not admin

Any ideas, suggestions?


[edit]I have also found that I can not do a search on the Userid field, but I can on Modified Userid field. Both are defaulted in from the persons login.

I would like to be able to search on this field also any suggestions?[/edit]
Quote Reply
Re: deleting records In reply to
For your first question, you might do something like:
Code:
print qq|
<input type="hidded" name="UserID" value="$db_userid">
<input type="hidded" name="DateModified" value="|; print &get_date; print qq|">

User ID: $db_userid
Modify Date: |; print &get_date; print qq|

etc...
Just change the name=""s to match your field names.
This will enter the values in a hidden input so they can not be edited, but still display the text of the values.

Is that what you were after?

As for your second question, how is your search set up?

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: deleting records In reply to
Thanks I will try that "hidded"

As to search ... as far as I am aware it is the standard search that is supplied with the html.pl

I haven't made any changes to it!!

Quote Reply
Re: deleting records In reply to
Woops Laugh

that should be "hidden"
Stupid fingers Crazy

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: deleting records In reply to
Thank you Mark.

I did wonder about the "hidded", but not being 100% on html I thought it might have been something new.

I have made those fields hidden. I still have the problem though that I cannot do a search on the Userid field.

Here is my code
print qq|
<TR><TD COLSPAN="4"> </FONT></TD></TR>
<TR><TD> </TD><TD VALIGN="TOP"> <input type="hidden" name="Userid" value="$db_userid"></TD> #*
<TD> </TD><TD VALIGN="TOP"> <INPUT TYPE="hidden" NAME="Date" value="$rec{'Date'}"></TD></TR>
<TR><TD> </TD><TD VALIGN="TOP"> <INPUT TYPE="hidden" NAME="Mod UID" VALUE="$rec{'Mod UID'}"></TD>
<TD> </TD><TD VALIGN="TOP"> <INPUT TYPE="hidden" NAME="Mod Date" VALUE="$rec{'Mod Date'}"></TD></TR>
|;

#* This used to be $rec{'Userid'}
searching using either pieces of script still doesnot return a list of records entered by that person.

Any ideas?

Quote Reply
Re: deleting records In reply to
Can you start over with your questions? I'm confused.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
Ok Starting over JPDeni.

I have two small hic-cups right now.
1. Is that when I used your configurator program I said that I wanted blank spaces removed. I have since found I don't and am not sure which part of the code to amend.

2. Thanks to Mark I have 4 hidden fields now ... those are them listed above your last post. The problem I am having is that I want to be able to
a. have the Userid default in from the persons login (which is what currently happens)
b. Also be able to do a record search on the Userid (Which currently only returns matches in the Mod UID field)

Hope that clears things for you.

Thanks

Quote Reply
Re: deleting records In reply to
In Reply To:
1. Is that when I used your configurator program I said that I wanted blank spaces removed. I have since found I don't and am not sure which part of the code to amend.
You could just enter the field data into the configurator again and generate the code for sub html_record.

But you probably don't want to do that. Smile

You probably have something like this in your database:

Code:

print qq|
<table><tr><td>Name:</td>
<td>$rec{'Name'}</td>|;
if ($rec{'Address'}) {
print qq|
<tr><td>Address</td>
<td>$rec{'Address'}</td>|;
}
print qq|

Delete the code that is in red above. Also, if there is any place that has

print qq| |;

delete that, too.

In Reply To:
Also be able to do a record search on the Userid (Which currently only returns matches in the Mod UID field)
I don't know what the Mod UID field is.

I need to see your actual html.pl file. Don't copy the code into the forum. It's too hard to read. Copy your html.pl file to a web-accessible directory (one where you would place .html files) and rename it to html_pl.txt. Then come back here and tell me where I can pick it up.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: deleting records In reply to
JP, thanks

I have had a look for this type of arrangement.
print qq|
In Reply To:
Code:
<table><tr><td>Name:</td>
<td>$rec{'Name'}</td>|;
if ($rec{'Address'}) {
print qq|<tr><td>Address</td>
<td>$rec{'Address'}</td>|;
}
I couldn't find any so maybe I have deleted them already as I have deleted quite a bit of code when I changed the last four fields to hidden.

My html.pl can be viewed here
http://sugilite.virtualave.net/html.txt

Again many thanks

Quote Reply
Re: deleting records In reply to
Yes, it looks like you deleted the code already for the blank fields thing.

I'm not sure about your problem with searching for the userid. There won't be a field on your search form because that field is hidden. Did you want a Userid field on your search form?

JPD
http://www.jpdeni.com/dbman/
> >