forked from SimpleMachines/SimpleDesk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSubs-SimpleDeskAdmin.php
More file actions
1093 lines (1001 loc) · 42 KB
/
Subs-SimpleDeskAdmin.php
File metadata and controls
1093 lines (1001 loc) · 42 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: Subs-SimpleDeskAdmin.php *
**************************************************************/
/**
* This file deals with some of the items required by the helpdesk, but are primarily supporting
* functions; they're not the principle functions that drive the admin area.
*
* @package subs
* @since 1.0
*/
if (!defined('SMF'))
die('Hacking attempt...');
/**
* Load the items from the helpdesk action log
*
* It is subject to given parameters (start, number of items, order/sorting), parses the language strings and adds the
* parameter information provided.
*
* @param int $start Number of items into the log to start (for pagination). If -1, return everything. If nothing is given, fall back to 0, i.e the first log item.
* @param int $items_per_page How many items to load. Default to 10 items.
* @param string $sort SQL clause to state which column(s) to order the data by. By default it orders by log_time.
* @param string $order SQL clause to state whether the order is ascending or descending. Defaults to descending.
* @param string $clause An SQL fragment that forms a WHERE clause to limit log items, e.g. to load a specific ticket or specific member's log items.
*
* @return array A hash array of the log items, with the auto-incremented id being the key:
* <ul>
* <li>id: Numeric identifier of the log item</li>
* <li>time: Formatted time of the event (as per usual for SMF, formatted for user's timezone)</li>
* <li>member: hash array:
* <ul>
* <li>id: Id of the user that committed the action</li>
* <li>name: Name of the user</li>
* <li>link: Link to the profile of the user that committed the action</li>
* <li>ip: User IP address recorded when the action was carried out</li>
* <li>group: Name of the group of the user (uses primary group, failing that post count group)</li>
* </ul>
* </li>
* <li>action: Raw name of the action (for use with collecting the image later)</li>
* <li>id_ticket: Numeric id of the ticket this action refers to</li>
* <li>id_msg: Numeric id of the individual reply this action refers to</li>
* <li>extra: Array of extra parameters for the log action</li>
* <li>action_text: Formatted text of the log item (parsed with parameters)</li>
* </ul>
*
* @see shd_log_action()
* @see shd_count_action_log_entries()
* @since 1.0
*/
function shd_load_action_log_entries($start = 0, $items_per_page = 10, $sort = 'la.log_time', $order = 'DESC', $clause = '')
{
global $smcFunc, $txt, $scripturl, $context, $user_info, $user_profile;
// Load languages incase they aren't there (Read: ticket-specific logs)
shd_load_language('sd_language/SimpleDeskAdmin');
shd_load_language('sd_language/SimpleDeskLogAction');
shd_load_language('sd_language/SimpleDeskNotifications');
// We may have to exclude some items from this depending on who the user is or is not. Forum/HD admins can always see everything.
$exclude = shd_action_log_exclusions();
if (!empty($exclude))
{
if (empty($clause))
$clause = 'la.action NOT IN ({array_string:exclude})';
else
$clause .= ' AND la.action NOT IN ({array_string:exclude})';
}
// Without further screaming and waving, fetch the actions.
$request = shd_db_query('', '
SELECT la.id_action, la.log_time, la.ip, la.action, la.id_ticket, la.id_msg, la.extra,
COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, {string:blank}) AS real_name, COALESCE(mg.group_name, {string:na}) AS group_name
FROM {db_prefix}helpdesk_log_action AS la
LEFT JOIN {db_prefix}members AS mem ON(mem.id_member = la.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
WHERE la.id_ticket != {int:no_ticket}' . (empty($clause) ? '' : '
AND ' . $clause) . '
ORDER BY ' . ($sort != '' ? '{raw:sort} {raw:order}' : 'la.log_time DESC') . '
' . ($start != -1 ? 'LIMIT {int:start}, {int:items_per_page}' : ''),
array(
'no_ticket' => 0,
'reg_group_id' => 0,
'sort' => $sort,
'start' => $start,
'items_per_page' => $items_per_page,
'order' => $order,
'na' => $txt['not_applicable'],
'blank' => '',
'exclude' => $exclude,
)
);
$actions = array();
$notify_members = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['extra'] = smf_json_decode($row['extra'], true);
$row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
// Uhoh, we don't know who this is! Check it's not automatically by the system. If it is... mark it so.
if (empty($row['id_member']))
{
if (isset($row['extra']['auto']) && $row['extra']['auto'] === true)
$row['real_name'] = $txt['shd_helpdesk'];
else
$row['real_name'] = $txt['shd_admin_actionlog_unknown'];
}
$actions[$row['id_action']] = array(
'id' => $row['id_action'],
'time' => timeformat($row['log_time']),
'member' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'link' => shd_profile_link($row['real_name'], $row['id_member']),
'group' => $row['group_name'],
),
'action' => $row['action'],
'id_ticket' => $row['id_ticket'],
'id_msg' => $row['id_msg'],
'extra' => $row['extra'],
'action_text' => '',
'action_icon' => 'log_' . $row['action'] . '.png',
'can_remove' => empty($context['waittime']) ? false : ($row['log_time'] < $context['waittime']),
);
// We want to use a generic icon for custom fields changes.
if (strpos($row['action'], 'cf_') === 0)
$actions[$row['id_action']]['action_icon'] = 'log_cfchange.png';
if (shd_allowed_to('shd_view_ip_any', 0) || ($row['id_member'] == $user_info['id'] && shd_allowed_to('shd_view_ip_own', 0)))
$actions[$row['id_action']]['member']['ip'] = !empty($row['ip']) ? $row['ip'] : $txt['shd_admin_actionlog_unknown'];
// Notifications require us to collate all the user ids as we go along.
if ($row['action'] == 'notify' && !empty($row['extra']['emails']))
foreach ($row['extra']['emails'] as $email_type => $recipients)
if (!empty($recipients['u']))
$notify_members = array_merge($notify_members, explode(',', $recipients['u']));
}
$smcFunc['db_free_result']($request);
if (!empty($notify_members))
loadMemberData(array_unique($notify_members));
// Do some formatting of the action string.
foreach ($actions as $k => $action)
{
if (empty($actions[$k]['action_text']))
$actions[$k]['action_text'] = isset($txt['shd_log_' . $action['action']]) ? $txt['shd_log_' . $action['action']] : $action['action'];
$actions[$k]['action_text'] = str_replace('{scripturl}', $scripturl, $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{shd_home}', $context['shd_home'], $actions[$k]['action_text']);
if (isset($action['extra']['subject']))
{
$actions[$k]['action_text'] = str_replace('{ticket}', $actions[$k]['id_ticket'], $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{msg}', $actions[$k]['id_msg'], $actions[$k]['action_text']);
if (isset($actions[$k]['extra']['subject']))
$actions[$k]['action_text'] = str_replace('{subject}', $actions[$k]['extra']['subject'], $actions[$k]['action_text']);
if (isset($actions[$k]['extra']['urgency']))
$actions[$k]['action_text'] = str_replace('{urgency}', $txt['shd_urgency_' . $actions[$k]['extra']['urgency']], $actions[$k]['action_text']);
}
// Notifications are pretty tricky. So let's take care of all of it at once, and skip the rest if we're doing that.
if ($action['action'] == 'notify' && isset($action['extra']['emails']))
{
// Because this could be a lot of people etc., we compact its storage heavily compared to a conventional smf_json_decode().
// See shd_notify_users in SimpleDesk-Notifications.php for what this is.
// Now we have all the usernames for this instance, let's go and build this entry.
$content = '';
foreach ($action['extra']['emails'] as $email_type => $recipients)
{
$this_content = '<br><a href="' . $scripturl . '?action=helpdesk;sa=emaillog;log=' . $action['id'] . ';template=' . $email_type . '" onclick="return reqWin(this.href);">' . $txt['template_log_notify_' . $email_type] . '</a> - ';
$new_content = '';
if (!empty($recipients['u']))
{
$first = true;
$users = array_map('intval', explode(',', $recipients['u']));
$unknown_users = 0;
foreach ($users as $user)
{
if (empty($user_profile[$user]))
{
$unknown_users++;
continue;
}
$new_content .= ($first ? $txt['shd_log_notify_users'] . ': ' : ', ') . shd_profile_link($user_profile[$user]['real_name'], $user);
$first = false;
}
if ($unknown_users > 0)
$new_content .= ($first ? $txt['shd_log_notify_users'] . ': ' : ', ') . ($unknown_users == 1 ? $txt['shd_log_unknown_user_1'] : sprintf($txt['shd_log_unknown_user_n'], $unknown_users));
}
if (!empty($new_content))
$content .= $this_content . $new_content;
}
if (!empty($content))
$actions[$k]['action_text'] .= $txt['shd_log_notify_to'] . $content;
continue;
}
if (isset($action['extra']['user_name']))
{
$actions[$k]['action_text'] = str_replace('{profile_link}', shd_profile_link($actions[$k]['extra']['user_name'], (isset($actions[$k]['extra']['user_id']) ? $actions[$k]['extra']['user_id'] : 0)), $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{user_name}', $actions[$k]['extra']['user_name'], $actions[$k]['action_text']);
}
if (isset($action['extra']['user_id']))
$actions[$k]['action_text'] = str_replace('{user_id}', $actions[$k]['extra']['user_id'], $actions[$k]['action_text']);
if (isset($actions[$k]['extra']['board_name']))
$actions[$k]['action_text'] = str_replace('{board_name}', $actions[$k]['extra']['board_name'], $actions[$k]['action_text']);
if (isset($actions[$k]['extra']['board_id']))
$actions[$k]['action_text'] = str_replace('{board_id}', $actions[$k]['extra']['board_id'], $actions[$k]['action_text']);
if (isset($action['extra']['othersubject']))
{
$actions[$k]['action_text'] = str_replace('{othersubject}', $actions[$k]['extra']['othersubject'], $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{otherticket}', $actions[$k]['extra']['otherticket'], $actions[$k]['action_text']);
}
if (isset($action['extra']['old_dept_id']))
{
$replace = array(
'{old_dept_id}' => $action['extra']['old_dept_id'],
'{old_dept_name}' => $action['extra']['old_dept_name'],
'{new_dept_id}' => $action['extra']['new_dept_id'],
'{new_dept_name}' => $action['extra']['new_dept_name'],
);
$actions[$k]['action_text'] = str_replace(array_keys($replace), array_values($replace), $actions[$k]['action_text']);
}
// Custom fields?
if (isset($action['extra']['fieldname']))
{
if ($action['extra']['fieldtype'] == CFIELD_TYPE_CHECKBOX)
{
$action['extra']['oldvalue'] = !empty($action['extra']['oldvalue']) ? $txt['yes'] : $txt['no'];
$action['extra']['newvalue'] = !empty($action['extra']['newvalue']) ? $txt['yes'] : $txt['no'];
}
elseif ($action['extra']['fieldtype'] == CFIELD_TYPE_RADIO || $action['extra']['fieldtype'] == CFIELD_TYPE_SELECT || $action['extra']['fieldtype'] == CFIELD_TYPE_MULTI)
{
if (empty($action['extra']['oldvalue']))
$action['extra']['oldvalue'] = $txt['shd_none_selected'];
if (empty($action['extra']['newvalue']))
$action['extra']['newvalue'] = $txt['shd_none_selected'];
}
else
{
if (empty($action['extra']['oldvalue']))
$action['extra']['oldvalue'] = $txt['shd_empty_item'];
if (empty($action['extra']['newvalue']))
$action['extra']['newvalue'] = $txt['shd_empty_item'];
}
$actions[$k]['action_text'] = str_replace('{fieldname}', $action['extra']['fieldname'], $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{oldvalue}', $action['extra']['oldvalue'], $actions[$k]['action_text']);
$actions[$k]['action_text'] = str_replace('{newvalue}', $action['extra']['newvalue'], $actions[$k]['action_text']);
}
// This should be the last pair of ops - always.
if (isset($action['extra']['att_added']))
$actions[$k]['action_text'] .= ' ' . $txt['shd_logpart_att_added'] . ': ' . implode(', ', $action['extra']['att_added']);
if (isset($action['extra']['att_removed']))
$actions[$k]['action_text'] .= ' ' . $txt['shd_logpart_att_removed'] . ': ' . implode(', ', $action['extra']['att_removed']);
}
return $actions;
}
/**
* Returns the total number of items in the helpdesk log.
*
* This function gets the total number of items logged in the helpdesk log, for the purposes of establishing the number of
* pages there should be in the page-index.
*
* @param string $clause An SQL fragment that forms a WHERE clause to limit log items, e.g. to load a specific ticket or specific member's log items.
*
* @return int Number of entries in the helpdesk action log table.
* @see shd_load_action_log_entries()
* @since 1.0
*/
function shd_count_action_log_entries($clause = '')
{
global $smcFunc;
$exclude = shd_action_log_exclusions();
if (!empty($exclude))
{
if (empty($clause))
$clause = 'la.action NOT IN ({array_string:exclude})';
else
$clause .= ' AND la.action NOT IN ({array_string:exclude})';
}
// Without further screaming and waving, fetch the actions.
$request = shd_db_query('', '
SELECT COUNT(*)
FROM {db_prefix}helpdesk_log_action AS la
LEFT JOIN {db_prefix}members AS mem ON(mem.id_member = la.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
WHERE la.id_ticket != {int:no_ticket}' . (empty($clause) ? '' : '
AND ' . $clause),
array(
'no_ticket' => 0,
'reg_group_id' => 0,
'exclude' => $exclude,
)
);
list ($entry_count) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return $entry_count;
}
function shd_action_log_exclusions()
{
global $user_info;
$exclude = array();
if (!$user_info['is_admin'] && !shd_allowed_to('admin_helpdesk', 0))
{
// First, custom field changes only available to admins.
$exclude = array('cf_tktchange_admin', 'cf_rplchange_admin', 'cf_tktchgdef_admin', 'cf_rplchgdef_admin');
// Next, staff only things
if (!shd_allowed_to('shd_staff', 0))
{
$exclude[] = 'cf_tktchange_staffadmin';
$exclude[] = 'cf_rplchange_staffadmin';
$exclude[] = 'cf_tktchgdef_staffadmin';
$exclude[] = 'cf_rplchgdef_staffadmin';
}
else
// Next, user only things (that staff can't see)
{
$exclude[] = 'cf_tktchange_useradmin';
$exclude[] = 'cf_rplchange_useradmin';
$exclude[] = 'cf_tktchgdef_useradmin';
$exclude[] = 'cf_rplchgdef_useradmin';
}
// Can they see multiple departments? If not, exclude dept move notices too.
$dept = shd_allowed_to('access_helpdesk', false);
if (!is_bool($dept) && count($dept) == 1)
$exclude[] = 'move_dept';
}
return $exclude;
}
/**
* Perform all the operations required for SimpleDesk to safely start operations inside the admin panel.
*
* @param array &$admin_areas The full admin area array from SMF's Admin.php.
* @since 2.0
*/
function shd_admin_bootstrap(&$admin_areas)
{
global $sourcedir, $modSettings, $txt, $context, $scripturl;
// Load the main admin language files and any needed for SD plugins in the admin panel.
require_once($sourcedir . '/sd_source/SimpleDesk-Admin.php');
shd_load_language('sd_language/SimpleDeskAdmin');
shd_load_plugin_files('hdadmin');
shd_load_plugin_langfiles('hdadmin');
// Now add the main SimpleDesk menu
if (empty($modSettings['helpdesk_active']))
return;
// The helpdesk action log
if (empty($modSettings['shd_disable_action_log']))
$admin_areas['maintenance']['areas']['logs']['subsections']['helpdesklog'] = array($txt['shd_admin_helpdesklog'], 'admin_forum', 'url' => $scripturl . '?action=admin;area=helpdesk_info;sa=actionlog');
// The main menu
$admin_areas['helpdesk_info'] = array(
'title' => $txt['shd_helpdesk'],
'enabled' => allowedTo('admin_forum') || shd_allowed_to('admin_helpdesk', 0),
'areas' => array(
'helpdesk_info' => array(
'label' => $txt['shd_admin_info'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_simpledesk',
'function' => 'shd_admin_main',
'subsections' => array(
'main' => array($txt['shd_admin_info']),
'actionlog' => array($txt['shd_admin_actionlog'], 'enabled' => empty($modSettings['shd_disable_action_log'])),
'adminlog' => array($txt['shd_admin_adminlog'], 'enabled' => allowedTo('admin_forum')),
'support' => array($txt['shd_admin_support']),
),
),
'helpdesk_options' => array(
'label' => $txt['shd_admin_options'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_options',
'function' => 'shd_admin_main',
'subsections' => array(
'display' => array($txt['shd_admin_options_display']),
'posting' => array($txt['shd_admin_options_posting']),
'admin' => array($txt['shd_admin_options_admin']),
'standalone' => array($txt['shd_admin_options_standalone']),
'actionlog' => array($txt['shd_admin_options_actionlog']),
'notifications' => array($txt['shd_admin_options_notifications']),
),
),
'helpdesk_cannedreplies' => array(
'label' => $txt['shd_admin_cannedreplies'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_cannedreplies',
'function' => 'shd_admin_main',
'subsections' => array(
),
),
'helpdesk_customfield' => array(
'label' => $txt['shd_admin_custom_fields'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_custom_fields',
'function' => 'shd_admin_main',
'subsections' => array(
),
),
'helpdesk_depts' => array(
'label' => $txt['shd_admin_departments'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_departments',
'function' => 'shd_admin_main',
'subsections' => array(
),
),
'helpdesk_permissions' => array(
'label' => $txt['shd_admin_permissions'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_permissions',
'function' => 'shd_admin_main',
'subsections' => array(
),
),
'helpdesk_plugins' => array(
'label' => $txt['shd_admin_plugins'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_plugins',
'function' => 'shd_admin_main',
'subsections' => array(
),
),
'helpdesk_maint' => array(
'label' => $txt['shd_admin_maint'],
'file' => 'sd_source/SimpleDesk-Admin.php',
'icon' => 'shd_maintenance',
'function' => 'shd_admin_main',
'subsections' => array(
'main' => array($txt['shd_admin_maint']),
'search' => array($txt['shd_maint_search_settings']),
),
),
),
);
// Now engage any hooks.
call_integration_hook('shd_hook_adminmenu', array(&$admin_areas));
}
/**
* Add the SimpleDesk option into the Core Features page inside the admin panel.
*
* @param array &$core_features The array of Core Features as provided by ManageSettings.php
*/
function shd_admin_core_features(&$core_features)
{
$temp = $core_features;
$core_features = array();
shd_load_language('sd_language/SimpleDeskAdmin');
foreach ($temp as $k => $v)
{
// Insert it before the moderation log
if ($k == 'ml')
$core_features['shd'] = array('url' => 'action=admin;area=helpdesk_info');
$core_features[$k] = $v;
}
}
/**
* Perform any processing on SMF permissions subject to SimpleDesk options (namely removing permissions that make no sense in helpdesk-only mode)
*
* All of the parameters are the normal variables provided by ManagePermissions.php to its integration hook.
* @since 2.0
* @param array &$permissionGroups The array of groups of permissions
* @param array &$permissionList The master list of permissions themselves
* @param array &$leftPermissionGroups The list of permission groups that are displayed on the left hand side of the screen in Classic Mode
* @param array &$hiddenPermissions A list of permissions to be hidden in the event of features being disabled
* @param array &$relabelPermissions A list of permissions to be renamed depending on features being active
*/
function shd_admin_smf_perms(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
{
global $modSettings;
if (!$modSettings['helpdesk_active'] || empty($modSettings['shd_helpdesk_only']) || empty($permissionGroups) || empty($permissionList) || empty($leftPermissionGroups) || empty($relabelPermissions))
return;
$perms_disable = array(
'view_stats',
'who_view',
'search_posts',
'karma_edit',
'calendar_view',
'calendar_post',
'calendar_edit',
'manage_boards',
'manage_attachments',
'manage_smileys',
'edit_news',
'access_mod_center',
'moderate_forum',
'send_mail',
'issue_warning',
'moderate_board',
'approve_posts',
'post_new',
'post_unapproved_topics',
'post_unapproved_replies',
'post_reply',
'merge_any',
'split_any',
'send_topic',
'make_sticky',
'move',
'lock',
'remove',
'modify_replies',
'delete_replies',
'announce_topic',
'delete',
'modify',
'report_any',
'poll_view',
'poll_vote',
'poll_post',
'poll_add',
'poll_edit',
'poll_lock',
'poll_remove',
'mark_any_notify',
'mark_notify',
'view_attachments',
'post_unapproved_attachments',
'post_attachment',
);
// that's the generic stuff, now for specific options
if (!empty($modSettings['shd_disable_pm']))
{
$perms_disable[] = 'pm_read';
$perms_disable[] = 'pm_send';
}
$hiddenPermissions = array_merge($hiddenPermissions, $perms_disable);
}
/**
* Intergrates into SMF's admin search.
*
* @since 2.0
* @param array &$language_files language files to include.
* @param array &$include_files Files to load.
* @param array &$settings_search Settings to search.
*/
function shd_admin_search(&$language_files, &$include_files, &$settings_search)
{
// Add in language files.
$language_files = array_merge($language_files, array(
'sd_language/SimpleDeskAdmin',
));
// Extra files.
$include_files = array_merge($include_files, array(
'sd_source/SimpleDesk-Admin',
));
// Add SimpleDesk functions
$settings_search = array_merge($settings_search, array(
array('shd_modify_display_options', 'area=helpdesk_options;sa=display'),
array('shd_modify_posting_options', 'area=helpdesk_options;sa=posting'),
array('shd_modify_admin_options', 'area=helpdesk_options;sa=admin'),
array('shd_modify_standalone_options', 'area=helpdesk_options;sa=standalone'),
array('shd_modify_actionlog_options', 'area=helpdesk_options;sa=actionlog'),
array('shd_modify_notifications_options', 'area=helpdesk_options;sa=notifications'),
));
// Our plugins may still use the old SHD hook.
call_integration_hook('shd_hook_hdadminoptssrch', array(&$settings_search));
}
/**
* Removes an attachment when removed from SMF.
*
* @since 2.1
* @param array &$attach All attachment IDs removed.
*/
function shd_remove_attachments($attach)
{
global $smcFunc;
// And now lastly to remove SimpleDesk attachments
if (!empty($attach))
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}helpdesk_attachments
WHERE id_attach IN ({array_int:attachment_list})',
array(
'attachment_list' => $attach,
)
);
}
/**
* Converts helpdesk body length to match SMF's.
*
* @since 2.1
* @param array $body_type Either text or other.
*/
function shd_convert_msgbody($body_type = 'null')
{
global $smcFunc;
if ($body_type == 'text')
$smcFunc['db_change_column']('{db_prefix}helpdesk_ticket_replies', 'body', array('type' => 'text'));
else
$smcFunc['db_change_column']('{db_prefix}helpdesk_ticket_replies', 'body', array('type' => 'mediumtext'));
}
/**
* Adds SimpleDesk language files into our search location.
*
* @since 2.1
* @param array &$themes all the themes avaiable.
* @param array &$themes all the language directories avaiable.
*/
function shd_modifylanguages(&$themes, &$lang_dirs)
{
global $settings;
$themes['shd'] = array('name' => 'SimpleDesk', 'theme_dir' => $settings['default_theme_dir'] . '/languages/sd_language');
$lang_dirs['shd'] = $settings['default_theme_dir'] . '/languages/sd_language';
$themes['shd_plugins'] = array('name' => 'SimpleDesk Plugins', 'theme_dir' => $settings['default_theme_dir'] . '/languages/sd_plugins_lang');
$lang_dirs['shd_plugins'] = $settings['default_theme_dir'] . '/languages/sd_plugins_lang';
}
/**
* Tracks a change to our options/configvars.
*
* @since 2.1
* @param array $save_vars Passed before we do the updateDBSettings but after everything else is ready.
*/
function shd_admin_log_configvar($save_vars)
{
global $smcFunc, $user_info, $modSettings;
foreach ($save_vars as $var)
{
if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
continue;
// Fix some data for proper testing.
$newValue = isset($_POST[$var[1]]) ? $_POST[$var[1]] : null;
// Checks are either on or off.
if ($var[0] == 'check')
$newValue = !empty($_POST[$var[1]]) ? '1' : '0';
// Skip it if nothing was changed.
if (isset($modSettings[$var[1]]) && $modSettings[$var[1]] == $newValue)
continue;
// Or if nothing exists.
elseif (!isset($modSettings[$var[1]]) && empty($newValue))
continue;
// Log this.
shd_admin_log('admin_change_option', array(
'action' => 'update',
'setting' => $var[1],
'type' => $var[0],
'from' => isset($modSettings[$var[1]]) ? $modSettings[$var[1]] : null,
'to' => $newValue,
));
}
}
/**
* Logs a change in our admin area.
*
* @since 2.1
* @param string $action The area this was from.
* @param array $extra An array of extra elements, in the following format.
* (required) string $action The action performed.
* (optional) string $setting During a setting update, this is the variable we changed.
* (optional) string $type The subaction peformed or during a setting update, int/string/etc.
* (optional) int $id The ID of the item we performed the action on.
* (optional) string $direction During a reorder up/down operation which way we moved.
* (optional) int $to The ID of the destination item used during copy/move operation.
* (optional) int $from The ID of the source item used during the copy/move operation
*/
function shd_admin_log($action, $extra)
{
global $smcFunc, $user_info;
$smcFunc['db_insert']('',
'{db_prefix}helpdesk_log_action',
array('log_time' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string', 'id_ticket' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534',),
array(time(), $user_info['id'], $user_info['ip'], $action, 0, 0, json_encode($extra)),
array('id_action')
);
}
/**
* Load the items from the helpdesk action log
*
* It is subject to given parameters (start, number of items, order/sorting), parses the language strings and adds the
* parameter information provided.
*
* @param int $start Number of items into the log to start (for pagination). If -1, return everything. If nothing is given, fall back to 0, i.e the first log item.
* @param int $items_per_page How many items to load. Default to 10 items.
* @param string $sort SQL clause to state which column(s) to order the data by. By default it orders by log_time.
* @param string $order SQL clause to state whether the order is ascending or descending. Defaults to descending.
* @param string $clause An SQL fragment that forms a WHERE clause to limit log items, e.g. to load a specific ticket or specific member's log items.
*
* @return array A hash array of the log items, with the auto-incremented id being the key:
* <ul>
* <li>id: Numeric identifier of the log item</li>
* <li>time: Formatted time of the event (as per usual for SMF, formatted for user's timezone)</li>
* <li>member: hash array:
* <ul>
* <li>id: Id of the user that committed the action</li>
* <li>name: Name of the user</li>
* <li>link: Link to the profile of the user that committed the action</li>
* <li>ip: User IP address recorded when the action was carried out</li>
* <li>group: Name of the group of the user (uses primary group, failing that post count group)</li>
* </ul>
* </li>
* <li>action: Raw name of the action (for use with collecting the image later)</li>
* <li>id_ticket: Numeric id of the ticket this action refers to</li>
* <li>id_msg: Numeric id of the individual reply this action refers to</li>
* <li>extra: Array of extra parameters for the log action</li>
* <li>action_text: Formatted text of the log item (parsed with parameters)</li>
* </ul>
*
* @see shd_log_action()
* @see shd_count_action_log_entries()
* @since 1.0
*/
function shd_load_admin_log_entries($start = 0, $items_per_page = 10, $sort = 'la.log_time', $order = 'DESC')
{
global $smcFunc, $txt, $scripturl, $context, $user_info, $user_profile;
// Load languages incase they aren't there (Read: ticket-specific logs)
shd_load_language('sd_language/SimpleDeskAdmin');
shd_load_language('sd_language/SimpleDeskLogAction');
shd_load_language('sd_language/SimpleDeskNotifications');
$request = shd_db_query('', '
SELECT la.id_action, la.log_time, la.ip, la.action, la.extra,
COALESCE(mem.id_member, 0) AS id_member, COALESCE(mem.real_name, {string:blank}) AS real_name, COALESCE(mg.group_name, {string:na}) AS group_name
FROM {db_prefix}helpdesk_log_action AS la
LEFT JOIN {db_prefix}members AS mem ON(mem.id_member = la.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_group_id} THEN mem.id_post_group ELSE mem.id_group END)
WHERE la.id_ticket = {int:no_ticket}
ORDER BY ' . ($sort != '' ? '{raw:sort} {raw:order}' : 'la.log_time DESC') . '
' . ($start != -1 ? 'LIMIT {int:start}, {int:items_per_page}' : ''),
array(
'no_ticket' => 0,
'reg_group_id' => 0,
'sort' => $sort,
'start' => $start,
'items_per_page' => $items_per_page,
'order' => $order,
'na' => $txt['not_applicable'],
'blank' => '',
)
);
$actions = array();
$ids = array(
'canned_cat' => array(),
'depts' => array(),
'canned_reply' => array(),
'custom_field' => array(),
'members' => array(),
'permissions' => array(),
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['extra'] = json_decode($row['extra'], true);
$row['extra'] = is_array($row['extra']) ? $row['extra'] : array();
// Uhoh, we don't know who this is! Check it's not automatically by the system. If it is... mark it so.
if (empty($row['id_member']))
{
if (isset($row['extra']['auto']) && $row['extra']['auto'] === true)
$row['real_name'] = $txt['shd_helpdesk'];
else
$row['real_name'] = $txt['shd_admin_actionlog_unknown'];
}
$actions[$row['id_action']] = array(
'id' => $row['id_action'],
'time' => timeformat($row['log_time']),
'member' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'link' => shd_profile_link($row['real_name'], $row['id_member']),
'group' => $row['group_name'],
'ip' => !empty($row['ip']) ? $row['ip'] : $txt['shd_admin_actionlog_unknown'],
),
'action' => $row['action'],
'type' => isset($row['extra']['type']) ? $row['extra']['type'] : '',
'extra' => $row['extra'],
'action_text' => '',
'can_remove' => empty($context['waittime']) ? false : ($row['log_time'] < $context['waittime']),
);
// Load these up so we can find them later, it looks bad, but is actually simple.
if ($row['action'] == 'admin_canned' && !empty($row['id']) && in_array($row['type'], array('cat_move', 'cat_delete', 'cat_add', 'cat_update')))
{
if (!isset($ids['canned_cat'][$row['extra']['id']]))
$ids['canned_cat'][$row['extra']['id']] = array();
$ids['canned_cat'][$row['extra']['id']][$row['id_action']] = 'id';
}
elseif ($row['action'] == 'admin_canned' && !empty($row['id']) && in_array($row['type'], array('reply_move', 'reply_delete', 'reply_add', 'reply_update')))
{
if (!isset($ids['canned_reply'][$row['extra']['id']]))
$ids['canned_reply'][$row['extra']['id']] = array();
$ids['canned_reply'][$row['extra']['id']][$row['id_action']] = 'id';
}
elseif ($row['action'] == 'admin_dept')
{
if (!isset($ids['depts'][$row['extra']['id']]))
$ids['depts'][$row['extra']['id']] = array();
$ids['depts'][$row['extra']['id']][$row['id_action']] = 'id';
}
elseif ($row['action'] == 'admin_customfield')
{
if (!isset($row['extra']['id']))
continue;
if (!isset($ids['custom_field'][$row['extra']['id']]))
$ids['custom_field'][$row['extra']['id']] = array();
$ids['custom_field'][$row['extra']['id']][$row['id_action']] = 'id';
}
elseif ($row['action'] == 'admin_maint')
{
if ($row['extra']['action'] == 'move_dept')
{
if (!isset($ids['depts'][$row['extra']['to']]))
$ids['depts'][$row['extra']['to']] = array();
$ids['depts'][$row['extra']['to']][$row['id_action']] = 'to';
if (!isset($ids['depts'][$row['extra']['from']]))
$ids['depts'][$row['extra']['from']] = array();
$ids['depts'][$row['extra']['from']][$row['id_action']] = 'from';
}
else
{
if (!empty($row['extra']['to']))
{
if (!isset($ids['members'][$row['extra']['to']]))
$ids['members'][$row['extra']['to']] = array();
$ids['members'][$row['extra']['to']][$row['id_action']] = 'to';
}
if (!empty($row['extra']['from']))
{
if (!isset($ids['members'][$row['extra']['from']]))
$ids['members'][$row['extra']['from']] = array();
$ids['members'][$row['extra']['from']][$row['id_action']] = 'from';
}
}
}
elseif ($row['action'] == 'admin_permissions')
{
if (!empty($row['extra']['id']))
{
if (!isset($ids['permissions'][$row['extra']['id']]))
$ids['permissions'][$row['extra']['id']] = array();
$ids['permissions'][$row['extra']['id']][$row['id_action']] = 'id';
}
if (!empty($row['extra']['to']))
{
if (!isset($ids['permissions'][$row['extra']['to']]))
$ids['permissions'][$row['extra']['to']] = array();
$ids['permissions'][$row['extra']['to']][$row['id_action']] = 'to';
}
if (!empty($row['extra']['from']))
{
if (!isset($ids['permissions'][$row['extra']['from']]))
$ids['permissions'][$row['extra']['from']] = array();
$ids['permissions'][$row['extra']['from']][$row['id_action']] = 'from';
}
}
}
$smcFunc['db_free_result']($request);
// Now lets try to find stuff.
if (!empty($ids['canned_cat']))
{
$request = shd_db_query('', '
SELECT id_cat AS id, cat_name AS name
FROM {db_prefix}helpdesk_cannedreplies_cats
WHERE id_cat IN ({array_int:cats})',
array(
'cats' => array_keys($ids['canned_cat']),
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
foreach ($ids['canned_cat'][$row['id']] as $id_action => $type)
if ($type == 'id')
$actions[$id_action]['id_name'] = $row['name'];
$smcFunc['db_free_result']($request);
}
if (!empty($ids['canned_reply']))
{
$request = shd_db_query('', '
SELECT id_reply AS id, title AS name
FROM {db_prefix}helpdesk_cannedreplies
WHERE id_reply IN ({array_int:replys})',
array(
'replys' => array_keys($ids['canned_reply']),
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
foreach ($ids['canned_reply'][$row['id']] as $id_action => $type)
if ($type == 'id')
$actions[$id_action]['id_name'] = $row['name'];
$smcFunc['db_free_result']($request);
}
if (!empty($ids['custom_field']))
{
// We do this as we just want the name really.
$request = shd_db_query('', '
SELECT id_field AS id, field_name AS name
FROM {db_prefix}helpdesk_custom_fields
WHERE id_field IN ({array_int:custom_fields})',
array(
'custom_fields' => array_keys($ids['custom_field']),
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
foreach ($ids['custom_field'][$row['id']] as $id_action => $type)
if ($type == 'id')
$actions[$id_action]['id_name'] = $row['name'];
$smcFunc['db_free_result']($request);
}
if (!empty($ids['depts']))
{
// We do this as we just want the name really.
$request = shd_db_query('', '
SELECT id_dept AS id, dept_name AS name
FROM {db_prefix}helpdesk_depts
WHERE id_dept IN ({array_int:depts})',
array(
'depts' => array_keys($ids['depts']),
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
foreach ($ids['depts'][$row['id']] as $id_action => $type)
$actions[$id_action][$type == 'id' ? 'id_name' : ($type == 'to' ? 'to_name' : 'from_name')] = $row['name'];
$smcFunc['db_free_result']($request);
}
if (!empty($ids['members']))
{
$request = shd_db_query('', '
SELECT id_member AS id, IFNULL(real_name, {string:blank}) AS name
FROM {db_prefix}members
WHERE id_member IN ({array_int:members})',
array(
'members' => array_keys($ids['members']),
'blank' => '',
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
foreach ($ids['custom_field'][$row['id']] as $id_action => $type)
$actions[$id_action][$type == 'to' ? 'to_name' : 'from_name'] = $row['name'];
$smcFunc['db_free_result']($request);