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