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

index.php ➔ userviewall_display()   F

Complexity

Conditions 19
Paths 12288

Size

Total Lines 173
Code Lines 112

Duplication

Lines 23
Ratio 13.29 %

Importance

Changes 0
Metric Value
cc 19
eloc 112
nc 12288
nop 0
dl 23
loc 173
rs 2
c 0
b 0
f 0

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 204 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: index.php,v 1.98 2005/12/12 19:08:05 eric_juden Exp $
3
require_once('header.php');
4
require_once(XHELP_INCLUDE_PATH.'/events.php');
5
include_once(XOOPS_ROOT_PATH . '/class/pagenav.php');
6
7
// Setup event handlers for page
8
9
//Initialise Necessary Data Handler Classes
10
$hStaff       =& xhelpGetHandler('staff');
11
$hXoopsMember =& xoops_gethandler('member');
12
$hDepartments =& xhelpGetHandler('department');
13
$hMembership  =& xhelpGetHandler('membership');
14
$hTickets     =& xhelpGetHandler('ticket');
15
$hTicketList  =& xhelpGetHandler('ticketList');
16
$hSavedSearch =& xhelpGetHandler('savedSearch');
17
18
//Determine default 'op' (if none is specified)
19
$uid     = 0;
20
if ($xoopsUser) {
21
    $uid = $xoopsUser->getVar('uid');
22
    if ($xhelp_isStaff) {
23
        $op = 'staffMain';
24
    } else {
25
        $op = 'userMain';
26
    }
27
} else {
28
    $op = 'anonMain';
29
}
30
31
// Page Global Variables
32
$status_opt   = array(_XHELP_TEXT_SELECT_ALL => -1, _XHELP_STATUS0 => 0, _XHELP_STATUS1 => 1, _XHELP_STATUS2 => 2);
33
$state_opt    = array(_XHELP_TEXT_SELECT_ALL => -1, _XHELP_STATE1 => 1, _XHELP_STATE2 => 2);
34
$sort_columns = array();
35
$sort_order   = array('ASC', 'DESC');
36
$vars         = array('op', 'limit', 'start', 'sort', 'order', 'refresh');
37
$all_users    = array();
38
$refresh      = $start = $limit = 0;
39
$sort         = '';
40
$order        = '';
41
42
//Initialize Variables
43
foreach ($vars as $var) {
44
    if (isset($_REQUEST[$var])) {
45
        $$var = $_REQUEST[$var];
46
    }
47
}
48
49
//Ensure Criteria Fields hold valid values
50
$limit = intval($limit);
51
$start = intval($start);
52
$sort  = strtolower($sort);
53
$order = (in_array(strtoupper($order), $sort_order) ? $order : 'ASC');
54
55
$displayName =& $xoopsModuleConfig['xhelp_displayName'];    // Determines if username or real name is displayed
56
57
switch($op) {
58
59
    case 'staffMain':
60
        staffmain_display();
61
        break;
62
63
    case 'staffViewAll':
64
        staffviewall_display();
65
        break;
66
67
    case 'userMain':
68
        usermain_display();
69
        break;
70
71
    case 'userViewAll':
72
        userviewall_display();
73
        break;
74
75 View Code Duplication
    case 'setdept':
76
        if (!$xhelp_isStaff) {
77
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
78
        }
79
80
        /*
81
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_EDIT)){
82
         $message = _XHELP_MESSAGE_NO_EDIT_TICKET;
83
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
84
         }
85
         */
86
        if (isset($_POST['setdept'])) {
87
            setdept_action();
88
        } else {
89
            setdept_display();
90
        }
91
        break;
92
93 View Code Duplication
    case 'setpriority':
94
        if (!$xhelp_isStaff) {
95
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
96
        }
97
        /*
98
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_PRIORITY)){
99
         $message = _XHELP_MESSAGE_NO_CHANGE_PRIORITY;
100
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
101
         }
102
         */
103
        if (isset($_POST['setpriority'])) {
104
            setpriority_action();
105
        } else {
106
            setpriority_display();
107
        }
108
        break;
109
110 View Code Duplication
    case 'setstatus':
111
        if (!$xhelp_isStaff) {
112
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
113
        }
114
        /*
115
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_STATUS)){
116
         $message = _XHELP_MESSAGE_NO_CHANGE_STATUS;
117
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
118
         }
119
         */
120
        if (isset($_POST['setstatus'])) {
121
            setstatus_action();
122
        } else {
123
            setstatus_display();
124
        }
125
        break;
126
127 View Code Duplication
    case 'setowner':
128
        if (!$xhelp_isStaff) {
129
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
130
        }
131
        /*
132
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_OWNERSHIP)){
133
         $message = _XHELP_MESSAGE_NO_CHANGE_OWNER;
134
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
135
         }
136
         */
137
        if (isset($_POST['setowner'])) {
138
            setowner_action();
139
        } else {
140
            setowner_display();
141
        }
142
        break;
143
144 View Code Duplication
    case 'addresponse':
145
        if (!$xhelp_isStaff) {
146
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
147
        }
148
        /*
149
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_RESPONSE_ADD)){
150
         $message = _XHELP_MESSAGE_NO_ADD_RESPONSE;
151
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
152
         }
153
         */
154
        if (isset($_POST['addresponse'])) {
155
            addresponse_action();
156
        } else {
157
            addresponse_display();
158
        }
159
        break;
160
161 View Code Duplication
    case 'delete':
162
        if (!$xhelp_isStaff) {
163
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
164
        }
165
        /*
166
         if(!$hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_DELETE)){
167
         $message = _XHELP_MESSAGE_NO_DELETE_TICKET;
168
         redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, $message);
169
         }
170
         */
171
        if (isset($_POST['delete'])) {
172
            delete_action();
173
        } else {
174
            delete_display();
175
        }
176
        break;
177
178
    case 'anonMain':
179
        $config_handler =& xoops_gethandler('config');
180
        $xoopsConfigUser = array();
181
        $crit = new CriteriaCompo(new Criteria('conf_name', 'allow_register'), 'OR');
182
        $crit->add(new Criteria('conf_name', 'activation_type'), 'OR');
183
        $myConfigs =& $config_handler->getConfigs($crit);
184
185
        foreach($myConfigs as $myConf){
186
            $xoopsConfigUser[$myConf->getVar('conf_name')] = $myConf->getVar('conf_value');
187
        }
188
189 View Code Duplication
        if ($xoopsConfigUser['allow_register'] == 0) {
190
            header("Location: ".XHELP_BASE_URL."/error.php");
191
        } else {
192
            header("Location: ".XHELP_BASE_URL."/addTicket.php");
193
        }
194
        exit();
195
        break;
196
    default:
197
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3);
198
        break;
199
}
200
201
/**
202
 * Assign the selected tickets to the specified department
203
 */
204
function setdept_action()
0 ignored issues
show
Coding Style introduced by
setdept_action 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
    global $_eventsrv, $xhelp_staff;
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...
207
208
    //Sanity Check: tickets and department are supplied
209
    if (!isset($_POST['tickets'])) {
210
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
211
    }
212
213
    if (!isset($_POST['department'])) {
214
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_DEPARTMENT);
215
    }
216
    $tickets = implode($_POST['tickets'], ',');
217
    $tickets  = _cleanTickets($tickets);
218
    $oTickets =& xhelpGetTickets($tickets);
219
220
    $depts = array();
221
    foreach($oTickets as $ticket){
222
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
223
    }
224
225
    // Check staff permissions
226
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_EDIT, $depts)){
227
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_EDIT_TICKET);
228
    }
229
230
    $ret = xhelpSetDept($tickets, $_POST['department']);
231
    if ($ret) {
232
        $_eventsrv->trigger('batch_dept', array(@$oTickets, $_POST['department']));
233
        if (count($oTickets)>1) {
234
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_DEPARTMENT);
235
        } else {
236
            redirect_header(XHELP_BASE_URL."/ticket.php?id=".$oTickets[0]->getVar('id'), 3, _XHELP_MESSAGE_UPDATE_DEPARTMENT);
237
        }
238
        end();
239
    }
240
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_DEPARTMENT_ERROR);
241
}
242
243
/**
244
 * Display form for the Batch Action: Set Department
245
 */
246
function setdept_display()
0 ignored issues
show
Coding Style introduced by
setdept_display 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...
247
{
248
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $displayName;
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...
249
250
    if (!isset($_POST['tickets'])) {
251
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
252
    }
253
254
    $hDepartments =& xhelpGetHandler('department');
255
    $depts = $hDepartments->getObjects(null, true);
256
    $oTickets =& xhelpGetTickets($_POST['tickets']);
257
    $all_users   = array();
258
    $j = 0;
259
260
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_TICKET_EDIT);
261
    unset($oTickets);
262
263
    $tplDepts = array();
264
    foreach ($depts as $dept) {
265
        $tplDepts[$dept->getVar('id')] = $dept->getVar('department');
266
    }
267
    unset($depts);
268
269
    //Retrieve all member information for the current page
