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_addlitter.tpl"; |
||
| 21 | include XOOPS_ROOT_PATH . '/header.php'; |
||
| 22 | $xoopsTpl->assign('page_title', "Pedigree database - add a litter"); |
||
| 23 | |||
| 24 | //check for access |
||
| 25 | $xoopsModule =& XoopsModule::getByDirname("pedigree"); |
||
| 26 | if (empty($xoopsUser)) { |
||
| 27 | redirect_header("index.php", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 28 | exit(); |
||
| 29 | } |
||
| 30 | |||
| 31 | //get module configuration |
||
| 32 | $module_handler =& xoops_gethandler('module'); |
||
| 33 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 34 | $config_handler =& xoops_gethandler('config'); |
||
| 35 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 36 | |||
| 37 | if (!isset($_GET['f'])) { |
||
| 38 | addlitter(); |
||
| 39 | } else { |
||
| 40 | $f = $_GET['f']; |
||
| 41 | if ($f == "sire") { |
||
| 42 | sire(); |
||
| 43 | } |
||
| 44 | if ($f == "dam") { |
||
| 45 | dam(); |
||
| 46 | } |
||
| 47 | if ($f == "check") { |
||
| 48 | check(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | function addlitter() |
||
| 53 | { |
||
| 54 | global $xoopsTpl, $xoopsUser, $xoopsDB, $xoopsOption; |
||
| 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 | //create xoopsform |
||
| 63 | include XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; |
||
| 64 | $searchform = new XoopsThemeForm(strtr(_MA_PEDIGREE_ADD_LITTER, array('[litter]' => $moduleConfig['litter'])), "searchform", "add_litter.php?f=sire", "post"); |
||
| 65 | $searchform->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
| 66 | //create random value |
||
| 67 | $random = (rand() % 10000); |
||
| 68 | $searchform->addElement(new XoopsFormHidden('random', $random)); |
||
| 69 | //find userid |
||
| 70 | $searchform->addElement(new XoopsFormHidden('userid', $xoopsUser->getVar("uid"))); |
||
| 71 | //create animal object |
||
| 72 | $animal = new Animal(); |
||
| 73 | //test to find out how many user fields there are... |
||
| 74 | $fields = $animal->numoffields(); |
||
| 75 | |||
| 76 | //create form contents |
||
| 77 | for ($count = 1; $count < 11; ++$count) { |
||
| 78 | //name |
||
| 79 | $searchform->addElement(new XoopsFormLabel($count . ".", strtr(_MA_PEDIGREE_KITT_NAME . $count . ".", array('[animalType]' => $moduleConfig['animalType'])))); |
||
| 80 | $textbox[$count] = new XoopsFormText("<b>" . _MA_PEDIGREE_FLD_NAME . "</b>", 'name' . $count, $size = 50, $maxsize = 50, ''); |
||
| 81 | $searchform->addElement($textbox[$count]); |
||
| 82 | //gender |
||
| 83 | $gender_radio[$count] = new XoopsFormRadio("<b>" . _MA_PEDIGREE_FLD_GEND . "</b>", 'roft' . $count, $value = '0'); |
||
| 84 | $gender_radio[$count]->addOptionArray( |
||
| 85 | array('0' => strtr(_MA_PEDIGREE_FLD_MALE, array('[male]' => $moduleConfig['male'])), '1' => strtr(_MA_PEDIGREE_FLD_FEMA, array('[female]' => $moduleConfig['female']))) |
||
| 86 | ); |
||
| 87 | $searchform->addElement($gender_radio[$count]); |
||
| 88 | //add userfields |
||
| 89 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 90 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 91 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 92 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 93 | if ($userfield->active() && $userfield->getSetting("Litter") == "1" && !$userfield->isLocked()) { |
||
| 94 | $newentry[$count][$i] = $fieldobject->newField($count); |
||
| 95 | $searchform->addElement($newentry[$count][$i]); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | //add empty place holder as divider |
||
| 99 | $searchform->addElement(new XoopsFormLabel(" ", "")); |
||
| 100 | } |
||
| 101 | |||
| 102 | $searchform->addElement(new XoopsFormLabel(_MA_PEDIGREE_ADD_DATA, _MA_PEDIGREE_DATA_INFO . $moduleConfig['litter'] . ".</h2>")); |
||
| 103 | //add userfields that are not shown in the litter |
||
| 104 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 105 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 106 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 107 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 108 | if ($userfield->active() && $userfield->generallitter() && !$userfield->isLocked()) { |
||
| 109 | //add the "-" character to the beginning of the fieldname !!! |
||
| 110 | $newentry[$i] = $fieldobject->newField("-"); |
||
| 111 | $searchform->addElement($newentry[$i]); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | //add the breeder to the list for the entire litter |
||
| 115 | //no need to add the owner here because they will be different for each animal in the litter. |
||
| 116 | if ($moduleConfig['ownerbreeder'] == '1') { |
||
| 117 | //breeder |
||
| 118 | $breeder = new XoopsFormSelect(_MA_PEDIGREE_FLD_BREE, 'id_breeder', $value = '', $size = 1, $multiple = false); |
||
| 119 | $queryfok = "SELECT ID, firstname, lastname from " . $xoopsDB->prefix("pedigree_owner") . " order by `lastname`"; |
||
| 120 | $resfok = $xoopsDB->query($queryfok); |
||
| 121 | $breeder->addOption(0, $name = 'Unknown', $disabled = false); |
||
| 122 | while ($rowfok = $xoopsDB->fetchArray($resfok)) { |
||
| 123 | $breeder->addOption($rowfok['ID'], $name = $rowfok['lastname'] . ", " . $rowfok['firstname'], $disabled = false); |
||
| 124 | } |
||
| 125 | $searchform->addElement($breeder); |
||
| 126 | } |
||
| 127 | |||
| 128 | //submit button |
||
| 129 | $searchform->addElement(new XoopsFormButton('', 'submit', strtr(_MA_PEDIGREE_ADD_SIRE, array('[father]' => $moduleConfig['father'])), 'submit')); |
||
| 130 | //send to template |
||
| 131 | $searchform->assign($xoopsTpl); |
||
| 132 | |||
| 133 | } |
||
| 134 | |||
| 135 | function sire() |
||
|
0 ignored issues
–
show
The function
sire() has been defined more than once; this definition is ignored, only the first definition in add_dog.php (L202-441) 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...
|
|||
| 136 | { |
||
| 137 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 138 | //debug option ! |
||
| 139 | //print_r($_POST); die(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% 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...
|
|||
| 140 | //get module configuration |
||
| 141 | $module_handler =& xoops_gethandler('module'); |
||
| 142 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 143 | $config_handler =& xoops_gethandler('config'); |
||
| 144 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 145 | |||
| 146 | //check for access |
||
| 147 | $xoopsModule =& XoopsModule::getByDirname("pedigree"); |
||
| 148 | if (empty($xoopsUser)) { |
||
| 149 | redirect_header("javascript:history.go(-1)", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST); |
||
| 150 | exit(); |
||
| 151 | } |
||
| 152 | $userid = $_POST['userid']; |
||
| 153 | if (empty($random)) { |
||
| 154 | $random = $_POST['random']; |
||
| 155 | } |
||
| 156 | if (isset($_GET['random'])) { |
||
| 157 | $random = $_GET['random']; |
||
| 158 | } |
||
| 159 | if (empty($st)) { |
||
| 160 | $st = 0; |
||
| 161 | } |
||
| 162 | if (isset($_GET['st'])) { |
||
| 163 | $st = $_GET['st']; |
||
| 164 | } |
||
| 165 | $userfields = ""; |
||
| 166 | for ($count = 1; $count < 11; ++$count) { |
||
| 167 | $namelitter = "name" . $count; |
||
| 168 | $roftlitter = "roft" . $count; |
||
| 169 | //check for an empty name |
||
| 170 | if ($_POST[$namelitter] !== "") { |
||
| 171 | $name .= ":" . $_POST[$namelitter]; |
||
| 172 | $roft .= ":" . $_POST[$roftlitter]; |
||
| 173 | } else { |
||
| 174 | if ($count == "1") { |
||
| 175 | redirect_header("add_litter.php", 3, _MA_PEDIGREE_ADD_NAMEPLZ); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | if (isset($_POST['id_breeder'])) { |
||
| 180 | $id_breeder = $_POST['id_breeder']; |
||
| 181 | } else { |
||
| 182 | $id_breeder = "0"; |
||
| 183 | } |
||
| 184 | |||
| 185 | //make the redirect |
||
| 186 | if (!isset($_GET['r'])) { |
||
| 187 | //create animal object |
||
| 188 | $animal = new Animal(); |
||
| 189 | //test to find out how many user fields there are.. |
||
| 190 | $fields = $animal->numoffields(); |
||
| 191 | sort($fields); |
||
| 192 | $usersql = ""; |
||
| 193 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 194 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 195 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 196 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 197 | $defvalue = $fieldobject->defaultvalue; |
||
| 198 | //emtpy string to house the different values for this userfield |
||
| 199 | $withinfield = ""; |
||
| 200 | for ($count = 1; $count < 11; ++$count) { |
||
| 201 | if ($_POST['name' . $count] !== "") { |
||
| 202 | if (isset($_POST[$count . 'user' . $fields[$i]])) { |
||
| 203 | //debug option |
||
| 204 | //echo $count.'user'.$fields[$i]."=".$_POST[$count.'user'.$fields[$i]]."<br />"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
71% 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...
|
|||
| 205 | $withinfield .= ":" . $_POST[$count . 'user' . $fields[$i]]; |
||
| 206 | } else { |
||
| 207 | if ($userfield->active() && $userfield->generallitter() && !$userfield->isLocked()) { |
||
| 208 | //use $_POST value if this is a general litter field |
||
| 209 | $withinfield .= ":" . $_POST['-user' . $fields[$i]]; |
||
| 210 | } else { |
||
| 211 | //create $withinfield for fields not added to the litter |
||
| 212 | $withinfield .= ":" . $defvalue; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | //debug option |
||
| 218 | //echo "user".$fields[$i]." - ".$withinfield."<br />"; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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...
|
|||
| 219 | $user{$fields[$i]} = $withinfield; |
||
| 220 | } |
||
| 221 | //insert into pedigree_temp |
||
| 222 | $query = "INSERT INTO " . $xoopsDB->prefix("pedigree_temp") . " VALUES ('" . $random . "','" . unhtmlentities($name) . "','0','" . $id_breeder . "','" . $userid . "','" . $roft . "','','','', ''"; |
||
| 223 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 224 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 225 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 226 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 227 | //do we only need to create a query for active fields ? |
||
| 228 | $query .= ",'" . $user{$fields[$i]} . "'"; |
||
| 229 | } |
||
| 230 | $query .= ")"; |
||
| 231 | //debug options |
||
| 232 | //echo $query."<br />"; die(); |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% 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...
|
|||
| 233 | $xoopsDB->query($query); |
||
| 234 | redirect_header("add_litter.php?f=sire&random=" . $random . "&st=" . $st . "&r=1&l=a", 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, array('[father]' => $moduleConfig['father']))); |
||
| 235 | } |
||
| 236 | //find letter on which to start else set to 'a' |
||
| 237 | if (isset($_GET['l'])) { |
||
| 238 | $l = $_GET['l']; |
||
| 239 | } else { |
||
| 240 | $l = "a"; |
||
| 241 | } |
||
| 242 | //assign 'sire' to the template |
||
| 243 | $xoopsTpl->assign("sire", "1"); |
||
| 244 | //create list of males dog to select from |
||
| 245 | $perp = $moduleConfig['perpage']; |
||
| 246 | //count total number of dogs |
||
| 247 | $numdog = "SELECT ID from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft='0' and NAAM LIKE '" . $l . "%'"; |
||
| 248 | $numres = $xoopsDB->query($numdog); |
||
| 249 | //total number of dogs the query will find |
||
| 250 | $numresults = $xoopsDB->getRowsNum($numres); |
||
| 251 | //total number of pages |
||
| 252 | $numpages = (floor($numresults / $perp)) + 1; |
||
| 253 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
| 254 | $numpages = $numpages - 1; |
||
| 255 | } |
||
| 256 | //find current page |
||
| 257 | $cpage = (floor($st / $perp)) + 1; |
||
| 258 | //create alphabet |
||
| 259 | $pages = ""; |
||
| 260 | View Code Duplication | for ($i = 65; $i <= 90; ++$i) { |
|
| 261 | if ($l == chr($i)) { |
||
| 262 | $pages .= "<b><a href=\"add_litter.php?f=sire&r=1&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a></b> "; |
||
| 263 | } else { |
||
| 264 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a> "; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | $pages .= "- "; |
||
| 268 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&random=" . $random . "&l=Ã…\">Ã…</a> "; |
||
| 269 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&random=" . $random . "&l=Ö\">Ö</a> "; |
||
| 270 | //create linebreak |
||
| 271 | $pages .= "<br />"; |
||
| 272 | //create previous button |
||
| 273 | if ($numpages > 1) { |
||
| 274 | if ($cpage > 1) { |
||
| 275 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
| 276 | } |
||
| 277 | } |
||
| 278 | //create numbers |
||
| 279 | for ($x = 1; $x < ($numpages + 1); ++$x) { |
||
| 280 | //create line break after 20 number |
||
| 281 | if (($x % 20) == 0) { |
||
| 282 | $pages .= "<br />"; |
||
| 283 | } |
||
| 284 | if ($x != $cpage) { |
||
| 285 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($perp * ($x - 1)) . "\">" . $x . "</a> "; |
||
| 286 | } else { |
||
| 287 | $pages .= $x . "  "; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | //create next button |
||
| 291 | if ($numpages > 1) { |
||
| 292 | if ($cpage < ($numpages)) { |
||
| 293 | $pages .= "<a href=\"add_litter.php?f=sire&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . "</a>  "; |
||
| 294 | } |
||
| 295 | } |
||
| 296 | //query |
||
| 297 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft = '0' and NAAM LIKE '" . $l . "%' ORDER BY NAAM LIMIT " . $st . ", " . $perp; |
||
| 298 | $result = $xoopsDB->query($queryString); |
||
| 299 | |||
| 300 | $animal = new Animal(); |
||
| 301 | //test to find out how many user fields there are... |
||
| 302 | $fields = $animal->numoffields(); |
||
| 303 | $numofcolumns = 1; |
||
| 304 | $columns[] = array('columnname' => "Name"); |
||
| 305 | View Code Duplication | for ($i = 0; $i < count($fields); ++$i) { |
|
| 306 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 307 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 308 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 309 | //create empty string |
||
| 310 | $lookupvalues = ""; |
||
| 311 | if ($userfield->active() && $userfield->inlist()) { |
||
| 312 | if ($userfield->haslookup()) { |
||
| 313 | $lookupvalues = $userfield->lookup($fields[$i]); |
||
| 314 | //debug information |
||
| 315 | //print_r($lookupvalues); |
||
| 316 | } |
||
| 317 | $columns[] = array('columnname' => $fieldobject->fieldname, 'columnnumber' => $userfield->getID(), 'lookupval' => $lookupvalues); |
||
| 318 | ++$numofcolumns; |
||
| 319 | unset($lookupvalues); |
||
| 320 | } |
||
| 321 | } |
||
| 322 | |||
| 323 | View Code Duplication | for ($i = 1; $i < ($numofcolumns); ++$i) { |
|
| 324 | $empty[] = array('value' => ""); |
||
| 325 | } |
||
| 326 | $dogs [] = array( |
||
| 327 | 'id' => "0", |
||
| 328 | 'name' => "", |
||
| 329 | 'gender' => "", |
||
| 330 | 'link' => "<a href=\"add_litter.php?f=dam&random=" . $random . "&selsire=0\">" . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, array('[father]' => $moduleConfig['father'])) . "</a>", |
||
| 331 | 'colour' => "", |
||
| 332 | 'number' => "", |
||
| 333 | 'usercolumns' => $empty |
||
| 334 | ); |
||
| 335 | |||
| 336 | View Code Duplication | while ($row = $xoopsDB->fetchArray($result)) { |
|
| 337 | //create picture information |
||
| 338 | if ($row['foto'] != '') { |
||
| 339 | $camera = " <img src=\"assets/images/camera.png\">"; |
||
| 340 | } else { |
||
| 341 | $camera = ""; |
||
| 342 | } |
||
| 343 | $name = stripslashes($row['NAAM']) . $camera; |
||
| 344 | //empty array |
||
| 345 | unset($columnvalue); |
||
| 346 | //fill array |
||
| 347 | for ($i = 1; $i < ($numofcolumns); ++$i) { |
||
| 348 | $x = $columns[$i]['columnnumber']; |
||
| 349 | if (is_array($columns[$i]['lookupval'])) { |
||
| 350 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 351 | if ($key == $row['user' . $x]) { |
||
| 352 | $value = $keyvalue['value']; |
||
| 353 | } |
||
| 354 | } |
||
| 355 | //debug information |
||
| 356 | ///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...
|
|||
| 357 | } //format value - cant use object because of query count |
||
| 358 | elseif (substr($row['user' . $x], 0, 7) == 'http://') { |
||
| 359 | $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . "</a>"; |
||
| 360 | } else { |
||
| 361 | $value = $row['user' . $x]; |
||
| 362 | } |
||
| 363 | $columnvalue[] = array('value' => $value); |
||
| 364 | } |
||
| 365 | $dogs[] = array( |
||
| 366 | 'id' => $row['ID'], |
||
| 367 | 'name' => $name, |
||
| 368 | 'gender' => '<img src="assets/images/male.gif">', |
||
| 369 | 'link' => "<a href=\"add_litter.php?f=dam&random=" . $random . "&selsire=" . $row['ID'] . "\">" . $name . "</a>", |
||
| 370 | 'colour' => "", |
||
| 371 | 'number' => "", |
||
| 372 | 'usercolumns' => $columnvalue |
||
| 373 | ); |
||
| 374 | } |
||
| 375 | |||
| 376 | //add data to smarty template |
||
| 377 | //assign dog |
||
| 378 | $xoopsTpl->assign("dogs", $dogs); |
||
| 379 | $xoopsTpl->assign("columns", $columns); |
||
| 380 | $xoopsTpl->assign("numofcolumns", $numofcolumns); |
||
| 381 | $xoopsTpl->assign("tsarray", sorttable($numofcolumns)); |
||
| 382 | $xoopsTpl->assign("nummatch", strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $moduleConfig['father']))); |
||
| 383 | $xoopsTpl->assign("pages", $pages); |
||
| 384 | } |
||
| 385 | |||
| 386 | function dam() |
||
|
0 ignored issues
–
show
The function
dam() has been defined more than once; this definition is ignored, only the first definition in add_dog.php (L443-624) 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...
|
|||
| 387 | { |
||
| 388 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 389 | |||
| 390 | //get module configuration |
||
| 391 | $module_handler =& xoops_gethandler('module'); |
||
| 392 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 393 | $config_handler =& xoops_gethandler('config'); |
||
| 394 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 395 | |||
| 396 | if (empty($random)) { |
||
| 397 | $random = $_POST['random']; |
||
| 398 | } |
||
| 399 | if (isset($_GET['random'])) { |
||
| 400 | $random = $_GET['random']; |
||
| 401 | } |
||
| 402 | if (empty($st)) { |
||
| 403 | $st = 0; |
||
| 404 | } |
||
| 405 | if (isset($_GET['st'])) { |
||
| 406 | $st = $_GET['st']; |
||
| 407 | } |
||
| 408 | //make the redirect |
||
| 409 | View Code Duplication | if (!isset($_GET['r'])) { |
|
| 410 | //insert into pedigree_temp |
||
| 411 | $query = "UPDATE " . $xoopsDB->prefix("pedigree_temp") . " SET father =" . $_GET['selsire'] . " WHERE ID=" . $random; |
||
| 412 | $xoopsDB->queryf($query); |
||
| 413 | redirect_header("add_litter.php?f=dam&random=" . $random . "&st=" . $st . "&r=1", 1, strtr(_MA_PEDIGREE_ADD_SIREOK, array('[mother]' => $moduleConfig['mother']))); |
||
| 414 | } |
||
| 415 | //find letter on which to start else set to 'a' |
||
| 416 | if (isset($_GET['l'])) { |
||
| 417 | $l = $_GET['l']; |
||
| 418 | } else { |
||
| 419 | $l = "a"; |
||
| 420 | } |
||
| 421 | //assign sire to the template |
||
| 422 | $xoopsTpl->assign("sire", "1"); |
||
| 423 | //create list of males dog to select from |
||
| 424 | $perp = $moduleConfig['perpage']; |
||
| 425 | //count total number of dogs |
||
| 426 | $numdog = "SELECT ID from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft='1' and NAAM LIKE '" . $l . "%'"; |
||
| 427 | $numres = $xoopsDB->query($numdog); |
||
| 428 | //total number of dogs the query will find |
||
| 429 | $numresults = $xoopsDB->getRowsNum($numres); |
||
| 430 | //total number of pages |
||
| 431 | $numpages = (floor($numresults / $perp)) + 1; |
||
| 432 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
| 433 | $numpages = $numpages - 1; |
||
| 434 | } |
||
| 435 | //find current page |
||
| 436 | $cpage = (floor($st / $perp)) + 1; |
||
| 437 | //create alphabet |
||
| 438 | $pages = ""; |
||
| 439 | View Code Duplication | for ($i = 65; $i <= 90; ++$i) { |
|
| 440 | if ($l == chr($i)) { |
||
| 441 | $pages .= "<b><a href=\"add_litter.php?f=dam&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a></b> "; |
||
| 442 | } else { |
||
| 443 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&random=" . $random . "&l=" . chr($i) . "\">" . chr($i) . "</a> "; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | $pages .= "- "; |
||
| 447 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&random=" . $random . "&l=Ã…\">Ã…</a> "; |
||
| 448 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&random=" . $random . "&l=Ö\">Ö</a> "; |
||
| 449 | //create linebreak |
||
| 450 | $pages .= "<br />"; |
||
| 451 | //create previous button |
||
| 452 | if ($numpages > 1) { |
||
| 453 | if ($cpage > 1) { |
||
| 454 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
| 455 | } |
||
| 456 | } |
||
| 457 | //create numbers |
||
| 458 | for ($x = 1; $x < ($numpages + 1); ++$x) { |
||
| 459 | //create line break after 20 number |
||
| 460 | if (($x % 20) == 0) { |
||
| 461 | $pages .= "<br />"; |
||
| 462 | } |
||
| 463 | if ($x != $cpage) { |
||
| 464 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&l=" . $l . "&random=" . $random . "&st=" . ($perp * ($x - 1)) . "\">" . $x . "</a> "; |
||
| 465 | } else { |
||
| 466 | $pages .= $x . "  "; |
||
| 467 | } |
||
| 468 | } |
||
| 469 | //create next button |
||
| 470 | if ($numpages > 1) { |
||
| 471 | if ($cpage < ($numpages)) { |
||
| 472 | $pages .= "<a href=\"add_litter.php?f=dam&r=1&l=" . $l . "&random=" . $random . "&st=" . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . "</a>  "; |
||
| 473 | } |
||
| 474 | } |
||
| 475 | //query |
||
| 476 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_tree") . " WHERE roft = '1' and NAAM LIKE '" . $l . "%' ORDER BY NAAM LIMIT " . $st . ", " . $perp; |
||
| 477 | $result = $xoopsDB->query($queryString); |
||
| 478 | |||
| 479 | $animal = new Animal(); |
||
| 480 | //test to find out how many user fields there are... |
||
| 481 | $fields = $animal->numoffields(); |
||
| 482 | $numofcolumns = 1; |
||
| 483 | $columns[] = array('columnname' => "Name"); |
||
| 484 | View Code Duplication | for ($i = 0; $i < count($fields); ++$i) { |
|
| 485 | $userfield = new Field($fields[$i], $animal->getconfig()); |
||
| 486 | $fieldType = $userfield->getSetting("FieldType"); |
||
| 487 | $fieldobject = new $fieldType($userfield, $animal); |
||
| 488 | //create empty string |
||
| 489 | $lookupvalues = ""; |
||
| 490 | if ($userfield->active() && $userfield->inlist()) { |
||
| 491 | if ($userfield->haslookup()) { |
||
| 492 | $lookupvalues = $userfield->lookup($fields[$i]); |
||
| 493 | //debug information |
||
| 494 | //print_r($lookupvalues); |
||
| 495 | } |
||
| 496 | $columns[] = array('columnname' => $fieldobject->fieldname, 'columnnumber' => $userfield->getID(), 'lookupval' => $lookupvalues); |
||
| 497 | ++$numofcolumns; |
||
| 498 | unset($lookupvalues); |
||
| 499 | } |
||
| 500 | } |
||
| 501 | |||
| 502 | View Code Duplication | for ($i = 1; $i < ($numofcolumns); ++$i) { |
|
| 503 | $empty[] = array('value' => ""); |
||
| 504 | } |
||
| 505 | $dogs [] = array( |
||
| 506 | 'id' => "0", |
||
| 507 | 'name' => "", |
||
| 508 | 'gender' => "", |
||
| 509 | 'link' => "<a href=\"add_litter.php?f=check&random=" . $random . "&seldam=0\">" . strtr(_MA_PEDIGREE_ADD_DAMUNKNOWN, array('[mother]' => $moduleConfig['mother'])) . "</a>", |
||
| 510 | 'colour' => "", |
||
| 511 | 'number' => "", |
||
| 512 | 'usercolumns' => $empty |
||
| 513 | ); |
||
| 514 | |||
| 515 | View Code Duplication | while ($row = $xoopsDB->fetchArray($result)) { |
|
| 516 | //create picture information |
||
| 517 | if ($row['foto'] != '') { |
||
| 518 | $camera = " <img src=\"assets/images/camera.png\">"; |
||
| 519 | } else { |
||
| 520 | $camera = ""; |
||
| 521 | } |
||
| 522 | $name = stripslashes($row['NAAM']) . $camera; |
||
| 523 | //empty array |
||
| 524 | unset($columnvalue); |
||
| 525 | //fill array |
||
| 526 | for ($i = 1; $i < ($numofcolumns); ++$i) { |
||
| 527 | $x = $columns[$i]['columnnumber']; |
||
| 528 | if (is_array($columns[$i]['lookupval'])) { |
||
| 529 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 530 | if ($key == $row['user' . $x]) { |
||
| 531 | $value = $keyvalue['value']; |
||
| 532 | } |
||
| 533 | } |
||
| 534 | //debug information |
||
| 535 | ///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...
|
|||
| 536 | } //format value - cant use object because of query count |
||
| 537 | elseif (substr($row['user' . $x], 0, 7) == 'http://') { |
||
| 538 | $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . "</a>"; |
||
| 539 | } else { |
||
| 540 | $value = $row['user' . $x]; |
||
| 541 | } |
||
| 542 | $columnvalue[] = array('value' => $value); |
||
| 543 | } |
||
| 544 | $dogs[] = array( |
||
| 545 | 'id' => $row['ID'], |
||
| 546 | 'name' => $name, |
||
| 547 | 'gender' => '<img src="assets/images/female.gif">', |
||
| 548 | 'link' => "<a href=\"add_litter.php?f=check&random=" . $random . "&seldam=" . $row['ID'] . "\">" . $name . "</a>", |
||
| 549 | 'colour' => "", |
||
| 550 | 'number' => "", |
||
| 551 | 'usercolumns' => $columnvalue |
||
| 552 | ); |
||
| 553 | } |
||
| 554 | |||
| 555 | //add data to smarty template |
||
| 556 | //assign dog |
||
| 557 | $xoopsTpl->assign("dogs", $dogs); |
||
| 558 | $xoopsTpl->assign("columns", $columns); |
||
| 559 | $xoopsTpl->assign("numofcolumns", $numofcolumns); |
||
| 560 | $xoopsTpl->assign("tsarray", sorttable($numofcolumns)); |
||
| 561 | $xoopsTpl->assign("nummatch", strtr(_MA_PEDIGREE_ADD_SELDAM, array('[mother]' => $moduleConfig['mother']))); |
||
| 562 | $xoopsTpl->assign("pages", $pages); |
||
| 563 | } |
||
| 564 | |||
| 565 | 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...
|
|||
| 566 | { |
||
| 567 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
| 568 | |||
| 569 | //get module configuration |
||
| 570 | $module_handler =& xoops_gethandler('module'); |
||
| 571 | $module =& $module_handler->getByDirname("pedigree"); |
||
| 572 | $config_handler =& xoops_gethandler('config'); |
||
| 573 | $moduleConfig =& $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 574 | |||
| 575 | if (empty($random)) { |
||
| 576 | $random = $_POST['random']; |
||
| 577 | } |
||
| 578 | if (isset($_GET['random'])) { |
||
| 579 | $random = $_GET['random']; |
||
| 580 | } |
||
| 581 | //query |
||
| 582 | $queryString = "SELECT * from " . $xoopsDB->prefix("pedigree_temp") . " WHERE ID = " . $random; |
||
| 583 | $result = $xoopsDB->query($queryString); |
||
| 584 | while ($row = $xoopsDB->fetchArray($result)) { |
||
| 585 | //pull data apart. |
||
| 586 | if ($row['NAAM'] !== "") { |
||
| 587 | $genders = explode(":", $row['roft']); |
||
| 588 | $names = explode(":", $row['NAAM']); |
||
| 589 | for ($c = 1; $c < count($names); ++$c) { |
||
| 590 | $query |
||
| 591 | = |
||
| 592 | "INSERT INTO " . $xoopsDB->prefix("pedigree_tree") . " VALUES ('','" . addslashes($names[$c]) . "','0','" . $row['id_breeder'] . "','" . $row['user'] . "','" . $genders[$c] . "','" |
||
| 593 | . $_GET['seldam'] . "','" . $row['father'] . "','',''"; |
||
| 594 | //create animal object |
||
| 595 | $animal = new Animal(); |
||
| 596 | //test to find out how many user fields there are.. |
||
| 597 | $fields = $animal->numoffields(); |
||
| 598 | sort($fields); |
||
| 599 | $usersql = ""; |
||
| 600 | for ($i = 0; $i < count($fields); ++$i) { |
||
| 601 | $userfields{$fields[$i]} = explode(":", $row['user' . $fields[$i]]); |
||
| 602 | $query .= ",'" . $userfields{$fields[$i]}[$c] . "'"; |
||
| 603 | } |
||
| 604 | //insert into pedigree |
||
| 605 | $query .= ");"; |
||
| 606 | $xoopsDB->queryf($query); |
||
| 607 | } |
||
| 608 | |||
| 609 | } |
||
| 610 | $sqlquery = "DELETE from " . $xoopsDB->prefix("pedigree_temp") . " where ID='" . $random . "'"; |
||
| 611 | } |
||
| 612 | redirect_header("latest.php", 1, strtr(_MA_PEDIGREE_ADD_LIT_OK, array('[animalTypes]' => $moduleConfig['animalTypes']))); |
||
| 613 | } |
||
| 614 | |||
| 615 | //footer |
||
| 616 | include XOOPS_ROOT_PATH . "/footer.php"; |
||
| 617 |
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.