1 | <?php |
||
2 | // ------------------------------------------------------------------------- |
||
3 | |||
4 | use Xmf\Request; |
||
5 | use XoopsModules\Pedigree; |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | |||
8 | //require_once dirname(dirname(__DIR__)) . '/mainfile.php'; |
||
9 | require_once __DIR__ . '/header.php'; |
||
10 | |||
11 | $moduleDirName = basename(__DIR__); |
||
12 | xoops_loadLanguage('main', $moduleDirName); |
||
13 | |||
14 | // Include any common code for this module. |
||
15 | require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php'; |
||
16 | //path taken |
||
17 | |||
18 | $GLOBALS['xoopsOption']['template_main'] = 'pedigree_latest.tpl'; |
||
19 | |||
20 | include $GLOBALS['xoops']->path('/header.php'); |
||
21 | |||
22 | //get module configuration |
||
23 | /** @var XoopsModuleHandler $moduleHandler */ |
||
24 | $moduleHandler = xoops_getHandler('module'); |
||
25 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
26 | $configHandler = xoops_getHandler('config'); |
||
27 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
28 | |||
29 | $st = Request::getInt('st', 0, 'GET'); |
||
30 | |||
31 | $perPage = $moduleConfig['perpage']; |
||
32 | global $xoopsTpl, $xoopsModuleConfig; |
||
33 | |||
34 | //iscurrent user a module admin ? |
||
35 | $modadmin = false; |
||
36 | $xoopsModule = XoopsModule::getByDirname($moduleDirName); |
||
37 | if (!empty($GLOBALS['xoopsUser'])) { |
||
38 | if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) { |
||
39 | $modadmin = true; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | //count total number of animals |
||
44 | $numanimal = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' NOLIMIT'; |
||
45 | $numRes = $GLOBALS['xoopsDB']->query($numanimal); |
||
46 | //total number of animals the query will find |
||
47 | $numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes); |
||
48 | //total number of pages |
||
49 | $numPages = floor($numResults / $perPage) + 1; |
||
50 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||
51 | --$numPages; |
||
52 | } |
||
53 | //find current page |
||
54 | $currentPage = floor($st / $perPage) + 1; |
||
55 | |||
56 | //create numbers |
||
57 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||
58 | $pages = $x . '  '; |
||
59 | } |
||
60 | |||
61 | //query |
||
62 | $queryString = 'SELECT d.id AS d_id, d.naam AS d_naam, d.roft AS d_roft, d.mother AS d_mother, d.father AS d_father, d.foto AS d_foto, d.user AS d_user, f.id AS f_id, f.naam AS f_naam, m.id AS m_id, m.naam AS m_naam, u.uname AS u_uname FROM ' |
||
63 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
64 | . ' d LEFT JOIN ' |
||
65 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
66 | . ' f ON d.father = f.id LEFT JOIN ' |
||
67 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
68 | . ' m ON d.mother = m.id LEFT JOIN ' |
||
69 | . $GLOBALS['xoopsDB']->prefix('users') |
||
70 | . ' u ON d.user = u.uid ORDER BY d.id DESC LIMIT ' |
||
71 | . $st |
||
72 | . ', ' |
||
73 | . $perPage; |
||
74 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
75 | $pathIcon16 = \Xmf\Module\Admin::iconUrl('', 16); |
||
76 | |||
77 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
78 | //reset $gender |
||
79 | $gender = ''; |
||
80 | if (!empty($GLOBALS['xoopsUser'])) { |
||
81 | if ($row['d_user'] == $GLOBALS['xoopsUser']->getVar('uid') || true === $modadmin) { |
||
82 | $gender = '<a href="dog.php?id=' . $row['d_id'] . '"><img src=' . $pathIcon16 . '/edit.png alt=' . _EDIT . '></a><a href="delete.php?id=' . $row['d_id'] . '"><img src=' . $pathIcon16 . '/delete.png alt=' . _DELETE . '></a>'; |
||
83 | } else { |
||
84 | $gender = ''; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if ('' != $row['d_foto']) { |
||
89 | $camera = ' <img src="assets/images/camera.png">'; |
||
90 | } else { |
||
91 | $camera = ''; |
||
92 | } |
||
93 | |||
94 | if (0 == $row['d_roft']) { |
||
95 | $gender .= '<img src="assets/images/male.gif">'; |
||
96 | } else { |
||
97 | $gender .= '<img src="assets/images/female.gif">'; |
||
98 | } |
||
99 | //create string for parents |
||
100 | if ('' == $row['f_naam']) { |
||
101 | $dad = _MA_PEDIGREE_UNKNOWN; |
||
102 | } else { |
||
103 | $dad = '<a href="pedigree.php?pedid=' . $row['f_id'] . '">' . stripslashes($row['f_naam']) . '</a>'; |
||
104 | } |
||
105 | if ('' == $row['m_naam']) { |
||
106 | $mom = _MA_PEDIGREE_UNKNOWN; |
||
107 | } else { |
||
108 | $mom = '<a href="pedigree.php?pedid=' . $row['m_id'] . '">' . stripslashes($row['m_naam']) . '</a>'; |
||
109 | } |
||
110 | $parents = $dad . ' x ' . $mom; |
||
111 | //create array for animals |
||
112 | $animals[] = [ |
||
113 | 'id' => $row['d_id'], |
||
114 | 'name' => stripslashes($row['d_naam']) . $camera, |
||
115 | 'gender' => $gender, |
||
116 | 'parents' => $parents, |
||
117 | 'addedby' => '<a href="../../userinfo.php?uid=' . $row['d_user'] . '">' . $row['u_uname'] . '</a>' |
||
118 | ]; |
||
119 | //reset rights ready for the next dog |
||
120 | $editdel = '0'; |
||
121 | } |
||
122 | |||
123 | //add data to smarty template |
||
124 | //assign dog |
||
125 | if (isset($animals)) { |
||
126 | $xoopsTpl->assign('dogs', $animals); |
||
127 | } |
||
128 | |||
129 | //find last shown number |
||
130 | if (($st + $perPage) > $numResults) { |
||
131 | $lastshown = $numResults; |
||
132 | } else { |
||
133 | $lastshown = $st + $perPage; |
||
134 | } |
||
135 | //create string |
||
136 | $matches = strtr(_MA_PEDIGREE_MATCHES, ['[animalTypes]' => $moduleConfig['animalTypes']]); |
||
137 | $nummatchstr = $numResults . $matches . ($st + 1) . '-' . $lastshown . ' (' . $numPages . ' pages)'; |
||
138 | $xoopsTpl->assign('nummatch', $nummatchstr); |
||
139 | if (isset($pages)) { |
||
140 | $xoopsTpl->assign('pages', $pages); |
||
141 | } |
||
142 | $xoopsTpl->assign('name', _MA_PEDIGREE_FLD_NAME); |
||
143 | $xoopsTpl->assign('parents', _MA_PEDIGREE_PA); |
||
144 | $xoopsTpl->assign('addedby', _MA_PEDIGREE_FLD_DBUS); |
||
145 | //comments and footer |
||
146 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
147 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: