10 years ago
3
Topic
Still hoping not breaking forum rules by yet another Topic.
All below is based on User Forms i mean using the user database table.
I created user let's say "A" by Joomla registration form. This user created a dependent user "B" with a Seblod custom user form.
So "A" and "B" users can edit this "B" user form. But "A" is as if Admin to "B".
I want user "A" to make visible or invisible some additional input fields to user "B" f.e. by a checkbox, but in a way that "B" don't see the checkbox and never can hack its working. Is it possible? How to do it?
"A" and "B" edit the same form in two versions.
What i was able to do so far is to make the checkbox visible to only user "A" but i cannot deal with availability of the form part to user "B" as i wrote above. Triggers don't work to me because "B" form does'nt react to a checkbox there isn't at all on "B" side or triggers can be used in another way i don't know yet.

Can i ask for some advice how to do the thing written in bold?
Get a VIP membership
10 years ago
0
Level 1
I don't know if it's a good custom to answer to myself :)
but probably i can on the "A" side of the Form change the user group of the user which sees "B" version of the form and by this his access (access levels) to the custom fields visible only in the case user "A" want it. If i want user "A" not to change user groups manually, seblod number [5] field "Conditional States + Computation" or maybe something else can be used to change the groups.
I'll try it later and write something. Or someone has a better idea?

Update:
Ok, i see a cannot change user group for a user if i am not a Super User or so.
So i need to find another way to change a group after checkbox has changed.
Maybe field 42? See you soon...

10 years ago
0
Level 1
I had much "headache" with figuring things out.
Let arrange things starting from scratch. I want a superior user to turn on/off different parts of his dependent user's form.
Warning - some access level related changes work only after loggin out and loggin in. Access levels are remembered for the session or so.

"A" - all concerning superior user
"B" - all dependent user related

Warning II. If you create links, forms care for proper access levels and permitions. For example A Seblod Form construction tool have a "Permission" button. If "A" user does't have access to see a form, maybe there you can changed or a menu link to it is ascribed to a wrong access level. I had a couple of time-wasting mistakes by this.

1. Let's create a "A" user group. Let's create a "A" access level and assign to it only "A" user group. By this i can display user "A" a checkbox field turning on/off additional fields for a dependent "B" user .
2. Let's create a "B" user group. Let's create a "B" access level and assign to it both "B" user group and the "A" one. By this "A" users will always see all parts of the user form, but a "B" user will see only its additional fields turned on/off by "A" user.
3. Let's change a default Seblod user form ascribing it only "A" user group (we can do it using "user groups" field for example and passing simply the ID number of the "A" group in the blue [2] field named "Live + Live Value"). We can also create a new user form from scratch. Using default user form proposed by Seblod maybe will help for easier integration with joomla registration system and modules for registation. Now we will be ascribed to "A" user group. At the end it will be good to find a way to make groups invisible or whatever.
4. Let's create another User Form (for dependent "B" users registration) in Seblod with an additional checkbox being visible only to "A" user - we set "A" access level using the blue button "[4] access +-". Let's add a field o even group of fields (group X) and set "B" access level to it. There is a fine way for both "A" and "B" users to see the same forms. But only "B" user will see it as its profile. What Seblod resolved fantastically that theres is a normal Joomla link to the currently logged user profile with additional "Seblod" fields - select simply a proper menu type.
5. Now if a user is ascribed to group "B" for example during her or his registration process performed by his superior user he will see additional part of the form. But if he is not in the "B" group the superior user have no right to change the "B" user rights after registration process becouse of his rights. That is the reason user "A" need its own checkbox turning on/off the user "B" his additional parts of the form by ascribing him to "B" group programatically (we have to read from $_POST var for example the value of the checbox and do some work in the database :) ).
6. This point will be explained later in another POST - how to ascribe "B" user to a "B" group in order he sees that additional part of the form.
7. We need to create a dependent "B" user list to edit already registered "B" users - we can achieve this by adding another field filled automatically with parent user id. I dont write here how to do it - there can be find some informations about searches & lists. By this there will be only dependent users on the list. We can click one user and edit his form turning him on/off his options.

