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() |
33
|
|
|
{ |
34
|
|
|
$urlToGetLbl = $this->config['Servers'][$this->config['Defaults']['Source']]['url'] |
|
|
|
|
35
|
|
|
. '?Label=---' . urlencode(' List of known labels'); |
36
|
|
|
$knownLabels = $this->getContentFromUrlThroughCurlAsArrayIfJson($urlToGetLbl)['response']; |
|
|
|
|
37
|
|
|
$informatorKnownLabels = array_diff($knownLabels, ['--- List of known labels']); |
38
|
|
|
$tmpOptions = []; |
39
|
|
|
foreach ($informatorKnownLabels as $value) { |
40
|
|
|
$tmpOptions[] = '<input type="radio" name="Label" id="Label_' . $value . '" value="' . $value . '" ' |
41
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus('Label', $value) |
42
|
|
|
. '/>' |
43
|
|
|
. '<label for="Label_' . $value . '">' . $value . '</label>'; |
44
|
|
|
} |
45
|
|
|
return '<fieldset style="float:left;">' |
46
|
|
|
. '<legend>Informator Label to use</legend>' |
47
|
|
|
. implode('<br/>', $tmpOptions) |
48
|
|
|
. '</fieldset>'; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function providers($inArray) |
52
|
|
|
{ |
53
|
|
|
$tmpOptions = []; |
54
|
|
|
foreach ($this->config['Servers'] as $key => $value) { |
55
|
|
|
$tmpOptions[] = '<a href="' . $value['url'] . '" target="_blank">run-me</a> ' |
56
|
|
|
. '<input type="radio" name="' . $inArray['ConfigName'] . '" id="' |
57
|
|
|
. $inArray['ConfigName'] . '_' . $key . '" value="' . $key . '" ' |
58
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus($inArray['ConfigName'], $key) |
59
|
|
|
. '/>' |
60
|
|
|
. '<label for="' . $inArray['ConfigName'] . '_' . $key . '">' . $value['name'] . '</label>'; |
61
|
|
|
} |
62
|
|
|
return '<fieldset style="float:left;">' |
63
|
|
|
. '<legend>' . $inArray['TitleStart'] . ' config providers</legend>' |
64
|
|
|
. implode('<br/>', $tmpOptions) |
65
|
|
|
. '</fieldset>'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function setFormOptions() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$sReturn = []; |
71
|
|
|
$sReturn[] = $this->typeOfResults(); |
72
|
|
|
$sReturn[] = $this->providers([ |
73
|
|
|
'TitleStart' => 'Source', |
74
|
|
|
'ConfigName' => 'localConfig', |
75
|
|
|
]); |
76
|
|
|
$sReturn[] = $this->providers([ |
77
|
|
|
'TitleStart' => 'Target', |
78
|
|
|
'ConfigName' => 'serverConfig', |
79
|
|
|
]); |
80
|
|
|
$sReturn[] = $this->listOfKnownLabels(); |
81
|
|
|
return '<div class="tabbertab" id="tabOptions" title="Options">' |
82
|
|
|
. '<style type="text/css" media="all" scoped>label { width: auto; }</style>' |
83
|
|
|
. '<form method="get" action="' |
84
|
|
|
. $_SERVER['PHP_SELF'] . '">' |
85
|
|
|
. '<input type="submit" value="Apply" />' |
86
|
|
|
. '<br/>' . implode('', $sReturn) |
87
|
|
|
. '</form>' |
88
|
|
|
. '<div style="float:none;clear:both;height:1px;"> </div>' |
89
|
|
|
. '</div><!--from tabOptions-->'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function turnRequestedValueIntoCheckboxStatus($requestedName, $checkedValue) |
93
|
|
|
{ |
94
|
|
|
$requestedNameValue = $this->informatorInternalArray['superGlobals']->get($requestedName); |
|
|
|
|
95
|
|
|
$checkboxStatus = ''; |
96
|
|
|
if ($requestedNameValue === $checkedValue) { |
97
|
|
|
$checkboxStatus = 'checked '; |
98
|
|
|
} |
99
|
|
|
return $checkboxStatus; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function typeOfResults() |
103
|
|
|
{ |
104
|
|
|
return '<fieldset style="float:left;">' |
105
|
|
|
. '<legend>Type of results displayed</legend>' |
106
|
|
|
. '<input type="radio" name="displayOnlyDifferent" id="displayOnlyDifferent" value="1" ' |
107
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus('displayOnlyDifferent', 1) |
108
|
|
|
. '/>' |
109
|
|
|
. '<label for="displayOnlyDifferent">Only the Different values</label>' |
110
|
|
|
. '<br/>' |
111
|
|
|
. '<input type="radio" name="displayOnlyDifferent" id="displayAll" value="0" ' |
112
|
|
|
. $this->turnRequestedValueIntoCheckboxStatus('displayOnlyDifferent', 0) |
113
|
|
|
. '/>' |
114
|
|
|
. '<label for="displayAll">All</label>' |
115
|
|
|
. '</fieldset>'; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
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: