class_RightManagementBC.inc.php
12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
/**
* @file RightManagementBC.inc.php
* @category freeSN
* @mailto code [at] netz.coop
* @version 0.4.200901
* @link http://netz.coop
*
* @copyright Copyright by netz.coop e.G. 2015
*
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
//* alle dürfen lesen /schreiben : a all
//* angemeldete dürfen lesen / schreiben : u user
//* nur schreib/lese -berechtigte dürfen : r right
class RightManagementBC extends aLosp {
protected $PartOfObj = null;
protected $PartOfObj_BasisClipboards = null;
protected $PartOfObj_ClassName = null;
protected $DBRightManagementValues = array();
private $CONFIG_RightManagement =null;
/**
*
* @var array BasisClipbords Rechte, wird von RightManagementBC::getRightManagementValues generiert
* beinhaltet alle möglichen BasisClipboards mit ihren jeweiligen Rechten
*/
protected $RightManagementValues = null;
private function __construct(iStorable &$param_DB, &$param_Obj) {
$this->PartOfObj =& $param_Obj;
$this->ThisClassName = get_class($this);
$this->DB =& $param_DB;
$this->PartOfObj_BasisClipboards = $this->PartOfObj->getObjVar('BasisClipboards');
$this->PartOfObj_ClassName = $this->PartOfObj->ThisClassName;
//$this->CONFIG_RightManagement = CONFIG::getConfig('RightManagement');
$this->CONFIG_RightManagement = CONFIG::getConfigRightManagement($this->PartOfObj->ThisClassName);
}
public static function createNewInstance(iStorable &$param_DB, &$param_Obj) {
return new RightManagementBC($param_DB, $param_Obj);
}
public function loadObject(Account &$param_HostAccount, iStorable &$param_iStorable, $param_Parameter=null) {
if(parent::loadObject($param_HostAccount, $param_iStorable, $param_Parameter)) {
$this->loadRightManagementValues();
return $this;
} else {
return false;
}
}
public function getBasisClipboardWriteArray(Account &$param_HostAccount, iStorable &$param_iStorable) {
$this->mkBasisClipboardWriteArray($param_HostAccount, $param_iStorable);
return $this->BasisClipboardWriteArray;
}
public function checkIfPossibleAddToBC(Account &$param_HostAccount, iStorable &$param_iStorable, $param_BasisClipboardName) {
$this->mkBasisClipboardWriteArray($param_HostAccount, $param_iStorable);
if($param_BasisClipboardName && is_array( $this->BasisClipboardWriteArray) && FALSE !=array_search($param_BasisClipboardName, $this->BasisClipboardWriteArray)) {
return true;
} else {
return false;
}
}
private static $Cache_BasisClipboardWriteArray = array();
private $BasisClipboardWriteArray=null;
/**
* @todo sollte demnächst mal auf php6 SplFixedArray klasse umgestellt werden, macht leider einfach so fehler 100427 @f
*
* @param Account $param_HostAccount
* @param iStorable $param_iStorable
*/
private function mkBasisClipboardWriteArray(Account &$param_HostAccount, iStorable &$param_iStorable) {
$var_PartOfID = $this->PartOfObj->getObjVar('ID');
if(!array_key_exists($var_PartOfID, self::$Cache_BasisClipboardWriteArray)) {
$var_CONFIG_Data = & $this->PartOfObj->getObjVar('CONFIG_Data');
self::$Cache_BasisClipboardWriteArray[$var_PartOfID] = array();
/**
* on BasisClipboard is possible to add BasisElement's
*/
if(is_array($this->PartOfObj_BasisClipboards)) {
// self::$Cache_BasisClipboardWriteArray[$var_PartOfID] = new SplFixedArray(count($this->PartOfObj_BasisClipboards));
$var_HasBasisClipboards = $this->PartOfObj->getObjVar('HasBasisClipboards') ;
$i=0;
foreach($this->PartOfObj_BasisClipboards as $var_key => $var_value) {
if($var_key) {
if( is_array($var_CONFIG_Data) && array_key_exists('BasisClipboards', $var_CONFIG_Data)
&&
array_key_exists($var_key, $var_CONFIG_Data['BasisClipboards'])
&&
is_array($var_CONFIG_Data['BasisClipboards'][$var_key])
&&
array_key_exists('Singleton', $var_CONFIG_Data['BasisClipboards'][$var_key])
&&
$var_CONFIG_Data['BasisClipboards'][$var_key]['Singleton']
&&
array_search($var_key, $var_HasBasisClipboards)!==false) {
} else if($param_HostAccount) {
//D::li($var_PartOfID.'->'.$var_key);
foreach($param_HostAccount->getPossibleProfileIDArray() as $var_PossibleRequestPID => $var_PossiblePArray) {
if( $this->checkWriteBC($var_key, $var_PossibleRequestPID, true)) {
//D::ulli('ok');
self::$Cache_BasisClipboardWriteArray[$var_PartOfID][$i++] = $var_key;
break;
}
}
}
}
}
} else {
// self::$Cache_BasisClipboardWriteArray[$var_PartOfID] = new SplFixedArray(0);
}
}
$this->BasisClipboardWriteArray =& self::$Cache_BasisClipboardWriteArray[$var_PartOfID];
}
/**
*
* @param array $param_PartOfObj_BasisClipboards Rechtepriorität
* @param array $param_DBRightManagementValues Rechtepriorität
* @param array $param_CONFIG_RightManagementBC Rechtepriorität
* @return array
*/
private static function &getRightManagementValues($param_PartOfObj_BasisClipboards, $param_DBRightManagementValues, array $param_CONFIG_RightManagementBC) {
//D::show($param_PartOfObj_BasisClipboards, '$param_PartOfObj_BasisClipboards');
$var_CONFIG_BCReadRight = $param_CONFIG_RightManagementBC['Default_BCReadRight'];
$var_CONFIG_BCWriteRight = $param_CONFIG_RightManagementBC['Default_BCWriteRight'];
$var_result = array();
if(is_array($param_PartOfObj_BasisClipboards)) {
foreach($param_PartOfObj_BasisClipboards as $var_BasisClipboardName => $var_array) {
if(array_key_exists($var_BasisClipboardName, $param_DBRightManagementValues)) {
$var_Default_BCReadRight = $param_DBRightManagementValues[$var_BasisClipboardName]['ReadAuthorisation'];
$var_Default_BCWriteRight = $param_DBRightManagementValues[$var_BasisClipboardName]['WriteAuthorisaton'];
} else if(is_array($var_array)) {
if(array_key_exists('Default_BCReadRight', $var_array)) {
$var_Default_BCReadRight = $var_array['Default_BCReadRight'];
} else {
$var_Default_BCReadRight = $var_CONFIG_BCReadRight ;
}
if(array_key_exists('Default_BCWriteRight', $var_array)) {
$var_Default_BCWriteRight = $var_array['Default_BCWriteRight'];
} else {
$var_Default_BCWriteRight = $var_CONFIG_BCWriteRight ;
}
}else {
$var_Default_BCWriteRight = $var_CONFIG_BCWriteRight ;
$var_Default_BCReadRight = $var_CONFIG_BCReadRight ;
}
$var_result[$var_BasisClipboardName]['BCWriteRight'] = $var_Default_BCWriteRight;
$var_result[$var_BasisClipboardName]['BCReadRight'] = $var_Default_BCReadRight;
}
}
return $var_result;
}
private function loadRightManagementValues() {
if(empty ($this->RightManagementValues)) {
$this->RightManagementValues = & self::getRightManagementValues($this->PartOfObj_BasisClipboards, $this->DBRightManagementValues, $this->CONFIG_RightManagement['RightManagementBC']);
}
}
public function checkWriteBC($param_BasisClipboardname, $param_RequestProfileID, $param_OnlyForToAddToBC=false) {
// D::li( $this->PartOfObj.'->'.$param_BasisClipboardname.' # '.$param_RequestProfileID. ' ('.$this->RightManagementValues[$param_BasisClipboardname]['BCWriteRight'].')',1,1);
if(is_array($this->RightManagementValues) && array_key_exists($param_BasisClipboardname, $this->RightManagementValues)) {
// alle dürfen lesen /schreiben : a all
if('a'==$this->RightManagementValues[$param_BasisClipboardname]['BCWriteRight']) {
//D::ulli($this.' a'.$param_RequestProfileID,1,1) ;
// D::ulli('a');
return true;
// angemeldete dürfen lesen / schreiben : u user
} else if('u'==$this->RightManagementValues[$param_BasisClipboardname]['BCWriteRight']) {
//D::ulli($this.' u'.$param_RequestProfileID,1,1) ;
if($param_RequestProfileID) {
return true;
} else {
return false;
}
// nur schreib/lese -berechtigte dürfen : r right
} else if('r'==$this->RightManagementValues[$param_BasisClipboardname]['BCWriteRight']) {
//D::ulli($this.' r'.$param_RequestProfileID,1,1) ;
return $this->PartOfObj->getObjVar('RightManagement')->isPIDinReadRightProfiles($param_RequestProfileID);
// nue schreib -berechtigte dürfen: w right
} else if('w'==$this->RightManagementValues[$param_BasisClipboardname]['BCWriteRight']) {
//D::ulli($this.' w '.$param_RequestProfileID,1,1) ;
return $this->PartOfObj->getObjVar('RightManagement')->isPIDinWriteRightProfiles($param_RequestProfileID, $param_OnlyForToAddToBC);
}
} else {
// D::ulli(__CLASS__ .'->'. __FUNCTION__ .': ggggggggggggggg'.$this->PartOfObj.'->'.$param_BasisClipboardname);
return false;
}
}
public function checkReadBC($param_BasisClipboardname, $param_RequestProfileID) {
if(is_array($this->RightManagementValues) && array_key_exists($param_BasisClipboardname, $this->RightManagementValues)) {
// alle dürfen lesen /schreiben : a all
if('a'==$this->RightManagementValues[$param_BasisClipboardname]['BCReadRight']) {
return true;
// angemeldete dürfen lesen / schreiben : u user
} else if('u'==$this->RightManagementValues[$param_BasisClipboardname]['BCReadRight']) {
if($param_RequestProfileID) {
return true;
} else {
return false;
}
// nur lese -berechtigte dürfen : r right
} else if('r'==$this->RightManagementValues[$param_BasisClipboardname]['BCReadRight']) {
return $this->PartOfObj->getObjVar('RightManagement')->isPIDinReadRightProfiles($param_RequestProfileID);
// nue schreib -berechtigte dürfen: w right
} else if('w'==$this->RightManagementValues[$param_BasisClipboardname]['BCReadRight']) {
return $this->PartOfObj->getObjVar('RightManagement')->isPIDinWriteRightProfiles($param_RequestProfileID);
}
} else {
return false;
}
}
public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {
$this->loadRightManagementValues();
$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente);
if($param_KindOf==='form') {
foreach($this->RightManagementValues as $var_BasisClipboardname => $var_Rights) {
{
$DOM_BasisClipboard = $param_DOMDocument->createElement('BasisClipboard');
$DOMElement->appendChild($DOM_BasisClipboard);
$var_BELanguage = Language::getClassLinks($this->PartOfObj_ClassName,$var_BasisClipboardname);
$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($var_BasisClipboardname, 'category');
$DOM_BasisClipboard->setAttribute('BasisClipboard', $FncVar_BasisClipboardnameArray[0]);
if(array_key_exists(1, $FncVar_BasisClipboardnameArray)) {
$DOM_BasisClipboard->setAttribute('Category', $FncVar_BasisClipboardnameArray[1]);
}
$DOM_BasisClipboard->setAttribute('name', $var_BasisClipboardname);
DOMElementHelper::setDOMElementLanguageParameter($DOM_BasisClipboard, $var_BELanguage);
}
foreach(array('ReadKeys' => 'BCReadRight', 'WriteKeys' => 'BCWriteRight') as $KindOfRight => $Right) {
$var_BCLanguage = Language::getBCRightManagement($var_BasisClipboardname);
$DOM_BCKeys = $param_DOMDocument->createElement($KindOfRight);
$DOM_BasisClipboard->appendChild($DOM_BCKeys);
$rightArray = $this->CONFIG_RightManagement['RightManagementBC'];
if(array_key_exists($var_BasisClipboardname,$rightArray) && array_key_exists($KindOfRight,$rightArray[$var_BasisClipboardname])){
$rightArray=$rightArray[$var_BasisClipboardname];
}
foreach($rightArray[$KindOfRight] as $Key => $var) {
$DOM_BCKey = $param_DOMDocument->createElement('Key');
$DOM_BCKeys->appendChild($DOM_BCKey);
$DOM_BCKey->setAttribute('key', $Key);
DOMElementHelper::setDOMElementLanguageParameter($DOM_BCKey, $var_BCLanguage[$KindOfRight][$Key]);
if($this->RightManagementValues[$var_BasisClipboardname][$Right] == $Key) {
$DOM_BCKey->setAttribute('selected', 'selected');
}
}
}
}
}
return $DOMElement;
}
}
?>