class_PostController.inc.php
18.9 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
442
443
444
445
446
447
448
449
450
451
<?php
/**
* @file PostController.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/>.
*
*/
class PostController {
/**
* @filesource class_PostController.inc.php
*
* @category freeSN
* @copyright Copyright by mensch.coop e.G. 2009
* @mailto dev [at] mensch.coop
* @version 0.4.200901
* @link http://mensch.coop
*/
/**
* Diese Klasse handelt den $_POST -Array
*
* @static Diese Klasse besitzt nur statische Funktionen
*/
private static $LinkClassArray = array();
/**
* @var array for the function post_setPreValues
*/
private static $PreValueArray;
/**
* Funktion erstellt ein neues BasisElement
*
* @param Account param_HostAccount
*
* @param array param_BEData hält die Daten des BEs
* @param array param_AddData hält BCs und IDs
* @param datatype param_Tree
* @param array param_FunctionData hält Post-Funktionen
*
* @return int die ID des erstellten BasisElements
*/
public static function makeNew(Account &$param_HostAccount, iStorable &$param_iStorable, $param_BEData, $param_AddData,array $param_Tree, $param_FunctionData){
//D::li("makeNew(Account &$param_HostAccount, iStorable &$param_iStorable, $param_BEData, $param_AddData,array $param_Tree, $param_FunctionData)");
$the_BasisClipboardname = null;
$the_BasisElementName = key($param_BEData);
$the_PartOfID = $param_BEData[$the_BasisElementName]['PartOfID'];
if(array_key_exists('AuthorProfileID',$param_BEData[$the_BasisElementName]) && $param_BEData[$the_BasisElementName]['AuthorProfileID']){
$param_HostAccount->setAuthorProfileID($param_BEData[$the_BasisElementName]['AuthorProfileID']);
}
// searchCodeAuthorisationList
// if($param_HostAccount->getAuthorProfileID() != $param_HostAccount->getActiveProfileID()){
// $AuthorProfile = MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $param_HostAccount->getAuthorProfileID());
// }
// else{
// $AuthorProfile = $param_HostAccount->getActiveProfile();
// }
//D::show($param_AddData,'addData');
foreach($param_AddData as $dataKey => $dataValue){
foreach($dataValue as $key => $value){
$BasisClipboardname[] = $key;
if($value){
if($value=='AuthorProfileID'){
//$value = $param_HostAccount->getAuthorProfileID();
$param_AddData[$dataKey][$key] =$param_HostAccount->getAuthorProfileID();
$the_BasisClipboardname = $key;
/*if($param_HostAccount->getAuthorProfileID() == $the_PartOfID){
$the_BasisClipboardname = $key;
}*/
//D::show($param_HostAccount->getAuthorProfileID(),'AuthorProfileID');
}
//$PartOfID[] = $value;
if($value == $the_PartOfID){
$the_BasisClipboardname = $key;
}
}
}
}
// D::show($param_AddData,'SecaddData');
// D::show($param_HostAccount->getAuthorProfileID(),$the_PartOfID);
$tmp_BasisElement =& MultimediaText::loadElement($param_HostAccount, $param_iStorable,null, $the_PartOfID);
$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($the_BasisClipboardname, 'category');
/**@todo warum muss denn hier das Clipboard geldaen werden? @um 100425*/
if(is_subclass_of($FncVar_BasisClipboardnameArray[0], 'BasisClipboard') ) {
$Clipboard =& $tmp_BasisElement->getClipboard($param_HostAccount, $param_iStorable, $the_BasisClipboardname);
BasisClipboard::loadObjectLevel($param_HostAccount, $param_iStorable, $Clipboard, 'makeNew' );
}
if(Form::checkDataCompleteness($param_BEData[$the_BasisElementName], $the_BasisElementName)) {
Form::replaceData($param_BEData[$the_BasisElementName]);
$BasisElement = Form::makeNewObjectFromFormData($param_HostAccount, $param_iStorable, $param_BEData[$the_BasisElementName], $tmp_BasisElement, $the_BasisClipboardname, $the_BasisElementName, null, null, $param_Tree, $param_AddData);
}
if(is_object($BasisElement) && $BasisElement->getID()){
if(is_array($param_FunctionData)) {
foreach($param_FunctionData as $kind => $value){
PostController::post_fnc($param_HostAccount, $param_iStorable,$kind, $value, $BasisElement->getID(),$BasisElement);
}
}
Message::newMessage('makeNew', $Clipboard->ThisClassName,$BasisElement->ThisClassName);
$param_HostAccount->resetAuthorProfileID();
return $BasisElement->getID();
} else{
$param_HostAccount->resetAuthorProfileID();
return Error::newError("Error",$param_BEData[$the_BasisElementName]['Subject'],"");
}
}
/**
* Funktion verändert ein besthendes BasisElement
*
* @param Account param_HostAccount
*
* @param array param_BEData hält die Daten des BEs
* @param array param_AddData hält BCs und IDs
* @param datatype param_Tree
* @param array param_FunctionData hält Post-Funktionen
*
* @return int die ID des erstellten BasisElements
*/
public static function edit(Account &$param_HostAccount, iStorable &$param_iStorable, $param_BEData, $param_AddData, $param_Tree, $param_FunctionData){
$Clipboard = $the_PartOfID = null;
$the_BasisElementName = key($param_BEData);
$BasisClipboardname = $PartOfID = array();
if(array_key_exists('AuthorProfileID',$param_BEData[$the_BasisElementName]) && $param_BEData[$the_BasisElementName]['AuthorProfileID']){
$param_HostAccount->setAuthorProfileID($param_BEData[$the_BasisElementName]['AuthorProfileID']);
}
// searchCodeAuthorisationList
// if($param_HostAccount->getAuthorProfileID() != $param_HostAccount->getActiveProfileID()){
// $AuthorProfile = MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $param_HostAccount->getAuthorProfileID());
// }
// else{
// $AuthorProfile = $param_HostAccount->getActiveProfile();
// }
// if(!$the_PartOfID){
// $the_PartOfID=$AuthorProfile->getID();
// }
//$AuthorProfile = $param_HostAccount->getActiveProfile();
foreach($param_AddData as $dataKey => $dataValue){
foreach($dataValue as $key => $value){
$BasisClipboardname[] = $key;
if($value){
if($value=='AuthorProfileID'){
//$value = $param_HostAccount->getAuthorProfileID();
$param_AddData[$dataKey][$key] =$param_HostAccount->getAuthorProfileID();
/*if($param_HostAccount->getAuthorProfileID() == $the_PartOfID){
$the_BasisClipboardname = $key;
}*/
//D::show($param_HostAccount->getAuthorProfileID(),'AuthorProfileID');
}
//$PartOfID[] = $value;
}
}
}/*
foreach($param_AddData as $dataValue){
foreach($dataValue as $key => $value){
$BasisClipboardname[] = $key;
if($value){
$PartOfID[] = $value;
}
else{
$PartOfID[] = $param_HostAccount->getActiveProfileID();
}
}
}*/
if(array_key_exists('PartOfID', $param_BEData[$the_BasisElementName]) && $param_BEData[$the_BasisElementName]['PartOfID']) {
$the_PartOfID = $param_BEData[$the_BasisElementName]['PartOfID'];
} else if($param_HostAccount->getAuthorProfileID() != $param_HostAccount->getActiveProfileID()){
$AuthorProfile = MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $param_HostAccount->getAuthorProfileID());
$the_PartOfID=$AuthorProfile->getID();
} else{
$the_PartOfID= $param_HostAccount->getActiveProfile()->getID();
}
$tmp_BasisElement =& MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $the_PartOfID);
/** solange das KAtegorie Problem besteht muss dies bestehen bleiben um das BE zu erzeugen*/
{
for($i=count($BasisClipboardname)-1;$i>=0;$i--){
$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($BasisClipboardname[$i], 'category');
if(class_exists($FncVar_BasisClipboardnameArray[0]) && is_subclass_of($FncVar_BasisClipboardnameArray[0], 'BasisClipboard') ) {
if(array_key_exists($BasisClipboardname[$i],Config::getMT_BasisClipboards($tmp_BasisElement->ThisClassName))){
$Clipboard =& $tmp_BasisElement->getClipboard($param_HostAccount, $param_iStorable, $BasisClipboardname[$i]);
BasisClipboard::loadObjectLevel($param_HostAccount, $param_iStorable, $Clipboard, 'Edit' );
break;
}
else if(array_key_exists($FncVar_BasisClipboardnameArray[0],Config::getMT_BasisClipboards($tmp_BasisElement->ThisClassName))){
$Clipboard =& $tmp_BasisElement->getClipboard($param_HostAccount, $param_iStorable, $FncVar_BasisClipboardnameArray[0]);
break;
}
}
}
if((boolean)($Clipboard)) {
BasisClipboard::loadObjectLevel($param_HostAccount, $param_iStorable, $Clipboard, 'Edit' );
} else if ($tmp_BasisElement->ThisClassName == 'Profile') {
} else {
return Error::newError('NoLoadBE','Fehler BasisClipboard '.$BasisClipboardname[0].' konnte nicht geladen werden',"");
}
}
if(array_key_exists('Delete', $param_BEData[$the_BasisElementName]) && $param_BEData[$the_BasisElementName]['Delete'] && $param_BEData[$the_BasisElementName]['MTextID']) {
//D::show($param_BEData[$the_BasisElementName],'delete object',1,1);
if(is_object($Clipboard) && $BasisClipboardname[0] != 'none'){
$BasisElement =& $Clipboard->get($param_HostAccount, $param_iStorable, $param_BEData[$the_BasisElementName]['MTextID']);
}
else if($tmp_BasisElement->ThisClassName != 'Profile'){
$BasisElement =$tmp_BasisElement;
}
if($BasisElement) {
if(BasisElement::deleteObject($param_HostAccount, $param_iStorable, $BasisElement)){
Message::newMessage('post_del', $BasisElement->ThisClassName,$param_BEData[$the_BasisElementName]['Subject']);
}
}
else {
$param_HostAccount->resetAuthorProfileID();
return Error::newError('NoLoadBE','Fehler BasisElement '.$_POST['MTextID'].' konnte nicht geladen werden',"");
}
}
else if(Form::checkDataCompleteness($param_BEData[$the_BasisElementName], $the_BasisElementName)) {
Form::replaceData($param_BEData[$the_BasisElementName]);
D::show($the_PartOfID,'$the_PartOfID');
if(is_object($Clipboard) && ( $BasisClipboardname[0] != 'none' && $param_BEData[$the_BasisElementName]['MTextID']!=$the_PartOfID )){
$BasisElement =& $Clipboard->get($param_HostAccount, $param_iStorable, $param_BEData[$the_BasisElementName]['MTextID']);
} else{
$BasisElement =$tmp_BasisElement;
}
if(is_object($BasisElement)) {
BasisElement::loadObjectLevel($param_HostAccount, $param_iStorable, $BasisElement, 'Edit' );
// śearchCodeAuthorisationList 100613
//D::show($param_BEData[$the_BasisElementName]['RightManagement']['AuthorisationList'],$the_BasisElementName );
// $WriteProfileIDList = $ReadProfileIDList = array();
// Form::manageRightFromForm($param_HostAccount, $param_iStorable, $param_BEData[$the_BasisElementName]['RightManagement'], $ReadProfileIDList, $WriteProfileIDList, $BasisElement->ThisClassName);//, $ReadPropfileCollection);
//D::show($ReadProfileIDList, 'ReadProfileIDList');
//D::show($WriteProfileIDList, 'WriteProfileIDList');
////D::li($param_BEData[$the_BasisElementName]['ReadKind'].' = '. CONSTKindOf::BC_RIGHT_ALL.' -- '.$the_BasisElementName,1,1);
// /**
// * @todo muss anscih wo anders hin ... im Zuge der AuthorisationList => RightMAnagement Aktion sollte das passieren 100428 @f
// */
// if(array_key_exists('ReadKind', $param_BEData[$the_BasisElementName]) && ($param_BEData[$the_BasisElementName]['ReadKind']== CONSTKindOf::BC_RIGHT_LOG || $param_BEData[$the_BasisElementName]['ReadKind']==CONSTKindOf::BC_RIGHT_ALL)){
// unset($param_BEData[$the_BasisElementName]['RightManagement']['RMProfileCollection']['ReadSelected']);
// }
//
//
// /*if(!$ReadPropfileCollection && array_key_exists('RightManagement',$param_BEData[$the_BasisElementName]) && array_key_exists('RMProfileCollection',$param_BEData[$the_BasisElementName]['RightManagement']) && array_key_exists('ReadSelected',$param_BEData[$the_BasisElementName]['RightManagement']['RMProfileCollection'])){
// unset($param_BEData[$the_BasisElementName]['RightManagement']['RMProfileCollection']['ReadSelected']);
// }*/
// /**
// * setAuth edit
// */
// $BasisElement->getObjVar('RightManagement')->getAuthorisationList()->updateAuthList($ReadProfileIDList, $WriteProfileIDList);
$BasisElement->setData($param_HostAccount, $param_iStorable, $param_BEData[$the_BasisElementName]);
if($BasisClipboardname[0] != 'none'){
Form::updateAddToLinkList ($param_HostAccount, $param_iStorable, $param_Tree, $tmp_BasisElement, $BasisClipboardname[0], $BasisElement, $param_AddData);
}
$BasisElement->saveObject($param_HostAccount, $param_iStorable);
if(is_object($Clipboard)) {
Message::newMessage('edit', $Clipboard->ThisClassName,$param_BEData[$the_BasisElementName]['Subject']);
}
if(is_array($param_FunctionData)) {
foreach($param_FunctionData as $kind => $value){
PostController::post_fnc($param_HostAccount, $param_iStorable,$kind, $value, $BasisElement->getID(),$BasisElement);
}
}
$param_HostAccount->resetAuthorProfileID();
} else {
$param_HostAccount->resetAuthorProfileID();
return Error::newError('NoLoadBE','Fehler BasisElement '.$_POST['MTextID'].' konnte nicht geladen werden',"");
}
}
$param_HostAccount->resetAuthorProfileID();
}
/**
*
* function calls static or object based post_functions
*
*/
public static function post_fnc(Account &$param_HostAccount, iStorable &$param_iStorable, $param_kind, $param_value, $param_makeNewID, $param_ObjectBE = false){
if($param_kind == 'Object'){
if(array_key_exists('post_action', $param_value) && $param_value['post_action']){
foreach($param_value['post_action'] as $key => $index){
if(array_key_exists('post_fnc', $param_value) && $param_value['post_fnc'] && array_key_exists($index, $param_value['post_fnc'])){
$the_function = $param_value['post_fnc'][$index];
//$the_function = $param_value['post_fnc'][$index];
if(array_key_exists('PartOfID', $param_value) && array_key_exists($index, $param_value['PartOfID']) && $param_value['PartOfID'][$index]){
if($param_value['PartOfID'][$index] == 'makeNew'){
$param_value['PartOfID'][$index] = $param_makeNewID;
$array_PartOfID = array($param_makeNewID);
}
else if($param_value['PartOfID'][$index] == 'allProfileIDs'){
$array_PartOfID = array();
foreach($param_value['Param'][$the_function][$index] as $keyID => $value){
$array_PartOfID[]=$keyID;
}
}
else{
$array_PartOfID = array($param_value['PartOfID'][$index]);
}
foreach($array_PartOfID as $var_PartOfID){
if($param_value['PartOfID'][$index] == 'allProfileIDs'){
$param_HostAccount->setAuthorProfileID($var_PartOfID);
}
if($the_Object = $param_ObjectBE){}
else{
$the_Object =& MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $var_PartOfID);
}
/**
* @todo ... wird hier die Variable $the_Object unterschiedlich überschrieben ... weil das ist ja schon ein wenig irrefürhrend (einmal BE, einmal BC) 100320 @f
*/
if(is_object($the_Object) && array_key_exists('BasisClipboardName', $param_value) && array_key_exists($index, $param_value['BasisClipboardName']) && $param_value['BasisClipboardName'][$index]){
$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($param_value['BasisClipboardName'][$index], 'category');
if(is_subclass_of($FncVar_BasisClipboardnameArray[0], 'BasisClipboard') ) {
$the_Object =& $the_Object->getClipboard($param_HostAccount, $param_iStorable, $param_value['BasisClipboardName'][$index]);
}
}
if(is_object($the_Object)){
/**
* @todo array_key 0 raus@um
*/
if(!(array_key_exists('Param',$param_value) && array_key_exists($the_function,$param_value['Param']) && array_key_exists(0,$param_value['Param'][$the_function]))){
$var_value = array();
}
else if (array_key_exists($var_PartOfID,$param_value['Param'][$the_function][0])){
$var_value = $param_value['Param'][$the_function][0][$var_PartOfID];
}
else{
$var_value = $param_value['Param'][$the_function][0];
}
/**
* post_* Funktions Aufrufe von BasisClipboard/BasisElement (post_deny, post_del, post_add .....)
*/
D::show($var_value,'$var_value');
D::show($the_function,'$the_function');
D::show($index,'$index');
$the_Object->$the_function($param_HostAccount, $param_iStorable, $var_value);
}
}
}
}
}
}
} else if($param_kind == 'Static'){
foreach($param_value as $fnc_Name => $postAction){
if(array_key_exists('class',$postAction) && $postAction['class'] && array_key_exists('value',$postAction)){
if(!array_key_exists($postAction['class'], self::$LinkClassArray)){
self::$LinkClassArray [$postAction['class']] = new $postAction['class']();
}
// self::$LinkClassArray [$postAction['class']] -> $fnc_Name($postAction['value'] );
/**
* das sind doch keine statischen Funktionsaufrufe ? 100320 @f
*
* Natürlich oder ist zB die funktion post_setPreValues etwa nicht statisch?! 100817 @ um
*/
self::$LinkClassArray [$postAction['class']] -> $fnc_Name($param_HostAccount, $param_iStorable, $postAction['value'] );
}
}
}
$param_HostAccount->resetAuthorProfileID();
}
/**
* sets the Array $PreValueArray
* @param Account &$param_HostAccount
* @param iStorable &$param_iStorable
* @param array $param_values
*/
private static function post_setPreValues(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_values){
self::$PreValueArray = $param_values;
}
public static function appendDOMPreValues($param_DOMDocument,$param_DOMElement){
if(is_array(self::$PreValueArray)){
$DOMElement_PreValue = $param_DOMDocument->createElement('PreValues');
foreach(self::$PreValueArray as $key => $value){
if(is_array($value)){
$DOMElement_Key = $param_DOMDocument->createElement($key);
foreach($value as $key2 => $value2){
$DOMElement_Value=$param_DOMDocument->createElement('Element',$value2);
$DOMElement_Value -> setAttribute('key',$key2);
$DOMElement_Key -> appendChild($DOMElement_Value);
}
$DOMElement_PreValue->appendChild($DOMElement_Key);
}
else{
$DOMElement_PreValue->appendChild($param_DOMDocument->createElement($key,$value));
}
}
$param_DOMElement->appendChild($DOMElement_PreValue);
}
}
}
?>