makeTreeCheckTable()   B
last analyzed

Complexity

Conditions 7
Paths 21

Size

Total Lines 49
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 26
nc 21
nop 4
dl 0
loc 49
rs 8.5706
c 0
b 0
f 0
1
<?php
2
/**
3
 * Module: WF
4
 * Version: v1.0.3
5
 * Release Date: 21 June 2005
6
 * Developer: John N
7
 * Team: WF-Projects
8
 * Licence: GNU
9
 */
10
11
use Xmf\Request;
12
use XoopsModules\Wflinks;
13
14
require_once __DIR__ . '/admin_header.php';
15
16
global $xoopsModuleConfig;
17
18
$op  = \Xmf\Request::getString('op', '');
19
$lid = \Xmf\Request::getInt('lid', 0);
20
21
/**
22
 * @param Wflinks\Tree $xt
23
 * @param              $itemid
24
 * @param              $title
25
 * @param              $checks
26
 */
27
function makeTreeCheckTable(Wflinks\Tree $xt, $itemid, $title, $checks)
28
{
29
    global $myts;
30
31
    echo "<div style='text-align: left;'>\n";
32
    echo "<form name='altcat' method='post' action='" . xoops_getenv('SCRIPT_NAME') . "'>\n";
33
    echo "<table width='100%' callspacing='1' class='outer'>\n";
34
    $sql = 'SELECT ' . $xt->id . ', ' . $title . ' FROM ' . $xt->table . ' WHERE ' . $xt->pid . '=0 ORDER BY ' . $title;
35
36
    $result = $xt->db->query($sql);
37
38
    while (list($cid, $name) = $xt->db->fetchRow($result)) {
39
        $checked  = array_key_exists($cid, $checks) ? 'checked' : '';
40
        $disabled = ($cid == Request::getInt('cid', 0, 'GET')) ? "disabled='yes'" : '';
41
        $level    = 1;
42
        echo "
43
        <tr style='text-align: left;'>
44
         <td width='30%' class='head'>$name</td>
45
         <td class='head'>
46
             <input type='checkbox' name='cid-" . (int)$cid . "' value='0' " . $checked . ' ' . $disabled . ">
47
         </td>
48
        </tr>\n";
49
        $arr = $xt->getChildTreeArray((int)$cid, $title);
50
51
        foreach ($arr as $cat) {
52
            $cat['prefix'] = str_replace('.', '-', $cat['prefix']);
53
            $catpath       = $cat['prefix'] . '&nbsp;' . htmlspecialchars($cat[$title], ENT_QUOTES | ENT_HTML5) . '&nbsp;';
54
            $checked       = array_key_exists($cat['cid'], $checks) ? 'checked' : '';
55
            $disabled      = ($cat['cid'] == Request::getInt('cid', 0, 'GET')) ? "disabled='yes'" : '';
56
            $level         = mb_substr_count($cat['prefix'], '-') + 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $level is dead and can be removed.
Loading history...
57
            //            echo "<tr><td>" . $catpath . "<input type='checkbox' name='cid-" . $cat['cid'] . "' value='0' " . $checked . " " . $disabled . "></td></tr>\n";
58
            echo "
59
        <tr style='text-align: left;'>
60
         <td width='30%' class='even'>$catpath</td>
61
         <td class='even'>
62
             <input type='checkbox' name='cid-" . $cat['cid'] . "' value='0' " . $checked . ' ' . $disabled . ">
63
         </td>
64
        </tr>\n";
65
        }
66
    }
67
    echo "<tr>
68
           <td width='30%' class='head'></td>
69
           <td class='even' style='text-align: left;'>
70
            <input type='submit' class='mainbutton' value='save'>
71
            <input type='hidden' name='op' value='save'>
72
            <input type='hidden' name='lid' value='" . $itemid . "'>
73
            </td>
74
          </tr>";
75
    echo "</table></form></div>\n";
76
}
77
78
switch (mb_strtolower($op)) {
79
    case 'save':
80
        // first delete all alternate categories for this topic
81
        $sql = 'DELETE FROM ' . $xoopsDB->prefix('wflinks_altcat') . ' WHERE lid=' . $lid;
82
        if (!$result = $xoopsDB->query($sql)) {
83
            /** @var \XoopsLogger $logger */
84
            $logger = \XoopsLogger::getInstance();
85
            $logger->handleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
86
87
            return false;
88
        }
89
90
        $k = array_keys($_REQUEST);
91
        foreach ($k as $sid) {
92
            if (preg_match('/cid-([0-9]*)/', $sid, $cid)) {
93
                $sql = 'INSERT INTO ' . $xoopsDB->prefix('wflinks_altcat') . "(cid, lid) VALUES('" . $cid[1] . "','" . $lid . "')";
94
                if (!$result = $xoopsDB->query($sql)) {
95
                    /** @var \XoopsLogger $logger */
96
                    $logger = \XoopsLogger::getInstance();
97
                    $logger->handleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
98
99
                    return false;
100
                }
101
            }
102
        }
103
        redirect_header('index.php', 1, _AM_WFL_ALTCAT_CREATED);
104
        break;
105
    case 'main':
106
    default:
107
        xoops_cp_header();
108
109
        echo "
110
            <fieldset style='border: #e8e8e8 1px solid;'><legend style='display: inline; font-weight: bold; color: #0A3760;'>" . _AM_WFL_ALTCAT_MODIFYF . "</legend>\n
111
            <div style='padding: 8px;'>" . _AM_WFL_ALTCAT_INFOTEXT . "</div>\n
112
            </fieldset>\n
113
        ";
114
115
        echo "<div style='text-align: left; font-size: larger;'><h4>" . htmlspecialchars(trim($_GET['title']), ENT_QUOTES | ENT_HTML5) . '</h4></div>';
116
        // Get an array of all alternate categories for this topic
117
        $sql     = $xoopsDB->query('SELECT cid FROM ' . $xoopsDB->prefix('wflinks_altcat') . ' WHERE lid=' . $lid . ' ORDER BY lid');
118
        $altcats = [];
119
        while (false !== ($altcat = $xoopsDB->fetchArray($sql))) {
120
            $altcats[$altcat['cid']] = true;
121
        }
122
        $mytree = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid');
123
124
        makeTreeCheckTable($mytree, $lid, 'title', $altcats);
125
        require_once __DIR__ . '/admin_footer.php';
126
}
127