Passed
Push — master ( 48d769...5ccf6e )
by Michael
07:14
created

update.php (1 issue)

Labels
Severity
1
<?php
2
// -------------------------------------------------------------------------
3
4
use Xmf\Request;
5
use XoopsModules\Pedigree;
6
7
8
//require_once  dirname(dirname(__DIR__)) . '/mainfile.php';
9
require_once __DIR__ . '/header.php';
10
$moduleDirName = basename(__DIR__);
11
xoops_loadLanguage('main', $moduleDirName);
12
// Include any common code for this module.
13
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
14
15
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_update.tpl';
16
include XOOPS_ROOT_PATH . '/header.php';
17
18
$xoopsTpl->assign('page_title', 'Pedigree database - Update details');
19
20
//check for access
21
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
22
if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) {
23
    redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST);
24
}
25
// ( $xoopsUser->isAdmin($xoopsModule->mid() ) )
26
27
global $xoopsTpl;
28
global $xoopsDB;
29
global $xoopsModuleConfig;
30
31
//get module configuration
32
/*
33
$moduleHandler = xoops_getHandler('module');
34
$module        = $moduleHandler->getByDirname($moduleDirName);
35
$configHandler = xoops_getHandler('config');
36
$moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
37
*/
38
$helper     = Pedigree\Helper::getInstance(false);
39
$moduleConfig = $helper->getConfig();
40
41
$myts = \MyTextSanitizer::getInstance();
42
43
$fld = Request::getString('fld', '', 'GET');
44
$id  = Request::getInt('id', 0, 'GET');
45
/*
46
$fld = $_GET['fld'];
47
$id  = $_GET['id'];
48
*/
49
50
//query (find values for this dog (and format them))
51
$queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $id;
52
$result      = $GLOBALS['xoopsDB']->query($queryString);
53
54
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
55
    //ID
56
    $id = $row['id'];
57
    //name
58
    $naam     = htmlentities(stripslashes($row['naam']), ENT_QUOTES);
59
    $namelink = '<a href="dog.php?id=' . $row['id'] . '">' . stripslashes($row['naam']) . '</a>';
60
    //owner
61
    $queryeig = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' WHERE id=' . $row['id_owner'];
62
    $reseig   = $GLOBALS['xoopsDB']->query($queryeig);
63
    while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) {
64
        $eig = '<a href="owner.php?ownid=' . $roweig['id'] . '">' . $roweig['firstname'] . ' ' . $roweig['lastname'] . '</a>';
65
    }
66
    $curvaleig = $row['id_owner'];
67
    //breeder
68
    $queryfok = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' WHERE id=' . $row['id_breeder'];
69
    $resfok   = $GLOBALS['xoopsDB']->query($queryfok);
70
    while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
71
        $fok = '<a href="owner.php?ownid=' . $rowfok['id'] . '">' . $rowfok['firstname'] . ' ' . $rowfok['lastname'] . '</a>';
72
    }
73
    $curvalfok = $row['id_breeder'];
74
    //gender
75
    if ('0' == $row['roft']) {
76
        $gender = '<img src="assets/images/male.gif"> ' . _MA_PEDIGREE_FLD_MALE;
77
    } else {
78
        $gender = '<img src="assets/images/female.gif"> ' . _MA_PEDIGREE_FLD_FEMA;
79
    }
80
    $curvalroft = $row['roft'];
81
    //Sire
82
    if (0 != $row['father']) {
83
        $querysire = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $row['father'];
84
        $ressire   = $GLOBALS['xoopsDB']->query($querysire);
85
        while (false !== ($rowsire = $GLOBALS['xoopsDB']->fetchArray($ressire))) {
86
            $sire = '<img src="assets/images/male.gif"><a href="dog.php?id=' . $row['father'] . '">' . stripslashes($rowsire['naam']) . '</a>';
87
        }
88
    }
89
    //Dam
90
    if (0 != $row['mother']) {
91
        $querydam = 'SELECT naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $row['mother'];
92
        $resdam   = $GLOBALS['xoopsDB']->query($querydam);
93
        while (false !== ($rowdam = $GLOBALS['xoopsDB']->fetchArray($resdam))) {
94
            $dam = '<img src="assets/images/female.gif"><a href="dog.php?id=' . $row['mother'] . '">' . stripslashes($rowdam['naam']) . '</a>';
95
        }
96
    }
97
    //picture
98
    $picture = '';
99
    if ('' != $row['foto']) {
100
        $picture = '<img src=' . PEDIGREE_UPLOAD_URL . '/images/thumbnails/' . $row['foto'] . '_400.jpeg>';
0 ignored issues
show
The constant PEDIGREE_UPLOAD_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
101
        $foto    = $row['foto'];
102
    } else {
103
        $foto = '';
104
    }
105
    //user who entered the info
106
    $dbuser = $row['user'];
