Blocksadmin::orderBlock()   C
last analyzed

Complexity

Conditions 15
Paths 38

Size

Total Lines 53
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 15
eloc 27
c 1
b 0
f 0
nc 38
nop 14
dl 0
loc 53
rs 5.9166

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll\Common;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 *
11
 * @category        Module
12
 * @author          XOOPS Development Team
13
 * @copyright       XOOPS Project
14
 * @link            https://xoops.org
15
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 */
17
18
use Xmf\Module\Admin;
19
use Xmf\Request;
20
use XoopsModules\Xoopspoll\{
21
    Helper
22
};
23
24
//require __DIR__ . '/admin_header.php';
25
require_once XOOPS_ROOT_PATH . '/kernel/block.php';
26
27
/**
28
 * class Blocksadmin
29
 */
30
class Blocksadmin
31
{
32
    /**
33
     * @var \XoopsMySQLDatabase|null
34
     */
35
    public $db;
36
    /**
37
     * @var Helper
38
     */
39
    public Helper $helper;
40
    
41
    private \XoopsModule $xoopsModule;
42
    private \XoopsSecurity $xoopsSecurity;
43
    /**
44
     * @var string
45
     */
46
    public string $moduleDirName;
47
    /**
48
     * @var string
49
     */
50
    public $moduleDirNameUpper;
51
52
    /**
53
     * Blocksadmin constructor.
54
     * @param \XoopsMySQLDatabase|null $db
55
     * @param Helper|null         $helper
56
     * @param \XoopsModule        $xoopsModule
57
     * @param \XoopsSecurity      $xoopsSecurity
58
     *
59
     */
60
    public function __construct(?\XoopsMySQLDatabase $db, Helper $helper, \XoopsModule $xoopsModule, \XoopsSecurity $xoopsSecurity)
61
    {
62
        if (null === $db) {
63
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
64
        }
65
        $this->db                 = $db;
66
        $this->helper             = $helper;
67
        $this->xoopsModule        = $xoopsModule;
68
        $this->xoopsSecurity      = $xoopsSecurity;
69
        $this->moduleDirName      = \basename(\dirname(__DIR__, 2));
70
        $this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName);
71
        \xoops_loadLanguage('admin', 'system');
72
        \xoops_loadLanguage('admin/blocksadmin', 'system');
73
        \xoops_loadLanguage('admin/groups', 'system');
74
        $this->helper->loadLanguage('common');
75
        $this->helper->loadLanguage('blocksadmin');
76
    }
77
78
    /**
79
     * @return void
80
     */
81
    public function listBlocks(): void
82
    {
83
        $pathIcon16 = Admin::iconUrl('', '16');
84
85
        require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
86
87
        /** @var \XoopsModuleHandler $moduleHandler */
88
        $moduleHandler = \xoops_getHandler('module');
89
        /** @var \XoopsMemberHandler $memberHandler */
90
        $memberHandler = \xoops_getHandler('member');
91
        /** @var \XoopsGroupPermHandler $grouppermHandler */
92
        $grouppermHandler = \xoops_getHandler('groupperm');
93
        $groups           = $memberHandler->getGroups();
94
        $criteria         = new \CriteriaCompo(new \Criteria('hasmain', '1'));
95
        $criteria->add(new \Criteria('isactive', '1'));
96
        $moduleList     = $moduleHandler->getList($criteria);
97
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
98
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
99
        \ksort($moduleList);
100
        echo "<h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>';
101
        echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>";
102
        echo $this->xoopsSecurity->getTokenHTML();
103
        echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
104
        <tr valign='middle'><th align='center'>" . \_AM_SYSTEM_BLOCKS_TITLE . "</th><th align='center' nowrap='nowrap'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE') . '<br>' . _LEFT . '-' . _CENTER . '-' . _RIGHT . "</th>
105
        <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT') . "</th>
106
        <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') . "</th><th align='center'>" . \_AM_SYSTEM_BLOCKS_VISIBLEIN . "</th>
107
        <th align='center'>" . \_AM_SYSTEM_ADGS . "</th>
108
        <th align='center'>" . \_AM_SYSTEM_BLOCKS_BCACHETIME . "</th>
109
        <th align='center'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') . '</th>
110
        </tr>';
111
        $blockArray = \XoopsBlock::getByModule($this->xoopsModule->mid());
112
        $blockCount = \count($blockArray);
0 ignored issues
show
Unused Code introduced by
The assignment to $blockCount is dead and can be removed.
Loading history...
113
        $class      = 'even';
114
        $cachetimes = [
115
            0       => \_NOCACHE,
116
            30      => \sprintf(\_SECONDS, 30),
117
            60      => \_MINUTE,
118
            300     => \sprintf(\_MINUTES, 5),
119
            1800    => \sprintf(\_MINUTES, 30),
120
            3600    => \_HOUR,
121
            18000   => \sprintf(\_HOURS, 5),
122
            86400   => \_DAY,
123
            259200  => \sprintf(\_DAYS, 3),
124
            604800  => \_WEEK,
125
            2592000 => \_MONTH,
126
        ];
127
        foreach ($blockArray as $i) {
128
            $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
129
            $sql               = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');
0 ignored issues
show
Bug introduced by
The method prefix() does not exist on null. ( Ignorable by Annotation )

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

129
            $sql               = 'SELECT module_id FROM ' . $this->db->/** @scrutinizer ignore-call */ prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
130
            $result            = $this->db->query($sql);
131
            if (!$this->db->isResultSet($result)) {
132
//                \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
133
                $errorMsg = \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error();
134
                $logger   = \XoopsLogger::getInstance();
135
                $logger->handleError(E_USER_WARNING, $errorMsg, __FILE__, __LINE__);
136
                $this->helper->redirect('admin/blocksadmin.php', 3, $errorMsg);
137
            }
138
            $modules           = [];
139
            while (false !== ($row = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, 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

139
            while (false !== ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
140
                $modules[] = (int)$row['module_id'];
141
            }
142
143
            $cachetimeOptions = '';
144
            foreach ($cachetimes as $cachetime => $cachetimeName) {
145
                if ($i->getVar('bcachetime') == $cachetime) {
146
                    $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n";
147
                } else {
148
                    $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n";
149
                }
150
            }
151
152
            $ssel7 = '';
153
            $ssel6 = $ssel7;
154
            $ssel5 = $ssel6;
155
            $ssel4 = $ssel5;
156
            $ssel3 = $ssel4;
157
            $ssel2 = $ssel3;
158
            $ssel1 = $ssel2;
159
            $ssel0 = $ssel1;
160
            $sel1  = $ssel0;
161
            $sel0  = $sel1;
162
            if (1 === $i->getVar('visible')) {
163
                $sel1 = ' checked';
164
            } else {
165
                $sel0 = ' checked';
166
            }
167
            if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) {
168
                $ssel0 = ' checked';
169
            } elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) {
170
                $ssel1 = ' checked';
171
            } elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) {
172
                $ssel2 = ' checked';
173
            } elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) {
174
                $ssel4 = ' checked';
175
            } elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) {
176
                $ssel3 = ' checked';
177
            } elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) {
178
                $ssel5 = ' checked';
179
            } elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) {
180
                $ssel6 = ' checked';
181
            } elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) {
182
                $ssel7 = ' checked';
183
            }
184
            if ('' === $i->getVar('title')) {
185
                $title = '&nbsp;';
186
            }else {
187
                $title = $i->getVar('title');
188
            }
189
            $name = $i->getVar('name');
0 ignored issues
show
Unused Code introduced by
The assignment to $name is dead and can be removed.
Loading history...
190
            echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" . $i->getVar('bid') . "]' value='" . $title . "'></td>
191
            <td class='$class' align='center' nowrap='nowrap'><div align='center' >
192
                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_LEFT . "'$ssel2>
193
                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_CENTER . "'$ssel3>
194
                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_RIGHT . "'$ssel4>
