Completed
Push — master ( ded118...cf7347 )
by Michael
02:48
created

category.php ➔ categorySave()   F

Complexity

Conditions 19
Paths 6144

Size

Total Lines 83
Code Lines 65

Duplication

Lines 9
Ratio 10.84 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 19
eloc 65
c 1
b 0
f 0
nc 6144
nop 1
dl 9
loc 83
rs 2.0734

How to fix   Long Method    Complexity   

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:

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 24 and the first side effect is on line 12.

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
 * $Id: category.php v 1.0 8 May 2004 hsalazar Exp $
4
 * Module: Lexikon - glossary module
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Licence: GNU
9
 */
10
11
// -- General Stuff -- //
12
include( "admin_header.php" );
13
$myts =& MyTextSanitizer::getInstance();
14
xoops_cp_header();
15
xoops_load('XoopsUserUtility');
16
$indexAdmin = new ModuleAdmin();
17
echo $indexAdmin->addNavigation('category.php');
18
$indexAdmin->addItemButton(_AM_LEXIKON_CREATECAT, 'category.php?op=addcat', 'add');
19
echo $indexAdmin->renderButton('left');
20
$op = '';
21
22
/* -- Available operations -- */
23
24
function categoryDefault() {
0 ignored issues
show
Coding Style introduced by
categoryDefault uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    $op = 'default';
0 ignored issues
show
Unused Code introduced by
$op is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
    include_once XOOPS_ROOT_PATH . "/class/xoopslists.php";
27
    include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
28
29
    $startentry = isset( $_GET['startentry'] ) ? intval( $_GET['startentry'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$startentry is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
    $startcat = isset( $_GET['startcat'] ) ? intval( $_GET['startcat'] ) : 0;
31
    $startsub = isset( $_GET['startsub'] ) ? intval( $_GET['startsub'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$startsub is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
32
    $datesub = isset( $_GET['datesub'] ) ? intval( $_GET['datesub'] ) : 0;
0 ignored issues
show
Unused Code introduced by
$datesub is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
    
34
    global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $entryID, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
35
36
    $myts =& MyTextSanitizer::getInstance();
37
//    lx_adminMenu(1, _AM_LEXIKON_CATS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
38
    $result01 = $xoopsDB -> query( "SELECT COUNT(*)
39
                                   FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
40
    list( $totalcategories ) = $xoopsDB -> fetchRow( $result01 );
41
42
    $result02 = $xoopsDB -> query( "SELECT COUNT(*)
43
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
44
                                   WHERE submit = 0" );
45
    list( $totalpublished ) = $xoopsDB -> fetchRow( $result02 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalpublished is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
46
47
    $result03 = $xoopsDB -> query( "SELECT COUNT(*)
48
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
49
                                   WHERE submit = '1' AND request = '0' " );
50
    list( $totalsubmitted ) = $xoopsDB -> fetchRow( $result03 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalsubmitted is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
51
52
    $result04 = $xoopsDB -> query( "SELECT COUNT(*)
53
                                   FROM " . $xoopsDB -> prefix( "lxentries" ) . "
54
                                   WHERE submit = '1' AND request = '1' " );
55
    list( $totalrequested ) = $xoopsDB -> fetchRow( $result04 );
0 ignored issues
show
Unused Code introduced by
The assignment to $totalrequested is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
56
57
//    echo "<table width='100%' class='outer' style=\"margin-top: 6px; clear:both;\" cellspacing='2' cellpadding='3' border='0' ><tr>";
58
//    echo "<td class='odd'>" . _AM_LEXIKON_TOTALENTRIES . "</td><td align='center' class='even'>" . $totalpublished . "</td>";
59
//    if ($xoopsModuleConfig['multicats'] == 1) {
60
//        echo "<td class='odd'>" . _AM_LEXIKON_TOTALCATS . "</td><td align='center' class='even'>" . $totalcategories . "</td>";
61
//    }
62
//    echo "<td class='odd'>" . _AM_LEXIKON_TOTALSUBM . "</td><td align='center' class='even'>" . $totalsubmitted . "</td>
63
//    <td class='odd'>" . _AM_LEXIKON_TOTALREQ . "</td><td align='center' class='even'>" . $totalrequested . "</td>
64
//    </tr></table>
65
//    <br /><br />";
66
67
    if ($xoopsModuleConfig['multicats'] == 1) {
68
        /**
69
        * Code to show existing categories
70
        **/
71
72
        echo" <table class='outer' width='100%' border='0'>
73
        <tr>
74
        <td colspan='7' class='odd'>
75
        <strong>". _AM_LEXIKON_SHOWCATS . ' (' . $totalcategories . ')'. "</strong></td></TR>";
76
        echo "<tr>";
77
        // create existing columns table //doppio
78
        $resultC1 = $xoopsDB -> query( "SELECT COUNT(*)
79
                                       FROM " . $xoopsDB -> prefix( "lxcategories" ) . " " );
80
        list( $numrows ) = $xoopsDB -> fetchRow( $resultC1 );
81
82
        $sql = "SELECT *
83
               FROM " . $xoopsDB -> prefix( "lxcategories" ) . "
84
               ORDER BY weight";
85
        $resultC2 = $xoopsDB -> query( $sql, $xoopsModuleConfig['perpage'], $startcat );
86
87
        echo "<th width='40'  align='center'><b>" . _AM_LEXIKON_ID . "</b></td>
88
        <th  align='center'><b>" . _AM_LEXIKON_WEIGHT . "</b></td>
89
        <th width='30%'  align='center'><b>" . _AM_LEXIKON_CATNAME . "</b></td>
90
        <th width='10'  align='center'><b>" . _AM_LEXIKON_ENTRIES . "</b></td>
91
        <th width='*'  align='center'><b>" . _AM_LEXIKON_DESCRIP . "</b></td>
92
        <th width='60'  align='center'><b>" . _AM_LEXIKON_ACTION . "</b></td>
93
        </tr>";
94
95
        $class   = "odd";
96
        if ( $numrows > 0 ) // That is, if there ARE columns in the system
97
        {
98
            while ( list( $categoryID, $name, $description, $total, $weight ) = $xoopsDB -> fetchrow( $resultC2 ) )
99
                //while ( list( $categoryID, $name, $description, $total, $weight, ) = $xoopsDB -> fetchrow( $resultC2 ) )
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
100
            {
101
                $name = $myts -> htmlSpecialChars( $name );
102
//                $description = $myts -> htmlSpecialChars(xoops_substr( strip_tags( $description ),0,60));
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
103
                $description = strip_tags(htmlspecialchars_decode($description));
104
                $modify = "<a href='category.php?op=mod&categoryID=" . $categoryID . "'><img src=" . $pathIcon16."/edit.png width='16' height='16' ALT='"._AM_LEXIKON_EDITCAT."'></a>";
105
                $delete = "<a href='category.php?op=del&categoryID=" . $categoryID . "'><img src=" . $pathIcon16."/delete.png  width='16' height='16' ALT='"._AM_LEXIKON_DELETECAT."'></a>";
106
107
                echo "<tr class='" . $class . "'>";
108
                $class = ($class == "even") ? "odd" : "even";
109
110
                echo "
111
                <td  align='center'>" . $categoryID . "</td>
112
                <td  width='10' align='center'>" . $weight . "</td>
113
                <td  align='left'><a href='../category.php?categoryID=" . $categoryID . "'>" . $name . "</td>
114
                <td  align='left'>" . $total . "</td>
115
                <td  align='left'>" . $description . "</td>
116
                <td  align='center'> $modify $delete </td>
117
                </tr></DIV>";
118
            }
119
        }
120
        else // that is, $numrows = 0, there's no columns yet
121
        {
122
            echo "<tr>";
123
            echo "<td class='odd' align='center' colspan= '7'>"._AM_LEXIKON_NOCATS."</td>";
124
            echo "</tr></DIV>";
125
            $categoryID = '0';
0 ignored issues
show
Unused Code introduced by
$categoryID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
126
        }
127
        echo "</table>\n";
128
        $pagenav = new XoopsPageNav( $numrows, $xoopsModuleConfig['perpage'], $startcat, 'startcat' );
129
        echo '<div style="text-align:right;">' . $pagenav -> renderNav(8) . '</div>';
130
        echo "<br /><br />\n";
131
        echo "</div>";
132
    } else {
133
        redirect_header( "index.php", 1, sprintf( _AM_LEXIKON_SINGLECAT, '' ) );
134
    }
135
}
136
137
/**
138
 * Code to edit categories
139
 **/
140
function categoryEdit( $categoryID = '' ) {
141
    include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
142
    include_once XOOPS_ROOT_PATH."/class/uploader.php";
143
    include_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php';
144
    
145
    $weight = 1;
146
    $name = '';
147
    $description = '';
148
    $logourl = '';
149
150
    Global $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
151
152
    // If there is a parameter, and the id exists, retrieve data: we're editing a column
153
    if ( $categoryID ) {
154
        $result = $xoopsDB -> query( "
155
                                     SELECT categoryID, name, description, total, weight,logourl
156
                                     FROM " . $xoopsDB -> prefix( "lxcategories" ) . "
157
                                     WHERE categoryID = '$categoryID'" );
158
159
        list( $categoryID, $name, $description, $total, $weight, $logourl ) = $xoopsDB -> fetchrow( $result );
0 ignored issues
show
Unused Code introduced by
The assignment to $total is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
160
        $myts =& MyTextSanitizer::getInstance();
161
        $name = $myts->htmlSpecialChars($name);
162
        //permissions
163
        $member_handler = & xoops_gethandler('member');
164
        $group_list = & $member_handler -> getGroupList();
165
        $gperm_handler = & xoops_gethandler('groupperm');
166
167
        $groups = $gperm_handler -> getGroupIds("lexikon_view", $categoryID, $xoopsModule -> getVar('mid'));
168
        $groups = $groups;
0 ignored issues
show
Bug introduced by
Why assign $groups to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
169
        if ( $xoopsDB -> getRowsNum( $result ) == 0 ) {
170
            redirect_header( "index.php", 1, _AM_LEXIKON_NOCATTOEDIT );
171
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categoryEdit() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
172
        }
173
        if ( $xoopsDB -> getRowsNum( $result ) == 0 ) {
174
            redirect_header( "index.php", 1, _AM_LEXIKON_NOCATTOEDIT );
175
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categoryEdit() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
176
        }
177
        //$myts =& MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
178
//        lx_adminMenu(1, _AM_LEXIKON_CATS);
179
180
        echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_CATSHEADER . "</h3>";
181
        $sform = new XoopsThemeForm( _AM_LEXIKON_MODCAT . ": $name" , "op", xoops_getenv( 'PHP_SELF' ) );
182
    } else {
183
        //$myts =& MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
184
//        lx_adminMenu(1, _AM_LEXIKON_CATS);
185
         $groups = true;
186
        echo "<h3 style=\"color: #2F5376; margin-top: 6px; \">" . _AM_LEXIKON_CATSHEADER . "</h3>";
187
        $sform = new XoopsThemeForm( _AM_LEXIKON_NEWCAT, "op", xoops_getenv( 'PHP_SELF' ) );
188
    }
189
190
    $sform -> setExtra( 'enctype="multipart/form-data"' );
191
    $sform -> addElement( new XoopsFormText( _AM_LEXIKON_CATNAME, 'name', 50, 80, $name ), true );
192
193
    $editor = lx_getWysiwygForm( _AM_LEXIKON_CATDESCRIPT, 'description', $description, 7, 60 );
194
    $sform -> addElement( $editor,true );
195
    unset($editor);
196
197
    $sform -> addElement( new XoopsFormText( _AM_LEXIKON_CATPOSIT, 'weight', 4, 4, $weight ), true );
198
    $sform -> addElement( new XoopsFormHidden( 'categoryID', $categoryID ) );
199
    //CategoryImage
200
    if ($xoopsModuleConfig['useshots'] == 1) {
201
        //CategoryImage :: Common querys from Article module by phppp
202
       $image_option_tray = new XoopsFormElementTray("<b>"._AM_LEXIKON_CATIMGUPLOAD."</b>", "<br />");
203
       $image_option_tray->addElement(new XoopsFormFile("", "userfile",""));
204
       $sform->addElement($image_option_tray);
205
       unset($image_tray);
206
       unset($image_option_tray);
207
208
       $path_catimg = "modules/".$xoopsModule->getVar('dirname')."/images/uploads";
209
       $image_option_tray = new XoopsFormElementTray(_AM_LEXIKON_CATIMAGE."<br />"._AM_LEXIKON_CATIMG_DSC."<br />".$path_catimg, "<br />");
210
       //$image_option_tray = new XoopsFormElementTray(_AM_LEXIKON_CATIMAGE.'');
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
211
       $image_array =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/".$path_catimg."/");
212
       array_unshift($image_array, _NONE);
213
214
       $image_select = new XoopsFormSelect("", "logourl", $logourl);
215
       $image_select->addOptionArray($image_array);
216
       $image_select->setExtra("onchange=\"showImgSelected('img', 'logourl', '/".$path_catimg."/', '', '" . XOOPS_URL . "')\"");
217
       $image_tray = new XoopsFormElementTray("", "&nbsp;");
218
       $image_tray->addElement($image_select);
219
       if (!empty($logourl) && file_exists(XOOPS_ROOT_PATH . "/" .$path_catimg."/" . $logourl)){
220
           $image_tray->addElement(new XoopsFormLabel("", "<div style=\"padding: 4px;\"><img src=\"" . XOOPS_URL . "/" .$path_catimg."/" . $logourl . "\" name=\"img\" id=\"img\" alt=\"\" /></div>"));
221
           } else {
222
           $image_tray->addElement(new XoopsFormLabel("", "<div style=\"padding: 4px;\"><img src=\"" . XOOPS_URL . "/" .$path_catimg."/blank.gif\" name=\"img\" id=\"img\" alt=\"\" /></div>"));
223
       }
224
       $image_option_tray->addElement($image_tray);
225
       $sform->addElement($image_option_tray);
226
    }
227
    $sform -> addElement(new XoopsFormSelectGroup(_AM_LEXIKON_CAT_GROUPSVIEW, "groups", true, $groups, 5, true));
228
    
229
    $button_tray = new XoopsFormElementTray( '', '' );
230
    $hidden = new XoopsFormHidden( 'op', 'addcategory' );
231
    $button_tray -> addElement( $hidden );
232
233
    // No ID for column -- then it's new column, button says 'Create'
234 View Code Duplication
    if ( !$categoryID ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
235
        $butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_CREATE, 'submit' );
236
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
237
        $button_tray->addElement( $butt_create );
238
239
        $butt_clear = new XoopsFormButton( '', '', _AM_LEXIKON_CLEAR, 'reset' );
240
        $button_tray->addElement( $butt_clear );
241
242
        $butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' );
243
        $butt_cancel->setExtra('onclick="history.go(-1)"');
244
        $button_tray->addElement( $butt_cancel );
245
    } else // button says 'Update'
246
    {
247
        $butt_create = new XoopsFormButton( '', '', _AM_LEXIKON_MODIFY, 'submit' );
248
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
249
        $button_tray->addElement( $butt_create );
250
251
        $butt_cancel = new XoopsFormButton( '', '', _AM_LEXIKON_CANCEL, 'button' );
252
        $butt_cancel->setExtra('onclick="history.go(-1)"');
253
        $button_tray->addElement( $butt_cancel );
254
    }
255
256
    $sform -> addElement( $button_tray );
257
    $sform -> display();
258
    unset( $hidden );
259
//  xoops_cp_footer();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
260
//  break;
261
}
262
263
/**
264
 * Code to delete existing categories
265
 **/
266
function categoryDelete($categoryID = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $categoryID is not used and could be removed.

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

Loading history...
Coding Style introduced by
categoryDelete uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
categoryDelete uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
267
    //global $xoopsDB, $xoopsConfig;
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
268
    global $xoopsConfig, $xoopsDB, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
269
    $idc = isset($_POST['categoryID']) ? intval($_POST['categoryID']) : intval($_GET['categoryID']);
270
    if ($idc == '') $idc = $_GET['categoryID'];
271
    if ($idc <= 0) {
272
        header('location: category.php');
273
        die();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categoryDelete() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
274
    }
275
276
    $ok = isset($_POST['ok']) ? intval($_POST['ok']) : 0;
277
    $result = $xoopsDB -> query( "SELECT categoryID, name FROM " . $xoopsDB -> prefix( "lxcategories" ) . " WHERE categoryID = $idc" );
278
    list( $categoryID, $name ) = $xoopsDB -> fetchrow( $result );
279
    // confirmed, so delete
280
    if ( $ok == 1 ) {
281
        //get all entries in the category
282
        $result3=$xoopsDB->query("SELECT entryID from ".$xoopsDB->prefix("lxentries")." where categoryID = $idc");
283
        //now for each entry, delete the coments
284
        while ( list($entryID)=$xoopsDB->fetchRow($result3) ) {
285
            xoops_comment_delete($xoopsModule->getVar('mid'), $entryID);
286
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'term', $entryID);
287
        }
288
        $xoopsDB->query("DELETE FROM ".$xoopsDB->prefix('lxcategories')." WHERE categoryID='$idc'");
289
        $result2 = $xoopsDB -> query( "DELETE FROM " .$xoopsDB -> prefix("lxentries")." WHERE categoryID = $idc");
0 ignored issues
show
Unused Code introduced by
$result2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
290
        // remove permissions
291
        xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_view', $categoryID);
292
        xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_submit', $categoryID);
293
        xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_approve', $categoryID);
294
        xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'lexikon_request', $categoryID);
295
        // delete notifications
296
        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'global', $categoryID);
297
        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'category', $categoryID);
298
        
299
        redirect_header("category.php",1,sprintf( _AM_LEXIKON_CATISDELETED, $name ) );
300
        exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categoryDelete() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
301
    } else {
302
        //xoops_cp_header();
303
        xoops_confirm(array('op' => 'del', 'categoryID' => $categoryID, 'ok' => 1, 'name' => $name ), 'category.php', _AM_LEXIKON_DELETETHISCAT . "<br /><br>" . $name, _AM_LEXIKON_DELETE );
304
    }
305
}
306
307
function categorySave ($categoryID = '') {
0 ignored issues
show
Coding Style introduced by
categorySave uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
categorySave uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
categorySave uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
308
    include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
309
    include_once XOOPS_ROOT_PATH."/class/uploader.php";
310
    Global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule, $xoopsDB, $myts, $categoryID;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
311
    //print_r ($_POST);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
312
    $categoryID = isset( $_POST['categoryID'] ) ? intval( $_POST['categoryID'] ) : intval( $_GET['categoryID'] );
313
    $weight = isset($_POST['weight'] ) ? intval($_POST['weight']) : intval($_GET['weight']);
314
    $name = isset($_POST['name'] ) ? htmlSpecialChars($_POST['name']) : htmlSpecialChars($_GET['name']);
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
315
    $description = isset($_POST['description'] ) ? htmlSpecialChars($_POST['description']) : htmlSpecialChars($_GET['description']);
316
    //$description = $myts->xoopsCodeDecode($description, $allowimage = 0);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
317
    $description = $myts -> xoopsCodeDecode($myts->censorString($description), $allowimage = 1);
318
    $name = $myts->addSlashes($_POST['name']);
319
    $logourl = $myts->addSlashes($_POST["logourl"]);
0 ignored issues
show
Unused Code introduced by
$logourl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
320
    $groups = isset($_POST['groups']) ? $_POST['groups'] : array();
321
    // image upload
322
    $logourl = "";
323
    $maxfilesize = 30000;
324
    $maxfilewidth = 128;
325
    $maxfileheight = 128;
326
      if (!empty($_FILES['userfile']['name'])) {
327
        $allowed_mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
328
        $uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH ."/modules/".$xoopsModule->getVar('dirname')."/images/uploads/", $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
329
        if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
330
          if (!$uploader->upload()) {
331
             echo $uploader->getErrors();
332
          } else {
333
             echo '<h4>'._AM_LEXIKON_FILESUCCESS.'</h4>';
334
             $logourl = $uploader->getSavedFileName();
335
          }
336
        } else {
337
          echo $uploader->getErrors();
338
        }
339
     }
340
    $logourl = empty($logourl)?(empty($_POST['logourl'])?"":$_POST['logourl']):$logourl;
341
    
342
    // Run the query and update the data
343
    if ( !$_POST['categoryID'] ) {
344
        if ( $xoopsDB -> query( "INSERT INTO " . $xoopsDB -> prefix( "lxcategories" ) . " (categoryID, name, description, weight, logourl)
345
								 VALUES ('', '$name', '$description', '$weight', '$logourl')" ) ) {
346
            $newid = $xoopsDB->getInsertId();
347
            // Increment author's posts count (only if it's a new definition)
348 View Code Duplication
            if (is_object($xoopsUser) && empty($categoryID)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
349
                $member_handler = &xoops_gethandler('member');
350
                $submitter =& $member_handler -> getUser($uid);
0 ignored issues
show
Bug introduced by
The variable $uid does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
351
                if (is_object($submitter) ) {
352
                    $submitter -> setVar('posts',$submitter -> getVar('posts') + 1);
353
                    $res=$member_handler -> insertUser($submitter, true);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
354
                    unset($submitter);
355
                }
356
            }
357
            //notification
358
            if(!empty($xoopsModuleConfig['notification_enabled']) ){
359
                if ($newid == 0) {
360
                    $newid = $xoopsDB -> getInsertId();
361
                }
362
                global $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
363
                $notification_handler =& xoops_gethandler('notification');
364
                $tags = array();
365
                $tags['ITEM_NAME'] = $name;
366
                $tags['ITEM_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $newid;
367
                $notification_handler->triggerEvent( 'global', 0, 'new_category', $tags);
368
            }
369
            lx_save_Permissions($groups, $categoryID, "lexikon_view");
370
            redirect_header( "category.php", 1, _AM_LEXIKON_CATCREATED );
371
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categorySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
372
        } else {
373
            redirect_header( "index.php", 1, _AM_LEXIKON_NOTUPDATED );
374
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categorySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
375
        }
376
    } else {
377
        if ( $xoopsDB -> queryF( "
378
								UPDATE " . $xoopsDB -> prefix( "lxcategories" ) . "
379
								SET name = '$name', description = '$description', weight = '$weight' , logourl = '$logourl'
380
								WHERE categoryID = '$categoryID'" ) ) {
381
            lx_save_Permissions($groups, $categoryID, "lexikon_view");
382
            redirect_header( "category.php", 1, _AM_LEXIKON_CATMODIFIED );
383
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categorySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
384
        } else {
385
            redirect_header( "index.php", 1, _AM_LEXIKON_NOTUPDATED );
386
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function categorySave() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
387
        }
388
    }
389
}
390
391
/**
392
 * Available operations
393
 **/
394
395
$op = 'default';
396 View Code Duplication
if (isset($_POST['op'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
    $op=$_POST['op'];
398
} else {
399
    if (isset($_GET['op'])) {
400
        $op=$_GET['op'];
401
    }
402
}
403
404
switch ( $op ) {
405
case "mod":
406
    $categoryID = isset( $_POST['categoryID'] ) ? intval( $_POST['categoryID'] ) : intval( $_GET['categoryID'] );
407
    categoryEdit( $categoryID );
408
    break;
409
410
case "addcat":
411
    categoryEdit();
412
    break;
413
414
case "addcategory":
415
    categorySave();
416
    break;
417
418
case "del":
419
    categoryDelete();
420
    break;
421
422
case "default":
423
default:
424
    categoryDefault();
425
    break;
426
}
427
xoops_cp_footer();
428