2016-02-24 13:37:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of a access control list.
|
|
|
|
*
|
|
|
|
* SeedDMS uses access control list for setting permission,
|
|
|
|
* on various operations.
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to represent an access request object
|
|
|
|
*
|
|
|
|
* This class provides a model for access request objects.
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2016-02-29 13:07:20 +00:00
|
|
|
class SeedDMS_Acl { /* {{{ */
|
2016-02-24 13:37:49 +00:00
|
|
|
/**
|
|
|
|
* @var object $dms reference to dms object.
|
2016-02-29 07:31:19 +00:00
|
|
|
* @access public
|
2016-02-24 13:37:49 +00:00
|
|
|
*/
|
2016-02-29 13:07:20 +00:00
|
|
|
public $_dms;
|
2016-02-24 13:37:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of an acl
|
|
|
|
*
|
|
|
|
* @param object $dms object of dms
|
|
|
|
* @return object instance of SeedDMS_Acl
|
|
|
|
*/
|
2016-02-29 13:07:20 +00:00
|
|
|
public function __construct($dms) { /* {{{ */
|
|
|
|
$this->_dms = $dms;
|
2016-02-24 13:37:49 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2016-04-13 06:47:33 +00:00
|
|
|
/**
|
|
|
|
* Check if Aro has access on Aco
|
|
|
|
*
|
|
|
|
* @param object $aro access request object
|
|
|
|
* @param object $aco access control object
|
|
|
|
* @return integer/boolean -1 if access is explictly denied, 1 if access
|
|
|
|
* is explictly allow, 0 if no access restrictions exists, false if
|
|
|
|
* an error occured.
|
|
|
|
*/
|
2016-02-24 13:37:49 +00:00
|
|
|
public function check($aro, $aco) { /* {{{ */
|
2016-02-29 13:07:20 +00:00
|
|
|
$db = $this->_dms->getDB();
|
2016-03-03 06:04:36 +00:00
|
|
|
|
|
|
|
while($aco) {
|
|
|
|
$acoid = $aco->getID();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblArosAcos` WHERE `aro`=".$aro->getID()." AND `aco`=".$acoid;
|
2016-03-03 06:04:36 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
|
|
|
if (is_bool($resArr) && $resArr === false)
|
|
|
|
return false;
|
|
|
|
if (count($resArr) == 1)
|
2016-04-13 06:47:33 +00:00
|
|
|
return((int) $resArr[0]['read']);
|
2016-03-03 06:04:36 +00:00
|
|
|
|
|
|
|
$aco = $aco->getParent();
|
|
|
|
}
|
|
|
|
|
2016-04-13 06:47:33 +00:00
|
|
|
return 0;
|
2016-02-29 13:07:20 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function toggle($aro, $aco) { /* {{{ */
|
|
|
|
$db = $this->_dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblArosAcos` WHERE `aro`=".$aro->getID()." AND `aco`=".$aco->getID();
|
2016-02-29 13:07:20 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-29 13:07:20 +00:00
|
|
|
return false;
|
|
|
|
if (count($resArr) != 1)
|
|
|
|
return false;
|
|
|
|
$resArr = $resArr[0];
|
|
|
|
|
|
|
|
$newperm = $resArr['read'] == 1 ? -1 : 1;
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "UPDATE `tblArosAcos` SET `read`=".$newperm." WHERE `aro`=".$aro->getID()." AND `aco`=".$aco->getID();
|
2016-02-29 13:07:20 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return false;
|
|
|
|
return true;
|
2016-02-24 13:37:49 +00:00
|
|
|
|
|
|
|
} /* }}} */
|
2016-02-29 13:07:20 +00:00
|
|
|
|
|
|
|
public function add($aro, $aco, $perm=-1) { /* {{{ */
|
|
|
|
$db = $this->_dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblArosAcos` WHERE `aro`=".$aro->getID()." AND `aco`=".$aco->getID();
|
2016-02-29 13:07:20 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-29 13:07:20 +00:00
|
|
|
return false;
|
|
|
|
if (count($resArr) == 1) {
|
|
|
|
$resArr = $resArr[0];
|
|
|
|
|
|
|
|
$newperm = $resArr['read'] == 1 ? -1 : 1;
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "UPDATE `tblArosAcos` SET `read`=".$newperm." WHERE `aro`=".$aro->getID()." AND `aco`=".$aco->getID();
|
2016-02-29 13:07:20 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return false;
|
|
|
|
} else {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "INSERT INTO `tblArosAcos` (`aro`, `aco`, `read`) VALUES (".$aro->getID().", ".$aco->getID().", ".$perm.")";
|
2016-02-29 13:07:20 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function remove($aro, $aco) { /* {{{ */
|
|
|
|
$db = $this->_dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "DELETE FROM `tblArosAcos` WHERE `aro`=".$aro->getID()." AND `aco`=".$aco->getID();
|
2016-02-29 13:07:20 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
} /* }}} */
|
|
|
|
} /* }}} */
|
2016-02-24 13:37:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to represent an access request/controll object
|
|
|
|
*
|
|
|
|
* This class provides a model for access request/controll objects.
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_AroAco { /* {{{ */
|
|
|
|
/**
|
|
|
|
* @var object $dms reference to dms object.
|
|
|
|
* @access protected
|
|
|
|
*/
|
2016-03-04 08:26:27 +00:00
|
|
|
public $_dms;
|
2016-02-24 13:37:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer id of access request object
|
|
|
|
*/
|
|
|
|
protected $_id;
|
|
|
|
|
2016-03-03 06:04:36 +00:00
|
|
|
/**
|
|
|
|
* @var integer id of parent of access request object
|
|
|
|
*/
|
|
|
|
protected $_parent;
|
|
|
|
|
2016-02-24 13:37:49 +00:00
|
|
|
/**
|
|
|
|
* @var string alias of access request object
|
|
|
|
*/
|
|
|
|
protected $_alias;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var object object of access request object
|
|
|
|
*/
|
|
|
|
protected $_object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of an aro
|
|
|
|
*
|
|
|
|
* @param object $dms object of dms
|
|
|
|
* @return object instance of SeedDMS_Aco
|
|
|
|
*/
|
2016-03-03 06:04:36 +00:00
|
|
|
function __construct($dms, $id, $parent, $object, $alias) { /* {{{ */
|
2023-08-28 10:09:33 +00:00
|
|
|
$this->_dms = $dms;
|
2016-02-24 13:37:49 +00:00
|
|
|
$this->_id = $id;
|
2016-03-03 06:04:36 +00:00
|
|
|
$this->_parent = $parent;
|
2016-02-24 13:37:49 +00:00
|
|
|
$this->_object = $object;
|
|
|
|
$this->_alias = $alias;
|
|
|
|
} /* }}} */
|
|
|
|
|
2016-02-29 07:31:19 +00:00
|
|
|
public function setDMS($dms) { /* {{{ */
|
2016-03-04 08:26:27 +00:00
|
|
|
$this->_dms = $dms;
|
2016-02-24 13:37:49 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2016-02-29 07:31:19 +00:00
|
|
|
public function getDMS() { /* {{{ */
|
2016-03-04 08:26:27 +00:00
|
|
|
return($this->_dms);
|
2016-02-29 07:31:19 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2016-02-24 13:37:49 +00:00
|
|
|
public function getID() { /* {{{ */
|
|
|
|
return $this->_id;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function getAlias() { /* {{{ */
|
|
|
|
return $this->_alias;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function getObject() { /* {{{ */
|
|
|
|
return $this->_object;
|
|
|
|
} /* }}} */
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to represent an access request object
|
|
|
|
*
|
|
|
|
* This class provides a model for access request objects.
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Aro extends SeedDMS_AroAco { /* {{{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of an aro
|
|
|
|
*
|
|
|
|
* @param object $dms object to access the underlying database
|
|
|
|
* @return object instance of SeedDMS_Aro
|
|
|
|
*/
|
|
|
|
public static function getInstance($id, $dms) { /* {{{ */
|
|
|
|
$db = $dms->getDB();
|
|
|
|
if(is_int($id)) {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAros` WHERE `id` = " . (int) $id;
|
2016-02-24 13:37:49 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-24 13:37:49 +00:00
|
|
|
return null;
|
|
|
|
if (count($resArr) != 1)
|
|
|
|
return null;
|
|
|
|
$resArr = $resArr[0];
|
|
|
|
} elseif(is_object($id)) {
|
|
|
|
if($dms->getClassname('role') == get_class($id)) {
|
|
|
|
$model = 'Role';
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAros` WHERE `model`=".$db->qstr($model)." AND `foreignid`=".$id->getID();
|
2016-02-24 13:37:49 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-24 13:37:49 +00:00
|
|
|
return null;
|
2016-03-03 06:04:36 +00:00
|
|
|
if (count($resArr) == 0) {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "INSERT INTO `tblAros` (`parent`, `model`, `foreignid`) VALUES (0, ".$db->qstr($model).", ".$id->getID().")";
|
2016-03-03 06:04:36 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return null;
|
|
|
|
$id = $db->getInsertID();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAros` WHERE `id` = " . $id;
|
2016-03-03 06:04:36 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
|
|
|
}
|
2016-02-25 09:16:40 +00:00
|
|
|
$resArr = $resArr[0];
|
2016-02-24 13:37:49 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 09:16:40 +00:00
|
|
|
if($resArr['model'] == 'Role') {
|
|
|
|
$classname = $dms->getClassname('role');
|
2016-02-24 13:37:49 +00:00
|
|
|
$object = $classname::getInstance($resArr['foreignid'], $dms);
|
|
|
|
} else {
|
|
|
|
$object = null;
|
|
|
|
}
|
|
|
|
|
2016-03-04 08:26:27 +00:00
|
|
|
$aro = new SeedDMS_Aro($dms, $resArr["id"], $resArr['parent'], $object, $resArr['alias']);
|
|
|
|
$aro->setDMS($dms);
|
2016-02-24 13:37:49 +00:00
|
|
|
return $aro;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class to represent an access control object
|
|
|
|
*
|
|
|
|
* This class provides a model for access control objects.
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright 2016 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Aco extends SeedDMS_AroAco{ /* {{{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of an aco
|
|
|
|
*
|
|
|
|
* @param object $dms object to access the underlying database
|
|
|
|
* @return object instance of SeedDMS_Aco
|
|
|
|
*/
|
|
|
|
public static function getInstance($id, $dms) { /* {{{ */
|
|
|
|
$db = $dms->getDB();
|
|
|
|
if(is_int($id)) {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `id` = " . (int) $id;
|
2016-02-24 13:37:49 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-24 13:37:49 +00:00
|
|
|
return null;
|
2016-03-03 06:04:36 +00:00
|
|
|
if (count($resArr) == 0) {
|
2016-02-24 13:37:49 +00:00
|
|
|
return null;
|
2016-03-03 06:04:36 +00:00
|
|
|
}
|
2016-02-24 13:37:49 +00:00
|
|
|
$resArr = $resArr[0];
|
|
|
|
} elseif(is_string($id)) {
|
|
|
|
$tmp = explode('/', $id);
|
|
|
|
$parentid = 0;
|
|
|
|
foreach($tmp as $part) {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `alias` = " . $db->qstr($part);
|
2016-03-03 06:04:36 +00:00
|
|
|
// if($parentid)
|
|
|
|
$queryStr .= " AND parent=".$parentid;
|
2016-02-24 13:37:49 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-24 13:37:49 +00:00
|
|
|
return null;
|
2016-03-03 06:04:36 +00:00
|
|
|
if (count($resArr) == 0) {
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "INSERT INTO `tblAcos` (`parent`, `alias`, `model`) VALUES (".$parentid.",".$db->qstr($part).", '')";
|
2016-03-03 06:04:36 +00:00
|
|
|
if (!$db->getResult($queryStr))
|
|
|
|
return null;
|
|
|
|
$id = $db->getInsertID();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `id` = " . $id;
|
2016-03-03 06:04:36 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
|
|
|
}
|
|
|
|
$parentid = (int) $resArr[0]['id'];
|
2016-02-24 13:37:49 +00:00
|
|
|
}
|
|
|
|
$resArr = $resArr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if($resArr['model'] == 'Document') {
|
|
|
|
$classname = $dms->getClassname('document');
|
|
|
|
$object = $classname::getInstance($resArr['foreignid'], $dms);
|
|
|
|
} elseif($resArr['model'] == 'Folder') {
|
|
|
|
$classname = $dms->getClassname('focument');
|
|
|
|
$object = $classname::getInstance($resArr['foreignid'], $dms);
|
|
|
|
} else {
|
|
|
|
$object = null;
|
|
|
|
}
|
|
|
|
|
2016-03-03 06:04:36 +00:00
|
|
|
$aco = new SeedDMS_Aco($dms, $resArr["id"], $resArr['parent'], $object, $resArr['alias']);
|
2016-02-29 07:31:19 +00:00
|
|
|
$aco->setDMS($dms);
|
2016-02-24 13:37:49 +00:00
|
|
|
return $aco;
|
|
|
|
} /* }}} */
|
2016-02-29 07:31:19 +00:00
|
|
|
|
|
|
|
public function getChildren() { /* {{{ */
|
|
|
|
$dms = $this->getDMS();
|
|
|
|
$db = $dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `parent` = ".$this->_id." ORDER BY `alias`";
|
2016-02-29 07:31:19 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-29 07:31:19 +00:00
|
|
|
return null;
|
2016-03-03 06:04:36 +00:00
|
|
|
if (count($resArr) == 0)
|
2016-02-29 07:31:19 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
$acos = array();
|
|
|
|
foreach($resArr as $row) {
|
2016-03-03 06:04:36 +00:00
|
|
|
$aco = new SeedDMS_Aco($dms, $row["id"], $row['parent'], null, $row['alias']);
|
2016-02-29 07:31:19 +00:00
|
|
|
$aco->setDMS($dms);
|
|
|
|
$acos[] = $aco;
|
|
|
|
}
|
|
|
|
return $acos;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public function getPermission($aro) { /* {{{ */
|
2016-03-03 06:04:36 +00:00
|
|
|
if(!$aro)
|
|
|
|
return 0;
|
2016-02-29 07:31:19 +00:00
|
|
|
$dms = $this->getDMS();
|
|
|
|
$db = $dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblArosAcos` WHERE `aro`=".$aro->getID()." AND `aco`=".$this->_id;
|
2016-02-29 07:31:19 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-29 07:31:19 +00:00
|
|
|
return false;
|
|
|
|
if (count($resArr) != 1)
|
|
|
|
return 0;
|
2017-07-27 10:36:20 +00:00
|
|
|
return (int) $resArr[0]['read'];
|
2016-02-29 07:31:19 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
public static function getRoot($dms) { /* {{{ */
|
|
|
|
$db = $dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `parent` = 0 ORDER BY `alias`";
|
2016-02-29 07:31:19 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
2016-03-03 06:04:36 +00:00
|
|
|
if (is_bool($resArr) && $resArr === false)
|
2016-02-29 07:31:19 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
$acos = array();
|
|
|
|
foreach($resArr as $row) {
|
2016-03-03 06:04:36 +00:00
|
|
|
$aco = new SeedDMS_Aco($dms, $row["id"], $row['parent'], null, $row['alias']);
|
2016-02-29 07:31:19 +00:00
|
|
|
$aco->setDMS($dms);
|
|
|
|
$acos[] = $aco;
|
|
|
|
}
|
|
|
|
return $acos;
|
|
|
|
} /* }}} */
|
2016-03-03 06:04:36 +00:00
|
|
|
|
|
|
|
public function getParent() { /* {{{ */
|
|
|
|
$dms = $this->getDMS();
|
|
|
|
$db = $dms->getDB();
|
2017-02-13 15:51:57 +00:00
|
|
|
$queryStr = "SELECT * FROM `tblAcos` WHERE `id` = ".$this->_parent;
|
2016-03-03 06:04:36 +00:00
|
|
|
$resArr = $db->getResultArray($queryStr);
|
|
|
|
if (is_bool($resArr) && $resArr === false)
|
|
|
|
return null;
|
|
|
|
if (count($resArr) != 1)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
$row = $resArr[0];
|
|
|
|
$aco = new SeedDMS_Aco($dms, $row["id"], $row['parent'], null, $row['alias']);
|
|
|
|
$aco->setDMS($dms);
|
|
|
|
return $aco;
|
|
|
|
} /* }}} */
|
2016-02-24 13:37:49 +00:00
|
|
|
} /* }}} */
|