Passed
Push — master ( ba995b...aecde2 )
by Michael
32s queued 12s
created

admin/pedigree_trash.php (2 issues)

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
/**
13
 * Module: Pedigree
14
 *
15
 * @package         Xoopsmodules\Pedigree
16
 * @copyright       2011-2018 XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18
 * @author          XOOPS Module Dev Team (https://xoops.org)
19
 */
20
21
use Xmf\Request;
22
use XoopsModules\Pedigree;
23
24
require_once __DIR__ . '/admin_header.php';
25
26
xoops_cp_header();
27
/** @var \Xmf\Module\Admin $adminObject */
28
29
$trashHandler = Pedigree\Helper::getInstance()->getHandler('Trash');
30
31
$op = Request::getCmd('op', 'list');
32
switch ($op) {
33
    case 'list':
34
    default:
35
        $adminObject->displayNavigation(basename(__FILE__));
36
        $adminObject->addItemButton(_AM_PEDIGREE_NEWPEDIGREE_TRASH, 'pedigree_trash.php?op=new_pedigree_trash', 'add');
37
        //$adminObject->displayButton('left');
38
        $criteria = new \CriteriaCompo();
39
        $criteria->setSort('id');
40
        $criteria->setOrder('ASC');
41
        $numRows = $trashHandler->getCount();
42
        $pedigreeTrashArr = $trashHandler->getAll($criteria);
43
44
        //Table view
45
        if ($numRows > 0) {
46
            echo "<table cellspacing='1' class='outer width100'>
47
                <thead>
48
                <tr>
49
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_NAAM . "</th>
50
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_ID_OWNER . "</th>
51
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_ID_BREEDER . "</th>
52
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_USER . "</th>
53
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_ROFT . "</th>
54
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_MOTHER . "</th>
55
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_FATHER . "</th>
56
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_FOTO . "</th>
57
                    <th class='txtcenter'>" . _AM_PEDIGREE_PEDIGREE_TRASH_COI . "</th>
58
                    <th class='txtcenter' width='10%'>" . _AM_PEDIGREE_FORMACTION . '</th>
59
                </tr>
60
                </thead>
61
                <tbody>';
62
63
            $class = 'odd';
64
65
            foreach ($pedigreeTrashArr) as $tId => $trashObj) {
0 ignored issues
show
A parse error occurred: Syntax error, unexpected ')' on line 65 at column 38
Loading history...
66
                if (0 == $trashObj->getVar('pedigree_trash_pid')) {
67
                    echo "<tr class='{$class}'>";
68
                    $class = ('even' === $class) ? 'odd' : 'even';
69
                    echo "<td class='txtcenter'>" . $trashObj->getVar('naam') . '</td>';
70
                    echo "<td class='txtcenter'>" . $trashObj->getVar('id_owner') . '</td>';
71
                    echo "<td class='txtcenter'>" . $trashObj->getVar('id_breeder') . '</td>';
72
                    echo "<td class='txtcenter'>" . $trashObj->getVar('user') . '</td>';
73
                    echo "<td class='txtcenter'>" . $trashObj->getVar('roft') . '</td>';
74
                    echo "<td class='txtcenter'>" . $trashObj->getVar('mother') . '</td>';
75
                    echo "<td class='txtcenter'>" . $trashObj->getVar('father') . '</td>';
76
                    echo "<td class='txtcenter'>" . $trashObj->getVar('foto') . '</td>';
77
                    echo "<td class='txtcenter'>" . $trashObj->getVar('coi') . '</td>';
78
                    echo "<td class'txtcenter width10'>
79
                        <a href='pedigree_trash.php?op=edit_pedigree_trash&id=" . $tId . "'><img src='{$pathIcon16}/edit.png' alt='" . _EDIT . "' title='" . _EDIT . "'></a>
80
                        <a href='pedigree_trash.php?op=delete_pedigree_trash&id=" . $tId . "'><img src='{$pathIcon16}/delete.png' alt='" . _DELETE . "' title='" . _DELETE . "'></a>
81
                        </td>";
82
                    echo '</tr>';
83
                }
84
            }
85
            echo '</tbody>
86
                  </table>
87
                  <br><br>';
88
        }