270 View Code Duplication
    if (count($all_users)) {
271
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
272
        $users =& xhelpGetUsers($crit, $displayName);
273
    } else {
274
        $users = array();
275
    }
276
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
277
278
    $xoopsOption['template_main'] = 'xhelp_setdept.html';   // Set template
279
    require(XOOPS_ROOT_PATH.'/header.php');                  // Include the page header
280
    $xoopsTpl->assign('xhelp_department_options', $tplDepts);
281
    $xoopsTpl->assign('xhelp_tickets', implode($_POST['tickets'], ','));
282
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
283
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
284
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
285
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
286
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_EDIT_TICKET);
287
    require(XOOPS_ROOT_PATH.'/footer.php');
288
}
289
290 View Code Duplication
function setpriority_action()
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...
Coding Style introduced by
setpriority_action 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...
291
{
292
    global $_eventsrv, $xhelp_staff;
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...
293
    if (!isset($_POST['tickets'])) {
294
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
295
    }
296
297
    if (!isset($_POST['priority'])) {
298
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_PRIORITY);
299
    }
300
    $tickets = implode($_POST['tickets'], ',');
301
    $tickets  = _cleanTickets($tickets);
302
    $oTickets =& xhelpGetTickets($tickets);
303
304
    $depts = array();
305
    foreach($oTickets as $ticket){
306
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
307
    }
308
309
    // Check staff permissions
310
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_PRIORITY, $depts)){
311
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_CHANGE_PRIORITY);
312
    }
313
314
    $ret      = xhelpSetPriority($tickets, $_POST['priority']);
315
    if ($ret) {
316
        $_eventsrv->trigger('batch_priority', array(@$oTickets, $_POST['priority']));
317
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_PRIORITY);
318
    }
319
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_PRIORITY_ERROR);
320
}
321
322
function setpriority_display()
0 ignored issues
show
Coding Style introduced by
setpriority_display 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...
323
{
324
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin, $displayName;
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...
325
326
    //Make sure that some tickets were selected
327
    if (!isset($_POST['tickets'])) {
328
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
329
    }
330
331
    $hDepartments =& xhelpGetHandler('department');
332
    $depts = $hDepartments->getObjects(null, true);
333
    $oTickets =& xhelpGetTickets($_POST['tickets']);
334
    $all_users   = array();
335
    $j = 0;
336
337
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_TICKET_PRIORITY);
338
    unset($oTickets);
339
340
    //Retrieve all member information for the current page
341 View Code Duplication
    if (count($all_users)) {
342
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
343
        $users =& xhelpGetUsers($crit, $displayName);
344
    } else {
345
        $users = array();
346
    }
347
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
348
349
    //Get Array of priorities/descriptions
350
    $aPriority  = array(1 => _XHELP_PRIORITY1, 2 => _XHELP_PRIORITY2, 3 => _XHELP_PRIORITY3, 4 => _XHELP_PRIORITY4, 5 => _XHELP_PRIORITY5);
351
352
    $xoopsOption['template_main'] = 'xhelp_setpriority.html';    // Set template
353
    require(XOOPS_ROOT_PATH.'/header.php');
354
    $xoopsTpl->assign('xhelp_priorities_desc', $aPriority);
355
    $xoopsTpl->assign('xhelp_priorities', array_keys($aPriority));
356
    $xoopsTpl->assign('xhelp_priority', 4);
357
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
358
    $xoopsTpl->assign('xhelp_tickets', implode($_POST['tickets'], ','));
359
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
360
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
361
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
362
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
363
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_CHANGE_PRIORITY);
364
    require(XOOPS_ROOT_PATH.'/footer.php');
365
}
366
367
function setstatus_action()
0 ignored issues
show
Coding Style introduced by
setstatus_action 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...
368
{
369
    global $_eventsrv, $xhelp_staff;
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...
370
    if (!isset($_POST['tickets'])) {
371
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
372
    }
373
374
    if (!isset($_POST['status'])) {
375
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_STATUS);
376
    }
377
    $tickets = implode($_POST['tickets'], ',');
378
    $tickets  = _cleanTickets($tickets);
379
    $oTickets =& xhelpGetTickets($tickets);
380
381
    $depts = array();
382
    foreach($oTickets as $ticket){
383
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
384
    }
385
386
    // Check staff permissions
387
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_STATUS, $depts)){
388
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_CHANGE_STATUS);
389
    }
390
391
    $hStatus  =& xhelpGetHandler('status');
392
    $status   =& $hStatus->get($_POST['status']);
393
    $ret      = xhelpSetStatus($tickets, $_POST['status']);
394
    if ($ret) {
395
        $_eventsrv->trigger('batch_status', array(&$oTickets, &$status));
396
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_STATUS);
397
        end();
398
    }
399
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_UPDATE_STATUS_ERROR);
400
401
}
402
403
function setstatus_display()
0 ignored issues
show
Coding Style introduced by
setstatus_display 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...
404
{
405
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin, $displayName;
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...
406
    $hStatus =& xhelpGetHandler('status');
407
    $crit = new Criteria('', '');
408
    $crit->setOrder('ASC');
409
    $crit->setSort('description');
410
    $statuses =& $hStatus->getObjects($crit);
411
412
    //Make sure that some tickets were selected
413
    if (!isset($_POST['tickets'])) {
414
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
415
    }
416
417
    $hDepartments =& xhelpGetHandler('department');
418
    $depts = $hDepartments->getObjects(null, true);
419
    $oTickets =& xhelpGetTickets($_POST['tickets']);
420
    $all_users   = array();
421
    $j = 0;
422
423
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_TICKET_STATUS);
424
    unset($oTickets);
425
426
    //Retrieve all member information for the current page
427 View Code Duplication
    if (count($all_users)) {
428
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
429
        $users =& xhelpGetUsers($crit, $displayName);
430
    } else {
431
        $users = array();
432
    }
433
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
434
435
    //Get Array of Status/Descriptions
436
    $aStatus = array();
437
    foreach($statuses as $status){
438
        $aStatus[$status->getVar('id')] = $status->getVar('description');
439
    }
440
441
    $xoopsOption['template_main'] = 'xhelp_setstatus.html'; // Set template
442
    require(XOOPS_ROOT_PATH.'/header.php');
443
    $xoopsTpl->assign('xhelp_status_options', $aStatus);
444
    $xoopsTpl->assign('xhelp_tickets', implode($_POST['tickets'], ','));
445
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
446
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
447
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
448
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
449
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_CHANGE_STATUS);
450
    require(XOOPS_ROOT_PATH.'/footer.php');
451
}
452
453 View Code Duplication
function setowner_action()
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...
Coding Style introduced by
setowner_action 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...
454
{
455
    global $_eventsrv, $xhelp_staff;
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...
456
    if (!isset($_POST['tickets'])) {
457
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
458
    }
459
460
    if (!isset($_POST['owner'])) {
461
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_OWNER);
462
    }
463
    $tickets = implode($_POST['tickets'], ',');
464
    $tickets  = _cleanTickets($tickets);
465
    $oTickets =& xhelpGetTickets($tickets);
466
467
    $depts = array();
468
    foreach($oTickets as $ticket){
469
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
470
    }
471
472
    // Check staff permissions
473
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_OWNERSHIP, $depts)){
474
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_CHANGE_OWNER);
475
    }
476
    $ret      = xhelpSetOwner($tickets, $_POST['owner']);
477
478
    if ($ret) {
479
        $_eventsrv->trigger('batch_owner', array(&$oTickets, $_POST['owner']));
480
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_ASSIGN_OWNER);
481
        end();
482
    }
483
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_ASSIGN_OWNER_ERROR);
484
}
485
486
function setowner_display()
0 ignored issues
show
Coding Style introduced by
setowner_display 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...
487
{
488
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsModuleConfig, $displayName;
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...
489
490
    //Make sure that some tickets were selected
491
    if (!isset($_POST['tickets'])) {
492
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
493
    }
494
495
    $hTickets     =& xhelpGetHandler('ticket');
496
    $hMember      =& xhelpGetHandler('membership');
497
    $hXoopsMember =& xoops_gethandler('member');
498
499
    $hDepartments =& xhelpGetHandler('department');
500
    $depts = $hDepartments->getObjects(null, true);
501
    $oTickets =& xhelpGetTickets($_POST['tickets']);
502
    $all_users   = array();
503
    $j = 0;
504
505
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_TICKET_OWNERSHIP);
506
    unset($oTickets);
507
508
    //Retrieve all member information for the current page
509 View Code Duplication
    if (count($all_users)) {
510
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
511
        $users =& xhelpGetUsers($crit, $displayName);
512
    } else {
513
        $users = array();
514
    }
515
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
516
517
    $aOwners = array();
518
    foreach($users as $uid=>$user){
519
        $aOwners[$uid] = $uid;
520
    }
521
    $crit  = new Criteria('uid', "(". implode(array_keys($aOwners), ',') .")", 'IN');
