Forums

Chronoforms with JUGA

pbeckermann 22 Mar, 2010
I am using Chronoforms to create a custom registration page. How can we add a function or plugin to now add the user to a specific JUGA group?

Thanks
GreyHead 22 Mar, 2010
Hi pbeckermann,

What code does JUGA use to do this?

Bob
deckg 03 Aug, 2011

Hi pbeckermann,

What code does JUGA use to do this?

Bob



Hi,

Was looking for an answer to this myself.
Juga has created a table called jos_juga_u2g with two fields, user_id and group_id

The user id is the normal joomla id. The group_id is the juga group created in the juga admin section.

Unfortunately the group_id is not dynamic so when a user is created via a chronoform this field is not updated, the juga settings are used (you can automatically assign a group type in juga but only one for new registrations)

I've created a website using joomla 1.5 and have created several different user types, type1, type2 etc. I then created a chronoform that creates users for these different types depending on which form is selected.

Last thing to do is assign the juga type, and I'm stumped here as new to all this! (think I've done well to hack joomla to allow me the new user types!!)

So how can I use chronoforms to update the group_id of the user_id of the newly created user to what I choose (numerical between 1 - 10)??

Once this is done my work is done for this website!

Any suggestions much appreciated.

All the best,

Derek
deckg 03 Aug, 2011
I think what is needed is for the chronoform to create a user (done), then find the new user id, then find the id in the juga list and update the group number.

Anyone know how to do this?????
deckg 04 Aug, 2011
$username = ($_POST['username']);
$user_id = JFactory::getUser($username)->get('id');


The above code finds the user id of the username just created with Chronoforms, any idea where I go from here??

When I tried a test to enter data from a form (user_id and Group_id entered) the DB function of Chronoforms entered them into the table perfectly, so how do I pass the data from the above piece of code into the DB function?

Almost there!😀
deckg 05 Aug, 2011
:D 😀 😀

Got it,

The script below should be inserted as custom code in the registration, onsucess box, with mode set to 'view'.

The code will look up the username just registered (username field in the form), find their id number from the joomla database and then update the juga database with the group id you choose, in this case "4".

My brain exploded with this as new to php, juga and chronoforms!

Let me know if anyone finds this useful🙂



<?php
$database = &JFactory::getDBO();
$username = ($_POST['username']);
$jugagroup_id = 4;
$user_id = JFactory::getUser($username)->get('id');

// query the db to see if the user is already a member of group
$database->setQuery("SELECT `user_id` FROM #__juga_u2g "
." WHERE `group_id` = '$jugagroup_id'"
." AND `user_id` = '$user_id' ");
$already = $database->loadResult();

// if they aren't already a member of the group, add them to the group
if (($already != $user_id)) {
$query = "INSERT INTO #__juga_u2g "
."\n SET `user_id` = '$user_id',"
."\n `group_id` = '$jugagroup_id'";
$database->setQuery( $query );
if (!$database->query()) {
echo $database->getErrorMsg();
}
}
?>
GreyHead 05 Aug, 2011
Hi debkg,

Well done !!!

Bob
deckg 05 Aug, 2011
Cheers!
Forgot to mention that if you leave the auto assign function in the Juga user plugin turned on, your user will be assigned to two groups, the one in the plugin and the one in the code above, so watch out for that!
This topic is locked and no more replies can be posted.