- 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
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
- Posts: 3722
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
- Posts: 198
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
- Posts: 8
Please Log in or Create an account to join the conversation.
- Terry Britton
-
Topic Author
- Offline
- Elite Member
- Posts: 198
Please Log in or Create an account to join the conversation.
- Radik
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Terry Britton
-
Topic Author
- Offline
- Elite Member
- Posts: 198
Please Log in or Create an account to join the conversation.
- Radik
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Radik
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Terry Britton
-
Topic Author
- Offline
- Elite Member
- Posts: 198
<?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.
- Radik
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Mihir Patel
-
- Offline
- Junior Member
- Posts: 22
Can you tell me how to hide the extrafields from the form.php.......I tried it but not successful. I want two user type in jomsocial. I just want to hide the last extrafield for one of the two user types.
Below is the code in form.php. anything i am trying to echo in td...its not even displaying....Am i working on wrong page or wat ???
<table class="admintable" id="extraFields" >
<?php foreach ($this->extraFields as $extraField): ?>
<tr>
<td align="right" class="key"><?php echo $extraField->name; ?></td>
<td><?php echo $extraField->element; ?></td>
</tr>
<?php endforeach; ?>
</table>
Please Log in or Create an account to join the conversation.
- Alessandro Catania
-
- Offline
- New Member
- Posts: 2
PS: the file is now at components/com_k2/templates/default/itemform.php i think. send me your feedback
<?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();?>
<?php if($userGroup == 2 OR $userGroup == 4) : ?> <div id="k2ToggleSidebarContainer"> <a href="#" id="k2ToggleSidebar"><?php echo JText::_('Toggle sidebar'); ?></a> </div> <?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