195
                    </div>
196
                    <div>
197
                        <span style='float:right;'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_RIGHT . "'$ssel1></span>
198
                    <div align='left'><input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_SIDEBLOCK_LEFT . "'$ssel0></div>
199
                    </div>
200
                    <div align='center'>
201
                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5>
202
                        <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7>
203
                    <input type='radio' name='side[" . $i->getVar('bid') . "]' value='" . \XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6>
204
                    </div>
205
                </td>
206
                <td class='$class' align='center'><input type='text' name='weight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "' size='5' maxlength='5'></td>
207
                 <td class='$class' align='center' nowrap><input type='radio' name='visible[" . $i->getVar('bid') . "]' value='1'$sel1>" . \_YES . "&nbsp;<input type='radio' name='visible[" . $i->getVar('bid') . "]' value='0'$sel0>" . \_NO . '</td>';
208
209
            echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
210
            foreach ($moduleList as $k => $v) {
211
                echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>";
212
            }
213
            echo '</select></td>';
214
215
            echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
216
            foreach ($groups as $grp) {
217
                echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
218
            }
219
            echo '</select></td>';
220
221
            // Cache lifetime
222
            echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select>
223
                                    </td>';
224
225
            // Actions
226
227
            echo "<td class='$class' align='center'>
228
                <a href='blocksadmin.php?op=edit&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . \_EDIT . "' title='" . \_EDIT . "'></a> 
229
                <a href='blocksadmin.php?op=clone&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . \_CLONE . "' title='" . \_CLONE . "'></a>";
230
            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
231
            //                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'>
232
            //                     </a>";
233
            //            }
234
235
            //            if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) {
236
            if (!\in_array($i->getVar('block_type'), ['M', 'S'])) {
237
                echo "&nbsp;
238
                <a href='blocksadmin.php?op=delete&amp;bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . \_DELETE . "' title='" . \_DELETE . "'>
239
                     </a>";
240
            }
241
            echo "
242
            <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'>
243
            <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'>
244
            <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'>
245
            <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'>
246
            <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'>
247
            <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'>
248
            <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'>
249
            </td></tr>
250
            ";
251
            $class = ('even' === $class) ? 'odd' : 'even';
252
        }
253
        echo "<tr><td class='foot' align='center' colspan='8'>
254
        <input type='hidden' name='op' value='order'>" . $this->xoopsSecurity->getTokenHTML() . "
255
        <input type='submit' name='submit' value='" . \_SUBMIT . "'>
256
        </td></tr>
257
        </table>
258
        </form>
259
        <br><br>";
260
    }
261
262
    /**
263
     * @param int $bid
264
     */
265
    public function deleteBlock(int $bid): void 
266
    {
267
        //        \xoops_cp_header();
268
269
        \xoops_loadLanguage('admin', 'system');
270
        \xoops_loadLanguage('admin/blocksadmin', 'system');
271
        \xoops_loadLanguage('admin/groups', 'system');
272
273
//        $myblock = new \XoopsBlock($bid);
274
275
        $sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid);
276
        $result = $this->db->queryF($sql);
277
        if (!$result) {
278
            \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
279
        }
280
        $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
281
        $result = $this->db->queryF($sql);
282
        if (!$result) {
283
            \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
284
        }
285
286
        $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
287
    }
288
289
    /**
290
     * @param int $bid
291
     */
292
    public function cloneBlock(int $bid)
293
    {
294
        //require __DIR__ . '/admin_header.php';
295
        //        \xoops_cp_header();
296
297
        \xoops_loadLanguage('admin', 'system');
298
        \xoops_loadLanguage('admin/blocksadmin', 'system');
299
        \xoops_loadLanguage('admin/groups', 'system');
300
301
        $myblock = new \XoopsBlock($bid);
302
        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
303
        $result  = $this->db->query($sql);
304
        if (!$this->db->isResultSet($result)) {
305
            $errorMsg = \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error();
306
            $logger   = \XoopsLogger::getInstance();
307
            $logger->handleError(E_USER_WARNING, $errorMsg, __FILE__, __LINE__);
308
            $this->helper->redirect('admin/blocksadmin.php', 3, $errorMsg);
309
        }
310
        $modules = [];
311
        while (false !== ($row = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, 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

311
        while (false !== ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
312
            $modules[] = (int)$row['module_id'];
313
        }
314
315
        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']);
316
        $block    = [
317
            'title'      => $myblock->getVar('title') . ' Clone',
318
            'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'),
319
            'name'       => $myblock->getVar('name'),
320
            'side'       => $myblock->getVar('side'),
321
            'weight'     => $myblock->getVar('weight'),
322
            'visible'    => $myblock->getVar('visible'),
323
            'content'    => $myblock->getVar('content', 'N'),
324
            'modules'    => $modules,
325
            'is_custom'  => $isCustom,
326
            'ctype'      => $myblock->getVar('c_type'),
327
            'bcachetime' => $myblock->getVar('bcachetime'),
328
            'op'         => 'clone_ok',
329
            'bid'        => $myblock->getVar('bid'),
330
            'edit_form'  => $myblock->getOptions(),
331
            'template'   => $myblock->getVar('template'),
332
            'options'    => $myblock->getVar('options'),
333
        ];
334
        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>';
335
        //        $form = new Blockform();
336
        //        $form->render();
337
338
        $output =  $this->render($block);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $output is correct as $this->render($block) targeting XoopsModules\Xoopspoll\C...n\Blocksadmin::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
339
        echo $output;
0 ignored issues
show
Bug introduced by
Are you sure $output of type void can be used in echo? ( Ignorable by Annotation )

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

339
        echo /** @scrutinizer ignore-type */ $output;
Loading history...
340
        //        xoops_cp_footer();
341
        //        require_once __DIR__ . '/admin_footer.php';
342
        //        exit();
343
    }
344
345
    /**
346
     * @param int $bid
347
     * @param string $bside
348
     * @param string $bweight
349
     * @param string $bvisible
350
     * @param string $bcachetime
351
     * @param array|null $bmodule
352
     * @param array|null $options
353
     * @param array|null $groups
354
     * @param bool $redirect
355
     */
356
    public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups, bool $redirect = true)
357
    {
358
        \xoops_loadLanguage('admin', 'system');
359
        \xoops_loadLanguage('admin/blocksadmin', 'system');
360
        \xoops_loadLanguage('admin/groups', 'system');
361
362
        $block = new \XoopsBlock($bid);
363
        /** @var \XoopsBlock $clone */
364
        $clone = $block->xoopsClone($bid);
0 ignored issues
show
Unused Code introduced by
The call to XoopsObject::xoopsClone() has too many arguments starting with $bid. ( Ignorable by Annotation )

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

364
        /** @scrutinizer ignore-call */ 
365
        $clone = $block->xoopsClone($bid);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
365
//        if (empty($bmodule)) {
366
//            //            \xoops_cp_header();
367
//            \xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
368
//            \xoops_cp_footer();
369
//            exit();
370
//        }
371
372
        if (empty($bmodule)) {
373
            throw new \InvalidArgumentException(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
374
        }
375
        $clone->setVar('side', $bside);
376
        $clone->setVar('weight', $bweight);
377
        $clone->setVar('visible', $bvisible);
378
        //$clone->setVar('content', $_POST['bcontent']);
379
        $clone->setVar('title', Request::getString('btitle', '', 'POST'));
380
        $clone->setVar('bcachetime', $bcachetime);
381
        if (\is_array($options) && (\count($options) > 0)) {
382
            $options = \implode('|', $options);
383
            $clone->setVar('options', $options);
384
        }
385
        $clone->setVar('bid', 0);
386
        if (\in_array($block->getVar('block_type'), ['C', 'E'])) {
387
             $clone->setVar('block_type', 'E');
388
        } else {
389
            $clone->setVar('block_type', 'D');
390
        }
391
        $newid = null;
392
        //        $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105
393
        if ($clone->store()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $clone->store() of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
Deprecated Code introduced by
The function XoopsBlock::store() has been deprecated. ( Ignorable by Annotation )

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

393
        if (/** @scrutinizer ignore-deprecated */ $clone->store()) {
Loading history...
394
            $newid = $clone->id();  //get the id of the cloned block
395
        }
396
//        if (!$newid) {
397
//            //            \xoops_cp_header();
398
//            $clone->getHtmlErrors();
399
//            \xoops_cp_footer();
400
//            exit();
401
//        }
402
403
        if (!$newid) {
404
            throw new \RuntimeException($clone->getHtmlErrors());
405
        }
406
407
        if ('' !== $clone->getVar('template')) {
408
409
            /** @var \XoopsTplfileHandler $tplfileHandler */
410
            $tplfileHandler = \xoops_getHandler('tplfile');
411
            $configHandler = xoops_getHandler('config');
412
            /** @var \XoopsConfigHandler $xoopsConfig */
413
            $xoopsConfig = $configHandler->getConfigsByCat(XOOPS_CONF);
0 ignored issues
show
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

413
            /** @scrutinizer ignore-call */ 
414
            $xoopsConfig = $configHandler->getConfigsByCat(XOOPS_CONF);
Loading history...
414
            $btemplate   = $tplfileHandler->find($xoopsConfig['template_set'], 'block', (string)$bid);
415
            if (\count($btemplate) > 0) {
416
                $tplclone = $btemplate[0]->xoopsClone();
417
                $tplclone->setVar('tpl_id', 0);
418
                $tplclone->setVar('tpl_refid', $newid);
419
                $tplfileHandler->insert($tplclone);
420
            }
421
        }
422
423
        foreach ($bmodule as $bmid) {
424
            $sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')';
425
            $this->db->query($sql);
426
        }
427
        //$groups = &$this->xoopsUser->getGroups();
428
        foreach ($groups as $iValue) {
429
            $sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
430
            $this->db->query($sql);
431
        }
432
433
        if ($redirect) {
434
            $this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED);
435
        }
436
437
        return true;
438
    }
439
440
    /**
441
     * @param string     $bid
442
     * @param string     $title
443
     * @param string     $weight
444
     * @param string     $visible
445
     * @param string     $side
446
     * @param string     $bcachetime
447
     * @param array|null $bmodule
448
     */
449
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $bmodule is not used and could be removed. ( Ignorable by Annotation )

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

449
    public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, /** @scrutinizer ignore-unused */ ?array $bmodule = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
450
    {
451
        $myblock = new \XoopsBlock($bid);
452
        $myblock->setVar('title', $title);
453
        $myblock->setVar('weight', $weight);
454
        $myblock->setVar('visible', $visible);
455
        $myblock->setVar('side', $side);
456
        $myblock->setVar('bcachetime', $bcachetime);
457
        $myblock->store();
0 ignored issues
show
Deprecated Code introduced by
The function XoopsBlock::store() has been deprecated. ( Ignorable by Annotation )

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

457
        /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
458
        //        /** @var \XoopsBlockHandler $blockHandler */
459
        //        $blockHandler = \xoops_getHandler('block');
460
        //        return $blockHandler->insert($myblock);
461
    }
462
463
    /**
464
     * @param int $bid
465
     * @return void
466
     */
467
    public function editBlock(int $bid): void
468
    {
469
        //        require_once \dirname(__DIR__,2) . '/admin/admin_header.php';
470
        //        \xoops_cp_header();
471
        \xoops_loadLanguage('admin', 'system');
472
        \xoops_loadLanguage('admin/blocksadmin', 'system');
473
        \xoops_loadLanguage('admin/groups', 'system');
474
        //        mpu_adm_menu();
475
        $myblock = new \XoopsBlock($bid);
476
        $sql     = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid;
477
        $result  = $this->db->query($sql);
478
        if (!$this->db->isResultSet($result)) {
479
            //            \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR);
480
            $errorMsg = \sprintf(_DB_QUERY_ERROR, $sql) . $this->db->error();
481
            $logger   = \XoopsLogger::getInstance();
482
            $logger->handleError(E_USER_WARNING, $errorMsg, __FILE__, __LINE__);
483
            $this->helper->redirect('admin/blocksadmin.php', 3, $errorMsg);
484
        }
485
        $modules = [];
486
            while (false !== ($row = $this->db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type boolean; however, parameter $result of XoopsMySQLDatabase::fetchArray() does only seem to accept mysqli_result, 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

486
            while (false !== ($row = $this->db->fetchArray(/** @scrutinizer ignore-type */ $result))) {
Loading history...
487
                $modules[] = (int)$row['module_id'];
488
            }
489
490
        $isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']);
491
        $block    = [
492
            'title'      => $myblock->getVar('title'),
493
            'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK,
494
            //        'name'       => $myblock->getVar('name'),
495
            'side'       => $myblock->getVar('side'),
496
            'weight'     => $myblock->getVar('weight'),
497
            'visible'    => $myblock->getVar('visible'),
498
            'content'    => $myblock->getVar('content', 'N'),
499
            'modules'    => $modules,
500
            'is_custom'  => $isCustom,
501
            'ctype'      => $myblock->getVar('c_type'),
502
            'bcachetime' => $myblock->getVar('bcachetime'),
503
            'op'         => 'edit_ok',
504
            'bid'        => $myblock->getVar('bid'),
505
            'edit_form'  => $myblock->getOptions(),
506
            'template'   => $myblock->getVar('template'),
507
            'options'    => $myblock->getVar('options'),
508
        ];
509
        echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>';
510
511
        $output = $this->render($block);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $output is correct as $this->render($block) targeting XoopsModules\Xoopspoll\C...n\Blocksadmin::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
512
        echo $output;
0 ignored issues
show
Bug introduced by
Are you sure $output of type void can be used in echo? ( Ignorable by Annotation )

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

512
        echo /** @scrutinizer ignore-type */ $output;
Loading history...
513
    }
514
515
    /**
516
     * @param int        $bid
517
     * @param string     $btitle
518
     * @param string     $bside
519
     * @param string     $bweight
520
     * @param string     $bvisible
521
     * @param string     $bcachetime
522
     * @param array|null $bmodule
523
     * @param array|null $options
524
     * @param array|null $groups
525
     */
526
    public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups)
527
    {
528
        $myblock = new \XoopsBlock($bid);
529
        $myblock->setVar('title', $btitle);
530
        $myblock->setVar('weight', $bweight);
531
        $myblock->setVar('visible', $bvisible);
532
        $myblock->setVar('side', $bside);
533
        $myblock->setVar('bcachetime', $bcachetime);
534
        //update block options
535
        if (isset($options)) {
536
            $optionsCount = \count($options);
537
            if ($optionsCount > 0) {
538
                //Convert array values to comma-separated
539
                foreach ($options as $i => $iValue) {
540
                    if (\is_array($iValue)) {
541
                        $options[$i] = \implode(',', $iValue);
542
                    }
543
                }
544
                $options = \implode('|', $options);
545
                $myblock->setVar('options', $options);
546
            }
547
        }
548
        $newbid = $myblock->store();
0 ignored issues
show
Unused Code introduced by
The assignment to $newbid is dead and can be removed.
Loading history...
Deprecated Code introduced by
The function XoopsBlock::store() has been deprecated. ( Ignorable by Annotation )

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

548
        $newbid = /** @scrutinizer ignore-deprecated */ $myblock->store();
Loading history...
549
550
        /** @var \XoopsBlockHandler $blockHandler */
551
        $blockHandler = \xoops_getHandler('block');
552
        $blockHandler->insert($myblock);
553
554
        if (!empty($bmodule) && \count($bmodule) > 0) {
555
            $sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid);
556
            $this->db->query($sql);
557
            if (\in_array(0, $bmodule)) {
558
                $sql = \sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0);
559
                $this->db->query($sql);
560
            } else {
561
                foreach ($bmodule as $bmid) {
562
                    $sql = \sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid);
563
                    $this->db->query($sql);
564
                }
565
            }
566
        }
567
        $sql = \sprintf('DELETE FROM %s WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid);
568
        $this->db->query($sql);
569
        if (!empty($groups)) {
570
            foreach ($groups as $grp) {
571
                $sql = \sprintf("INSERT INTO %s (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid);
572
                $this->db->query($sql);
573
            }
574
        }
575
        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
576
    }
577
578
    /**
579
     * @param array $bid
580
     * @param array $oldtitle
581
     * @param array $oldside
582
     * @param array $oldweight
583
     * @param array $oldvisible
584
//     * @param array $oldgroups
585
     * @param array $oldbcachetime
586
     * @param array $oldbmodule
587
     * @param array $title
588
     * @param array $weight
589
     * @param array $visible
590
     * @param array $side
591
     * @param array $bcachetime
592
     * @param array $groups
593
     * @param array $bmodule
594
     */
595
    public function orderBlock(
596
        array $bid,
597
        array $oldtitle,
598
        array $oldside,
599
        array $oldweight,
600
        array $oldvisible,
601
//        array $oldgroups,
602
        array $oldbcachetime,
603
        array $oldbmodule,
604
        array $title,
605
        array $weight,
606
        array $visible,
607
        array $side,
608
        array $bcachetime,
609
        array $groups,
610
        array $bmodule
611
    ): void {
612
        if (!$this->xoopsSecurity->check()) {
613
            \redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $this->xoopsSecurity->getErrors()));
614
        }
