Translations of this page:

Permission Based Icon Array

This component was designed to display permission based icon array on the intranet homepage Displays content depending on user permissions. Permissions defined by attributes: user, group, group_tree, role, extranet Each attribute may contain comma-separated list of IDs. They work the same way as normal Claromentis permissions. Displayed content is defined by attributes: * href, src, alt

1. Create file called ComponentIconArray.php and paste in the following code.

<?
/**
 * Displays content depending on user permissions.
 *
 * Permissions defined by attributes:
 *   user, group, group_tree, role, extranet
 * Each attribute may contain comma-separated list of IDs. They work the same way as normal Claromentis permissions.
 *
 * Displayed content is defined by attributes:
 *   href, src, alt
 * Template is main/component_icon.html
 */
 
class ComponentIconArray extends TemplaterComponentTmpl
{
	public function Show($attributes)
	{
		$args = array();
		$perm_block_obj = new TemplaterComponentPermBlock();
		if ($perm_block_obj->UserHasPermission($attributes))
		{
			$args['outer_div.visible'] = 1;
			$args['href_tag.href'] = $attributes['href'];
			$args['image.src'] = $attributes['src'];
			$args['image.alt'] = $attributes['alt'];
			$args['image.title'] = isset($attributes['title']) ? $attributes['title'] : $attributes['alt'];
		} else
		{
			$args['outer_div.visible'] = 0;
		}
		return $this->CallTemplater("main/component_icon.html", $args);
	}
}
?>

For Claromentis version earlier than 5.6.2 create TemplaterComponentPermBlock.php

Not required in Claromentis starting from version 5.6.2.
<?
require_once("../common/common.php");
 
/**
 * Displays content depending on user permissions.
 *
 * Permissions defined by attributes:
 *   user, group, group_tree, role, extranet
 * Each attribute may contain comma-separated list of IDs. They work the same way as normal Claromentis permissions.
 *
 *
 * If according to these permissions user has rights, component returns value of attribute "content".
 * If no access, returns value of "content_denied", if exists, or empty string if "content_denied" is not given.
 *
 * Note, value of attributes "content" and "content_denied" should have all html special chars properly escaped -
 * usually this means replacing double quotes by &quot;, ampersands by &amp; and angle brackets by &lt; and &gt;
 *
 *
 * Example usage:
 *   <component class="TemplaterComponentPermBlock" role="1,5,12" user="1" content="accessible" content_denied="no access">
 * this will display text "accessible" to users with roles 1, 5 and 12 and to admin (user=1). Others will see "no access"
 *
 */
class TemplaterComponentPermBlock implements TemplaterComponent
{
	public function Show($attributes)
	{
		if ($this->UserHasPermission($attributes))
			return $attributes['content'];
 
		return isset($attributes['content_denied']) ? $attributes['content_denied'] : '';
	}
 
	public function UserHasPermission($attributes)
	{
		$perm = new Permissions(0, 0);
		foreach ($attributes as $a_name => $ids_str)
		{
			$perm_oclass = 0;
			switch ($a_name)
			{
				case 'user':
					$perm_oclass = PERM_OCLASS_INDIVIDUAL;
					break;
				case 'group':
					$perm_oclass = PERM_OCLASS_GROUP;
					break;
				case 'group_tree':
					$perm_oclass = PERM_OCLASS_GROUPTREE;
					break;
				case 'role':
					$perm_oclass = PERM_OCLASS_ROLE;
					break;
				case 'extranet':
					$perm_oclass = PERM_OCLASS_EXAREA;
					break;
				default:
					continue;
			}
			$ids = intval_r(explode(',', $ids_str));
			foreach ($ids as $id)
				$perm->Add(PERM_VIEW, $perm_oclass, $id);
		}
		return $perm->UserHasPermission(PERM_VIEW);
	}
}
 
?>

2. Copy both files into

/intranet/common/classes/

3. Create templater file called component_icon.html

<div class="icon_float" name="outer_div" visible="0">
<a href="http://www.somerurlhere.com/" target="_blank" name="href_tag"><img src="/pathtoimages.jpg" name="image" alt="SomeAltTaghere"/></a>
</div>

4. Paste the following component code anywhere on templater file

<component class="ComponentIconArray" role="1,5,12" user="1" href="http://www.someurlhere.com" src="/pathtoimages.jpg" alt="SomeAltTaghere">

Suggested location:

/interface_{custom}/main/intranet_home.html  

or

/interface_{custom}/main/right_column.html
 
components/icon_array.txt · Last modified: 07/06/2011 10:49 by sweta
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki