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

profile.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

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

1
<?php
2
//$Id: profile.php,v 1.42 2005/11/29 17:52:26 ackbarr Exp $
3
require_once('header.php');
4
include_once(XHELP_BASE_PATH.'/functions.php');
5
6
// Disable module caching in smarty
7
$xoopsConfig['module_cache'][$xoopsModule->getVar('mid')] = 0;
8
9
if($xoopsUser){
10
    $responseTplID = 0;
11
12
    $op = 'default';
13
    if(isset($_REQUEST['op'])){
14
        $op = $_REQUEST['op'];
15
    }
16
17
    if(isset($_GET['responseTplID'])){
18
        $responseTplID = intval($_GET['responseTplID']);
19
    }
20
21
    $xoopsOption['template_main'] = 'xhelp_staff_profile.html';   // Set template
22
    require(XOOPS_ROOT_PATH.'/header.php');                     // Include the page header
23
24
    $numResponses = 0;
25
    $uid = $xoopsUser->getVar('uid');
26
    $hStaff =& xhelpGetHandler('staff');
27
    if (!$staff =& $hStaff->getByUid($uid)) {
28
        redirect_header(XHELP_BASE_URL."/index.php", 3, _XHELP_ERROR_INV_STAFF);
29
        exit();
30
    }
31
    $hTicketList =& xhelpGetHandler('ticketList');
32
    $hResponseTpl =& xhelpGetHandler('responseTemplates');
33
    $crit = new Criteria('uid', $uid);
34
    $crit->setSort('name');
35
    $responseTpl =& $hResponseTpl->getObjects($crit);
36
37 View Code Duplication
    foreach($responseTpl as $response){
38
        $aResponseTpl[] = array('id'=>$response->getVar('id'),
39
                              'uid'=>$response->getVar('uid'),
40
                              'name'=>$response->getVar('name'),
41
                              'response'=>$response->getVar('response'));
42
    }
43
    $has_responseTpl = count($responseTpl) > 0;
44
    unset($responseTpl);
45
46
    $displayTpl =& $hResponseTpl->get($responseTplID);
47
48
    switch($op){
49
        case "responseTpl":
50
            if(isset($_POST['updateResponse'])){
51
                if(isset($_POST['attachSig'])){
52
                    $staff->setVar('attachSig', $_POST['attachSig']);
53
                    if(!$hStaff->insert($staff)){
54
                        $message = _XHELP_MESSAGE_UPDATE_SIG_ERROR;
55
                    }
56
                }
57
                if($_POST['name'] == '' || $_POST['replyText'] == ''){
58
                    redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_ERROR_INV_TEMPLATE);
59
                }
60
                if($_POST['responseid'] != 0){
61
                    $updateTpl =& $hResponseTpl->get($_POST['responseid']);
62
                } else {
63
                    $updateTpl =& $hResponseTpl->create();
64
                }
65
                $updateTpl->setVar('uid', $uid);
66
                $updateTpl->setVar('name',$_POST['name']);
67
                $updateTpl->setVar('response',$_POST['replyText']);
68
                if($hResponseTpl->insert($updateTpl)){
69
                    $message = _XHELP_MESSAGE_RESPONSE_TPL;
70
                } else {
71
                    $message = _XHELP_MESSAGE_RESPONSE_TPL_ERROR;
72
                }
73
                redirect_header(XHELP_BASE_URL."/profile.php", 3, $message);
74
            } else {        // Delete response template
75
                $hResponseTpl =& xhelpGetHandler('responseTemplates');
76
                $displayTpl =& $hResponseTpl->get($_POST['tplID']);
77
                if($hResponseTpl->delete($displayTpl)){
78
                    $message = _XHELP_MESSAGE_DELETE_RESPONSE_TPL;
79
                } else {
80
                    $message = _XHELP_MESSAGE_DELETE_RESPONSE_TPL_ERROR;
81
                }
82
                redirect_header(XHELP_BASE_URL."/profile.php", 3, $message);
83
            }
84
            break;
85
86
        case "updateNotification":
87
            $notArray = (is_array($_POST['notifications']) ?  $_POST['notifications'] : array(0));
88
            $notValue = array_sum($notArray);
89
            $staff->setVar('notify', $notValue);
90
            if(isset($_POST['email']) && $_POST['email'] <> $staff->getVar('email')){
91
                $staff->setVar('email', $_POST['email']);
92
            }
93
            if(!$hStaff->insert($staff)){
94
                $message = _XHELP_MESSAGE_UPDATE_EMAIL_ERROR;
95
96
            }
97
            $message = _XHELP_MESSAGE_NOTIFY_UPDATE;
98
            redirect_header(XHELP_BASE_URL."/profile.php", 3, $message);
99
            break;
100
101
        case "addTicketList":
102
            if(isset($_POST['savedSearch']) && ($_POST['savedSearch'] != 0)){
103
                $searchid = intval($_POST['savedSearch']);
104
                $ticketList =& $hTicketList->create();
105
                $ticketList->setVar('uid', $xoopsUser->getVar('uid'));
106
                $ticketList->setVar('searchid', $searchid);
107
                $ticketList->setVar('weight', $hTicketList->createNewWeight($xoopsUser->getVar('uid')));
108
109 View Code Duplication
                if($hTicketList->insert($ticketList)){
110
                    header("Location: ".XHELP_BASE_URL."/profile.php");
111
                } else {
112
                    redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_MSG_ADD_TICKETLIST_ERR);
113
                }
114
            }
