1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Daniel Popiniuc |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace danielgp\info_compare; |
28
|
|
|
|
29
|
|
|
trait OutputFormBuilder |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
private function listOfKnownLabels($superGlobals, $knownLabels) |
33
|
|
|
{ |
34
|
|
|
$informatorKnownLabels = array_diff($knownLabels, ['--- List of known labels']); |
35
|
|
|
$tmpOptions = []; |
36
|
|
|
foreach ($informatorKnownLabels as $value) { |
37
|
|
|
$tmpOptions[] = '<input type="radio" name="Label" id="Label_' . $value . '" value="' . $value . '" ' |
38
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus($superGlobals, 'Label', $value) |
39
|
|
|
. '/>' |
40
|
|
|
. '<label for="Label_' . $value . '">' . $value . '</label>'; |
41
|
|
|
} |
42
|
|
|
return '<fieldset style="float:left;">' |
43
|
|
|
. '<legend>Informator Label to use</legend>' |
44
|
|
|
. implode('<br/>', $tmpOptions) |
45
|
|
|
. '</fieldset>'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function providers($inAry) |
49
|
|
|
{ |
50
|
|
|
$tmpOptions = []; |
51
|
|
|
foreach ($this->config['Servers'] as $key => $value) { |
|
|
|
|
52
|
|
|
$tmpOptions[] = '<a href="' . $value['url'] . '" target="_blank">run-me</a> ' |
53
|
|
|
. '<input type="radio" name="' . $inAry['ConfigName'] . '" id="' |
54
|
|
|
. $inAry['ConfigName'] . '_' . $key . '" value="' . $key . '" ' |
55
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus($inAry['SuperGlobals'], $inAry['ConfigName'], $key) |
56
|
|
|
. '/>' |
57
|
|
|
. '<label for="' . $inAry['ConfigName'] . '_' . $key . '">' . $value['name'] . '</label>'; |
58
|
|
|
} |
59
|
|
|
return '<fieldset style="float:left;">' |
60
|
|
|
. '<legend>' . $inAry['TitleStart'] . ' config providers</legend>' |
61
|
|
|
. implode('<br/>', $tmpOptions) |
62
|
|
|
. '</fieldset>'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function setFormOptions($superGlobals, $knownLabels) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$sReturn = []; |
68
|
|
|
$sReturn[] = $this->typeOfResults($superGlobals); |
69
|
|
|
$sReturn[] = $this->providers([ |
70
|
|
|
'SuperGlobals' => $superGlobals, |
71
|
|
|
'TitleStart' => 'Source', |
72
|
|
|
'ConfigName' => 'localConfig', |
73
|
|
|
]); |
74
|
|
|
$sReturn[] = $this->providers([ |
75
|
|
|
'SuperGlobals' => $superGlobals, |
76
|
|
|
'TitleStart' => 'Target', |
77
|
|
|
'ConfigName' => 'serverConfig', |
78
|
|
|
]); |
79
|
|
|
$sReturn[] = $this->listOfKnownLabels($superGlobals, $knownLabels); |
80
|
|
|
return '<div class="tabbertab" id="tabOptions" title="Options">' |
81
|
|
|
. '<style type="text/css" media="all" scoped>label { width: auto; }</style>' |
82
|
|
|
. '<form method="get" action="' |
83
|
|
|
. $_SERVER['PHP_SELF'] . '">' |
84
|
|
|
. '<input type="submit" value="Apply" />' |
85
|
|
|
. '<br/>' . implode('', $sReturn) |
86
|
|
|
. '</form>' |
87
|
|
|
. '<div style="float:none;clear:both;height:1px;"> </div>' |
88
|
|
|
. '</div><!--from tabOptions-->'; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
private function turnRequestedValueIntoCheckboxStatus($superGlobals, $requestedName, $checkedValue) |
92
|
|
|
{ |
93
|
|
|
$requestedNameValue = $superGlobals->get($requestedName); |
94
|
|
|
$checkboxStatus = ''; |
95
|
|
|
if ($requestedNameValue === $checkedValue) { |
96
|
|
|
$checkboxStatus = 'checked '; |
97
|
|
|
} |
98
|
|
|
return $checkboxStatus; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function typeOfResults($superGlobals) |
102
|
|
|
{ |
103
|
|
|
return '<fieldset style="float:left;">' |
104
|
|
|
. '<legend>Type of results displayed</legend>' |
105
|
|
|
. '<input type="radio" name="displayOnlyDifferent" id="displayOnlyDifferent" value="1" ' |
106
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus($superGlobals, 'displayOnlyDifferent', 1) |
107
|
|
|
. '/>' |
108
|
|
|
. '<label for="displayOnlyDifferent">Only the Different values</label>' |
109
|
|
|
. '<br/>' |
110
|
|
|
. '<input type="radio" name="displayOnlyDifferent" id="displayAll" value="0" ' |
111
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus($superGlobals, 'displayOnlyDifferent', 0) |
112
|
|
|
. '/>' |
113
|
|
|
. '<label for="displayAll">All</label>' |
114
|
|
|
. '</fieldset>'; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: