- Posts: 198
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Hiding unwanted fields in frontend editor by user group
Hiding unwanted fields in frontend editor by user group
- Terry Britton
- Topic Author
- Offline
- Elite Member
Less
More
13 years 8 months ago #93349
by Terry Britton
Hiding unwanted fields in frontend editor by user group was created 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.
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.
- william white
- Offline
- Platinum Member
Less
More
- Posts: 3722
13 years 8 months ago #93350
by william white
Replied by william white on topic Hiding unwanted fields in frontend editor by user group
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!
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
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 198
13 years 8 months ago #93351
by Terry Britton
Replied by Terry Britton on topic Hiding unwanted fields in frontend editor by user group
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!
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.
- Radik
- Offline
- New Member
Less
More
- Posts: 8
13 years 6 months ago #93352
by Radik
Replied by Radik on topic Hiding unwanted fields in frontend editor by user group
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
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 198
13 years 6 months ago #93353
by Terry Britton
Replied by Terry Britton on topic Hiding unwanted fields in frontend editor by user group
/components/com_k2/views/item/tmpl/form.php
Please Log in or Create an account to join the conversation.
- Radik
- Offline
- New Member
Less
More
- Posts: 8
13 years 6 months ago #93354
by Radik
Replied by Radik on topic Hiding unwanted fields in frontend editor by user group
I have extra fields, Can i hide this fileds?
Please Log in or Create an account to join the conversation.
- Terry Britton
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 198
13 years 6 months ago #93355
by Terry Britton
Replied by Terry Britton on topic Hiding unwanted fields in frontend editor by user group
In the input form or in the item view?
Please Log in or Create an account to join the conversation.
- Radik
- Offline
- New Member
Less
More
- Posts: 8
13 years 6 months ago #93356
by Radik
Replied by Radik on topic Hiding unwanted fields in frontend editor by user group
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.
- Radik
- Offline
- New Member
Less
More
- Posts: 8
13 years 6 months ago #93357
by Radik
Replied by Radik on topic Hiding unwanted fields in frontend editor by user group
Can You help me?
Please Log in or Create an account to join the conversation.
- Terry Britton
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 198
13 years 6 months ago #93358
by Terry Britton
Replied by Terry Britton on topic Hiding unwanted fields in frontend editor by user group
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; ?>
<?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.
- Forum
- K2 Community Forum
- English K2 Community
- Hiding unwanted fields in frontend editor by user group