115
            break;
116
117 View Code Duplication
        case "editTicketList":
118
            if(isset($_REQUEST['id']) && $_REQUEST['id'] != 0){
119
                $listID = intval($_REQUEST['id']);
120
            } else {
121
                redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_MSG_NO_ID);
122
            }
123
            break;
124
125
        case "deleteTicketList":
126
            if(isset($_REQUEST['id']) && $_REQUEST['id'] != 0){
127
                $listID = intval($_REQUEST['id']);
128
            } else {
129
                redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_MSG_NO_ID);
130
            }
131
            $ticketList =& $hTicketList->get($listID);
132
            if($hTicketList->delete($ticketList, true)){
133
                header("Location: ".XHELP_BASE_URL."/profile.php");
134
            } else {
135
                redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_MSG_DEL_TICKETLIST_ERR);
136
            }
137
            break;
138
139
        case "changeListWeight":
140
            if(isset($_REQUEST['id']) && $_REQUEST['id'] != 0){
141
                $listID = intval($_REQUEST['id']);
142
            } else {
143
                redirect_header(XHELP_BASE_URL."/profile.php", 3, _XHELP_MSG_NO_ID);
144
            }
145
            $up = false;
146
            if(isset($_REQUEST['up'])){
147
                $up = $_REQUEST['up'];
148
            }
149
            $hTicketList->changeWeight($listID, $up);
150
            header("Location: ".XHELP_BASE_URL."/profile.php");
151
            break;
152
153
        default:
154
            $xoopsTpl->assign('xhelp_responseTplID', $responseTplID);
155
            $module_header = '<!--[if gte IE 5.5000]><script src="iepngfix.js" language="JavaScript" type="text/javascript"></script><![endif]-->';
156
            $xoopsTpl->assign('xhelp_imagePath', XOOPS_URL .'/modules/xhelp/images/');
157
            $xoopsTpl->assign('xhelp_has_sig', $staff->getVar('attachSig'));
158
            if(isset($aResponseTpl)){
159
                $xoopsTpl->assign('xhelp_responseTpl', $aResponseTpl);
160
            } else {
161
                $xoopsTpl->assign('xhelp_responseTpl', 0);
162
            }
163
            $xoopsTpl->assign('xhelp_hasResponseTpl', (isset($aResponseTpl)) ? count($aResponseTpl) > 0 : 0);
164
            if(!empty($responseTplID)){
165
                $xoopsTpl->assign('xhelp_displayTpl_id', $displayTpl->getVar('id'));
166
                $xoopsTpl->assign('xhelp_displayTpl_name', $displayTpl->getVar('name'));
167
                $xoopsTpl->assign('xhelp_displayTpl_response', $displayTpl->getVar('response', 'e'));
168
            } else {
169
                $xoopsTpl->assign('xhelp_displayTpl_id', 0);
170
                $xoopsTpl->assign('xhelp_displayTpl_name', '');
171
                $xoopsTpl->assign('xhelp_displayTpl_response', '');
172
            }
