mambax7 /
pedigree
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | // ------------------------------------------------------------------------- |
||
| 3 | |||
| 4 | require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
||
| 5 | |||
| 6 | $moduleDirName = basename(__DIR__); |
||
| 7 | xoops_loadLanguage('main', $moduleDirName); |
||
| 8 | |||
| 9 | // Include any common code for this module. |
||
| 10 | require_once(XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php'); |
||
| 11 | require_once $GLOBALS['xoops']->path("modules/{$moduleDirName}/include/class_field.php"); |
||
| 12 | require_once $GLOBALS['xoops']->path("modules/{$moduleDirName}/class/animal.php"); |
||
| 13 | require_once __DIR__ . '/header.php'; |
||
| 14 | |||
| 15 | $xoopsOption['template_main'] = 'pedigree_result.tpl'; |
||
| 16 | |||
| 17 | include $GLOBALS['xoops']->path('/header.php'); |
||
| 18 | |||
| 19 | //get module configuration |
||
| 20 | $moduleHandler = xoops_getHandler('module'); |
||
| 21 | $module = $moduleHandler->getByDirname('pedigree'); |
||
| 22 | $configHandler = xoops_getHandler('config'); |
||
| 23 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 24 | |||
| 25 | $f = XoopsRequest::getCmd('f', 'NAAM', 'GET'); |
||
| 26 | $q = XoopsRequest::getString('query', '', 'POST'); |
||
| 27 | /* |
||
| 28 | if (!isset($_GET['f'])) { |
||
| 29 | $f = "NAAM"; |
||
| 30 | } else { |
||
| 31 | $f = $_GET['f']; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (isset($_POST['query'])) { |
||
| 35 | $q = $_POST['query']; |
||
| 36 | } else { |
||
| 37 | $q = ''; |
||
| 38 | } |
||
| 39 | */ |
||
| 40 | if ('' === $q < 1 && isset($_POST['query'])) { |
||
| 41 | redirect_header('index.php', 3, _MA_PEDIGREE_SEARCH_SHORT); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!isset($_GET['w'])) { |
||
| 45 | $w = '%' . $q . '%'; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (isset($_GET['p'])) { |
||
| 49 | $p = $_GET['p']; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (isset($p)) { |
||
| 53 | $w = $q; |
||
| 54 | } |
||
| 55 | |||
| 56 | if (isset($_GET['w'])) { |
||
| 57 | if ($_GET['w'] === 'zero' || $_GET['w'] === '' || $_GET['w'] === '0') { |
||
| 58 | $w = '0'; |
||
| 59 | } else { |
||
| 60 | $w = $_GET['w']; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | if (isset($_GET['l'])) { |
||
| 64 | if ($_GET['l'] == '1' || $_GET['l'] === 'LIKE') { |
||
| 65 | $l = 'LIKE'; |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | $l = '='; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!$_GET['o']) { |
||
| 72 | $o = 'NAAM'; |
||
| 73 | } else { |
||
| 74 | $o = $_GET['o']; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (!isset($_GET['d'])) { |
||
| 78 | $d = 'ASC'; |
||
| 79 | } else { |
||
| 80 | $d = $_GET['d']; |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!isset($_GET['st'])) { |
||
| 84 | $st = 0; |
||
| 85 | } else { |
||
| 86 | $st = $_GET['st']; |
||
| 87 | } |
||
| 88 | |||
| 89 | $perp = $moduleConfig['perpage']; |
||
| 90 | |||
| 91 | //is current user a module admin? |
||
| 92 | $modadmin = false; |
||
| 93 | $xoopsModule = XoopsModule::getByDirname('pedigree'); |
||
| 94 | View Code Duplication | if (!empty($GLOBALS['xoopsUser']) && ($GLOBALS['xoopsUser'] instanceof XoopsUser) && $GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) { |
|
| 95 | $modadmin = true; |
||
| 96 | } |
||
| 97 | |||
| 98 | //count total number of dogs |
||
| 99 | $numdog = 'SELECT COUNT(ID) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ' . $f . ' ' . $l . " '" . $w . "'"; |
||
| 100 | $numres = $GLOBALS['xoopsDB']->query($numdog); |
||
| 101 | //total number of dogs the query will find |
||
| 102 | list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres); |
||
| 103 | //if nothing is found |
||
| 104 | if (0 == $numresults) { |
||
| 105 | //just for debug information |
||
| 106 | //echo $numdog; |
||
| 107 | redirect_header('index.php', 15, strtr(_MA_PEDIGREE_SEARCH_NO, array('[animalTypes]' => $moduleConfig['animalTypes']))); |
||
| 108 | } |
||
| 109 | //total number of pages |
||
| 110 | $numpages = floor($numresults / $perp) + 1; |
||
| 111 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
| 112 | --$numpages; |
||
| 113 | } |
||
| 114 | //find current page |
||
| 115 | $cpage = floor($st / $perp) + 1; |
||
| 116 | //create empty pages variable |
||
| 117 | $pages = ''; |
||
| 118 | |||
| 119 | $length = strlen($w); |
||
| 120 | if (substr($w, $length - 1, $length) === '%') { |
||
| 121 | $whe = substr($w, 0, $length - 1) . '%25'; |
||
| 122 | if (0 === strpos($whe, '%')) { |
||
| 123 | $length = strlen($whe); |
||
| 124 | $whe = '%25' . substr($whe, 1, $length); |
||
| 125 | } |
||
| 126 | } else { |
||
| 127 | $whe = $w; |
||
| 128 | } |
||
| 129 | /* @todo: replace this with standard XOOPS Page Navigation */ |
||
| 130 | //create previous button |
||
| 131 | if ($numpages > 1) { |
||
| 132 | View Code Duplication | if ($cpage > 1) { |
|
| 133 | $pages .= "<a href=\"result.php?f=" . $f . '&l=' . $l . '&w=' . $whe . '&o=' . $o . '&d=' . $d . '&st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a> '; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | //create numbers |
||
| 137 | for ($x = 1; $x < ($numpages + 1); ++$x) { |
||
| 138 | //create line break after 20 number |
||
| 139 | if (($x % 20) == 0) { |
||
| 140 | $pages .= '<br />'; |
||
| 141 | } |
||
| 142 | if ($x != $cpage) { |
||
| 143 | $pages .= "<a href=\"result.php?f=" . $f . '&l=' . $l . '&w=' . $whe . '&o=' . $o . '&d=' . $d . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a> '; |
||
| 144 | } else { |
||
| 145 | $pages .= '<b>' . $x . '</b>  '; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | //create next button |
||
| 149 | if ($numpages > 1) { |
||
| 150 | if ($cpage < $numpages) { |
||
| 151 | $pages .= "<a href=\"result.php?f=" . $f . '&l=' . $l . '&w=' . $whe . '&o=' . $o . '&d=' . $d . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>  '; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | //query |
||
| 156 | $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE ' . $f . ' ' . $l . " '" . $w . "' ORDER BY " . $o . ' ' . $d . ' LIMIT ' . $st . ', ' . $perp; |
||
| 157 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
| 158 | |||
| 159 | $animal = new PedigreeAnimal(); |
||
| 160 | //test to find out how many user fields there are... |
||
| 161 | $fields = $animal->getNumOfFields(); |
||
| 162 | $fieldsCount = count($fields); |
||
| 163 | $numofcolumns = 1; |
||
| 164 | $columns = array(array('columnname' => 'Name')); |
||
| 165 | View Code Duplication | for ($i = 0; $i < $fieldsCount; ++$i) { |
|
| 166 | $userField = new Field($fields[$i], $animal->getConfig()); |
||
| 167 | $fieldType = $userField->getSetting('FieldType'); |
||
| 168 | $fieldObject = new $fieldType($userField, $animal); |
||
| 169 | //create empty string |
||
| 170 | if ($userField->isActive() && $userField->inList()) { |
||
| 171 | if ($userField->hasLookup()) { |
||
| 172 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
| 173 | } else { |
||
| 174 | $lookupvalues = ''; |
||
| 175 | } |
||
| 176 | /* print_r($lookupvalues); //debug information */ |
||
| 177 | $columns[] = array( |
||
| 178 | 'columnname' => $fieldObject->fieldname, |
||
| 179 | 'columnnumber' => $userField->getId(), |
||
| 180 | 'lookupval' => $lookupvalues |
||
| 181 | ); |
||
| 182 | ++$numofcolumns; |
||
| 183 | unset($lookupvalues); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $pathIcon16 = $GLOBALS['xoopsModule']->getInfo('icons16'); |
||
| 188 | |||
| 189 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 190 | //reset $gender |
||
| 191 | $gender = ''; |
||
| 192 | if ((!empty($GLOBALS['xoopsUser']) && ($GLOBALS['xoopsUser'] instanceof XoopsUser)) && (($row['user'] == $xoopsUser->getVar('uid')) || (true == $modadmin))) { |
||
|
0 ignored issues
–
show
|
|||
| 193 | $gender = "<a href='dog.php?id={$row['Id']}'><img src=" . $pathIcon16 . '/edit.png alt=' . _EDIT . "'></a> |
||
| 194 | . <a href='delete.php?id={$row['Id']}'><img src=" . $pathIcon16 . '/delete.png alt=' . _DELETE . "'></a>"; |
||
| 195 | } |
||
| 196 | if ($row['roft'] == 0) { |
||
| 197 | $gender .= "<img src='assets/images/male.gif'>"; |
||
| 198 | } else { |
||
| 199 | $gender .= "<img src='assets/images/female.gif'>"; |
||
| 200 | } |
||
| 201 | $camera = ('' != $row['foto']) ? " <img src='assets/images/dog-icon25.png'>" : ''; |
||
| 202 | $name = stripslashes($row['NAAM']) . $camera; |
||
| 203 | //empty array |
||
| 204 | unset($columnvalue); |
||
| 205 | //fill array |
||
| 206 | View Code Duplication | for ($i = 1; $i < $numofcolumns; ++$i) { |
|
| 207 | $x = 'user' . $columns[$i]['columnnumber']; |
||
| 208 | //echo $x."columnnumber"; |
||
| 209 | if (is_array($columns[$i]['lookupval'])) { |
||
| 210 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
| 211 | if ($keyvalue['id'] == $row[$x]) { |
||
| 212 | //echo "key:".$row['user5']."<br />"; |
||
| 213 | $value = $keyvalue['value']; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | //debug information |
||
| 217 | ///echo $columns[$i]['columnname']."is an array !"; |
||
| 218 | } //format value - cant use object because of query count |
||
| 219 | elseif (0 === strpos($row[$x], 'http://')) { |
||
| 220 | $value = "<a href='{$row[$x]}'>{$row[$x]}</a>"; |
||
| 221 | } else { |
||
| 222 | $value = $row[$x]; |
||
| 223 | } |
||
| 224 | if (isset($value)) { |
||
| 225 | $columnvalue[] = array('value' => $value); |
||
| 226 | unset($value); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | $animals[] = array( |
||
| 230 | 'id' => $row['Id'], |
||
| 231 | 'name' => $name, |
||
| 232 | 'gender' => $gender, |
||
| 233 | 'link' => "<a href='pedigree.php?pedid={$row['Id']}'>{$name}</a>", |
||
| 234 | 'colour' => '', |
||
| 235 | 'number' => '', |
||
| 236 | 'usercolumns' => isset($columnvalue) ? $columnvalue : 0 |
||
| 237 | ); |
||
| 238 | } |
||
| 239 | |||
| 240 | //add data to smarty template |
||
| 241 | //assign dog |
||
| 242 | $GLOBALS['xoopsTpl']->assign(array( |
||
| 243 | 'dogs' => $animals, |
||
| 244 | 'columns' => $columns, |
||
| 245 | 'numofcolumns' => $numofcolumns, |
||
| 246 | 'tsarray' => PedigreeUtilities::sortTable($numofcolumns) |
||
| 247 | )); |
||
| 248 | //assign links |
||
| 249 | |||
| 250 | //find last shown number |
||
| 251 | if (($st + $perp) > $numresults) { |
||
| 252 | $lastshown = $numresults; |
||
| 253 | } else { |
||
| 254 | $lastshown = $st + $perp; |
||
| 255 | } |
||
| 256 | //create string |
||
| 257 | $matches = strtr(_MA_PEDIGREE_MATCHES, array('[animalTypes]' => $moduleConfig['animalTypes'])); |
||
| 258 | $nummatchstr = "{$numresults}{$matches}" . ($st + 1) . " - {$lastshown} ({$numpages} pages)"; |
||
| 259 | $GLOBALS['xoopsTpl']->assign('nummatch', $nummatchstr); |
||
| 260 | $GLOBALS['xoopsTpl']->assign('pages', $pages); |
||
| 261 | |||
| 262 | //comments and footer |
||
| 263 | include $GLOBALS['xoops']->path('footer.php'); |
||
| 264 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.