/
mysupport.php
executable file
·4318 lines (3900 loc) · 139 KB
/
mysupport.php
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
/**
* MySupport 0.4
* Copyright 2010 Matthew Rogowski
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
** http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
if(!defined("IN_MYBB"))
{
header("HTTP/1.0 404 Not Found");
exit;
}
define("MYSUPPORT_VERSION", "0.5");
$plugins->add_hook("admin_config_action_handler", "mysupport_admin_config_action_handler");
$plugins->add_hook("admin_config_menu", "mysupport_admin_config_menu");
$plugins->add_hook("admin_config_permissions", "mysupport_admin_config_permissions");
$plugins->add_hook("admin_config_plugins_activate_commit", "mysupport_settings_redirect");
$plugins->add_hook("admin_page_output_footer", "mysupport_settings_footer");
$plugins->add_hook("build_forumbits_forum", "mysupport_forum_overview");
$plugins->add_hook("build_friendly_wol_location_end", "mysupport_build_wol");
$plugins->add_hook("datahandler_post_validate_post", "mysupport_datahandler_post_validate_post");
$plugins->add_hook("editpost_start", "mysupport_thread_info");
$plugins->add_hook("fetch_wol_activity_end", "mysupport_friendly_wol");
$plugins->add_hook("forumdisplay_start", "mysupport_forumdisplay_searchresults");
$plugins->add_hook("forumdisplay_thread", "mysupport_threadlist_thread");
$plugins->add_hook("global_start", "mysupport_notices");
$plugins->add_hook("member_profile_end", "mysupport_profile");
$plugins->add_hook("modcp_start", "mysupport_modcp_support_denial");
$plugins->add_hook("modcp_start", "mysupport_navoption", -10);
$plugins->add_hook("modcp_start", "mysupport_thread_list");
$plugins->add_hook("moderation_start", "mysupport_do_inline_thread_moderation");
$plugins->add_hook("newreply_start", "mysupport_bump_thread_notice");
$plugins->add_hook("newreply_start", "mysupport_thread_info");
$plugins->add_hook("newthread_do_newthread_end", "mysupport_set_is_support_thread");
$plugins->add_hook("newthread_start", "mysupport_newthread");
$plugins->add_hook("newthread_start", "mysupport_thread_info");
$plugins->add_hook("postbit", "mysupport_postbit");
$plugins->add_hook("search_results_start", "mysupport_forumdisplay_searchresults");
$plugins->add_hook("search_results_thread", "mysupport_threadlist_thread");
$plugins->add_hook("showthread_start", "mysupport_bump_thread_notice");
$plugins->add_hook("showthread_start", "mysupport_showthread");
$plugins->add_hook("usercp_menu_built", "mysupport_navoption", -10);
$plugins->add_hook("usercp_start", "mysupport_thread_list");
$plugins->add_hook("usercp_start", "mysupport_usercp_options");
global $templatelist;
if(isset($templatelist))
{
$templatelist .= ',';
}
$mysupport_templates = mysupport_templates();
$mysupport_templates = implode(",", $mysupport_templates);
$templatelist .= $mysupport_templates;
/**
* These are just here for when I'm debugging or updating templates, to run some code at runtime which is usually called in the upgrade function
**/
if(!defined("IN_ADMINCP"))
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
/*if(!defined("MYBB_ADMIN_DIR"))
{
define("MYBB_ADMIN_DIR", MYBB_ROOT."/admin/");
}*/
//mysupport_do_templates(0, true);
//mysupport_do_templates(1);
//mysupport_template_edits(0);
//mysupport_template_edits(1);
//mysupport_import_settings();
//mysupport_table_columns(1);
//mysupport_stylesheet(2);
//mysupport_cache();
}
function mysupport_info()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_info();
}
function mysupport_install()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_install();
}
function mysupport_is_installed()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_is_installed();
}
function mysupport_uninstall()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_uninstall();
}
function mysupport_activate()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_activate();
}
function mysupport_deactivate()
{
require_once MYBB_ROOT."inc/plugins/mysupport/mysupport.php";
return mysupport_do_deactivate();
}
function mysupport_cache($what = "")
{
global $db, $cache;
$old_cache = $cache->read("mysupport");
$new_cache = array();
if($what == "version" || !$what)
{
$new_cache['version'] = MYSUPPORT_VERSION;
}
else
{
$new_cache['version'] = $old_cache['version'];
}
if($what == "priorities" || !$what)
{
$query = $db->simple_select("mysupport", "mid, name, description, extra", "type = 'priority'");
$new_cache['priorities'] = array();
while($priority = $db->fetch_array($query))
{
$new_cache['priorities'][$priority['mid']] = $priority;
}
}
else
{
$new_cache['priorities'] = $old_cache['priorities'];
}
if($what == "deniedreasons" || !$what)
{
$query = $db->simple_select("mysupport", "mid, name, description", "type = 'deniedreason'");
$new_cache['deniedreasons'] = array();
while($deniedreason = $db->fetch_array($query))
{
$new_cache['deniedreasons'][$deniedreason['mid']] = $deniedreason;
}
}
else
{
$new_cache['deniedreasons'] = $old_cache['deniedreasons'];
}
$cache->update("mysupport", $new_cache);
}
// can't put this in the external functions file as it's needed for the templates list above
function mysupport_templates()
{
return array(
'mysupport_assigned',
'mysupport_assigned_toyou',
'mysupport_bestanswer',
'mysupport_deny_support',
'mysupport_deny_support_deny',
'mysupport_deny_support_list',
'mysupport_deny_support_post',
'mysupport_deny_support_post_linked',
'mysupport_form',
'mysupport_form_ajax',
'mysupport_jumpto_bestanswer',
'mysupport_nav_option',
'mysupport_notice',
'mysupport_status_image',
'mysupport_status_text',
'mysupport_tab',
'mysupport_threadlist',
'mysupport_threadlist_footer',
'mysupport_threadlist_list',
'mysupport_threadlist_stats',
'mysupport_threadlist_thread',
'mysupport_deny_support_list_user',
'mysupport_usercp_options',
'mysupport_inline_thread_moderation',
'mysupport_member_profile'
);
}
// get the gid of the MySupport settings group
function mysupport_settings_gid()
{
global $db;
$query = $db->simple_select("settinggroups", "gid", "name = 'mysupport'", array("limit" => 1));
$gid = $db->fetch_field($query, "gid");
return intval($gid);
}
// redirect to the settings page after activating
function mysupport_settings_redirect()
{
global $mybb, $db, $lang, $installed;
if($installed === true && $mybb->input['plugin'] == "mysupport")
{
$lang->load("mysupport", true);
$gid = mysupport_settings_gid();
flash_message($lang->mysupport_activated, 'success');
admin_redirect("index.php?module=config-settings&action=change&gid={$gid}");
}
}
// show the form in the thread to change the status of the thread
function mysupport_showthread()
{
global $mybb;
if($mybb->settings['enablemysupport'] != 1)
{
return;
}
global $db, $cache, $lang, $templates, $theme, $thread, $forum, $mysupport_status, $mysupport_options, $mysupport_js, $support_denial_reasons, $mod_log_action, $redirect;
$lang->load("mysupport");
$tid = intval($thread['tid']);
$fid = intval($thread['fid']);
if(mysupport_forum($forum['fid']) && $mybb->input['action'] != "mysupport" && $mybb->input['action'] != "bestanswer")
{
// load the denied reasons so we can display them to staff if necessary
if($mybb->settings['enablemysupportsupportdenial'] == 1 && mysupport_usergroup("canmanagesupportdenial"))
{
$support_denial_reasons = array();
$mysupport_cache = $cache->read("mysupport");
if(!empty($mysupport_cache['deniedreasons']))
{
foreach($mysupport_cache['deniedreasons'] as $deniedreasons)
{
$support_denial_reasons[$deniedreason['mid']] = htmlspecialchars_uni($deniedreason['name']);
}
}
}
if($thread['issupportthread'] == 1)
{
$mysupport_options = "";
$count = 0;
$mysupport_solved = $mysupport_solved_and_close = $mysupport_technical = $mysupport_not_solved = $on_hold = $assigned_list = $priorities_list = $categories_list = $is_support_thread = "";
// if it's not already solved
if($thread['status'] != 1)
{
// can they mark as solved?
if(mysupport_usergroup("canmarksolved") || ($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))
{
// closing when solved is either optional, or off
if($mybb->settings['mysupportclosewhensolved'] != "always")
{
if($mybb->input['mysupport_full'])
{
$mysupport_solved = "<option value=\"1\">".$lang->solved."</option>";
}
else
{
$text = $lang->sprintf($lang->markas_link, $lang->solved);
$class = "mysupport_tab_solved";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&status=1&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
++$count;
}
// is the ability to close turned on?
if($mybb->settings['mysupportclosewhensolved'] != "never" && $thread['closed'] != 1)
{
// if the close setting isn't never, this option would show regardless of whether it's set to always or optional
if($mybb->input['mysupport_full'])
{
$mysupport_solved_and_close = "<option value=\"3\">".$lang->solved_close."</option>";
}
else
{
$text = $lang->sprintf($lang->markas_link, $lang->solved_close);
$class = "mysupport_tab_solved";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&status=3&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
++$count;
}
}
// is the technical threads feature on?
if($mybb->settings['enablemysupporttechnical'] == 1)
{
// can they mark as techincal?
if(mysupport_usergroup("canmarktechnical"))
{
if($thread['status'] != 2)
{
// if it's not marked as technical, give an option to mark it as such
if($mybb->input['mysupport_full'])
{
$mysupport_technical = "<option value=\"2\">".$lang->technical."</option>";
}
else
{
$text = $lang->sprintf($lang->markas_link, $lang->technical);
$class = "mysupport_tab_technical";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&status=2&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
}
else
{
// if it's already marked as technical, have an option to put it back to normal
if($mybb->input['mysupport_full'])
{
$mysupport_technical = "<option value=\"4\">".$lang->not_technical."</option>";
}
else
{
$text = $lang->sprintf($lang->markas_link, $lang->not_technical);
$class = "mysupport_tab_technical";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&status=4&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
}
++$count;
}
}
}
// if it's solved, all you can do is mark it as not solved
else
{
// are they allowed to mark it as not solved if it's been marked solved already?
if($mybb->settings['mysupportunsolve'] == 1 && (mysupport_usergroup("canmarksolved") || ($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid'])))
{
if($mybb->input['mysupport_full'])
{
$mysupport_not_solved = "<option value=\"0\">".$lang->not_solved."</option>";
}
else
{
$text = $lang->sprintf($lang->markas_link, $lang->not_solved);
$class = "mysupport_tab_not_solved";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&status=0&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
++$count;
}
}
$status_list = "";
// if the current count is more than 0 there's some status options to show
if($count > 0)
{
$current_status = mysupport_get_friendly_status($thread['status']);
$status_list .= "<label for=\"status\">".$lang->markas."</label> <select name=\"status\">\n";
// show the current status but have the value as -1 so it's treated as not submitting a status
// doing this because the assigning and priority menus show their current values, so do it here too for consistency
$status_list .= "<option value=\"-1\">".htmlspecialchars_uni($current_status)."</option>\n";
// also show a blank option with a value of -1
$status_list .= "<option value=\"-1\"></option>\n";
$status_list .= $mysupport_not_solved."\n";
$status_list .= $mysupport_solved."\n";
$status_list .= $mysupport_solved_and_close."\n";
$status_list .= $mysupport_technical."\n";
$status_list .= "</select>\n";
if($mybb->input['ajax'])
{
$status_list = "<tr>\n<td class=\"trow1\" align=\"center\">".$status_list."\n</td>\n</tr>";
}
}
if($mybb->settings['enablemysupportbestanswer'] == 1)
{
// this doesn't need to show when viewing the 'full' form, as only staff will be seeing that
if($thread['bestanswer'] != 0 && !$mybb->input['mysupport_full'])
{
$post = intval($thread['bestanswer']);
$text = $lang->jump_to_bestanswer_tab;
$class = "mysupport_tab_best_answer";
$url = $mybb->settings['bburl']."/".get_post_link($post, $tid)."#pid".$post;
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
}
if($thread['status'] != 1 && (mysupport_usergroup("canmarksolved") || ($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid'])))
{
if($mybb->settings['enablemysupportonhold'] == 1)
{
if($mybb->input['mysupport_full'])
{
$checked = "";
if($thread['onhold'] == 1)
{
$checked = " checked=\"checked\"";
}
$on_hold = "<label for=\"onhold\">".$lang->onhold_form."</label> <input type=\"checkbox\" name=\"onhold\" id=\"onhold\" value=\"1\"{$checked} />";
if($mybb->input['ajax'])
{
$on_hold = "<tr>\n<td class=\"trow1\" align=\"center\">".$on_hold."\n</td>\n</tr>";
}
}
else
{
if($thread['onhold'] == 1)
{
$text = $lang->hold_off;
$class = "mysupport_tab_hold";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&onhold=0&tid={$tid}&my_post_key={$mybb->post_code}";
}
else
{
$text = $lang->hold_on;
$class = "mysupport_tab_hold";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&action=mysupport&onhold=1&tid={$tid}&my_post_key={$mybb->post_code}";
}
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
}
}
// do we need to show the link to show the additional options?
// for assigning users, and setting priorities and categories, check the permission; if we're requesting the information, show it, if not, set this to true
$show_more_link = false;
// check if assigning threads is enabled and make sure you can assign threads to people
// also check if the thread is currently not solved, or if it's solved but you can unsolve it; if any of those are true, you may want to assign it
if($mybb->settings['enablemysupportassign'] == 1 && mysupport_usergroup("canassign") && ($thread['status'] != 1 || ($thread['status'] == 1 && $mybb->settings['mysupportunsolve'] == 1)))
{
if($mybb->input['mysupport_full'])
{
$assign_users = mysupport_get_assign_users();
// only continue if there's one or more users that can be assigned threads
if(!empty($assign_users))
{
$assigned_list .= "<label for=\"assign\">".$lang->assign_to."</label> <select name=\"assign\">\n";
$assigned_list .= "<option value=\"0\"></option>\n";
foreach($assign_users as $assign_userid => $assign_username)
{
$selected = "";
if($thread['assign'] == $assign_userid)
{
$selected = " selected=\"selected\"";
}
$assigned_list .= "<option value=\"".intval($assign_userid)."\"{$selected}>".htmlspecialchars_uni($assign_username)."</option>\n";
++$count;
}
if($thread['assign'] != 0)
{
$assigned_list .= "<option value=\"-1\">".$lang->assign_to_nobody."</option>\n";
}
$assigned_list .= "</select>\n";
if($mybb->input['ajax'])
{
$assigned_list = "<tr>\n<td class=\"trow1\" align=\"center\">".$assigned_list."\n</td>\n</tr>";
}
}
}
$show_more_link = true;
}
// are priorities enabled and can this user set priorities?
if($mybb->settings['enablemysupportpriorities'] == 1 && mysupport_usergroup("cansetpriorities"))
{
if($mybb->input['mysupport_full'])
{
$mysupport_cache = $cache->read("mysupport");
if(!empty($mysupport_cache['priorities']))
{
$priorities_list .= "<label for=\"priority\">".$lang->priority."</label> <select name=\"priority\">\n";
$priorities_list .= "<option value=\"0\"></option>\n";
foreach($mysupport_cache['priorities'] as $priority)
{
$option_style = "";
if(!empty($priority['extra']))
{
$option_style = " style=\"background: #".htmlspecialchars_uni($priority['extra'])."\"";
}
$selected = "";
if($thread['priority'] == $priority['mid'])
{
$selected = " selected=\"selected\"";
}
$priorities_list .= "<option value=\"".intval($priority['mid'])."\"{$option_style}{$selected}>".htmlspecialchars_uni($priority['name'])."</option>\n";
++$count;
}
if($thread['priority'] != 0)
{
$priorities_list .= "<option value=\"-1\">".$lang->priority_none."</option>\n";
}
$priorities_list .= "</select>\n";
if($mybb->input['ajax'])
{
$priorities_list = "<tr>\n<td class=\"trow1\" align=\"center\">".$priorities_list."\n</td>\n</tr>";
}
}
}
$show_more_link = true;
}
if(mysupport_usergroup("canmarksolved") || ($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))
{
if($mybb->input['mysupport_full'])
{
$categories = mysupport_get_categories($forum);
if(!empty($categories))
{
$categories_list .= "<label for=\"category\">".$lang->category."</label> <select name=\"category\">\n";
$categories_list .= "<option value=\"0\"></option>\n";
foreach($categories as $category_id => $category)
{
$selected = "";
if($thread['prefix'] == $category_id)
{
$selected = " selected=\"selected\"";
}
$categories_list .= "<option value=\"".intval($category_id)."\"{$selected}>".htmlspecialchars_uni($category)."</option>\n";
++$count;
}
if($thread['prefix'] != 0)
{
$categories_list .= "<option value=\"-1\">".$lang->category_none."</option>\n";
}
$categories_list .= "</select>\n";
if($mybb->input['ajax'])
{
$categories_list = "<tr>\n<td class=\"trow1\" align=\"center\">".$categories_list."\n</td>\n</tr>";
}
}
}
$show_more_link = true;
}
if(mysupport_usergroup("canmarksolved") || ($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']) && $mybb->settings['enablemysupportnotsupportthread'] != 0)
{
if($mybb->input['mysupport_full'])
{
$checked = "";
if($thread['issupportthread'] == 1)
{
$checked = " checked=\"checked\"";
}
$is_support_thread .= "<label for=\"issupportthread\">".$lang->issupportthread."</label>\n";
$is_support_thread .= "<input type=\"checkbox\" name=\"issupportthread\" id=\"issupportthread\"{$checked} value=\"1\" />\n";
if($mybb->input['ajax'])
{
$is_support_thread = "<tr>\n<td class=\"trow1\" align=\"center\">".$is_support_thread."\n</td>\n</tr>";
}
}
$show_more_link = true;
}
if($show_more_link)
{
$mysupport_js = "<div id=\"mysupport_showthread_more_box\" style=\"display: none;\"></div>
<script type=\"text/javascript\">
function mysupport_more_link()
{
var url = '{$mybb->settings['bburl']}/showthread.php?tid={$tid}&mysupport_full=1';
new Ajax.Request(url+'&ajax=1', {
method: 'get',
onSuccess: function(data) {
if(data.responseText != '')
{
$('mysupport_showthread_more_box').style.display = '';
$('mysupport_showthread_more_box').innerHTML = data.responseText;
}
else
{
window.location = url;
}
}
});
}
function mysupport_close_more_box()
{
$('mysupport_showthread_more_box').style.display = 'none';
$('mysupport_showthread_more_box').innerHTML = '';
}
</script>";
$text = $lang->mysupport_tab_more;
$class = "mysupport_tab_misc";
$url = $mybb->settings['bburl']."/showthread.php?tid={$tid}&mysupport_full=1";
$onclick = " onclick=\"mysupport_more_link(); return false\"";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
}
else
{
$text = $lang->issupportthread_mark_as_support_thread;
$class = "mysupport_tab_misc";
$url = $mybb->settings['bburl']."/showthread.php?action=mysupport&issupportthread=1&tid={$tid}&my_post_key={$mybb->post_code}";
eval("\$mysupport_options .= \"".$templates->get('mysupport_tab')."\";");
}
if($mybb->input['mysupport_full'])
{
// are there actually any options to show for this user?
if($count > 0)
{
if($mybb->input['ajax'] == 1)
{
eval("\$mysupport_options = \"".$templates->get('mysupport_form_ajax')."\";");
// this is an AJAX request, echo and exit, GO GO GO
echo $mysupport_options;
exit;
}
else
{
eval("\$mysupport_options = \"".$templates->get('mysupport_form')."\";");
}
}
}
else
{
$mysupport_options = "<br /><div class=\"mysupport_tabs\">{$mysupport_options}</div>";
}
if($thread['issupportthread'] == 1)
{
$mysupport_status = mysupport_get_display_status($thread['status'], $thread['onhold'], $thread['statustime'], $thread['uid']);
}
}
if($mybb->input['action'] == "mysupport")
{
verify_post_check($mybb->input['my_post_key']);
$status = $db->escape_string($mybb->input['status']);
$assign = $db->escape_string($mybb->input['assign']);
$priority = $db->escape_string($mybb->input['priority']);
$category = $db->escape_string($mybb->input['category']);
$onhold = $db->escape_string($mybb->input['onhold']);
$issupportthread = $db->escape_string($mybb->input['issupportthread']);
$tid = intval($thread['tid']);
$fid = intval($thread['fid']);
$old_status = intval($thread['status']);
$old_assign = intval($thread['assign']);
$old_priority = intval($thread['priority']);
$old_category = intval($thread['prefix']);
$old_onhold = intval($thread['onhold']);
$old_issupportthread = intval($thread['issupportthread']);
// we need to make sure they haven't edited the form to try to perform an action they're not allowed to do
// we check everything in the entire form, if any part of it is wrong, it won't do anything
if(!mysupport_forum($fid))
{
mysupport_error($lang->error_not_mysupport_forum);
exit;
}
// are they trying to assign the same status it already has?
if($status == $old_status && !isset($mybb->input['onhold']) && !isset($mybb->input['issupportthread']))
{
$duplicate_status = mysupport_get_friendly_status($status);
mysupport_error($lang->sprintf($lang->error_same_status, $duplicate_status));
exit;
}
elseif($status == 0)
{
// either the ability to unsolve is turned off,
// they don't have permission to mark as not solved via group permissions, or they're not allowed to mark it as not solved even though they authored it
if($mybb->settings['mysupportunsolve'] != 1 || (!mysupport_usergroup("canmarksolved") && !($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid'])))
{
mysupport_error($lang->no_permission_mark_notsolved);
exit;
}
$valid_action = true;
}
elseif($status == 1)
{
// either they're not in a group that can mark as solved
// or they're not allowed to mark it as solved even though they authored it
if(!mysupport_usergroup("canmarksolved") && !($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))
{
mysupport_error($lang->no_permission_mark_solved);
exit;
}
$valid_action = true;
}
elseif($status == 2)
{
if($mybb->settings['enablemysupporttechnical'] != 1)
{
mysupport_error($lang->technical_not_enabled);
exit;
}
// they don't have the ability to mark threads as technical
if(!mysupport_usergroup("canmarktechnical"))
{
mysupport_error($lang->no_permission_mark_technical);
exit;
}
$valid_action = true;
}
elseif($status == 3)
{
// either closing of threads is turned off altogether
// or it's on, but they're not in a group that can't mark as solved
if($thread['closed'] == 1 || $mybb->settings['mysupportclosewhensolved'] == "never" || ($mybb->settings['mysupportclosewhensolved'] != "never" && (!mysupport_usergroup("canmarksolved") && !($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))))
{
mysupport_error($lang->no_permission_mark_solved_close);
exit;
}
$valid_action = true;
}
elseif($status == 4)
{
// they don't have the ability to mark threads as not technical
if(!mysupport_usergroup("canmarktechnical"))
{
mysupport_error($lang->no_permission_mark_nottechnical);
exit;
}
$valid_action = true;
}
// check if the thread is being put on/taken off hold
// check here is a bit weird as it'll be 1/-1 if coming from the tab link, and 1 or nothing if coming from the checkbox in the form
// if it's coming from the form, check if it's being put on hold and wasn't on hold before (put on hold), or the box wasn't checked and it was on hold before (taken off hold)
// or, if it's coming from the link, check if it's being put on hold and wasn't on hold before (put on hold), or it's being taken off hold and was on hold before
if(($mybb->input['via_form'] == 1 && (($onhold == 1 && $old_onhold == 0) || (!$onhold && $old_onhold == 1))) || (!$mybb->input['via_form'] && (($onhold == 1 && $old_onhold == 0) || ($onhold == -1 && $old_onhold == 1))))
{
if($mybb->settings['enablemysupportonhold'] != 1)
{
mysupport_error($lang->onhold_not_enabled);
exit;
}
if($thread['status'] == 1)
{
mysupport_error($lang->onhold_solved);
exit;
}
if(!mysupport_usergroup("canmarksolved") && !($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))
{
mysupport_error($lang->no_permission_thread_hold);
exit;
}
// we don't need to perform the big check above again, as if we're in here we know it's being changed
// it'll either be 1, 0 or -1, if it's anything other than 1, we're taking it off hold
if($onhold != 1)
{
$ohold = 0;
}
$valid_action = true;
}
if(($mybb->input['via_form'] == 1 && (($issupportthread == 1 && $old_issupportthread == 0) || (!$issupportthread && $old_issupportthread == 1))))
{
if($mybb->settings['enablemysupportnotsupportthread'] != 1)
{
mysupport_error($lang->issupportthread_not_enabled);
exit;
}
if(!mysupport_usergroup("canmarksolved") && !($mybb->settings['mysupportauthor'] == 1 && $thread['uid'] == $mybb->user['uid']))
{
mysupport_error($lang->no_permission_issupportthread);
}
}
// trying to assign a thread to someone
if($assign != 0)
{
if($mybb->settings['enablemysupportassign'] != 1)
{
mysupport_error($lang->assign_not_enabled);
exit;
}
// trying to assign a solved thread
// this is needed to see if we're trying to assign a currently solved thread whilst at the same time changing the status of it
// the option to assign will still be there if it's solved as you may want to unsolve it and assign it again, but we can't assign it if it's staying solved, we have to be unsolving it
if($thread['status'] == 1 && $status != 0)
{
mysupport_error($lang->assign_solved);
exit;
}
if(!mysupport_usergroup("canassign"))
{
mysupport_error($lang->assign_no_perms);
exit;
}
$assign_users = mysupport_get_assign_users();
// -1 is what's used to unassign a thread so we need to exclude that
if(!array_key_exists($assign, $assign_users) && $assign != "-1")
{
mysupport_error($lang->assign_invalid);
exit;
}
$valid_action = true;
}
// setting a priority
if($priority != 0)
{
if($mybb->settings['enablemysupportpriorities'] != 1)
{
mysupport_error($lang->priority_not_enabled);
exit;
}
if(!mysupport_usergroup("cansetpriorities"))
{
mysupport_error($lang->priority_no_perms);
exit;
}
if($thread['status'] == 1 && $status != 0)
{
mysupport_error($lang->priority_solved);
exit;
}
$mysupport_cache = $cache->read("mysupport");
$mids = array();
if(!empty($mysupport_cache['priorities']))
{
foreach($mysupport_cache['priorities'] as $priority_info)
{
$mids[] = intval($priority_info['mid']);
}
}
if(!in_array($priority, $mids) && $priority != "-1")
{
mysupport_error($lang->priority_invalid);
exit;
}
$valid_action = true;
}
// setting a category
if($category != 0)
{
$categories = mysupport_get_categories($forum);
if(!array_key_exists($category, $categories) && $category != "-1")
{
mysupport_error($lang->category_invalid);
exit;
}
$valid_action = true;
}
// it didn't hit an error with any of the above, it's a valid action
if($valid_action !== false)
{
// if you're choosing the same status or choosing none
// and assigning the same user or assigning none (as in the empty option, not choosing 'Nobody' to remove an assignment)
// and setting the same priority or setting none (as in the empty option, not choosing 'None' to remove a priority)
// and setting the same hold status, and setting the same issupportthread status
// then you're not actually doing anything, because you're either choosing the same stuff, or choosing nothing at all
if(($status == $old_status || $status == "-1") && ($assign == $old_assign || $assign == 0) && ($priority == $old_priority || $priority == 0) && ($category == $old_category || $category == 0) && ($onhold == $old_onhold) && ($issupportthread == $old_issupportthread))
{
mysupport_error($lang->error_no_action);
exit;
}
$mod_log_action = "";
$redirect = "";
if($issupportthread != $old_issupportthread)
{
mysupport_change_issupportthread($thread, $issupportthread);
}
else
{
// change the status and move/close
if($status != $old_status && $status != "-1")
{
mysupport_change_status($thread, $status);
}
if($onhold != $old_onhold)
{
mysupport_change_hold($thread, $onhold);
}
// we need to see if the same user has been submitted so it doesn't run this for no reason
// we also need to check if it's being marked as solved, if it is we don't need to do anything with assignments, it'll just be ignored
if($assign != $old_assign && ($assign != 0 && $status != 1 && $status != 3))
{
mysupport_change_assign($thread, $assign);
}
// we need to see if the same priority has been submitted so it doesn't run this for no reason
// we also need to check if it's being marked as solved, if it is we don't need to do anything with priorities, it'll just be ignored
if($priority != $old_priority && ($priority != 0 && $status != 1))
{
mysupport_change_priority($thread, $priority);
}
// we need to see if the same category has been submitted so it doesn't run this for no reason
if($category != $old_category && ($category != 0 && $status != 1))
{
mysupport_change_category($thread, $category);
}
}
if(!empty($mod_log_action))
{
$mod_log_data = array(
"fid" => intval($fid),
"tid" => intval($tid)
);
log_moderator_action($mod_log_data, $mod_log_action);
}
// where should they go to afterwards?
$thread_url = get_thread_link($tid);
redirect($thread_url, $redirect);
}
}
elseif($mybb->input['action'] == "bestanswer")
{
verify_post_check($mybb->input['my_post_key']);
if($mybb->settings['enablemysupportbestanswer'] != 1)
{
mysupport_error($lang->bestanswer_not_enabled);
exit;
}
$pid = intval($mybb->input['pid']);
// we only have a pid so we need to get the tid, fid, uid, and mysupport information of the thread it belongs to
$query = $db->query("
SELECT t.fid, t.tid, t.uid AS author_uid, p.uid AS bestanswer_uid, t.status, t.bestanswer
FROM ".TABLE_PREFIX."threads t
INNER JOIN ".TABLE_PREFIX."forums f
INNER JOIN ".TABLE_PREFIX."posts p
ON (t.tid = p.tid AND t.fid = f.fid AND p.pid = '".$pid."')
");
$post_info = $db->fetch_array($query);
// is this post in a thread that isn't within an allowed forum?
if(!mysupport_forum($post_info['fid']))
{
mysupport_error($lang->bestanswer_invalid_forum);
exit;
}
// did this user author this thread?
elseif($mybb->user['uid'] != $post_info['author_uid'])
{
mysupport_error($lang->bestanswer_not_author);
exit;
}
// is this post already the best answer?
elseif($pid == $post_info['bestanswer'])
{
// this will mark it as the best answer
$status_update = array(
"bestanswer" => 0
);
// update the bestanswer column for this thread with 0
$db->update_query("threads", $status_update, "tid = '".intval($post_info['tid'])."'");
// are we removing points for this?
if(mysupport_points_system_enabled())
{
if(!empty($mybb->settings['mysupportbestanswerpoints']) && $mybb->settings['mysupportbestanswerpoints'] != 0)
{
mysupport_update_points($mybb->settings['mysupportbestanswerpoints'], $post_info['bestanswer_uid'], true);
}