Gossamer Forum
Home : Products : DBMan : Customization :

Admin deletes all records

Quote Reply
Admin deletes all records
I am using the short/long mod. Whenever I am logged in as admin and I try to delete one record, I delete them all. Is is it a permission?

Please look at:
http://agecon.tamu.edu/.../db.cgi?db=guatemala

Thanks

Also, I would love any suggestions on the site.
Quote Reply
Re: Admin deletes all records In reply to
I could be wrong but I think this may have to do with HTML formatting errors.

I added a record to test your db and then validated the coding from viewing your source code.

Perhaps by correcting some of the errors, it may solve your problem.

This line:

<TR><TD ALIGN="Right" VALIGN="centerP"><Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399>E-mail Address:</FONT></TD>
<TD> <font face="verdana,arial,helvetica" size="2"><A HREF="mailto:-">-</Font></TD></TR>

change to:

<TR><TD ALIGN="Right" VALIGN="center"><Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399>E-mail Address:</FONT></TD>
<TD> <font face="verdana,arial,helvetica" size="2"><A HREF="mailto:-"></A>-</Font></TD></TR>

what changed is <centerP> to <CENTER> and also adding a closing </A> for your email field. Perhaps this open tag was causing problems ?

It also shows this line as having closing table tags but no opening to match:

</td></tr></table></center>

before </BODY></HTML>

I would suggest checking all your HTML coding for your page displays and see if your problem goes away.

Hope this helps Smile
Quote Reply
Re: Admin deletes all records In reply to
Are all of these records ones that you added while logged in as username "admin"?


------------------
JPD






Quote Reply
Re: Admin deletes all records In reply to
No. One record has been added by just a user. One record has been added by a user with admin.
Quote Reply
Re: Admin deletes all records In reply to
Also, while in admin, please take a look at the modify screen. The radio buttons do not correspond with the entries.
Quote Reply
Re: Admin deletes all records In reply to
The radio buttons not corresponding to the records is another indication that you need to check your HTML coding.

I really believe the problems you are having are directly relating to your coding.

If you post a .txt copy of your html.pl file I will be glad to help you find and fix any HTML errors.
Quote Reply
Re: Admin deletes all records In reply to
Here is the html.pl file. I truly appreciate your help. I agree that coding could definately be a problem, but it all starts running together after a while.

http://agecon.tamu.edu/...mala/guatemalapl.txt

Thanks!
Quote Reply
Re: Admin deletes all records In reply to
Sorry it took so long to get back to you Smile

I think I may have found what's causing problems.

All of your fields need to be defined in your
html_record_form and should be included in your other forms (can be hidden fields).

What you have now is:

html_record_form: (3 fields)

Name
Major
Classification

sub html_record_edit: (9 fields)

$rec{'ID'}
$rec{'Name'}
$rec{'Phone'}
$rec{'Email'}
$rec{'Resume'}
$rec{'Webpage'}
$rec{'Major'}
$rec{'Classification'}
$rec{'Description'}


sub html_record_long: (8 fields)

$rec{'Name'}
$rec{'Phone'}
$rec{'Email'}
$rec{'Resume'}
$rec{'Webpage'}
$rec{'Major'}
$rec{'Classification'}
$rec{'Description'}

Notice you have a different number of fields defined in each form?

Include all your fields in all your forms and I think this may get your database working correctly.

Also I noticed a few changes you might want to make here:

sub html_page_top {
####################
&html_print_headers;

print qq|
<html><head><title>$html_title: $page_title</title></head>
<body bgcolor="#FFFFFF">
<center><table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500>
<TR><TD><i><font color="#0080C0" font size=+1>Guatemala Student Information Database</font></i><br></TD></TR>
<TR><TD> |;

sub html_error_page_top {
########################
&html_print_headers;
print qq|
<html><head><title>$html_title: Error! $page_title</title></head>
<body bgcolor="#DDDDDD">
<center><table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF"><b>$html_title: Error: $page_title</b></font></td></tr>
<tr><td><p><center><B><$font_title>Error:</font> <$error_color>$page_title</font></b></center><br>
</TD></TR><TR><TD> |;

sub html_page_bottom {
#############################
<table border=0 width=100%>
<tr><td align=left><$font>Copyright 1998 <A HREF="http://www.gossamer-threads.com">Gossamer Threads Inc.</A></font></td>
<td align=right><a href="http://www.gossamer-threads.com/scripts/dbman/"><img src="http://www.gossamer-threads.com/images/powered.gif" border=0 width=100 height=31 alt="Database Powered by Gossamer Threads Inc."></a></td></tr></table> |;
print qq| </td></tr></table></center></body></html> |;
}


Another tip:

If you use &html_page_top;

and &html_page_bottom;

within your various page displays you can also eliminate having to include the same page headers and footers in your html.pl file and just pull this from one location. It sure saves on the file size Smile

Hope this helps Smile
Quote Reply
Re: Admin deletes all records In reply to
Thanks so much. I will make those changes. How exactly do the hidden fields work? Does that have to do with the .cfg file or is that something that is done in the .pl? Thanks again. I will post an updated one ASAP.

Thanks
Quote Reply
Re: Admin deletes all records In reply to
Unless you are using the autogenerate for forms you would define the hidden fields in your html.pl file.

Hidden fields come in handy when you want some fields to be displayed only by admin. Like when your long record is displayed you seemed to not want visitors to see the Record ID.

You could setup the field like this:

html_record_form:

<CENTER><TABLE WIDTH="460" CELLPADDING=5 CELLSPACING=0 BORDER=0> |;
if ($per_admin) {
print qq|
<TR><TD><$font>ID:</FONT></TD><TD><input type="text" NAME="UserID" VALUE="$rec{'UserID'}"></TD></TR> |;
}
else {
print qq| <TR><TD> <input type="hidden" NAME="ID" VALUE="$rec{'ID'}"></TD></TR> |;
}
print qq|


And if you did not want to display this in sub html_record_long:

<CENTER><TABLE WIDTH="460" CELLPADDING=5 CELLSPACING=0 BORDER=0> |;

if ($per_admin) { print qq|
<TR><TD><$font>Record ID:</font></TD><TD><$font>$rec{'UserID'}</font></TD></TR> |;
}
print qq|
<TR><TD><$font>Name:</font></TD><TD><$font>$rec{'Name'}</font></TD></TR>

When people want to modify their record it will bring up the html_record_form, so it's not necessary to have your EDIT form unless it serves another purpose.

Hope this helps Smile
Quote Reply
Re: Admin deletes all records In reply to
How do I use the hidden fields to work for a non-admin user that I want them to see the ID field when they are adding a record, yet I do not want them to see it when they are viewing. That is why I set up the edit form. Also, I just installed the default graphic mod, so you might take a look and see if you think it is functioning properly. I truly appreciate all that you have done.
Quote Reply
Re: Admin deletes all records In reply to
If you want them to be able to see the user ID number when adding a record in

html_record_form:

<TR><TD><$font>User ID:</font></TD><TD><input type="TEXT" NAME="UserID" VALUE="$rec{'UserID'}" MAXLENGTH="10"></TD></TR>

Then use the example given above for html_record_long to so it will only be displayed for admin.

I use a separate image upload script, so I would not be a good tester for the mod you installed Smile

Perhaps you could create another thread if you have any problems which are specific to that mod.

By the way your database is looking good, I'm so glad you have it up and running Smile
Quote Reply
Re: Admin deletes all records In reply to
Ok. I'm finally back and LoisC - if you're out there - I appreciate your help and am asking for more. I made the suggestions for hidden fields (as opposed to just leaving them out) and it works great. My problem is still that when the admin deletes a record it still deletes all records in the database. If a non-admin user uses the database to delete his/her record then it works fine. I'm really puzzled.

I noticed that in the delete section of the .pl file the delete operation uses NAME="$tmp{$db_key}" VALUE="delete" while in the modify section the modify operation uses NAME="modify" VALUE="$tmp{$db_key}". These appear to be opposite. Modify works and delete doesn't for the admin (only single user). I tried switching them around on the delete form section but to no avail. I have an idea what these do but not how they do it. I am using the short/long mod and haven't changed the delete form other than to get the checkbox and record output on the same line. I will say that it didn't work even when not changed to this configuration.

I currently have all the mods working in the database that I want: short/long, limit record to single user, file upload, censor text, change password,... and only need to get this admin delete working to be finished.

The files can be found at http://agecon.tamu.edu/...mala/guatemalapl.txt and
http://agecon.tamu.edu/...ala/guatemalacfg.txt. If anybody can help me I would be MOST grateful. LoisC - are you out there still? JPDeni - can you provide more assistance? The author/author, admin/admin, and guest/guest logon id's still work as this is only a test database. You can try out the database at http://agecon.tamu.edu/.../db.cgi?db=guatemala.

Thanks for all the help and I'm eternally optimistic.
cwhatley


Quote Reply
Re: Admin deletes all records In reply to
The difference in the code is because you can modify only one record at a time but you can delete multiple records. (I'm not sure if I can explain this any further. I understand it for myself, but not well enough to explain it to someone else.)

I did test it out. I added a record when I logged on as "author" and then logged on as "admin" and all of your records were deleted. Sorry. Blush

Everything looks okay in your html.pl and .cfg file. Can I see your db.cgi file? Seems like the problem is there.


Quote Reply
Re: Admin deletes all records In reply to
Thanks JPDeni,

It's nice to know that at least my .pl and .cfg files are ok. Here is the link to my http://agecon.tamu.edu/.../guatemala/dbcgi.txt file. I hope you can find the answer there. It's pretty frustrating to be so close and yet soooooo... far. I've added a couple of records back into the database for you to help diagnose the problem with.

Thanks for your efforts,
cwhatley

Quote Reply
Re: Admin deletes all records In reply to
Well, I did it again. I tried deleting a record from the "long" display, and it deleted all the records again. (I was hoping, but no dice.)

Try changing the code back to the original in sub delete_records. Instead of


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) {
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$data[$db_key_pos].$extension") && (unlink "$SAVE_DIRECTORY/$data[$db_key_pos].$extension")

}
}
}