522
    $owners =& xhelpGetUsers($crit, $xoopsModuleConfig['xhelp_displayName']);
523
524
    $a_users = array();
525
    $a_users[0] = _XHELP_NO_OWNER;
526
    foreach($owners as $owner_id=>$owner_name) {
527
        $a_users[$owner_id] = $owner_name;
528
    }
529
    unset($users);
530
    unset($owners);
531
    unset($aOwners);
532
533
    $xoopsOption['template_main'] = 'xhelp_setowner.html'; // Set template
534
    require(XOOPS_ROOT_PATH.'/header.php');
535
    $xoopsTpl->assign('xhelp_staff_ids', $a_users);
536
    $xoopsTpl->assign('xhelp_tickets', implode($_POST['tickets'], ','));
537
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
538
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
539
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
540
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
541
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_CHANGE_OWNER);
542
    require(XOOPS_ROOT_PATH.'/footer.php');
543
}
544
545
function addresponse_action()
0 ignored issues
show
Coding Style introduced by
addresponse_action 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...
546
{
547
    global $_eventsrv, $_xhelpSession, $xhelp_staff;
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...
548
    if (!isset($_POST['tickets'])) {
549
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
550
    }
551
552
    if (!isset($_POST['response'])) {
553
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_RESPONSE);
554
    }
555
    $private = isset($_POST['private']);
556
557
    $tickets = implode($_POST['tickets'], ',');
558
    $tickets  = _cleanTickets($tickets);
559
    $oTickets =& xhelpGetTickets($tickets);
560
561
    $depts = array();
562
    foreach($oTickets as $ticket){
563
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
564
    }
565
566
    // Check staff permissions
567
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_RESPONSE_ADD, $depts)){
568
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_ADD_RESPONSE);
569
    }
570
    $ret =& xhelpAddResponse($tickets, $_POST['response'], $_POST['timespent'], $private);
571
    if ($ret) {
572
        $_xhelpSession->del('xhelp_batch_addresponse');
573
        $_xhelpSession->del('xhelp_batch_response');
574
        $_xhelpSession->del('xhelp_batch_timespent');
575
        $_xhelpSession->del('xhelp_batch_private');
576
577
        $_eventsrv->trigger('batch_response', array(&$oTickets, &$ret));
578
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_ADDRESPONSE);
579
        end();
580
    }
581
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_ADDRESPONSE_ERROR);
582
583
}
584
585
function addresponse_display()
0 ignored issues
show
Coding Style introduced by
addresponse_display 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
addresponse_display 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...
586
{
587
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin, $_xhelpSession, $displayName;
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...
588
    $hResponseTpl =& xhelpGetHandler('responseTemplates');
589
    $ticketVar    = 'xhelp_batch_addresponse';
590
    $tpl          = 0;
591
    $uid          = $xoopsUser->getVar('uid');
592
593
    //Make sure that some tickets were selected
594
    if (!isset($_POST['tickets'])) {
595
        if (!$tickets = $_xhelpSession->get($ticketVar)) {
596
            redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
597
        }
598
    } else {
599
        $tickets = $_POST['tickets'];
600
    }
601
602
    $hDepartments =& xhelpGetHandler('department');
603
    $depts = $hDepartments->getObjects(null, true);
604
    $oTickets =& xhelpGetTickets($_POST['tickets']);
605
    $all_users   = array();
606
    $j = 0;
607
608
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_RESPONSE_ADD);
609
    unset($oTickets);
610
611
    //Retrieve all member information for the current page
612 View Code Duplication
    if (count($all_users)) {
613
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
614
        $users =& xhelpGetUsers($crit, $displayName);
615
    } else {
616
        $users = array();
617
    }
618
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
619
620
    //Store tickets in session so they won't be in URL
621
    $_xhelpSession->set($ticketVar, $tickets);
622
623
    //Check if a predefined response was selected
624
    if (isset($_REQUEST['tpl'])) {
625
        $tpl = $_REQUEST['tpl'];
626
    }
627
628
    $xoopsOption['template_main'] = 'xhelp_batch_response.html';
629
    require(XOOPS_ROOT_PATH.'/header.php');
630
    $xoopsTpl->assign('xhelp_tickets', implode($tickets, ','));
631
    $xoopsTpl->assign('xhelp_formaction', basename(__FILE__));
632
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
633
    $xoopsTpl->assign('xhelp_timespent', ($timespent =$_xhelpSession->get('xhelp_batch_timespent') ? $timespent: ''));
0 ignored issues
show
Bug introduced by
The variable $timespent seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
634
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
635
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
636
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
637
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
638
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_ADD_RESPONSE);
639
    $xoopsTpl->assign('xhelp_responseTpl', $tpl);
640
641
    //Get all staff defined templates
642
    $crit = new Criteria('uid', $uid);
643
    $crit->setSort('name');
644
    $responseTpl =& $hResponseTpl->getObjects($crit, true);
645
646
    //Fill Response Template Array
647
    $tpls = array();
648
    $tpls[0] = '------------------';
649
650
    foreach($responseTpl as $key=>$obj) {
651
        $tpls[$key] = $obj->getVar('name');
652
    }
653
    $xoopsTpl->assign('xhelp_responseTpl_options', $tpls);
654
    //Get response message to display
655
    if (isset($responseTpl[$tpl])) {    // Display Template Text
656
        $xoopsTpl->assign('xhelp_response_message', $responseTpl[$tpl]->getVar('response', 'e'));
657
    } else {
658
        if ($response = $_xhelpSession->get('xhelp_batch_response')) {  //Display Saved Text
659
            $xoopsTpl->assign('xhelp_response_message', $response);
660
        }
661
    }
662
663
    //Private Message?
664
    $xoopsTpl->assign('xhelp_private', ($private = $_xhelpSession->get('xhelp_batch_private') ? $private : false));
0 ignored issues
show
Bug introduced by
The variable $private seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
665
666
    require(XOOPS_ROOT_PATH.'/footer.php');
667
}
668
669
function delete_action()
0 ignored issues
show
Coding Style introduced by
delete_action 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...
670
{
671
    global $_eventsrv, $xhelp_staff;
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...
672
    if (!isset($_POST['tickets'])) {
673
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_TICKETS);
674
    }
675
676
    $tickets = implode($_POST['tickets'], ',');
677
    $tickets  = _cleanTickets($tickets);
678
    $oTickets =& xhelpGetTickets($tickets);
679
680
    $depts = array();
681
    foreach($oTickets as $ticket){
682
        $depts[$ticket->getVar('department')] = $ticket->getVar('department');
683
    }
684
685
    // Check staff permissions
686
    if(!$xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_DELETE, $depts)){
687
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_NO_DELETE_TICKET);
688
    }
689
690
    $ret      = xhelpDeleteTickets($tickets);
691
    if ($ret) {
692
        $_eventsrv->trigger('batch_delete_ticket', array(@$oTickets));
693
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_DELETE_TICKETS);
694
        end();
695
    }
696
    redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _XHELP_MESSAGE_DELETE_TICKETS_ERROR);
697
}
698
699
function delete_display()
0 ignored issues
show
Coding Style introduced by
delete_display 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...
700
{
701
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin, $displayName;
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...
702
703
    //Make sure that some tickets were selected
704
    if (!isset($_POST['tickets'])) {
705
        redirect_header(XHELP_BASE_URL."/index.php", 3, _XHELP_MESSAGE_NO_TICKETS);
706
    }
707
708
    $hDepartments =& xhelpGetHandler('department');
709
    $depts = $hDepartments->getObjects(null, true);
710
    $oTickets =& xhelpGetTickets($_POST['tickets']);
711
    $all_users   = array();
712
    $j = 0;
713
714
    $sortedTickets = _makeBatchTicketArray($oTickets, $depts, $all_users, $j, XHELP_SEC_TICKET_DELETE);
715
    unset($oTickets);
716
717
    //Retrieve all member information for the current page
718 View Code Duplication
    if (count($all_users)) {
719
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
720
        $users =& xhelpGetUsers($crit, $displayName);
721
    } else {
722
        $users = array();
723
    }
724
    $sortedTickets =& _updateBatchTicketInfo($sortedTickets, $users, $j);
725
726
    $hiddenvars = array('delete' => _XHELP_BUTTON_SET,        //'tickets' => implode($_POST['tickets'], ','),
727
        'op' => 'delete');
728
    $aHiddens[] = array('name' => 'delete',
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aHiddens was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aHiddens = 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...
729
                        'value' => _XHELP_BUTTON_SET);
730
    $aHiddens[] = array('name' => 'op',
731
                        'value' => 'delete');
732
    $xoopsOption['template_main'] = 'xhelp_deletetickets.html';
733
    require(XOOPS_ROOT_PATH.'/header.php');
734
    $xoopsTpl->assign('xhelp_message', _XHELP_MESSAGE_TICKET_DELETE_CNFRM);
735
    $xoopsTpl->assign('xhelp_hiddens', $aHiddens);
736
    $xoopsTpl->assign('xhelp_goodTickets', $sortedTickets['good']);
737
    $xoopsTpl->assign('xhelp_badTickets', $sortedTickets['bad']);
738
    $xoopsTpl->assign('xhelp_hasGoodTickets', count($sortedTickets['good']) > 0);
739
    $xoopsTpl->assign('xhelp_hasBadTickets', count($sortedTickets['bad']) > 0);
740
    $xoopsTpl->assign('xhelp_batchErrorMsg', _XHELP_MESSAGE_NO_DELETE_TICKET);
741
    require(XOOPS_ROOT_PATH.'/footer.php');
742
}
743
744
/**
745
 * @todo make SmartyNewsRenderer class
746
 */
747
function getAnnouncements($topicid, $limit=5, $start=0)
748
{
749
    global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsTpl;
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...
750
    $module_handler = xoops_gethandler('module');
751
752
    if(!$count =& $module_handler->getByDirname('news') || $topicid == 0){
753
        $xoopsTpl->assign('xhelp_useAnnouncements', false);
754
755
        return false;
756
    }
757
    include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
758
    $news_version = round($count->getVar('version') / 100, 2);
759
760
    switch ($news_version){
761
        case "1.1":
762
            $sarray = NewsStory::getAllPublished($limit, $start, $topicid);
763
            break;
764
765
        case "1.21":
766
        default:
767
            $sarray = NewsStory::getAllPublished($limit, $start, false, $topicid);
768
    }
769
770
    $scount = count($sarray);
771
    for ( $i = 0; $i < $scount; $i++ ) {
772
        $story = array();
773
        $story['id'] = $sarray[$i]->storyid();
774
        $story['poster'] = $sarray[$i]->uname();
775
        if ( $story['poster'] != false ) {
776
            $story['poster'] = "<a href='".XOOPS_URL."/userinfo.php?uid=".$sarray[$i]->uid()."'>".$story['poster']."</a>";
777
        } else {
778
            $story['poster'] = $xoopsConfig['anonymous'];
779
        }
780
        $story['posttime'] = formatTimestamp($sarray[$i]->published());
781
        $story['text'] = $sarray[$i]->hometext();
782
        $introcount = strlen($story['text']);
783
        $fullcount = strlen($sarray[$i]->bodytext());
784
        $totalcount = $introcount + $fullcount;
0 ignored issues
show
Unused Code introduced by
$totalcount 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...
785
        $morelink = '';
786
        if ( $fullcount > 1 ) {
787
            $morelink .= '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$sarray[$i]->storyid().'';
788
            $morelink .= '">'._XHELP_ANNOUNCE_READMORE.'</a> | ';
789
            //$morelink .= sprintf(_NW_BYTESMORE,$totalcount);
790
            //$morelink .= ' | ';
791
        }
792
        $ccount = $sarray[$i]->comments();
793
        $morelink .= '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$sarray[$i]->storyid().'';
794
        $morelink2 = '<a href="'.XOOPS_URL.'/modules/news/article.php?storyid='.$sarray[$i]->storyid().'';
795
        if ( $ccount == 0 ) {
796
            $morelink .= '">'._XHELP_COMMMENTS.'</a>';
797
        } else {
798
            if ( $fullcount < 1 ) {
799
                if ( $ccount == 1 ) {
800
                    $morelink .= '">'._XHELP_ANNOUNCE_READMORE.'</a> | '.$morelink2.'">'._XHELP_ANNOUNCE_ONECOMMENT.'</a>';
801 View Code Duplication
                } else {
802
                    $morelink .= '">'._XHELP_ANNOUNCE_READMORE.'</a> | '.$morelink2.'">';
803
                    $morelink .= sprintf(_XHELP_ANNOUNCE_NUMCOMMENTS, $ccount);
804
                    $morelink .= '</a>';
805
                }
806
            } else {
807 View Code Duplication
                if ( $ccount == 1 ) {
808
                    $morelink .= '">'._XHELP_ANNOUNCE_ONECOMMENT.'</a>';
809
                } else {
810
                    $morelink .= '">';
811
                    $morelink .= sprintf(_XHELP_ANNOUNCE_NUMCOMMENTS, $ccount);
812
                    $morelink .= '</a>';
813
                }
814
            }
815
        }
816
        $story['morelink'] = $morelink;
817
        $story['adminlink'] = '';
818
        if ( $xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid()) ) {
819
            $story['adminlink'] = $sarray[$i]->adminlink();
820
        }
821
        //$story['mail_link'] = 'mailto:?subject='.sprintf(_NW_INTARTICLE,$xoopsConfig['sitename']).'&amp;body='.sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']).':  '.XOOPS_URL.'/modules/news/article.php?storyid='.$sarray[$i]->storyid();
822
        $story['imglink'] = '';
823
        $story['align'] = '';
824
        if ( $sarray[$i]->topicdisplay() ) {
825
            $story['imglink'] = $sarray[$i]->imglink();
826
            $story['align'] = $sarray[$i]->topicalign();
827
        }
828
        $story['title'] = $sarray[$i]->textlink().'&nbsp;:&nbsp;'."<a href='".XOOPS_URL."/modules/news/article.php?storyid=".$sarray[$i]->storyid()."'>".$sarray[$i]->title()."</a>";
829
        $story['hits'] = $sarray[$i]->counter();
830
        // The line below can be used to display a Permanent Link image
831
        // $story['title'] .= "&nbsp;&nbsp;<a href='".XOOPS_URL."/modules/news/article.php?storyid=".$sarray[$i]->storyid()."'><img src='".XOOPS_URL."/modules/news/images/x.gif' alt='Permanent Link' /></a>";
832
833
        $xoopsTpl->append('xhelp_announcements', $story);
834
        $xoopsTpl->assign('xhelp_useAnnouncements', true);
835
        unset($story);
836
    }
837
}
838
839
function getDepartmentName($dept)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
840
{
841
    //BTW - I don't like that we rely on the global $depts variable to exist.
842
    // What if we moved this into the DepartmentsHandler class?
843
    global $depts;
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...
844
    if(isset($depts[$dept])){     // Make sure that ticket has a department
845
        $department = $depts[$dept]->getVar('department');
846
    } else {    // Else, fill it with 0
847
        $department = _XHELP_TEXT_NO_DEPT;
848
    }
849
850
    return $department;
851
}
852
853
function _cleanTickets($tickets)
854
{
855
    $t_tickets = explode(',', $tickets);
856
    $ret   = array();
857
    foreach($t_tickets as $ticket) {
858
        $ticket = intval($ticket);
859
        if ($ticket) {
860
            $ret[] = $ticket;
861
        }
862
    }
863
    unset($t_tickets);
864
865
    return $ret;
866
}
867
868
function staffmain_display()
869
{
870
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
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...
871
    global $limit, $start, $refresh, $displayName, $xhelp_isStaff, $_xhelpSession, $_eventsrv, $xhelp_module_header, $aSavedSearches;
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...
872
873
    if (!$xhelp_isStaff) {
874
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
875
    }
876
877
    $xhelpConfig = xhelpGetModuleConfig();
878
    //Get Saved Searches for Current User + Searches for every user
879
    $allSavedSearches =& xhelpGetSavedSearches(array($xoopsUser->getVar('uid'), XHELP_GLOBAL_UID));
880
881
    $hDepartments =& xhelpGetHandler('department');
882
    $hTickets     =& xhelpGetHandler('ticket');
883
    $hTicketList  =& xhelpGetHandler('ticketList');
884
885
    //Set Number of items in each section
886 View Code Duplication
    if ($limit == 0) {
887
        $limit = $xhelpConfig['xhelp_staffTicketCount'];
888
    } elseif ($limit == -1) {
889
        $limit = 0;
890
    }
891
    $uid = $xoopsUser->getVar('uid');
892
    $depts       =& $hDepartments->getObjects(null, true);
893
    $priority    =& $hTickets->getStaffTickets($uid, XHELP_QRY_STAFF_HIGHPRIORITY, $start, $limit);
894
    $ticketLists =& $hTicketList->getListsByUser($uid);
895
    $all_users   = array();
896
897
    $tickets = array();
898
    $i = 0;
899
    foreach($ticketLists as $ticketList){
900
        $searchid = $ticketList->getVar('searchid');
901
        $crit     = $allSavedSearches[$searchid]['search'];
902
        $searchname = $allSavedSearches[$searchid]['name'];
903
        $searchOnCustFields = $allSavedSearches[$searchid]['hasCustFields'];
904
        $crit->setLimit($limit);
905
        $newTickets = $hTickets->getObjectsByStaff($crit, false, $searchOnCustFields);
906
        $tickets[$i] = array();
907
        $tickets[$i]['tickets'] = array();
908
        $tickets[$i]['searchid'] = $searchid;
909
        $tickets[$i]['searchname'] = $searchname;
910
        $tickets[$i]['tableid'] = _safeHTMLId($searchname);
911
        $tickets[$i]['hasTickets'] = count($newTickets) > 0;
912
        $j = 0;
913
        foreach($newTickets as $ticket){
914
            $dept = @$depts[$ticket->getVar('department')];
915
            $tickets[$i]['tickets'][$j] = array('id'   => $ticket->getVar('id'),
916
                            'uid'           => $ticket->getVar('uid'),
917
                            'subject'       => xoops_substr($ticket->getVar('subject'),0,35),
918
                            'full_subject'  => $ticket->getVar('subject'),
919
                            'description'   => $ticket->getVar('description'),
920
                            'department'    => _safeDepartmentName($dept),
921
                            'departmentid'  => $ticket->getVar('department'),
922
                            'departmenturl' => xhelpMakeURI('index.php', array('op' => 'staffViewAll', 'dept'=> $ticket->getVar('department'))),
923
                            'priority'      => $ticket->getVar('priority'),
924
                            'status'        => xhelpGetStatus($ticket->getVar('status')),
925
                            'posted'        => $ticket->posted(),
926
                            'ownership'     => _XHELP_MESSAGE_NOOWNER,
927
                            'ownerid'       => $ticket->getVar('ownership'),
928
                            'closedBy'      => $ticket->getVar('closedBy'),
929
                            'totalTimeSpent'=> $ticket->getVar('totalTimeSpent'),
930
                            'uname'         => '',
931
                            'userinfo'      => XHELP_SITE_URL . '/userinfo.php?uid=' . $ticket->getVar('uid'),
932
                            'ownerinfo'     => '',
933
                            'url'           => XHELP_BASE_URL . '/ticket.php?id=' . $ticket->getVar('id'),
934
                            'overdue'       => $ticket->isOverdue());
935
            $all_users[$ticket->getVar('uid')] = '';
936
            $all_users[$ticket->getVar('ownership')] = '';
937
            $all_users[$ticket->getVar('closedBy')] = '';
938
            $j++;
939
        }
940
        $i++;
941
        unset($newTickets);
942
    }
943
944
    //Retrieve all member information for the current page
945 View Code Duplication
    if (count($all_users)) {
946
        $crit  = new Criteria('uid', "(". implode(array_keys($all_users), ',') .")", 'IN');
947
        $users =& xhelpGetUsers($crit, $displayName);
948
    } else {
949
        $users = array();
950
    }
951
952
    //Update tickets with user information
953
    for($i=0; $i<count($ticketLists);$i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
954
        for($j=0;$j<count($tickets[$i]['tickets']);$j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
955
            if (isset($users[ $tickets[$i]['tickets'][$j]['uid'] ])) {
956
                $tickets[$i]['tickets'][$j]['uname'] = $users[$tickets[$i]['tickets'][$j]['uid']];
957
            } else {
958
                $tickets[$i]['tickets'][$j]['uname'] = $xoopsConfig['anonymous'];
959
            }
960
            if ($tickets[$i]['tickets'][$j]['ownerid']) {
961
                if (isset($users[$tickets[$i]['tickets'][$j]['ownerid']])) {
962
                    $tickets[$i]['tickets'][$j]['ownership'] = $users[$tickets[$i]['tickets'][$j]['ownerid']];
963
                    $tickets[$i]['tickets'][$j]['ownerinfo'] = XOOPS_URL.'/userinfo.php?uid=' . $tickets[$i]['tickets'][$j]['ownerid'];
964
                }
965
            }
966
        }
967
    }
968
969
    $xoopsOption['template_main'] = 'xhelp_staff_index.html';   // Set template
970
    require(XOOPS_ROOT_PATH.'/header.php');                     // Include the page header
971
    if($refresh > 0){
972
        $xhelp_module_header .= "<meta http-equiv=\"Refresh\" content=\"$refresh;url=".XOOPS_URL."/modules/xhelp/index.php?refresh=$refresh\">";
973
    }
974
    $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
975
    $xoopsTpl->assign('xhelp_ticketLists', $tickets);
976
    $xoopsTpl->assign('xhelp_hasTicketLists', count($tickets) > 0);
977
    $xoopsTpl->assign('xhelp_refresh', $refresh);
978
    $xoopsTpl->assign('xoops_module_header',$xhelp_module_header);
979
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
980
    $xoopsTpl->assign('xhelp_uid', $xoopsUser->getVar('uid'));
981
    $xoopsTpl->assign('xhelp_current_file', basename(__FILE__));
982
    $xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches);
983
    $xoopsTpl->assign('xhelp_allSavedSearches', $allSavedSearches);
984
985
    getAnnouncements($xhelpConfig['xhelp_announcements']);
986
987
    require(XOOPS_ROOT_PATH.'/footer.php');
988
}
989
990
function _safeHTMLId($orig_text)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
991
{
992
    //Only allow alphanumeric characters
993
    $match = array('/[^a-zA-Z0-9]]/', '/\s/');
994
    $replace = array('', '');
995
996
    $htmlID = preg_replace($match, $replace, $orig_text);
997
998
    return $htmlID;
999
}
1000
1001
function _safeDepartmentName($deptObj)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
1002
{
1003
    if (is_object($deptObj)) {
1004
        $department = $deptObj->getVar('department');
1005
    } else {    // Else, fill it with 0
1006
        $department = _XHELP_TEXT_NO_DEPT;
1007
    }
1008
1009
    return $department;
1010
}
1011
1012
function staffviewall_display()
0 ignored issues
show
Coding Style introduced by
staffviewall_display 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...
1013
{
1014
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
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...
1015
    global $xhelp_isStaff, $sort_order, $start, $limit, $xhelp_module_header, $state_opt, $aSavedSearches;
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...
1016
    if (!$xhelp_isStaff) {
1017
        redirect_header(XHELP_BASE_URL."/".basename(__FILE__), 3, _NOPERM);
1018
    }
1019
1020
    //Sanity Check: sort / order column valid
1021
    $sort  = @$_REQUEST['sort'];
1022
    $order = @$_REQUEST['order'];
1023
1024
    $sort_columns = array('id' => 'DESC', 'priority' => 'DESC', 'elapsed' => 'ASC', 'lastupdate' => 'ASC', 'status' => 'ASC', 'subject' => 'ASC' , 'department' => 'ASC', 'ownership' => 'ASC', 'uid' => 'ASC');
1025
    $sort  = array_key_exists(strtolower($sort), $sort_columns) ? $sort : 'id';
1026
    $order = (in_array(strtoupper($order), $sort_order) ? $order : $sort_columns[$sort]);
1027
1028
    $uid       = $xoopsUser->getVar('uid');
1029
    $dept      = intval(isset($_REQUEST['dept']) ? $_REQUEST['dept'] : 0);
1030
    $status    = intval(isset($_REQUEST['status']) ? $_REQUEST['status'] : -1);
1031
    $ownership = intval(isset($_REQUEST['ownership']) ? $_REQUEST['ownership'] : -1);
1032
    $state     = intval(isset($_REQUEST['state']) ? $_REQUEST['state'] : -1);
1033
1034
    $xhelpConfig  =& xhelpGetModuleConfig();
1035
    $hTickets     =& xhelpGetHandler('ticket');
1036
    $hMembership  =& xhelpGetHandler('membership');
1037
1038 View Code Duplication
    if ($limit == 0) {
1039
        $limit = $xhelpConfig['xhelp_staffTicketCount'];
1040
    } elseif ($limit == -1) {
1041
        $limit = 0;
1042
    }
1043
1044
    //Prepare Database Query and Querystring
1045
    $crit     = new CriteriaCompo(new Criteria('uid', $uid, '=', 'j'));
1046
    $qs       = array('op' => 'staffViewAll', //Common Query String Values
1047
                    'start' => $start,
1048
                    'limit' => $limit);
1049
1050
    if ($dept) {
1051
        $qs['dept'] = $dept;
1052
        $crit->add(new Criteria('department', $dept, '=', 't'));
1053
    }
1054 View Code Duplication
    if ($status != -1) {
1055
        $qs['status'] = $status;
1056
        $crit->add(new Criteria('status', $status, '=', 't'));
1057
    }
1058
    if ($ownership != -1) {
1059
        $qs['ownership'] = $ownership;
1060
        $crit->add(new Criteria('ownership', $ownership, '=', 't'));
1061
    }
1062
1063 View Code Duplication
    if($state != -1){
1064
        $qs['state'] = $state;
1065
        $crit->add(new Criteria('state', $state, '=', 's'));
1066
    }
1067
1068
    $crit->setLimit($limit);
1069
    $crit->setStart($start);
1070
    $crit->setSort($sort);
1071
    $crit->setOrder($order);
1072
1073
    //Setup Column Sorting Vars
1074
    $tpl_cols = array();
1075 View Code Duplication
    foreach ($sort_columns as $col=>$initsort) {
1076
        $col_qs = array('sort' => $col);
1077
        //Check if we need to sort by current column
1078
        if ($sort == $col) {
1079
            $col_qs['order'] = ($order == $sort_order[0] ? $sort_order[1]: $sort_order[0]);
1080
            $col_sortby = true;
1081
        } else {
1082
            $col_qs['order'] = $initsort;
1083
            $col_sortby = false;
1084
        }
1085
        $tpl_cols[$col] = array('url'=>xhelpMakeURI(basename(__FILE__), array_merge($qs, $col_qs)),
1086
                        'urltitle' => _XHELP_TEXT_SORT_TICKETS,
1087
                        'sortby' => $col_sortby,
1088
                        'sortdir' => strtolower($col_qs['order']));
1089
    }
1090
1091
    $allTickets  = $hTickets->getObjectsByStaff($crit, true);
1092
    $count       = $hTickets->getCountByStaff($crit);
1093
    $nav         = new XoopsPageNav($count, $limit, $start, 'start', "op=staffViewAll&amp;limit=$limit&amp;sort=$sort&amp;order=$order&amp;dept=$dept&amp;status=$status&amp;ownership=$ownership");
1094
    $tickets     = array();
1095
    $allUsers    = array();
1096
    $depts       =& $hMembership->membershipByStaff($xoopsUser->getVar('uid'), true);    //All Departments for Staff Member
1097
1098
    foreach($allTickets as $ticket){
1099
        $deptid = $ticket->getVar('department');
1100
        $tickets[] = array('id'=>$ticket->getVar('id'),
1101
            'uid'=>$ticket->getVar('uid'),
1102
            'subject'       => xoops_substr($ticket->getVar('subject'),0,35),
1103
            'full_subject'  => $ticket->getVar('subject'),
1104
            'description'=>$ticket->getVar('description'),
1105
            'department'=>_safeDepartmentName($depts[$deptid]),
1106
            'departmentid'=> $deptid,
1107
            'departmenturl'=>xhelpMakeURI('index.php', array('op' => 'staffViewAll', 'dept'=> $deptid)),
1108
            'priority'=>$ticket->getVar('priority'),
1109
            'status'=>xhelpGetStatus($ticket->getVar('status')),
1110
            'posted'=>$ticket->posted(),
1111
            'ownership'=>_XHELP_MESSAGE_NOOWNER,
1112
            'ownerid' => $ticket->getVar('ownership'),
1113
            'closedBy'=>$ticket->getVar('closedBy'),
1114
            'closedByUname'=>'',
1115
            'totalTimeSpent'=>$ticket->getVar('totalTimeSpent'),
1116
            'uname'=>'',
1117
            'userinfo'=>XHELP_SITE_URL . '/userinfo.php?uid=' . $ticket->getVar('uid'),
1118
            'ownerinfo'=>'',
1119
            'url'=>XHELP_BASE_URL . '/ticket.php?id=' . $ticket->getVar('id'),
1120
            'elapsed' => $ticket->elapsed(),
1121
            'lastUpdate' => $ticket->lastUpdate(),
1122
            'overdue' => $ticket->isOverdue());
1123
        $allUsers[$ticket->getVar('uid')] = '';
1124
        $allUsers[$ticket->getVar('ownership')] = '';
1125
        $allUsers[$ticket->getVar('closedBy')] = '';
1126
    }
1127
    $has_allTickets = count($allTickets) > 0;
1128
    unset($allTickets);
1129
1130
    //Get all member information needed on this page
1131
    $crit  = new Criteria('uid', "(". implode(array_keys($allUsers), ',') .")", 'IN');
1132
    $users =& xhelpGetUsers($crit, $xhelpConfig['xhelp_displayName']);
1133
    unset($allUsers);
1134
1135
    $staff_opt =& xhelpGetStaff($xhelpConfig['xhelp_displayName']);
1136
1137
    for($i=0;$i<count($tickets);$i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1138
        if (isset($users[$tickets[$i]['uid']])) {
1139
            $tickets[$i]['uname'] = $users[$tickets[$i]['uid']];
1140
        } else {
1141
            $tickets[$i]['uname'] = $xoopsConfig['anonymous'];
1142
        }
1143
        if ($tickets[$i]['ownerid']) {
1144
            if (isset($users[$tickets[$i]['ownerid']])) {
1145
                $tickets[$i]['ownership'] = $users[$tickets[$i]['ownerid']];
1146
                $tickets[$i]['ownerinfo'] = XHELP_SITE_URL.'/userinfo.php?uid=' . $tickets[$i]['ownerid'];
1147
            }
1148
        }
1149
        if ($tickets[$i]['closedBy']) {
1150
            if (isset($users[$tickets[$i]['closedBy']])) {
1151
                $tickets[$i]['closedByUname'] = $users[$tickets[$i]['closedBy']];
1152
            }
1153
        }
1154
    }
1155
1156
    $xoopsOption['template_main'] = 'xhelp_staff_viewall.html';   // Set template
1157
    require(XOOPS_ROOT_PATH.'/header.php');                     // Include the page header
1158
1159
    $javascript = "<script type=\"text/javascript\" src=\"". XHELP_BASE_URL ."/include/functions.js\"></script>
1160
<script type=\"text/javascript\" src='".XHELP_SCRIPT_URL."/changeSelectedState.php?client'></script>
1161
<script type=\"text/javascript\">
1162
<!--
1163
function states_onchange()
1164
{
1165
    state = xoopsGetElementById('state');
1166
    var sH = new xhelpweblib(stateHandler);
1167
    sH.statusesbystate(state.value);
1168
}
1169
1170
var stateHandler = {
1171
    statusesbystate: function(result){
1172
        var statuses = gE('status');
1173
        xhelpFillSelect(statuses, result);
1174
    }
1175
}
1176
1177
function window_onload()
1178
{
1179
    xhelpDOMAddEvent(xoopsGetElementById('state'), 'change', states_onchange, true);
1180
}
1181
1182
window.setTimeout('window_onload()', 1500);
1183
//-->
1184
</script>";
1185
1186
    $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
1187
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
1188
    $xoopsTpl->assign('xhelp_cols', $tpl_cols);
1189
    $xoopsTpl->assign('xhelp_allTickets', $tickets);
1190
    $xoopsTpl->assign('xhelp_has_tickets', $has_allTickets);
1191
    $xoopsTpl->assign('xhelp_priorities', array(5, 4, 3, 2, 1));
1192
    $xoopsTpl->assign('xoops_module_header',$javascript.$xhelp_module_header);
1193
    $xoopsTpl->assign('xhelp_priorities_desc', array('5' => _XHELP_PRIORITY5, '4' => _XHELP_PRIORITY4,'3' => _XHELP_PRIORITY3, '2' => _XHELP_PRIORITY2, '1' => _XHELP_PRIORITY1));
1194
    if($limit != 0){
1195
        $xoopsTpl->assign('xhelp_pagenav', $nav->renderNav());
1196
    }
1197
    $xoopsTpl->assign('xhelp_limit_options', array(-1 => _XHELP_TEXT_SELECT_ALL, 10 => '10', 15 => '15', 20 => '20', 30 => '30'));
1198
    $xoopsTpl->assign('xhelp_filter', array('department' => $dept,
1199
            'status' => $status,
1200
            'state' => $state,
1201
            'ownership' => $ownership,
1202
            'limit' => $limit,
1203
            'start' => $start,
1204
            'sort' => $sort,
1205
            'order' => $order));
1206
1207
    $xoopsTpl->append('xhelp_department_values', 0);
1208
    $xoopsTpl->append('xhelp_department_options', _XHELP_TEXT_SELECT_ALL);
1209
1210
    if($xhelpConfig['xhelp_deptVisibility'] == 1){    // Apply dept visibility to staff members?
1211
        $hMembership =& xhelpGetHandler('membership');
1212
        $depts =& $hMembership->getVisibleDepartments($xoopsUser->getVar('uid'));
1213
    }
1214
1215
    foreach($depts as $xhelp_id=>$obj) {
1216
        $xoopsTpl->append('xhelp_department_values', $xhelp_id);
1217
        $xoopsTpl->append('xhelp_department_options', $obj->getVar('department'));
1218
    }
1219
1220
    $xoopsTpl->assign('xhelp_ownership_options', array_values($staff_opt));
1221
    $xoopsTpl->assign('xhelp_ownership_values', array_keys($staff_opt));
1222
    $xoopsTpl->assign('xhelp_state_options', array_keys($state_opt));
1223
    $xoopsTpl->assign('xhelp_state_values', array_values($state_opt));
1224
    $xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches);
1225
1226
    $hStatus =& xhelpGetHandler('status');
1227
    $crit = new Criteria('', '');
1228
    $crit->setSort('description');
1229
    $crit->setOrder('ASC');
1230
    $statuses =& $hStatus->getObjects($crit);
1231
1232
    $xoopsTpl->append('xhelp_status_options', _XHELP_TEXT_SELECT_ALL);
1233
    $xoopsTpl->append('xhelp_status_values', -1);
1234
    foreach($statuses as $status){
1235
        $xoopsTpl->append('xhelp_status_options', $status->getVar('description'));
1236
        $xoopsTpl->append('xhelp_status_values', $status->getVar('id'));
1237
    }
