|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Pedigree; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @package XoopsModules\Pedigree |
|
17
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
18
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
|
19
|
|
|
* @author XOOPS Module Dev Team |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use XoopsModules\Pedigree\{ |
|
23
|
|
|
Helper |
|
|
|
|
|
|
24
|
|
|
}; |
|
25
|
|
|
|
|
26
|
|
|
\defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class Pedigree\Fields |
|
30
|
|
|
*/ |
|
31
|
|
|
class Fields extends \XoopsObject |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct() |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct(); |
|
39
|
|
|
$this->initVar('id', \XOBJ_DTYPE_INT, null, false, 2); |
|
40
|
|
|
$this->initVar('isactive', \XOBJ_DTYPE_INT, 1, false, 1); |
|
41
|
|
|
$this->initVar('fieldname', \XOBJ_DTYPE_TXTBOX, null, false, 50); |
|
42
|
|
|
$this->initVar('fieldtype', \XOBJ_DTYPE_ENUM, 'textbox', false); |
|
43
|
|
|
$this->initVar('lookuptable', \XOBJ_DTYPE_INT, 0, false, 1); |
|
44
|
|
|
$this->initVar('defaultvalue', \XOBJ_DTYPE_TXTBOX, null, false, 50); |
|
45
|
|
|
$this->initVar('fieldexplanation', \XOBJ_DTYPE_TXTAREA, null, false); |
|
46
|
|
|
$this->initVar('hassearch', \XOBJ_DTYPE_INT, 0, false, 1); |
|
47
|
|
|
$this->initVar('litter', \XOBJ_DTYPE_INT, 0, false, 1); |
|
48
|
|
|
$this->initVar('generallitter', \XOBJ_DTYPE_INT, 1, false, 1); |
|
49
|
|
|
$this->initVar('searchname', \XOBJ_DTYPE_TXTBOX, null, false, 50); |
|
50
|
|
|
$this->initVar('searchexplanation', \XOBJ_DTYPE_TXTAREA, null, false); |
|
51
|
|
|
$this->initVar('viewinpedigree', \XOBJ_DTYPE_INT, 1, false, 1); |
|
52
|
|
|
$this->initVar('viewinadvanced', \XOBJ_DTYPE_INT, 1, false, 1); |
|
53
|
|
|
$this->initVar('viewinpie', \XOBJ_DTYPE_INT, 1, false, 1); |
|
54
|
|
|
$this->initVar('viewinlist', \XOBJ_DTYPE_INT, 1, false, 1); |
|
55
|
|
|
$this->initVar('locked', \XOBJ_DTYPE_INT, 0, false, 1); |
|
56
|
|
|
$this->initVar('order', \XOBJ_DTYPE_INT, 0, false, 3); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function __toString() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getVar('fieldname'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param null|bool $action |
|
66
|
|
|
* |
|
67
|
|
|
* @return object {@see \XoopsThemeForm} |
|
68
|
|
|
* @todo refactor to eliminate XoopsObjectTree since it's not structured to |
|
69
|
|
|
* handle this type of object |
|
70
|
|
|
* |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getForm(?bool $action = false): \XoopsThemeForm |
|
73
|
|
|
{ |
|
74
|
|
|
if (false === $action) { |
|
75
|
|
|
$action = $_SERVER['REQUEST_URI']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** @var Helper $helper */ |
|
79
|
|
|
$helper = Helper::getInstance(); |
|
80
|
|
|
$helper->loadLanguage('admin'); |
|
81
|
|
|
|
|
82
|
|
|
$title = $this->isNew() ? \sprintf(\_AM_PEDIGREE_PEDIGREE_CONFIG_ADD) : \sprintf(\_AM_PEDIGREE_PEDIGREE_CONFIG_EDIT); |
|
83
|
|
|
|
|
84
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
85
|
|
|
|
|
86
|
|
|
$form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
|
87
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
|
88
|
|
|
|
|
89
|
|
|
$form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDNAME, 'fieldname', 50, 255, $this->getVar('fieldname')), true); |
|
|
|
|
|
|
90
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_ISACTIVE, 'isactive', (int)$this->getVar('isactive')), false); |
|
91
|
|
|
$fieldTypes = new \XoopsFormSelect(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, 'fieldtype', $this->getVar('fieldtype'), false); |
|
|
|
|
|
|
92
|
|
|
$fieldTypes->addOptionArray([ |
|
93
|
|
|
'DateSelect' => 'DateSelect', |
|
94
|
|
|
'Picture' => 'Picture', |
|
95
|
|
|
'radiobutton' => 'radiobutton', |
|
96
|
|
|
'selectbox' => 'selectbox', |
|
97
|
|
|
'textarea' => 'textarea', |
|
98
|
|
|
'textbox' => 'textbox', |
|
99
|
|
|
'urlfield' => 'urlfield', |
|
100
|
|
|
]); |
|
101
|
|
|
$form->addElement($fieldTypes); |
|
102
|
|
|
// $form->addElement(new \XoopsFormTextArea(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, "fieldtype", $this->getVar("fieldtype"), 4, 47), false); |
|
103
|
|
|
$form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_LOOKUPTABLE, 'lookupTable', 50, 255, $this->getVar('lookuptable')), false); |
|
104
|
|
|
$form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_DEFAULTVALUE, 'defaultValue', 50, 255, $this->getVar('defaultvalue')), false); |
|
105
|
|
|
$form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDEXPLANATION, 'fieldExplanation', 50, 255, $this->getVar('fieldexplanation')), false); |
|
106
|
|
|
$form->addElement(new \XoopsFormRadioYN(\_AM_PEDIGREE_PEDIGREE_CONFIG_HASSEARCH, 'hasSearch', (int)$this->getVar('hassearch')), false); |
|
107
|
|
|
/* @todo: should be single select for either General Litter or Litter, can't have both */ |
|
108
|
|
|
$currentType = $this->getVar('litter') ? 'litter' : 'generallitter'; |
|
109
|
|
|
$litterRadio = new \XoopsFormRadio(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER_TYPE, 'littertype', $currentType); |
|
110
|
|
|
$litterRadio->addOptionArray([ |
|
111
|
|
|
'litter' => _AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, |
|
112
|
|
|
'generallitter' => _AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, |
|
113
|
|
|
]); |
|
114
|
|
|
$form->addElement($litterRadio, false); |
|
115
|
|
|
// $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, "litter", $this->getVar("litter")), false); |
|
116
|
|
|
// $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, "generallitter", $this->getVar("generallitter")), false); |
|
117
|
|
|
$form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHNAME, 'searchname', 50, 255, $this->getVar('searchname')), false); |
|
118
|
|
|
$form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHEXPLANATION, 'searchexplanation', 50, 255, $this->getVar('searchexplanation')), false); |
|
119
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPEDIGREE, 'viewinpedigree', (int)$this->getVar('viewinpedigree')), false); |
|
120
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINADVANCED, 'viewinadvanced', (int)$this->getVar('viewinadvanced')), false); |
|
121
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPIE, 'viewinpie', (int)$this->getVar('viewinpie')), false); |
|
122
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINLIST, 'viewinlist', (int)$this->getVar('viewinlist')), false); |
|
123
|
|
|
$form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, 'locked', (int)$this->getVar('locked')), false); |
|
124
|
|
|
$form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, 'order', 3, 8, (int)$this->getVar('order')), false); |
|
125
|
|
|
// require_once XOOPS_ROOT_PATH."/class/tree.php"; |
|
126
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsDB']->getVar("dirname")); |
|
127
|
|
|
// $criteria = new \CriteriaCompo(); |
|
128
|
|
|
// $criteria->setSort('_id'); |
|
129
|
|
|
// $criteria->setOrder('ASC'); |
|
130
|
|
|
// $_arr = $Handler->getAll(); |
|
131
|
|
|
// $mytree = new \XoopsObjectTree($_arr, "_id", "_pid"); |
|
132
|
|
|
// $form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
|
133
|
|
|
// |
|
134
|
|
|
// require_once XOOPS_ROOT_PATH."/class/tree.php"; |
|
135
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
|
136
|
|
|
// $criteria = new \CriteriaCompo(); |
|
137
|
|
|
// $criteria->setSort('_id'); |
|
138
|
|
|
// $criteria->setOrder('ASC'); |
|
139
|
|
|
// $_arr = $Handler->getAll(); |
|
140
|
|
|
// $mytree = new \XoopsObjectTree($_arr, "_id", "_pid"); |
|
141
|
|
|
// $form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
|
142
|
|
|
/* |
|
143
|
|
|
require_once $GLOBALS['xoops']->path("class/tree.php"); |
|
144
|
|
|
// $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
|
145
|
|
|
$Handler = Helper::getInstance()->getHandler('Fields'); |
|
146
|
|
|
// $Handler = & $fieldsHandler; |
|
147
|
|
|
$criteria = new \CriteriaCompo(); |
|
148
|
|
|
$criteria->setSort('id'); |
|
149
|
|
|
$criteria->setOrder('ASC'); |
|
150
|
|
|
$_arr = $Handler->getAll(); |
|
151
|
|
|
$mytree = new \XoopsObjectTree($_arr, "ID", "_pid"); |
|
152
|
|
|
$form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title", "--", $this->getVar("_pid"), false))); |
|
153
|
|
|
*/ |
|
154
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save_pedigree_fields')); |
|
155
|
|
|
|
|
156
|
|
|
//Submit buttons |
|
157
|
|
|
$form->addElement(new \XoopsFormButtonTray('fieldButtons', _SUBMIT, 'submit')); |
|
158
|
|
|
|
|
159
|
|
|
/* |
|
160
|
|
|
$buttonTray = new \XoopsFormElementTray("", ""); |
|
161
|
|
|
$submit_button = new \XoopsFormButton("", "submit", _SUBMIT, "submit"); |
|
162
|
|
|
$buttonTray->addElement($submit_button); |
|
163
|
|
|
|
|
164
|
|
|
$cancel_button = new \XoopsFormButton("", "", _CANCEL, "cancel"); |
|
165
|
|
|
$cancel_button->setExtra('onclick="history.go(-1)"'); |
|
166
|
|
|
$buttonTray->addElement($cancel_button); |
|
167
|
|
|
|
|
168
|
|
|
$form->addElement($buttonTray); |
|
169
|
|
|
*/ |
|
170
|
|
|
|
|
171
|
|
|
return $form; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return bool |
|
176
|
|
|
*/ |
|
177
|
|
|
public function isActive(): bool |
|
178
|
|
|
{ |
|
179
|
|
|
return (1 == $this->getVar('isactive')); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return bool |
|
184
|
|
|
*/ |
|
185
|
|
|
public function inAdvanced(): bool |
|
186
|
|
|
{ |
|
187
|
|
|
return (1 == $this->getVar('viewinadvanced')); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return bool |
|
192
|
|
|
*/ |
|
193
|
|
|
public function isLocked(): bool |
|
194
|
|
|
{ |
|
195
|
|
|
return (1 == $this->getVar('locked')); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return bool |
|
200
|
|
|
*/ |
|
201
|
|
|
public function hasSearch(): bool |
|
202
|
|
|
{ |
|
203
|
|
|
return (1 == $this->getVar('hassearch')); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @return bool |
|
208
|
|
|
*/ |
|
209
|
|
|
public function addLitter(): bool |
|
210
|
|
|
{ |
|
211
|
|
|
return (1 == $this->getVar('litter')); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return bool |
|
216
|
|
|
*/ |
|
217
|
|
|
public function generalLitter(): bool |
|
218
|
|
|
{ |
|
219
|
|
|
return (1 == $this->getVar('generallitter')); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @return bool |
|
224
|
|
|
*/ |
|
225
|
|
|
public function hasLookup(): bool |
|
226
|
|
|
{ |
|
227
|
|
|
return (1 == $this->getVar('lookuptable')); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @return string |
|
232
|
|
|
*/ |
|
233
|
|
|
public function getSearchString(): string |
|
234
|
|
|
{ |
|
235
|
|
|
return '&o=pname&p'; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @return bool |
|
240
|
|
|
*/ |
|
241
|
|
|
public function inPie(): bool |
|
242
|
|
|
{ |
|
243
|
|
|
return (1 == $this->getVar('viewinpie')); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @return bool |
|
248
|
|
|
*/ |
|
249
|
|
|
public function inPedigree(): bool |
|
250
|
|
|
{ |
|
251
|
|
|
return (1 == $this->getVar('viewinpedigree')); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @return bool |
|
256
|
|
|
*/ |
|
257
|
|
|
public function inList(): bool |
|
258
|
|
|
{ |
|
259
|
|
|
return (1 == $this->getVar('viewinlist')); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* @return int |
|
264
|
|
|
*/ |
|
265
|
|
|
public function getId(): int |
|
266
|
|
|
{ |
|
267
|
|
|
$id = $this->getVar('id'); |
|
268
|
|
|
|
|
269
|
|
|
return !empty($id) ? (int)$id : 0; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @param $setting |
|
274
|
|
|
* |
|
275
|
|
|
* @return mixed |
|
276
|
|
|
* @deprecated |
|
277
|
|
|
*/ |
|
278
|
|
|
public function getSetting(string $setting) |
|
279
|
|
|
{ |
|
280
|
|
|
return isset($this->$setting) ? $this->setting : null; |
|
|
|
|
|
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: