Completed
Push — master ( 26776f...d9604e )
by Michael
11:31
created

department.php ➔ _clearAddSessionVars()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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 100 and the first side effect is on line 3.

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
//$Id: department.php,v 1.22 2005/11/29 17:48:12 ackbarr Exp $
3
include('../../../include/cp_header.php');
4
include_once('admin_header.php');
5
include_once(XOOPS_ROOT_PATH . '/class/pagenav.php');
6
require_once(XHELP_CLASS_PATH . '/xhelpForm.php');
7
require_once(XHELP_CLASS_PATH . '/xhelpFormRadio.php');
8
require_once(XHELP_CLASS_PATH . '/xhelpFormCheckbox.php');
9
10
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...
11
$module_id = $xoopsModule->getVar('mid');
12
13
$start = $limit = 0;
14
if (isset($_REQUEST['limit'])) {
15
    $limit = intval($_REQUEST['limit']);
16
}
17
if (isset($_REQUEST['start'])) {
18
    $start = intval($_REQUEST['start']);
19
}
20
if (!$limit) {
21
    $limit = 15;
22
}
23
if(isset($_REQUEST['order'])){
24
    $order = $_REQUEST['order'];
25
} else {
26
    $order = "ASC";
27
}
28
if(isset($_REQUEST['sort'])) {
29
    $sort = $_REQUEST['sort'];
30
} else {
31
    $sort = "department";
32
}
33
$dept_search = false;
34
if(isset($_REQUEST['dept_search'])) {
35
    $dept_search = $_REQUEST['dept_search'];
36
}
37
38
$aSortBy = array('id' => _AM_XHELP_TEXT_ID, 'department' => _AM_XHELP_TEXT_DEPARTMENT);
39
$aOrderBy = array('ASC' => _AM_XHELP_TEXT_ASCENDING, 'DESC' => _AM_XHELP_TEXT_DESCENDING);
40
$aLimitBy = array('10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100);
41
42
$op = 'default';
43
44
if ( isset( $_REQUEST['op'] ) )
45
{
46
    $op = $_REQUEST['op'];
47
}
48
49
switch ( $op )
50
{
51
    case "activateMailbox":
52
        activateMailbox();
53
        break;
54
55
    case "AddDepartmentServer":
56
        addDepartmentServer();
57
        break;
58
59
    case "DeleteDepartmentServer":
60
        DeleteDepartmentServer();
61
        break;
62
63
    case "deleteStaffDept":
64
        deleteStaffDept();
65
        break;
66
67
    case "editDepartment":
68
        editDepartment();
69
        break;
70
71
    case "EditDepartmentServer":
72
        EditDepartmentServer();
73
        break;
74
75
    case "manageDepartments":
76
        manageDepartments();
77
        break;
78
79
    case "testMailbox":
80
        testMailbox();
81
        break;
82
83
    case "clearAddSession":
84
        clearAddSession();
85
        break;
86
87
    case "clearEditSession":
88
        clearEditSession();
89
        break;
90
91
    case "updateDefault":
92
        updateDefault();
93
        break;
94
95
    default:
96
        header("Location: ".XHELP_BASE_URL."/admin/index.php");
97
        break;
98
}
99
100
function activateMailbox()
0 ignored issues
show
Coding Style introduced by
activateMailbox 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...
101
{
102
    $id = intval($_GET['id']);
103
    $setstate = intval($_GET['setstate']);
104
105
    $hMailbox =& xhelpGetHandler('departmentMailBox');
106
    if ($mailbox =& $hMailbox->get($id)) {
107
        $url = XHELP_BASE_URL.'/admin/department.php?op=editDepartment&id='. $mailbox->getVar('departmentid');
108
        $mailbox->setVar('active', $setstate);
109
        if ($hMailbox->insert($mailbox, true)) {
110
            header("Location: $url");
111
        } else {
112
            redirect_header($url, 3, _AM_XHELP_DEPARTMENT_SERVER_ERROR);
113
        }
114
    } else {
115
        redirect_header(XHELP_BASE_URL.'/admin/department.php?op=manageDepartments', 3, _XHELP_NO_MAILBOX_ERROR);
116
    }
117
}
118
119
function addDepartmentServer()
0 ignored issues
show
Coding Style introduced by
addDepartmentServer 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
addDepartmentServer 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...
120
{
121
    if(isset($_GET['id'])){
122
        $deptID = intval($_GET['id']);
123
    } else {
124
        redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, _AM_XHELP_DEPARTMENT_NO_ID);
125
    }
126
127
    $hDeptServers =& xhelpGetHandler('departmentMailBox');
128
    $server = $hDeptServers->create();
129
    $server->setVar('departmentid',$deptID);
0 ignored issues
show
Bug introduced by
The variable $deptID does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
130
    $server->setVar('emailaddress', $_POST['emailaddress']);
131
    $server->setVar('server',       $_POST['server']);
132
    $server->setVar('serverport',   $_POST['port']);
133
    $server->setVar('username',     $_POST['username']);
134
    $server->setVar('password',     $_POST['password']);
135
    $server->setVar('priority',     $_POST['priority']);
136
    //
137
    if ($hDeptServers->insert($server))   {
138
        header("Location: ".XHELP_ADMIN_URL."/department.php?op=manageDepartments");
139
    } else {
140
        redirect_header(XHELP_ADMIN_URL.'/department.php?op=manageDepartments', 3, _AM_XHELP_DEPARTMENT_SERVER_ERROR);
141
    }
142
}
143
144
function DeleteDepartmentServer() {
0 ignored issues
show
Coding Style introduced by
DeleteDepartmentServer uses the super-global variable $_REQUEST 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
DeleteDepartmentServer 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...
145
146
    if(isset($_REQUEST['id'])){
147
        $emailID = intval($_REQUEST['id']);
148
    } else {
149
        redirect_header(XHELP_ADMIN_URL.'/department.php?op=manageDepartments', 3, _AM_XHELP_DEPARTMENT_SERVER_NO_ID);
150
    }
151
152
    $hDeptServers =& xhelpGetHandler('departmentMailBox');
153
    $server       =& $hDeptServers->get($emailID);
0 ignored issues
show
Bug introduced by
The variable $emailID does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
154
155
    if (!isset($_POST['ok'])) {
156
        xoops_cp_header();
157
        //echo $oAdminButton->renderButtons('manDept');
158
        $indexAdmin = new ModuleAdmin();
159
        echo $indexAdmin->addNavigation('department.php');
160
161
        xoops_confirm(array('op' => 'DeleteDepartmentServer', 'id' => $emailID, 'ok' => 1), XHELP_BASE_URL .'/admin/department.php', sprintf(_AM_XHELP_MSG_DEPT_MBOX_DEL_CFRM, $server->getVar('emailaddress')));
162
        xoops_cp_footer();
163
    } else {
164
        //get handler
165
        if ($hDeptServers->delete($server,true)) {
166
            header("Location: ".XHELP_ADMIN_URL."/department.php?op=manageDepartments");
167
        } else {
168
            redirect_header(XHELP_ADMIN_URL.'/department.php?op=manageDepartments', 3, _AM_XHELP_DEPARTMENT_SERVER_DELETE_ERROR);
169
        }
170
    }
171
}
172
173
function deleteStaffDept()
0 ignored issues
show
Coding Style introduced by
deleteStaffDept 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
deleteStaffDept 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...
174
{
175
    if(isset($_GET['deptid'])){
176
        $deptID = intval($_GET['deptid']);
177
    } else {
178
        redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_NO_DEPTID);
179
    }
180
    if(isset($_GET['uid'])){
181
        $staffID = intval($_GET['uid']);
182
    } elseif(isset($_POST['staff'])){
183
        $staffID = $_POST['staff'];
184
    } else {
185
        redirect_header(XHELP_ADMIN_URL."/department.php?op=editDepartment&deptid=$deptID", 3, _AM_XHELP_MSG_NO_UID);
0 ignored issues
show
Bug introduced by
The variable $deptID does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
186
    }
187
188
    $hMembership =& xhelpGetHandler('membership');
189
    if(is_array($staffID)){
190
        foreach($staffID as $sid){
0 ignored issues
show
Bug introduced by
The variable $staffID does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
191
            $ret = $hMembership->removeDeptFromStaff($deptID, $sid);
192
        }
193
    } else {
194
        $ret = $hMembership->removeDeptFromStaff($deptID, $staffID);
195
    }
196
197
    if($ret){
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
198
        header("Location: ".XHELP_ADMIN_URL."/department.php?op=editDepartment&deptid=$deptID");
199
    } else {
200
        redirect_header(XHELP_ADMIN_URL."/department.php??op=editDepartment&deptid=$deptID", 3, _AM_XHELP_MSG_REMOVE_STAFF_DEPT_ERR);
201
    }
202
}
203
204
function editDepartment()
0 ignored issues
show
Coding Style introduced by
editDepartment uses the super-global variable $_SERVER 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
editDepartment uses the super-global variable $_REQUEST 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
editDepartment 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...
205
{
206
    $_xhelpSession = Session::singleton();
207
    global $imagearray, $xoopsModule, $limit, $start, $xoopsModuleConfig;
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...
208
    $module_id = $xoopsModule->getVar('mid');
209
    $displayName =& $xoopsModuleConfig['xhelp_displayName'];    // Determines if username or real name is displayed
210
211
    $_xhelpSession->set("xhelp_return_page", substr(strstr($_SERVER['REQUEST_URI'], 'admin/'), 6));
212
213 View Code Duplication
    if(isset($_REQUEST["deptid"])){
214
        $deptID = $_REQUEST['deptid'];
215
    } else {
216
        redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_NO_DEPTID);
217
    }
218
219
    $hDepartments  =& xhelpGetHandler('department');
220
    $hGroups =& xoops_gethandler('group');
221
    $hGroupPerm =& xoops_gethandler('groupperm');
222
223
    if(isset($_POST['updateDept'])){
224
        $groups = (isset($_POST['groups']) ? $_POST['groups'] : array());
225
226
        $hasErrors = false;
227
        //Department Name supplied?
228
        if (trim($_POST['newDept']) == '') {
229
            $hasErrors = true;
230
            $errors['newDept'][] = _AM_XHELP_MESSAGE_NO_DEPT;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$errors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errors = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
231
        } else {
232
233
            //Department Name unique?
234
            $crit = new CriteriaCompo(new Criteria('department', $_POST['newDept']));
235
            $crit->add(new Criteria('id', $deptID, '!='));
0 ignored issues
show
Bug introduced by
The variable $deptID does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
236 View Code Duplication
            if($existingDepts = $hDepartments->getCount($crit)){
0 ignored issues
show
Unused Code introduced by
$existingDepts 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...
237
                $hasErrors = true;
238
                $errors['newDept'][] = _XHELP_MESSAGE_DEPT_EXISTS;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$errors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $errors = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
239
240
            }
241
        }
242
243
        if ($hasErrors) {
244
            $session =& Session::singleton();
245
            //Store existing dept info in session, reload addition page
246
            $aDept = array();
247
            $aDept['newDept'] = $_POST['newDept'];
248
            $aDept['groups'] = $groups;
249
            $session->set("xhelp_editDepartment_$deptID", $aDept);
250
            $session->set("xhelp_editDepartmentErrors_$deptID", $errors);
0 ignored issues
show
Bug introduced by
The variable $errors does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
251
            header('Location: '. xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'editDepartment', 'deptid'=>$deptID), false));
252
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function editDepartment() 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...
253
        }
254
255
        $dept =& $hDepartments->get($deptID);
256
257
        $oldDept = $dept;
258
        $groups = $_POST['groups'];
259
260
        // Need to remove old group permissions first
261
        $crit = new CriteriaCompo(new Criteria('gperm_modid', $module_id));
262
        $crit->add(new Criteria('gperm_itemid', $deptID));
263
        $crit->add(new Criteria('gperm_name', _XHELP_GROUP_PERM_DEPT));
264
        $hGroupPerm->deleteAll($crit);
265
266
        foreach($groups as $group){     // Add new group permissions
267
            $hGroupPerm->addRight(_XHELP_GROUP_PERM_DEPT, $deptID, $group, $module_id);
268
        }
269
270
        $dept->setVar('department', $_POST['newDept']);
271
272
        if($hDepartments->insert($dept)){
273
            $message = _XHELP_MESSAGE_UPDATE_DEPT;
0 ignored issues
show
Unused Code introduced by
$message 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...
274
275
            // Update default dept
276
            if(isset($_POST['defaultDept']) && ($_POST['defaultDept'] == 1)){
277
                xhelpSetMeta("default_department", $dept->getVar('id'));
278 View Code Duplication
            } else {
279
                $depts =& $hDepartments->getObjects();
280
                $aDepts = array();
281
                foreach($depts as $dpt){
282
                    $aDepts[] = $dpt->getVar('id');
283
                }
284
                xhelpSetMeta("default_department", $aDepts[0]);
285
            }
286
287
            // Edit configoption for department
288
            $hConfigOption =& xoops_gethandler('configoption');
289
            $crit = new CriteriaCompo(new Criteria('confop_name', $oldDept->getVar('department')));
290
            $crit->add(new Criteria('confop_value', $oldDept->getVar('id')));
291
            $confOption =& $hConfigOption->getObjects($crit);
292
293
            if(count($confOption) > 0){
294
                $confOption[0]->setVar('confop_name', $dept->getVar('department'));
295
296
                if(!$hConfigOption->insert($confOption[0])){
297
                    redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_UPDATE_CONFIG_ERR);
298
                }
299
            }
300
            _clearEditSessionVars($deptID);
301
            header("Location: ".XHELP_ADMIN_URL."/department.php?op=manageDepartments");
302
        } else {
303
            $message = _XHELP_MESSAGE_UPDATE_DEPT_ERROR . $dept->getHtmlErrors();
304
            redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, $message);
305
        }
306
307
    } else {
308
        xoops_cp_header();
309
        //echo $oAdminButton->renderButtons('manDept');
310
311
        $dept =& $hDepartments->get($deptID);
312
313
        $session =& Session::singleton();
314
        $sess_dept = $session->get("xhelp_editDepartment_$deptID");
315
        $sess_errors = $session->get("xhelp_editDepartmentErrors_$deptID");
316
317
        //Display any form errors
318
        if (! $sess_errors === false) {
319
            xhelpRenderErrors($sess_errors, xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'clearEditSession', 'deptid'=>$deptID)));
320
        }
321
322
        $indexAdmin = new ModuleAdmin();
323
        echo $indexAdmin->addNavigation('department.php?op=editDepartment');
324
325
        // Get list of groups with permission
326
        $crit = new CriteriaCompo(new Criteria('gperm_modid', $module_id));
327
        $crit->add(new Criteria('gperm_itemid', $deptID));
328
        $crit->add(new Criteria('gperm_name', _XHELP_GROUP_PERM_DEPT));
329
        $group_perms =& $hGroupPerm->getObjects($crit);
330
331
        $aPerms = array();      // Put group_perms in usable format
332
        foreach($group_perms as $perm){
333
            $aPerms[$perm->getVar('gperm_groupid')] = $perm->getVar('gperm_groupid');
334
        }
335
336 View Code Duplication
        if (! $sess_dept === false) {
337
            $fld_newDept = $sess_dept['newDept'];
338
            $fld_groups  = $sess_dept['groups'];
339
        } else {
340
            $fld_newDept = $dept->getVar('department');
341
            $fld_groups = $aPerms;
342
        }
343
344
        // Get list of all groups
345
        $crit = new Criteria('', '');
346
        $crit->setSort('name');
347
        $crit->setOrder('ASC');
348
        $groups =& $hGroups->getObjects($crit, true);
349
350
        $aGroups = array();
351
        foreach($groups as $group_id=>$group){
352
            $aGroups[$group_id] = $group->getVar('name');
353
        }
354
        asort($aGroups);    // Set groups in alphabetical order
355
356
        echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>';
357
        $form = new xhelpForm(_AM_XHELP_EDIT_DEPARTMENT, 'edit_dept', xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'editDepartment', 'deptid' => $deptID)));
358
        $dept_name = new XoopsFormText(_AM_XHELP_TEXT_EDIT_DEPT, 'newDept', 20, 35, $fld_newDept);
359
        $group_select = new XoopsFormSelect(_AM_XHELP_TEXT_EDIT_DEPT_PERMS, 'groups', $fld_groups, 6, true);
360
        $group_select->addOptionArray($aGroups);
361
        $defaultDeptID = xhelpGetMeta("default_department");
362
        $defaultDept = new xhelpFormCheckbox(_AM_XHELP_TEXT_DEFAULT_DEPT, 'defaultDept', (($defaultDeptID == $deptID) ? 1 : 0), 'defaultDept');
363
        $defaultDept->addOption(1, "");
364
        $btn_tray = new XoopsFormElementTray('');
365
        $btn_tray->addElement(new XoopsFormButton('', 'updateDept', _AM_XHELP_BUTTON_SUBMIT, 'submit'));
366
        $form->addElement($dept_name);
367
        $form->addElement($group_select);
368
        $form->addElement($defaultDept);
369
        $form->addElement($btn_tray);
370
        $form->setLabelWidth('20%');
371
        echo $form->render();
372
373
        // Get dept staff members
374
        $hMembership =& xhelpGetHandler('membership');
375
        $hMember =& xoops_gethandler('member');
376
        $hStaffRole =& xhelpGetHandler('staffRole');
377
        $hRole =& xhelpGetHandler('role');
378
379
        $staff = $hMembership->membershipByDept($deptID, $limit, $start);
380
        $crit = new Criteria('j.department', $deptID);
381
        $staffCount =& $hMembership->getCount($crit);
382
        $roles =& $hRole->getObjects(null, true);
383
384
        echo "<form action='".XHELP_ADMIN_URL."/department.php?op=deleteStaffDept&amp;deptid=".$deptID."' method='post'>";
385
        echo "<table width='100%' cellspacing='1' class='outer'>
386
              <tr><th colspan='".(3+count($roles))."'><label>". _AM_XHELP_MANAGE_STAFF ."</label></th></tr>";
387
388
        if($staffCount > 0){
389
            $aStaff = array();
390
            foreach($staff as $stf){
391
                $aStaff[$stf->getVar('uid')] = $stf->getVar('uid');     // Get array of staff uid
392
            }
393
394
            // Get user list
395
            $crit = new Criteria('uid', "(". implode($aStaff, ',') .")", "IN");
396
            //$members =& $hMember->getUserList($crit);
397
            $members =& xhelpGetUsers($crit, $displayName);
398
399
            // Get staff roles
400
            $crit = new CriteriaCompo(new Criteria('uid', "(". implode($aStaff, ',') .")", "IN"));
401
            $crit->add(new Criteria('deptid', $deptID));
402
            $staffRoles =& $hStaffRole->getObjects($crit);
403
            unset($aStaff);
404
405
            $staffInfo = array();
406
            foreach($staff as $stf){
407
                $staff_uid = $stf->getVar('uid');
408
                $staffInfo[$staff_uid]['uname'] = $members[$staff_uid];
409
                $aRoles = array();
410
                foreach($staffRoles as $role){
411
                    $role_id = $role->getVar('roleid');
412
                    if($role->getVar('uid') == $staff_uid){
413
                        $aRoles[$role_id] = $roles[$role_id]->getVar('name');
414
                    }
415
                    $staffInfo[$staff_uid]['roles'] = implode($aRoles, ', ');
416
                }
417
            }
418
            $nav = new XoopsPageNav($staffCount, $limit, $start, 'start', "op=editDepartment&amp;deptid=$deptID&amp;limit=$limit");
419
420
            echo "<tr class='head'><td rowspan='2'>"._AM_XHELP_TEXT_ID."</td><td rowspan='2'>"._AM_XHELP_TEXT_USER."</td><td colspan='".count($roles)."'>"._AM_XHELP_TEXT_ROLES."</td><td rowspan='2'>"._AM_XHELP_TEXT_ACTIONS."</td></tr>";
421
            echo "<tr class='head'>";
422
            foreach ($roles as $thisrole) echo "<td>".$thisrole->getVar('name')."</td>";
423
            echo "</tr>";
424
            foreach($staffInfo as $uid=>$staff){
425
                echo "<tr class='even'>
426
                          <td><input type='checkbox' name='staff[]' value='".$uid."' />".$uid."</td>
427
                          <td>".$staff['uname']."</td>";
428
                foreach ($roles as $thisrole) {
429
                    echo "<td><img src='".XHELP_BASE_URL."/images/";
430
                    echo (in_array($thisrole->getVar('name'),explode(', ',$staff['roles']))) ? "on.png" : "off.png";
431
                    echo "' /></td>";
432
                }
433
                echo "    <td>
434
                          <a href='".XHELP_ADMIN_URL."/staff.php?op=editStaff&amp;uid=".$uid."'><img src='".XOOPS_URL."/modules/xhelp/images/button_edit.png' title='"._AM_XHELP_TEXT_EDIT."' name='editStaff' /></a>&nbsp;
435
                          <a href='".XHELP_ADMIN_URL."/department.php?op=deleteStaffDept&amp;uid=".$uid."&amp;deptid=".$deptID."'><img src='".XOOPS_URL."/modules/xhelp/images/button_delete.png' title='"._AM_XHELP_TEXT_DELETE_STAFF_DEPT."' name='deleteStaffDept' /></a>
436
                      </td>
437
                  </tr>";
438
            }
439
            echo "<tr>
440
                      <td class='foot' colspan='".(3+count($roles))."'>
441
                          <input type='checkbox' name='checkallRoles' value='0' onclick='selectAll(this.form,\"staff[]\",this.checked);' />
442
                          <input type='submit' name='deleteStaff' id='deleteStaff' value='"._AM_XHELP_BUTTON_DELETE."' />
443
                      </td>
444
                  </tr>";
445
            echo "</table></form>";
446
            echo "<div id='staff_nav'>".$nav->renderNav()."</div>";
447
        } else {
448
            echo "</table></form>";
449
        }
450
451
        //now do the list of servers
452
        $hDeptServers =& xhelpGetHandler('departmentMailBox');
453
        $deptServers  =& $hDeptServers->getByDepartment($deptID);
454
        //iterate
455
        if (count($deptServers) > 0) {
456
            echo "<br /><table width='100%' cellspacing='1' class='outer'>
457
               <tr>
458
                 <th colspan='5'><label>". _AM_XHELP_DEPARTMENT_SERVERS ."</label></th>
459
               </tr>
460
               <tr>
461
                 <td class='head' width='20%'><label>". _AM_XHELP_DEPARTMENT_SERVERS_EMAIL ."</label></td>
462
                 <td class='head'><label>". _AM_XHELP_DEPARTMENT_SERVERS_TYPE ."</label></td>
463
                 <td class='head'><label>". _AM_XHELP_DEPARTMENT_SERVERS_SERVERNAME ."</label></td>
464
                 <td class='head'><label>". _AM_XHELP_DEPARTMENT_SERVERS_PORT ."</label></td>
465
                 <td class='head'><label>". _AM_XHELP_DEPARTMENT_SERVERS_ACTION ."</label></td>
466
               </tr>";
467
            $i = 0;
468
            foreach($deptServers as $server){
469
                if ($server->getVar('active')) {
470
                    $activ_link = '".XHELP_ADMIN_URL."/department.php?op=activateMailbox&amp;setstate=0&amp;id='. $server->getVar('id');
471
                    $activ_img = $imagearray['online'];
472
                    $activ_title = _AM_XHELP_MESSAGE_DEACTIVATE;
473
                } else {
474
                    $activ_link = '".XHELP_ADMIN_URL."/department.php?op=activateMailbox&amp;setstate=1&amp;id='. $server->getVar('id');
475
                    $activ_img = $imagearray['offline'];
476
                    $activ_title = _AM_XHELP_MESSAGE_ACTIVATE;
477
                }
478
479
                echo '<tr class="even">
480
                   <td>'.$server->getVar('emailaddress').'</td>
481
                   <td>'.xhelpGetMBoxType($server->getVar('mboxtype')).'</td>
482
                   <td>'.$server->getVar('server').'</td>
483
                   <td>'.$server->getVar('serverport').'</td>
484
                   <td> <a href="'. $activ_link.'" title="'. $activ_title.'">'. $activ_img.'</a>
485
                        <a href="'.XHELP_ADMIN_URL.'/department.php?op=EditDepartmentServer&amp;id='.$server->GetVar('id').'">'.$imagearray['editimg'].'</a>
486
                        <a href="'.XHELP_ADMIN_URL.'/department.php?op=DeleteDepartmentServer&amp;id='.$server->GetVar('id').'">'.$imagearray['deleteimg'].'</a>
487
488
                   </td>
489
                 </tr>';
490
            }
491
            echo '</table>';
492
        }
493
        //finally add Mailbox form
494
        echo "<br /><br />";
495
496
        $formElements = array('type_select', 'server_text', 'port_text', 'username_text', 'pass_text', 'priority_radio',
497
                              'email_text', 'btn_tray');
498
        $form = new xhelpForm(_AM_XHELP_DEPARTMENT_ADD_SERVER, 'add_server', xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'AddDepartmentServer', 'id' => $deptID)));
499
500
        $type_select = new XoopsFormSelect(_AM_XHELP_DEPARTMENT_SERVERS_TYPE, 'mboxtype');
501
        $type_select->setExtra("id='mboxtype'");
502
        $type_select->addOption(_XHELP_MAILBOXTYPE_POP3, _AM_XHELP_MBOX_POP3);
503
504
        $server_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVERS_SERVERNAME, 'server', 40, 50);
505
        $server_text->setExtra("id='txtServer'");
506
507
        $port_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVERS_PORT, 'port', 5, 5, "110");
508
        $port_text->setExtra("id='txtPort'");
509
510
        $username_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_USERNAME, 'username', 25, 50);
511
        $username_text->setExtra("id='txtUsername'");
512
513
        $pass_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_PASSWORD, 'password', 25, 50);
