1 | <?php |
||||
2 | // ------------------------------------------------------------------------- |
||||
3 | |||||
4 | use XoopsModules\Pedigree; |
||||
5 | |||||
6 | //require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
||||
7 | require_once __DIR__ . '/header.php'; |
||||
8 | $moduleDirName = basename(__DIR__); |
||||
9 | xoops_loadLanguage('main', $moduleDirName); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
10 | // Include any common code for this module. |
||||
11 | |||||
12 | // Get all HTTP post or get parameters into global variables that are prefixed with "param_" |
||||
13 | //import_request_variables("gp", "param_"); |
||||
14 | extract($_GET, EXTR_PREFIX_ALL, 'param'); |
||||
15 | extract($_POST, EXTR_PREFIX_ALL, 'param'); |
||||
16 | |||||
17 | $GLOBALS['xoopsOption']['template_main'] = 'pedigree_breeder.tpl'; |
||||
18 | |||||
19 | include XOOPS_ROOT_PATH . '/header.php'; |
||||
0 ignored issues
–
show
|
|||||
20 | // Include any common code for this module. |
||||
21 | require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php'; |
||||
22 | $xoopsTpl->assign('page_title', 'Pedigree database - View owner/breeder'); |
||||
23 | |||||
24 | // Breadcrumb |
||||
25 | $breadcrumb = new Pedigree\Breadcrumb(); |
||||
26 | $breadcrumb->addLink($helper->getModule()->getVar('name'), PEDIGREE_URL); |
||||
27 | $GLOBALS['xoopsTpl']->assign('module_home', Pedigree\Utility::getModuleName(false)); // this definition is not removed for backward compatibility issues |
||||
28 | $GLOBALS['xoopsTpl']->assign('pedigree_breadcrumb', $breadcrumb->render()); |
||||
29 | |||||
30 | //get module configuration |
||||
31 | /** @var XoopsModuleHandler $moduleHandler */ |
||||
32 | $moduleHandler = xoops_getHandler('module'); |
||||
0 ignored issues
–
show
The function
xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
33 | $module = $moduleHandler->getByDirname($moduleDirName); |
||||
34 | $configHandler = xoops_getHandler('config'); |
||||
35 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||||
36 | |||||
37 | if (!isset($f)) { |
||||
38 | $f = 'lastname'; |
||||
39 | } |
||||
40 | //find letter on which to start else set to 'a' |
||||
41 | if (isset($_GET['l'])) { |
||||
42 | $l = $_GET['l']; |
||||
43 | } else { |
||||
44 | $l = 'a'; |
||||
45 | } |
||||
46 | $w = $l . '%'; |
||||
47 | if (1 == $l) { |
||||
48 | $l = 'LIKE'; |
||||
49 | } |
||||
50 | if (!isset($o)) { |
||||
51 | $o = 'lastname'; |
||||
52 | } |
||||
53 | if (!isset($d)) { |
||||
54 | $d = 'ASC'; |
||||
55 | } |
||||
56 | if (!isset($st)) { |
||||
57 | $st = 0; |
||||
58 | } |
||||
59 | |||||
60 | $perPage = $moduleConfig['perpage']; |
||||
61 | |||||
62 | global $xoopsTpl; |
||||
63 | global $xoopsDB; |
||||
64 | global $xoopsModuleConfig; |
||||
65 | |||||
66 | //iscurrent user a module admin ? |
||||
67 | $modadmin = false; |
||||
68 | $xoopsModule = XoopsModule::getByDirname($moduleDirName); |
||||
69 | if (!empty($xoopsUser)) { |
||||
70 | if ($xoopsUser->isAdmin($xoopsModule->mid())) { |
||||
71 | $modadmin = true; |
||||
72 | } |
||||
73 | } |
||||
74 | |||||
75 | //count total number of owners |
||||
76 | $numowner = 'SELECT count(id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' WHERE ' . $f . " LIKE '" . $w . "'"; |
||||
77 | $numRes = $GLOBALS['xoopsDB']->query($numowner); |
||||
78 | //total number of owners the query will find |
||||
79 | list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes); |
||||
80 | //total number of pages |
||||
81 | $numPages = floor($numResults / $perPage) + 1; |
||||
82 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||||
83 | ++$numPages; |
||||
84 | } |
||||
85 | //find current page |
||||
86 | $currentPage = floor($st / $perPage) + 1; |
||||
87 | //create alphabet |
||||
88 | $pages = ''; |
||||
89 | /* |
||||
90 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=a\">A</a> "; |
||||
91 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=b\">B</a> "; |
||||
92 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=c\">C</a> "; |
||||
93 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=d\">D</a> "; |
||||
94 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=e\">E</a> "; |
||||
95 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=f\">F</a> "; |
||||
96 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=g\">G</a> "; |
||||
97 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=h\">H</a> "; |
||||
98 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=i\">I</a> "; |
||||
99 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=j\">J</a> "; |
||||
100 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=k\">K</a> "; |
||||
101 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=l\">L</a> "; |
||||
102 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=m\">M</a> "; |
||||
103 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=n\">N</a> "; |
||||
104 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=o\">O</a> "; |
||||
105 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=p\">P</a> "; |
||||
106 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=q\">Q</a> "; |
||||
107 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=r\">R</a> "; |
||||
108 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=s\">S</a> "; |
||||
109 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=t\">T</a> "; |
||||
110 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=u\">U</a> "; |
||||
111 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=v\">V</a> "; |
||||
112 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=w\">W</a> "; |
||||
113 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=x\">X</a> "; |
||||
114 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=y\">Y</a> "; |
||||
115 | $pages .= "<a href=\"breeder.php?f=" . $f . '&o=' . $o . '&d=' . $d . "&st=0&l=z\">Z</a> "; |
||||
116 | //create linebreak |
||||
117 | $pages .= '<br>'; |
||||
118 | */ |
||||
119 | //create previous button |
||||
120 | if ($numPages > 1) { |
||||
121 | if ($currentPage > 1) { |
||||
122 | $pages .= '<a href="breeder.php?f=' . $f . '&o=' . $o . '&d=' . $d . '&l=' . $l . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a> '; |
||||
123 | } |
||||
124 | |||||
125 | //create numbers |
||||
126 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||||
127 | //create line break after 20 number |
||||
128 | if (0 == ($x % 20)) { |
||||
129 | $pages .= '<br>'; |
||||
130 | } |
||||
131 | if ($x != $currentPage) { |
||||
132 | $pages .= '<a href="breeder.php?f=' . $f . '&o=' . $o . '&d=' . $d . '&l=' . $l . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a> '; |
||||
133 | } else { |
||||
134 | $pages .= $x . '  '; |
||||
135 | } |
||||
136 | } |
||||
137 | } |
||||
138 | |||||
139 | //create next button |
||||
140 | if ($numPages > 1) { |
||||
141 | if ($currentPage < $numPages) { |
||||
142 | $pages .= '<a href="breeder.php?f=' . $f . '&o=' . $o . '&d=' . $d . '&l=' . $l . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a> '; |
||||
143 | } |
||||
144 | } |
||||
145 | |||||
146 | //query |
||||
147 | $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' WHERE ' . $f . " LIKE '" . $w . "' ORDER BY " . $o . ' ' . $d . ' LIMIT ' . $st . ', ' . $perPage; |
||||
148 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||||
149 | |||||
150 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||
151 | //check for access |
||||
152 | $access = ''; |
||||
153 | if (!empty($xoopsUser)) { |
||||
154 | if ($row['user'] == $xoopsUser->getVar('uid') || true === $modadmin) { |
||||
155 | //$access = "<a href=\"dog.php?id=".$row['id']."\"><img src=\"assets/images/edit.png\" alt="._EDIT."></a>"; |
||||
156 | $access .= '<a href="deletebreeder.php?id=' . $row['id'] . "\"><img src='" . $pathIcon16 . "/delete.png' alt=" . _DELETE . '></a>'; |
||||
0 ignored issues
–
show
|
|||||
157 | } else { |
||||
158 | $access = ''; |
||||
159 | } |
||||
160 | } |
||||
161 | //make names |
||||
162 | $name = $access . '<a href="owner.php?ownid=' . $row['id'] . '">' . stripslashes($row['lastname']) . ', ' . stripslashes($row['firstname']) . '</a>'; |
||||
163 | //create array for owners |
||||
164 | $dogs[] = [ |
||||
165 | 'id' => $row['id'], |
||||
166 | 'name' => $name, |
||||
167 | 'city' => $row['city'] |
||||
168 | ]; |
||||
169 | } |
||||
170 | |||||
171 | //add data to smarty template |
||||
172 | //assign dog |
||||
173 | if (isset($dogs)) { |
||||
174 | $xoopsTpl->assign('dogs', $dogs); |
||||
175 | } |
||||
176 | //assign links |
||||
177 | if ('ASC' === $d) { |
||||
178 | $nl = '<a href="breeder.php?f=' . $f . '&o=lastname&d=DESC">' . _MA_PEDIGREE_OWN_NAME . '</a>'; |
||||
179 | $cl = '<a href="breeder.php?f=' . $f . '&o=city&d=DESC">' . _MA_PEDIGREE_OWN_CITY . '</a>'; |
||||
180 | } else { |
||||
181 | $nl = '<a href="breeder.php?f=' . $f . '&o=lastname&d=ASC">' . _MA_PEDIGREE_OWN_NAME . '</a>'; |
||||
182 | $cl = '<a href="breeder.php?f=' . $f . '&o=city&d=ASC">' . _MA_PEDIGREE_OWN_CITY . '</a>'; |
||||
183 | } |
||||
184 | $xoopsTpl->assign('namelink', $nl); |
||||
185 | $xoopsTpl->assign('colourlink', $cl); |
||||
186 | |||||
187 | //find last shown number |
||||
188 | if (($st + $perPage) > $numResults) { |
||||
189 | $lastshown = $numResults; |
||||
190 | } else { |
||||
191 | $lastshown = $st + $perPage; |
||||
192 | } |
||||
193 | //create string |
||||
194 | $matches = _MA_PEDIGREE_MATCHESB; |
||||
195 | $nummatchstr = $numResults . $matches . ($st + 1) . '-' . $lastshown . ' (' . $numPages . ' pages)'; |
||||
196 | $xoopsTpl->assign('nummatch', $nummatchstr); |
||||
197 | $xoopsTpl->assign('pages', $pages); |
||||
198 | |||||
199 | //$breederArray['letters'] = Pedigree\Utility::lettersChoice(); |
||||
200 | |||||
201 | $myObject = Pedigree\Helper::getInstance(); |
||||
202 | $criteria = $myObject->getHandler('Tree')->getActiveCriteria(); |
||||
203 | $activeObject = 'owner'; |
||||
204 | $name = 'lastname'; |
||||
205 | //$file = 'breeder.php'; |
||||
206 | //$file2 = "breeder.php?f={$name}&o={$name}&d=ASC&st=0&l={$letter}"; |
||||
207 | $link = "breeder.php?f={$name}&o={$name}&d=ASC&st=0&l="; |
||||
208 | $link2 = ''; |
||||
209 | |||||
210 | $breederArray['letters'] = Pedigree\Utility::lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2); |
||||
211 | //$catarray['toolbar'] = pedigree_toolbar(); |
||||
212 | |||||
213 | $xoopsTpl->assign('breederArray', $breederArray); |
||||
214 | $xoopsTpl->assign('pageTitle', _MA_PEDIGREE_BREEDER_PAGETITLE); |
||||
215 | |||||
216 | //comments and footer |
||||
217 | include XOOPS_ROOT_PATH . '/footer.php'; |
||||
218 |