forked from SimpleMachines/SimpleDesk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleDesk.php
More file actions
1422 lines (1307 loc) · 60.5 KB
/
SimpleDesk.php
File metadata and controls
1422 lines (1307 loc) · 60.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**************************************************************
* Simple Desk Project - www.simpledesk.net *
***************************************************************
* An advanced help desk modification built on SMF *
***************************************************************
* *
* * Copyright 2025 - SimpleDesk.net *
* *
* This file and its contents are subject to the license *
* included with this distribution, license.txt, which *
* states that this software is New BSD Licensed. *
* Any questions, please contact SimpleDesk.net *
* *
***************************************************************
* SimpleDesk Version: 2.1.0 *
* File Info: SimpleDesk.php *
**************************************************************/
/**
* This file serves as the entry point for SimpleDesk generally, as well as the home of the ticket listing
* code, for open, closed and deleted tickets.
*
* @package source
* @since 1.0
*/
if (!defined('SMF'))
die('Hacking attempt...');
/**
* Begins SimpleDesk general processing.
*
* Several things are done here, the results of which are unilaterally assumed by all other SimpleDesk functions.
* - work out which departments are applicable, and which department we are currently in (as far as possible)
* - set up general navigation
* - see if the URL or POST data contains a ticket, if so sanitise and store that value
* - see if a msg was specified in the URL, if so identify the relevant ticket
* - add in the helpdesk CSS file
* - identify the sub action to direct them to, then send them on their way.
*
* @since 1.0
*/
function shd_main()
{
global $context, $txt, $settings, $sourcedir, $modSettings, $scripturl, $user_profile, $user_info, $smcFunc;
// Basic sanity stuff
if (!$modSettings['helpdesk_active'])
shd_fatal_lang_error('shd_inactive', false);
// Let's be sneaky. Can they only access one department? If they can only access one department, put them there and make a note of it for later.
$depts = shd_allowed_to('access_helpdesk', false);
$context['shd_multi_dept'] = true;
if (is_bool($depts))
shd_fatal_error('Bug hunters unite...');
elseif (count($depts) == 1)
{
$_REQUEST['dept'] = $depts[0];
$context['shd_multi_dept'] = false;
}
elseif (empty($_REQUEST['dept']) && !empty($context['queried_dept']) && in_array($context['queried_dept'], $depts))
$_REQUEST['dept'] = $context['queried_dept'];
$context['shd_department'] = isset($_REQUEST['dept']) && in_array($_REQUEST['dept'], $depts) ? (int) $_REQUEST['dept'] : 0;
$context['shd_dept_link'] = !empty($context['shd_department']) && $context['shd_multi_dept'] ? ';dept=' . $context['shd_department'] : '';
shd_is_allowed_to('access_helpdesk', $context['shd_department']);
// If we know the department up front, we probably should get it now. Tickets themselves will deal with this but most other places won't.
// Note that we may already have loaded this if we went and got the department id earlier, but not always.
if (!empty($context['shd_department']) && $context['shd_multi_dept'] && empty($context['shd_dept_name']))
{
$query = $smcFunc['db_query']('', '
SELECT dept_name
FROM {db_prefix}helpdesk_depts
WHERE id_dept = {int:dept}',
array(
'dept' => $context['shd_department'],
)
);
list($context['shd_dept_name']) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
}
// Load stuff: preferences the core template - and any hook-required files
$context['shd_preferences'] = shd_load_user_prefs();
$context['shd_home'] = 'action=helpdesk;sa=main';
loadTemplate('sd_template/SimpleDesk');
shd_load_plugin_files('helpdesk');
shd_load_plugin_langfiles('helpdesk');
// List of sub actions.
$subactions = array(
'main' => array(null, 'shd_main_helpdesk'),
'dept' => array(null, 'shd_main_dept'),
'viewblock' => array(null, 'shd_view_block'),
'ticket' => array('SimpleDesk-Display.php', 'shd_view_ticket'),
'newticket' => array('SimpleDesk-Post.php', 'shd_post_ticket'),
'editticket' => array('SimpleDesk-Post.php', 'shd_post_ticket'),
'saveticket' => array('SimpleDesk-Post.php', 'shd_save_post'), // this is the equivalent of post2
'reply' => array('SimpleDesk-Post.php', 'shd_post_reply'),
'savereply' => array('SimpleDesk-Post.php', 'shd_save_post'),
'editreply' => array('SimpleDesk-Post.php', 'shd_post_reply'),
'markunread' => array('SimpleDesk-MiscActions.php', 'shd_ticket_unread'),
'assign' => array('SimpleDesk-Assign.php', 'shd_assign'),
'assign2' => array('SimpleDesk-Assign.php', 'shd_assign2'),
'movedept' => array('SimpleDesk-MoveDept.php', 'shd_movedept'),
'movedept2' => array('SimpleDesk-MoveDept.php', 'shd_movedept2'),
'resolveticket' => array('SimpleDesk-MiscActions.php', 'shd_ticket_resolve'),
'relation' => array('SimpleDesk-MiscActions.php', 'shd_ticket_relation'),
'ajax' => array('SimpleDesk-AjaxHandler.php', 'shd_ajax'),
'privacychange' => array('SimpleDesk-MiscActions.php', 'shd_privacy_change_noajax'),
'urgencychange' => array('SimpleDesk-MiscActions.php', 'shd_urgency_change_noajax'),
'closedtickets' => array(null, 'shd_closed_tickets'),
'recyclebin' => array(null, 'shd_recycle_bin'),
'tickettotopic' => array('SimpleDesk-TicketTopicMove.php', 'shd_tickettotopic'),
'tickettotopic2' => array('SimpleDesk-TicketTopicMove.php', 'shd_tickettotopic2'),
'topictoticket' => array('SimpleDesk-TicketTopicMove.php', 'shd_topictoticket'),
'topictoticket2' => array('SimpleDesk-TicketTopicMove.php', 'shd_topictoticket2'),
'permadelete' => array('SimpleDesk-Delete.php', 'shd_perma_delete'),
'deleteticket' => array('SimpleDesk-Delete.php', 'shd_ticket_delete'),
'deletereply' => array('SimpleDesk-Delete.php', 'shd_reply_delete'),
'deleteattach' => array('SimpleDesk-Delete.php', 'shd_attach_delete'),
'restoreticket' => array('SimpleDesk-Delete.php', 'shd_ticket_restore'),
'restorereply' => array('SimpleDesk-Delete.php', 'shd_reply_restore'),
'emaillog' => array('SimpleDesk-Notifications.php', 'shd_notify_popup'),
'notify' => array('SimpleDesk-Notifications.php', 'shd_notify_ticket_options'),
'search' => array('SimpleDesk-Search.php', 'shd_search'),
'search2' => array('SimpleDesk-Search.php', 'shd_search2'),
);
// Navigation menu
$context['navigation'] = array(
'main' => array(
'text' => 'shd_home',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=main',
),
'dept' => array(
'text' => 'shd_departments',
'test' => 'shd_multi_dept',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=dept',
),
'newticket' => array(
'text' => 'shd_new_ticket',
'test' => 'can_new_ticket',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=newticket' . $context['shd_dept_link'],
),
'newticketproxy' => array(
'text' => 'shd_new_ticket_proxy',
'test' => 'can_proxy_ticket',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=newticket;proxy' . $context['shd_dept_link'],
),
'closedtickets' => array(
'text' => 'shd_tickets_closed',
'test' => 'can_view_closed',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=closedtickets' . $context['shd_dept_link'],
),
'recyclebin' => array(
'text' => 'shd_recycle_bin',
'test' => 'can_view_recycle',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=recyclebin' . $context['shd_dept_link'],
),
'search' => array(
'text' => 'shd_search_menu',
'test' => 'can_shd_search',
'lang' => true,
'url' => $scripturl . '?action=helpdesk;sa=search',
),
// Only for certain sub areas.
'back' => array(
'text' => 'shd_back_to_hd',
'test' => 'display_back_to_hd',
'lang' => true,
'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'],
),
'options' => array(
'text'=> 'shd_options',
'test' => 'can_view_options',
'lang' => true,
'url' => $scripturl . '?action=profile;area=hd_prefs',
),
);
// Build the link tree.
$context['linktree'][] = array(
'url' => $scripturl . '?action=helpdesk;sa=main',
'name' => $txt['shd_helpdesk'],
);
if (!$context['shd_multi_dept'])
$context['linktree'][] = array(
'url' => $scripturl . '?' . $context['shd_home'],
'name' => $txt['shd_linktree_tickets'],
);
// See if a ticket has been specified, like $topic can be.
if (!empty($_REQUEST['ticket']))
{
if (strpos($_REQUEST['ticket'], '.') === false)
{
$context['ticket_id'] = (int) $_REQUEST['ticket'];
$context['ticket_start'] = 0;
}
else
{
list ($context['ticket_id'], $context['ticket_start']) = explode('.', $_REQUEST['ticket']);
$context['ticket_id'] = (int) $context['ticket_id'];
if (!is_numeric($context['ticket_start']))
{
// Let's see if it's 'new' first. If it is, great, we'll figure out the new point then throw it at the next one.
if (substr($context['ticket_start'], 0, 3) == 'new')
{
$query = shd_db_query('', '
SELECT COALESCE(hdlr.id_msg, -1) + 1 AS new_from
FROM {db_prefix}helpdesk_tickets AS hdt
LEFT JOIN {db_prefix}helpdesk_log_read AS hdlr ON (hdlr.id_ticket = {int:ticket} AND hdlr.id_member = {int:member})
WHERE {query_see_ticket}
AND hdt.id_ticket = {int:ticket}
LIMIT 1',
array(
'member' => $user_info['id'],
'ticket' => $context['ticket_id'],
)
);
list ($new_from) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
$context['ticket_start'] = 'msg' . $new_from;
$context['ticket_start_newfrom'] = $new_from;
}
if (substr($context['ticket_start'], 0, 3) == 'msg')
{
$virtual_msg = (int) substr($context['ticket_start'], 3);
$query = shd_db_query('', '
SELECT COUNT(hdtr.id_msg)
FROM {db_prefix}helpdesk_ticket_replies AS hdtr
INNER JOIN {db_prefix}helpdesk_tickets AS hdt ON (hdtr.id_ticket = hdt.id_ticket)
WHERE {query_see_ticket}
AND hdtr.id_ticket = {int:ticket}
AND hdtr.id_msg > hdt.id_first_msg
AND hdtr.id_msg < {int:virtual_msg}' . (!isset($_GET['recycle']) ? '
AND hdtr.message_status = {int:message_notdel}' : ''),
array(
'ticket' => $context['ticket_id'],
'virtual_msg' => $virtual_msg,
'message_notdel' => MSG_STATUS_NORMAL,
)
);
list ($context['ticket_start']) = $smcFunc['db_fetch_row']($query);
$smcFunc['db_free_result']($query);
}
}
else
{
$context['ticket_start'] = (int) $context['ticket_start']; // it IS numeric but let's make sure it's the right kind of number
$context['ticket_start_natural'] = true;
}
}
}
if (empty($context['ticket_start_newfrom']))
$context['ticket_start_newfrom'] = empty($context['ticket_start']) ? 0 : $context['ticket_start'];
// Do we have just a message id? We can get the ticket from that - but only if we don't already have a ticket id!
$_REQUEST['msg'] = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
if (!empty($_REQUEST['msg']) && empty($context['ticket_id']))
{
$query = shd_db_query('', '
SELECT hdt.id_ticket, hdtr.id_msg
FROM {db_prefix}helpdesk_ticket_replies AS hdtr
INNER JOIN {db_prefix}helpdesk_tickets AS hdt ON (hdtr.id_ticket = hdt.id_ticket)
WHERE {query_see_ticket}
AND hdtr.id_msg = {int:msg}',
array(
'msg' => $_REQUEST['msg'],
)
);
if ($row = $smcFunc['db_fetch_row']($query))
$context['ticket_id'] = (int) $row[0];
$smcFunc['db_free_result']($query);
}
$context['items_per_page'] = 10;
$context['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
loadCSSFile('helpdesk.css', array('minimize' => false, 'seed' => $context['shd_css_version']), 'helpdesk');
loadCSSFile('helpdesk_responsive.css', array('minimize' => false, 'seed' => $context['shd_css_version']), 'helpdesk_responsive');
loadJavascriptFile('helpdesk.js', array('defer' => false, 'minimize' => false), 'helpdesk');
// Custom settings?
if (file_exists($settings['default_theme_url'] . '/css/helpdesk_custom.css'))
loadCSSFile('helpdesk_def_custom.css', array('minimize' => false, 'seed' => $context['shd_css_version'], 'default_theme' => true), 'helpdesk_def_custom');
if (file_exists($settings['theme_dir'] . '/css/helpdesk_custom.css'))
loadCSSFile('helpdesk_custom.css', array('minimize' => false, 'seed' => $context['shd_css_version']), 'helpdesk_custom');
// Int hooks - after we basically set everything up (so it's manipulatable by the hook, but before we do the last bits of finalisation)
call_integration_hook('shd_hook_helpdesk', array(&$subactions));
// What are we doing?, We shouldn't use $_REQUEST anywhere, but clean it just incase.
$_REQUEST['sa'] = (!empty($_REQUEST['sa']) && isset($subactions[$_REQUEST['sa']])) ? $_REQUEST['sa'] : 'main';
$context['shd_current_subaction'] = $_REQUEST['sa'];
$context['sub_action'] = $subactions[$context['shd_current_subaction']];
$context['can_new_ticket'] = shd_allowed_to('shd_new_ticket', $context['shd_department']);
$context['can_proxy_ticket'] = $context['can_new_ticket'] && shd_allowed_to('shd_post_proxy', $context['shd_department']);
$context['can_view_closed'] = shd_allowed_to(array('shd_view_closed_own', 'shd_view_closed_any'), $context['shd_department']);
$context['can_view_recycle'] = shd_allowed_to('shd_access_recyclebin', $context['shd_department']);
$context['display_back_to_hd'] = !in_array($context['shd_current_subaction'], array('main', 'viewblock', 'recyclebin', 'closedtickets', 'dept'));
$context['can_shd_search'] = shd_allowed_to('shd_search', 0);
$context['can_view_options'] = shd_allowed_to(array('shd_view_preferences_own', 'shd_view_preferences_any'), 0);
// Highlight the correct button.
if (isset($context['navigation'][$context['shd_current_subaction']]))
$context['navigation'][$context['shd_current_subaction']]['active'] = true;
// Send them away.
if ($context['sub_action'][0] !== null)
require ($sourcedir . '/sd_source/' . $context['sub_action'][0]);
call_user_func($context['sub_action'][1]);
// Maintenance mode? If it were, the helpdesk is considered inactive for the purposes of everything to all but those without admin-helpdesk rights - but we must have them if we're here!
if (!empty($modSettings['shd_maintenance_mode']) && $context['shd_current_subaction'] != 'ajax')
$context['template_layers'][] = 'shd_maintenance';
call_integration_hook('shd_hook_after_main');
}
/**
* Display the main front page, showing tickets waiting for staff, waiting for user feedback and so on.
*
* This function sets up multiple blocks to be shown to users, defines what columns these blocks should have and states
* the rules to be used in getting the data.
*
* Each block has multiple parameters, and is stated in $context['ticket_blocks']:
* <ul>
* <li>block_icon: which image to use in Themes/default/images/simpledesk for denoting the type of block; filename plus extension</li>
* <li>title: the text string to use as the block's heading</li>
* <li>where: an SQL clause denoting the rule for obtaining the items in this block</li>
* <li>display: whether the block should be processed and prepared for display</li>
* <li>count: the number of items in this block, for pagination; generally should be a call to {@link shd_count_helpdesk_tickets()}</li>
* <li>columns: an array of columns to display in this block, in the order they should be displayed, using the following options, derived from {@link shd_get_block_columns()}:
* <ul>
* <li>ticket_id: the ticket's read status, privacy icon, and id</li>
* <li>ticket_name: name/link to the ticket</li>
* <li>starting_user: profile link to the user who opened the ticket</li>
* <li>replies: number of (visible) replies in the ticket</li>
* <li>allreplies: number of (all) replies in the ticket (includes deleted replies, which 'replies' does not)</li>
* <li>last_reply: the user who last replied</li>
* <li>status: the current ticket's status</li>
* <li>assigned: link to the profile of the user the ticket is assigned to, or 'Unassigned' if not assigned</li>
* <li>urgency: the current ticket's urgency</li>
* <li>updated: time of the last reply in the ticket; states Never if no replies</li>
* <li>actions: icons that may or may not relate to a given ticket; buttons for recycle, delete, unresolve live in this column</li>
* </ul>
* <li>required: whether the block is required to be displayed even if empty</li>
* <li>collapsed: whether the block should be compressed to a header with count of tickets or not (mostly for {@link shd_view_block()}'s benefit)</li>
* </ul>
*
* This function declares the following blocks:
* <ul>
* <li>Assigned to me (staff only)</li>
* <li>New tickets (staff only)</li>
* <li>Pending with staff (for staff, this is just tickets with that status, for regular users this is both pending staff and new unreplied to tickets)</li>
* <li>Pending with user (both)</li>
* </ul>
*
* @see shd_count_helpdesk_tickets()
* @since 1.0
*/
function shd_main_helpdesk()
{
global $context, $modSettings, $txt, $smcFunc, $user_profile, $scripturl, $user_info;
$is_staff = shd_allowed_to('shd_staff', 0);
// Stuff we need to add to $context, page title etc etc
$context += array(
'page_title' => $txt['shd_helpdesk'],
'sub_template' => 'main',
'ticket_blocks' => array( // the numbers tie back to the master status idents
'assigned' => array(
'block_icon' => 'assign.png',
'title' => $txt['shd_status_assigned_heading'],
'where' => 'hdt.id_member_assigned = ' . $user_info['id'] . ' AND hdt.status NOT IN (' . TICKET_STATUS_CLOSED . ',' . TICKET_STATUS_DELETED . ')',
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('assigned'),
'columns' => shd_get_block_columns('assigned'),
'required' => $is_staff,
'collapsed' => false,
),
'new' => array(
'block_icon' => 'status.png',
'title' => $txt['shd_status_' . TICKET_STATUS_NEW . '_heading'],
'where' => 'hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_NEW,
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('new'),
'columns' => shd_get_block_columns('new'),
'required' => false,
'collapsed' => false,
),
'staff' => array(
'block_icon' => 'staff.png',
'title' => $txt['shd_status_' . TICKET_STATUS_PENDING_STAFF . '_heading'],
'where' => $is_staff ? ('hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_PENDING_STAFF) : ('hdt.status IN (' . TICKET_STATUS_NEW . ',' . TICKET_STATUS_PENDING_STAFF . ')'), // put new and with staff together in 'waiting for staff' for end user
'display' => true,
'count' => shd_count_helpdesk_tickets('staff', $is_staff),
'columns' => shd_get_block_columns('staff'),
'required' => true,
'collapsed' => false,
),
'user' => array(
'block_icon' => 'user.png',
'title' => $txt['shd_status_' . TICKET_STATUS_PENDING_USER . '_heading'],
'where' => $is_staff ? ('hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_PENDING_USER) : ('hdt.status = ' . TICKET_STATUS_PENDING_USER),
'display' => true,
'count' => shd_count_helpdesk_tickets('with_user'),
'columns' => shd_get_block_columns($is_staff ? 'user_staff' : 'user_user'),
'required' => true,
'collapsed' => false,
),
'hold' => array(
'block_icon' => 'ticket_hold.png',
'title' => $txt['shd_status_' . TICKET_STATUS_HOLD . '_heading'],
'where' => 'hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_HOLD,
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('hold', $is_staff),
'columns' => shd_get_block_columns('hold'),
'required' => true,
'collapsed' => false,
),
),
'shd_home_view' => $is_staff ? 'staff' : 'user',
);
// Are we going to reorder these?
if (isset($modSettings['shd_block_order_1'], $modSettings['shd_block_order_2'], $modSettings['shd_block_order_3'], $modSettings['shd_block_order_4']))
{
$context['ticket_block_order'] = array();
$unused = array('assigned' => 0, 'new' => 0, 'staff' => 0, 'user' => 0, 'hold' => 0);
for ($i = 1; $i <= 5; $i++)
{
// Is anything even set for this block?
if (!isset($modSettings['shd_block_order_' . $i]))
continue;
// Did we already use this?
if (in_array($modSettings['shd_block_order_' . $i], $context['ticket_block_order']))
continue;
// Can they see this?
elseif (empty($context['ticket_blocks'][$modSettings['shd_block_order_' . $i]]['display']))
continue;
$context['ticket_block_order'][$i] = $modSettings['shd_block_order_' . $i];
unset($unused[$modSettings['shd_block_order_' . $i]]);
}
foreach ($unused as $u => $j)
$context['ticket_block_order'][] = $u;
}
else
$context['ticket_block_order'] = array(1 => 'assigned', 2 => 'new', 3 => 'staff', 4 => 'user', 5 => 'hold');
if (!empty($context['shd_dept_name']) && $context['shd_multi_dept'])
$context['linktree'][] = array(
'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'],
'name' => $context['shd_dept_name'],
);
shd_helpdesk_listing();
}
/**
* Sets up viewing the list of departments.
*
* $context['dept_list'] contains the list of departments that the user can see, key/value pair, array is ordered according to the ordering specified in the Departments administration area.
* The key for $context['dept_list'] is the department's id, with the array content being:
* - id_dept - departmental id (numeric)
* - dept_name - department's name
* - tickets - an array containing three elements, open, closed and assigned - containing the counts thereof for each department for the current user.
* - new - boolean whether this department has some new items to be read by the current user
*
* The linktree is also modified to inclue the department list.
*
* @see shd_get_ticket_counts()
* @see shd_get_unread_departments()
* @since 2.0
*/
function shd_main_dept()
{
global $context, $txt, $smcFunc, $scripturl, $user_info, $sourcedir;
$dept_list = shd_allowed_to('access_helpdesk', false);
$context += array(
'page_title' => $txt['shd_helpdesk'] . ' - ' . $txt['shd_departments'],
'sub_template' => 'shd_depts',
'shd_home_view' => shd_allowed_to('shd_staff', 0) ? 'staff' : 'user',
);
// Get the departments and order them in the same order they would be on the board index.
$context['dept_list'] = array();
$query = $smcFunc['db_query']('', '
SELECT hdd.id_dept, hdd.dept_name, hdd.description
FROM {db_prefix}helpdesk_depts AS hdd
WHERE hdd.id_dept IN ({array_int:depts})
ORDER BY hdd.dept_order',
array(
'depts' => $dept_list,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
$context['dept_list'][$row['id_dept']] = array(
'id_dept' => $row['id_dept'],
'dept_name' => $row['dept_name'],
'description' => !empty($row['description']) ? parse_bbc($row['description']) : '',
'tickets' => array(
'open' => 0,
'closed' => 0,
'assigned' => 0,
),
'new' => false,
);
$smcFunc['db_free_result']($query);
require_once($sourcedir . '/sd_source/Subs-SimpleDeskBoardIndex.php');
shd_get_ticket_counts();
shd_get_unread_departments();
$context['linktree'][] = array(
'url' => $scripturl . '?action=helpdesk;sa=dept',
'name' => $txt['shd_departments'],
);
}
/**
* Sets up viewing of a single block without any pagination.
*
* This provides the ability to see all of a given type of ticket at once without paging through them, which are all sortable.
*
* @see shd_main_helpdesk()
* @since 1.0
*/
function shd_view_block()
{
global $context, $txt, $smcFunc, $user_profile, $scripturl, $user_info;
$is_staff = shd_allowed_to('shd_staff', 0);
// Stuff we need to add to $context, page title etc etc
$context += array(
'page_title' => $txt['shd_helpdesk'],
'sub_template' => 'main',
'ticket_blocks' => array( // the numbers tie back to the master status idents
'assigned' => array(
'block_icon' => 'assign.png',
'title' => $txt['shd_status_assigned_heading'],
'where' => 'hdt.id_member_assigned = ' . $user_info['id'] . ' AND hdt.status NOT IN (' . TICKET_STATUS_CLOSED . ',' . TICKET_STATUS_DELETED . ')',
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('assigned'),
'columns' => shd_get_block_columns('assigned'),
'required' => $is_staff,
'collapsed' => false,
),
'new' => array(
'block_icon' => 'status.png',
'title' => $txt['shd_status_' . TICKET_STATUS_NEW . '_heading'],
'where' => 'hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_NEW,
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('new'),
'columns' => shd_get_block_columns('new'),
'required' => false,
'collapsed' => false,
),
'staff' => array(
'block_icon' => 'staff.png',
'title' => $txt['shd_status_' . TICKET_STATUS_PENDING_STAFF . '_heading'],
'where' => $is_staff ? ('hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_PENDING_STAFF) : ('hdt.status IN (' . TICKET_STATUS_NEW . ',' . TICKET_STATUS_PENDING_STAFF . ')'), // put new and with staff together in 'waiting for staff' for end user
'display' => true,
'count' => shd_count_helpdesk_tickets('staff', $is_staff),
'columns' => shd_get_block_columns('staff'),
'required' => true,
'collapsed' => false,
),
'user' => array(
'block_icon' => 'user.png',
'title' => $txt['shd_status_' . TICKET_STATUS_PENDING_USER . '_heading'],
'where' => $is_staff ? ('hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_PENDING_USER) : ('hdt.status = ' . TICKET_STATUS_PENDING_USER),
'display' => true,
'count' => shd_count_helpdesk_tickets('with_user'),
'columns' => shd_get_block_columns($is_staff ? 'user_staff' : 'user_user'),
'required' => true,
'collapsed' => false,
),
'hold' => array(
'block_icon' => 'ticket_hold.png',
'title' => $txt['shd_status_' . TICKET_STATUS_HOLD . '_heading'],
'where' => 'hdt.id_member_assigned != ' . $user_info['id'] . ' AND hdt.status = ' . TICKET_STATUS_HOLD,
'display' => $is_staff,
'count' => shd_count_helpdesk_tickets('hold', $is_staff),
'columns' => shd_get_block_columns('hold'),
'required' => true,
'collapsed' => false,
),
),
'shd_home_view' => $is_staff ? 'staff' : 'user',
);
if (empty($_REQUEST['block']) || empty($context['ticket_blocks'][$_REQUEST['block']]) || empty($context['ticket_blocks'][$_REQUEST['block']]['count']))
redirectexit($context['shd_home'] . $context['shd_dept_link']);
// At this point we have validated the block and kicked out the bad ones.
$context['shd_current_block'] = $_REQUEST['block'];
$context['items_per_page'] = 10;
foreach ($context['ticket_blocks'] as $block => $details)
{
if ($block == $_REQUEST['block'])
{
$context['items_per_page'] = $details['count'];
$context['ticket_blocks'][$block]['viewing_as_block'] = true;
}
else
$context['ticket_blocks'][$block]['collapsed'] = true;
}
if (!empty($context['shd_dept_name']) && $context['shd_multi_dept'])
$context['linktree'][] = array(
'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'],
'name' => $context['shd_dept_name'],
);
shd_helpdesk_listing();
}
/**
* Set up the paginated lists of closed tickets.
*
* Much like the main helpdesk, this function prepares a list of all the closed/resolved tickets, with a more specific
* list of columns that is better suited to resolved tickets.
*
* @see shd_main_helpdesk()
* @since 1.0
*/
function shd_closed_tickets()
{
global $context, $txt, $smcFunc, $user_profile, $scripturl, $settings, $user_info;
if (!shd_allowed_to('shd_view_closed_own', $context['shd_department']) && !shd_allowed_to('shd_view_closed_any', $context['shd_department']))
shd_fatal_lang_error('shd_cannot_view_resolved', false);
// Stuff we need to add to $context, the permission we want to use, page title etc etc
$context += array(
'page_title' => $txt['shd_helpdesk'],
'sub_template' => 'closedtickets',
'ticket_blocks' => array(
'closed' => array(
'block_icon' => 'resolved.png',
'title' => $txt['shd_status_' . TICKET_STATUS_CLOSED . '_heading'],
'where' => 'hdt.status = ' . TICKET_STATUS_CLOSED,
'display' => true,
'count' => shd_count_helpdesk_tickets('closed'),
'columns' => shd_get_block_columns('closed'),
'required' => true,
'collapsed' => false,
),
),
'shd_home_view' => shd_allowed_to('shd_staff', $context['shd_department']) ? 'staff' : 'user', // This might be removed in the future. We do this here to be able to re-use template_ticket_block() in the template.
);
// Build the link tree.
if (!empty($context['shd_dept_name']) && $context['shd_multi_dept'])
$context['linktree'][] = array(
'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'],
'name' => $context['shd_dept_name'],
);
$context['linktree'][] = array(
'url' => $scripturl . '?action=helpdesk;sa=closedtickets' . $context['shd_dept_link'],
'name' => $txt['shd_tickets_closed'],
);
shd_helpdesk_listing();
}
/**
* Set up the paginated lists of deleted/recyclebin tickets.
*
* Much like the main helpdesk, this function prepares a list of all the deleted tickets, with a more specific
* list of columns that is better suited to recyclable or permadeletable tickets.
*
* @see shd_main_helpdesk()
* @since 1.0
*/
function shd_recycle_bin()
{
global $context, $txt, $smcFunc, $user_profile, $scripturl, $settings, $user_info;
// Stuff we need to add to $context, the permission we want to use, page title etc etc
$context += array(
'shd_permission' => 'shd_access_recyclebin',
'page_title' => $txt['shd_helpdesk'],
'sub_template' => 'recyclebin',
'ticket_blocks' => array(
'recycle' => array(
'block_icon' => 'recycle.png',
'title' => $txt['shd_status_' . TICKET_STATUS_DELETED . '_heading'],
'tickets' => array(),
'where' => 'hdt.status = ' . TICKET_STATUS_DELETED,
'display' => true,
'count' => shd_count_helpdesk_tickets('recycled'),
'columns' => shd_get_block_columns('recycled'),
'required' => true,
'collapsed' => false,
),
'withdeleted' => array(
'block_icon' => 'recycle.png',
'title' => $txt['shd_status_withdeleted_heading'],
'tickets' => array(),
'where' => 'hdt.status != ' . TICKET_STATUS_DELETED . ' AND hdt.deleted_replies > 0',
'display' => true,
'count' => shd_count_helpdesk_tickets('withdeleted'),
'columns' => shd_get_block_columns('withdeleted'),
'required' => true,
'collapsed' => false,
),
),
);
// Build the link tree.
if (!empty($context['shd_dept_name']) && $context['shd_multi_dept'])
$context['linktree'][] = array(
'url' => $scripturl . '?' . $context['shd_home'] . $context['shd_dept_link'],
'name' => $context['shd_dept_name'],
);
$context['linktree'][] = array(
'url' => $scripturl . '?action=helpdesk;sa=recyclebin' . $context['shd_dept_link'],
'name' => $txt['shd_recycle_bin'],
);
shd_helpdesk_listing();
}
/**
* Gather the data and prepare to display the ticket blocks.
*
* Actually performs the queries to get data for each block, subject to the parameters specified by the calling functions.
*
* It also sets up per-block pagination links, collects a variety of data (enough to populate all the columns as listed in shd_main_helpdesk,
* even if not entirely applicable, and populates it all into $context['ticket_blocks']['tickets'], extending the array that was
* already there.
*
* @see shd_main_helpdesk()
* @see shd_closed_tickets()
* @see shd_recycle_bin()
* @since 1.0
*/
function shd_helpdesk_listing()
{
global $context, $txt, $smcFunc, $user_profile, $scripturl, $settings, $user_info, $modSettings, $language;
if (!empty($context['shd_permission']))
shd_is_allowed_to($context['shd_permission']);
$block_list = array_keys($context['ticket_blocks']);
$primary_url = '?action=helpdesk;sa=' . $context['shd_current_subaction'];
// First figure out the start positions of each item and sanitise them
foreach ($context['ticket_blocks'] as $block_key => $block)
{
if (empty($block['viewing_as_block']))
{
$num_per_page = !empty($context['shd_preferences']['blocks_' . $block_key . '_count']) ? $context['shd_preferences']['blocks_' . $block_key . '_count'] : $context['items_per_page'];
$start = empty($_REQUEST['st_' . $block_key]) ? 0 : (int) $_REQUEST['st_' . $block_key];
$max_value = $block['count']; // easier to read
}
else
{
$num_per_page = $context['items_per_page'];
$max_value = $context['items_per_page'];
$start = 0;
}
if ($start < 0)
$start = 0;
elseif ($start >= $max_value)
$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
else
$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
$context['ticket_blocks'][$block_key]['start'] = $start;
$context['ticket_blocks'][$block_key]['num_per_page'] = $num_per_page;
if ($start != 0)
$_REQUEST['st_' . $block_key] = $start; // sanitise!
elseif (isset($_REQUEST['st_' . $block_key]))
unset($_REQUEST['st_' . $block_key]);
}
// Now ordering the columns, separate loop for breaking the two processes apart
$sort_methods = array(
'ticketid' => array(
'sql' => 'hdt.id_ticket',
),
'ticketname' => array(
'sql' => 'hdt.subject',
),
'replies' => array(
'sql' => 'hdt.num_replies',
),
'allreplies' => array(
'sql' => '(hdt.num_replies + hdt.deleted_replies)',
),
'urgency' => array(
'sql' => 'hdt.urgency',
),
'updated' => array(
'sql' => 'hdt.last_updated',
),
'assigned' => array(
'sql' => 'assigned_name',
'sql_select' => 'COALESCE(mem.real_name, 0) AS assigned_name',
'sql_join' => 'LEFT JOIN {db_prefix}members AS mem ON (hdt.id_member_assigned = mem.id_member)',
),
'status' => array(
'sql' => 'hdt.status',
),
'starter' => array(
'sql' => 'starter_name',
'sql_select' => 'COALESCE(mem.real_name, 0) AS starter_name',
'sql_join' => 'LEFT JOIN {db_prefix}members AS mem ON (hdt.id_member_started = mem.id_member)',
),
'lastreply' => array(
'sql' => 'last_reply',
'sql_select' => 'COALESCE(mem.real_name, 0) AS last_reply',
'sql_join' => 'LEFT JOIN {db_prefix}members AS mem ON (hdtr_last.id_member = mem.id_member)',
),
);
foreach ($context['ticket_blocks'] as $block_key => $block)
{
$sort = isset($_REQUEST['so_' . $block_key]) ? $_REQUEST['so_' . $block_key] : (!empty($context['shd_preferences']['block_order_' . $block_key . '_block']) ? $context['shd_preferences']['block_order_' . $block_key . '_block'] : '');
if (strpos($sort, '_') > 0 && substr_count($sort, '_') == 1)
{
list($sort_item, $sort_dir) = explode('_', $sort);
if (empty($sort_methods[$sort_item]))
{
$sort_item = 'updated';
$sort = '';
}
if (!in_array($sort_dir, array('asc', 'desc')))
{
$sort = '';
$sort_dir = 'asc';
}
}
else
{
$sort = '';
$sort_item = 'updated';
$sort_dir = $context['shd_current_subaction'] == 'closedtickets' || $context['shd_current_subaction'] == 'recyclebin' ? 'desc' : 'asc'; // default to newest first if on recyclebin or closed tickets, otherwise oldest first
}
if ($sort != '')
$_REQUEST['so_' . $block_key] = $sort; // sanitise!
elseif (isset($_REQUEST['so_' . $block_key]))
unset($_REQUEST['so_' . $block_key]);
$context['ticket_blocks'][$block_key]['sort'] = array(
'item' => $sort_item,
'direction' => $sort_dir,
'add_link' => ($sort != ''),
'sql' => array(
'select' => !empty($sort_methods[$sort_item]['sql_select']) ? $sort_methods[$sort_item]['sql_select'] : '',
'join' => !empty($sort_methods[$sort_item]['sql_join']) ? $sort_methods[$sort_item]['sql_join'] : '',
'sort' => $sort_methods[$sort_item]['sql'] . ' ' . strtoupper($sort_dir),
),
'link_bits' => array(),
);
}
// Having got all that, step through the blocks again to determine the full URL fragments
foreach ($context['ticket_blocks'] as $block_key => $block)
foreach ($sort_methods as $method => $sort_details)
$context['ticket_blocks'][$block_key]['sort']['link_bits'][$method] = ';so_' . $block_key . '=' . $method . '_' . $block['sort']['direction'];
// Figure out if the user is filtering on anything, and if so, set up containers for the extra joins, selects, pagination link fragments, etc
$_REQUEST['field'] = isset($_REQUEST['field']) ? (int) $_REQUEST['field'] : 0;
$_REQUEST['filter'] = isset($_REQUEST['filter']) ? (int) $_REQUEST['filter'] : 0;
if ($_REQUEST['field'] > 0 && $_REQUEST['filter'] > 0)
{
$context['filter_fragment'] = ';field=' . $_REQUEST['field'] . ';filter=' . $_REQUEST['filter'];
$context['filter_join'] = '
INNER JOIN {db_prefix}helpdesk_custom_fields_values AS hdcfv ON (hdcfv.id_post = hdt.id_ticket AND hdcfv.id_field = {int:field} AND hdcfv.post_type = {int:type_ticket})
INNER JOIN {db_prefix}helpdesk_custom_fields AS hdcf ON (hdcf.id_field = hdcfv.id_field AND hdcf.active = {int:active})';
$context['filter_where'] = '
AND hdcfv.value = {string:filter}';
}
else
{
$context['filter_fragment'] = '';
$context['filter_join'] = '';
$context['filter_where'] = '';
}
// Now go actually do the whole block thang, setting up space for a list of users and tickets as we go along
$users = array();
$tickets = array();
foreach ($context['ticket_blocks'] as $block_key => $block)
{
if (empty($block['display']) || !empty($block['collapsed']))
continue;
$context['ticket_blocks'][$block_key]['tickets'] = array();
// If we're filtering, we have to query it first to figure out how many rows there are in this block. It's not pretty.
if (!empty($context['filter_join']))
{
$query = shd_db_query('', '
SELECT COUNT(hdt.id_ticket)
FROM {db_prefix}helpdesk_tickets AS hdt
INNER JOIN {db_prefix}helpdesk_ticket_replies AS hdtr_first ON (hdt.id_first_msg = hdtr_first.id_msg)
INNER JOIN {db_prefix}helpdesk_ticket_replies AS hdtr_last ON (hdt.id_last_msg = hdtr_last.id_msg)
INNER JOIN {db_prefix}helpdesk_depts AS hdd ON (hdt.id_dept = hdd.id_dept)
' . (!empty($block['sort']['sql']['join']) ? $block['sort']['sql']['join'] : '') . $context['filter_join'] . '
WHERE {query_see_ticket}' . (!empty($block['where']) ? ' AND ' . $block['where'] : '') . (!empty($context['shd_department']) ? ' AND hdt.id_dept = {int:dept}' : '') . $context['filter_where'],
array(
'dept' => $context['shd_department'],
'user' => $context['user']['id'],
'field' => $_REQUEST['field'],
'filter' => $_REQUEST['filter'],
'type_ticket' => CFIELD_TICKET,
'active' => 1,
)
);
list($context['ticket_blocks'][$block_key]['count']) = $smcFunc['db_fetch_row']($query);
$block['count'] = $context['ticket_blocks'][$block_key]['count'];
$smcFunc['db_free_result']($query);
if ($block['start'] >= $block['count'])
{
$context['ticket_blocks'][$block_key]['start'] = max(0, (int) $block['count'] - (((int) $block['count'] % (int) $block['num_per_page']) == 0 ? $block['num_per_page'] : ((int) $block['count'] % (int) $block['num_per_page'])));
$block['start'] = $context['ticket_blocks'][$block_key]['start'];
}
}
$query = shd_db_query('', '
SELECT hdt.id_ticket, hdt.id_dept, hdd.dept_name, hdt.id_last_msg, hdt.id_member_started, hdt.id_member_updated,
hdt.id_member_assigned, hdt.subject, hdt.status, hdt.num_replies, hdt.deleted_replies, hdt.private, hdt.urgency,
hdt.last_updated, hdtr_first.poster_name AS ticket_opener, hdtr_last.poster_name AS respondent, hdtr_last.poster_time,
COALESCE(hdlr.id_msg, 0) AS log_read' . (!empty($block['sort']['sql']['select']) ? ', ' . $block['sort']['sql']['select'] : '') . '
FROM {db_prefix}helpdesk_tickets AS hdt
INNER JOIN {db_prefix}helpdesk_ticket_replies AS hdtr_first ON (hdt.id_first_msg = hdtr_first.id_msg)
INNER JOIN {db_prefix}helpdesk_ticket_replies AS hdtr_last ON (hdt.id_last_msg = hdtr_last.id_msg)
INNER JOIN {db_prefix}helpdesk_depts AS hdd ON (hdt.id_dept = hdd.id_dept)
LEFT JOIN {db_prefix}helpdesk_log_read AS hdlr ON (hdt.id_ticket = hdlr.id_ticket AND hdlr.id_member = {int:user})
' . (!empty($block['sort']['sql']['join']) ? $block['sort']['sql']['join'] : '') . $context['filter_join'] . '
WHERE {query_see_ticket}' . (!empty($block['where']) ? ' AND ' . $block['where'] : '') . (!empty($context['shd_department']) ? ' AND hdt.id_dept = {int:dept}' : '') . $context['filter_where'] . '
ORDER BY ' . (!empty($block['sort']['sql']['sort']) ? $block['sort']['sql']['sort'] : 'hdt.id_last_msg ASC') . '
LIMIT {int:start}, {int:items_per_page}',
array(
'dept' => $context['shd_department'],
'user' => $context['user']['id'],
'start' => $block['start'],
'items_per_page' => $block['num_per_page'],
'field' => $_REQUEST['field'],
'filter' => $_REQUEST['filter'],
'type_ticket' => CFIELD_TICKET,
'active' => 1,
)
);
while ($row = $smcFunc['db_fetch_assoc']($query))
{
$is_own = $user_info['id'] == $row['id_member_started'];
censorText($row['subject']);
$new_block = array(
'id' => $row['id_ticket'],
'display_id' => str_pad($row['id_ticket'], $modSettings['shd_zerofill'], '0', STR_PAD_LEFT),
'dept_link' => empty($context['shd_department']) && $context['shd_multi_dept'] ? '[<a href="' . $scripturl . '?' . $context['shd_home'] . ';dept=' . $row['id_dept'] . '">' . $row['dept_name'] . '</a>] ' : '',
'link' => '<a href="' . $scripturl . '?action=helpdesk;sa=ticket;ticket=' . $row['id_ticket'] . ($context['shd_current_subaction'] == 'recyclebin' ? ';recycle' : '') . '">' . $row['subject'] . '</a>',
'subject' => $row['subject'],
'status' => array(
'level' => $row['status'],
'label' => $txt['shd_status_' . $row['status']],
),
'starter' => array(
'id' => $row['id_member_started'],
'name' => $row['ticket_opener'],
),