September 10, 2010, 08:03:13 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Always search the forum before posting !
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Rightmanagement for single elements in a form  (Read 3360 times)
Bitsqueezer
Moderator
Living Legend
*****
Offline Offline

Posts: 1872



« on: March 29, 2007, 02:41:12 am »

Hi!

One thing I'm missing at Joomla is a method to integrate my own groups and give them access-rights to different content. I found a module which does this. Now in FacileForms I have the problem that different users should use the same form but with different fields. For example: The manager should be able to edit data which a technician or backoffice-user only can add to the database. So the button for "edit" should be disabled or hidden when the form is displayed by backoffice- or technician-user.
This could be solved with little work - but what if the fielddisplaying is more complex? It is much more complicated with every field which should be displayed in dependence of the user-right.

So I made a package which could be used as an extension to FacileForms, maybe useful for a future version.

Attached you will find a zip-file which contains the necessary files.

Here's a little more info about that:

Script API Reference Package 'CC'.html
Contains the complete documentation of all functions in the package in the same form as the FacileForms-API-documentation (I copied the template from the documentation-page.)

FacileFormsRightExtension.xml
Contains all functions of the package "CC".

The simple way of using this package is by generating arrays as showed in the examples of the documentation. With many users, modes and fields the list of entries could be very long so I added database-support for the array.

First, you can create a table in the database using the file "Rightmanagement.sql". It uses the prefix "jos_", if you have another one in joomla, just change it here. A table named "jos_facileforms_formrights" will be created which contains the fields "id" (primary key), "form" (id of the form like used in the table "jos_facileforms_forms"), "usertype" (the groupname of the group you want, can be anything), "mode" (the mode how the form should be used, can be anything, for example "add","edit","delete","view" - whatever you want), "name" (the name of the field like entered in the formeditor of facileforms), "disorhide" (0 for disable and 1 for hide).

You must fill this table in the same way like shown with the array-example in the documentation. The ID-field is an autoincrement-field and doesn't need input. Look into the table "jos_facileforms_forms" to find out the ID for the form you want to use and fill it into the "form"-column of the table.

To use this table in your form, add the following PHP-code of the zip-file into the form in the pieces before-form (I don't know the exact name, I use the German version of FF):
VorForm.php

This will generate an array as Javascript-code which will be executed later by the browser. The SQL-command reads this table and only looks for all entries which belongs to the actual form by using the "WHERE"-statement. Just enter the name of your own form instead of "nameofmyform".
Result: You can have one table for all your forms but the array only contains the fields of the used form.
Another advantage: Feel free to generate your own GUI to edit this table, but be sure that this GUI can only be used by users who should change the rights.

To use the array in your form, you can use a line like shown in the file
Skript_Init.js

Here an "alert"-function is used which have the advantage that you can see if everything was OK with the fields and if there was no error during execution. This is not useable for a live-form, but the best method to check if everything was OK (debugging). After debugging you can remove the alert and call the function directly. You can also add IFs or SWITCHes to test the result of the function in livemode.
The line shows a usergroup named "Administrator" in form-mode "edit".

Now where do the groupnames and form-modes does come from?
Just do it like you want. You can use the Joomla-builtin-usertable and add a field to this with the groupnames and read it in your form. You can use constants to assign users to groups. You can use an own table which is be connected to the Joomla-builtin-usertable. You can use the Joomla-module and its tables for rightmanagement. You can use the usertypes of Joomla (Editor, Publisher, Author and so on).
The modes are as free as you want: You can name them like the use of the form, for example "view", "edit", "add". You can use it as calendarmode like "Christmas", "Eastern", "Holidays". You can use it as timemode like "after10","before6", whatever you want to differ.
The mode can be left, just fill the fields with NULL-values, then they will not be used.

How it works:
The function "dishideFieldsByRights" tests if the string "strUsertype" is equal to the "type"-column of the array "objArr" and if yes, it checks if the "mode"-column is not empty. If not, it checks if it is equal to "strMode" and if it is the case it uses the "disorhide"-column to disable or hide the field contained in the column "fname".

For the other functions, just look into the documentation.

For me it works, I didn't found an error, but you're welcome to report about any error.

Have fun with it...

PS.: The package contains two other little functions which have nothing to do with this for testing an input-field for timevalues (hours and minutes) and changes the content automatically if it is wrong.

Cheers,

Christian

* FacileFormsRightExtension.zip (6 KB - downloaded 293 times.)
« Last Edit: March 05, 2008, 06:43:57 pm by Bitsqueezer » Logged
Bitsqueezer
Moderator
Living Legend
*****
Offline Offline

Posts: 1872



« Reply #1 on: December 07, 2007, 01:28:18 pm »

Hi,

due to questions about the Joomla component I mentioned above here's the link to the component named "Group Access":

http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,103/Itemid,35/

Cheers,

Christian
Logged
Bitsqueezer
Moderator
Living Legend
*****
Offline Offline

Posts: 1872



« Reply #2 on: March 07, 2008, 05:26:37 pm »

Hi,

as the link above doesn't work anymore here's the link to the author's website where you can download the module. Moreover there's a little flash tutorial explaining exactly how to use it:

http://www.shadowrain.co.za/joomla/mambo-groupaccess.php

Cheers,

Christian
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by SMF © 2001-2006 Lewis Media
| Terms of Use | Privacy | Sitemap |