<?php
/*
* Column Optionen
*/
define("COLUMN_OPTION_ONLINE", 1 << 0);
define("COLUMN_OPTION_LOCAL_PERMS", 1 << 1);
define("COLUMN_PERM_EDIT_COLUMN", 1 << 0);
define("COLUMN_PERM_EDIT_OWN_ARTICLES", 1 << 1);
define("COLUMN_PERM_EDIT_ALL_ARTICLES", 1 << 2);
define("COLUMN_PERM_PUBLISH_ARTICLES", 1 << 3);
define("COLUMN_PERM_MEDIA_UPLOAD", 1 << 4);
class CB_permission_article extends CB_permission {
var $cbPerms = 0;
var $allUserPerms = 0;
/**
* CB_permission_column::CB_permission_column()
*
* @param boolean $optionArr
* @return
**/
function CB_permission_article($optionArr = false) {
parent::CB_permission($optionArr);
$this->setType("columnPerms");
$this->getPermissionList();
$this->cbPerms = $optionArr['cbPerms'];
$this->allUserPerms = $this->getAllPermissionSet(true);
$this->allUserPerms = $this->checkAdmin($this->allUserPerms, $this->cbPerms);
}
/**
* CB_permission_column::hasEditPermission()
*
* @param boolean $id
* @param boolean $optionArr
* @return
**/
function hasEditPermission($id = false, $optionArr = false) {
if($optionArr[type] == "column") {
$result = $this->hasColumnEditPermission($id);
} else {
$result = $this->hasArticleEditPermission($id);
}
return $result;
}
/**
* CB_permission_article::hasEditArticlePermission()
*
* @param boolean $id
* @return
**/
function hasArticleEditPermission($id = false) {
$result = 0;
if($id) {
$article = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLE."_art_general WHERE ide = '$id'"));
if($article['userID'] == $this->userID) {
$result = 1;
}
if(!$result) {
$result = $this->hasColumnEditAllPermission($article['folderID']);
}
}
return $result;
}
/**
* CB_permission_article::hasColumnEditPermission()
*
* @param boolean $id
* @return
**/
function hasColumnEditPermission($id = false) {
$generalSet = $this->getSpecificPermissionSet('general');
if($id == false) {
if( (COLUMN_PERM_EDIT_OWN_ARTICLES & $generalSet) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $generalSet)) {
$result = 1;
} else {
$result = 0;
}
} else {
$editAllowed = 0;
$node = $this->nestedSet->getNode($id, true);
if($node != false) {
$nodePermissionSet = $this->checkAdmin($this->getMultiplePermissionSet($id, true), $this->cbPerms);
if(COLUMN_OPTION_LOCAL_PERMS & $node[options]) {
if( (COLUMN_PERM_EDIT_OWN_ARTICLES & $nodePermissionSet) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $nodePermissionSet)) {
$editAllowed = 1;
}
} else {
if( (COLUMN_PERM_EDIT_OWN_ARTICLES & $generalSet) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $generalSet) ||
(COLUMN_PERM_EDIT_OWN_ARTICLES & $nodePermissionSet) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $nodePermissionSet)) {
$editAllowed = 1;
}
}
}
$result = $editAllowed;
}
return $result;
}
/**
* CB_permission_article::hasColumnEditAllPermission()
*
* @param boolean $id
* @return
**/
function hasColumnEditAllPermission($id = false) {
$generalSet = $this->getSpecificPermissionSet('general');
if($id == false) {
if(COLUMN_PERM_EDIT_ALL_ARTICLES & $generalSet) {
$result = 1;
} else {
$result = 0;
}
} else {
$editAllowed = 0;
$node = $this->nestedSet->getNode($id, true);
if($node != false) {
$nodePermissionSet = $this->checkAdmin($this->getMultiplePermissionSet($id, true), $this->cbPerms);
if(COLUMN_OPTION_LOCAL_PERMS & $node[options]) {
if( (COLUMN_PERM_EDIT_ALL_ARTICLES & $nodePermissionSet)) {
$editAllowed = 1;
}
} else {
if( (COLUMN_PERM_EDIT_ALL_ARTICLES & $generalSet) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $nodePermissionSet)) {
$editAllowed = 1;
}
}
}
$result = $editAllowed;
}
return $result;
}
/**
* CB_permission_article::hasUploadPermission()
*
* @param boolean $id
* @param boolean $optionArr
* @return
**/
function hasUploadPermission($id = false, $optionArr = false) {
if($optionArr[type] == "column") {
$result = $this->hasColumnUploadPermission($id);
} else {
$result = $this->hasArticleUploadPermission($id);
}
return $result;
}
/**
* CB_permission_article::hasArticleUploadPermission()
*
* @param boolean $id
* @return
**/
function hasArticleUploadPermission($id = false) {
$result = 0;
if($id) {
$article = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLE."_art_general WHERE ide = '$id'"));
$result = $this->hasColumnUploadPermission($article['folderID']);
}
return $result;
}
/**
* CB_permission_article::hasColumnUploadPermission()
*
* @param boolean $id
* @return
**/
function hasColumnUploadPermission($id = false) {
$generalSet = $this->getSpecificPermissionSet('general');
if($id == false) {
if(COLUMN_PERM_MEDIA_UPLOAD & $generalSet) {
$result = 1;
} else {
$result = 0;
}
} else {
$editAllowed = 0;
$node = $this->nestedSet->getNode($id, true);
if($node != false) {
$nodePermissionSet = $this->checkAdmin($this->getMultiplePermissionSet($id, true), $this->cbPerms);
if(COLUMN_OPTION_LOCAL_PERMS & $node[options]) {
if(COLUMN_PERM_MEDIA_UPLOAD & $nodePermissionSet) {
$editAllowed = 1;
}
} else {
if( (COLUMN_PERM_MEDIA_UPLOAD & $generalSet) ||
(COLUMN_PERM_MEDIA_UPLOAD & $nodePermissionSet)) {
$editAllowed = 1;
}
}
}
$result = $editAllowed;
}
return $result;
}
function hasPublishPermission($id = false, $optionArr = false) {
if($optionArr[type] != "column") {
$result = 0;
$article = mysql_fetch_assoc(mysql_query("SELECT * FROM ".TABLE."_art_general WHERE ide = '$id'"));
$fid = $article['folderID'];
} else {
$fid = $id;
}
$generalSet = $this->getSpecificPermissionSet('general');
if($fid == false) {
$result = 0;
if(COLUMN_PERM_PUBLISH_ARTICLES & $generalSet) {
$result = 1;
}
} else {
$editAllowed = 0;
$node = $this->nestedSet->getNode($fid, true);
if($node != false) {
$nodePermissionSet = $this->checkAdmin($this->getMultiplePermissionSet($fid, true), $this->cbPerms);
if(COLUMN_OPTION_LOCAL_PERMS & $node[options]) {
if( COLUMN_PERM_PUBLISH_ARTICLES & $nodePermissionSet) {
$editAllowed = 1;
}
} else {
if( (COLUMN_PERM_PUBLISH_ARTICLES & $generalSet) ||
(COLUMN_PERM_PUBLISH_ARTICLES & $nodePermissionSet)) {
$editAllowed = 1;
}
}
}
$result = $editAllowed;
}
return $result;
}
/**
* CB_permission_column::setNestedSetObject()
*
* @param $nestedSet
* @return
**/
function setNestedSetObject(&$nestedSet) {
$this->nestedSet = $nestedSet;
}
/**
* CB_permission_column::getSpecificPermissionSet()
*
* @param $id
* @return
**/
function getSpecificPermissionSet($id) {
$rights = $this->getMultiplePermissionSet($id, true);
$rights = $this->checkAdmin($rights, $this->cbPerms);
return $rights;
}
/**
* CB_permission_column::hasAccess()
*
* @return
**/
function hasAccess() {
$result = false;
if( (COLUMN_PERM_EDIT_OWN_ARTICLES & $this->allUserPerms) ||
(COLUMN_PERM_EDIT_ALL_ARTICLES & $this->allUserPerms)) {
$result = 1;
} else {
$result = 0;
}
return $result;
}
/**
* CB_permission_column::checkAdmin()
*
* @param $rights
* @param $_perms
* @return
**/
function checkAdmin($rights, $perms) {
if((ADMIN & $perms) || (COL_MNG & $perms)) {
/*
* ersten 16 Bits auf 1 setzen, Admin darf immer alles
*/
$rights = 65535;
}
return $rights;
}
}
?>