89
90
        break;
91
92
    case 'new_pedigree_trash':
93
        $adminObject->displayNavigation(basename(__FILE__));
94
        $adminObject->addItemButton(_AM_PEDIGREE_PEDIGREE_TRASHLIST, 'pedigree_trash.php?op=list', 'list');
95
        $adminObject->displayButton('left');
96
97
        $tObj  = $trashHandler->create();
98
        $form = $tObj->getForm();
99
        $form->display();
100
        break;
101
102
    case 'save_pedigree_trash':
103
        if (!$GLOBALS['xoopsSecurity']->check()) {
104
            $helper->redirect('admin/pedigree_trash.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
105
        }
106
        $tId = Request::getInt('id', null, 'POST');
107
        $tObj = $trashHandler->get($tId); // gets object or creates one if tId is empty
108
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
109
        if (isset($_REQUEST['id'])) {
110
            $obj = $trashHandler->get($_REQUEST['id']);
111
        } else {
112
            $obj = $trashHandler->create();
113
        }
114
        */
115
116
        $tObj->setVar('naam', Request::getString('naam', '', 'POST')); //Form naam
117
        $tObj->setVar('id_owner', Request::getInt('id_owner', 0, 'POST')); //Form id_owner
118
        $tObj->setVar('id_breeder', Request::getInt('id_breeder', 0, 'POST')); //Form id_breeder
119
        $tObj->setVar('user', Request::getString('user', '', 'POST')); //Form user
120
        $tObj->setVar('roft', Request::getString('roft', '', 'POST')); //Form roft
121
        $tObj->setVar('mother', Request::getInt('mother', 0, 'POST')); //Form mother
122
        $tObj->setVar('father', Request::getInt('father', 0, 'POST')); //Form father
123
        $tObj->setVar('foto', Request::getString('foto', '', 'POST')); //Form foto
124
        $tObj->setVar('coi', Request::getString('coi', '', 'POST')); //Form coi
125
126
        if ($trashHandler->insert($tObj)) {
127
            $helper->redirect('admin/pedigree_trash.php?op=list', 2, _AM_PEDIGREE_FORMOK);
128
        }
129
130
        echo $tObj->getHtmlErrors();
131
        $form = $tObj->getForm();
132
        $form->display();
133
        break;
134
135
    case 'edit_pedigree_trash':
136
        $adminObject->displayNavigation(basename(__FILE__));
137
        $adminObject->addItemButton(_AM_PEDIGREE_NEWPEDIGREE_TRASH, 'pedigree_trash.php?op=new_pedigree_trash', 'add');
138
        $adminObject->addItemButton(_AM_PEDIGREE_PEDIGREE_TRASHLIST, 'pedigree_trash.php?op=list', 'list');
139
        $adminObject->displayButton('left');
140
        $obj  = $trashHandler->get($_REQUEST['id']);
141
        $form = $obj->getForm();
142
        $form->display();
143
        break;
144
145
    case 'delete_pedigree_trash':
146
        $tId = Request::getInt('id', 0);
147
        if (!$tId)) {
148
            $helper->redirect('admin/pedigree_trash.php', 3, _AM_PEDIGREE_ERR_INVALID);
149
        }
150
        $tObj = $trashHandler->get($tId);
151
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
152
            if (!$GLOBALS['xoopsSecurity']->check()) {
153
                $helper->redirect('admin/pedigree_trash.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
154
            }
155
            if ($trashHandler->delete($obj)) {
156
                $helper->redirect('admin/pedigree_trash.php', 3, _AM_PEDIGREE_FORMDELOK);
157
            } else {
158
                echo $obj->getHtmlErrors();
159
            }
160
        } else {
161
            xoops_confirm(['ok' => 1, 'id' => $tId, 'op' => 'delete_pedigree_trash'], $_SERVER['REQUEST_URI'], sprintf(_AM_PEDIGREE_FORMSUREDEL, $obj->getVar('pedigree_trash')));
162
        }
163
        break;
164
}
165
require_once __DIR__ . '/admin_footer.php';
166