mambax7 /
pedigree
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | // ------------------------------------------------------------------------- |
||
| 3 | |||
| 4 | require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
||
| 5 | |||
| 6 | /* |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 7 | if (file_exists(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/" . $xoopsConfig['language'] . "/main.php")) { |
||
| 8 | require_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/" . $xoopsConfig['language'] . "/main.php"; |
||
| 9 | } else { |
||
| 10 | include_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/english/main.php"; |
||
| 11 | } |
||
| 12 | */ |
||
| 13 | |||
| 14 | xoops_loadLanguage('main', basename(dirname(__DIR__))); |
||
| 15 | |||
| 16 | // Include any common code for this module. |
||
| 17 | require_once(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/include/functions.php"); |
||
| 18 | require_once(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/include/class_field.php"); |
||
| 19 | |||
| 20 | $xoopsOption['template_main'] = "pedigree_adddog.tpl"; |
||
| 21 | |||
| 22 | include XOOPS_ROOT_PATH . '/header.php'; |
||
| 23 | $xoopsTpl->assign('page_title', "Pedigree database - Update details"); |
||
| 24 | |||
| 25 | //check for access |
||
| 26 | $xoopsModule =& XoopsModule::getByDirname("pedigree"); |
||
| 27 | if (empty($xoopsUser)) { |
||
| 28 | redirect_header("index.php", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 29 | exit(); |
||
| 30 | } |
||
| 31 | |||
| 32 | //create function variable from url |
||
| 33 | if (isset($_GET['f'])) { |
||
| 34 | $f = $_GET['f']; |
||
| 35 | } else { |
||
| 36 | $f = ""; |
||
| 37 | adddog(); |
||
| 38 | } |
||
| 39 | if ($f == "checkname") { |
||
| 40 | checkname(); |
||
| 41 | } |
||
| 42 | if ($f == "sire") { |
||
| 43 | sire(); |
||
| 44 | } |
||
| 45 | if ($f == "dam") { |
||
| 46 | dam(); |
||
| 47 | } |
||
| 48 | if ($f == "check") { |
||
| 49 | check(); |
||
| 50 | } |
||
| 51 | |||
| 52 | function adddog() |
||
| 53 | { |
||
| 54 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 55 | |||
| 56 | //get module configuration |
||
| 57 | $module_handler =& xoops_gethandler('module'); |
||
| 58 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 59 | $config_handler =& xoops_gethandler('config'); |
||
| 60 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 61 | |||
| 62 | //check for access |
||
| 63 | if (empty($xoopsUser)) { |
||
| 64 | redirect_header("javascript:history.go(-1)", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 65 | exit(); |
||
| 66 | } |
||
| 67 | if ($xoopsUser->getVar("uid") == 0) { |
||
| 68 | redirect_header("javascript:history.go(-1)", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 69 | exit(); |
||
| 70 | } |
||
| 71 | //create form |
||
| 72 | include XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; |
||
| 73 | $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=checkname', 'POST'); |
||
| 74 | $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
| 75 | //create random value |
||
| 76 | $random = (rand() % 10000); |
||
| 77 | $form->addElement(new XoopsFormHidden('random', $random)); |
||
| 78 | //find userid |
||
| 79 | $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar("uid"))); |
||
| 80 | |||
| 81 | //name |
||
| 82 | $form->addElement(new XoopsFormText("<b>" . _MA_PEDIGREE_FLD_NAME . "</b>", 'NAAM', $size = 50, $maxsize = 255, $value = '')); |
||
| 83 | $string = strtr(_MA_PEDIGREE_FLD_NAME_EX, array('[animalType]' => $moduleConfig['animalType'])); |
||
| 84 | $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, $string)); |
||
| 85 | |||
| 86 | //submit button |
||
| 87 | $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_DATA, array('[animalType]' => $moduleConfig['animalType'])), 'submit')); |
||
| 88 | |||
| 89 | //add data (form) to smarty template |
||
| 90 | $xoopsTpl->assign("form", $form->render()); |
||
| 91 | } |
||
| 92 | |||
| 93 | function checkname() |
||
| 94 | |||
| 95 | { |
||
| 96 | //configure global variables |
||
| 97 | global $xoopsTpl, $xoopsDB, $xoopsUser; |
||
| 98 | |||
| 99 | //get module configuration |
||
| 100 | $module_handler =& xoops_gethandler('module'); |
||
| 101 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 102 | $config_handler =& xoops_gethandler('config'); |
||
| 103 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 104 | |||
| 105 | $name = $_POST['NAAM']; |
||
| 106 | //query |
||
| 107 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_tree") . " WHERE NAAM LIKE'%" . $name . "%' ORDER BY NAAM"; |
||
| 108 | $result = $xoopsDB->query($queryString); |
||
| 109 | $numresults = $xoopsDB->getRowsNum($result); |
||
| 110 | if ($numresults >= 1 && !(isset($_GET['r']))) { |
||
| 111 | //create form |
||
| 112 | include XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; |
||
| 113 | $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=checkname&r=1', 'POST'); |
||
| 114 | //other elements |
||
| 115 | $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
| 116 | $form->addElement(new XoopsFormHidden('NAAM', $_POST['NAAM'])); |
||
| 117 | $form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar("uid"))); |
||
| 118 | while ($row = $xoopsDB->fetchArray($result)) { |
||
| 119 | //name |
||
| 120 | $form->addElement(new XoopsFormLabel("<b>" . _MA_PEDIGREE_FLD_NAME . "</b>", "<a href=\"dog.php?id=" . $row['ID'] . "\">" . stripslashes($row['NAAM']) . "</a>")); |
||
| 121 | } |
||
| 122 | $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_ADD_KNOWN, array('[animalTypes]' => $moduleConfig['animalTypes'])))); |
||
| 123 | //submit button |
||
| 124 | $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_KNOWNOK, array('[animalType]' => $moduleConfig['animalType'])), 'submit')); |
||
| 125 | //add data (form) to smarty template |
||
| 126 | $xoopsTpl->assign("form", $form->render()); |
||
| 127 | } else { |
||
| 128 | //create form |
||
| 129 | include XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; |
||
| 130 | $form = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_DOG, array('[animalType]' => $moduleConfig['animalType'])), 'dogname', 'add_dog.php?f=sire', 'POST'); |
||
| 131 | //added to handle upload |
||
| 132 | $form->setExtra("enctype='multipart/form-data'"); |
||
| 133 | $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
| 134 | //create random value |
||
| 135 | $random = (rand() % 10000); |
||
| 136 | $form->addElement(new XoopsFormHidden('random', $random)); |
||
| 137 | $form->addElement(new XoopsFormHidden('NAAM', htmlspecialchars($_POST['NAAM'], ENT_QUOTES))); |
||
| 138 | //find userid from previous form |
||
| 139 | $form->addElement(new XoopsFormHidden('user', $_POST['user'])); |
||
| 140 | |||
| 141 | //name |
||
| 142 | $form->addElement(new XoopsFormLabel("<b>" . _MA_PEDIGREE_FLD_NAME . "</b>", stripslashes($_POST['NAAM']))); |
||
| 143 | //gender |
||
| 144 | $gender_radio = new XoopsFormRadio("<b>" . _MA_PEDIGREE_FLD_GEND . "</b>", 'roft', $value = '0'); |
||
| 145 | $gender_radio->addOptionArray( |
||
| 146 | array('0' => strtr(_MA_PEDIGREE_FLD_MALE, array('[male]' => $moduleConfig['male'])), '1' => strtr(_MA_PEDIGREE_FLD_FEMA, array('[female]' => $moduleConfig['female']))) |
||
| 147 | ); |
||
| 148 | $form->addElement($gender_radio); |
||
| 149 | if ($moduleConfig['ownerbreeder'] == '1') { |
||
| 150 | //breeder |
||
| 151 | $breeder_select = new XoopsFormSelect("<b>" . _MA_PEDIGREE_FLD_BREE . "</b>", $name = "id_breeder", $value = '0', $size = 1, $multiple = false); |
||
| 152 | $queryfok = "SELECT ID, lastname, firstname from " . $xoopsDB->prefix("pedigree_owner") . " ORDER BY lastname"; |
||
| 153 | $resfok = $xoopsDB->query($queryfok); |
||
| 154 | $breeder_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN, $disabled = false); |
||
| 155 | while ($rowfok = $xoopsDB->fetchArray($resfok)) { |
||
| 156 | $breeder_select->addOption($rowfok['ID'], $name = $rowfok['lastname'] . ", " . $rowfok['firstname'], $disabled = false); |
||
| 157 | } |
||
| 158 | $form->addElement($breeder_select); |
||
| 159 | $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_BREE_EX, array('[animalType]' => $moduleConfig['animalType'])))); |
||
| 160 | |||
| 161 | //owner |
||
| 162 | $owner_select = new XoopsFormSelect("<b>" . _MA_PEDIGREE_FLD_OWNE . "</b>", $name = "id_owner", $value = '0', $size = 1, $multiple = false); |
||
| 163 | $queryfok = "SELECT ID, lastname, firstname from " . $xoopsDB->prefix("pedigree_owner") . " ORDER BY lastname"; |
||
| 164 | $resfok = $xoopsDB->query($queryfok); |
||
| 165 | $owner_select->addOption('0', $name = _MA_PEDIGREE_UNKNOWN, $disabled = false); |
||
| 166 | while ($rowfok = $xoopsDB->fetchArray($resfok)) { |
||
| 167 | $owner_select->addOption($rowfok['ID'], $name = $rowfok['lastname'] . ", " . $rowfok['firstname'], $disabled = false); |
||
| 168 | } |
||
| 169 | $form->addElement($owner_select); |
||
| 170 | $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, strtr(_MA_PEDIGREE_FLD_OWNE_EX, array('[animalType]' => $moduleConfig['animalType'])))); |
||
| 171 | } |
||
| 172 | //picture |
||
| 173 | $max_imgsize = 1024000; |
||
| 174 | $img_box = new XoopsFormFile("Image", "photo", $max_imgsize); |
||
| 175 | $img_box->setExtra("size ='50'"); |
||
| 176 | $form->addElement($img_box); |
||
| 177 | |||
| 178 | //create animal object |
||
| 179 | $animal = new Animal(); |
||
| 180 | //test to find out how many user fields there are.. |
||
| 181 | $fields = $animal->numoffields(); |
||
| 182 | |||
| 183 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 184 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 185 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 186 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 187 | if ($userfield->active() && !$userfield->isLocked()) { |
||
| 188 | $newentry = $fieldobject->newField(); |
||
| 189 | $form->addElement($newentry); |
||
| 190 | } |
||
| 191 | unset($newentry); |
||
| 192 | } |
||
| 193 | |||
| 194 | //submit button |
||
| 195 | $form->addElement(new XoopsFormButton('', 'button_id', strtr(_MA_PEDIGREE_ADD_SIRE, array('[father]' => $moduleConfig['father'])), 'submit')); |
||
| 196 | |||
| 197 | //add data (form) to smarty template |
||
| 198 | $xoopsTpl->assign("form", $form->render()); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | |||
| 202 | function sire() |
||
| 203 | { |
||
| 204 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 205 | |||
| 206 | //get module configuration |
||
| 207 | $module_handler =& xoops_gethandler('module'); |
||
| 208 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 209 | $config_handler =& xoops_gethandler('config'); |
||
| 210 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 211 | $empty = array(); // an empty array |
||
| 212 | |||
| 213 | //check for access |
||
| 214 | if (empty($xoopsUser)) { |
||
| 215 | redirect_header("javascript:history.go(-1)", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 216 | exit(); |
||
| 217 | } |
||
| 218 | $user = isset($_POST['user']) ? $_POST['user'] : null; |
||
| 219 | if (empty($random)) { |
||
| 220 | $random = isset($_POST['random']) ? $_POST['random'] : null; |
||
| 221 | } |
||
| 222 | if (isset($_GET['random'])) { |
||
| 223 | $random = $_GET['random']; |
||
| 224 | } |
||
| 225 | if (empty($st)) { |
||
| 226 | $st = 0; |
||
| 227 | } |
||
| 228 | if (isset($_GET['st'])) { |
||
| 229 | $st = $_GET['st']; |
||
| 230 | } |
||
| 231 | $name = isset($_POST['NAAM']) ? $_POST['NAAM'] : null; |
||
| 232 | $roft = isset($_POST['roft']) ? $_POST['roft'] : null; |
||
| 233 | |||
| 234 | $id_owner = isset($_POST['id_owner']) ? $_POST['id_owner'] : null; |
||
| 235 | $id_breeder = isset($_POST['id_breeder']) ? $_POST['id_breeder'] : null; |
||
| 236 | |||
| 237 | $picturefield = isset($_FILES['photo']) ? $_FILES['photo']['name'] : null; // $_FILES['photo']['name']; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
89% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 238 | if (empty($picturefield) || $picturefield == "") { |
||
| 239 | $foto = ""; |
||
| 240 | } else { |
||
| 241 | $foto = uploadedpict(0); |
||
| 242 | } |
||
| 243 | $numpicturefield = 1; |
||
| 244 | |||
| 245 | //make the redirect |
||
| 246 | if (!isset($_GET['r'])) { |
||
| 247 | if ($_POST['NAAM'] == "") { |
||
| 248 | redirect_header("add_dog.php", 1, _MA_PEDIGREE_ADD_NAMEPLZ); |
||
| 249 | } |
||
| 250 | //create animal object |
||
| 251 | $animal = new Animal(); |
||
| 252 | //test to find out how many user fields there are.. |
||
| 253 | $fields = $animal->numoffields(); |
||
| 254 | sort($fields); //sort by ID not by order |
||
| 255 | $usersql = ""; |
||
| 256 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 257 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 258 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 259 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 260 | if ($userfield->active()) { |
||
| 261 | //check if _FILES variable exists for user picturefield |
||
| 262 | $currentfield = 'user' . $fields[$i]; |
||
| 263 | $picturefield = $_FILES[$currentfield]['name']; |
||
| 264 | if ($fieldType == "Picture" && (!empty($picturefield) || $picturefield != "")) { |
||
| 265 | $userpicture = uploadedpict($numpicturefield); |
||
| 266 | $usersql .= ",'" . $userpicture . "'"; |
||
| 267 | ++$numpicturefield; |
||
| 268 | } elseif ($userfield->isLocked()) { |
||
| 269 | //userfield is locked, substitute default value |
||
| 270 | $usersql .= ",'" . $userfield->DefaultValue . "'"; |
||
| 271 | } else { |
||
| 272 | //echo $fieldType.":".$i.":".$fields[$i]."<br />"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 273 | $usersql .= ",'" . unhtmlentities($_POST['user' . $fields[$i]]) . "'"; |
||
| 274 | } |
||
| 275 | } else { |
||
| 276 | $usersql .= ",''"; |
||
| 277 | } |
||
| 278 | //echo $fields[$i]."<br/>"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
78% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 279 | |||
| 280 | } |
||
| 281 | |||
| 282 | //insert into pedigree_temp |
||
| 283 | $query |
||
| 284 | = "INSERT INTO " . $xoopsDB->prefix("pedigree_temp") . " VALUES ('" . $random . "','" . unhtmlentities($name) . "','" . $id_owner . "','" . $id_breeder . "','" . $user . "','" . $roft |
||
| 285 | . "','','','" . $foto . "', ''" . $usersql . ")"; |
||
| 286 | //echo $query; die(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
78% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 287 | $xoopsDB->query($query); |
||
| 288 | redirect_header("add_dog.php?f=sire&random=" . $random . "&st=" . $st . "&r=1&l=a", 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, array('[father]' => $moduleConfig['father']))); |
||
| 289 | } |
||
| 290 | //find letter on which to start else set to 'a' |
||
| 291 | if (isset($_GET['l'])) { |
||
| 292 | $l = $_GET['l']; |
||
| 293 | } else { |
||
| 294 | $l = "a"; |
||
| 295 | } |
||
| 296 | //assign sire to template |
||
| 297 | $xoopsTpl->assign("sire", "1"); |
||
| 298 | //create list of males dog to select from |
||
| 299 | $perp = $moduleConfig['perpage']; |
||
| 300 | //count total number of dogs |
||
| 301 | $numdog = "SELECT count(ID) from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft='0' and NAAM LIKE '" . $l . "%'"; |
||
| 302 | $numres = $xoopsDB->query($numdog); |
||
| 303 | //total number of dogs the query will find |
||
| 304 | list($numresults) = $xoopsDB->fetchRow($numres); |
||
| 305 | //total number of pages |
||
| 306 | $numpages = (floor($numresults / $perp)) + 1; |
||
| 307 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
| 308 | $numpages = $numpages - 1; |
||
| 309 | } |
||
| 310 | //find current page |
||
| 311 | $cpage = (floor($st / $perp)) + 1; |
||
| 312 | //create alphabet |
||
| 313 | $pages = ""; |
||
| 314 | View Code Duplication | for ($i = 65; $i <= 90; ++$i) { |
|
| 315 | if ($l == chr($i)) { |
||
| 316 | $pages .= "<b><a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a></b> "; |
||
| 317 | } else { |
||
| 318 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a> "; |
||
| 319 | } |
||
| 320 | } |
||
| 321 | $pages .= "- "; |
||
| 322 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ã…\">Ã…</a> "; |
||
| 323 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&random=" . $random . "&l=Ö\">Ö</a> "; |
||
| 324 | //create linebreak |
||
| 325 | $pages .= "<br />"; |
||
| 326 | //create previous button |
||
| 327 | if ($numpages > 1) { |
||
| 328 | if ($cpage > 1) { |
||
| 329 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | //create numbers |
||
| 333 | for ($x = 1; $x < ($numpages + 1); ++$x) { |
||
| 334 | //create line break after 20 number |
||
| 335 | if (($x % 20) == 0) { |
||
| 336 | $pages .= "<br />"; |
||
| 337 | } |
||
| 338 | if ($x != $cpage) { |
||
| 339 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($perp * ($x - 1)) . "\">" . $x . "</a> "; |
||
| 340 | } else { |
||
| 341 | $pages .= $x . "  "; |
||
| 342 | } |
||
| 343 | } |
||
| 344 | //create next button |
||
| 345 | if ($numpages > 1) { |
||
| 346 | if ($cpage < ($numpages)) { |
||
| 347 | $pages .= "<a href=\"add_dog.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . "</a>  "; |
||
| 348 | } |
||
| 349 | } |
||
| 350 | |||
| 351 | //query |
||
| 352 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft = '0' and NAAM like '" . $l . "%'ORDER BY NAAM LIMIT " . $st . ", " . $perp; |
||
| 353 | $result = $xoopsDB->query($queryString); |
||
| 354 | |||
| 355 | $animal = new Animal(); |
||
| 356 | //test to find out how many user fields there are... |
||
| 357 | $fields = $animal->numoffields(); |
||
| 358 | $numofcolumns = 1; |
||
| 359 | $columns[] = array('columnname' => "Name"); |
||
| 360 | View Code Duplication | for ($i = 0; $i < count($fields); ++$i) { |
|
| 361 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 362 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 363 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 364 | //create empty string |
||
| 365 | $lookupvalues = ""; |
||
| 366 | if ($userfield->active() && $userfield->inlist()) { |
||
| 367 | if ($userfield->haslookup()) { |
||
| 368 | $lookupvalues = $userfield->lookup($fields[$i]); |
||
| 369 | //debug information |
||
| 370 | //print_r($lookupvalues); |
||
| 371 | } |
||
| 372 | $columns[] = array('columnname' => $fieldobject->fieldname, 'columnnumber' => $userfield->getID(), 'lookupval' => $lookupvalues); |
||
| 373 | ++$numofcolumns; |
||
| 374 | unset($lookupvalues); |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | View Code Duplication | for ($i = 1; $i < ($numofcolumns); ++$i) { |
|
| 379 | $empty[] = array('value' => ""); |
||
| 380 | } |
||
| 381 | $dogs [] = array( |
||
| 382 | 'id' => "0", |
||
| 383 | 'name' => "", |
||
| 384 | 'gender' => "", |
||
| 385 | 'link' => "<a href=\"add_dog.php?f=dam&random=" . $random . "&selsire=0\">" . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, array('[father]' => $moduleConfig['father'])) . "</a>", |
||
| 386 | 'colour' => "", |
||
| 387 | 'number' => "", |
||
| 388 | 'usercolumns' => $empty |
||
| 389 | ); |
||
| 390 | |||
| 391 | View Code Duplication | while ($row = $xoopsDB->fetchArray($result)) { |
|
| 392 | //create picture information |
||
| 393 | if ($row['foto'] != '') { |
||
| 394 | $camera = " <img src=\"assets/images/camera.png\">"; |
||
| 395 | } else { |
||
| 396 | $camera = ""; |
||
| 397 | } |
||
| 398 | $name = stripslashes($row['NAAM']) . $camera; |
||
| 399 | //empty array |
||
| 400 | unset($columnvalue); |
||
| 401 | //fill array |
||
| 402 | for ($i = 1; $i < ($numofcolumns); ++$i) { |
||
| 403 | $x = $columns[$i]['columnnumber']; |
||
| 404 | if (is_array($columns[$i]['lookupval'])) { |
||
| 405 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 406 | if ($key == $row['user' . $x]) { |
||
| 407 | $value = $keyvalue['value']; |
||
| 408 | } |
||
| 409 | } |
||
| 410 | //debug information |
||
| 411 | ///echo $columns[$i]['columnname']."is an array !"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 412 | } //format value - cant use object because of query count |
||
| 413 | elseif (substr($row['user' . $x], 0, 7) == 'http://') { |
||
| 414 | $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . "</a>"; |
||
| 415 | } else { |
||
| 416 | $value = $row['user' . $x]; |
||
| 417 | } |
||
| 418 | $columnvalue[] = array('value' => $value); |
||
| 419 | } |
||
| 420 | $dogs[] = array( |
||
| 421 | 'id' => $row['ID'], |
||
| 422 | 'name' => $name, |
||
| 423 | 'gender' => '<img src="assets/images/male.gif">', |
||
| 424 | 'link' => "<a href=\"add_dog.php?f=dam&random=" . $random . "&selsire=" . $row['ID'] . "\">" . $name . "</a>", |
||
| 425 | 'colour' => "", |
||
| 426 | 'number' => "", |
||
| 427 | 'usercolumns' => $columnvalue |
||
| 428 | ); |
||
| 429 | } |
||
| 430 | |||
| 431 | //add data to smarty template |
||
| 432 | //assign dog |
||
| 433 | $xoopsTpl->assign("dogs", $dogs); |
||
| 434 | $xoopsTpl->assign("columns", $columns); |
||
| 435 | $xoopsTpl->assign("numofcolumns", $numofcolumns); |
||
| 436 | $xoopsTpl->assign("tsarray", sorttable($numofcolumns)); |
||
| 437 | //assign links |
||
| 438 | $xoopsTpl->assign("nummatch", strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $moduleConfig['father']))); |
||
| 439 | $xoopsTpl->assign("pages", $pages); |
||
| 440 | |||
| 441 | } |
||
| 442 | |||
| 443 | function dam() |
||
| 444 | { |
||
| 445 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 446 | |||
| 447 | //get module configuration |
||
| 448 | $module_handler =& xoops_gethandler('module'); |
||
| 449 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 450 | $config_handler =& xoops_gethandler('config'); |
||
| 451 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 452 | $empty = array(); // an empty array |
||
| 453 | |||
| 454 | //check for access |
||
| 455 | $xoopsModule =& XoopsModule::getByDirname("pedigree"); |
||
| 456 | if (empty($xoopsUser)) { |
||
| 457 | redirect_header("javascript:history.go(-1)", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 458 | exit(); |
||
| 459 | } |
||
| 460 | if (empty($random)) { |
||
| 461 | $random = isset($_POST['random']) ? $_POST['random'] : null; |
||
| 462 | } |
||
| 463 | if (isset($_GET['random'])) { |
||
| 464 | $random = $_GET['random']; |
||
| 465 | } |
||
| 466 | if (empty($st)) { |
||
| 467 | $st = 0; |
||
| 468 | } |
||
| 469 | if (isset($_GET['st'])) { |
||
| 470 | $st = $_GET['st']; |
||
| 471 | } |
||
| 472 | //find letter on which to start else set to 'a' |
||
| 473 | if (isset($_GET['l'])) { |
||
| 474 | $l = $_GET['l']; |
||
| 475 | } else { |
||
| 476 | $l = "a"; |
||
| 477 | } |
||
| 478 | //make the redirect |
||
| 479 | View Code Duplication | if (!isset($_GET['r'])) { |
|
| 480 | //insert into pedigree_temp |
||
| 481 | $query = "UPDATE " . $xoopsDB->prefix("pedigree_temp") . " SET father =" . $_GET['selsire'] . " WHERE ID=" . $random; |
||
| 482 | $xoopsDB->queryf($query); |
||
| 483 | redirect_header("add_dog.php?f=dam&random=" . $random . "&st=" . $st . "&r=1&l=a", 1, strtr(_MA_PEDIGREE_ADD_SIREOK, array('[mother]' => $moduleConfig['mother']))); |
||
| 484 | } |
||
| 485 | |||
| 486 | $xoopsTpl->assign("sire", "1"); |
||
| 487 | //create list of males dog to select from |
||
| 488 | $perp = $moduleConfig['perpage']; |
||
| 489 | //count total number of dogs |
||
| 490 | $numdog = "SELECT count(ID) from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft='1' and NAAM LIKE '" . $l . "%'"; |
||
| 491 | $numres = $xoopsDB->query($numdog); |
||
| 492 | list($numresults) = $xoopsDB->fetchRow($numres); |
||
| 493 | $numpages = (floor($numresults / $perp)) + 1; |
||
| 494 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
| 495 | $numpages = $numpages - 1; |
||
| 496 | } |
||
| 497 | $cpage = (floor($st / $perp)) + 1; |
||
| 498 | //create alphabet |
||
| 499 | $pages = ""; |
||
| 500 | View Code Duplication | for ($i = 65; $i <= 90; ++$i) { |
|
| 501 | if ($l == chr($i)) { |
||
| 502 | $pages .= "<b><a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a></b> "; |
||
| 503 | } else { |
||
| 504 | $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a> "; |
||
| 505 | } |
||
| 506 | } |
||
| 507 | $pages .= "- "; |
||
| 508 | $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ã…\">Ã…</a> "; |
||
| 509 | $pages .= "<a href=\"add_dog.php?f=dam&r=1&random=" . $random . "&l=Ö\">Ö</a> "; |
||
| 510 | $pages .= "<br />"; |
||
| 511 | //create previous button |
||
| 512 | if ($numpages > 1) { |
||
| 513 | if ($cpage > 1) { |
||
| 514 | $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
| 515 | } |
||
| 516 | } |
||
| 517 | //create numbers |
||
| 518 | for ($x = 1; $x < ($numpages + 1); ++$x) { |
||
| 519 | //create line break after 20 number |
||
| 520 | if (($x % 20) == 0) { |
||
| 521 | $pages .= "<br />"; |
||
| 522 | } |
||
| 523 | if ($x != $cpage) { |
||
| 524 | $pages .= "<a href=\"add_dog.php?f=dam&r=1&l=" . $l . "&random=" . $random . "&st=" . ($perp * ($x - 1)) . "\">" . $x . "</a> "; |
||
| 525 | } else { |
||
| 526 | $pages .= $x . "  "; |
||
| 527 | } |
||
| 528 | } |
||
| 529 | //create next button |
||
| 530 | if ($numpages > 1) { |
||
| 531 | if ($cpage < ($numpages)) { |
||
| 532 | $pages .= "<a href=\"add_dog.php?f=dam&l=" . $l . "&r=1&random=" . $random . "&st=" . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . "</a> "; |
||
| 533 | } |
||
| 534 | } |
||
| 535 | |||
| 536 | //query |
||
| 537 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft = '1' and NAAM LIKE '" . $l . "%' ORDER BY NAAM LIMIT " . $st . ", " . $perp; |
||
| 538 | $result = $xoopsDB->query($queryString); |
||
| 539 | |||
| 540 | $animal = new Animal(); |
||
| 541 | //test to find out how many user fields there are... |
||
| 542 | $fields = $animal->numoffields(); |
||
| 543 | $numofcolumns = 1; |
||
| 544 | $columns[] = array('columnname' => "Name"); |
||
| 545 | View Code Duplication | for ($i = 0; $i < count($fields); ++$i) { |
|
| 546 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 547 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 548 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 549 | //create empty string |
||
| 550 | $lookupvalues = ""; |
||
| 551 | if ($userfield->active() && $userfield->inlist()) { |
||
| 552 | if ($userfield->haslookup()) { |
||
| 553 | $lookupvalues = $userfield->lookup($fields[$i]); |
||
| 554 | //debug information |
||
| 555 | //print_r($lookupvalues); |
||
| 556 | } |
||
| 557 | $columns[] = array('columnname' => $fieldobject->fieldname, 'columnnumber' => $userfield->getID(), 'lookupval' => $lookupvalues); |
||
| 558 | ++$numofcolumns; |
||
| 559 | unset($lookupvalues); |
||
| 560 | } |
||
| 561 | } |
||
| 562 | |||
| 563 | View Code Duplication | for ($i = 1; $i < ($numofcolumns); ++$i) { |
|
| 564 | $empty[] = array('value' => ""); |
||
| 565 | } |
||
| 566 | $dogs [] = array( |
||
| 567 | 'id' => "0", |
||
| 568 | 'name' => "", |
||
| 569 | 'gender' => "", |
||
| 570 | 'link' => "<a href=\"add_dog.php?f=check&random=" . $random . "&seldam=0\">" . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, array('[mother]' => $moduleConfig['mother'])) . "</a>", |
||
| 571 | 'colour' => "", |
||
| 572 | 'number' => "", |
||
| 573 | 'usercolumns' => $empty |
||
| 574 | ); |
||
| 575 | |||
| 576 | View Code Duplication | while ($row = $xoopsDB->fetchArray($result)) { |
|
| 577 | //create picture information |
||
| 578 | if ($row['foto'] != '') { |
||
| 579 | $camera = " <img src=\"assets/images/camera.png\">"; |
||
| 580 | } else { |
||
| 581 | $camera = ""; |
||
| 582 | } |
||
| 583 | $name = stripslashes($row['NAAM']) . $camera; |
||
| 584 | //empty array |
||
| 585 | unset($columnvalue); |
||
| 586 | //fill array |
||
| 587 | for ($i = 1; $i < ($numofcolumns); ++$i) { |
||
| 588 | $x = $columns[$i]['columnnumber']; |
||
| 589 | if (is_array($columns[$i]['lookupval'])) { |
||
| 590 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 591 | if ($key == $row['user' . $x]) { |
||
| 592 | $value = $keyvalue['value']; |
||
| 593 | } |
||
| 594 | } |
||
| 595 | //debug information |
||
| 596 | ///echo $columns[$i]['columnname']."is an array !"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
77% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 597 | } //format value - cant use object because of query count |
||
| 598 | elseif (substr($row['user' . $x], 0, 7) == 'http://') { |
||
| 599 | $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . "</a>"; |
||
| 600 | } else { |
||
| 601 | $value = $row['user' . $x]; |
||
| 602 | } |
||
| 603 | $columnvalue[] = array('value' => $value); |
||
| 604 | } |
||
| 605 | $dogs[] = array( |
||
| 606 | 'id' => $row['ID'], |
||
| 607 | 'name' => $name, |
||
| 608 | 'gender' => '<img src="assets/images/female.gif">', |
||
| 609 | 'link' => "<a href=\"add_dog.php?f=check&random=" . $random . "&seldam=" . $row['ID'] . "\">" . $name . "</a>", |
||
| 610 | 'colour' => "", |
||
| 611 | 'number' => "", |
||
| 612 | 'usercolumns' => $columnvalue |
||
| 613 | ); |
||
| 614 | } |
||
| 615 | |||
| 616 | //add data to smarty template |
||
| 617 | //assign dog |
||
| 618 | $xoopsTpl->assign("dogs", $dogs); |
||
| 619 | $xoopsTpl->assign("columns", $columns); |
||
| 620 | $xoopsTpl->assign("numofcolumns", $numofcolumns); |
||
| 621 | $xoopsTpl->assign("tsarray", sorttable($numofcolumns)); |
||
| 622 | $xoopsTpl->assign("nummatch", strtr(_MA_PEDIGREE_ADD_SELDAM, array('[mother]' => $moduleConfig['mother']))); |
||
| 623 | $xoopsTpl->assign("pages", $pages); |
||
| 624 | } |
||
| 625 | |||
| 626 | function check() |
||
|
0 ignored issues
–
show
The function
check() has been defined more than once; this definition is ignored, only the first definition in add_breeder.php (L36-54) is considered.
This check looks for functions that have already been defined in other files. Some Codebases, like WordPress, make a practice of defining functions multiple times. This
may lead to problems with the detection of function parameters and types. If you really
need to do this, you can mark the duplicate definition with the /**
* @ignore
*/
function getUser() {
}
function getUser($id, $realm) {
}
See also the PhpDoc documentation for @ignore. Loading history...
|
|||
| 627 | { |
||
| 628 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 629 | |||
| 630 | //get module configuration |
||
| 631 | $module_handler =& xoops_gethandler('module'); |
||
| 632 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 633 | $config_handler =& xoops_gethandler('config'); |
||
| 634 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 635 | |||
| 636 | //check for access |
||
| 637 | $xoopsModule =& XoopsModule::getByDirname("pedigree"); |
||
| 638 | if (empty($xoopsUser)) { |
||
| 639 | redirect_header("index.php", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 640 | exit(); |
||
| 641 | } |
||
| 642 | if (empty($random)) { |
||
| 643 | $random = $_POST['random']; |
||
| 644 | } |
||
| 645 | if (isset($_GET['random'])) { |
||
| 646 | $random = $_GET['random']; |
||
| 647 | } |
||
| 648 | |||
| 649 | //query |
||
| 650 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_temp") . " WHERE ID = " . $random; |
||
| 651 | $result = $xoopsDB->query($queryString); |
||
| 652 | while ($row = $xoopsDB->fetchArray($result)) { |
||
| 653 | //create animal object |
||
| 654 | $animal = new Animal(); |
||
| 655 | //test to find out how many user fields there are.. |
||
| 656 | $fields = $animal->numoffields(); |
||
| 657 | sort($fields); |
||
| 658 | $usersql = ""; |
||
| 659 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 660 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 661 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 662 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 663 | if ($userfield->active()) { |
||
| 664 | $usersql .= ",'" . addslashes($row['user' . $fields[$i]]) . "'"; |
||
| 665 | } else { |
||
| 666 | $usersql .= ",'" . $fieldobject->defaultvalue . "'"; |
||
| 667 | } |
||
| 668 | //echo $fields[$i]."<br/>"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
78% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 669 | } |
||
| 670 | //insert into pedigree |
||
| 671 | $query |
||
| 672 | = "INSERT INTO " . $xoopsDB->prefix("pedigree_tree") . " VALUES ('','" . addslashes($row['NAAM']) . "','" . $row['id_owner'] . "','" . $row['id_breeder'] . "','" . $row['user'] . "','" |
||
| 673 | . $row['roft'] . "','" . $_GET['seldam'] . "','" . $row['father'] . "','" . addslashes($row['foto']) . "',''" . $usersql . ")"; |
||
| 674 | $xoopsDB->queryF($query); |
||
| 675 | //echo $query; die(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
78% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 676 | } |
||
| 677 | $sqlquery = "DELETE from " . $xoopsDB->prefix("pedigree_temp") . " where ID='" . $random . "'"; |
||
| 678 | $xoopsDB->queryF($sqlquery); |
||
| 679 | redirect_header("latest.php", 1, strtr(_MA_PEDIGREE_ADD_OK, array('[animalType]' => $moduleConfig['animalType']))); |
||
| 680 | } |
||
| 681 | |||
| 682 | //footer |
||
| 683 | include XOOPS_ROOT_PATH . "/footer.php"; |
||
| 684 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.