2013-01-11 16:55:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of view class
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2013-01-11 16:55:34 +00:00
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
2017-06-19 09:08:06 +00:00
|
|
|
require_once "inc.ClassHook.php";
|
2017-05-02 16:29:47 +00:00
|
|
|
|
2013-01-11 16:55:34 +00:00
|
|
|
/**
|
|
|
|
* Parent class for all view classes
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2013-01-11 16:55:34 +00:00
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2013-02-14 11:10:53 +00:00
|
|
|
class SeedDMS_View_Common {
|
2015-08-20 13:53:30 +00:00
|
|
|
protected $theme;
|
2013-01-11 16:55:34 +00:00
|
|
|
|
2015-08-20 13:53:30 +00:00
|
|
|
protected $params;
|
2013-01-11 16:55:34 +00:00
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
protected $baseurl;
|
|
|
|
|
|
|
|
protected $imgpath;
|
|
|
|
|
|
|
|
public function __construct($params, $theme='bootstrap') {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->theme = $theme;
|
|
|
|
$this->params = $params;
|
2018-04-06 06:31:11 +00:00
|
|
|
$this->baseurl = '';
|
2021-07-05 14:29:30 +00:00
|
|
|
if(isset($params['settings']))
|
|
|
|
$this->imgpath = $params['settings']->_httpRoot.'views/'.$theme.'/images/';
|
|
|
|
else
|
|
|
|
$this->imgpath = '../views/'.$theme.'/images/';
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 19:41:12 +00:00
|
|
|
/**
|
|
|
|
* Call method with name in $get['action']
|
|
|
|
*
|
|
|
|
* Until 5.1.26 (6.0.19) this method took the name of the
|
|
|
|
* controller method to run from the element 'action' passed
|
|
|
|
* in the array $get. Since 5.1.27 (6.0.20) a PSR7 Request
|
|
|
|
* object is available in the controller and used to get the
|
|
|
|
* action.
|
|
|
|
*
|
|
|
|
* @params array $get $_GET or $_POST variables (since 5.1.27 this is no longer used)
|
|
|
|
* @return mixed return value of called method
|
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function __invoke($get=array()) {
|
2022-07-29 19:41:12 +00:00
|
|
|
$action = null;
|
|
|
|
$request = $this->getParam('request');
|
|
|
|
if($request) {
|
|
|
|
if($request->isMethod('get'))
|
|
|
|
$action = $request->query->get('action');
|
|
|
|
elseif($request->isMethod('post'))
|
|
|
|
$action = $request->request->get('action');
|
|
|
|
}
|
2022-08-01 10:11:51 +00:00
|
|
|
if(!$this->callHook('preRun', get_class($this), $action ? $action : 'show')) {
|
2022-07-29 19:41:12 +00:00
|
|
|
if($action) {
|
|
|
|
if(method_exists($this, $action)) {
|
|
|
|
$this->{$action}();
|
|
|
|
} else {
|
|
|
|
echo "Missing action '".htmlspecialchars($action)."'";
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
$this->show();
|
2022-08-01 10:11:51 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
2022-07-29 19:41:12 +00:00
|
|
|
}
|
|
|
|
$this->callHook('postRun', $action ? $action : 'show');
|
2015-08-20 13:53:30 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setParams($params) {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setParam($name, $value) {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->params[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function getParam($name) {
|
2015-08-25 12:58:16 +00:00
|
|
|
if(isset($this->params[$name]))
|
|
|
|
return $this->params[$name];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-12 10:02:03 +00:00
|
|
|
/**
|
|
|
|
* Check if the view has a parameter with the given name
|
|
|
|
*
|
|
|
|
* @param string $name name of parameter
|
|
|
|
* @return boolean true if parameter exists otherwise false
|
|
|
|
*/
|
2022-07-29 19:41:12 +00:00
|
|
|
public function hasParam($name) {
|
2020-05-12 10:02:03 +00:00
|
|
|
return isset($this->params[$name]) ? true : false;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function unsetParam($name) {
|
2013-06-18 16:14:14 +00:00
|
|
|
if(isset($this->params[$name]))
|
|
|
|
unset($this->params[$name]);
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setBaseUrl($baseurl) {
|
|
|
|
$this->baseurl = $baseurl;
|
|
|
|
}
|
|
|
|
|
2021-01-13 08:05:19 +00:00
|
|
|
public function getTheme() {
|
|
|
|
return $this->theme;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function show() {
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
|
2013-07-31 15:28:02 +00:00
|
|
|
/**
|
2021-04-23 07:56:25 +00:00
|
|
|
* Return a list of hook classes for the current class
|
2013-07-31 15:28:02 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* Hooks are associated to a view class. Calling a hook with
|
|
|
|
* SeedDMS_View_Common::callHook() will run through a list of
|
|
|
|
* view classes searching for the hook. This method returns this
|
|
|
|
* list.
|
2013-07-31 15:28:02 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* If a view is implemented in SeedDMS_View_Example which inherits
|
|
|
|
* from SeedDMS_Theme_Style which again inherits from SeedDMS_View_Common,
|
|
|
|
* then this method will return an array with the elments:
|
|
|
|
* 'Example', 'Style', 'Common'. If SeedDMS_View_Example also sets
|
|
|
|
* the class property 'viewAliasName', then this value will be added
|
|
|
|
* to the beginning of the list.
|
2015-07-15 20:30:03 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* When a hook is called, it will run through this list and checks
|
|
|
|
* if $GLOBALS['SEEDDMS_HOOKS']['view'][<element>] exists and contains
|
|
|
|
* an instanciated class. This class must implement the hook.
|
|
|
|
*
|
|
|
|
* @return array list of view class names.
|
2013-07-31 15:28:02 +00:00
|
|
|
*/
|
2021-04-23 07:56:25 +00:00
|
|
|
protected function getHookClassNames() { /* {{{ */
|
2019-08-08 07:11:47 +00:00
|
|
|
$tmps = array();
|
2021-04-23 04:55:10 +00:00
|
|
|
/* the viewAliasName can be set in the view to specify a different name
|
|
|
|
* than extracted from the class name.
|
|
|
|
*/
|
|
|
|
if(property_exists($this, 'viewAliasName') && !empty($this->viewAliasName)) {
|
|
|
|
$tmps[] = $this->viewAliasName;
|
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
$tmp = explode('_', get_class($this));
|
2019-08-08 07:11:47 +00:00
|
|
|
$tmps[] = $tmp[2];
|
2020-12-15 19:20:37 +00:00
|
|
|
foreach(class_parents($this) as $pc) {
|
|
|
|
$tmp = explode('_', $pc);
|
|
|
|
$tmps[] = $tmp[2];
|
|
|
|
}
|
2019-08-08 07:11:47 +00:00
|
|
|
/* Run array_unique() in case the parent class has the same suffix */
|
|
|
|
$tmps = array_unique($tmps);
|
2021-04-23 07:56:25 +00:00
|
|
|
return $tmps;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call a hook with a given name
|
|
|
|
*
|
|
|
|
* Checks if a hook with the given name and for the current view
|
|
|
|
* exists and executes it. The name of the current view is taken
|
|
|
|
* from the current class name by lower casing the first char.
|
|
|
|
* This function will execute all registered hooks in the order
|
|
|
|
* they were registered.
|
|
|
|
*
|
|
|
|
* Attention: as func_get_arg() cannot handle references passed to the hook,
|
|
|
|
* callHook() should not be called if that is required. In that case get
|
|
|
|
* a list of hook objects with getHookObjects() and call the hooks yourself.
|
|
|
|
*
|
|
|
|
* @params string $hook name of hook
|
|
|
|
* @return string concatenated string, merged arrays or whatever the hook
|
|
|
|
* function returns
|
|
|
|
*/
|
|
|
|
public function callHook($hook) { /* {{{ */
|
|
|
|
$tmps = $this->getHookClassNames();
|
2013-09-03 20:07:16 +00:00
|
|
|
$ret = null;
|
2019-08-08 07:11:47 +00:00
|
|
|
foreach($tmps as $tmp)
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)] as $hookObj) {
|
2013-05-02 10:12:28 +00:00
|
|
|
if (method_exists($hookObj, $hook)) {
|
2013-07-31 15:28:02 +00:00
|
|
|
switch(func_num_args()) {
|
|
|
|
case 1:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this);
|
|
|
|
break;
|
2013-07-31 15:28:02 +00:00
|
|
|
case 2:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1));
|
|
|
|
break;
|
2013-07-31 15:28:02 +00:00
|
|
|
case 3:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
|
2017-01-17 16:41:52 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 5:
|
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
|
2017-05-02 16:29:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-13 12:41:57 +00:00
|
|
|
if($tmpret !== null) {
|
2019-01-17 17:30:10 +00:00
|
|
|
if(is_string($tmpret)) {
|
|
|
|
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? $ret.$tmpret : array_merge($ret, array($tmpret)));
|
|
|
|
} elseif(is_array($tmpret) || is_object($tmpret)) {
|
|
|
|
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? array_merge(array($ret), $tmpret) : array_merge($ret, $tmpret));
|
2017-06-13 12:41:57 +00:00
|
|
|
} else
|
2017-05-02 16:29:47 +00:00
|
|
|
$ret = $tmpret;
|
2013-07-31 15:28:02 +00:00
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-03 20:07:16 +00:00
|
|
|
return $ret;
|
2014-01-10 06:56:19 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2015-07-15 20:30:03 +00:00
|
|
|
/**
|
|
|
|
* Return all hook objects for the given or calling class
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* <?php
|
|
|
|
* $hookObjs = $this->getHookObjects();
|
|
|
|
* foreach($hookObjs as $hookObj) {
|
|
|
|
* if (method_exists($hookObj, $hook)) {
|
|
|
|
* $ret = $hookObj->$hook($this, ...);
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ?>
|
|
|
|
* </code>
|
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* The method does not return hooks for parent classes nor does it
|
|
|
|
* evaluate the viewAliasName property.
|
|
|
|
*
|
2015-07-15 20:30:03 +00:00
|
|
|
* @params string $classname name of class (current class if left empty)
|
|
|
|
* @return array list of hook objects registered for the class
|
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function getHookObjects($classname='') { /* {{{ */
|
2015-07-15 20:30:03 +00:00
|
|
|
if($classname)
|
2022-06-16 10:43:50 +00:00
|
|
|
$tmps = array(explode('_', $classname)[2]);
|
2015-07-15 20:30:03 +00:00
|
|
|
else
|
2022-06-16 10:43:50 +00:00
|
|
|
$tmps = $this->getHookClassNames();
|
|
|
|
$hooks = [];
|
|
|
|
foreach($tmps as $tmp) {
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) {
|
|
|
|
$hooks = array_merge($hooks, $GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)]);
|
|
|
|
}
|
2015-07-15 20:30:03 +00:00
|
|
|
}
|
2022-06-16 10:43:50 +00:00
|
|
|
return $hooks;
|
2015-07-15 20:30:03 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2014-01-10 06:56:19 +00:00
|
|
|
/**
|
|
|
|
* Check if a hook is registered
|
|
|
|
*
|
|
|
|
* @param $hook string name of hook
|
|
|
|
* @return mixed false if one of the hooks fails,
|
|
|
|
* true if all hooks succedded,
|
|
|
|
* null if no hook was called
|
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function hasHook($hook) { /* {{{ */
|
2021-04-23 07:56:25 +00:00
|
|
|
$tmps = $this->getHookClassNames();
|
2019-10-01 12:06:00 +00:00
|
|
|
foreach($tmps as $tmp) {
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, $hook)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-10 06:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} /* }}} */
|
|
|
|
|
2021-07-06 07:31:11 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-07-07 06:25:26 +00:00
|
|
|
protected function check_view_access($name='') { /* {{{ */
|
2021-07-06 07:31:11 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-07-07 06:25:26 +00:00
|
|
|
protected function html_url($view, $urlparams=array()) { /* {{{ */
|
2021-07-06 16:15:00 +00:00
|
|
|
$url = $this->params['settings']->_httpRoot."out/out.".$view.".php";
|
2021-07-06 07:31:11 +00:00
|
|
|
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
|
|
|
|
*/
|
2023-06-02 16:10:39 +00:00
|
|
|
protected function html_link($view, $urlparams, $linkparams, $link, $hsc=true, $nocheck=false, $wrap=array()) { /* {{{ */
|
2021-07-06 07:31:11 +00:00
|
|
|
if(!$nocheck)
|
2021-07-07 06:25:26 +00:00
|
|
|
if(!$this->check_view_access($view))
|
2021-07-06 07:31:11 +00:00
|
|
|
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;
|
|
|
|
} /* }}} */
|
|
|
|
|
2019-08-08 07:11:47 +00:00
|
|
|
public function jsTranslations($keys) { /* {{{ */
|
2016-03-08 09:37:07 +00:00
|
|
|
echo "var trans = {\n";
|
|
|
|
foreach($keys as $key) {
|
|
|
|
echo " '".$key."': '".str_replace("'", "\\\'", getMLText($key))."',\n";
|
|
|
|
}
|
|
|
|
echo "};\n";
|
2019-08-08 07:11:47 +00:00
|
|
|
} /* }}} */
|
2023-02-22 08:59:45 +00:00
|
|
|
|
|
|
|
public static function getContrastColor($hexcolor) { /* {{{ */
|
|
|
|
$r = hexdec(substr($hexcolor, 1, 2));
|
|
|
|
$g = hexdec(substr($hexcolor, 3, 2));
|
|
|
|
$b = hexdec(substr($hexcolor, 5, 2));
|
2023-03-03 15:14:01 +00:00
|
|
|
if(0) {
|
|
|
|
$yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
|
|
|
|
return ($yiq >= 148) ? '000000' : 'ffffff';
|
|
|
|
} else {
|
|
|
|
$l = (max($r, max($g, $b)) + min($r, min($g, $b)))/2;
|
|
|
|
return ($l > 128) ? '000000' : 'ffffff';
|
|
|
|
}
|
2023-02-22 08:59:45 +00:00
|
|
|
} /* }}} */
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|