107
}
108
109
//create form
110
include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
111
$form = new \XoopsThemeForm($naam, 'updatedata', 'updatepage.php', 'post', true);
112
$form->setExtra("enctype='multipart/form-data'");
113
//hidden value current record owner
114
$form->addElement(new \XoopsFormHidden('dbuser', $dbuser));
115
//hidden value dog ID
116
$form->addElement(new \XoopsFormHidden('dogid', $id));
117
$form->addElement(new \XoopsFormHidden('curname', $naam));
118
$form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
119
//name
120
if ('nm' === $fld || 'all' === $fld) {
121
    $form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'naam', $size = 50, $maxsize = 255, $value = $naam));
122
    $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, _MA_PEDIGREE_FLD_NAME_EX));
123
    $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
124
    $form->addElement(new \XoopsFormHidden('dbfield', 'naam'));
125
    $form->addElement(new \XoopsFormHidden('curvalname', $naam));
126
} else {
127
    //owner
128
    if ('ow' === $fld || 'all' === $fld) {
129
        $owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = null, $size = 1, $multiple = false);
130
        $queryeig     = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY `lastname`';
131
        $reseig       = $GLOBALS['xoopsDB']->query($queryeig);
132
        $owner_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN);
133
        while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) {
134
            $owner_select->addOption($roweig['id'], $name = $roweig['lastname'] . ', ' . $roweig['firstname']);
135
        }
136
        $form->addElement($owner_select);
137
        $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, _MA_PEDIGREE_FLD_OWNE_EX));
138
        $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
139
        $form->addElement(new \XoopsFormHidden('dbfield', 'id_owner'));
140
        $form->addElement(new \XoopsFormHidden('curvaleig', $curvaleig));
141
    }
142
}
143
144
//breeder
145
if ('br' === $fld || 'all' === $fld) {
146
    $breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = null, $size = 1, $multiple = false);
147
    $queryfok       = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY `lastname`';
148
    $resfok         = $GLOBALS['xoopsDB']->query($queryfok);
149
    $breeder_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN);
150
    while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) {
151
        $breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']);
152
    }
153
    $form->addElement($breeder_select);
154
    $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, _MA_PEDIGREE_FLD_BREE_EX));
155
    $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
156
    $form->addElement(new \XoopsFormHidden('dbfield', 'id_breeder'));
157
    $form->addElement(new \XoopsFormHidden('curvalfok', $curvalfok));
158
}
159
160
//gender
161
if ('sx' === $fld || 'all' === $fld) {
162
    $gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = null);
163
    $gender_radio->addOptionArray(['0' => _MA_PEDIGREE_FLD_MALE, '1' => _MA_PEDIGREE_FLD_FEMA]);
164
    $form->addElement($gender_radio);
165
    $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, _MA_PEDIGREE_FLD_GEND_EX));
166
    $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
167
    $form->addElement(new \XoopsFormHidden('dbfield', 'roft'));
168
    $form->addElement(new \XoopsFormHidden('curvalroft', $curvalroft));
169
}
170
171
//picture
172
if ('pc' === $fld || 'all' === $fld) {
173
    $form->addElement(new \XoopsFormLabel('Picture', $picture));
174
    $form->setExtra("enctype='multipart/form-data'");
175
    $img_box = new \XoopsFormFile('Image', 'photo', 1024000);
176
    $img_box->setExtra("size ='50'");
177
    $form->addElement($img_box);
178
    $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_PICT_EX, ['[animalType]' => $moduleConfig['animalType']])));
179
    $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
180
    $form->addElement(new \XoopsFormHidden('dbfield', 'foto'));
181
    $form->addElement(new \XoopsFormHidden('curvalpic', $foto));
182
}
183
184
//create animal object
185
186
$a      = (!isset($_GET['id']) ? $a = 1 : $a = $_GET['id']);
187
$animal = new Pedigree\Animal($a);
188
189
//test to find out how many user fields there are..
190
$fields = $animal->getNumOfFields();
191
192
foreach ($fields as $i => $iValue) {
193
    if ($_GET['fld'] == $iValue) {
194
        $userField = new Pedigree\Field($fields[$i], $animal->getConfig());
195
        if ($userField->isActive()) {
196
            $fieldType   = $userField->getSetting('FieldType');
197
            $fieldObject = new $fieldType($userField, $animal);
198
            $edditable   = $fieldObject->editField();
199
            $form->addElement($edditable);
200
            $explain = $userField->getSetting('FieldExplanation');
201
            $form->addElement(new \XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $explain));
202
            $form->addElement(new \XoopsFormHidden('dbtable', 'pedigree_tree'));
203
            $form->addElement(new \XoopsFormHidden('dbfield', 'user' . $iValue));
204
        }
205
    }
206
}
207
208
//submit button
209
if ($fld) {
210
    $form->addElement(new \XoopsFormButton('', 'button_id', _MA_PEDIGREE_BUT_SUB, 'submit'));
211
}
212
//add data (form) to smarty template
213
$xoopsTpl->assign('form', $form->render());
214
215
//footer
216
include XOOPS_ROOT_PATH . '/footer.php';
217