-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocietyToSocietyRelationship_transfer.php
429 lines (347 loc) · 15.5 KB
/
societyToSocietyRelationship_transfer.php
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
<?php
require_once 'config/boot.php';
require_once 'classes/System.php';
$system = new System ( 'config/host.json' );
session_start ();
if (! isset ( $_SESSION ['pendingProcess'] )) {
$_SESSION ['pendingProcess'] = array ();
$_SESSION ['pendingProcess'] ['name'] = 'society relationship transfer';
// toutes les données à collecter pour accomplir le processus
$_SESSION ['pendingProcess'] ['society'] = null;
$_SESSION ['pendingProcess'] ['formerRelationship'] = null;
$_SESSION ['pendingProcess'] ['society_role'] = null;
$_SESSION ['pendingProcess'] ['targetSociety'] = null;
$_SESSION ['pendingProcess'] ['targetSociety_role'] = null;
$_SESSION ['pendingProcess'] ['followingSocietiesCollectionIds'] = null;
// l'étape du processus dans lequel on se trouve
$_SESSION ['pendingProcess'] ['currentStep'] = 'target society role selection';
}
// la société à transférer
if (array_key_exists ( 'society_id', $_REQUEST )) {
$_SESSION ['pendingProcess'] ['society'] = new Society($_REQUEST ['society_id']);
$_SESSION ['pendingProcess'] ['society']->feed();
}
// la relation d'origine
if (array_key_exists ( 'relationship_id', $_REQUEST )) {
$_SESSION ['pendingProcess'] ['formerRelationship'] = new Relationship($_REQUEST ['relationship_id']);
$_SESSION ['pendingProcess'] ['formerRelationship']->feed();
}
// la société ciblée
if (array_key_exists ( 'targetSociety_id', $_REQUEST )) {
$_SESSION ['pendingProcess'] ['targetSociety'] = new Society($_REQUEST ['targetSociety_id']);
$_SESSION ['pendingProcess'] ['targetSociety']->feed();
}
$society = $_SESSION['pendingProcess']['society'];
$relationship = $_SESSION['pendingProcess']['formerRelationship'];
$formerRelatedSociety = $relationship->getRelatedItem($society);
if (isset ( $_POST )) {
ToolBox::formatUserPost ( $_POST );
}
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Quitter' :
unset ( $_SESSION ['pendingProcess'] );
header ( 'location:' . $formerRelatedSociety->getDisplayUrl() );
exit ();
}
}
$fb = new UserFeedBack ();
if (isset ( $_POST ['task_id'] )) {
switch ($_POST ['task_id']) {
case 'target society role selection' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Poursuivre' :
if (isset($_POST ['targetSociety_role'])) {
$_SESSION ['pendingProcess'] ['targetSociety_role'] = $_POST ['targetSociety_role'];
$_SESSION ['pendingProcess'] ['currentStep'] = 'target society selection';
} else {
$fb->addWarningMessage ( 'Il faut choisir une des options.' );
}
break;
}
}
break;
case 'target society selection' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Poursuivre' :
if (isset($_POST ['targetSociety_id'])) {
$_SESSION ['pendingProcess'] ['targetSociety'] = new Society($_POST ['targetSociety_id']);
$_SESSION ['pendingProcess'] ['targetSociety'] -> feed();
$_SESSION ['pendingProcess'] ['currentStep'] = 'new role definition';
} else {
$fb->addWarningMessage ( 'Il faut choisir une des options.' );
}
break;
}
}
break;
case 'new role definition' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Poursuivre' :
$_SESSION ['pendingProcess'] ['society_role'] = $_POST ['society_role'];
$_SESSION ['pendingProcess'] ['currentStep'] = 'target society role definition';
break;
}
}
break;
case 'target society role definition' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Poursuivre' :
$_SESSION ['pendingProcess'] ['targetSociety_role'] = $_POST ['society_role'];
$items = $formerRelatedSociety->getRelatedSocieties($relationship->getRole($society));
if (count($items)>1) {
$_SESSION ['pendingProcess'] ['currentStep'] = 'following societies selection';
} else {
// on passe l'étape de transfert des sociétés tenant le même rôle s'il n'y en a pas
$_SESSION ['pendingProcess'] ['currentStep'] = 'confirmation';
}
break;
}
}
break;
case 'following societies selection' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Poursuivre' :
if (isset($_POST['followingSocietiesCollectionIds'])) {
$_SESSION ['pendingProcess'] ['followingSocietiesCollectionIds'] = $_POST['followingSocietiesCollectionIds'];
}
$_SESSION ['pendingProcess'] ['currentStep'] = 'confirmation';
break;
}
}
break;
case 'confirmation' :
if (isset ( $_POST ['cmd'] )) {
switch ($_POST ['cmd']) {
case 'Je confirme' :
$relationship->setRole($society, $_SESSION ['pendingProcess'] ['society_role']);
$relationship->setRelatedItem($society, $_SESSION ['pendingProcess'] ['targetSociety'], $_SESSION ['pendingProcess'] ['targetSociety_role']);
if ($relationship->toDB()) {
if (isset($_SESSION['pendingProcess']['followingSocietiesCollectionIds'])){
$followingOnes = $system->getSocieties(array("ids"=>$_SESSION['pendingProcess']['followingSocietiesCollectionIds']));
foreach ($followingOnes as $s) {
$r = $system->getRelationship($s,$formerRelatedSociety);
$r->setRole($s, $_SESSION ['pendingProcess'] ['society_role']);
$r->setRelatedItem($s, $_SESSION ['pendingProcess'] ['targetSociety'], $_SESSION ['pendingProcess'] ['targetSociety_role']);
$r->toDB();
}
}
unset ( $_SESSION ['pendingProcess'] );
header ( 'location:' . $formerRelatedSociety->getDisplayUrl() );
exit ();
}
}
}
break;
}
}
$formerRelatedSociety = $relationship->getRelatedItem($society);
$targetSociety = $_SESSION['pendingProcess']['targetSociety'];
/*
echo '<h2>Post</h2>';
var_dump($_POST);
echo '<h2>Session</h2>';
var_dump($_SESSION);
*/
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="<?php echo ToolBox::toHtml($system->getAppliDescription()) ?>" />
<title><?php echo ToolBox::toHtml($system->getAppliName().' : déplacer une société'); ?></title>
<link type="text/css" rel="stylesheet" href="<?php echo $system->getSkinUrl(); ?>/theme.css"></link>
<?php echo $system->writeHtmlHeadTagsForFavicon(); ?>
</head>
<body>
<div class="container-fluid">
<?php
switch ($_SESSION ['pendingProcess'] ['currentStep']) {
case 'target society role selection' :
$role = $relationship->getRole($society);
$options = $formerRelatedSociety->getRelatedSocietiesRoles();
echo '<header><h1>Transférer vers une société tenant quel rôle ? <small>étape 1</small></h1></header>';
echo $fb->toHtml();
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="target society role selection" />';
echo '<ul class="list-group list-group-flush">';
for($i= 0; $i<count($options); $i++) {
if (strcasecmp($options[$i], $role)==0) {
continue;
}
echo '<li class="p-2 list-group-item">';
echo '<div class="form-check">';
echo '<input id="targetSociety_role_i'.$i.'" name="targetSociety_role" class="form-check-input" type="radio" value="'.$options[$i].'" />';
echo '<label class="form-check-label" for="targetSociety_role_i'.$i.'">'.Toolbox::toHtml($options[$i]).'</label>';
echo '</div>';
echo '</li>';
}
echo '</ul>';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Poursuivre" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
echo '</form>';
break;
case 'target society selection' :
$options = $formerRelatedSociety->getRelatedSocieties($_SESSION ['pendingProcess'] ['targetSociety_role']);
echo '<header><h1>Quelle est la société ? <small>étape 2</small></h1></header>';
echo $fb->toHtml();
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="target society selection" />';
echo '<ul class="list-group list-group-flush">';
foreach($options as $o) {
echo '<li class="p-2 list-group-item">';
echo '<div class="form-check">';
echo '<input id="targetSociety_i" name="targetSociety_id" class="form-check-input" type="radio" value="'.$o[0]->getId().'">';
echo '<label class="form-check-label" for="targetSociety_role_i">'.Toolbox::toHtml($o[0]->getName()).'</label>';
echo '</div>';
echo '</li>';
}
echo '</ul>';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Poursuivre" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
echo '</form>';
break;
case 'new role definition' :
echo '<header><h1>Quel rôle pour '.$society->getName().' ? <small>étape 3</small></h1></header>';
echo '<p>Vis à vis de <em>'.$_SESSION['pendingProcess']['targetSociety']->getName().'</em></p>';
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="new role definition" />';
echo '<datalist id="role_list">';
foreach (Relationship::getKnownRoles() as $r) {
echo '<option value="'.ToolBox::toHtml($r['role']).'"/>';
}
echo '</datalist>';
echo '<div class="form-group">';
echo '<label for="society_role_i">Son rôle</label>';
echo '<input id="society_role_i" name="society_role" type="text" list="role_list" value="'.$relationship->getRole($society).'" size="20" class="form-control" />';
echo '</div>';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Poursuivre" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
echo '</form>';
break;
case 'target society role definition' :
echo '<header><h1>Quel rôle pour '.$_SESSION['pendingProcess']['targetSociety']->getName().' ? <small>étape 4</small></h1></header>';
echo '<p>Vis à vis de <em>'.$society->getName().'</em></p>';
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="target society role definition" />';
echo '<datalist id="role_list">';
foreach (Relationship::getKnownRoles() as $r) {
echo '<option value="'.ToolBox::toHtml($r['role']).'"/>';
};
echo '</datalist>';
echo '<div class="form-group">';
echo '<label for="society_role_i">Son rôle</label>';
echo '<input id="society_role_i" name="society_role" type="text" list="role_list" value="'.$_SESSION ['pendingProcess'] ['targetSociety_role'].'" size="20" class="form-control" />';
echo '</div>';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Poursuivre" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
echo '</form>';
break;
case 'following societies selection' :
$options = $formerRelatedSociety->getRelatedSocieties($relationship->getRole($society));
echo '<header><h1>Même chemin pour d'autres sociétés ? <small>étape 5</small></h1></header>';
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="following societies selection" />';
echo '<ul class="list-group list-group-flush">';
for($i=0; $i<count($options); $i++) {
if(strcmp($options[$i][0]->getId(),$society->getId())==0){
continue;
}
echo '<li class="p-2 list-group-item">';
echo '<div class="form-check">';
echo '<input id="followingSocieties_i'.$i.'" name="followingSocietiesCollectionIds[]" class="form-check-input" type="checkbox" value="'.$options[$i][0]->getId().'">';
echo '<label class="form-check-label" for="followingSocieties_i'.$i.'">'.Toolbox::toHtml($options[$i][0]->getName()).'</label>';
echo '</div>';
echo '</li>';
}
echo '</ul>';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Poursuivre" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
echo '</form>';
break;
case 'confirmation' :
echo '<header><h1>Récapitulatif <small>étape 6</small></h1></header>';
if (isset($_SESSION['pendingProcess']['followingSocietiesCollectionIds'])) {
$followingOnes = $system->getSocieties(array("ids"=>$_SESSION['pendingProcess']['followingSocietiesCollectionIds']));
}
echo '<div class="table-responsive">';
echo '<table class="table">';
echo '<thead><tr><th></th><th scope="col">avant</th><th scope="col">après</th></tr></thead>';
echo '<tbody>';
echo '<tr>';
echo '<th scope="row">'.Toolbox::toHtml($society->getName()).'</th>';
echo '<td>';
if (!empty($relationship->getPeriod())) {
echo '<div><small>'.$relationship->getPeriod().'</small></div>';
}
echo Toolbox::toHtml($relationship->getRole($society)).' <em>'.Toolbox::toHtml($formerRelatedSociety->getName()).'</em>';
if (!empty($relationship->getDescription())) {
echo '<p>'.Toolbox::toHtml($relationship->getDescription()).'</p>';
}
echo '</td>';
echo '<td>';
if (!empty($relationship->getPeriod())) {
echo '<div><small>'.$relationship->getPeriod().'</small></div>';
}
echo Toolbox::toHtml($_SESSION ['pendingProcess'] ['society_role']).' <em>'.Toolbox::toHtml($targetSociety->getName()).'</em>';
if (!empty($relationship->getDescription())) {
echo '<p>'.Toolbox::toHtml($relationship->getDescription()).'</p>';
}
echo '</td>';
echo '</tr>';
foreach ($followingOnes as $s) {
$r = $system->getRelationship($s,$formerRelatedSociety);
echo '<tr>';
echo '<th scope="row">'.Toolbox::toHtml($s->getName()).'</th>';
echo '<td>';
if (!empty($r->getPeriod())) {
echo '<div><small>'.$r->getPeriod().'</small></div>';
}
echo Toolbox::toHtml($r->getRole($s)).' <em>'.Toolbox::toHtml($formerRelatedSociety->getName()).'</em>';
if (!empty($r->getDescription())) {
echo '<p>'.Toolbox::toHtml($r->getDescription()).'</p>';
}
echo '</td>';
echo '<td>';
if (!empty($r->getPeriod())) {
echo '<div><small>'.$r->getPeriod().'</small></div>';
}
echo Toolbox::toHtml($_SESSION ['pendingProcess'] ['society_role']).' <em>'.Toolbox::toHtml($targetSociety->getName()).'</em>';
if (!empty($r->getDescription())) {
echo '<p>'.Toolbox::toHtml($r->getDescription()).'</p>';
}
echo '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
echo '</div>';
echo '<form action="' . $_SERVER ['PHP_SELF'] . '" method="post">';
echo '<input type="hidden" name="task_id" value="confirmation" />';
echo '<div class="btn-group">';
echo '<input type="submit" name="cmd" value="Je confirme" class="btn btn-default btn-primary" />';
echo '<input type="submit" name="cmd" value="Quitter" class="btn btn-default" />';
echo '</div>';
break;
default :
echo '<p>'.$_SESSION ['pendingProcess'] ['currentStep'].' est une étape inconnue</p>.';
}
?>
</div>
</body>