173
            $xoopsTpl->assign('xoops_module_header', $module_header);
174
            $xoopsTpl->assign('xhelp_callsClosed', $staff->getVar('callsClosed'));
175
            $xoopsTpl->assign('xhelp_numReviews', $staff->getVar('numReviews'));
176
            $xoopsTpl->assign('xhelp_responseTime', xhelpFormatTime( ($staff->getVar('ticketsResponded') ? $staff->getVar('responseTime') / $staff->getVar('ticketsResponded') : 0)));
177
            $notify_method = $xoopsUser->getVar('notify_method');
178
            $xoopsTpl->assign('xhelp_notify_method', ($notify_method == 1) ? _XHELP_NOTIFY_METHOD1 : _XHELP_NOTIFY_METHOD2);
179
180
            if(($staff->getVar('rating') == 0) || ($staff->getVar('numReviews') == 0)){
181
                $xoopsTpl->assign('xhelp_rating', 0);
182
            } else {
183
                $xoopsTpl->assign('xhelp_rating', intval($staff->getVar('rating')/$staff->getVar('numReviews')));
184
            }
185
            $xoopsTpl->assign('xhelp_uid', $xoopsUser->getVar('uid'));
186
            $xoopsTpl->assign('xhelp_rating0', _XHELP_RATING0);
187
            $xoopsTpl->assign('xhelp_rating1', _XHELP_RATING1);
188
            $xoopsTpl->assign('xhelp_rating2', _XHELP_RATING2);
189
            $xoopsTpl->assign('xhelp_rating3', _XHELP_RATING3);
190
            $xoopsTpl->assign('xhelp_rating4', _XHELP_RATING4);
191
            $xoopsTpl->assign('xhelp_rating5', _XHELP_RATING5);
192
            $xoopsTpl->assign('xhelp_staff_email', $staff->getVar('email'));
193
            $xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches);
194
195
            $myRoles =& $hStaff->getRoles($xoopsUser->getVar('uid'), true);
196
            $hNotification =& xhelpGetHandler('notification');
197
            $settings =& $hNotification->getObjects(null, true);
198
199
            $templates =& $xoopsModule->getInfo('_email_tpl');
200
            $has_notifications = count($templates);
201
202
            // Check that notifications are enabled by admin
203
            $i = 0;
204
            $staff_enabled = true;
205
            foreach($templates as $template_id=>$template){
206
                if($template['category'] == 'dept'){
207
                    $staff_setting = $settings[$template_id]->getVar('staff_setting');
208
                    if($staff_setting == 4){
209
                        $staff_enabled = false;
210
                    } elseif($staff_setting == 2){
211
                        $staff_options = $settings[$template_id]->getVar('staff_options');
212
                        foreach($staff_options as $role){
213
                            if(array_key_exists($role, $myRoles)){
214
                                $staff_enabled = true;
215
                                break;
216
                            } else {
217
                                $staff_enabled = false;
218
                            }
219
                        }
220
                    }
221
222
                    $deptNotification[] = array('id'=> $template_id,
223
                                                'name'=>$template['name'],
224
                                                'category'=>$template['category'],
225
                                                'template'=>$template['mail_template'],
226
                                                'subject'=>$template['mail_subject'],
227
                                                'bitValue'=>(pow(2, $template['bit_value'])),
228
                                                'title'=>$template['title'],
229
                                                'caption'=>$template['caption'],
230
                                                'description'=>$template['description'],
231
                                                'isChecked'=>($staff->getVar('notify') & pow(2, $template['bit_value'])) > 0,
232
                                                'staff_setting'=> $staff_enabled);
233
                }
234
            }
235
            if($has_notifications){
236
                $xoopsTpl->assign('xhelp_deptNotifications', $deptNotification);
237
            } else {
238
                $xoopsTpl->assign('xhelp_deptNotifications', 0);
239
            }