Let's say, to be prepared for more sofisticate situation, we want two turned on/off parts of the form as above not just one.
Let it be "B2".
2. We create exactly as in 2. point above but "B2" group, access level with "A" and "B2" user groups ascribed to it.
4. We have to add another "A" access-level checbox which will be programmed as his counterpart earlier has been. Then adding "B2" part of the form is left.............
................................
All the rest of "B2" as "B" or try to think what you are doing :)

I hope it will help someone. Later i'll have to do something with point 6.




10 years ago
0
Level 1
As i've said point 6 of the above approach.
Some information first:
I know the code may be lacking something but you can improve it. F.e. new groups can be assigned by checbox and below code only after a "B" user had been registered.
In order for it to work we need to put this code below in FieldPrepareStore or onCCK_FieldPrepareStore place. It can be found as i remember in 42 field, but i'havent tested it on this field rahter i created my own plugin called php_code and in it's file php_code.php used on onCCK_FieldPrepareStore function. I put some code there or used eval function for custom field i'had created. So different approaches are good. Whateve approach below code should work the same.
$_POST['parent_user_id'] - it is my way to be sure whether i am in the right form - maybe it is not necessary
$_POST['user_groups'][0]=="18" - not necessary too - it is another way for me to determine if i am in a right form - you can drop this piece of code alongside with $_POST['parent_user_id'] part.
Update: Watch out! If $_POST['user_groups'] can be without [0] when the corresponding field is hidden not tree-like with checkboxes they are presented in the $_POST['user_groups'] variable as an array not string.
Then it probably could be $_POST['user_groups']="18" or $_POST['user_groups']="18,19,20" or so.
If you're a beginner remove this part with 18 :)

19,17 - ids of groups B and B2 - you should have already known about from the previous posts what i mean. You of course can actually have your own ids (If you are more beginner than i am i wrote this).
You can use for your purposes only one group f.e 17 id and remove all 19 related parts

I used checkboxes but you can use f.e select field.


if (isset($_POST['id'])&&isset($_POST['parent_user_id'])&&$_POST['user_groups'][0]=="18") {

$db = JFactory::getDbo();

$query = $db->getQuery(true);

$query->select($db->quoteName(array('user_id', 'group_id')));
$query->from($db->quoteName('#__user_usergroup_map'));
$query->where($db->quoteName('user_id') . ' = '. $_POST['id']);

$db->setQuery($query);
$row = $db->loadRowList();



if (isset($_POST['checkbox_one'][0])&& $_POST['checkbox_one'][0] == "yes") {
$assign_to_group_1=true;
} else {
$assign_to_group_1=false;
}

if (isset($_POST['checkbox_two'][0])&& $_POST['checkbox_two'][0] == "yes") {
$assign_to_group_2=true;
} else {
$assign_to_group_2=false;
}


$is_group_1_already_assigned=false;
for ($i=0;$i if ($row[$i][1]=="17") $is_group_1_already_assigned=true;
}

$is_group_2_already_assigned=false;
for ($i=0;$i if ($row[$i][1]=="19") $is_group_2_already_assigned=true;
}

if ($assign_to_group_1===true&&$is_group_1_already_assigned===false) {

$query = $db->getQuery(true);
$columns = array('user_id', 'group_id');
$values = array($_POST['id'], 17);
$query
->insert($db->quoteName('#__user_usergroup_map'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);
$db->query();

}

if ($assign_to_group_1===false&&$is_group_1_already_assigned===true) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$conditions = array(
$db->quoteName('user_id') . '='.$_POST['id'],
$db->quoteName('group_id') . '=17'
);
$query->delete($db->quoteName('#__user_usergroup_map'));
$query->where($conditions);
$db->setQuery($query);
$result = $db->query();


}

if ($assign_to_group_2===true&&$is_group_2_already_assigned===false) {

$query = $db->getQuery(true);
$columns = array('user_id', 'group_id');
$values = array($_POST['id'], 19);
$query
->insert($db->quoteName('#__user_usergroup_map'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);
$db->query();

}

if ($assign_to_group_2===false&&$is_group_2_already_assigned===true) {

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$conditions = array(
$db->quoteName('user_id') . '='.$_POST['id'],
$db->quoteName('group_id') . '=19'
);
$query->delete($db->quoteName('#__user_usergroup_map'));
$query->where($conditions);
$db->setQuery($query);
$result = $db->query();

}

}



Get a Book for SEBLOD