Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

admin/pedigree.php (2 issues)

Labels
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * Pedigree module for XOOPS
13
 *
14
 * @package         \XoopsModules\Pedigree
15
 * @copyright       {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
16
 * @license         https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
17
 * @author          XOOPS Module Dev Team (https://xoops.org)
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Pedigree;
22
23
require_once __DIR__ . '/admin_header.php';
24
25
xoops_cp_header();
26
/**
27
 * @var Xmf\Module\Admin $adminObject
28
 * @var XoopsModules\Pedigree\Helper $helper
29
 * @var XoopsModules\Pedigree\TreeHandler $treeHandler
30
 */
31
$helper     = Pedigree\Helper::getInstance();
32
$treeHandler = $helper->getHandler('Tree');
33
34
//It recovered the value of argument op in URL$
35
$op = Request::getCmd('op', 'list');
36
switch ($op) {
37
    case 'list':
38
    default:
39
        $adminObject->displayNavigation(basename(__FILE__));
40
        $adminObject->addItemButton(_AM_PEDIGREE_NEWPEDIGREE, $helper->url('admin/pedigree.php?op=new_pedigree'), 'add');
41
        $adminObject->displayButton('left');
42
        $criteria = new \CriteriaCompo();
43
        $criteria->setSort('id');
44
        $criteria->setOrder('ASC');
45
        $numrows      = $treeHandler->getCount();
46
        $pedigree_arr = $treeHandler->getAll($criteria);
47
48
        //Table view
49
        if ($numrows > 0) {
50
            echo "<table class=\"width100 outer\" cellspacing=\"1\">\n"
51
               . "  <tr>\n"
52
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_NAAM . "</th>\n"
53
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_ID_OWNER . "</th>\n"
54
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_ID_BREEDER . "</th>\n"
55
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_USER . "</th>\n"
56
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_ROFT . "</th>\n"
57
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_MOTHER . "</th>\n"
58
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_FATHER . "</th>\n"
59
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_FOTO . "</th>\n"
60
               . "    <th class=\"center\">" . _AM_PEDIGREE_PEDIGREE_COI . "</th>\n"
61
               . "    <th class=\"center width10\">" . _AM_PEDIGREE_FORMACTION . "</th>\n"
62
               . "  </tr>\n";
63
64
            $class = 'even';
65
66
            /** @var XoopsModules\Pedigree\Tree $tObj */
67
            foreach ($pedigree_arr as $i => $tObj) {
68
                if (0 == $tObj->getVar('pedigree_pid')) {
69
                    $class = ('even' === $class) ? 'odd' : 'even';
70
                    echo "  <tr class=\"{$class}\">\n"
71
                       . "    <td class=\"center\">" . $tObj->getVar('naam') . "</td>\n"
72
                       . "    <td class=\"center\">" . $tObj->getVar('id_owner') . "</td>\n"
73
                       . "    <td class=\"center\">" . $tObj->getVar('id_breeder') . "</td>\n"
74
                       . "    <td class=\"center\">" . $tObj->getVar('user') . "</td>\n"
75
                       . "    <td class=\"center\">" . $tObj->getVar('roft') . "</td>\n"
76
                       . "    <td class=\"center\">" . $tObj->getVar('mother') . "</td>\n"
77
                       . "    <td class=\"center\">" . $tObj->getVar('father') . "</td>\n"
78
                       . "    <td class=\"center\">" . $tObj->getVar('foto') . "</td>\n"
79
                       . "    <td class=\"center\">" . $tObj->getVar('coi') . "</td>\n"
80
                       . "    <td class=\"center width10\">\n"
81
                       . "      <a href=\"" . $_SERVER['SCRIPT_NAME'] . "?op=edit_pedigree&id=" . $tObj->getVar('id') . "\"><img src=\"{$pathIcon16}/edit.png\" alt=\"" . _EDIT . "\" title=\"" . _EDIT . "\"></a>\n"
82
                       . "      <a href=" . $helper->url('delete.php?id=' . $tObj->getVar('id')) . "><img src=\"{$pathIcon16}/delete.png\" alt=\"" . _DELETE . "\" title=\"" . _DELETE . "\"></a>\n"
83
                       . "    </td>\n"
84
                       . "  </tr>\n";
85
                }
86
            }
87
            echo "</table><br><br>\n";
88
        } //@todo should add 'else' here to display "nothing here" message
89
90
        break;
91
92
    case 'new_pedigree':
93
        $adminObject->displayNavigation(basename(__FILE__));
94
        $adminObject->addItemButton(_AM_PEDIGREE_PEDIGREELIST, $helper->url('pedigree.php?op=list'), 'list');
95
        $adminObject->displayButton('left');
96
97
        /**
98
         * @var XoopsModules\Pedigree\Tree $tObj
99
         * @var \XoopsThemeForm $form
100
        */
101
        $tObj = $treeHandler->create();
102
        $form = $tObj->getForm();
103
        $form->display();
104
        break;
105
106
    case 'save_pedigree':
107
        /** @var \XoopsSecurity $GLOBALS['xoopsSecurity'] */
108
        if (!$GLOBALS['xoopsSecurity']->check()) {
109
            $helper->redirect('admin/pedigree.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
110
        }
111
112
        /** @var XoopsModules\Pedigree\Tree $tObj */
113
        $id   = Request::getInt('id', null, 'post');
114
        $tObj = $treeHandler->get($id);
115
116
        $varArray = array(
117
                'naam' => Request::getString('naam', '', 'post'),
118
            'id_owner' => Request::getInt('id_owner', 0, 'post'),
119
          'id_breeder' => Request::getInt('id_breeder', 0, 'post'),
120
                'user' => Request::getString('user', '', 'post'),
121
                'roft' => Request::getInt('roft', 0, 'post'),
122
              'mother' => Request::getInt('mother', 0, 'post'),
123
              'father' => Request::getInt('father', 0, 'post'),
124
                'foto' => Request::getString('foto', '', 'post'),
125
                 'coi' => Request::getString('coi', '', 'post')
126
        );
127
128
        $tObj->setVars($varArray);
129
        if ($treeHandler->insert($tObj)) {
130
            $helper->redirect('admin/pedigree.php?op=list', 2, _AM_PEDIGREE_FORMOK);
131
        }
132
133
        echo $tObj->getHtmlErrors();
134
        /** @var \XoopsThemeForm $form */
135
        $form = $tObj->getForm();
0 ignored issues
show
The method getForm() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModules\Pedigree\Temp or SystemSmilies or XoopsModules\Pedigree\Owner or SystemBanner or SystemBannerclient or XoopsModules\Pedigree\Tree or XoopsModules\Pedigree\Trash or XoopsModules\Pedigree\Fields or ProfileCategory or SystemUserrank or SystemGroup or SystemBlock or SystemAvatar or SystemUsers. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
        /** @scrutinizer ignore-call */ 
136
        $form = $tObj->getForm();
Loading history...
136
        $form->display();
137
        break;
138
139
    case 'edit_pedigree':
140
        $adminObject->displayNavigation(basename(__FILE__));
141
        $adminObject->addItemButton(_AM_PEDIGREE_NEWPEDIGREE, $helper->url('admin/pedigree.php?op=new_pedigree'), 'add');
142
        $adminObject->addItemButton(_AM_PEDIGREE_PEDIGREELIST, $helper->url('admin/pedigree.php?op=list'), 'list');
143
        $adminObject->displayButton('left');
144
145
        /**
146
         * @var XoopsModules\Pedigree\Tree $tObj
147
         * @var XoopsThemeForm $form
148
         */
149
        $id   = Request::getInt('id', 0);
150
        $tObj = $treeHandler->get($id);
151
        $form = $tObj->getForm();
152
        $form->display();
153
        break;
154
155
    case 'delete_pedigree':
156
        /** @var XoopsModules\Pedigree\Tree $tObj */
157
        $id  = Request::getInt('id', 0);
158
        $tObj = $treeHandler->get($id);
159
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
160
            if (!$GLOBALS['xoopsSecurity']->check()) {
161
                $helper->redirect('admin/pedigree.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
162
            }
163
            if ($treeHandler->delete($obj)) {
164
                $helper->redirect('admin/pedigree.php', 3, _AM_PEDIGREE_FORMDELOK);
165
            } else {
166
                echo $tObj->getHtmlErrors();
167
            }
168
        } else {
169
            xoops_confirm(['ok' => 1, 'id' => $id, 'op' => 'delete_pedigree'], $_SERVER['REQUEST_URI'], sprintf(_AM_PEDIGREE_FORMSUREDEL, $tObj->getVar('pedigree')));
0 ignored issues
show
It seems like $tObj->getVar('pedigree') can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

169
            xoops_confirm(['ok' => 1, 'id' => $id, 'op' => 'delete_pedigree'], $_SERVER['REQUEST_URI'], sprintf(_AM_PEDIGREE_FORMSUREDEL, /** @scrutinizer ignore-type */ $tObj->getVar('pedigree')));
Loading history...
170
        }
171
        break;
172
}
173
require_once __DIR__ . '/admin_footer.php';
174