Keyword

Hiding unwanted fields in frontend editor by user group

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 8 months ago #93349 by Terry Britton
I have seen several posts regarding hiding unwanted fields in the frontend editor and several posts asking about getting the user's group, and I needed to do both, so here's my solution.

Put the following code near the top of form.php

<?php// get user ID$user = &JFactory::getUser();$userId = $user->get('id');// get user Group$db =& JFactory::getDBO();$query = "  SELECT ".$db->nameQuote('group')."    FROM ".$db->nameQuote('jos_k2_users')."    WHERE ".$db->nameQuote('userID')." = ".$db->quote($userId).";  ";$db->setQuery($query);$userGroup = $db->loadResult();?>

 

You can then surround whatever element you want to hide as in the following example where I hide the toggle sidebar unless user is editor or site owner.

 

<?php if($userGroup == 2 OR $userGroup == 4) : ?>    <div id="k2ToggleSidebarContainer">     <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a>    </div>   <?php endif; ?>

 

These are my user group numbers and will be different on your site. Just check your database (jos_k2_user_groups) to get the numbers that correspond to each of your groups. 

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

More
13 years 8 months ago #93350 by william white
No rating system here so i will make one *****

This can be used in many instances, especially the query of the database to get info

thanks for posting!

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

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 8 months ago #93351 by Terry Britton
William,

Here's a great resource for writing db queries in Joomla: docs.joomla.org/How_to_use_the_database_classes_in_your_script.William White said:

No rating system here so i will make one *****

This can be used in many instances, especially the query of the database to get info

thanks for posting!

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

More
13 years 6 months ago #93352 by Radik
Where is file form.php? I can;t find it. Please help me!

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

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 6 months ago #93353 by Terry Britton
/components/com_k2/views/item/tmpl/form.php

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

More
13 years 6 months ago #93354 by Radik
I have extra fields, Can i hide this fileds?

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

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 6 months ago #93355 by Terry Britton
In the input form or in the item view?

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

More
13 years 6 months ago #93356 by Radik
I need to hide Extra fields from non-registered users. If a user is logged in Extra Fields need to show.

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

More
13 years 6 months ago #93357 by Radik
Can You help me?

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

  • Terry Britton
  • Terry Britton's Avatar Topic Author
  • Offline
  • Elite Member
More
13 years 6 months ago #93358 by Terry Britton
In item.php add the following near the top of the page.

<?php$user = &JFactory::getUser();$userId = $user->get('id');?>

Then surround the extra fields (lines 254-268) with the following.

<?php if($userId != 0) : ?>

    extra fields stuff

<?php endif; ?>

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


Powered by Kunena Forum