1
|
|
|
<?php |
2
|
|
|
// ------------------------------------------------------------------------- |
3
|
|
|
|
4
|
|
|
use Xmf\Request; |
5
|
|
|
use XoopsModules\Pedigree; |
6
|
|
|
|
7
|
|
|
//require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
8
|
|
|
require_once __DIR__ . '/header.php'; |
9
|
|
|
$moduleDirName = basename(__DIR__); |
10
|
|
|
xoops_loadLanguage('main', $moduleDirName); |
11
|
|
|
|
12
|
|
|
//needed for generation of pie charts |
13
|
|
|
ob_start(); |
14
|
|
|
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/class_eq_pie.php'; |
15
|
|
|
|
16
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_edit.tpl'; |
17
|
|
|
|
18
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
19
|
|
|
// Include any common code for this module. |
20
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php'; |
21
|
|
|
|
22
|
|
|
global $xoopsTpl, $xoopsDB; |
23
|
|
|
|
24
|
|
|
//get module configuration |
25
|
|
|
/** @var XoopsModuleHandler $moduleHandler */ |
26
|
|
|
$moduleHandler = xoops_getHandler('module'); |
27
|
|
|
$module = $moduleHandler->getByDirname($moduleDirName); |
28
|
|
|
$configHandler = xoops_getHandler('config'); |
29
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
|
|
|
|
30
|
|
|
|
31
|
|
|
if (isset($_GET['f'])) { |
32
|
|
|
if ('save' === $_GET['f']) { |
33
|
|
|
save(); |
34
|
|
|
} |
35
|
|
|
} else { |
36
|
|
|
edit(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function save() |
40
|
|
|
{ |
41
|
|
|
global $xoopsDB, $moduleConfig; |
42
|
|
|
$a = (!isset($_POST['id']) ? $a = '' : $a = $_POST['id']); |
|
|
|
|
43
|
|
|
$animal = new Pedigree\Animal($a); |
|
|
|
|
44
|
|
|
$fields = $animal->getNumOfFields(); |
|
|
|
|
45
|
|
|
foreach ($fields as $i => $iValue) { |
46
|
|
|
$userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
47
|
|
|
if ($userField->isActive()) { |
48
|
|
|
$currentfield = 'user' . $iValue; |
49
|
|
|
$pictureField = $_FILES[$currentfield]['name']; |
50
|
|
|
if (empty($pictureField) || '' == $pictureField) { |
51
|
|
|
$newvalue = $_POST['user' . $iValue]; |
52
|
|
|
} else { |
53
|
|
|
$newvalue = Pedigree\Utility::uploadPicture(0); |
54
|
|
|
} |
55
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' SET user' . $iValue . "='" . $GLOBALS['xoopsDB']->escape($newvalue) . "' WHERE id='" . $a . "'"; |
56
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
// $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET naam = '" . $_POST['naam'] . "', roft = '" . $_POST['roft'] . "' WHERE id='" . $a . "'"; |
60
|
|
|
$NAAM = Request::getString('naam', '', 'post'); |
61
|
|
|
$roft = Request::getString('roft', '', 'post'); |
62
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET naam = '" . $GLOBALS['xoopsDB']->escape($NAAM) . "', roft = '" . $GLOBALS['xoopsDB']->escape($roft) . "' WHERE id='" . $a . "'"; |
63
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
64
|
|
|
$pictureField = $_FILES['photo']['name']; |
65
|
|
|
if (empty($pictureField) || '' == $pictureField) { |
66
|
|
|
//llalalala |
67
|
|
|
} else { |
68
|
|
|
$foto = Pedigree\Utility::uploadPicture(0); |
69
|
|
|
// $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET foto='" . $foto . "' WHERE id='" . $a . "'"; |
70
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET foto='" . $GLOBALS['xoopsDB']->escape($foto) . "' WHERE id='" . $a . "'"; |
71
|
|
|
} |
72
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
73
|
|
|
if ('1' == $moduleConfig['ownerbreeder']) { |
74
|
|
|
// $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET id_owner = '" . $_POST['id_owner'] . "', id_breeder = '" . $_POST['id_breeder'] . "' WHERE id='" . $a . "'"; |
75
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " SET id_owner = '" . Request::getInt('id_owner', 0, 'post') . "', id_breeder = '" . Request::getInt('id_breeder', 0, 'post') . "' WHERE id='" . $a . "'"; |
76
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
77
|
|
|
} |
78
|
|
|
redirect_header('dog.php?id=' . $a, 2, 'Your changes have been saved'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param int $id |
83
|
|
|
*/ |
84
|
|
|
function edit($id = 0) |
85
|
|
|
{ |
86
|
|
|
global $xoopsTpl, $xoopsDB, $moduleConfig; |
87
|
|
|
if (isset($_GET['id'])) { |
88
|
|
|
$id = $_GET['id']; |
89
|
|
|
} |
90
|
|
|
include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
91
|
|
|
|
92
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $id; |
93
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); |
94
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
95
|
|
|
$form = new \XoopsThemeForm('Edit ' . $row['naam'], 'dogname', 'edit.php?f=save', 'post', true); |
96
|
|
|
$form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
97
|
|
|
$form->addElement(new \XoopsFormHidden('id', $id)); |
98
|
|
|
//name |
99
|
|
|
$naam = htmlentities(stripslashes($row['naam']), ENT_QUOTES); |
100
|
|
|
$form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'naam', $size = 50, $maxsize = 255, $value = $naam)); |
101
|
|
|
//gender |
102
|
|
|
$roft = $row['roft']; |
103
|
|
|
$gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = $roft); |
104
|
|
|
$gender_radio->addOptionArray([ |
105
|
|
|
'0' => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $moduleConfig['male']]), |
106
|
|
|
'1' => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $moduleConfig['female']]), |
107
|
|
|
]); |
108
|
|
|
$form->addElement($gender_radio); |
109
|
|
|
//father |
110
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $row['father'] . "'"; |
111
|
|
|
$resfather = $GLOBALS['xoopsDB']->query($sql); |
112
|
|
|
$numfields = $GLOBALS['xoopsDB']->getRowsNum($resfather); |
113
|
|
|
if ('0' == !$numfields) { |
114
|
|
|
while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resfather))) { |
115
|
|
|
$form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">' . $rowfetch['naam'] . '</a>')); |
116
|
|
|
} |
117
|
|
|
} else { |
118
|
|
|
$form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">Unknown</a>')); |
119
|
|
|
} |
120
|
|
|
//mother |
121
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $row['mother'] . "'"; |
122
|
|
|
$resmother = $GLOBALS['xoopsDB']->query($sql); |
123
|
|
|
$numfields = $GLOBALS['xoopsDB']->getRowsNum($resmother); |
124
|
|
|
if ('0' == !$numfields) { |
125
|
|
|
while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resmother))) { |
126
|
|
|
$form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">' . $rowfetch['naam'] . '</a>')); |
127
|
|
|
} |
128
|
|
|
} else { |
129
|
|
|
$form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">Unknown</a>')); |
130
|
|
|
} |
131
|
|
|
//owner/breeder |
132
|
|
|
if ('1' == $moduleConfig['ownerbreeder']) { |
133
|
|
|
$owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = $row['id_owner'], $size = 1, $multiple = false); |
134
|
|
|
$queryeig = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
135
|
|
|
$reseig = $GLOBALS['xoopsDB']->query($queryeig); |
136
|
|
|
$owner_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
137
|
|
|
while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) { |
138
|
|
|
$owner_select->addOption($roweig['id'], $name = $roweig['lastname'] . ', ' . $roweig['firstname']); |
139
|
|
|
} |
140
|
|
|
$form->addElement($owner_select); |
141
|
|
|
//breeder |
142
|
|
|
$breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = $row['id_breeder'], $size = 1, $multiple = false); |
143
|
|
|
$queryfok = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
144
|
|
|
$resfok = $GLOBALS['xoopsDB']->query($queryfok); |
145
|
|
|
$breeder_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
146
|
|
|
while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) { |
147
|
|
|
$breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']); |
148
|
|
|
} |
149
|
|
|
$form->addElement($breeder_select); |
150
|
|
|
} |
151
|
|
|
//picture |
152
|
|
|
if ('' != $row['foto']) { |
153
|
|
|
$picture = '<img src=' . PEDIGREE_UPLOAD_URL . '/images/thumbnails/' . $row['foto'] . '_400.jpeg>'; |
|
|
|
|
154
|
|
|
$form->addElement(new \XoopsFormLabel('<b>Picture</b>', $picture)); |
155
|
|
|
} else { |
156
|
|
|
$picture = ''; |
157
|
|
|
} |
158
|
|
|
$form->setExtra("enctype='multipart/form-data'"); |
159
|
|
|
$img_box = new \XoopsFormFile('<b>Image</b>', 'photo', 1024000); |
160
|
|
|
$img_box->setExtra("size ='50'"); |
161
|
|
|
$form->addElement($img_box); |
162
|
|
|
//userfields |
163
|
|
|
//create animal object |
164
|
|
|
$animal = new Pedigree\Animal($id); |
165
|
|
|
//test to find out how many user fields there are.. |
166
|
|
|
$fields = $animal->getNumOfFields(); |
167
|
|
|
for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
168
|
|
|
$userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
169
|
|
|
if ($userField->isActive()) { |
170
|
|
|
$fieldType = $userField->getSetting('FieldType'); |
171
|
|
|
$fieldObject = new $fieldType($userField, $animal); |
172
|
|
|
$edditable[$i] = $fieldObject->editField(); |
173
|
|
|
$form->addElement($edditable[$i]); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
$form->addElement(new \XoopsFormButton('', 'button_id', _MA_PEDIGREE_BUT_SUB, 'submit')); |
|
|
|
|
178
|
|
|
$xoopsTpl->assign('form', $form->render()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
//comments and footer |
182
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
183
|
|
|
|