1238
1239
    $xoopsTpl->assign('xhelp_department_current', $dept);
1240
    $xoopsTpl->assign('xhelp_status_current', $status);
1241
    $xoopsTpl->assign('xhelp_current_file', basename(__FILE__));
1242
    $xoopsTpl->assign('xhelp_text_allTickets', _XHELP_TEXT_ALL_TICKETS);
1243
1244
    require(XOOPS_ROOT_PATH.'/footer.php');
1245
}
1246
1247
function usermain_display()
1248
{
1249
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
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...
1250
    global $xhelp_module_header;
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...
1251
1252
    $xoopsOption['template_main'] = 'xhelp_user_index.html';    // Set template
1253
    require(XOOPS_ROOT_PATH.'/header.php');                     // Include the page header
1254
1255
    $xhelpConfig = xhelpGetModuleConfig();
1256
    $hStaff =& xhelpGetHandler('staff');
1257
1258
    $staffCount =& $hStaff->getObjects();
1259
    if (count($staffCount) == 0) {
1260
        $xoopsTpl->assign('xhelp_noStaff', true);
1261
    }
1262
    /**
1263
     * @todo remove calls to these three classes and use the ones in beginning
1264
     */
1265
    $member_handler =& xoops_gethandler('member');
1266
    $hDepartments =& xhelpGetHandler('department');
1267
    $hTickets =& xhelpGetHandler('ticket');
1268
1269
    $userTickets =& $hTickets->getMyUnresolvedTickets($xoopsUser->getVar('uid'), true);
1270
1271
    foreach($userTickets as $ticket){
1272
        $aUserTickets[] = array('id'=>$ticket->getVar('id'),
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aUserTickets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aUserTickets = 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...
1273
            'uid'=>$ticket->getVar('uid'),
1274
            'subject'=>$ticket->getVar('subject'),
1275
            'status'=>xhelpGetStatus($ticket->getVar('status')),
1276
            'priority'=>$ticket->getVar('priority'),
1277
            'posted'=>$ticket->posted());
1278
    }
1279
    $has_userTickets = count($userTickets) > 0;
1280
    if($has_userTickets){
1281
        $xoopsTpl->assign('xhelp_userTickets', $aUserTickets);
0 ignored issues
show
Bug introduced by
The variable $aUserTickets 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...
1282
    } else {
1283
        $xoopsTpl->assign('xhelp_userTickets', 0);
1284
    }
1285
    $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
1286
    $xoopsTpl->assign('xhelp_has_userTickets', $has_userTickets);
1287
    $xoopsTpl->assign('xhelp_priorities', array(5, 4, 3, 2, 1));
1288
    $xoopsTpl->assign('xhelp_priorities_desc', array('5' => _XHELP_PRIORITY5, '4' => _XHELP_PRIORITY4,'3' => _XHELP_PRIORITY3, '2' => _XHELP_PRIORITY2, '1' => _XHELP_PRIORITY1));
1289
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
1290
    $xoopsTpl->assign('xoops_module_header',$xhelp_module_header);
1291
1292
    getAnnouncements($xhelpConfig['xhelp_announcements']);
1293
1294
    require(XOOPS_ROOT_PATH.'/footer.php');                     //Include the page footer
1295
}
1296
1297
function userviewall_display()
0 ignored issues
show
Coding Style introduced by
userviewall_display 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...
1298
{
1299
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
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...
1300
    global $xhelp_module_header, $sort, $order, $sort_order, $limit, $start, $state_opt, $state;
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...
1301
1302
    $xoopsOption['template_main'] = 'xhelp_user_viewall.html';    // Set template
1303
    require(XOOPS_ROOT_PATH.'/header.php');                     // Include the page header
1304
1305
    //Sanity Check: sort column valid
1306
    $sort_columns = array('id' => 'DESC', 'priority' => 'DESC', 'elapsed' => 'ASC', 'lastupdate' => 'ASC', 'status' => 'ASC', 'subject' => 'ASC' , 'department' => 'ASC', 'ownership' => 'ASC', 'uid' => 'ASC');
1307
    $sort  = array_key_exists($sort, $sort_columns) ? $sort : 'id';
1308
    $order = @$_REQUEST['order'];
1309
    $order = (in_array(strtoupper($order), $sort_order) ? $order : $sort_columns[$sort]);
1310
    $uid   = $xoopsUser->getVar('uid');
1311
1312
    $hDepartments =& xhelpGetHandler('department');
1313
    $hTickets      =& xhelpGetHandler('ticket');
1314
    $hStaff       =& xhelpGetHandler('staff');
1315
1316
    $dept     = intval(isset($_REQUEST['dept']) ? $_REQUEST['dept'] : 0);
1317
    $status   = intval(isset($_REQUEST['status']) ? $_REQUEST['status'] : -1);
1318
    $state    = intval(isset($_REQUEST['state']) ? $_REQUEST['state'] : -1);
1319
    $depts    =& $hDepartments->getObjects(null, true);
1320
1321
    if ($limit == 0) {
1322
        $limit = 10;
1323
    } elseif ($limit == -1) {
1324
        $limit = 0;
1325
    }
1326
1327
    //Prepare Database Query and Querystring
1328
    $crit     = new CriteriaCompo(new Criteria ('uid', $uid));
1329
    $qs       = array('op' => 'userViewAll', //Common Query String Values
1330
                    'start' => $start,
1331
                    'limit' => $limit);
1332
1333
    if ($dept) {
1334
        $qs['dept'] = $dept;
1335
        $crit->add(new Criteria('department', $dept, '=', 't'));
1336
    }
1337 View Code Duplication
    if ($status != -1) {
1338
        $qs['status'] = $status;
1339
        $crit->add(new Criteria('status', $status, '=', 't'));
1340
    }
1341
1342 View Code Duplication
    if($state != -1){
1343
        $qs['state'] = $state;
1344
        $crit->add(new Criteria('state', $state, '=', 's'));
1345
    }
1346
1347
    $crit->setLimit($limit);
1348
    $crit->setStart($start);
1349
    $crit->setSort($sort);
1350
    $crit->setOrder($order);
1351
1352
    //Setup Column Sorting Vars
1353
    $tpl_cols = array();
1354 View Code Duplication
    foreach ($sort_columns as $col => $initsort) {
1355
        $col_qs = array('sort' => $col);
1356
        //Check if we need to sort by current column
1357
        if ($sort == $col) {
1358
            $col_qs['order'] = ($order == $sort_order[0] ? $sort_order[1]: $sort_order[0]);
1359
            $col_sortby = true;
1360
        } else {
1361
            $col_qs['order'] = $initsort;
1362
            $col_sortby = false;
1363
        }
1364
        $tpl_cols[$col] = array('url'=>xhelpMakeURI(basename(__FILE__), array_merge($qs, $col_qs)),
1365
                        'urltitle' => _XHELP_TEXT_SORT_TICKETS,
1366
                        'sortby' => $col_sortby,
1367
                        'sortdir' => strtolower($col_qs['order']));
1368
    }
1369
1370
    $xoopsTpl->assign('xhelp_cols', $tpl_cols);
1371
    $staffCount =& $hStaff->getObjects();
1372
    if(count($staffCount) == 0){
1373
        $xoopsTpl->assign('xhelp_noStaff', true);
1374
    }
1375
1376
    $userTickets =& $hTickets->getObjects($crit);
1377
    foreach($userTickets as $ticket){
1378
        $aUserTickets[] = array('id'=>$ticket->getVar('id'),
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aUserTickets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aUserTickets = 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...
1379
                        'uid'=>$ticket->getVar('uid'),
1380
                        'subject'       => xoops_substr($ticket->getVar('subject'),0,35),
1381
                        'full_subject'  => $ticket->getVar('subject'),
1382
                        'status'=>xhelpGetStatus($ticket->getVar('status')),
1383
                        'department'=>_safeDepartmentName($depts[$ticket->getVar('department')]),
1384
                        'departmentid'=> $ticket->getVar('department'),
1385
                        'departmenturl'=>xhelpMakeURI(basename(__FILE__), array('op' => 'userViewAll', 'dept'=> $ticket->getVar('department'))),
1386
                        'priority'=>$ticket->getVar('priority'),
1387
                        'posted'=>$ticket->posted(),
1388
                        'elapsed'=>$ticket->elapsed());
1389
    }
1390
    $has_userTickets = count($userTickets) > 0;
1391
    if($has_userTickets){
1392
        $xoopsTpl->assign('xhelp_userTickets', $aUserTickets);
0 ignored issues
show
Bug introduced by
The variable $aUserTickets 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...
1393
    } else {
1394
        $xoopsTpl->assign('xhelp_userTickets', 0);
1395
    }
1396
1397
    $javascript = "<script type=\"text/javascript\" src=\"". XHELP_BASE_URL ."/include/functions.js\"></script>
1398
<script type=\"text/javascript\" src='".XHELP_SCRIPT_URL."/changeSelectedState.php?client'></script>
1399
<script type=\"text/javascript\">
1400
<!--
1401
function states_onchange()
1402
{
1403
    state = xoopsGetElementById('state');
1404
    var sH = new xhelpweblib(stateHandler);
1405
    sH.statusesbystate(state.value);
1406
}
1407
1408
var stateHandler = {
1409
    statusesbystate: function(result){
1410
        var statuses = gE('status');
1411
        xhelpFillSelect(statuses, result);
1412
    }
1413
}
1414
1415
function window_onload()
1416
{
1417
    xhelpDOMAddEvent(xoopsGetElementById('state'), 'change', states_onchange, true);
1418
}
1419
1420
window.setTimeout('window_onload()', 1500);
1421
//-->
1422
</script>";
1423
1424
    $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
1425
    $xoopsTpl->assign('xhelp_has_userTickets', $has_userTickets);
1426
    $xoopsTpl->assign('xhelp_viewAll', true);
1427
    $xoopsTpl->assign('xhelp_priorities', array(5, 4, 3, 2, 1));
1428
    $xoopsTpl->assign('xhelp_priorities_desc', array('5' => _XHELP_PRIORITY5, '4' => _XHELP_PRIORITY4,'3' => _XHELP_PRIORITY3, '2' => _XHELP_PRIORITY2, '1' => _XHELP_PRIORITY1));
1429
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL .'/');
1430
    $xoopsTpl->assign('xoops_module_header',$javascript.$xhelp_module_header);
