Home > CMS, Joomla, Technology > category wise user management in Joomla (part 1)

category wise user management in Joomla (part 1)

Joomla 1.5.8 user management component have some limitation , There you cant give user rights on category basis , If user “xyz” is an editor then he can edit all the contents in all categories , But if there is an requirement that user “xyz” can edit only category “abc” then what to do ? Current Joomla 1.5.8  components dont have this built in functionality, And all extensions related this are commercial , So In this opensource world we dont need to buy component for this functionality , I have found some simple code which we need to add in some files of Joomla .

Here are the steps to do it

1) Open \administrator\components\com_users\models\author.xml

2) Replace the  existing code by following code

<?xml version=”1.0″ encoding=”utf-8″?>
<form>
<params>
<param name=”admin_language” type=”languages” client=”administrator” default=”" label=”Back-end Language” description=”paramAdminLanguage” />
<param name=”language” type=”languages” client=”site” default=”" label=”Front-end Language” description=”paramLanguage” />
<param name=”editor” type=”editors” default=”" label=”User Editor” description=”WYSIWYG Editor for this User” />
<param name=”helpsite” type=”helpsites” default=”" label=”Help Site” description=”Help Site for this User” />
<param name=”timezone” type=”timezones” default=”" label=”Time Zone” description=”Time Zone for this User” />
<param name=”categoryuser” type=”list” default=”" label=”Category based user” description=”If yes user permission restricted to category wise, Enter the ids of categories in Associated Categories field ” >
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>
<param name=”categories” type=”text” default=”" size=”80″ label=”Associated Categories” description=”Enter the categories ID , for multiple categories comma separated ” />
</params>
</form>

3) Open \administrator\components\com_users\models\user.xml

4) Replace the  existing code by following code

<?xml version=”1.0″ encoding=”utf-8″?>
<form>
<params>
<param name=”admin_language” type=”languages” client=”administrator” default=”" label=”Back-end Language” description=”paramAdminLanguage” />
<param name=”language” type=”languages” client=”site” default=”" label=”Front-end Language” description=”paramLanguage” />
<param name=”editor” type=”editors” default=”" label=”User Editor” description=”WYSIWYG Editor for this User” />
<param name=”helpsite” type=”helpsites” default=”" label=”Help Site” description=”Help Site for this User” />
<param name=”timezone” type=”timezones” default=”" label=”Time Zone” description=”Time Zone for this User” />
<param name=”categoryuser” type=”list” default=”" label=”Category based user” description=”If yes user permission restricted to category wise, Enter the ids of categories in Associated Categories field ” >
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>
<param name=”categories” type=”text” default=”" size=”80″ label=”Associated Categories” description=”Enter the categories ID , for multiple categories comma separated ” />
</params>
</form>

5) Now open the file \components\com_content\helpers\icon.php

6) Find out edit function and replace that edit function by following updated edit function

function edit($article, $params, $access, $attribs = array())
{
$user =& JFactory::getUser();
$uri =& JFactory::getURI();
$ret = $uri->toString();

if ($params->get(‘popup’)) {
return;
}

if ($article->state < 0) {
return;
}

/* —- The code is added by prasad —- Purpose is content category wise user management ——*/

$userParams=array();
$a=array();

$userParams=explode(“\n”,$_SESSION['__default']["user"]->params);

for($i=0;$i<count($userParams);$i++)
{
$userParamskey=explode(“=”,$userParams[$i]);
$a[$userParamskey[0]]=$userParamskey[1];

}

if($a["categoryuser"]==”1″)
{

$userParams=explode(“,”,$a["categories"]);
$userPermit=false;
for($i=0;$i<count($userParams);$i++)
{

if($article->catid==$userParams[$i])
{
$userPermit=true;
}
}
if(!$userPermit)
{

return;
}
}

/* —- End of The code added by prasad —- Purpose is content category wise user management ——*/

if (!$access->canEdit && !($access->canEditOwn && $article->created_by == $user->get(‘id’))) {
return;
}

JHTML::_(‘behavior.tooltip’);

$url = ‘index.php?view=article&id=’.$article->slug.’&task=edit&ret=’.base64_encode($ret);
$icon = $article->state ? ‘edit.png’ : ‘edit_unpublished.png’;
$text = JHTML::_(‘image.site’, $icon, ‘/images/M_images/’, NULL, NULL, JText::_(‘Edit’));

if ($article->state == 0) {
$overlib = JText::_(‘Unpublished’);
} else {
$overlib = JText::_(‘Published’);
}
$date = JHTML::_(‘date’, $article->created);
$author = $article->created_by_alias ? $article->created_by_alias : $article->author;

$overlib .= ‘&lt;br /&gt;’;
$overlib .= JText::_($article->groups);
$overlib .= ‘&lt;br /&gt;’;
$overlib .= $date;
$overlib .= ‘&lt;br /&gt;’;
$overlib .= $author;

$button = JHTML::_(‘link’, JRoute::_($url), $text);

$output = ‘<span title=”‘.JText::_( ‘Edit Item’ ).’ :: ‘.$overlib.’”>’.$button.’</span>’;
return $output;
}

7) Now go to admin , user manager ,  add new user , there in RHS , In parameter block , 2 parameters added

a) Category Based user

b) Associated Categories

If Category Based user field is set to yes then the enter the associated category ids in Associated Categories field which we want to associate for the user . and save it ,  If that newly created user log in from frontend then he will have access only for those associated categories.

If  Category Based user field is set to No then user have access to all the categories .

For More info : mail me @ prasadwagholikar@in.com

Due to these changes the edit image or button will not be displayed with the unassociated categories article , it will be displayed only with associated categories for the user  , It can be useful for editor and publisher once they visit those category articles pages after login , But if they login through frontend then editor will get list of newly added articles to edit . Those articles can be from any categories, hence these changes wont affect there for the newly added articles  ,  this is a limitation for publisher also , he  also get the list from all categories. I am using  com_camelcitycontent2 component and I have made some changes in that component to achieve these requirements for my client  ” Read category wise user management in Joomla (part 2) to know how can we  achieve that?

“I have used these techniques to enhance my application and to meet my client requirements ,  please take backups of your stuff before changing or replacing anything , These changes are done for joomla 1.5.8 version”


Advertisement
Categories: CMS, Joomla, Technology
  1. Susheel
    October 12, 2010 at 5:42 am | #1

    Hi prasad,
    The tutorial you provided was an excellent one. I did the first part of this into my intranet site. Its working fine as u told. But there are two links {Submit An article, Submit a web link} in my menu. Now through this the publisher or editor can upload files in other categories.Is there any way we can stop this?

  1. August 18, 2009 at 7:25 am | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.