mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 07:22:11 +00:00
add methods check_access(), html_url(), html_link() backported from 6.0.x
This commit is contained in:
parent
6ce08a531f
commit
496c70c024
|
@ -248,6 +248,80 @@ class SeedDMS_View_Common {
|
|||
return false;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Check if the access on the view with given name or the current view itself
|
||||
* may be accessed.
|
||||
*
|
||||
* The function requires the parameter 'accessobject' to be available in the
|
||||
* view, because it calls SeedDMS_AccessOperation::check_view_access()
|
||||
* to check access rights. If the the optional $name is not set the
|
||||
* current view is used.
|
||||
*
|
||||
* If $name is an array then just one of the passed objects in the array
|
||||
* must be accessible for this function to return true.
|
||||
*
|
||||
* @param string|array $name name of view or list of view names
|
||||
* @return boolean true if access is allowed otherwise false
|
||||
*/
|
||||
protected function check_access($name='') { /* {{{ */
|
||||
if(!$name)
|
||||
$name = $this;
|
||||
if(!isset($this->params['accessobject']))
|
||||
return false;
|
||||
$access = $this->params['accessobject']->check_view_access($name);
|
||||
return $access;
|
||||
|
||||
if(isset($this->params['user']) && $this->params['user']->isAdmin()) {
|
||||
if($access === -1)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
return ($access === 1);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Create an url to a view
|
||||
*
|
||||
* @param string $name name of view
|
||||
* @param array $urlparams list of url parameters
|
||||
* @return string $url
|
||||
*/
|
||||
protected function html_url($view='', $urlparams) { /* {{{ */
|
||||
$url = "../out/out.".$view.".php";
|
||||
if($urlparams)
|
||||
$url .= "?".http_build_query($urlparams);
|
||||
return $url;
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Create a html link to a view
|
||||
*
|
||||
* First checks if the view may be accessed by the user
|
||||
*
|
||||
* @param string $name name of view
|
||||
* @param array $urlparams list of url parameters
|
||||
* @param array $linkparams list of link attributes (e.g. class, target)
|
||||
* @param string $link the link text itself
|
||||
* @param boolean $hsc set to false if htmlspecialchars() shall not be called
|
||||
* @return string link
|
||||
*/
|
||||
protected function html_link($view='', $urlparams=array(), $linkparams=array(), $link, $hsc=true, $nocheck=false, $wrap=array()) { /* {{{ */
|
||||
if(!$nocheck)
|
||||
if(!$this->check_access($view))
|
||||
return '';
|
||||
$url = $this->html_url($view, $urlparams);
|
||||
$tag = "<a href=\"".$url."\"";
|
||||
if($linkparams)
|
||||
foreach($linkparams as $k=>$v)
|
||||
$tag .= " ".$k."=\"".$v."\"";
|
||||
$tag .= ">".($hsc ? htmlspecialchars($link) : $link)."</a>";
|
||||
if(is_array($wrap) && count($wrap) == 2)
|
||||
return $wrap[0].$tag.$wrap[1];
|
||||
return $tag;
|
||||
} /* }}} */
|
||||
|
||||
public function jsTranslations($keys) { /* {{{ */
|
||||
echo "var trans = {\n";
|
||||
foreach($keys as $key) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user