Example #1
0
function smarty_block_ifAllowed($params, $content, $smarty, $repeat)
{
	$tpl_vars = $smarty->_tpl_vars;
	// only output on the closing tag
	if (!$repeat)
	{
		if (isset($content) && isset($params['controller']))
		{
			if (RivetyCore_ResourceCheck::isAllowed($params['resource'], $params['module'], $params['username'], $params['controller']))
			{
				return $content;
			}
			else
			{
				return null;
			}
		}
		if (isset($content) && !isset($params['controller']))
		{
			if (RivetyCore_ResourceCheck::isAllowed($params['resource'], $params['module'], $params['username']))
			{
				return $content;
			}
			else
			{
				return null;
			}
		}
	}
}
Example #2
0
	public function _bumpRegionalAccess ($bypass = null) {
		$roles_table = new Roles();
		$roles_resources_table = new RolesResources();

		if (isset($this->resource_locale)) {
			$resource_locale = $this->resource_locale;
		} else {
			$resource_locale = $this->locale_code;
		}
		$role_lock = array();
		if ($this->_identity->isAdmin) {
			$role_lock = @RivetyCore_ResourceCheck::isAllowed("locale_specific_admin_role", "default", $this->_identity->username);
		}
		if(count($role_lock) > 0){ //user is under some type of locale restriction
			$shortnames = array();
			if (is_array($role_lock)){
				foreach ($role_lock as $i) {
					$shortnames[] = $roles_table->getShortnameById($i); //get the shortnames of the locked roles
				}
			}
			$match = array();
			foreach ($shortnames as $sn) {
				if(stristr($sn,$resource_locale)){  //we've got an access match to a shortname locale
					$match[] = array("id" => $roles_table->getIdByShortname($sn), "shortname" => $sn);
				} else {
					$no_match[] = array("id" => $roles_table->getIdByShortname($sn), "shortname" => $sn);
				}
			}
			$access = array();
			if (count($match) > 0 || count($bypass) > 0) {

				if (count($match) > 0) {
					foreach ($match as $m) {
						$m_in = $this->_checkMatch($m['id']);
						if (count($m_in) > 0) {
							foreach ($m_in as $m) {
								$access[] = array("id"=>$m,"shortname"=>$roles_table->getShortnameById($m));
							}
						}
					}
				}
				if (count($bypass) > 0) {
					foreach ($bypass as $bp) {
						$b_in = $this->_checkMatch($bp);
						if (count($b_in) > 0) {
							foreach ($b_in as $b) {
								$access[] = array("id"=>$b,"shortname"=>$roles_table->getShortnameById($b));
							}
						}
					}
				}
			}
			if (count($access) === 0) { //if no access we have to put them somewhere they belong.
				$allowed = array();
				foreach ($shortnames as $allowed_locales) {

					$allowed[] = strtolower(substr($allowed_locales, -5));
				}
				if (!in_array($this->locale_code,$allowed) && count($allowed) > 0) {
					$this->locale_code = $allowed[0];
				}
				$this->_redirect('/default/admin/index/'); // bump to admin home

			}
			else
			{
				$this->restricted_role_id = $access;
				return $access;
			}
		}
	}