Gossamer Forum
Home : Products : DBMan : Installation :

Admin fields

Quote Reply
Admin fields
I have edited the html.pl and default.cfg to include everything I need. Works nice so far! Great Job! I have 2 questions:

First: I have brain lock on one simple subject. Admin fields when you are not using auto generate...I know its probably very simple but I cant get it. I want 2 fields to be visiable ONLY when logged in with admin. Is there a way for me to add a statement that when my forms see -2 to only show it when logged in as admin? And I have 1 field I want user to be able to add/modify but only visible to them and admin? HELP me please!
Second: How would I go about making a field a admin field by user choice.

What I want to do it have the user choose whether to have their email published i.e.-

email public: NO YES if they choose NO its a admin field if they choose yes its viewable for everyone?

Now I am going to be doing more but I am taking this project in little baby steps..right now thats my problem. I can give you the site addy I am playing with this if necessary.. Thank in advance for all your help!

~Gina

Quote Reply
Re: Admin fields In reply to
A wise person you are to take baby steps. Smile

I'm going to give you just a little bit of info on how perl works, so I know we're on the same page. If you already know this, please bear with me.

When the script creates the html pages, either the forms or the displays, it prints out whatever is in a print statement. All print statements have to include quotation marks around what is to be printed. Normally, one thinks of quotation marks as working like 'quote' or "quote" -- and they do work that way in perl, too, but there are times when you need to use other types of quote delimiters. For one thing, in DBMan, there are a whole lot of times when variables (anything that starts with a $ is a variable) need to be printed. You can use double quotes to print out the value of a variable -- print "My name is $rec{'Name'}" for example.

But there are also times in printing out html pages when you have to use double quotes in the pages, like in a URL. If you used
print "<a href="$rec{'URL'}">"
perl wouldn't know that the middle set of quotation marks are supposed to be printed and would become very confused. It's not nice when perl gets confused! Smile

But what we can do is use other quote delimiters. You can use just about any character you want as a delimiter. You just have to tell perl that you're going to use it. The syntax is print qq and then the delimeter. When you close the quote, you use the same delimiter again to tell perl that you're done quoting. What you get is

print qq|<a href="$rec{'Url'}">|;

The other part of this that is extremely important to remember is that every perl statement must end with a ; (semicolon).

Are you still with me?

All of this is necessary for you to know because we're going to be dealing with things that will be printed to the html page and things that will be for perl's internal use only. We have to make a distinction between them.

Now to answer your question.

Your html_record subroutine will start with something like

print qq|<table><tr><td>

and then a bunch of stuff to print out the record information. Then you will come to the field you want only the "owner" of the record and those with "admin" permissions to see.

First, close off the previous print qq| statment with a

|;

Then add

Code:
if (($db_userid eq $rec{'UserID'}) | | ($per_admin)) {
print qq|[The record information]|;
}

Be extremely careful if you're copying and pasting the above code. You'll notice there's a | | in the first line. UBB adds a space between them when it adds the post to the forum. Take out the space between the two | marks.

Also, be sure to change UserID to match the field name of the userid field in your database. Remember that case counts!

After the closing bracket above -- } -- start another print qq| statement to continue printing your record.

Your "user choice" field is done a similar way. First close off a print qq| statement with a |;.

Then add -- well, it depends on who you want to see this. If you want the email address to show up for the record owner and admin no matter whether the "email public" is checked or not, you would use

Code:
if (($db_userid eq $rec{'UserID'}) | | ($per_admin) | | ($rec{'email public'} eq "Yes")) {
print qq|[The record information]|;
}

This, again, is making some assumptions about your database -- that the field name is

email public

and that one of the options is

Yes

If your option is

yes

be sure to change it in the code above.

If you only want the email address to show for records with the "email public" option selected -- not even the record owner or admin can see it otherwise -- use

Code:
if ($rec{'email public'} eq "Yes") {
print qq|[The record information]|;
}

Looks like you hit me in one of my more verbose moods. Smile

Don't hesitate to ask if you have any questions.


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



[This message has been edited by JPDeni (edited May 13, 1999).]
Quote Reply
Re: Admin fields In reply to
You are terriffic! Its late so let me look over this tommorrow (in between diaper changes! lol) and I will post a reply to your reply! Thanks a million I absolutely LOVE this script so far...

Gina
Quote Reply
Re: Admin fields In reply to
It worked wonderfully! Had a couple problems with thinking where to put the statements and exactly how I wanted to use them. I am having a ball! Thanks a million! I am sure you will hear more from me before I am through. (And maybe not!) Thanks

~Gina
Quote Reply
Re: Admin fields In reply to
You're very welcome. Please don't hesitate to ask any questions you might have. There's a really nice bunch of folks who hang around here who are willing to help.

You'll find that the more you know about DBMan, the more things you'll want to do with it. I haven't found much that isn't possible with a little pondering.

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