Completed
Push — master ( 8ca430...3024c9 )
by Michael
03:12
created

admin/altcat.php (1 issue)

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 21.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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-2013 The XOOPS Project
15
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @version         $Id$
17
 * @link            http://sourceforge.net/projects/xoops/
18
 * @since           1.0.6
19
 */
20
21
include_once __DIR__ . '/admin_header.php';
22
23
global $xoopsModuleConfig;
24
25
$op  = xtubeCleanRequestVars($_REQUEST, 'op', '');
26
$lid = xtubeCleanRequestVars($_REQUEST, 'lid', 0);
27
28
/**
29
 * @param        $xt
30
 * @param        $itemid
31
 * @param        $title
32
 * @param        $checks
33
 * @param string $order
34
 */
35
function makeTreeCheckTable($xt, $itemid, $title, $checks, $order = '')
36
{
37
    global $xtubemyts;
38
39
    echo '<div style="text-align: left;">';
40
    echo '<form name="altcat" method="post" action="' . xoops_getenv('PHP_SELF') . '">';
41
    echo '<table width="100%" callspacing="1" class="outer">';
42
    $sql = 'SELECT ' . $xt->id . ', ' . $title . ' FROM ' . $xt->table . ' WHERE ' . $xt->pid . '=0' . ' ORDER BY ' . $title;
43
    if ($order != '') {
44
        $sql .= ' ORDER BY ' . $order;
45
    }
46
    $result = $xt->db->query($sql);
47
48
    while (list($cid, $name) = $xt->db->fetchRow($result)) {
49
        $checked  = array_key_exists($cid, $checks) ? "checked='checked'" : "";
50
        $disabled = ($cid == intval($_GET['cid'])) ? "disabled='yes'" : "";
51
        $level    = 1;
52
        echo '
53
        <tr style="text-align: left;">
54
         <td width="30%" class="head">' . $name . '</td>
55
         <td class="head">
56
             <input type="checkbox" name="cid-' . $cid . '" value="0" ' . $checked . ' ' . $disabled . '/>
57
         </td>
58
        </tr>';
59
        $arr = $xt->getChildTreeArray($cid, $order);
60
        foreach ($arr as $cat) {
61
            $cat['prefix'] = str_replace('.', '-', $cat['prefix']);
62
            $catpath       = '&nbsp;' . $cat['prefix'] . '&nbsp;' . $xtubemyts->htmlSpecialCharsStrip($cat[$title]);
63
            $checked       = array_key_exists($cat['cid'], $checks) ? "checked='checked'" : "";
64
            $disabled      = ($cat['cid'] == intval($_GET['cid'])) ? "disabled='yes'" : "";
65
            $level         = substr_count($cat['prefix'], '-') + 1;
66
//          echo "<tr><td>" . $catpath . "<input type='checkbox' name='cid-" . $cat['cid'] . "' value='0' " . $checked . " " . $disabled . "/></td></tr>\n";
67
            echo '
68
        <tr style="text-align: left;">
69
         <td width="30%" class="even">' . $catpath . '</td>
70
         <td class="even">
71
             <input type="checkbox" name="cid-' . $cat['cid'] . '" value="0" ' . $checked . ' ' . $disabled . '/>
72
         </td>
73
        </tr>';
74
        }
75
76
    }
77
    echo '<tr>
78
           <td width="30%"></td>
79
           <td style="text-align: left;">
80
            <input type="submit" class="mainbutton" value="save" />
81
            <input type="hidden" name="op" value="save" />
82
            <input type="hidden" name="lid" value="' . $itemid . '" />
83
            </td>
84
          </tr>';
85
    echo '</table></form></div>';
86
}
87
88
switch (strtolower($op)) {
89
    case 'save':
90
        // first delete all alternate categories for this topic
91
        $sql = 'DELETE FROM ' . $xoopsDB->prefix('xoopstube_altcat') . ' WHERE lid=' . $lid;
92
        if (!$result = $xoopsDB->query($sql)) {
93
            XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
94
95
            return false;
96
        }
97
98
        $k = array_keys($_REQUEST);
99
        foreach ($k as $sid) {
100
            if (preg_match("/cid-([0-9]*)/", $sid, $cid)) {
101
                $sql
102
                    = 'INSERT INTO ' . $xoopsDB->prefix('xoopstube_altcat') . '(cid, lid) VALUES("' . $cid[1] . '","' . $lid . '")';
103
                if (!$result = $xoopsDB->query($sql)) {
104
                    XoopsErrorHandler_HandleError(E_USER_WARNING, $sql, __FILE__, __LINE__);
105
106
                    return false;
107
                }
108
            }
109
        }
110
        redirect_header('index.php', 1, _AM_XOOPSTUBE_ALTCAT_CREATED);
111
        break;
112
113
    case 'main':
114
    default:
115
        xoops_cp_header();
116
        //xtubeRenderAdminMenu(_AM_XOOPSTUBE_MALTCAT);
117
        echo '<fieldset><legend style="font-weight: bold; color: #0A3760;">' . _AM_XOOPSTUBE_ALTCAT_MODIFYF . '</legend>
118
          <div style="padding: 8px;">' . _AM_XOOPSTUBE_ALTCAT_INFOTEXT . '</div>
119
          </fieldset>';
120
121
        echo '<div style="text-align: left;"><h3> ' . $_REQUEST['title'] . ' </h3></div>';
122
        // Get an array of all alternate categories for this topic
123
        $sql     = $xoopsDB->query(
124
            'SELECT cid FROM ' . $xoopsDB->prefix('xoopstube_altcat') . ' WHERE lid="' . $lid . '" ORDER BY lid'
125
        );
126
        $altcats = array();
127
        while ($altcat = $xoopsDB->fetchArray($sql)) {
128
            $altcats[$altcat['cid']] = true;
129
        }
130
        $mytree = new XoopstubeTree($xoopsDB->prefix('xoopstube_cat'), 'cid', 'pid');
131
        makeTreeCheckTable($mytree, $lid, 'title', $altcats);
132
        xoops_cp_footer();
133
}
134