Gossamer Forum
Home : Products : DBMan : Customization :

Drop down list of users

Quote Reply
Drop down list of users
HI JPD,

I want to put a drop down list of users in my html_record_form. What's the most efficient way of doing this ..?

I don't want admin to be displayed in this list.
Quote Reply
Re: Drop down list of users In reply to
You could try this:

Code:
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

$user_list = qq~<select name="username"><option>---</option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
unless ($data[6]) {
push (@users,$data[0]);
}
}
foreach $user (sort @users) {
if ($rec{$db_cols[$auth_user_field]} eq $user) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
}
else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";

Then use $user_list in the place where you want to place the select field.


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





Quote Reply
Re: Drop down list of users In reply to
Thanks a mill JPD,

That works almost perfectly (sorted and everything!) !!! Only thing is, I don't want the user named admin included; I want to include other admin users,however. What do I change to effect this ..?

(Your assistance to me is invaluable, ....I am going to show my appreciation early next week Smile )
Quote Reply
Re: Drop down list of users In reply to
Ah. I see. Okay.

Change

unless ($data[6]) {

to

unless ($data[0] eq 'admin') {

That'll do it! Smile



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





Quote Reply
Re: Drop down list of users In reply to
Thanks a lot, JPD

That did it for sure. I had tried == instead of eq, and of course the select list was blank. I need to buy a perl book to brush up on those 'simpler' points.

Amazon gift cert will be forwarded next week !! (unless there's something you'd prefer)
Quote Reply
Re: Drop down list of users In reply to
You use == to test for equality between numbers and eq to test for equality between strings. It's just one of those things you start to remember with practice.

A gift certificate would be great! I have my eye on some CDs -- I'm trying to replace all my Beatles vinyl with silver Smile -- and some other programming books. Thank you so much!

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





Quote Reply
Re: Drop down list of users In reply to
Hi,
I am really really new with perl and my english is quite bad: so, please, speak slow.... :)

I've read your posts about the "Drop down list of users"'s problem and, using the code that you suggested in that post, I'm trying, with this code, to put a dropdown list of users, viewable only by admin, so that the admin could add record for all the users: what's wrong?...and, how can I make that admin could add a record for all the users in the same time? I'm sure this post seems to be stupid for you but..please, help me ...:)

..................
...............
....if ($rec{$db_cols[$auth_user_field]} eq $user) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
} else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";

print qq|
<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<input type="hidden" NAME="eventi_id" VALUE="$rec{'eventi_id'}">|;
if ($per_admin) {print qq|$user_list|} else{ print qq|<input type="hidden" NAME="userid" VALUE="$rec{'userid'}">|;};
print qq|........................
.............
......

Quote Reply
Re: Drop down list of users In reply to
Try changing it to this:

print qq|
<TABLE WIDTH="450" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<input type="hidden" NAME="eventi_id" VALUE="$rec{'eventi_id'}">|;
if ($per_admin) {
print qq|$user_list |;
}
else {
print qq|<input type="hidden" NAME="userid" VALUE="$rec{'userid'}">|;
}
### ; remove this ;
print qq|

you were missing an ending ; to close off the print line here:

print qq|$user_list |;

and added an extra one before your final print statement

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Drop down list of users In reply to
Yes, yes,
I had fixed these errors just two minutes after posted the question...sorry, but it doesn't works yet:

(i'm using the relational mod with two db:
item (eventi)
users (utenti)

I'm trying to give the admin the possibility to add records for other users (also all useres at the same time)but now this "print qq|$user_list |;" is good only for searching items which userid is selected by the list. How can I do?
Thank you a lot for the reply!!!!



Quote Reply
Re: Drop down list of users In reply to
I'm not sure I understand what you are trying to do.

Could you please explain step by step what you want to happen. Are the users already signed up for an account prior to your wanting to add their record?

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Drop down list of users In reply to
Sorry,
my english is really a shame!
I'm trying to do that admin could add records in the item database for all the users (registered)and at the same time: the $user_list contain the list of all the userid and this (key)field is in common between the two databases (events and users) I'm tryng to add events for all the users in one time.
Ex. user database's fields are:
0:userid(key field)
1:name
2:email

and items database is:
0:userid
1:event_id(key_field)
3:date
4:item

i'm trying to add a record like a date and an item, that is the same for all the users but which each user (already signed up) can modify individually.
Registered users can only modify record, not add, not registered users cannot do nothing.

Hi, and thanks a lot for the reply!

Quote Reply
Re: Drop down list of users In reply to
If you are just wanting to enter a default value for a field the easiest solution may be to just have the field filled in automatically when the record is added.

This can be accomplished within your .cfg file similiar to the example below.

'item' => [22,'alpha',50,60,'itemname',''],
'date' => [23,'date',15,15,1,September 10, 2000,''],

replacing "itemname" to what you want to appear in that field, replacing "enterdate" with the date to be displayed (of course matching the format being used for your database.

I hope i understood correctly. There is not a problem with your english Smile just my understanding of what you wanted to do.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Drop down list of users In reply to
Hi,
if users cannot add records but only mofify them as I need, how can i add them the first record? These records, in the event db, are an year, a month and a set of 31 checkbox field representing the days of the month when they are avaiable in work. I'm planning to create two of this records with default value for each user after the first time they signup in the users db, so that they can change these records monthly filling with them personal avaiabilities simply changing the month and year but, if they can't add but only modify I have to give to the admin the possibility to add records for user the first time. Then they will change this records every month. Understand? If I only enter a default value for a field
like if I put this in the .cfg
'item' => [22,'alpha',50,60,'itemname',''],
'date' => [23,'date',15,15,1,September 10, 2000,''],
they still have nothing to modify the first time they use the db.
...i'm beginning mad Mad
hi Smile



Quote Reply
Re: [JPDeni] Drop down list of users In reply to
I am also trying to add the list of users to the add form so that the admin can select a user and then complete the form to add a record for the user they select from the list but I am confused as to spefically how to modify the html and cgi files with the information provided. Can someone help me?

I've tried putting this code at the beginning of sub add_record in the cgi file:

code:
......................................................................................

open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

$user_list = qq~<select name="username"><option>---</option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
unless ($data[6]) {
push (@users,$data[0]);
}
}
foreach $user (sort @users) {
if ($rec{$db_cols[$auth_user_field]} eq $user) {
$user_list .= qq~<option value="$user" SELECTED>$user</option>\n~;
}
else {
$user_list .= qq~<option value="$user">$user</option>\n~;
}
}
$user_list .= "</select>";

......................................................................................

And have added $user_list to my form at the beginning so that the dropdown list of users will display but it's not working.

Could there be something I am missing? Did I not add it in the correct place? I'm confused.
Cher
Quote Reply
Re: [chronisca] Drop down list of users In reply to
Putting that code into sub add_record is not correct. The add_record sub gets used after the record is submitted, and you need the information created when the form is generated.

Here are some options;

1. put the code in the html.pl file in sub html_add_form, perhaps just after &html_print_headers;

2. make a new sub for the code in db.cgi, call it something like ... user_list, then call the sub with &user_list, probably at about the same place as mentioned above.

Not tested, but makes sense to me.

Good luck.