1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Pedigree\Form; |
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
|
|
|
* Module: Pedigree |
17
|
|
|
* |
18
|
|
|
* @category Module |
19
|
|
|
* @package pedigree |
20
|
|
|
* @author XOOPS Development Team <https://xoops.org> |
21
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
22
|
|
|
* @license GPL 2.0 or later |
23
|
|
|
* @link https://xoops.org/ |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
use CriteriaCompo; |
28
|
|
|
use RuntimeException; |
29
|
|
|
use Xmf\Module\Helper\Permission; |
30
|
|
|
use XoopsDatabaseFactory; |
31
|
|
|
use XoopsFormButton; |
32
|
|
|
use XoopsFormElementTray; |
33
|
|
|
use XoopsFormFile; |
34
|
|
|
use XoopsFormHidden; |
35
|
|
|
use XoopsFormLabel; |
36
|
|
|
use XoopsFormSelect; |
37
|
|
|
use XoopsFormSelectUser; |
38
|
|
|
use XoopsFormText; |
39
|
|
|
use XoopsFormTextArea; |
40
|
|
|
use XoopsLists; |
41
|
|
|
use XoopsModules\Pedigree\{ |
42
|
|
|
Helper, |
43
|
|
|
Utility |
44
|
|
|
}; |
45
|
|
|
use XoopsObjectTree; |
46
|
|
|
use XoopsThemeForm; |
47
|
|
|
|
48
|
|
|
require_once \dirname(__DIR__, 2) . '/include/common.php'; |
49
|
|
|
|
50
|
|
|
$moduleDirName = \basename(\dirname(__DIR__, 2)); |
51
|
|
|
//$helper = Helper::getInstance(); |
52
|
|
|
$permHelper = new Permission(); |
53
|
|
|
|
54
|
|
|
\xoops_load('XoopsFormLoader'); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Class TreeForm |
58
|
|
|
*/ |
59
|
|
|
class TreeForm extends XoopsThemeForm |
60
|
|
|
{ |
61
|
|
|
public $targetObject; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Constructor |
65
|
|
|
* |
66
|
|
|
* @param $target |
67
|
|
|
*/ |
68
|
|
|
public function __construct($target) |
69
|
|
|
{ |
70
|
|
|
// global $helper; |
71
|
|
|
$this->helper = $target->helper; |
|
|
|
|
72
|
|
|
$this->targetObject = $target; |
73
|
|
|
|
74
|
|
|
$title = $this->targetObject->isNew() ? \sprintf(AM_PEDIGREE_TREE_ADD) : \sprintf(AM_PEDIGREE_TREE_EDIT); |
|
|
|
|
75
|
|
|
parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
76
|
|
|
$this->setExtra('enctype="multipart/form-data"'); |
77
|
|
|
|
78
|
|
|
//include ID field, it's needed so the module knows if it is a new form or an edited form |
79
|
|
|
|
80
|
|
|
$hidden = new \XoopsFormHidden('id', $this->targetObject->getVar('id')); |
81
|
|
|
$this->addElement($hidden); |
82
|
|
|
unset($hidden); |
83
|
|
|
|
84
|
|
|
// Id |
85
|
|
|
$this->addElement(new \XoopsFormLabel(AM_PEDIGREE_TREE_ID, $this->targetObject->getVar('id'), 'id')); |
|
|
|
|
86
|
|
|
// Pname |
87
|
|
|
$this->addElement(new \XoopsFormTextArea(AM_PEDIGREE_TREE_PNAME, 'pname', $this->targetObject->getVar('pname'), 4, 47), false); |
|
|
|
|
88
|
|
|
// Id_owner |
89
|
|
|
$this->addElement(new \XoopsFormText(AM_PEDIGREE_TREE_ID_OWNER, 'id_owner', 50, 255, $this->targetObject->getVar('id_owner')), false); |
|
|
|
|
90
|
|
|
// Id_breeder |
91
|
|
|
$this->addElement(new \XoopsFormText(AM_PEDIGREE_TREE_ID_BREEDER, 'id_breeder', 50, 255, $this->targetObject->getVar('id_breeder')), false); |
|
|
|
|
92
|
|
|
// User |
93
|
|
|
$this->addElement(new \XoopsFormSelectUser(AM_PEDIGREE_TREE_USER, 'user', false, $this->targetObject->getVar('user'), 1, false), false); |
|
|
|
|
94
|
|
|
// Roft |
95
|
|
|
$roft = new \XoopsFormSelect(AM_PEDIGREE_TREE_ROFT, 'roft', $this->targetObject->getVar('roft')); |
|
|
|
|
96
|
|
|
$optionsArray = Utility::enumerate('pedigree_tree', 'roft'); |
97
|
|
|
if (!\is_array($optionsArray)) { |
98
|
|
|
throw new RuntimeException($optionsArray . ' must be an array.'); |
99
|
|
|
} |
100
|
|
|
foreach ($optionsArray as $enum) { |
101
|
|
|
$roft->addOption($enum, (\defined($enum) ? \constant($enum) : $enum)); |
102
|
|
|
} |
103
|
|
|
$this->addElement($roft, false); |
104
|
|
|
// Mother |
105
|
|
|
require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
106
|
|
|
//$treeHandler = xoops_getModuleHandler('tree', 'pedigree' ); |
107
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
108
|
|
|
/** @var \XoopsPersistableObjectHandler $Handler */ |
109
|
|
|
$treeHandler = new Pedigree\TreeHandler($db); |
|
|
|
|
110
|
|
|
|
111
|
|
|
$criteria = new CriteriaCompo(); |
112
|
|
|
$categoryArray = $treeHandler->getObjects($criteria); |
113
|
|
|
if ($categoryArray) { |
114
|
|
|
$categoryTree = new \XoopsObjectTree($categoryArray, 'id', 'pid'); |
115
|
|
|
|
116
|
|
|
if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { |
117
|
|
|
$treePid = $categoryTree->makeSelectElement('pid', 'title', '--', $this->targetObject->getVar('pname'), true, 0, '', AM_PEDIGREE_TREE_MOTHER); |
|
|
|
|
118
|
|
|
$this->addElement($treePid); |
119
|
|
|
} else { |
120
|
|
|
$treePid = $categoryTree->makeSelBox('pname', 'title', '--', $this->targetObject->getVar('pname', 'e'), true); |
121
|
|
|
$this->addElement(new \XoopsFormLabel(AM_PEDIGREE_TREE_MOTHER, $treePid)); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
// Father |
125
|
|
|
require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
126
|
|
|
//$treeHandler = xoops_getModuleHandler('tree', 'pedigree' ); |
127
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
128
|
|
|
/** @var \XoopsPersistableObjectHandler $Handler */ |
129
|
|
|
$treeHandler = new Pedigree\TreeHandler($db); |
130
|
|
|
|
131
|
|
|
$criteria = new CriteriaCompo(); |
132
|
|
|
$categoryArray = $treeHandler->getObjects($criteria); |
133
|
|
|
if ($categoryArray) { |
134
|
|
|
$categoryTree = new \XoopsObjectTree($categoryArray, 'id', 'pid'); |
135
|
|
|
|
136
|
|
|
if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) { |
137
|
|
|
$treePid = $categoryTree->makeSelectElement('pid', 'title', '--', $this->targetObject->getVar('pname'), true, 0, '', AM_PEDIGREE_TREE_FATHER); |
|
|
|
|
138
|
|
|
$this->addElement($treePid); |
139
|
|
|
} else { |
140
|
|
|
$treePid = $categoryTree->makeSelBox('pname', 'title', '--', $this->targetObject->getVar('pname', 'e'), true); |
141
|
|
|
$this->addElement(new \XoopsFormLabel(AM_PEDIGREE_TREE_FATHER, $treePid)); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
// Foto |
145
|
|
|
$foto = $this->targetObject->getVar('foto') ?: 'blank.png'; |
146
|
|
|
|
147
|
|
|
$uploadDir = '/uploads/pedigree/images/'; |
148
|
|
|
$imgtray = new \XoopsFormElementTray(AM_PEDIGREE_TREE_FOTO, '<br>'); |
|
|
|
|
149
|
|
|
$imgpath = \sprintf(\AM_PEDIGREE_FORMIMAGE_PATH, $uploadDir); |
150
|
|
|
$imageselect = new \XoopsFormSelect($imgpath, 'foto', $foto); |
151
|
|
|
$imageArray = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir); |
152
|
|
|
foreach ($imageArray as $image) { |
153
|
|
|
$imageselect->addOption((string)$image, $image); |
154
|
|
|
} |
155
|
|
|
$imageselect->setExtra("onchange='showImgSelected(\"image_foto\", \"foto\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'"); |
156
|
|
|
$imgtray->addElement($imageselect); |
157
|
|
|
$imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $foto . "' name='image_foto' id='image_foto' alt='' >")); |
158
|
|
|
$fileseltray = new \XoopsFormElementTray('', '<br>'); |
159
|
|
|
$fileseltray->addElement(new \XoopsFormFile(\AM_PEDIGREE_FORMUPLOAD, 'foto', \xoops_getModuleOption('maxsize'))); |
|
|
|
|
160
|
|
|
$fileseltray->addElement(new \XoopsFormLabel('')); |
161
|
|
|
$imgtray->addElement($fileseltray); |
162
|
|
|
$this->addElement($imgtray); |
163
|
|
|
// Coi |
164
|
|
|
$this->addElement(new \XoopsFormText(AM_PEDIGREE_TREE_COI, 'coi', 50, 255, $this->targetObject->getVar('coi')), false); |
|
|
|
|
165
|
|
|
|
166
|
|
|
$this->addElement(new \XoopsFormHidden('op', 'save')); |
167
|
|
|
$this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|