1431
    $xoopsTpl->assign('xhelp_limit_options', array(-1 => _XHELP_TEXT_SELECT_ALL, 10 => '10', 15 => '15', 20 => '20', 30 => '30'));
1432
    $xoopsTpl->assign('xhelp_filter', array('department' => $dept,
1433
            'status' => $status,
1434
            'limit' => $limit,
1435
            'start' => $start,
1436
            'sort' => $sort,
1437
            'order' => $order,
1438
            'state' => $state));
1439
    $xoopsTpl->append('xhelp_department_values', 0);
1440
    $xoopsTpl->append('xhelp_department_options', _XHELP_TEXT_SELECT_ALL);
1441
1442
    //$depts = getVisibleDepartments($depts);
1443
    $hMembership =& xhelpGetHandler('membership');
1444
    $depts =& $hMembership->getVisibleDepartments($xoopsUser->getVar('uid'));
1445
    foreach($depts as $xhelp_id=>$obj) {
1446
        $xoopsTpl->append('xhelp_department_values', $xhelp_id);
1447
        $xoopsTpl->append('xhelp_department_options', $obj->getVar('department'));
1448
    }
1449
1450
    $hStatus =& xhelpGetHandler('status');
1451
    $crit = new Criteria('', '');
1452
    $crit->setSort('description');
1453
    $crit->setOrder('ASC');
1454
    $statuses =& $hStatus->getObjects($crit);
1455
1456
    $xoopsTpl->append('xhelp_status_options', _XHELP_TEXT_SELECT_ALL);
1457
    $xoopsTpl->append('xhelp_status_values', -1);
1458
    foreach($statuses as $status){
1459
        $xoopsTpl->append('xhelp_status_options', $status->getVar('description'));
1460
        $xoopsTpl->append('xhelp_status_values', $status->getVar('id'));
1461
    }
1462
1463
    $xoopsTpl->assign('xhelp_department_current', $dept);
1464
    $xoopsTpl->assign('xhelp_status_current', $status);
1465
    $xoopsTpl->assign('xhelp_state_options', array_keys($state_opt));
1466
    $xoopsTpl->assign('xhelp_state_values', array_values($state_opt));
1467
1468
    require(XOOPS_ROOT_PATH.'/footer.php');
1469
}
1470
1471
function _makeBatchTicketArray(&$oTickets, &$depts, &$all_users, &$j, $task)
1472
{
1473
    global $xhelp_staff;
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...
1474
1475
    $sortedTickets['good'] = array();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sortedTickets was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sortedTickets = 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...
1476
    $sortedTickets['bad'] = array();
1477
    foreach($oTickets as $ticket){
1478
        $dept = @$depts[$ticket->getVar('department')];
1479
        if(!$hasRights = $xhelp_staff->checkRoleRights($task, $ticket->getVar('department'))){
1480
            $sortedTickets['bad'][] = array(
1481
                            'id'   => $ticket->getVar('id'),
1482
                            'uid'           => $ticket->getVar('uid'),
1483
                            'subject'       => xoops_substr($ticket->getVar('subject'),0,35),
1484
                            'full_subject'  => $ticket->getVar('subject'),
1485
                            'description'   => $ticket->getVar('description'),
1486
                            'department'    => _safeDepartmentName($dept),
1487
                            'departmentid'  => $ticket->getVar('department'),
1488
                            'departmenturl' => xhelpMakeURI('index.php', array('op' => 'staffViewAll', 'dept'=> $ticket->getVar('department'))),
1489
                            'priority'      => $ticket->getVar('priority'),
1490
                            'status'        => xhelpGetStatus($ticket->getVar('status')),
1491
                            'posted'        => $ticket->posted(),
1492
                            'ownership'     => _XHELP_MESSAGE_NOOWNER,
1493
                            'ownerid'       => $ticket->getVar('ownership'),
1494
                            'closedBy'      => $ticket->getVar('closedBy'),
1495
                            'totalTimeSpent'=> $ticket->getVar('totalTimeSpent'),
1496
                            'uname'         => '',
1497
                            'userinfo'      => XHELP_SITE_URL . '/userinfo.php?uid=' . $ticket->getVar('uid'),
1498
                            'ownerinfo'     => '',
1499
                            'url'           => XHELP_BASE_URL . '/ticket.php?id=' . $ticket->getVar('id'),
1500
                            'overdue'       => $ticket->isOverdue());
1501
        } else {
1502
            $sortedTickets['good'][] = array(
1503
                            'id'   => $ticket->getVar('id'),
1504
                            'uid'           => $ticket->getVar('uid'),
1505
                            'subject'       => xoops_substr($ticket->getVar('subject'),0,35),
1506
                            'full_subject'  => $ticket->getVar('subject'),
1507
                            'description'   => $ticket->getVar('description'),
1508
                            'department'    => _safeDepartmentName($dept),
1509
                            'departmentid'  => $ticket->getVar('department'),
1510
                            'departmenturl' => xhelpMakeURI('index.php', array('op' => 'staffViewAll', 'dept'=> $ticket->getVar('department'))),
1511
                            'priority'      => $ticket->getVar('priority'),
1512
                            'status'        => xhelpGetStatus($ticket->getVar('status')),
1513
                            'posted'        => $ticket->posted(),
1514
                            'ownership'     => _XHELP_MESSAGE_NOOWNER,
1515
                            'ownerid'       => $ticket->getVar('ownership'),
1516
                            'closedBy'      => $ticket->getVar('closedBy'),
1517
                            'totalTimeSpent'=> $ticket->getVar('totalTimeSpent'),
1518
                            'uname'         => '',
1519
                            'userinfo'      => XHELP_SITE_URL . '/userinfo.php?uid=' . $ticket->getVar('uid'),
1520
                            'ownerinfo'     => '',
1521
                            'url'           => XHELP_BASE_URL . '/ticket.php?id=' . $ticket->getVar('id'),
1522
                            'overdue'       => $ticket->isOverdue());
1523
        }
1524
        $all_users[$ticket->getVar('uid')] = '';
1525
        $all_users[$ticket->getVar('ownership')] = '';
1526
        $all_users[$ticket->getVar('closedBy')] = '';
1527
        $j++;
1528
    }
1529
1530
    return $sortedTickets;
1531
}
1532
1533
function _updateBatchTicketInfo(&$sortedTickets, &$users, &$j)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
1534
{
1535
    global $xoopsConfig;
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...
1536
1537
    //Update tickets with user information
1538
    $aTicketTypes = array('good', 'bad');
1539
    foreach($aTicketTypes as $ticketType){
1540
        for($j=0;$j<count($sortedTickets[$ticketType]);$j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1541
            if (isset($users[$sortedTickets[$ticketType][$j]['uid'] ])) {
1542
                $sortedTickets[$ticketType][$j]['uname'] = $users[$sortedTickets[$ticketType][$j]['uid']];
1543
            } else {
1544
                $sortedTickets[$ticketType][$j]['uname'] = $xoopsConfig['anonymous'];
1545
            }
1546
            if ($sortedTickets[$ticketType][$j]['ownerid']) {
1547
                if (isset($users[$sortedTickets[$ticketType][$j]['ownerid']])) {
1548
                    $sortedTickets[$ticketType][$j]['ownership'] = $users[$sortedTickets[$ticketType][$j]['ownerid']];
1549
                    $sortedTickets[$ticketType][$j]['ownerinfo'] = XOOPS_URL.'/userinfo.php?uid=' . $sortedTickets[$ticketType][$j]['ownerid'];
1550
                }
1551
            }
1552
        }
1553
    }
1554
1555
    return $sortedTickets;
1556
}
1557