Completed
Push — master ( 3024c9...954431 )
by Michael
04:21
created

admin/altcat.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Module: XoopsTube
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 *
9
 * PHP version 5
10
 *
11
 * @category        Module
12
 * @package         Xoopstube
13
 * @author          XOOPS Development Team
14
 * @copyright       2001-2016 XOOPS Project (http://xoops.org)
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @link            http://xoops.org/
17
 * @since           1.0.6
18
 */
19
20
include_once __DIR__ . '/admin_header.php';
21
22
$op  = XoopsRequest::getCmd('op', XoopsRequest::getCmd('op', '', 'POST'), 'GET'); //xtubeCleanRequestVars($_REQUEST, 'op', '');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
23
$lid = XoopsRequest::getInt('lid', XoopsRequest::getInt('lid', 0, 'POST'), 'GET'); //xtubeCleanRequestVars($_REQUEST, 'lid', 0);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
24
25
/**
26
 * @param  XoopstubeTree      $xt
27
 * @param int       $itemid
28
 * @param        $title
29
 * @param        $checks
30
 * @param string $order
31
 */
32
function makeTreeCheckTable(XoopstubeTree $xt, $itemid, $title, $checks, $order = '')
33
{
34
    global $xtubemyts;
35
36
    echo '<div style="text-align: left;">';
37
    echo '<form name="altcat" method="post" action="' . xoops_getenv('PHP_SELF') . '">';
38
    echo '<table width="100%" callspacing="1" class="outer">';
39
    $sql = 'SELECT ' . $xt->id . ', ' . $title . ' FROM ' . $xt->table . ' WHERE ' . $xt->pid . '=0' . ' ORDER BY ' . $title;
40
    if ($order !== '') {
41
        $sql .= ' ORDER BY ' . $order;
42
    }
43
    $result = $xt->db->query($sql);
44
45
    while (false !== (list($cid, $name) = $xt->db->fetchRow($result))) {
46
        $checked  = array_key_exists($cid, $checks) ? "checked='checked'" : '';
47
        $disabled = ($cid == XoopsRequest::getInt('cid', 0, 'GET')) ? "disabled='yes'" : '';
48
        $level    = 1;
49
        echo '
50
        <tr style="text-align: left;">
51
         <td width="30%" class="head">' . $name . '</td>
52
         <td class="head">
53
             <input type="checkbox" name="cid-' . $cid . '" value="0" ' . $checked . ' ' . $disabled . '/>
54
         </td>
55
        </tr>';
56
        $arr = $xt->getChildTreeArray($cid, $order);
57
        foreach ($arr as $cat) {
58
            $cat['prefix'] = str_replace('.', '-', $cat['prefix']);
59
            $catpath       = '&nbsp;' . $cat['prefix'] . '&nbsp;' . $xtubemyts->htmlSpecialCharsStrip($cat[$title]);
60
            $checked       = array_key_exists($cat['cid'], $checks) ? "checked='checked'" : '';
61
            $disabled      = ($cat['cid'] == XoopsRequest::getInt('cid', 0, 'GET')) ? "disabled='yes'" : '';
62
            $level         = substr_count($cat['prefix'], '-') + 1;
63
            //          echo "<tr><td>" . $catpath . "<input type='checkbox' name='cid-" . $cat['cid'] . "' value='0' " . $checked . " " . $disabled . "/></td></tr>\n";
64
            echo '
65
        <tr style="text-align: left;">
66
         <td width="30%" class="even">' . $catpath . '</td>
67
         <td class="even">
68
             <input type="checkbox" name="cid-' . $cat['cid'] . '" value="0" ' . $checked . ' ' . $disabled . '/>
69
         </td>
70
        </tr>';
71
        }
72
    }
73
    echo '<tr>
74
           <td width="30%"></td>
75
           <td style="text-align: left;">
76
            <input type="submit" class="mainbutton" value="save" />
77
            <input type="hidden" name="op" value="save" />
78
            <input type="hidden" name="lid" value="' . $itemid . '" />
79
            </td>
80
          </tr>';
81
    echo '</table></form></div>';
82
}
83
84
switch (strtolower($op)) {
85
    case 'save':
86
        // first delete all alternate categories for this topic
87
        $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') . ' WHERE lid=' . $lid;
88
        if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
89
            XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
90
91
            return false;
92
        }
93
94
        $k = array_keys($_REQUEST);
95
        foreach ($k as $sid) {
96
            if (preg_match('/cid-(\d*)/', $sid, $cid)) {
97
                $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') . '(cid, lid) VALUES("' . $cid[1] . '","' . $lid . '")';
98
                if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
99
                    XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
100
101
                    return false;
102
                }
103
            }
104
        }
105
        redirect_header('index.php', 1, _AM_XOOPSTUBE_ALTCAT_CREATED);
106
        break;
107
108
    case 'main':
109
    default:
110
        xoops_cp_header();
111
        //xtubeRenderAdminMenu(_AM_XOOPSTUBE_MALTCAT);
112
        echo '<fieldset><legend style="font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_ALTCAT_MODIFYF . '</legend>
113
          <div style="padding: 8px;">' . _AM_XOOPSTUBE_ALTCAT_INFOTEXT . '</div>
114
          </fieldset>';
115
116
        echo '<div style="text-align: left;"><h3> ' . $_REQUEST['title'] . ' </h3></div>';
117
        // Get an array of all alternate categories for this topic
118
        $sql     = $GLOBALS['xoopsDB']->query('SELECT cid FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_altcat') . ' WHERE lid="' . $lid . '" ORDER BY lid');
119
        $altcats = array();
120
        while (false !== ($altcat = $GLOBALS['xoopsDB']->fetchArray($sql))) {
121
            $altcats[$altcat['cid']] = true;
122
        }
123
        $mytree = new XoopstubeTree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid');
124
        makeTreeCheckTable($mytree, $lid, 'title', $altcats);
125
        xoops_cp_footer();
126
}
127