-
Notifications
You must be signed in to change notification settings - Fork 1
/
private.php
2490 lines (2131 loc) · 80.3 KB
/
private.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
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 4.2.0 Patch Level 3 - Licence Number VBFBED0615
|| # ---------------------------------------------------------------- # ||
|| # Copyright �2000-2012 vBulletin Solutions Inc. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('GET_EDIT_TEMPLATES', 'newpm,insertpm,showpm');
define('THIS_SCRIPT', 'private');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
'messaging',
'posting',
'postbit',
'pm',
'reputationlevel',
'user'
);
// get special data templates from the datastore
$specialtemplates = array(
'smiliecache',
'bbcodecache',
'banemail',
'noavatarperms',
);
// pre-cache templates used by all actions
$globaltemplates = array(
'USERCP_SHELL',
'usercp_nav_folderbit'
);
// pre-cache templates used by specific actions
$actiontemplates = array(
'editfolders' => array(
'pm_editfolders',
'pm_editfolderbit',
),
'emptyfolder' => array(
'pm_emptyfolder',
),
'showpm' => array(
'pm_showpm',
'postbit',
'postbit_wrapper',
'postbit_onlinestatus',
'bbcode_code',
'bbcode_html',
'bbcode_php',
'bbcode_quote',
'bbcode_video',
'im_aim',
'im_icq',
'im_msn',
'im_yahoo',
'im_skype',
),
'newpm' => array(
'pm_newpm',
),
'managepm' => array(
'pm_movepm',
),
'trackpm' => array(
'pm_trackpm',
'pm_receipts',
'pm_receiptsbit',
),
'messagelist' => array(
'pm_messagelist',
'pm_messagelist_periodgroup',
'pm_messagelistbit',
'pm_messagelistbit_ignore',
'pm_filter',
'forumdisplay_sortarrow'
),
'report' => array(
'newpost_usernamecode',
'reportitem'
),
'showhistory' => array(
'postbit',
'postbit_wrapper',
'postbit_onlinestatus',
'bbcode_code',
'bbcode_html',
'bbcode_php',
'bbcode_quote',
'bbcode_video',
'im_aim',
'im_icq',
'im_msn',
'im_yahoo',
'im_skype',
'pm_nomessagehistory'
)
);
$actiontemplates['insertpm'] =& $actiontemplates['newpm'];
//Limit the number of folders and the length of title text
$char_limit = 200;
$folder_limit = 1000;
// ################## SETUP PROPER NO DO TEMPLATES #######################
if (empty($_REQUEST['do']))
{
$temppmid = ($temppmid = intval($_REQUEST['pmid'])) < 0 ? 0 : $temppmid;
if ($temppmid > 0)
{
$actiontemplates['none'] =& $actiontemplates['showpm'];
}
else
{
$actiontemplates['none'] =& $actiontemplates['messagelist'];
}
}
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_user.php');
require_once(DIR . '/includes/functions_misc.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
// ###################### Start pm code parse #######################
function parse_pm_bbcode($bbcode, $smilies = true)
{
global $vbulletin;
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser = new vB_BbCodeParser($vbulletin, fetch_tag_list());
return $bbcode_parser->parse($bbcode, 'privatemessage', $smilies);
}
// ###################### Start pm update counters #######################
// update the pm counters for $vbulletin->userinfo
function build_pm_counters()
{
global $vbulletin;
$pmcount = $vbulletin->db->query_first("
SELECT
COUNT(pmid) AS pmtotal,
SUM(IF(messageread = 0 AND folderid >= 0, 1, 0)) AS pmunread
FROM " . TABLE_PREFIX . "pm AS pm
WHERE pm.userid = " . $vbulletin->userinfo['userid'] . "
");
$pmcount['pmtotal'] = intval($pmcount['pmtotal']);
$pmcount['pmunread'] = intval($pmcount['pmunread']);
if ($vbulletin->userinfo['pmtotal'] != $pmcount['pmtotal'] OR $vbulletin->userinfo['pmunread'] != $pmcount['pmunread'])
{
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('pmtotal', $pmcount['pmtotal']);
$userdata->set('pmunread', $pmcount['pmunread']);
$userdata->save();
}
}
// ############################### initialisation ###############################
if (!$vbulletin->options['enablepms'])
{
eval(standard_error(fetch_error('pm_adminoff')));
}
// the following is the check for actions which allow creation of new pms
if ($permissions['pmquota'] < 1 OR !$vbulletin->userinfo['receivepm'])
{
$show['createpms'] = false;
}
// check permission to use private messaging
if (($permissions['pmquota'] < 1 AND (!$vbulletin->userinfo['pmtotal'] OR in_array($_REQUEST['do'], array('insertpm', 'newpm')))) OR !$vbulletin->userinfo['userid'])
{
print_no_permission();
}
if (!$vbulletin->userinfo['receivepm'] AND in_array($_REQUEST['do'], array('insertpm', 'newpm')))
{
eval(standard_error(fetch_error('pm_turnedoff')));
}
// start navbar
$navbits = array(
'usercp.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['user_control_panel'],
'private.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['private_messages']
);
// select correct part of forumjump
$navpopup = array(
'id' => 'pm_navpopup',
'title' => $vbphrase['private_messages'],
'link' => 'private.php' . $vbulletin->session->vars['sessionurl_q'],
);
construct_quick_nav($navpopup);
$onload = '';
$show['trackpm'] = $cantrackpm = $permissions['pmpermissions'] & $vbulletin->bf_ugp_pmpermissions['cantrackpm'];
$includecss = array();
$includeiecss = array();
$vbulletin->input->clean_gpc('r', 'pmid', TYPE_UINT);
// ############################### default do value ###############################
if (empty($_REQUEST['do']))
{
if (!$vbulletin->GPC['pmid'])
{
$_REQUEST['do'] = 'messagelist';
}
else
{
$_REQUEST['do'] = 'showpm';
}
}
($hook = vBulletinHook::fetch_hook('private_start')) ? eval($hook) : false;
// ############################### start update folders ###############################
// update the user's custom pm folders
if ($_POST['do'] == 'updatefolders')
{
$vbulletin->input->clean_gpc('p', 'folder', TYPE_ARRAY_NOHTML);
if (!empty($vbulletin->GPC['folder']))
{
$oldpmfolders = unserialize($vbulletin->userinfo['pmfolders']);
$pmfolders = array();
$updatefolders = array();
$old_count = count($oldpmfolders);
foreach ($vbulletin->GPC['folder'] AS $folderid => $foldername)
{
$folderid = intval($folderid);
if (($foldername != ''))
{
//limit the title to something sane.
$pmfolders["$folderid"] = vbchop($foldername, $char_limit);
}
else if (isset($oldpmfolders["$folderid"]))
{
$updatefolders[] = $folderid;
}
}
$new_count = count($pmfolders);
//its possible, though unlikely, that there is a legitimate user out there
//with too many folders. Rather than preventing them from saving anything,
//we'll just prevent them from adding any folders if they are over the limit
//if they just change some titles or delete some but not enough folders (or
//even delete some and add no more than they deleted) we'll let it slide.
if ($new_count > $folder_limit and $new_count > $old_count)
{
eval(standard_error(fetch_error('folder_limit_exceeded', $folder_limit)));
}
if (!empty($updatefolders))
{
$db->query_write("UPDATE " . TABLE_PREFIX . "pm SET folderid=0 WHERE userid=" . $vbulletin->userinfo['userid'] . " AND folderid IN(" . implode(', ', $updatefolders) . ")");
}
require_once(DIR . '/includes/functions_databuild.php');
if (!empty($pmfolders))
{
natcasesort($pmfolders);
}
build_usertextfields('pmfolders', iif(empty($pmfolders), '', serialize($pmfolders)), $vbulletin->userinfo['userid']);
}
($hook = vBulletinHook::fetch_hook('private_updatefolders')) ? eval($hook) : false;
$itemtype = $vbphrase['private_message'];
$itemtypes = $vbphrase['private_messages'];
print_standard_redirect(array('foldersedited',$itemtype,$itemtypes));
}
// ############################### start empty folders ###############################
if ($_REQUEST['do'] == 'emptyfolder')
{
$vbulletin->input->clean_gpc('r', 'folderid', TYPE_INT);
$folderid = $vbulletin->GPC['folderid'];
// generate navbar
$navbits[''] = $vbphrase['confirm_deletion'];
$pmfolders = array('0' => $vbphrase['inbox'], '-1' => $vbphrase['sent_items']);
if (!empty($vbulletin->userinfo['pmfolders']))
{
$pmfolders = $pmfolders + unserialize($vbulletin->userinfo['pmfolders']);
}
if (!isset($pmfolders["{$vbulletin->GPC['folderid']}"]))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['folder'], $vbulletin->options['contactuslink'])));
}
$folder = $pmfolders["{$vbulletin->GPC['folderid']}"];
$dateline = TIMENOW;
($hook = vBulletinHook::fetch_hook('private_emptyfolder')) ? eval($hook) : false;
$page_templater = vB_Template::create('pm_emptyfolder');
$page_templater->register('dateline', $dateline);
$page_templater->register('folder', $folder);
$page_templater->register('folderid', $folderid);
}
// ############################### start confirm empty folders ###############################
if ($_POST['do'] == 'confirmemptyfolder')
{ // confirmation page
$vbulletin->input->clean_array_gpc('p', array(
'folderid' => TYPE_INT,
'dateline' => TYPE_UNIXTIME,
));
$deletepms = array();
// get pms
$pms = $db->query_read_slave("
SELECT pmid
FROM " . TABLE_PREFIX . "pm AS pm
LEFT JOIN " . TABLE_PREFIX . "pmtext AS pmtext USING (pmtextid)
WHERE folderid = " . $vbulletin->GPC['folderid'] . "
AND userid = " . $vbulletin->userinfo['userid'] . "
AND dateline < " . $vbulletin->GPC['dateline']
);
while ($pm = $db->fetch_array($pms))
{
$deletepms[] = $pm['pmid'];
}
if (!empty($deletepms))
{
// remove pms and receipts!
$db->query_write("DELETE FROM " . TABLE_PREFIX . "pm WHERE pmid IN (" . implode(',', $deletepms) . ")");
$db->query_write("DELETE FROM " . TABLE_PREFIX . "pmreceipt WHERE pmid IN (" . implode(',', $deletepms) . ")");
build_pm_counters();
}
($hook = vBulletinHook::fetch_hook('private_confirmemptyfolder')) ? eval($hook) : false;
$vbulletin->url = 'private.php?' . $vbulletin->session->vars['sessionurl'];
print_standard_redirect('pm_messagesdeleted');
}
// ############################### start edit folders ###############################
// edit the user's custom pm folders
if ($_REQUEST['do'] == 'editfolders')
{
if (!isset($pmfolders))
{
$pmfolders = unserialize($vbulletin->userinfo['pmfolders']);
}
$folderjump = construct_folder_jump();
($hook = vBulletinHook::fetch_hook('private_editfolders_start')) ? eval($hook) : false;
$usedids = array();
$editfolderbits = '';
$show['messagecount'] = true;
if (!empty($pmfolders))
{
$show['customfolders'] = true;
foreach ($pmfolders AS $folderid => $foldername)
{
$usedids[] = $folderid;
$foldertotal = intval($messagecounters["$folderid"]);
($hook = vBulletinHook::fetch_hook('private_editfolders_bit')) ? eval($hook) : false;
$templater = vB_Template::create('pm_editfolderbit');
$templater->register('folderid', $folderid);
$templater->register('foldername', $foldername);
$templater->register('foldertotal', $foldertotal);
$editfolderbits .= $templater->render();
}
}
else
{
$show['customfolders'] = false;
}
$show['messagecount'] = false;
// build the inputs for new folders
//Only if they are allowed to have more folders
if (count($pmfolders) < $folder_limit)
{
$addfolderbits = '';
$donefolders = 0;
$folderid = 0;
$foldername = '';
$foldertotal = 0;
$done = 0;
$max_adds = min(3, ($folder_limit - count($pmfolders)));
while ($done < $max_adds)
{
$folderid ++;
if (in_array($folderid, $usedids))
{
continue;
}
else
{
($hook = vBulletinHook::fetch_hook('private_editfolders_bit')) ? eval($hook) : false;
$done++;
$templater = vB_Template::create('pm_editfolderbit');
$templater->register('folderid', $folderid);
$templater->register('foldername', $foldername);
$templater->register('foldertotal', $foldertotal);
$addfolderbits .= $templater->render();
}
}
}
$inboxtotal = intval($messagecounters[0]);
$sentitemstotal = intval($messagecounters['-1']);
// generate navbar
$navbits[''] = $vbphrase['edit_folders'];
$page_templater = vB_Template::create('pm_editfolders');
//if they have all the allowed folders they don't get an 'add';
if (count($pmfolders) < $folder_limit)
{
$page_templater->register('addfolderbits', $addfolderbits);
$show['ok_to_add'] = 1;
}
else
{
$show['ok_to_add'] = 0;
}
$page_templater->register('editfolderbits', $editfolderbits);
$page_templater->register('inboxtotal', $inboxtotal);
$page_templater->register('sentitemstotal', $sentitemstotal);
}
// ############################### delete pm receipt ###############################
// delete one or more pm receipts
if ($_POST['do'] == 'deletepmreceipt')
{
$vbulletin->input->clean_gpc('p', 'receipt', TYPE_ARRAY_UINT);
if (empty($vbulletin->GPC['receipt']))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['private_message_receipt'], $vbulletin->options['contactuslink'])));
}
($hook = vBulletinHook::fetch_hook('private_deletepmreceipt')) ? eval($hook) : false;
$db->query_write("DELETE FROM " . TABLE_PREFIX . "pmreceipt WHERE userid=" . $vbulletin->userinfo['userid'] . " AND pmid IN(". implode(', ', $vbulletin->GPC['receipt']) . ")");
if ($db->affected_rows() == 0)
{
eval(standard_error(fetch_error('invalidid', $vbphrase['private_message_receipt'], $vbulletin->options['contactuslink'])));
}
else
{
print_standard_redirect('pm_receiptsdeleted');
}
}
// ############################### start deny receipt ###############################
// set a receipt as denied
if ($_REQUEST['do'] == 'dopmreceipt')
{
$vbulletin->input->clean_array_gpc('r', array(
'pmid' => TYPE_UINT,
'confirm' => TYPE_BOOL,
'type' => TYPE_NOHTML,
));
if (!$vbulletin->GPC['confirm'] AND ($permissions['pmpermissions'] & $vbulletin->bf_ugp_pmpermissions['candenypmreceipts']))
{
$receiptSql = "UPDATE " . TABLE_PREFIX . "pmreceipt SET readtime = 0, denied = 1 WHERE touserid = " . $vbulletin->userinfo['userid'] . " AND pmid = " . $vbulletin->GPC['pmid'];
}
else
{
$receiptSql = "UPDATE " . TABLE_PREFIX . "pmreceipt SET readtime = " . TIMENOW . ", denied = 0 WHERE touserid = " . $vbulletin->userinfo['userid'] . " AND pmid = " . $vbulletin->GPC['pmid'];
}
($hook = vBulletinHook::fetch_hook('private_dopmreceipt')) ? eval($hook) : false;
$db->query_write($receiptSql);
if ($vbulletin->GPC['type'] == 'img')
{
header('Content-type: image/gif');
readfile(DIR . '/' . $vbulletin->options['cleargifurl']);
}
else
{
?>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title><?php echo $vbulletin->options['bbtitle']; ?></title><style type="text/css"><?php echo $style['css']; ?></style></head><body>
<script type="text/javascript">
self.close();
</script>
</body></html>
<?php
}
flush();
exit;
}
// ############################### start pm receipt tracking ###############################
// message receipt tracking
if ($_REQUEST['do'] == 'trackpm')
{
if (!$cantrackpm)
{
print_no_permission();
}
$vbulletin->input->clean_array_gpc('r', array(
'pagenumber' => TYPE_UINT,
'type' => TYPE_NOHTML
));
switch ($vbulletin->GPC['type'])
{
case 'confirmed':
case 'unconfirmed':
break;
default:
$vbulletin->GPC['type'] = '';
$vbulletin->GPC['pagenumber'] = 1;
}
$perpage = $vbulletin->options['pmperpage'];
if (!$vbulletin->GPC['pagenumber'])
{
$vbulletin->GPC['pagenumber'] = 1;
}
$startat = ($vbulletin->GPC['pagenumber'] - 1) * $perpage;
($hook = vBulletinHook::fetch_hook('private_trackpm_start')) ? eval($hook) : false;
$confirmedreceipts = '';
if (!$vbulletin->GPC['type'] OR $vbulletin->GPC['type'] == 'confirmed')
{
$pmreceipts = $db->query_read_slave("
SELECT SQL_CALC_FOUND_ROWS
pmreceipt.*, pmreceipt.pmid AS receiptid
FROM " . TABLE_PREFIX . "pmreceipt AS pmreceipt
WHERE pmreceipt.userid = " . $vbulletin->userinfo['userid'] . "
AND pmreceipt.readtime <> 0
ORDER BY pmreceipt.sendtime DESC
LIMIT $startat, $perpage
");
list($readtotal) = $db->query_first_slave("SELECT FOUND_ROWS()", DBARRAY_NUM);
$counter = 1;
if ($readtotal)
{
$show['readpm'] = true;
$tabletitle = $vbphrase['confirmed_private_message_receipts'];
$tableid = 'pmreceipts_read';
$collapseobj_tableid =& $vbcollapse["collapseobj_$tableid"];
$collapseimg_tableid =& $vbcollapse["collapseimg_$tableid"];
$receiptbits = '';
while ($receipt = $db->fetch_array($pmreceipts))
{
$receipt['send_date'] = vbdate($vbulletin->options['dateformat'], $receipt['sendtime'], true);
$receipt['send_time'] = vbdate($vbulletin->options['timeformat'], $receipt['sendtime']);
$receipt['read_date'] = vbdate($vbulletin->options['dateformat'], $receipt['readtime'], true);
$receipt['read_time'] = vbdate($vbulletin->options['timeformat'], $receipt['readtime']);
$receiptinfo = array(
'userid' => $receipt['touserid'],
'username' => $receipt['tousername'],
);
($hook = vBulletinHook::fetch_hook('private_trackpm_receiptbit')) ? eval($hook) : false;
$templater = vB_Template::create('pm_receiptsbit');
$templater->register('receipt', $receipt);
$receiptbits .= $templater->render();
}
$confirmed_pagenav = construct_page_nav($vbulletin->GPC['pagenumber'], $perpage, $readtotal,
"private.php?" . $vbulletin->session->vars['sessionurl'] . "do=trackpm&type=confirmed"
);
$templater = vB_Template::create('pm_receipts');
$templater->register('collapseimg_tableid', $collapseimg_tableid);
$templater->register('collapseobj_tableid', $collapseobj_tableid);
$templater->register('startreceipt', vb_number_format($startat + 1));
$templater->register('endreceipt', vb_number_format(($vbulletin->GPC['pagenumber'] * $perpage) > $readtotal ? $readtotal : ($vbulletin->GPC['pagenumber'] * $perpage)));
$templater->register('numreceipts', vb_number_format($readtotal));
$templater->register('receiptbits', $receiptbits);
$templater->register('tableid', $tableid);
$templater->register('tabletitle', $tabletitle);
$templater->register('counter', $counter++);
$confirmedreceipts = $templater->render();
}
}
$unconfirmedreceipts = '';
if (!$vbulletin->GPC['type'] OR $vbulletin->GPC['type'] == 'unconfirmed')
{
$pmreceipts = $db->query_read_slave("
SELECT SQL_CALC_FOUND_ROWS
pmreceipt.*, pmreceipt.pmid AS receiptid
FROM " . TABLE_PREFIX . "pmreceipt AS pmreceipt
WHERE pmreceipt.userid = " . $vbulletin->userinfo['userid'] . "
AND pmreceipt.readtime = 0
ORDER BY pmreceipt.sendtime DESC
LIMIT $startat, $perpage
");
list($unreadtotal) = $db->query_first_slave("SELECT FOUND_ROWS()", DBARRAY_NUM);
if ($unreadtotal)
{
$show['readpm'] = false;
$tabletitle = $vbphrase['unconfirmed_private_message_receipts'];
$tableid = 'pmreceipts_unread';
$collapseobj_tableid =& $vbcollapse["collapseobj_$tableid"];
$collapseimg_tableid =& $vbcollapse["collapseimg_$tableid"];
$receiptbits = '';
while ($receipt = $db->fetch_array($pmreceipts))
{
$receipt['send_date'] = vbdate($vbulletin->options['dateformat'], $receipt['sendtime'], true);
$receipt['send_time'] = vbdate($vbulletin->options['timeformat'], $receipt['sendtime']);
$receipt['read_date'] = vbdate($vbulletin->options['dateformat'], $receipt['readtime'], true);
$receipt['read_time'] = vbdate($vbulletin->options['timeformat'], $receipt['readtime']);
$receiptinfo = array(
'userid' => $receipt['touserid'],
'username' => $receipt['tousername'],
);
($hook = vBulletinHook::fetch_hook('private_trackpm_receiptbit')) ? eval($hook) : false;
$templater = vB_Template::create('pm_receiptsbit');
$templater->register('receipt', $receipt);
$receiptbits .= $templater->render();
}
$unconfirmed_pagenav = construct_page_nav($vbulletin->GPC['pagenumber'], $perpage, $unreadtotal,
"private.php?" . $vbulletin->session->vars['sessionurl'] . "do=trackpm&type=unconfirmed"
);
$templater = vB_Template::create('pm_receipts');
$templater->register('collapseimg_tableid', $collapseimg_tableid);
$templater->register('collapseobj_tableid', $collapseobj_tableid);
$templater->register('startreceipt', vb_number_format($startat + 1));
$templater->register('endreceipt', vb_number_format(($vbulletin->GPC['pagenumber'] * $perpage) > $unreadtotal ? $unreadtotal : ($vbulletin->GPC['pagenumber'] * $perpage)));
$templater->register('numreceipts', vb_number_format($unreadtotal));
$templater->register('receiptbits', $receiptbits);
$templater->register('tableid', $tableid);
$templater->register('tabletitle', $tabletitle);
$templater->register('counter', $counter);
$unconfirmedreceipts = $templater->render();
}
}
$folderjump = construct_folder_jump();
// generate navbar
$navbits[''] = $vbphrase['message_tracking'];
$show['receipts'] = ($confirmedreceipts != '' OR $unconfirmedreceipts != '');
$page_templater = vB_Template::create('pm_trackpm');
$page_templater->register('confirmedreceipts', $confirmedreceipts);
$page_templater->register('confirmed_pagenav', $confirmed_pagenav);
$page_templater->register('unconfirmedreceipts', $unconfirmedreceipts);
$page_templater->register('unconfirmed_pagenav', $unconfirmed_pagenav);
}
// ############################### start move pms ###############################
if ($_POST['do'] == 'movepm')
{
$vbulletin->input->clean_array_gpc('p', array(
'folderid' => TYPE_INT,
'messageids' => TYPE_STR,
));
$vbulletin->GPC['messageids'] = @unserialize(verify_client_string($vbulletin->GPC['messageids']));
if (!is_array($vbulletin->GPC['messageids']) OR empty($vbulletin->GPC['messageids']))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['private_message'], $vbulletin->options['contactuslink'])));
}
$pmids = array();
foreach ($vbulletin->GPC['messageids'] AS $pmid)
{
$id = intval($pmid);
$pmids["$id"] = $id;
}
($hook = vBulletinHook::fetch_hook('private_movepm')) ? eval($hook) : false;
$db->query_write("UPDATE " . TABLE_PREFIX . "pm SET folderid=" . $vbulletin->GPC['folderid'] . " WHERE userid=" . $vbulletin->userinfo['userid'] . " AND folderid<>-1 AND pmid IN(" . implode(', ', $pmids) . ")");
$vbulletin->url = 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'];
// deselect messages
setcookie('vbulletin_inlinepm', '', TIMENOW - 3600, '/');
print_standard_redirect('pm_messagesmoved');
}
// ############################### start pm manager ###############################
// actions for moving pms between folders, and deleting pms
if ($_POST['do'] == 'managepm')
{
$vbulletin->input->clean_array_gpc('p', array(
'folderid' => TYPE_INT,
'dowhat' => TYPE_NOHTML,
'pm' => TYPE_ARRAY_UINT,
));
// get cookie
$vbulletin->input->clean_array_gpc('c', array(
'vbulletin_inlinepm' => TYPE_STR,
));
// get selected via post
$messageids = array();
foreach (array_keys($vbulletin->GPC['pm']) AS $pmid)
{
$pmid = intval($pmid);
$messageids["$pmid"] = $pmid;
}
unset($pmid);
// get selected via cookie
if (!empty($vbulletin->GPC['vbulletin_inlinepm']))
{
$cookielist = explode('-', $vbulletin->GPC['vbulletin_inlinepm']);
$cookielist = $vbulletin->input->clean($cookielist, TYPE_ARRAY_UINT);
$messageids = array_unique(array_merge($messageids, $cookielist));
}
// check that we have an array to work with
if (empty($messageids))
{
eval(standard_error(fetch_error('no_private_messages_selected')));
}
($hook = vBulletinHook::fetch_hook('private_managepm_start')) ? eval($hook) : false;
// now switch the $dowhat...
switch($vbulletin->GPC['dowhat'])
{
// *****************************
// deselect all messages
case 'clear':
setcookie('vbulletin_inlinepm', '', TIMENOW - 3600, '/');
print_standard_redirect('pm_allmessagesdeselected');
break;
// *****************************
// move messages to a new folder
case 'move':
$totalmessages = sizeof($messageids);
$messageids = sign_client_string(serialize($messageids));
$folderoptions = construct_folder_jump(0, 0, array($vbulletin->GPC['folderid'], -1));
switch ($vbulletin->GPC['folderid'])
{
case -1:
$fromfolder = $vbphrase['sent_items'];
break;
case 0:
$fromfolder = $vbphrase['inbox'];
break;
default:
{
$folders = unserialize($vbulletin->userinfo['pmfolders']);
$fromfolder = $folders["{$vbulletin->GPC['folderid']}"];
}
}
($hook = vBulletinHook::fetch_hook('private_managepm_move')) ? eval($hook) : false;
if ($folderoptions)
{
$page_templater = vB_Template::create('pm_movepm');
$page_templater->register('folderoptions', $folderoptions);
$page_templater->register('fromfolder', $fromfolder);
$page_templater->register('messageids', $messageids);
$page_templater->register('totalmessages', $totalmessages);
}
else
{
eval(standard_error(fetch_error('pm_nofolders', $vbulletin->options['bburl'], $vbulletin->session->vars['sessionurl'])));
}
break;
// *****************************
// mark messages as unread
case 'unread':
$db->query_write("UPDATE " . TABLE_PREFIX . "pm SET messageread=0 WHERE userid=" . $vbulletin->userinfo['userid'] . " AND pmid IN (" . implode(', ', $messageids) . ")");
build_pm_counters();
$readunread = $vbphrase['unread_date'];
($hook = vBulletinHook::fetch_hook('private_managepm_unread')) ? eval($hook) : false;
// deselect messages
setcookie('vbulletin_inlinepm', '', TIMENOW - 3600, '/');
print_standard_redirect(array('pm_messagesmarkedas',$readunread));
break;
// *****************************
// mark messages as read
case 'read':
$db->query_write("UPDATE " . TABLE_PREFIX . "pm SET messageread=1 WHERE messageread=0 AND userid=" . $vbulletin->userinfo['userid'] . " AND pmid IN (" . implode(', ', $messageids) . ")");
build_pm_counters();
$readunread = $vbphrase['read'];
($hook = vBulletinHook::fetch_hook('private_managepm_read')) ? eval($hook) : false;
// deselect messages
setcookie('vbulletin_inlinepm', '', TIMENOW - 3600, '/');
print_standard_redirect(array('pm_messagesmarkedas',$readunread));
break;
// *****************************
// download as XML
case 'xml':
$_REQUEST['do'] = 'downloadpm';
break;
// *****************************
// download as CSV
case 'csv':
$_REQUEST['do'] = 'downloadpm';
break;
// *****************************
// download as TEXT
case 'txt':
$_REQUEST['do'] = 'downloadpm';
break;
// *****************************
// delete messages completely
case 'delete':
$pmids = array();
$textids = array();
// get the pmid and pmtext id of messages to be deleted
$pms = $db->query_read_slave("
SELECT pmid
FROM " . TABLE_PREFIX . "pm
WHERE userid = " . $vbulletin->userinfo['userid'] . "
AND pmid IN(" . implode(', ', $messageids) . ")
");
// check to see that we still have some ids to work with
if ($db->num_rows($pms) == 0)
{
eval(standard_error(fetch_error('invalidid', $vbphrase['private_message'], $vbulletin->options['contactuslink'])));
}
// build the final array of pmids to work with
while ($pm = $db->fetch_array($pms))
{
$pmids[] = $pm['pmid'];
}
// delete from the pm table using the results from above
$deletePmSql = "DELETE FROM " . TABLE_PREFIX . "pm WHERE pmid IN(" . implode(', ', $pmids) . ")";
$db->query_write($deletePmSql);
// deselect messages
setcookie('vbulletin_inlinepm', '', TIMENOW - 3600, '/');
build_pm_counters();
($hook = vBulletinHook::fetch_hook('private_managepm_delete')) ? eval($hook) : false;
// all done, redirect...
$vbulletin->url = 'private.php?' . $vbulletin->session->vars['sessionurl'] . 'folderid=' . $vbulletin->GPC['folderid'];
print_standard_redirect('pm_messagesdeleted');
break;
// *****************************
// unknown action specified
default:
$handled_do = false;
($hook = vBulletinHook::fetch_hook('private_managepm_action_switch')) ? eval($hook) : false;
if (!$handled_do)
{
eval(standard_error(fetch_error('invalidid', $vbphrase['action'], $vbulletin->options['contactuslink'])));
}
break;
}
}
// ############################### start download pm ###############################
// downloads selected private messages to a file type of user's choice
if ($_REQUEST['do'] == 'downloadpm')
{
if (($current_memory_limit = ini_size_to_bytes(@ini_get('memory_limit'))) < 128 * 1024 * 1024 AND $current_memory_limit > 0)
{
@ini_set('memory_limit', 128 * 1024 * 1024);
}
$vbulletin->input->clean_gpc('r', 'dowhat', TYPE_NOHTML);
require_once(DIR . '/includes/functions_file.php');
function fetch_touser_string($pm)
{
global $vbulletin;
$cclist = array();
$bcclist = array();
$ccrecipients = '';
$touser = unserialize($pm['touser']);
foreach($touser AS $key => $item)
{
if (is_array($item))
{
foreach($item AS $subkey => $subitem)
{
$username = $subitem;
$userid = $subkey;
if ($key == 'bcc')
{
$bcclist[] = $username;
}
else
{
$cclist[] = $username;
}
}
}
else
{
$username = $item;
$userid = $key;
$cclist[] = $username;
}
}
if (!empty($cclist))
{
$ccrecipients = implode("\r\n", $cclist);
}
if ($pm['folder'] == -1)
{
if (!empty($bcclist))
{
$ccrecipients = implode("\r\n", array_unique(array_merge($cclist, $bcclist)));
}
}
else
{
$ccrecipients = implode("\r\n", array_unique(array_merge($cclist, array("{$vbulletin->userinfo['username']}"))));
}
return $ccrecipients;
}
// set sql condition for selected messages
if (is_array($messageids))
{
$sql = 'AND pm.pmid IN(' . implode(', ', $messageids) . ')';
}
// set blank sql condition (get all user's messages)
else
{
$sql = '';
}
// query the specified messages
$pms = $db->query_read_slave("