514
        $pass_text->setExtra("id='txtPassword'");
515
516
        $priority_radio = new xhelpFormRadio(_AM_XHELP_DEPARTMENT_SERVERS_PRIORITY, 'priority', XHELP_DEFAULT_PRIORITY);
517
        $priority_array = array('1' => "<label for='priority1'><img src='".XHELP_IMAGE_URL."/priority1.png' title='". xhelpGetPriority(1)."' alt='priority1' /></label>",
518
                                '2' => "<label for='priority2'><img src='".XHELP_IMAGE_URL."/priority2.png' title='". xhelpGetPriority(2)."' alt='priority2' /></label>",
519
                                '3' => "<label for='priority3'><img src='".XHELP_IMAGE_URL."/priority3.png' title='". xhelpGetPriority(3)."' alt='priority3' /></label>",
520
                                '4' => "<label for='priority4'><img src='".XHELP_IMAGE_URL."/priority4.png' title='". xhelpGetPriority(4)."' alt='priority4' /></label>",
521
                                '5' => "<label for='priority5'><img src='".XHELP_IMAGE_URL."/priority5.png' title='". xhelpGetPriority(5)."' alt='priority5' /></label>");
522
        $priority_radio->addOptionArray($priority_array);
523
524
        $email_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_EMAILADDRESS, 'emailaddress', 50, 255);
525
        $email_text->setExtra("id='txtEmailaddress'");
526
527
        $btn_tray = new XoopsFormElementTray('');
528
        $test_button = new XoopsFormButton('', 'email_test', _AM_XHELP_BUTTON_TEST, 'button');
529
        $test_button->setExtra("id='test'");
530
        $submit_button = new XoopsFormButton('', 'updateDept2', _AM_XHELP_BUTTON_SUBMIT, 'submit');
531
        $cancel2_button = new XoopsFormButton('', 'cancel2', _AM_XHELP_BUTTON_CANCEL, 'button');
532
        $cancel2_button->setExtra("onclick='history.go(-1)'");
533
        $btn_tray->addElement($test_button);
534
        $btn_tray->addElement($submit_button);
535
        $btn_tray->addElement($cancel2_button);
536
537
        $form->setLabelWidth('20%');
538
        foreach($formElements as $element){
539
            $form->addElement($$element);
540
        }
541
        echo $form->render();
542
543
        echo "<script type=\"text/javascript\" language=\"javascript\">
544
          <!--
545
          function xhelpEmailTest()
546
          {
547
            pop = openWithSelfMain(\"\", \"email_test\", 250, 150);
548
            frm = xoopsGetElementById(\"add_server\");
549
            newaction = \"department.php?op=testMailbox\";
550
            oldaction = frm.action;
551
            frm.action = newaction;
552
            frm.target = \"email_test\";
553
            frm.submit();
554
            frm.action = oldaction;
555
            frm.target = \"main\";
556
557
          }
558
559
          xhelpDOMAddEvent(xoopsGetElementById(\"email_test\"), \"click\", xhelpEmailTest, false);
560
561
          //-->
562
          </script>";
563
include_once "admin_footer.php";
564
    }
565
}
566
567
function EditDepartmentServer()
0 ignored issues
show
Coding Style introduced by
EditDepartmentServer 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
EditDepartmentServer 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...
568
{
569
    if(isset($_GET['id'])){
570
        $id = intval($_GET['id']);
571
    } else {
572
        redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3);       // TODO: Make message for no mbox_id
573
    }
574
575
    $hDeptServers =& xhelpGetHandler('departmentMailBox');
576
    $deptServer =& $hDeptServers->get($id);
0 ignored issues
show
Bug introduced by
The variable $id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
577
578
    if(isset($_POST['updateMailbox'])){
579
        $deptServer->setVar('emailaddress', $_POST['emailaddress']);
580
        $deptServer->setVar('server',       $_POST['server']);
581
        $deptServer->setVar('serverport',   $_POST['port']);
582
        $deptServer->setVar('username',     $_POST['username']);
583
        $deptServer->setVar('password',     $_POST['password']);
584
        $deptServer->setVar('priority',     $_POST['priority']);
585
        $deptServer->setVar('active',       $_POST['activity']);
586
587
        if($hDeptServers->insert($deptServer)){
588
            header("Location: ".XHELP_ADMIN_URL."/department.php?op=editDepartment&deptid=".$deptServer->getVar('departmentid'));
589
        } else {
590
            redirect_header(XHELP_ADMIN_URL."/department.php?op=editDepartment&deptid=".$deptServer->getVar('departmentid'),3);
591
        }
592
    } else {
593
        xoops_cp_header();
594
        //echo $oAdminButton->renderButtons('manDept');
595
        $indexAdmin = new ModuleAdmin();
596
        echo $indexAdmin->addNavigation('department.php');
597
        echo '<script type="text/javascript" src="'.XOOPS_URL.'/modules/xhelp/include/functions.js"></script>';
598
        echo "<form method='post' id='edit_server' action='department.php?op=EditDepartmentServer&amp;id=".$id."'>
599
               <table width='100%' cellspacing='1' class='outer'>
600
                 <tr>
601
                   <th colspan='2'><label>". _AM_XHELP_DEPARTMENT_EDIT_SERVER ."</label></th>
602
                 </tr>
603
                 <tr>
604
                   <td class='head' width='20%'><label for='mboxtype'>"._AM_XHELP_DEPARTMENT_SERVERS_TYPE."</label></td>
605
                   <td class='even'>
606
                     <select name='mboxtype' id='mboxtype' onchange='xhelpPortOnChange(this.options[this.selectedIndex].text, \"txtPort\")'>
607
                       <option value='"._XHELP_MAILBOXTYPE_POP3."'>"._AM_XHELP_MBOX_POP3."</option>
608
                       <!--<option value='"._XHELP_MAILBOXTYPE_IMAP."'>"._AM_XHELP_MBOX_IMAP."</option>-->
609
                     </select>
610
                   </td>
611
                 </tr>
612
                 <tr>
613
                   <td class='head'><label for='txtServer'>"._AM_XHELP_DEPARTMENT_SERVERS_SERVERNAME."</label></td>
614
                   <td class='even'><input type='text' id='txtServer' name='server' value='".$deptServer->getVar('server')."' size='40' maxlength='50' />
615
                 </tr>
616
                 <tr>
617
                   <td class='head'><label for='txtPort'>"._AM_XHELP_DEPARTMENT_SERVERS_PORT."</label></td>
618
                   <td class='even'><input type='text' id='txtPort' name='port' maxlength='5' size='5' value='".$deptServer->getVar('serverport')."' />
619
                 </tr>
620
                 <tr>
621
                   <td class='head'><label for='txtUsername'>"._AM_XHELP_DEPARTMENT_SERVER_USERNAME."</label></td>
622
                   <td class='even'><input type='text' id='txtUsername' name='username' value='".$deptServer->getVar('username')."' size='25' maxlength='50' />
623
                 </tr>
624
                 <tr>
625
                   <td class='head'><label for='txtPassword'>"._AM_XHELP_DEPARTMENT_SERVER_PASSWORD."</label></td>
626
                   <td class='even'><input type='text' id='txtPassword' name='password' value='".$deptServer->getVar('password')."' size='25' maxlength='50' />
627
                 </tr>
628
                 <tr>
629
                   <td width='38%' class='head'><label for='txtPriority'>"._AM_XHELP_DEPARTMENT_SERVERS_PRIORITY."</label></td>
630
                   <td width='62%' class='even'>";
631
        for($i = 1; $i < 6; $i++) {
632
            $checked = '';
633
            if($deptServer->getVar('priority') == $i){
634
                $checked = 'checked="checked"';
635
            }
636
            echo("<input type=\"radio\" value=\"$i\" id=\"priority$i\" name=\"priority\" $checked />");
637
            echo("<label for=\"priority$i\"><img src=\"../images/priority$i.png\" title=\"". xhelpGetPriority($i)."\" alt=\"priority$i\" /></label>");
638
        }
639
        echo "</td>
640
                 </tr>
641
                 <tr>
642
                   <td class='head'><label for='txtEmailaddress'>"._AM_XHELP_DEPARTMENT_SERVER_EMAILADDRESS."</label></td>
643
                   <td class='even'><input type='text' id='txtEmailaddress' name='emailaddress' value='".$deptServer->getVar('emailaddress')."' size='50' maxlength='255' />
644
                 </tr>
645
                 <tr>
646
                   <td class='head'><label for='txtActive'>"._AM_XHELP_TEXT_ACTIVITY."</label></td>
647
                   <td class='even'>";
648
        if($deptServer->getVar('active') == 1){
649
            echo "<input type='radio' value='1' name='activity' checked='checked' />"._AM_XHELP_TEXT_ACTIVE."
650
                                      <input type='radio' value='0' name='activity' />"._AM_XHELP_TEXT_INACTIVE;
651
        } else {
652
            echo "<input type='radio' value='1' name='activity' />"._AM_XHELP_TEXT_ACTIVE."
653
                                      <input type='radio' value='0' name='activity' checked='checked' />"._AM_XHELP_TEXT_INACTIVE;
654
        }
655
656
        echo "</td>
657
                 </tr>
658
659
                 <tr class='foot'>
660
                   <td colspan='2'><div align='right'><span >
661
                       <input type='button' id='email_test' name='test' value='"._AM_XHELP_BUTTON_TEST."' class='formButton' />
662
                       <input type='submit' name='updateMailbox' value='"._AM_XHELP_BUTTON_SUBMIT."' class='formButton' />
663
                       <input type='button' name='cancel' value='"._AM_XHELP_BUTTON_CANCEL."' onclick='history.go(-1)' class='formButton' />
664
                   </span></div></td>
665
                 </tr>
666
               </table>
667
             </form>";
668
        echo "<script type=\"text/javascript\" language=\"javascript\">
669
          <!--
670
          function xhelpEmailTest()
671
          {
672
            pop = openWithSelfMain(\"\", \"email_test\", 250, 150);
673
            frm = xoopsGetElementById(\"edit_server\");
674
            newaction = \"department.php?op=testMailbox\";
675
            oldaction = frm.action;
676
            frm.action = newaction;
677
            frm.target = \"email_test\";
678
            frm.submit();
679
            frm.action = oldaction;
680
            frm.target = \"main\";
681
682
          }
683
684
          xhelpDOMAddEvent(xoopsGetElementById(\"email_test\"), \"click\", xhelpEmailTest, false);
685
686
          //-->
687
          </script>";
688
include_once "admin_footer.php";
689
    }
690
}
691
692
function manageDepartments()
0 ignored issues
show
Coding Style introduced by
manageDepartments 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...
693
{
694
    global $xoopsModule, $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort, $dept_search;
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...
695
    $module_id = $xoopsModule->getVar('mid');
696
697
    $hGroups =& xoops_gethandler('group');
698
    $hGroupPerm =& xoops_gethandler('groupperm');
699
700
    if(isset($_POST['addDept'])){
701
        $hasErrors = false;
702
        $errors = array();
703
        $groups = (isset($_POST['groups']) ? $_POST['groups'] : array());
704
        $hDepartments  =& xhelpGetHandler('department');
705
706
        //Department Name supplied?
707
        if (trim($_POST['newDept']) == '') {
708
            $hasErrors = true;
709
            $errors['newDept'][] = _AM_XHELP_MESSAGE_NO_DEPT;
710
        } else {
711
712
            //Department Name unique?
713
            $crit = new Criteria('department', $_POST['newDept']);
714 View Code Duplication
            if($existingDepts = $hDepartments->getCount($crit)){
0 ignored issues
show
Unused Code introduced by
$existingDepts 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...
715
                $hasErrors = true;
716
                $errors['newDept'][] = _XHELP_MESSAGE_DEPT_EXISTS;
717
718
            }
719
        }
720
721
        if ($hasErrors) {
722
            $session =& Session::singleton();
723
            //Store existing dept info in session, reload addition page
724
            $aDept = array();
725
            $aDept['newDept'] = $_POST['newDept'];
726
            $aDept['groups'] = $groups;
727
            $session->set('xhelp_addDepartment', $aDept);
728
            $session->set('xhelp_addDepartmentErrors', $errors);
729
            header('Location: '. xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'manageDepartments'), false));
730
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function manageDepartments() 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...
731
        }
732
733
        $department =& $hDepartments->create();
734
        $department->setVar('department', $_POST['newDept']);
735
736
        if($hDepartments->insert($department)){
737
            $deptID = $department->getVar('id');
738
            foreach($groups as $group){     // Add new group permissions
739
                $hGroupPerm->addRight(_XHELP_GROUP_PERM_DEPT, $deptID, $group, $module_id);
740
            }
741
742
            // Set as default department?
743
            if(isset($_POST['defaultDept']) && ($_POST['defaultDept'] == 1)){
744
                xhelpSetMeta("default_department", $deptID);
745
            }
746
747
            $hStaff =& xhelpGetHandler('staff');
748
            $allDeptStaff =& $hStaff->getByAllDepts();
749
            if (count($allDeptStaff) > 0) {
750
                $hMembership =& xhelpGetHandler('membership');
751
                if($hMembership->addStaffToDept($allDeptStaff, $department->getVar('id'))){
752
                    $message = _XHELP_MESSAGE_ADD_DEPT;
753
                } else {
754
                    $message = _AM_XHELP_MESSAGE_STAFF_UPDATE_ERROR;
755
                }
756
            } else {
757
                $message = _XHELP_MESSAGE_ADD_DEPT;
758
            }
759
760
            // Add configoption for new department
761
            $hConfig =& xoops_gethandler('config');
762
            $hConfigOption =& xoops_gethandler('configoption');
763
764
            $crit = new Criteria('conf_name', 'xhelp_defaultDept');
765
            $config =& $hConfig->getConfigs($crit);
766
767
            if(count($config) > 0){
768
                $newOption =& $hConfigOption->create();
769
                $newOption->setVar('confop_name', $department->getVar('department'));
770
                $newOption->setVar('confop_value', $department->getVar('id'));
771
                $newOption->setVar('conf_id', $config[0]->getVar('conf_id'));
772
773
                if(!$hConfigOption->insert($newOption)){
774
                    redirect_header(XHELP_ADMIN_URL."/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_ADD_CONFIG_ERR);
775
                }
776
            }
777
            _clearAddSessionVars();
778
            header("Location: ".XHELP_ADMIN_URL."/department.php?op=manageDepartments");
779
        } else {
780
            $message = _XHELP_MESSAGE_ADD_DEPT_ERROR . $department->getHtmlErrors();
781
        }
782
783
        $deptID = $department->getVar('id');
0 ignored issues
show
Unused Code introduced by
$deptID 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...
784
785
        /* Not sure if this is needed. Already exists in if block above (ej)
786
         foreach($groups as $group){
787
         $hGroupPerm->addRight(_XHELP_GROUP_PERM_DEPT, $deptID, $group, $module_id);
788
         }
789
         */
790
791
        redirect_header(XHELP_ADMIN_URL.'/department.php?op=manageDepartments', 3, $message);
792
    } else {
793
        $hDepartments  =& xhelpGetHandler('department');
794 View Code Duplication
        if($dept_search == false){
795
            $crit = new Criteria('','');
796
        } else {
797
            $crit = new Criteria('department',"%$dept_search%", 'LIKE');
798
        }
799
        $crit->setOrder($order);
800
        $crit->setSort($sort);
801
        $crit->setLimit($limit);
802
        $crit->setStart($start);
803
        $total = $hDepartments->getCount($crit);
804
        $departmentInfo =& $hDepartments->getObjects($crit);
805
806
        $nav = new XoopsPageNav($total, $limit, $start, 'start', "op=manageDepartments&amp;limit=$limit");
807
808
        // Get list of all groups
809
        $crit = new Criteria('', '');
810
        $crit->setSort('name');
811
        $crit->setOrder('ASC');
812
        $groups =& $hGroups->getObjects($crit, true);
813
814
        $aGroups = array();
815
        foreach($groups as $group_id=>$group){
816
            $aGroups[$group_id] = $group->getVar('name');
817
        }
818
        asort($aGroups);    // Set groups in alphabetical order
819
820
        xoops_cp_header();
821
        //echo $oAdminButton->renderButtons('manDept');
822
        $indexAdmin = new ModuleAdmin();
823
        echo $indexAdmin->addNavigation('department.php?op=manageDepartments');
824
825
        $session =& Session::singleton();
826
        $sess_dept = $session->get('xhelp_addDepartment');
827
        $sess_errors = $session->get('xhelp_addDepartmentErrors');
828
829
        //Display any form errors
830 View Code Duplication
        if (! $sess_errors === false) {
831
            xhelpRenderErrors($sess_errors, xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'clearAddSession'), false));
832
        }
833
834 View Code Duplication
        if (! $sess_dept === false) {
835
            $fld_newDept = $sess_dept['newDept'];
836
            $fld_groups  = $sess_dept['groups'];
837
        } else {
838
            $fld_newDept = '';
839
            $fld_groups = array();
840
        }
841
842
        echo "<form method='post' action='".XHELP_ADMIN_URL."/department.php?op=manageDepartments'>";
843
        echo "<table width='100%' cellspacing='1' class='outer'>
844
              <tr><th colspan='2'><label for='newDept'>". _AM_XHELP_LINK_ADD_DEPT ." </label></th></tr>";
845
        echo "<tr><td class='head' width='20%' valign='top'>". _AM_XHELP_TEXT_NAME ."</td><td class='even'>";
846
        echo "<input type='text' id='newDept' name='newDept' class='formButton' value='$fld_newDept' /></td></tr>";
847
        echo "<tr><td class='head' width='20%' valign='top'>"._AM_XHELP_TEXT_EDIT_DEPT_PERMS."</td><td class='even'>";
848
        echo "<select name='groups[]' multiple='multiple'>";
849
        foreach($aGroups as $group_id=>$group){
850
            if (in_array($group_id, $fld_groups, true)) {
851
                echo "<option value='$group_id' selected='selected'>$group</option>";
852
            } else {
853
                echo "<option value='$group_id'>$group</option>";
854
            }
855
        }
856
        echo "</select></td></tr>";
857
        echo "<tr><td class='head' width='20%' valign='top'>"._AM_XHELP_TEXT_DEFAULT_DEPT."?</td>
858
                  <td class='even'><input type='checkbox' name='defaultDept' id='defaultDept' value='1' /></td></tr>";
859
        echo "<tr><td class='foot' colspan='2'><input type='submit' name='addDept' value='"._AM_XHELP_BUTTON_SUBMIT."' class='formButton' /></td></tr>";
860
        echo "</table><br />";
861
        echo "</form>";
862
        if($total > 0){     // Make sure there are departments
863
            echo "<form action='". XHELP_ADMIN_URL."/department.php?op=manageDepartments' style='margin:0; padding:0;' method='post'>";
864
            echo "<table width='100%' cellspacing='1' class='outer'>";
865
            echo "<tr><td align='right'>"._AM_XHELP_BUTTON_SEARCH."
866
                          <input type='text' name='dept_search' value='$dept_search'/>
867
                        &nbsp;&nbsp;&nbsp;
868
                        "._AM_XHELP_TEXT_SORT_BY."
869
                          <select name='sort'>";
870 View Code Duplication
            foreach($aSortBy as $value=>$text){
871
                ($sort == $value) ? $selected = "selected='selected'" : $selected = '';
872
                echo "<option value='$value' $selected>$text</option>";
873
            }
874
            echo "</select>
875
                        &nbsp;&nbsp;&nbsp;
876
                          "._AM_XHELP_TEXT_ORDER_BY."
877
                          <select name='order'>";
878 View Code Duplication
            foreach($aOrderBy as $value=>$text){
879
                ($order == $value) ? $selected = "selected='selected'" : $selected = '';
880
                echo "<option value='$value' $selected>$text</option>";
881
            }
882
            echo "</select>
883
                          &nbsp;&nbsp;&nbsp;
884
                          "._AM_XHELP_TEXT_NUMBER_PER_PAGE."
885
                          <select name='limit'>";
886 View Code Duplication
            foreach($aLimitBy as $value=>$text){
887
                ($limit == $value) ? $selected = "selected='selected'" : $selected = '';
888
                echo "<option value='$value' $selected>$text</option>";
889
            }
890
            echo "</select>
891
                          <input type='submit' name='dept_sort' id='dept_sort' value='"._AM_XHELP_BUTTON_SUBMIT."' />
892
                      </td>
893
                  </tr>";
894
            echo "</table></form>";
895
            echo "<table width='100%' cellspacing='1' class='outer'>
896
                  <tr><th colspan='4'>"._AM_XHELP_EXISTING_DEPARTMENTS."</th></tr>
897
                  <tr><td class='head'>"._AM_XHELP_TEXT_ID."</td><td class='head'>"._AM_XHELP_TEXT_DEPARTMENT."</td><td class='head'>"._AM_XHELP_TEXT_DEFAULT."</td><td class='head'>"._AM_XHELP_TEXT_ACTIONS."</td></tr>";
898
899
            if(isset($departmentInfo)){
900
                $defaultDept = xhelpGetMeta("default_department");
901
                foreach($departmentInfo as $dept){
902
                    echo "<tr><td class='even'>". $dept->getVar('id')."</td><td class='even'>". $dept->getVar('department') ."</td>";
903
                    if($dept->getVar('id') != $defaultDept){
904
                        echo "<td class='even' width='10%'><a href='".XHELP_ADMIN_URL."/department.php?op=updateDefault&amp;id=".$dept->getVar('id')."'><img src='".XHELP_IMAGE_URL."/off.png' alt='"._AM_XHELP_TEXT_MAKE_DEFAULT_DEPT."' title='"._AM_XHELP_TEXT_MAKE_DEFAULT_DEPT."' /></a></td>";
905
                    } else {
906
                        echo "<td class='even' width='10%'><img src='".XHELP_IMAGE_URL."/on.png'</td>";
907
                    }
908
                    //echo "<td class='even' width='10%'><img src='".XHELP_IMAGE_URL."/". (($dept->getVar('id') == $defaultDept) ? "on.png" : "off.png")."'</td>";
909
                    echo "<td class='even' width='70'><a href='".XHELP_ADMIN_URL."/department.php?op=editDepartment&amp;deptid=".$dept->getVar('id')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_edit.png' title='"._AM_XHELP_TEXT_EDIT."' name='editDepartment' /></a>&nbsp;&nbsp;";
910
                    echo "<a href='".XHELP_ADMIN_URL."/delete.php?deleteDept=1&amp;deptid=".$dept->getVar('id')."'><img src='".XOOPS_URL."/modules/xhelp/images/button_delete.png' title='"._AM_XHELP_TEXT_DELETE."' name='deleteDepartment' /></a></td></tr>";
911
                }
912
913
            }
914
        }
915
        echo "</td></tr></table>";
916
        echo "<div id='dept_nav'>".$nav->renderNav()."</div>";
917
include_once "admin_footer.php";
918
    }
919
}
920
921
function testMailbox()
0 ignored issues
show
Coding Style introduced by
testMailbox 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...
922
{
923
    $hDeptServers =& xhelpGetHandler('departmentMailBox');
924
    $server = $hDeptServers->create();
925
    $server->setVar('emailaddress', $_POST['emailaddress']);
926
    $server->setVar('server',       $_POST['server']);
927
    $server->setVar('serverport',   $_POST['port']);
928
    $server->setVar('username',     $_POST['username']);
929
    $server->setVar('password',     $_POST['password']);
930
    $server->setVar('priority',     $_POST['priority']);
931
    echo "<html>";
932
    echo "<head>";
933
    echo "<link rel='stylesheet' type='text/css' media'screen' href='".XOOPS_URL."/xoops.css' />
934
          <link rel='stylesheet' type='text/css' media='screen' href='". xoops_getcss() ."' />
935
          <link rel='stylesheet' type='text/css' media='screen' href='".XOOPS_URL."/modules/system/style.css' />";
936
    echo "</head>";
937
    echo "<body>";
938
    echo "<table style='margin:0; padding:0;' class='outer'>";
939
    if (@$server->connect()) {
940
        //Connection Succeeded
941
        echo "<tr><td class='head'>Connection Successful!</td></tr>";
942
    } else {
943
        //Connection Failed
944
        echo "<tr class='head'><td>Connection Failed!</td></tr>";
945
        echo "<tr class='even'><td>". $server->getHtmlErrors()."</td></tr>";
946
    }
947
    echo "</table>";
948
    echo "</body>";
949
    echo "</html>";
950
}
951
952
function clearAddSession()
953
{
954
    _clearAddSessionVars();
955
    header('Location: ' . xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'manageDepartments'), false));
956
}
957
958
function _clearAddSessionVars()
959
{
960
    $session = Session::singleton();
961
    $session->del('xhelp_addDepartment');
962
    $session->del('xhelp_addDepartmentErrors');
963
}
964
965
function clearEditSession()
0 ignored issues
show
Coding Style introduced by
clearEditSession uses the super-global variable $_REQUEST 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...
966
{
967
    $deptid = $_REQUEST['deptid'];
968
    _clearEditSessionVars($deptid);
969
    header('Location: ' . xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'editDepartment', 'deptid'=>$deptid), false));
970
}
971
972 View Code Duplication
function _clearEditSessionVars($id)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
973
{
974
    $id = intval($id);
975
    $session = Session::singleton();
976
    $session->del("xhelp_editDepartment_$id");
977
    $session->del("xhelp_editDepartmentErrors_$id");
978
}
979
980
function updateDefault()
0 ignored issues
show
Coding Style introduced by
updateDefault uses the super-global variable $_REQUEST 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...
981
{
982
    $id = intval($_REQUEST['id']);
983
    xhelpSetMeta("default_department", $id);
984
    header('Location: '. xhelpMakeURI(XHELP_ADMIN_URL.'/department.php', array('op'=>'manageDepartments'), false));
985
}
986