615
        foreach (\array_keys($bid) as $i) {
616
            if ($oldtitle[$i] !== $title[$i]
617
                || $oldweight[$i] !== $weight[$i]
618
                || $oldvisible[$i] !== $visible[$i]
619
                || $oldside[$i] !== $side[$i]
620
                || $oldbcachetime[$i] !== $bcachetime[$i]
621
                || $oldbmodule[$i] !== $bmodule[$i]) {
622
                $this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]);
623
            }
624
            if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) {
625
                $sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]);
626
                $this->db->query($sql);
627
                if (\in_array(0, $bmodule[$i], true)) {
628
                    $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0);
629
                    $this->db->query($sql);
630
                } else {
631
                    foreach ($bmodule[$i] as $bmid) {
632
                        $sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid);
633
                        $this->db->query($sql);
634
                    }
635
                }
636
            }
637
            $sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]);
638
            $this->db->query($sql);
639
            if (!empty($groups[$i])) {
640
                foreach ($groups[$i] as $grp) {
641
                    $sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]);
642
                    $this->db->query($sql);
643
                }
644
            }
645
        }
646
647
        $this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS'));
648
    }
649
650
    /**
651
     * @param array|null $block
652
     * @return void
653
     */
654
    public function render(?array $block = null): void
655
    {
656
        \xoops_load('XoopsFormLoader');
657
        \xoops_loadLanguage('common', $this->moduleDirNameUpper);
658
659
        $form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
660
        if (isset($block['name'])) {
661
            $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name']));
662
        }
663
        $sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']);
664
        $sideSelect->addOptionArray([
665
                                        0 => \_AM_SYSTEM_BLOCKS_SBLEFT,
666
                                        1 => \_AM_SYSTEM_BLOCKS_SBRIGHT,
667
                                        3 => \_AM_SYSTEM_BLOCKS_CBLEFT,
668
                                        4 => \_AM_SYSTEM_BLOCKS_CBRIGHT,
669
                                        5 => \_AM_SYSTEM_BLOCKS_CBCENTER,
670
                                        7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT,
671
                                        8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT,
672
                                        9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM,
673
                                    ]);
674
        $form->addElement($sideSelect);
675
        $form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight']));
676
        $form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible']));
677
        $modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true);
678
        /** @var \XoopsModuleHandler $moduleHandler */
679
        $moduleHandler = \xoops_getHandler('module');
