2013-07-21 09:47:49 +00:00
|
|
|
<?php
|
|
|
|
// SeedDMS. Document Management System
|
|
|
|
// Copyright (C) 2013 Uwe Steinmann
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
class SeedDMS_Controller_Common {
|
2014-12-08 13:36:26 +00:00
|
|
|
/**
|
|
|
|
* @var array $params list of parameters
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $params;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer $error error number of last run
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $error;
|
|
|
|
|
2015-04-15 14:11:45 +00:00
|
|
|
/**
|
|
|
|
* @var string $errormsg error message of last run
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $errormsg;
|
|
|
|
|
2013-07-21 09:47:49 +00:00
|
|
|
function __construct($params) {
|
|
|
|
$this->params = $params;
|
2014-12-08 13:36:26 +00:00
|
|
|
$this->error = 0;
|
2015-04-15 14:11:45 +00:00
|
|
|
$this->errormsg = '';
|
2013-07-21 09:47:49 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 06:15:26 +00:00
|
|
|
/**
|
|
|
|
* Call methods with name in $get['action']
|
|
|
|
*
|
|
|
|
* @params array $get $_GET or $_POST variables
|
|
|
|
* @return mixed return value of called method
|
|
|
|
*/
|
|
|
|
function __invoke($get=array()) {
|
|
|
|
if(isset($get['action']) && $get['action']) {
|
|
|
|
if(method_exists($this, $get['action'])) {
|
|
|
|
return $this->{$get['action']}();
|
|
|
|
} else {
|
|
|
|
echo "Missing action '".$get['action']."'";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return $this->run();
|
|
|
|
}
|
|
|
|
|
2013-07-21 09:47:49 +00:00
|
|
|
function setParams($params) {
|
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setParam($name, $value) {
|
|
|
|
$this->params[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2015-01-08 07:12:11 +00:00
|
|
|
/**
|
|
|
|
* Return value of a parameter with the given name
|
|
|
|
*
|
|
|
|
* This function may return null if the parameter does not exist or
|
|
|
|
* has a value of null. If in doubt call hasParam() to check if the
|
|
|
|
* parameter exists.
|
|
|
|
*
|
|
|
|
* @param string $name name of parameter
|
|
|
|
* @return mixed value of parameter or null if parameter does not exist
|
|
|
|
*/
|
|
|
|
function getParam($name) {
|
|
|
|
return isset($this->params[$name]) ? $this->params[$name] : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the controller has a parameter with the given name
|
|
|
|
*
|
|
|
|
* @param string $name name of parameter
|
|
|
|
* @return boolean true if parameter exists otherwise false
|
|
|
|
*/
|
|
|
|
function hasParam($name) {
|
|
|
|
return isset($this->params[$name]) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a parameter with the given name
|
|
|
|
*
|
|
|
|
* @param string $name name of parameter
|
|
|
|
*/
|
2013-07-21 09:47:49 +00:00
|
|
|
function unsetParam($name) {
|
|
|
|
if(isset($this->params[$name]))
|
|
|
|
unset($this->params[$name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
|
|
|
}
|
|
|
|
|
2014-12-08 13:36:26 +00:00
|
|
|
/**
|
|
|
|
* Get error number of last run
|
|
|
|
*
|
|
|
|
* @return integer error number
|
|
|
|
*/
|
|
|
|
public function getErrorNo() { /* {{{ */
|
|
|
|
return $this->error;
|
|
|
|
} /* }}} */
|
|
|
|
|
2015-04-15 14:11:45 +00:00
|
|
|
/**
|
|
|
|
* Get error message of last run
|
|
|
|
*
|
|
|
|
* @return string error message
|
|
|
|
*/
|
|
|
|
public function getErrorMsg() { /* {{{ */
|
|
|
|
return $this->errormsg;
|
|
|
|
} /* }}} */
|
|
|
|
|
2017-06-09 10:27:26 +00:00
|
|
|
/**
|
|
|
|
* Set error message
|
|
|
|
*
|
|
|
|
* @param string $msg error message
|
|
|
|
*/
|
|
|
|
public function setErrorMsg($msg) { /* {{{ */
|
|
|
|
$this->errormsg = $msg;
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-01-10 06:52:53 +00:00
|
|
|
/**
|
|
|
|
* Call a controller hook
|
|
|
|
*
|
2016-11-22 08:21:12 +00:00
|
|
|
* If a hook returns false, then no other hook will be called, because the
|
|
|
|
* method returns right away. If hook returns null, then this is treated like
|
|
|
|
* it was never called and the default action is executed. Any other value
|
|
|
|
* returned by the hook will be returned by this method.
|
|
|
|
*
|
2014-01-10 06:52:53 +00:00
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
function callHook($hook) { /* {{{ */
|
2013-07-21 09:47:49 +00:00
|
|
|
$tmp = explode('_', get_class($this));
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])])) {
|
2016-11-22 08:21:12 +00:00
|
|
|
$r = null;
|
2013-07-21 09:47:49 +00:00
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, $hook)) {
|
2014-01-10 06:52:53 +00:00
|
|
|
switch(func_num_args()) {
|
2017-05-02 16:28:56 +00:00
|
|
|
case 3:
|
|
|
|
$result = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
|
|
|
|
break;
|
2014-01-10 06:52:53 +00:00
|
|
|
case 2:
|
|
|
|
$result = $hookObj->$hook($this, func_get_arg(1));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
$result = $hookObj->$hook($this);
|
|
|
|
}
|
|
|
|
if($result === false) {
|
|
|
|
return $result;
|
|
|
|
}
|
2016-11-22 08:21:12 +00:00
|
|
|
if($result !== null) {
|
|
|
|
$r = $result;
|
|
|
|
}
|
2014-01-10 06:52:53 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-22 08:21:12 +00:00
|
|
|
return $r;
|
2014-01-10 06:52:53 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
function hasHook($hook) { /* {{{ */
|
|
|
|
$tmp = explode('_', get_class($this));
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, $hook)) {
|
|
|
|
return true;
|
2013-07-21 09:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2014-01-10 06:52:53 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2013-07-21 09:47:49 +00:00
|
|
|
}
|