240
241
            $hReview  =& xhelpGetHandler('staffReview');
242
            $hMembers =& xoops_gethandler('member');
243
            $crit = new Criteria('staffid', $xoopsUser->getVar('uid'));
244
            $crit->setSort('id');
245
            $crit->setOrder('DESC');
246
            $crit->setLimit(5);
247
248
            $reviews =& $hReview->getObjects($crit);
249
250
            $displayName =& $xoopsModuleConfig['xhelp_displayName'];    // Determines if username or real name is displayed
251
252 View Code Duplication
            foreach ($reviews as $review) {
253
                $reviewer = $hMembers->getUser($review->getVar('submittedBy'));
254
                $xoopsTpl->append('xhelp_reviews', array('rating' => $review->getVar('rating'),
255
                            'ratingdsc' => xhelpGetRating($review->getVar('rating')),
256
                            'submittedBy' => ($reviewer ? xhelpGetUsername($reviewer, $displayName) : $xoopsConfig['anonymous']),
257
                            'submittedByUID' => $review->getVar('submittedBy'),
258
                            'responseid' => $review->getVar('responseid'),
259
                            'comments' => $review->getVar('comments'),
260
                            'ticketid' => $review->getVar('ticketid')));
261
            }
262
            $xoopsTpl->assign('xhelp_hasReviews', (count($reviews) > 0));
263
264
            // Ticket Lists
265
            $ticketLists =& $hTicketList->getListsByUser($xoopsUser->getVar('uid'));
266
            $aMySavedSearches = array();
267
            $mySavedSearches = xhelpGetSavedSearches(array($xoopsUser->getVar('uid'), XHELP_GLOBAL_UID));
268
            $has_savedSearches = count($aMySavedSearches > 0);
269
            $ticketListCount = count($ticketLists);
270
            $aTicketLists = array();
271
            $aUsedSearches = array();
272
            $eleNum = 0;
273
            foreach($ticketLists as $ticketList){
274
                $weight = $ticketList->getVar('weight');
275
                $searchid = $ticketList->getVar('searchid');
276
                $aTicketLists[$ticketList->getVar('id')] = array('id' => $ticketList->getVar('id'),
277
                                                                 'uid' => $ticketList->getVar('uid'),
278
                                                                 'searchid' => $searchid,
279
                                                                 'weight' => $weight,
280
                                                                 'name' => $mySavedSearches[$ticketList->getVar('searchid')]['name'],
281
                                                                 'hasWeightUp' => (($eleNum != $ticketListCount - 1) ? true : false),
282
                                                                 'hasWeightDown' => (($eleNum != 0) ? true : false),
283
                                                                 'hasEdit' => (($mySavedSearches[$ticketList->getVar('searchid')]['uid'] != -999) ? true : false));
284
                $eleNum++;
285
                $aUsedSearches[$searchid] = $searchid;
286
            }
287
            unset($ticketLists);
288
289
            // Take used searches to get unused searches
290
            $aSearches = array();
291
            foreach($mySavedSearches as $savedSearch){
0 ignored issues
show
The expression $mySavedSearches of type array|false is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
292
                if(!in_array($savedSearch['id'], $aUsedSearches)){
293
                    if($savedSearch['id'] != ""){
294
                        $aSearches[$savedSearch['id']] = $savedSearch;
295
                    }
296
                }
297
            }
298
            $hasUnusedSearches = count($aSearches) > 0;
299
            $xoopsTpl->assign('xhelp_ticketLists', $aTicketLists);
300
            $xoopsTpl->assign('xhelp_hasTicketLists', count($aTicketLists) > 0);
301
            $xoopsTpl->assign('xhelp_unusedSearches', $aSearches);
302
            $xoopsTpl->assign('xhelp_hasUnusedSearches', $hasUnusedSearches);
303
            $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
304
            break;
305
    }
306
} else {
307
    redirect_header(XOOPS_URL .'/user.php', 3);
308
}
309
310
require(XOOPS_ROOT_PATH.'/footer.php');
311