Forum OpenACS Q&A: Re: How do I know, if someone is Admin?

Collapse
Posted by Richard Hamilton on
OK, well I am quite new to this as well so someone else may correct my mistakes, but I'll have a go....

ad_page_contract is a function that is called at the top of every *.tcl page to provide services such as automatic documentation (extracts comments from the code), variable declarations, data input filtering and validation and other bits and bobs that I have yet to familiarise myself with. It seems to be a general purpose gateway for tcl code and provides a standard means of integrating tcl page scripts with the acs api.

The first lines are a call to ad_page_contract (will already be in the page you are editing) and the -properties tag in this example declares the variable admin_p (_p for predicate - naming convention only i.e. boolean true/false) as data type onevalue (multiple value datatypes are available in the templating system). This has the effect of making the variable available to the *.adp page that is called at the end of the *.tcl page.

The

 set package_id[ad_conn package_id]
retrieves the current package instance's id number and stores it in the variable package_id.

The

set admin_p[ad_permission_p $package_id admin]
calls the ad_permission_p service passing the package instance and asking for the admin property - the value is left in admin_p

The value of the admin_p variable is then accessible in the template using the form @admin_p@ and conditional tags can be used i.e. >if @admin@ eq 1>DO SOMETHING>/if>
see the templating help in the docs. (>< wrong way round so that the forum will accept the post!)

Hope this helps.
Regards
Richard