There is no build-in function in Joomla yet for custom user groups according to your needs. You're obligated to use Joomla's default groups, or to use JaCL (commercial), which is not always possible, depending on the project.
If you use Community Builder, and that you wish to use different user groups, each owning their own custom tabs (and fields), there is a solution. It is possible to set a custom tab only for a user group; you only have to split correctly fields to tabs, to show or not to show a tab, depending on the user group that owns it.
This article will show you how to apply a manual hack to Joomla 1.5.x to allow using different and custom user groups for Community Builder.
A good advice would be to save backups of your files before doing anything, because it is really a mess to do.
Joomla! and CB versions used in this tutorial are Joomla! 1.5.9 and Community Builder 1.2 RC4.
The first step is to create custom groups in Joomla build-in group system. For the need of this article, we'll say that we are creating a job website for a online community that needs two user groups : employers and employees.
This only part of the tutorial is taken for Joomla documentation, because I'd like to make a very complete tutorial. Don't follow steps on documentation's page, it's no more up to date.
The mess begins here : you must edit the database, and then execute a script to restructure it correctly. I won't explain here how is working the table that contains user groups in Joomla; I'll only show how to edit it for your need.
Access to your database (with PHPmyAdmin, in my case). Find user groups table (its name is « jos_core_acl_aro_groups »). Default prefix for tables is « jos », but check what is your prefixe and replace « jos » by your table prefix if it's different. In all examples, I'll use « jos » as prefix, but don't forget to change it on every code you'll copy and paste from this tutorial.
Then, In PHPmyAdmin, I found « jos_core_acl_aro_groups » table. This table contains all my user groups. We will insert two new groups : one for employees and one other for employers (or what ever you want). You must correctly specify as parent_id the id of the parent user group. In our case, it'll be simply Registered (id : 18). We add these records, specifying only the parent_id value.
Our groups are now inserted, but their level values is wrong, because this table uses a category level system with a left and right value (integers), that, according to some calculation, allow to specify which group is embed in which group, but we inserted no value for this. No panic : we have a script to regenerate the good values for both new groups.
Create a file named rebuild.php, place-it at Joomla's root with this inside :
...don't forget to change « USERNAME_DB », « PASSWORD_DB » et « NAME_DB » for the username, the password and the name of the database.
Run the script in your browser, by opening rebuild.php page. Normally, you should not notice something; the script doesn't write any confirmation (so you get a blank page). Go to check what it does look like in the database, if you understand a little bit how's working this category level system... else, try to go on the next step, it should be okay.
Hint : your two new groups should now own a new value (higher than zero), for columns « lft » and « rgt ». Else, you have probably specified wrong informations for database connection in the script above, or you forgot to change table names (prefix) in queries.
Another good way to check if everything is working fine is : go to Users administration (Administration Joomla!), select a user and check that you can set one of the new groups as group for this user.
The idea itself is really simple : In Community Builder, you can set a user group to a tab.
To go on with this example, go to Community Builder's component page, click on Tab Management and create two new tabs :
« About my business » : Set this tab to « Employer » group, and don't forget to publish it.
« Job experiences » : Set this tab to « Employee » group, and don't forget to publish it.
Each custom user group now owns its own tab. As tabs that do not contain any field won't show up, go to Field Management, and create for these two new tabs field (same name as the tab, let's say), and don't forget to place each of them in the right tab.
We created two new custom groups, and in Joomla!'s reality, there are only three access levels : « public », « registered » and « special ». These levels are embed into each other; a « special » user will also own rights of a « registered » user. It causes a problem, because we wish that each user have its own tabs, without any mix!
For instance, the employer owns in its profile a tab to describe what's about is business, but the employee doesn't need this tab at all. One of the two groups will have more rights than the other, then we must find a way to make them independant from each other.
Now it's time to make some dirty coding : we must apply a little hack to Community Builder so that tabs are well splited. Don't forget to save your file before any modification! Numbers of code lines are given for CB 1.2 RC4, so if you use a older version, look for the same lines but their place may have changed. There will be three replacements to do; please note that we let the replaced line, commented.
Open this file : [VOTRE SITE]/administrator/components/com_comprofiler/comprofiler.class.php
Look for this line (line 3036) :
Replace it by this :
Look for this line (line 3493) :
Replace it by this :
Look for this line (line 3550) :
Replace it by this :
That's it, your file is now correctly patched!
Then, if you make a test by creating a user for each user group, each user account should normally see its own custom tab in its profile.
Now that display of custom tabs for custom user groups is working correctly, we must face another problem : how to include right users into right user groups?
Let them choose, of course!
A good thing for us, a plugin for that already exists : CB JLS Group Selection, created by Jorge Luis Savoini. Be aware that this plugin only works with Community Builder 1.2 RC3 !
After you downloaded the plugin, install it (Bottom of Plugin Management page of component Community Builder).
In Field Management page, create a new field named exactly « cb_usertype », « Drop Down (Single Select) ») type. Insert 2 values, exact names of your two groups (in our example, it is « employer » and « employeer »).
Click on the plugin (JLSGroupSelector) in the plugin list of Plugin Management page to configure it.
Now that it's possible to access configuration of JLS Group Selection, be sure that the plugin is published AND enabled.
All you have to do is asking user on registration to fill up the « cb_usertype » field, to force it choosing his user group itself.
That's all! It's pretty complex for something that should be so simple to do...
Thanks to Jorge Luis Savoini for his help concerning this custom user group problem and for his very useful plugin!
Comments
At first thanks for your
At first thanks for your great guide. Fortunatelly I've been operating a Job seeker site, to where this function mentioned absolutely useful. I've made 2 categories, namely: Employer, Job Seeker... I've checked in Joomla/User management and both of them exist, but if I registering as a employer the registration get in to the Employer section, if register a Job Seeker, the registered user get in to regular registered user section, not in the Job Seeker.
How can solve it, is that means any difficulties on the further??
Avec ses 55 millions de
Avec ses 55 millions de membres, force est de reconnaître que Facebook est une plateforme intéressante pour pousser son business. microsoft mcitp Intelligemment utilisé et pour les bons sujets, ce réseau social se révèle être une machine de guerre très efficace pour augmenter votre visibilité, voire vos ventes.
Hello, Its great work :) &
Hello,
Its great work :) & its work with me now ;)
Please ... do you have similir solution to add more user Access goroups more then Public/Registers/Special ?
Thanks again
Best Regards
That's the matter of this
That's the matter of this tutorial, isn't it?
This is the code am using :
This is the code am using :
mysql_connect("localhost", "NOM_DUTILISATEUR_BD", "MOT_DE_PASSE_BD") or
die("Could not connect: " . mysql_error());
mysql_select_db("NOM_DELA_BD");
rebuild_tree ( 0 , 1);
function rebuild_tree($parent_id, $left) {
$right = $left+1;
$result = mysql_query('SELECT id FROM jos_core_acl_aro_groups '.
'WHERE parent_id="'.$parent_id.'";');
while ($row = mysql_fetch_array($result)) {
$right = rebuild_tree($row['id'], $right);
}
mysql_query('UPDATE jos_core_acl_aro_groups SET lft='.$left.', rgt='.
$right.' WHERE id="'.$parent_id.'";');
return $right+1;
}
?>
You must replace database
You must replace database connection informations by yours.
NOM_DUTILISATEUR_BD = enter your username here
MOT_DE_PASSE_BD = enter your password here
NOM_DELA_BD = enter name of the database here
Hello , I did every thing
Hello ,
I did every thing exatlly as you said here!
But while am running the php patch rebuild.php I always have this error :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sifae/public_html/mbn/rebuild.php on line 11
Please note my Joomla Ver = 1.5.14.
Thanks for this great Idea,
Best Regards,
Tariq Hamed
hello, i want to create
hello, i want to create custom access group like "public , registered , special " thats i want..to make my new vip group member to have view access on my pages with specific access group like "vip" ..
did...you read the article?
did...you read the article?
Thanks for the walk
Thanks for the walk through... everything works perfectly except for one small problem.
When I as an admin try to create users myself in the backend I get an error that reads the following:
illegal attempt to set user at higher level than allowed !
Warning: Invalid argument supplied for foreach() in /home/sdunited/public_html/recruit/administrator/components/com_comprofiler/comprofiler.class.php on line 3897
Warning: Invalid argument supplied for foreach() in /home/sdunited/public_html/recruit/administrator/components/com_comprofiler/comprofiler.class.php on line 3502
Any thoughts? Thanks
Hi Joe, what is your Joomla!
Hi Joe, what is your Joomla! version? (exactly)
that nice patch and solved my
that nice patch and solved my many problems, only one thing remaining, how to show different fields during new user registration. working fine also in cb 1.2.1. i have created two usertype talent and employer your patch helps me to show different tabs on both usertypes profile. but it cant show same fields on registration form can anyone help me.
thanks in advance
I used Jquery to hide and pop
I used Jquery to hide and pop back fields that were not needed. For fields that were needed in one usertype to fields that were needed in some other usertype and filled the hidden ones with garbage data. A lot of possibilities are available but it's messy.
Uzair.
P.S. I've made a demo on the homepage, check it out.
Hi, I use both CB and JUGA.
Hi,
I use both CB and JUGA. (www.dioscouri.com)
JUGA creates 'groups' inside the 'registered' users.
Having applied your hack both nee groups act on the same level.
This makes it impossible to use JUGA's option to hide content A in an article to group B if group A and B both are children of Registered.
Any workaround?
Aftyer some adjustement it
Aftyer some adjustement it works, even with 3 groups.
I use {jugaaccess [groupname] to show conten belonging to each specific group.
sorry I couldn't reply to you
sorry I couldn't reply to you before, I'm glad to see you've found a workaround. I don't know Juga so I think I weren't able to help you
I did everything right. It
I did everything right. It works, but I would like to show some articles just to the people of my "newgroup" and not to other registered users. Is that possible? I just see the options : public, registered and special. The plugin that you suggest does not work for me. Any other solution????
Thanks a lot
Go to your phpmyadmin, if
Go to your phpmyadmin, if available and add the custom made groups into your 'jos_groups' table as well. It somewhat worked for me but you may need some other changes.
Uzair.
hi sir thats nice patch and
hi sir
thats nice patch and helps me a lot. only one thing remaining it cant so diff. fields on registration acc. to usertype. my mean to say if i choose usertype A on registration i want those tab fields on which i had giveN access level to usertype A. and if i choose usertype B on registration i want those tab fields on which i had given access level to usertype B.
THANKS IN ADVANCE
I think this set of 3 user
I think this set of 3 user groups is a different concept than the level user groups we made custom.
I think you will have to hack the content component + admin page... which is pretty dirty... if you have no choice, do it. But keep notes of what you're doing, because, of course, you'll have to do it again each time you upgrade your Joomla!; something you may already know. If you're in need of some hack work such this one you can contact me at info at guylabbe.ca
How can i display a Specific
How can i display a Specific tab only for a different user group.
EX: i want to show "messages" tab on community builder to my custom made user group"Paid members" & hide it from "Registered " user group when a Registered user visit to a profile i want to show a tab called "Pay to contact this user"
Help Appreciated.
Hi, you can set which user
Hi, you can set which user group has the "right" to see a tab. Click on the detail page of your tab in CB admin
For some reason I can't get
For some reason I can't get the rebuild.php script to work. It keeps giving me this error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content1/public_html/geronet/rebuild.php on line 1
Any ideas? Thanks!
Hi, look up your code, you
Hi, look up your code, you probably forgot to put a quote somewhere. If you want, Paste your code here (or send it to me info@guylabbe.ca) we'll help you out with this.
This hack won't work on CB
This hack won't work on CB 1.2.1 will it?
articles maintain same
articles maintain same groups
Hi Guy, Thank you for sharing your investigation. I did all you post and worked fine, but then I was supposed that when I need post an article now, it would be posible to match with some of the new groups, but id didn't. My question is if it is possible to do or not?
Thanks in advance,
Marcelo Parra
Hi, that should be possible
Hi, that should be possible without much trouble, need to see closer. I suggest you to use this component instead, according to "crony" (posted comment bellow) : http://extensions.joomla.org/extensions/access-&-security/frontend-acces...
Guy, can you use the above
Guy, can you use the above method for the older Joomla v1.0. Or is it only for v1.5. I have a site with several v1.0 components that will not work on v1.5
Sorry I'm affraid it's only
Sorry I'm affraid it's only working on J!1.5 and above versions ...
This is a hack that's going
This is a hack that's going to make patching hard
This tutorial is about adding custom user groups and as part of the solution modifies both Joomla and Community Builder. Ask your self what happens when you have to patch both Joomla and Community Builder with security updates? Then you have to reapply all you "hacks" again. And it's not even sure you can, because your a messing with the source code and new updates have every right to change everything in the code as long as the public interfaces are intact.
The tutorial demonstrates a clear violatoin of the Open Closed Principle - leaving the code open for extension but closed for modification. However, I understand that its extremly anoying that Joomla does not come with custom user groups!
I know Mark, that it isn't
I know Mark, that it isn't going to work with any update. It's only a short way to have this working with custom groups. I didn't mean to give a perfect and updatable solution, I just expected to give at least a way to do it, even if it's dirty.
You are a lifesaver. Thank
You are a lifesaver.
Thank you Guy, for your most excellent tutorial and your personal attention to help me get this working. I have a project that needed exactly this solution, and you saved us.
L'article a été mis à jour
L'article a été mis à jour après que Trish m'aie signalé une erreur dans
les remplacements de lignes de code vers la fin du tutoriel. Il manquait un ;
quelque part.
-----
The article was updated after that Trish noticed an error in
code replacements, at the end of the tutorial. It missed a ; somewhere.
Post new comment