TOPIC:

Section only to a specific user 4 years 2 weeks ago #206142

  • MarioPuco's Avatar
  • MarioPuco
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 5958
  • Karma: 119
  • Thanks: 557
Hi,

Glad to be of assistance.
Let us know if you have any other questions.

Regards,
Mario

Please Log in or Create an account to join the conversation.

Section only to a specific user 1 year 2 months ago #243989

  • DavidLGCrawford
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 7
  • Thanks: 0
There is a bug in that code.
If the user is a superuser (group 8), but is also in another group, then the above code will turn on, and off, the section 2. The end result is that it may be on, or it may be off, depending upon the order that the groups were listed in.
Example. I am in group 6 and 8. If Joomla returns "6,8", then the first time through the foreach it will be 6 and turn section 2 OFF. Then it will go through the foreach with the value of 8 and turn section 2 ON. This gives the expected result of ON for group 8.
But if Joomla returns the groups as "8,6" then the first time through with value 8 turns section 2 ON, but then going through the foreach with a value of 6 would turn it OFF. The end result is that it would be OFF for me, even though I am in group 8 and should see it.

The following code clears that issue up by first setting a variable to FALSE, then turns it to TRUE if any of my groups is an 8. It doesn't matter what order the groups are returned in, if it foreach ever gets an 8, it will set the variable to TRUE. After all the groups have been checked we then turn ON or OFF sections based upon that variable.
$user = JFactory::getUser();
$groups = $user->get('groups');
$super = FALSE;
foreach($groups as $group)
{ 
  if ($group=='8') $super = TRUE;
}

if ($super)
{
  echo "<script>
    jQuery( document ).ready(function() {
    bfToggleFields('on','section','section2',bfDeactivateField);
    bfToggleFields('on','section','section1',bfDeactivateField);
    });
    </script>";
} else {
  echo "<script>
    jQuery( document ).ready(function() {
    bfToggleFields('off','section','section2',bfDeactivateField);
    bfToggleFields('on','section','section1',bfDeactivateField);
    });
    </script>";
}

Please Log in or Create an account to join the conversation.

Section only to a specific user 1 year 2 months ago #243993

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6888
  • Karma: 3
  • Thanks: 492
Hi,

so everything is fine now or you need help?

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Last edit: Post by tihana.krivic.
  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.044 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!