680
        $criteria      = new \CriteriaCompo(new \Criteria('hasmain', '1'));
681
        $criteria->add(new \Criteria('isactive', '1'));
682
        $moduleList     = $moduleHandler->getList($criteria);
683
        $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE;
684
        $moduleList[0]  = \_AM_SYSTEM_BLOCKS_ALLPAGES;
685
        \ksort($moduleList);
686
        $modSelect->addOptionArray($moduleList);
687
        $form->addElement($modSelect);
688
        $form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
689
        if ($block['is_custom']) {
690
            $textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
691
            $textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
692
            $form->addElement($textarea, true);
693
            $ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']);
694
            $ctypeSelect->addOptionArray([
695
                                             'H' => \_AM_SYSTEM_BLOCKS_HTML,
696
                                             'P' => \_AM_SYSTEM_BLOCKS_PHP,
697
                                             'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE,
698
                                             'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE,
699
                                         ]);
700
            $form->addElement($ctypeSelect);
701
        } elseif ('' !== $block['template']) {
702
            /** @var \XoopsTplfileHandler $tplfileHandler */
703
            $tplfileHandler = \xoops_getHandler('tplfile');
704
            /** @var \XoopsConfigHandler $configHandler */
705
            $configHandler = xoops_getHandler('config');
706
            /** @var \XoopsConfigItem $xoopsConfig */
707
            $xoopsConfig = $configHandler->getConfigsByCat(XOOPS_CONF);
708
            $btemplate   = $tplfileHandler->find($xoopsConfig['template_set'], 'block', $block['bid']);
709
            if (\count($btemplate) > 0) {
710
                $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
711
            } else {
712
                $btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']);
713
                if (\count($btemplate2) > 0) {
714
                    $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&amp;op=edittpl&amp;id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>'));
715
                }
716
            }
717
        }
718
        if (false !== $block['edit_form']) {
719
            $form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form']));
720
        }
721
        $cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
722
        $cache_select->addOptionArray([
723
                                          0       => \_NOCACHE,
724
                                          30      => \sprintf(\_SECONDS, 30),
725
                                          60      => \_MINUTE,
726
                                          300     => \sprintf(\_MINUTES, 5),
727
                                          1800    => \sprintf(\_MINUTES, 30),
728
                                          3600    => \_HOUR,
729
                                          18000   => \sprintf(\_HOURS, 5),
730
                                          86400   => \_DAY,
731
                                          259200  => \sprintf(\_DAYS, 3),
732
                                          604800  => \_WEEK,
733
                                          2592000 => \_MONTH,
734
                                      ]);
735
        $form->addElement($cache_select);
736
737
        /** @var \XoopsGroupPermHandler $grouppermHandler */
738
        $grouppermHandler = \xoops_getHandler('groupperm');
739
        $groups           = $grouppermHandler->getGroupIds('block_read', $block['bid']);
740
741
        $form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true));
742
743
        if (isset($block['bid'])) {
744
            $form->addElement(new \XoopsFormHidden('bid', $block['bid']));
745
        }
746
        $form->addElement(new \XoopsFormHidden('op', $block['op']));
747
        $form->addElement(new \XoopsFormHidden('fct', 'blocksadmin'));
748
        $buttonTray = new \XoopsFormElementTray('', '&nbsp;');
749
        if ($block['is_custom']) {
750
            $buttonTray->addElement(new \XoopsFormButton('', 'previewblock', \_PREVIEW, 'submit'));
751
        }
752
753
        //Submit buttons
754
        $buttonTray   = new \XoopsFormElementTray('', '');
755
        $submitButton = new \XoopsFormButton('', 'submitblock', \_SUBMIT, 'submit');
756
        $buttonTray->addElement($submitButton);
757
758
        $cancelButton = new \XoopsFormButton('', '', \_CANCEL, 'button');
759
        $cancelButton->setExtra('onclick="history.go(-1)"');
760
        $buttonTray->addElement($cancelButton);
761
762
        $form->addElement($buttonTray);
763
        $form->display();
764
    }
765
}
766