else { $output .= $line . "\n"; }


use


$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.
($output .= $line . "\n"); # otherwise print it.


We can put the code back in for deleting the uploaded files later. First, I'd like to see whether there's some other problem.



JPD
Quote Reply
Re: Admin deletes all records In reply to
Ok JPDeni, I loaded up a couple more records for you in the database. I also modified the dg.cgi file as you suggested and sent it over. I logged in as an admin and deleted a record and - big sigh! - it still deletes all records. I'm ready to keep trying. What else do you need me to do?

Thanks,
Cwhatley

Quote Reply
Re: Admin deletes all records In reply to
Well, at least I know it's not due to the code from the upload mod. (That makes me feel a little better. Smile)

This is a real puzzler.

Try changing

$delete_list{$data[$db_key_pos]} ?

to

($delete_list{$data[$db_key_pos]} == 1) ?

(I'm really just clutching at straws here. I don't know what else to suggest.)

JPD
Quote Reply
Re: Admin deletes all records In reply to
Well that doesn't work either. Could this possibly have anything to do with the key field (id)? I look at the records and the id fields are all different (i.e. they are user's first names) so I didn't think this would be a problem.

I put more records back in and would like to keep trying. Next suggestion?

Feel free to actually take the .pl, .cfg, and db.cgi file to your own server to see if you can get it working. If you want access to the test db of 3 records then just let me know.

Thanks,
cwhatley

Quote Reply
Re: Admin deletes all records In reply to
I may just do that -- take your files and put them on my server. I don't know what else to do.

The only thing I saw in your .cfg file that was a little odd was that you had the field type for your ID field set as 'numer' instead of 'alpha.' But I can't see where that would make a difference.

I'm not sure how much time I'm going to have today, but I'll try to get to it as soon as I can.


JPD
Quote Reply
Re: Admin deletes all records In reply to
My apologies. I completely forgot about your problem. I'll see what I can do to figure it out now.


JPD
Quote Reply
Re: Admin deletes all records In reply to
I found it!!!!

You have a misplaced } in your db.cgi file.

You have:

Code:

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) {
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$data[$db_key_pos].$extension") && (unlink "$SAVE_DIRECTORY/$data[$db_key_pos].$extension")

}
}
}

else { $output .= $line . "\n"; }
It needs to be

Code:

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"; }
}
The green } is the one that needs to be moved.

The code above includes an improved way of deleting the graphic files as well, from the latest version of the file upload mod.


JPD
Quote Reply
Re: Admin deletes all records In reply to
At last! The database now works as it needs to. Now I can work on making it look better. I can't tell you how much your help is appreciated. Thank you! Thank you! Thank you!

You really are a great person to help us the way you do.

Thanks,
Cwhatley



Quote Reply
Re: Admin deletes all records In reply to
JPDeni,

Can I ask you one more question? I think it won't take as long to correct this problem as it did the other problem.

I am using the short/long mod with the upload file mod. I have a link called MORE? in the short record that takes you to the long record. When I upload a file, the upload success screen shows the short version but the MORE? link doesn't work. Can you take one more look at it to let me know why?

The links to the files are still listed above.

Thanks,
cwhatley

Quote Reply
Re: Admin deletes all records In reply to
Hi all,

I didn't figure out the problem but I circumvented it. I was looking at the email notification thread at http://www.gossamer-threads.com/...w=collapsed&sb=5 and saw the suggestion to just show the long record after a record is successfully loaded. I put the coding into the upload_success portion of my .pl file and now, instead of showing the short record with the MORE? link that didn't work, it automatically provides the long record. The list all function then displays the short records and the MORE? link works there.

Thanks again for all your help.
cwhatley