class_RightManagement.inc.php
18.1 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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?php
/**
* @file RightManagement.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/>.
*
*/
/**
* manage the RightSystem of one BasisElement
* @see self::WriteRightProfiles
* @see self::ReadRightProfiles
* @see self::AuthorisationList
* @see self::RMProfileCollection
* @see self::RightManagementBC
*
*/
class RightManagement extends aLosp {
// wird derzeit nicht aufgerufen und ansich könnte auch direkt die RightManagementBC Funktion genutzt werden
public function checkWriteRightForBasisClipboard(Account &$param_HostAccount, $param_ObjVar) {
$PossibleProfileIDArray = $param_HostAccount->getPossibleProfileIDArray();
foreach($PossibleProfileIDArray as $key => $value){
if($this->RightManagementBC->checkWriteBC($param_ObjVar, $key)) {
return true;
}
}
return false;
}
public function checkReadRightForBasisClipboard(Account & $param_HostAccount, $param_ObjVar) {
$PossibleProfileIDArray = $param_HostAccount->getPossibleProfileIDArray();
foreach ($PossibleProfileIDArray as $key => $value) {
if ($this->RightManagementBC->checkReadBC($param_ObjVar, $key)) {
return true;
}
}
// D::li($this->PartOfObj."->$param_HostAccount, $param_ObjVar ",1,1);
return false;
}
public function getPCAuthReadListID() {
return $this->RMProfileCollection->getPCAuthReadListID();
}
public function getPCAuthWriteListID() {
return $this->RMProfileCollection->getPCAuthWriteListID();
}
public function getReadListID() {
return $this->AuthorisationList->getReadListID();
}
public function getWriteListID(){
return $this->AuthorisationList->getWriteListID();
}
/**
* the write right values are the result from PDORightManagement::checkBEAuth or self::loadWriteRightProfiles function
* the result depends from the Account and include the possible Profiles which Account can used
*
* @var array
*/
private $WriteRightProfiles = null;
/**
* the read right values are the result from PDORightManagement::checkBEAut function
* the result depends from the Account and include the possible Profiles which Account can used
*
* @var array
*/
private $ReadRightProfiles = null;
/**
* responsible for the RightManagement
* use losp_BEBasisClipboardsRightManagement table
*
* @var RightManagementBC
*/
protected $RightManagementBC = null;
/**
* responsible for the direct RightManagement
* use losp_BasisElement_writeauthorisation and losp_BasisElement_readauthorisation tables
*
* @var AuthorisationList
*/
private $AuthorisationList = FALSE;
/**
* responsible for the indirect RightManagement
* use losp_BasisElement_profilecollection_readauthorisation and losp_BasisElement_profilecollection_writeauthorisation
*
* @var RMProfileCollection
*/
private $RMProfileCollection = null;
/**
* link to the BasisElement
* (this is work for PartOfObj)
*
* @var BasisElement
*/
private $PartOfObj = null;
public function &getRMProfileCollection(){
return $this->RMProfileCollection;
}
public function &getAuthorisationList(){
return $this->AuthorisationList;
}
public function setAuthorisationList(AuthorisationList &$param_AuthorisationList) {
$this->AuthorisationList = &$param_AuthorisationList;
}
public function setWriteRightProfiles(array $param_WriteRightProfiles=null) {
//D::show($param_WriteRightProfiles, $this.' WriteRightProfiles',1,1) ;
$this->WriteRightProfiles = $param_WriteRightProfiles;
}
// public function getWriteRightProfiles(){
// return $this->WriteRightProfiles;
// }
public function isWriteAble(Account &$param_HostAccount) {
$PossibleProfileIDArray = $param_HostAccount->getPossibleProfileIDArray();
foreach($PossibleProfileIDArray as $key => $value){
if($this->isPIDinWriteRightProfiles($key)) {
return true;
}
}
return false;
}
public function isPIDinWriteRightProfiles($param_RequestProfileID, $param_OnlyForToAddToBC=false) {
//D::backtrace(1,1,1);
// if($param_RequestProfileID == 2300) {
// D::show($this->WriteRightProfiles['profilecollection'][$param_RequestProfileID]['ProfileStateID'], $this.' - '. $param_RequestProfileID,1,1) ;
// }
if(is_array($this->WriteRightProfiles)){
if(array_key_exists($param_RequestProfileID, $this->WriteRightProfiles) && $this->WriteRightProfiles[$param_RequestProfileID]['WriteRight']) {
return true;
// } else if(array_key_exists($param_RequestProfileID, $this->WriteRightProfiles) && $this->WriteRightProfiles[$param_RequestProfileID]['kindof'] == MemberProfileBC::STATE_AUTHOR_NAME && $param_RequestProfileID!=$this->PartOfObj->getObjVar('ID')) {
} else if(array_key_exists($param_RequestProfileID, $this->WriteRightProfiles) && $this->WriteRightProfiles[$param_RequestProfileID]['kindof'] == MemberProfileBC::STATE_AUTHOR_NAME ) {
if($param_OnlyForToAddToBC || $param_RequestProfileID!=$this->PartOfObj->getObjVar('ID')) {
return true;
} else {
return false;
}
} else if (array_key_exists('profilecollection', $this->WriteRightProfiles) && array_key_exists($param_RequestProfileID, $this->WriteRightProfiles['profilecollection']) && $this->WriteRightProfiles['profilecollection'][$param_RequestProfileID]['WriteRight']) {
return true;
} else if (array_key_exists('profilecollection', $this->WriteRightProfiles) && array_key_exists($param_RequestProfileID, $this->WriteRightProfiles['profilecollection']) && $this->WriteRightProfiles['profilecollection'][$param_RequestProfileID]['kindof'] == MemberProfileBC::STATE_AUTHOR_NAME && $param_RequestProfileID!=$this->PartOfObj->getObjVar('ID')) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public function isPIDinReadRightProfiles($param_RequestProfileID) {
//D::show($this->ReadRightProfiles,"isPIDinReadRightProfiles($param_RequestProfileID)",1,1) ;
if(is_array($this->ReadRightProfiles)
&& ( array_key_exists($param_RequestProfileID, $this->ReadRightProfiles)
||
(array_key_exists('profilecollection', $this->ReadRightProfiles) && array_key_exists($param_RequestProfileID, $this->ReadRightProfiles['profilecollection'])))
){
return true;
} else {
return false;
}
}
public function setReadRightProfiles(array $param_ReadRightProfiles=null) {
$this->ReadRightProfiles = $param_ReadRightProfiles;
}
private function __construct(iStorable &$param_DB, BasisElement &$param_Obj) {
$this->RightManagementBC = RightManagementBC::createNewInstance($param_DB, $param_Obj);
$this->ThisClassName = get_class($this);
$this->PartOfObj = &$param_Obj;
$this->RMProfileCollection = RMProfileCollection::createNewInstance($param_Obj->getID(), $this);
}
public function loadObject(Account &$param_HostAccount, iStorable &$param_iStorable, $param_Parameter=null) {
if($this->PartOfObj->getObjVar('PCAuthReadListID') || $this->PartOfObj->getObjVar('PCAuthWriteListID')) {
$this->RMProfileCollection->setPCAuthReadListID($this->PartOfObj->getObjVar('PCAuthReadListID'));
$this->RMProfileCollection->setPCAuthWriteListID($this->PartOfObj->getObjVar('PCAuthWriteListID'));
$this->RMProfileCollection->loadObject($param_HostAccount, $param_iStorable);
}
if($this->RightManagementBC->loadObject($param_HostAccount, $param_iStorable, $param_Parameter)) {
return $this;
} else {
return false;
}
}
public function saveObjectBeforeID(Account &$param_HostAccount, iStorable &$param_iStorable) {
if( $this->RMProfileCollection->getPCAuthReadList() && !$this->AuthorisationList->getAuthorisationReadList()) {
$this->AuthorisationList->addReadAuthorisation(new ReadAuthorisation($this->AuthorisationList->getReadListID(),$param_HostAccount->getAuthorProfileID(),$param_HostAccount->getActiveProfile()->getObjVar('NickName')));
}
//D::show($this->RMProfileCollection->getPCAuthReadList(), '$this->RMProfileCollection->getPCAuthReadList(1)');
$this->RMProfileCollection->saveObject($param_HostAccount, $param_iStorable);
//D::show($this->RMProfileCollection->getPCAuthReadList(), '$this->RMProfileCollection->getPCAuthReadList(2)');
$this->AuthorisationList->saveObject($param_HostAccount, $param_iStorable);
}
public function saveObject(Account &$param_HostAccount, iStorable &$param_iStorable) {
$this->RightManagementBC->saveObject($param_HostAccount, $param_iStorable);
}
/**
* function load WriteRightProfiles when its empty,
* it is necessary when $this->PartOfObj is new for the formular (and not aleady in database)
* otherwise it is loaded over PDORightManagement::checkBEAuth function
*
* @param Account $param_HostAccount
* @param iStorable $param_iStorable
*/
private function loadWriteRightProfiles(Account &$param_HostAccount, iStorable &$param_iStorable) {
if(!is_array($this->WriteRightProfiles)) {
$PossibleProfileIDArray = $param_HostAccount->getPossibleProfileIDArray($this->PartOfObj->getObjVar('PartOf')->getObjVar('ID'), $this->PartOfObj->getObjVar('PartOfObjVar'));
if($this->PartOfObj->getObjVar('CategoryName')) {
$var_BCName = $this->PartOfObj->getObjVar('PartOfObjVar').'::'.$this->PartOfObj->getObjVar('CategoryName');
} else {
$var_BCName = $this->PartOfObj->getObjVar('PartOfObjVar');
}
//D::li('ID '.$this->PartOfObj->getID(),1,1);
$var_PartOfBEArray = array();
/**
* schau nach ob PartOf ist Profile, ja: dann füll $var_PartOfBEArray auf mit anderen possible Profiles
*/
if(array_key_exists($this->PartOfObj->getObjVar('PartOf')->getObjVar('ID'), $PossibleProfileIDArray)) {
/**
* feststellen bei welchem Profile ich Elemente hinzufügen darf
*/
$updated_PossibleProfileIDArray = array();
foreach($PossibleProfileIDArray as $var_PID => $var_P_states) {
if($var_P_states['WriteRight'] || (array_key_exists('kindof', $var_P_states) && $var_P_states['kindof']==MemberProfileBC::STATE_AUTHOR_NAME)) {
$var_PartOfBEArray[] = MultimediaText::loadElement($param_HostAccount, $param_iStorable, '*', $var_PID);
$updated_PossibleProfileIDArray[$var_PID] = $var_P_states;
}
}
$PossibleProfileIDArray = &$updated_PossibleProfileIDArray;
} else {
$var_PartOfBEArray[] =$this->PartOfObj->getObjVar('PartOf');
}
//D::show($PossiblecProfileIDArray, '$PossibleProfileIDArray',1,1);
$this->WriteRightProfiles = array();
foreach($var_PartOfBEArray as $var_BCPartOfBE) {
foreach($PossibleProfileIDArray as $var_PID => $var_notused) {
// D::li($var_PID.' => '.$var_BCPartOfBE.'->'.$var_BCName,1,1);
if($var_BCPartOfBE->getObjVar('RightManagement')->RightManagementBC->checkWriteBC($var_BCName, $var_PID)) {
$this->WriteRightProfiles[$var_PID] = $var_notused;
D::ulli($var_PID.' => '.$var_BCPartOfBE.'->'.$var_BCName);
/**
* @new 100513 @f
*/
} else if (!$this->PartOfObj->getID() && $var_BCPartOfBE->getObjVar('RightManagement')->RightManagementBC->checkWriteBC($var_BCName, $var_PID, true)) {
$this->WriteRightProfiles[$var_PID] = $var_notused;
}
}
}
// if($this->PartOfObj->getObjVar('ID') == 1242) {
// D::show($this->WriteRightProfiles, $this.'->setWriteRightProfiles',1,1) ;
// }
}
}
public function getObjDOMElement(Account &$param_HostAccount, iStorable &$param_iStorable, DOMDocument $param_DOMDocument, $param_KindOf=null, array $param_DOMElemente=null) {
$DOMElement = parent::getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf, $param_DOMElemente);
if($param_KindOf === 'form') {
// foreach(array('WriteRightProfiles', 'ReadRightProfiles' ) as $var_key) {
// D::li('1#########################');
// D::show($this->WriteRightProfiles, '1 WriteRightProfiles',1,1);
$var_key = 'WriteRightProfiles';
$this->loadWriteRightProfiles($param_HostAccount, $param_iStorable);
// D::li($this.'->'. __FUNCTION__);
// D::show($this->WriteRightProfiles, '2 WriteRightProfiles',1,1);
// D::show($this->RMProfileCollection->getPCAuthWriteList(), ' RMProfileCollection->getPCAuthWriteist()');
// D::show($this->AuthorisationList->getWriteList(), ' AuthorisationList->getWriteList');
//
//
// D::show($this->ReadRightProfiles,' ReadRightProfiles');
// D::show($this->RMProfileCollection->getPCAuthReadList(),' RMProfileCollection->getPCAuthReadList()');
// D::li('2#########################');
if(is_array($this->$var_key)) {
$DOMElement_Child = $DOMElement->appendChild($param_DOMDocument->createElement($var_key));
$DOMElement_Child->setAttribute('label', Language::getWord($var_key));
foreach($this->$var_key as $var_PID => $var_ProfileValues) {
//D::show($var_ProfileValues, $var_PID,1,1);
if($var_PID!=='profilecollection') {
if($var_ProfileValues['WriteRight'] || (array_key_exists('kindof', $var_ProfileValues) && $var_ProfileValues['kindof'] == MemberProfileBC::STATE_AUTHOR_NAME)) {
$DOMElement_ShortProfile = $DOMElement_Child->appendChild($param_DOMDocument->createElement('ShortProfile'));
$DOMElement_ShortProfile->setAttribute('ID',$var_PID);
foreach($var_ProfileValues as $var_ProfileKindOf => $var_ProfileValue) {
if(is_array($var_ProfileValue)) {
D::ulli(__CLASS__.'=>'. __FUNCTION__.': '.$this.' ## '.$var_ProfileKindOf);
} else {
$DOMElement_ShortProfile->setAttribute($var_ProfileKindOf,$var_ProfileValue);
}
}
}
} else {
$DOMElement_ProfileCollection = $DOMElement_Child->appendChild($param_DOMDocument->createElement('ProfileCollection'));
//D::show($var_ProfileValues, $var_key.' - '.$var_PID,1,1);
foreach($var_ProfileValues as $var_PCID => $notused) {
//D::ulli($var_PCID,1,1);
$var_PCBE = MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $var_PCID);
$DOMElement_ProfileCollection->appendChild($var_PCBE->getShortObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument));
}
}
}
}
// }
}
if($this->AuthorisationList){
$DOMElement->appendChild($this->AuthorisationList->getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf));
} else {
$AuthorisationList = AuthorisationList::createNewInstance($param_iStorable, "", "");
if($param_HostAccount->getActiveProfileID()) {
$var_RequestProfileID = $param_HostAccount->getActiveProfileID();
if(CONFIG::getRightManagementValues("ReadPrivate")) {
$AuthorisationList->addReadAuthorisation(new ReadAuthorisation(0, $var_RequestProfileID, Profile::IDToNickName($param_iStorable, $var_RequestProfileID)));
}
if(CONFIG::getRightManagementValues("WritePrivate")) {
$AuthorisationList->addWriteAuthorisation(new WriteAuthorisation(0, $var_RequestProfileID, Profile::IDToNickName($param_iStorable, $var_RequestProfileID)));
}
}
$DOMElement->appendChild($AuthorisationList->getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf));
}
if($param_KindOf === 'form') {
$DOMElement->appendChild($this->RMProfileCollection->getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf));
$DOMElement->appendChild($this->RightManagementBC->getObjDOMElement($param_HostAccount, $param_iStorable, $param_DOMDocument, $param_KindOf));
}
return $DOMElement;
}
public static function createNewInstance(iStorable &$param_DB, &$param_Obj) {
return new RightManagement($param_DB, $param_Obj);
}
public function setData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_Data) {
/**
* śearchCodeAuthorisationList
*/
if(array_key_exists('AuthorisationList', $param_Data)) {
if(is_array($param_Data['AuthorisationList'])) {
$WriteProfileIDList = $ReadProfileIDList = array();
Form::manageRightFromForm($param_HostAccount, $param_iStorable, $param_Data, $ReadProfileIDList, $WriteProfileIDList, $this->PartOfObj->ThisClassName);
if(is_object($this->AuthorisationList)) {
$this->AuthorisationList->updateAuthList($ReadProfileIDList, $WriteProfileIDList);
} else {
$this->AuthorisationList = AuthorisationList::makeNew($param_HostAccount, $param_iStorable, $ReadProfileIDList, $WriteProfileIDList);
}
} else if(is_object($param_Data['AuthorisationList'])) {
$this->AuthorisationList =$param_Data['AuthorisationList'];
}
}
if(array_key_exists('RightManagementBC', $param_Data)) {
$this->RightManagementBC->setData($param_HostAccount, $param_iStorable, $param_Data['RightManagementBC']);
}
if(array_key_exists('RMProfileCollection', $param_Data)) {
if(array_key_exists('ReadSelected', $param_Data['RMProfileCollection']) && array_key_exists('ReadKind', $param_Data) && ($param_Data['ReadKind']== CONSTKindOf::BC_RIGHT_LOG || $param_Data['ReadKind']==CONSTKindOf::BC_RIGHT_ALL)){
unset($param_Data['RMProfileCollection']['ReadSelected']);
}
//D::li($param_Data['RMProfileCollection'],1,1) ;
if(is_object($param_Data['RMProfileCollection']) && get_class($param_Data['RMProfileCollection']) == 'RMProfileCollection') {
$this->RMProfileCollection = $param_Data['RMProfileCollection'];
$this->RMProfileCollection->setConstructValues($this->PartOfObj->getID(), $this);
//D::show($this->RMProfileCollection, $this.'->RMProfileCollection',1,1) ;
} else {
$this->RMProfileCollection->setData($param_HostAccount, $param_iStorable, $param_Data['RMProfileCollection']);
}
} else if($this->RMProfileCollection->getPCAuthReadListID() || $this->RMProfileCollection->getPCAuthWriteListID()) {
$this->RMProfileCollection->setData($param_HostAccount, $param_iStorable, array());
}
// D::show($param_Data,1,1,1);
}
public function __toString() {
return $this->ThisClassName.' from '.$this->PartOfObj;
}
}
?>