-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathws.php
More file actions
1850 lines (1616 loc) · 68.8 KB
/
ws.php
File metadata and controls
1850 lines (1616 loc) · 68.8 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
$ws_version = "2.1.2f";
#
# Version 2.1.2, 8th September 2007, Removed resize_jpg as Fred moved it to functions.php
# Version 2.1.1, 27th May 2007, Added 2 new parameters for sig strips.
# 'start' which controls where to start from
# So, instead of listing the first 10 for example
# if start is set to 20, it will display from the 20th
# which is useful it you want to position multiple things
# on your web page. Also, 'type' which defaults to 'watched'
# which is the normal sig strip. But if 'type' is set to 'new'
# it will show the most recent additions to your owned collection
# (by purchase date) as we don't know when you added it.
# Put back SetShadow as that was removed in error. But
# removed AdjBackgroundImage as that's what is not GD2 compatible.
# Fixed the fact I was including jpgraph stuff even if $usejpgraph
# was set to false.
# Version 2.1.0, 26th May 2007, Fixed ws.php not using the format.css.php
# Fixed resetting rows for sig strips
# Fixed exiting correctly when doing static images
# Fixed handling if nothing is watched
# Removed SetShadow from fonts as not compatible with GD2.0
# Added code to clean imagecachedir if its being used
# Version 2.0.9, 13th April 2007, Added ability to have multiple rows in signature strips
# Fixed scaling of images if they aren't normal sizes
# Version 2.0.8, 6th April 2007, Some fixes Fred put in for image handling.
# Added some code for calling ws.php action=update
# when called from incupdate.php.
# Added some code to better handle when the putenv fails.
# Fixed review discs but calling FixAReviewValue
# Version 2.0.7, 25th February 2007, Replaced $img_physpath with $img_webpath
# Version 2.0.6, 6th December 2006, Added date formating to sig config.
# Fixed problem with 'Watched' & 'watched' instead of '$watched'
# Added #MOTD_RAND# and #MOTD_X# for top/bot message to handle
# message of the day.
# Make sig strips get built at update time
# Added WS_SELF to url names.
# Added action=phpinfo to report phpinfo
# Fixed the fact I wasn't making $user web safe (so it could
# have spaces in.
# Added $ws_borrowed_is_watched so people that borrow, count as watched
# Version 2.0.5, 9th September 2006, Added option to expand a user automatically. And year and month.
# Added 'info' option to report version.
# Version 2.0.4, 8th September 2006, Has extra code for configuring all the 'me' stuff.
# Version 2.0.3, 7th August 2006. Yet again fixed problems with ' and ". Hopefully for
# the last time.
# Version 2.0.2, 6th August 2006. Fixed problem with ' in title in the detail list.
# Changed graph scaling.
# Version 2.0.1, 11th July 2006. Fixed multiple thumbnails bug in 'best' and 'worst'
# like the 'last' thumbnails had.
# Fixed problem with ' getting changed to \\' in the T_TITLE.
# Version 2.0.0, 4rd July 2006. Added the DISTINICT back to fix the problem.
# Added sort to mouseover events.
# Fixed last thumbnail list. Removed 'DISTINICT' and 'GROUP BY'.
# See all the stuff below.
# Version 1.9.9, 1st July 2006. Fixed handling of missing image in my_watched().
# Don't display months where nothing was watched.
# Fixed colspan when changing $maxthumbs.
# Fixed various link building issues.
# Added some scaling to the graphs.
# Version 1.9.8, 30th June 2006. Added reviewfilm to mouseover if it's present.
# Fixed line2 spacing.
# Fixed bug with resetting last/most/best/worst when selecting a
# different person/year/month.
# Fixed duplicate thumb on last if watched by multiple users.
# Changed resize_jpg to check if image exists and return unknown.jpg
# and also returns thumb of main image if requested size is larger than
# the width of the thumbnail.
# Version 1.9.7, 29th June 2006. Fixed tooltop on images displaying the 'alt' text in buggy browsers.
# Added js navigation to select last/most/best/worst.
# Fixed rouge <table> tag
# Version 1.9.6, 28th June 2006. Added best/worst list.
# Added toggles to last/most/best/worst and setup defaults.
# Moved $me handling to its own function so I can hack it later.
# Version 1.9.5, 27th June 2006. Fixed image resizing, so it didn't change the
# image height and therefore just let the browser
# scale it correctly.
# Removed the </img> and put just / before closing >
# Changed title to use $lang['WATCHED'].
# Moved label to be a subheadings for last/most watched.
# Added mouseover to last/most watched to popup info about watched
# but without the image as we already have it.
# Added tiny thumbnail caching. Thanks Cal for sample code
# although my version is done via returning the filename rather
# than returning the actual image.
# Version 1.9.4, 27th June 2006. Added last and most watched thumbnails
# Version 1.9.3. 26th June 2006. More enhancements. Mouseover graphs for
# watcher, year and month.
# Added globals to control mouseovers.
# $ws_watcher, $ws_year, $ws_month & $ws_title
# Added sorting by title, running time & timestamp
# Version 1.9.2. 25th June 2006. Yet another fix for no last name.
# Version 1.9.1. 25th June 2006. Fix for no last name and double quotes in titles
# in the mouseover.
# Version 1.9.0. 24th June 2006. Total Re-write for multiuser support.
#
# To Do
# -----
# 1. Multiple expanded people/years/months for ya_shin
# 2. *DONE* Well sort of. Obey's handlewatched now at least.
# Remove IN_SCRIPT but still have my_watched() working without it.
# 3. DONE. Change array handling from $row[0] to $row['xxxx']
# 4. DONE. Check the globals for graphs
# 5. DONE. Enhance thumbcache to also check for no image and also use full image if thumb is missing
# 6. DONE. Remove double line2.
# 7. DONE. Add indicator to nav window for enable/disable.
# 8. DONE. Add code to delete mysql return info
# 9. Change watched() function to not do all 4 in the code, but take an argument of
# what line to do.
#10. Tidy $sql variables.
#11. DONE. Fix bug where if you have changed what last/most/best/worst is displayed and then click
# a new person/year/month, it goes back to defaults for last/most/best/worst.
#12. DONE. Check what happens with images don't exist for all the mouseovers.
#13. DONE. Test default sort orders.
#14. Change link building code so it's just a function. Saves changing it everywhere.
#15. Change the limit for $maxthumbs so that it works out the max based upon window width (for ws not me routine).
if (!defined('IN_SCRIPT'))
define('IN_SCRIPT', 1);
include_once('global.php');
$WS_SELF = 'ws.php';
global $ClassColors;
$ColScheme = "this.T_BGCOLOR='$ClassColor[2]';this.T_TITLECOLOR='$ClassColor[17]';this.T_BORDERCOLOR='$ClassColor[5]'";
if (!isset($me)) $me='';
if (!isset($action)) $action = '';
if (!isset($watched)) $watched = 'Watched';
if (!isset($borrowed)) $borrowed = 'Borrowed';
if (!isset($searchby)) $searchby = '';
if (!isset($searchtext)) $searchtext = '';
if ($searchtext == '') $searchby = '';
$ws_wb = "(eventtype='$watched'";
if (isset($ws_borrowed_is_watched) && $ws_borrowed_is_watched)
$ws_wb .= "OR eventtype='$borrowed'";
$ws_wb .= ')';
if (($handlewatched == 2) || (($handlewatched == 1) && !$IsPrivate)) {
if (!$me && !$action) {
die('This script should not be manually executed ... Possible Hacking attempt');
}
}
if ($action == 'phpinfo') {
phpinfo();
exit;
}
if ($action == 'info') {
echo "ws:Version=$ws_version";
exit;
}
if ($action == 'update') {
if (isset($profiles) && isset($imagecachedir) && is_dir($imagecachedir) && is_writeable($imagecachedir)) {
echo "{$lang['WS']['STATIC']}:";
foreach($profiles as $profilename => $profiledata) {
my_watched($profilename);
echo " $profilename";
}
echo ". {$lang['WS']['DONE']}$eoln";
# Tidy the imagecache
$ct = time();
$minus30 = $ct - (30 * 24*60*60);
$removed = 0;
$dir = @opendir($imagecachedir);
if ($dir) {
echo "{$lang['WS']['CLEAN']}:";
while ($entry = readdir($dir)) {
if ($entry != '..' && $entry != '.' && $entry != 'index.html' && $entry != 'index.htm') {
// $lm = filemtime($imagecachedir . $entry);
// I think we want to cache most frequently used images, and I think that using filemtime()
// causes us to cache most frequently *changed* files. fileatime() should tell us the most
// frequently *accessed* files ... now, if atime updates are turned off (UNiX) or not supported (FAT)
// then I expect that the ctime() is returned.
$lm = fileatime($imagecachedir . $entry);
if ($lm < $minus30) {
$ret = @unlink($imagecachedir . $entry);
}
}
}
echo " {$lang['WS']['DONE']}$eoln";
}
# end of tidy
}
}
if ($action == 'profiles' && isset($profiles)) {
echo 'Profile info<br>';
foreach($profiles as $profilename => $profiledata) {
echo "profile name is $profilename<br>";
foreach($profiles[$profilename] as $key => $value) {
printf(' Key %-10s - Value %s<br>', $key, $value);
}
}
echo 'End of profiles.<br>';
exit;
}
if ($me) {
my_watched($me);
exit;
}
# Oh this is cheap, but it should work for now!
if ($action <> 'update') {
if ($usejpgraph) {
include_once($jpgraphlocation.'jpgraph.php');
include_once($jpgraphlocation.'jpgraph_bar.php');
}
if (isset($graph)) {
do_graph();
exit;
}
if (!isset($ws_watcher)) $ws_watcher = 1;
if (!isset($ws_year)) $ws_year = 1;
if (!isset($ws_month)) $ws_month = 1;
if (!isset($ws_title)) $ws_title = 1;
$sort = '';
$order = '';
$yeartext = '';
$monthtext = '';
$numcols=6;
$uclass = '';
$yclass = '';
$mclass = '';
if (isset($user) && $user)
$yeartext = $lang['WS']['YEAR'];
if (isset($year) && $year)
$monthtext = $lang['WS']['MONTH'];
if (!isset($user)) $user = '';
if (!isset($year)) $year = '';
if (!isset($month)) $month = '';
$lasturl = $mosturl = $besturl = $worsturl = '';
if (!isset($lastlist)) $lastlist=1;
if (!isset($mostlist)) $mostlist=1;
if (!isset($bestlist)) $bestlist=1;
if (!isset($worstlist)) $worstlist=1;
if (!isset($dolast)) $dolast=$lastlist;
if (!isset($domost)) $domost=$mostlist;
if (!isset($dobest)) $dobest=$bestlist;
if (!isset($doworst)) $doworst=$worstlist;
$uuser = rawurlencode($user);
# This code requires changing once I allow multiple expanded items.
if (isset($expand_user[0]) && $user == '') {
$user = $expand_user[0];
}
if (isset($expand_year[0]) && $year == '') {
# Don't care what user, if you've asked for a year to be expanded.
if ($expand_year[0] > 0)
$year = $expand_year[0];
elseif ($expand_year[0] < 0)
$year = date('Y',time());
}
if (isset($expand_month[0]) && $month == '') {
# Only expand months, if we've asked for years to be expanded.
# and it's the year requested.
if (isset($expand_year[0]) && $expand_year[0] <> 0) {
if ($expand_year[0] == $year || ($expand_year[0] == -1 && $year == date('Y', time()))) {
if ($expand_month[0] > 0)
$month = $expand_month[0];
elseif ($expand_month[0] < 0)
$month = date('m',time());
}
}
}
# Control whether the 'menu' item gets displayed on nav panel
# Only do it, if there is something to display
$dooptions = 0;
if ($lastlist<>2 || $mostlist<>2 || $bestlist<>2 || $worstlist<>2) $dooptions=1;
# Setup urls for the links
$nextlast=($dolast==1)?0:1;
$lasturl="$WS_SELF?user=$uuser&year=$year&month=$month&dolast=$nextlast&domost=$domost&dobest=$dobest&doworst=$doworst&sort=$sort&order=$order";
$nextmost=($domost==1)?0:1;
$mosturl="$WS_SELF?user=$uuser&year=$year&month=$month&dolast=$dolast&domost=$nextmost&dobest=$dobest&doworst=$doworst&sort=$sort&order=$order";
$nextbest=($dobest==1)?0:1;
$besturl="$WS_SELF?user=$uuser&year=$year&month=$month&dolast=$dolast&domost=$domost&dobest=$nextbest&doworst=$doworst&sort=$sort&order=$order";
$nextworst=($doworst==1)?0:1;
$worsturl="$WS_SELF?user=$uuser&year=$year&month=$month&dolast=$dolast&domost=$domost&dobest=$dobest&doworst=$nextworst&sort=$sort&order=$order";
header('Content-Type: text/html; charset="windows-1252";');
echo<<<EOT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="./format.css.php"></link>
<title>{$lang['WS']['TITLE']}</title>
<SCRIPT type="text/javascript" SRC="mom.js" language="JavaScript1.2"></SCRIPT>
<SCRIPT type="text/javascript" SRC="momItems.js.php" language="JavaScript1.2"></SCRIPT>
<script type="text/javascript">
<!--
var num=0;
EOT;
if ($dooptions) {
echo<<<EOT
momItems[num++]=["$lang[MENU]"]
EOT;
}
if ($lastlist<>2) {
$sh = ($dolast==1)? $lang['WS']['HIDE']: $lang['WS']['SHOW'];
$sh .= ' ' . $lang['WS']['LAST'];
echo<<<EOT
momItems[num++]=["$sh", "$lasturl", "entry"]
EOT;
}
if ($mostlist<>2) {
$sh = ($domost==1)? $lang['WS']['HIDE']: $lang['WS']['SHOW'];
$sh .= ' ' . $lang['WS']['MOST'];
echo<<<EOT
momItems[num++]=["$sh", "$mosturl", "entry"]
EOT;
}
if ($bestlist<>2) {
$sh = ($dobest==1)? $lang['WS']['HIDE']: $lang['WS']['SHOW'];
$sh .= ' ' . $lang['WS']['BEST'];
echo<<<EOT
momItems[num++]=["$sh", "$besturl", "entry"]
EOT;
}
if ($worstlist<>2) {
$sh = ($doworst==1)? $lang['WS']['HIDE']: $lang['WS']['SHOW'];
$sh .= ' ' . $lang['WS']['WORST'];
echo<<<EOT
momItems[num++]=["$sh", "$worsturl", "entry"]
EOT;
}
// I've created a landing page on bws.com for the about. it links back to the pages on dvdaholic.
$vver = preg_replace('/\./', '_', $ws_version);
$vlink = "http://www.bws.com/phpdvdprofiler/ws_version_$vver.html";
#$vlink = "http://www.dvdaholic.me.uk/phpdvdprofiler/ws_version_$vver.html";
#$vlink = "http://didi/dvd/ws_version_$vver.html";
echo<<<EOT
momItems[num++]=["{$lang['WS']['INFO']}"]
momItems[num++]=["DVD Profiler", "http://www.invelos.com", "_blank"]
momItems[num++]=["$lang[ANDYFORUM]", "http://www.dvdaholic.me.uk/forums/", "_blank"]
momItems[num++]=["{$lang['WS']['ABOUT']}", "javascript:; \" onClick=\" window.open('{$vlink}','About','toolbar=no, width=670, height=400, resizable=yes, scrollbars=yes, status=yes'); return true;", ""]
MOMbilden();
//-->
</SCRIPT>
</head>
<body>
<center>
<table width="100%" cellpadding=0 cellspacing=0>
<tr class=f1>
<td colspan=$numcols>{$lang['WS']['HEADING']}</td>
</tr>
EOT;
watched();
echo<<<EOT
<tr><td class=line2 colspan=$numcols></td></tr>
<tr class=t align=center>
<td width="15%"></td>
<td width="5%"></td>
<td width="5%"></td>
<td width="25%" align=right>{$lang['WS']['TOTRUN']}</td>
<td width="25%"></td>
<td width="25%">{$lang['WS']['AVERUNT']}</td>
</tr>
<tr class=t align=center>
<td width="15%" align=center>{$lang['WS']['VIEWER']}</td>
<td width="5">$yeartext</td>
<td width="5%">$monthtext</td>
<td width="25%" align=right>{$lang['WS']['DHM']}</td>
<td width="25%">{$lang['WS']['NOTITLES']}</td>
<td width="25%">{$lang['WS']['AVERUNB']}</td>
</tr>
EOT;
$line = 0;
#find watchers
get_watchers();
# Check numusers. If its 0 nothing has been watched
$cmd = "SELECT SUM(1) AS count, SUM(runningtime) AS runningtime FROM $DVD_EVENTS_TABLE LEFT JOIN $DVD_TABLE ON $DVD_EVENTS_TABLE.id=$DVD_TABLE.id WHERE $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY eventtype";
$sql = $db->sql_query($cmd) or die($db->sql_error());
$rt = 0;
$cnt = 0;
$row = $db->sql_fetch_array($sql);
$cnt = $row['count'];
$rt = $row['runningtime'];
$avg = 0;
if ($cnt <> 0) $avg = intval($rt / $cnt);
$db->sql_freeresult($sql);
$days = floor($rt / 1440);
$hours = floor(($rt - ($days * 1440)) / 60);
$mins = $rt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
if ($cnt == 0) {
echo<<<EOT
<tr class=line><td colspan=$numcols></td></tr>
<tr class=f1><td align=center colspan=$numcols>You may own lots of DVDs, but have you ever thought of watching them!</td></tr>
EOT;
}
echo<<<EOT
<tr class=line><td colspan=$numcols></td></tr>
<tr class=t align=center>
<td colspan=3 width="25%">{$lang['WS']['TOTAL']}</td>
<td width="25%" align=right>$dhm</td>
<td width="25%">$cnt</td>
<td width="25%">$avg</td>
</tr>
EOT;
$cmd = "SELECT DISTINCT $DVD_EVENTS_TABLE.id, runningtime FROM $DVD_EVENTS_TABLE LEFT JOIN $DVD_TABLE ON $DVD_EVENTS_TABLE.id=$DVD_TABLE.id WHERE $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$sql = $db->sql_query($cmd) or die($db->sql_error());
$rt = 0;
$cnt = 0;
while ($row = $db->sql_fetch_array($sql)) {
$rt += $row['runningtime'];
$cnt++;
}
$avg = 0;
if ($cnt <> 0) $avg = intval($rt / $cnt);
$db->sql_freeresult($sql);
$days = floor($rt / 1440);
$hours = floor(($rt - ($days * 1440)) / 60);
$mins = $rt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
echo<<<EOT
<tr class=t align=center>
<td colspan=3 width="25%">{$lang['WS']['UNIQUEW']}</td>
<td width="25%" align=right>$dhm</td>
<td width="25%">$cnt</td>
<td width="25%">$avg</td>
</tr>
</table>
</center>
<script language="JavaScript" type="text/javascript" src="wz_tooltip.js"></script>
</body>
EOT;
$db->sql_freeresult($sql);
#exit;
}
function get_watchers() {
global $db, $DVD_TABLE, $DVD_EVENTS_TABLE, $DVD_USERS_TABLE, $lang, $watched, $user, $year, $line, $handleadult, $IsPrivate, $numcols;
global $uclass, $ws_watcher, $usejpgraph, $dolast, $domost, $dobest, $doworst, $ignore_list, $WS_SELF, $ws_wb, $ColScheme;
$uline = 0;
$cmd = "SELECT u.uid,firstname,lastname FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e, $DVD_USERS_TABLE u WHERE e.id=d.id AND e.uid=u.uid AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY lastname, firstname";
$sql = $db->sql_query($cmd) or die($db->sql_error());
$numusers = $db->sql_numrows($sql);
while ($row = $db->sql_fetch_array($sql)) {
$ignore = false;
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$uid = $row['uid'];
$name = $firstname . ' ' . $lastname;
$n1 = preg_replace("/ /", "", $name);
if (isset($ignore_list)) {
foreach($ignore_list as $iuser) {
$u1 = preg_replace("/ /", "", $iuser);
if ($u1 == $n1)
$ignore = true;
}
}
if (!$ignore) {
$cmd = "SELECT SUBSTRING(timestamp,1,4) as year, SUM(1) AS count FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.uid=$uid AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY year";
$sql1a = $db->sql_query($cmd) or die($db->sql_error());
$numyears = $db->sql_numrows($sql1a);
$row = $db->sql_fetch_array($sql1a);
$cmd = "SELECT SUM(1) AS count, SUM(runningtime) AS runningtime FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id = d.id AND e.uid=$uid AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY eventtype";
$sql1 = $db->sql_query($cmd) or die($db->sql_error());
$rt = 0;
$cnt = 0;
$row = $db->sql_fetch_array($sql1);
$tcnt = $row['count'];
$trt = $row['runningtime'];
$tavg = 0;
if ($tcnt <> 0) $tavg = intval($trt / $tcnt);
$db->sql_freeresult($sql1);
$cmd = "SELECT DISTINCT e.id, runningtime FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.uid=$uid AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$sql1 = $db->sql_query($cmd) or die($db->sql_error());
$urt = 0;
$ucnt = 0;
while ($row = $db->sql_fetch_array($sql1)) {
$urt += $row['runningtime'];
$ucnt++;
}
$uavg = 0;
if ($ucnt <> 0) $uavg = intval($urt / $ucnt);
$db->sql_freeresult($sql1);
$days = floor($trt / 1440);
$hours = floor(($trt - ($days * 1440)) / 60);
$mins = $trt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
$name = $firstname . ' ' . $lastname;
$u1 = preg_replace("/ /", "", $user);
$n1 = preg_replace("/ /", "", $name);
$link = "$WS_SELF?user=";
if ($u1 <> $n1)
$link = "$WS_SELF?user=" . $n1;
$link .= "&dolast=$dolast&domost=$domost&dobest=$dobest&doworst=$doworst";
$line++;
if ($line % 2)
$thisclass = 'class=o';
else
$thisclass = 'class=l';
$uline++;
if ($uline % 2)
$uclass = 'class=z1';
else
$uclass = 'class=z2';
$width = 45 + ($numyears * 20);
$mouse = "<a href=\"$link\"";
if ($usejpgraph && $ws_watcher) {
$mouse .= " onmouseover=\"";
$mouse .= " this.T_WIDTH=$width;";
$mouse .= "$ColScheme;return escape('";
$mouse .= "<img src=\'$WS_SELF?graph=1&uid=$uid\'>";
$mouse .= "')\"";
}
$mouse .= ">";
$mouse .= $firstname . " ". HideName($lastname) . "</a>";
echo<<<EOT
<tr class=line><td colspan=$numcols></td></tr>
<tr $thisclass valign=middle align=center>
<td $uclass width="15%" rowspan=2 align=center>
$mouse
</td>
<td $uclass width="5%" rowspan=2></td>
<td $uclass width="5%" rowspan=2></td>
<td width="25%" align=right>$dhm</td>
<td width="25%" >$tcnt</td>
<td width="25%" >$tavg</td>
</tr>
EOT;
$days = floor($urt / 1440);
$hours = floor(($urt - ($days * 1440)) / 60);
$mins = $urt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
$line++;
if ($line % 2)
$thisclass = 'class=o';
else
$thisclass = 'class=l';
echo<<<EOT
<tr $thisclass align=center>
<td width="25%" align=right>$dhm</td>
<td width="25%">$ucnt</td>
<td width="25%">$uavg</td>
</tr>
<tr class=line><td colspan=$numcols></td></tr>
EOT;
# Get Years per watcher if user is set
$u1 = preg_replace("/ /", "", $user);
$n1 = preg_replace("/ /", "", $name);
if ($u1 == $n1 || $numusers == 1) {
get_years($uid, $firstname, $lastname);
}
}
}
}
function get_years($uid, $firstname, $lastname) {
# Get Years per watcher
global $db, $DVD_TABLE, $DVD_EVENTS_TABLE, $lang, $name, $watched, $user, $year, $line, $handleadult, $IsPrivate, $numcols;
global $uclass, $yclass, $ws_year, $usejpgraph, $dolast, $domost, $dobest, $doworst, $WS_SELF, $ws_wb, $ColScheme;
$uuser = rawurlencode($user);
$yline = 0;
$cmd = "SELECT SUBSTRING(timestamp,1,4) AS year, SUM(runningtime) AS runningtime, SUM(1) AS count FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.uid=$uid AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY year ORDER BY year DESC";
$sql2 = $db->sql_query($cmd) or die($db->sql_error());
$urt = 0;
$ucnt = 0;
while ($row = $db->sql_fetch_array($sql2)) {
$yr = $row['year'];
$yrt = $row['runningtime'];
$ycnt = $row['count'];
$yavg = 0;
if ($ycnt <> 0) $yavg = intval($yrt / $ycnt);
$days = floor($yrt / 1440);
$hours = floor(($yrt - ($days * 1440)) / 60);
$mins = $yrt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
# Display total year figures
$yline++;
if ($yline % 2)
$yclass = 'class=y';
else
$yclass = 'class=x';
$link = "$WS_SELF?user=" . $uuser . "&year=";
if ($year <> $yr)
$link = "$WS_SELF?user=" . $uuser . "&year=" . $yr;
$link .= "&dolast=$dolast&domost=$domost&dobest=$dobest&doworst=$doworst";
$line++;
if ($line % 2)
$thisclass = 'class=o';
else
$thisclass = 'class=l';
$width = 45 + (12 * 20);
$mouse = "<a href=\"$link\"";
if ($usejpgraph && $ws_year) {
$mouse .= " onmouseover=\"";
$mouse .= " this.T_WIDTH=$width;";
$mouse .= "$ColScheme;return escape('";
$mouse .= "<img src=\'$WS_SELF?graph=1&uid=$uid&year=$yr\'>";
$mouse .= "')\"";
}
$mouse .= ">";
$mouse .= $yr . "</a>";
echo<<<EOT
<tr valign=middle align=center>
<td $uclass width="15%" rowspan=2></td>
<td $yclass width="5%" rowspan=2 valign=middle>
$mouse
</td>
<td $yclass width="5%" rowspan=2></td>
<td $thisclass width="25%" align=right>$dhm</td>
<td $thisclass width="25%" >$ycnt</td>
<td $thisclass width="25%" >$yavg</td>
</tr>
EOT;
$cmd = "SELECT DISTINCT e.id, runningtime FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.uid=$uid "
."AND $ws_wb AND SUBSTRING(timestamp,1,4)='$yr'";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$sql3 = $db->sql_query($cmd) or die($db->sql_error());
$yurt = 0;
$yucnt = 0;
$yuavg = 0;
while ($row = $db->sql_fetch_array($sql3)) {
$yurt += $row['runningtime'];
$yucnt++;
}
if ($yucnt <> 0) $yuavg = intval($yurt / $yucnt);
$db->sql_freeresult($sql3);
$days = floor($yurt / 1440);
$hours = floor(($yurt - ($days * 1440)) / 60);
$mins = $yurt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
$line++;
if ($line % 2)
$thisclass = 'class=o';
else
$thisclass = 'class=l';
echo<<<EOT
<tr $thisclass valign=middle align=center>
<td width="25%" align=right>$dhm</td>
<td width="25%" >$yucnt</td>
<td width="25%" >$yuavg</td>
</tr>
<tr class=line><td colspan=$numcols></td></tr>
EOT;
if ($year == $yr) {
get_months($uid, $firstname, $lastname);
}
}
$db->sql_freeresult($sql3);
}
function get_months($uid, $firstname, $lastname) {
global $db, $DVD_TABLE, $DVD_EVENTS_TABLE, $lang, $line, $user, $year, $month, $handleadult, $IsPrivate, $numcols;
global $uclass, $yclass, $ws_month, $usejpgraph, $dolast, $domost, $dobest, $doworst, $watched, $WS_SELF, $ws_wb, $ColScheme;
# Now get the months
$uuser = rawurlencode($user);
$mline = 0;
$maxmonths = 12;
if ($year == date("Y",time())) {
$maxmonths = date("m", time());
}
for ($mth=$maxmonths;$mth>0;$mth--) {
$yearmonth = sprintf('%04d-%02d', $year, $mth);
$cmd = "SELECT SUM(runningtime) AS runningtime, SUM(1) AS count, e.id FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e ";
$cmd .= "WHERE e.id=d.id AND e.uid=$uid AND SUBSTRING(timestamp,1,7)='$yearmonth' AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate)) {
$cmd .= " AND isadulttitle=0";
}
$cmd .= " GROUP BY SUBSTRING(timestamp,1,7)";
$sql4 = $db->sql_query($cmd) or die($db->sql_error());
$murt = 0;
$mucnt = 0;
$row = $db->sql_fetch_array($sql4);
$db->sql_freeresult($sql4);
$mrt = $row == null ? 0 : $row['runningtime'];
$mcnt = $row == null ? 0 : $row['count'];
$mavg = 0;
if ($mcnt <> 0) { $mavg = intval($mrt / $mcnt); }
$days = floor($mrt / 1440);
$hours = floor(($mrt - ($days * 1440)) / 60);
$mins = $mrt - (($hours * 60) + ($days * 1440));
$dhm = sprintf('%d : %02d : %02d', $days, $hours, $mins);
# Display total month figures
if ($mcnt) {
$mline++;
if ($mline % 2)
$mclass = 'class=u';
else
$mclass = 'class=v';
$line++;
if ($line % 2)
$thisclass = 'class=o';
else
$thisclass = 'class=l';
$monthp = sprintf('%02d', $mth);
$link = "$WS_SELF?user=" . $uuser . "&year=" . $year . "&month=";
if ($month <> $monthp)
$link = "$WS_SELF?user=" . $uuser . "&year=" . $year . "&month=" . $monthp;
$link .= "&dolast=$dolast&domost=$domost&dobest=$dobest&doworst=$doworst";
# This gets the month name in the current locale
$amth = fix88595(ucwords(strftimeReplacement("%B", mktime(0,0,0,$mth,1,0))));
# $width = 45 + (cal_days_in_month(CAL_GREGORIAN, $mth, $year) * 10);
$width = 45 + (date("j", mktime(0,0,0,intval($month)+1,0, $year)) * 10);
$mouse = "<a href=\"$link\"";
if ($usejpgraph && $ws_month) {
$mouse .= " onmouseover=\"";
$mouse .= " this.T_WIDTH=$width;";
$mouse .= "$ColScheme;return escape('";
$mouse .= "<img src=\'$WS_SELF?graph=1&uid=$uid&year=$year&month=$monthp\'>";
$mouse .= "')\"";
}
$mouse .= ">";
$mouse .= $amth . "</a>";
$html = $mouse;
echo<<<EOT
<tr valign=middle align=center>
<td $uclass width="15%"></td>
<td $yclass width="5%"></td>
<td $mclass align=right width="5%" valign=middle>$html</td>
<td $thisclass width="25%" align=right>$dhm</td>
<td $thisclass width="25%" >$mcnt</td>
<td $thisclass width="25%" >$mavg</td>
</tr>
<tr class=line><td colspan=$numcols></td></tr>
EOT;
if ($month == $monthp) {
get_titles($uid, $firstname, $lastname, $mclass);
}
}
}
}
function get_titles($uid, $firstname, $lastname, $mclass) {
global $db, $DVD_TABLE, $DVD_EVENTS_TABLE, $defaultorder, $lang, $watched, $line, $user, $year, $handleadult, $month;
global $IsPrivate, $wssortorder, $numcols, $uclass, $yclass, $ws_title, $sort, $order, $dolast, $domost, $dobest, $doworst, $WS_SELF, $ws_wb;
$uuser = rawurlencode($user);
if (!isset($wssortorder))
$wssortorder = "sorttitle";
if (!isset($sort) || !$sort)
$sort = $wssortorder;
if (!isset($order) || ($order != 'asc' && $order != 'desc')) {
$order = $defaultorder[$sort];
}
$sortimg_title = ($sort=='sorttitle') ? "<img src=\"gfx/$order.gif\" width=13 height=13 border=0 alt=\"\"/> {$lang['WS']['MOVIE']}": $lang['WS']['MOVIE'] ;
$sortimg_runtime = ($sort=='runningtime') ? "<img src=\"gfx/$order.gif\" width=13 height=13 border=0 alt=\"\"/> {$lang['WS']['RUNTIME']}": $lang['WS']['RUNTIME'];
$sortimg_date = ($sort=='timestamp') ? "<img src=\"gfx/$order.gif\" width=13 height=13 border=0 alt=\"\"/> {$lang['WS']['DATE']}": $lang['WS']['DATE'];
$sorthdr_title = ($sort=='sorttitle') ? ($order=='asc')?'desc':'asc': $defaultorder['sorttitle'];
$sorthdr_runtime = ($sort=='runningtime') ? ($order=='asc')?'desc':'asc': $defaultorder['runningtime'];
$sorthdr_date = ($sort=='timestamp') ? ($order=='asc')?'desc':'asc': $defaultorder['timestamp'];
$s1 = addslashes($lang['SORTTITLE']);
$s2 = addslashes($lang['SORTRUNTIME']);
$s3 = addslashes($lang['SORTTIMESTAMP']);
$dolink="&dolast=$dolast&domost=$domost&dobest=$dobest&doworst=$doworst";
$link_title = "<a class=n href=\"$WS_SELF?user=$firstname$lastname&year=$year&month=$month&sort=sorttitle&order=$sorthdr_title$dolink\" title=\"$s1\">$sortimg_title</a>";
$link_runtime = "<a class=n href=\"$WS_SELF?user=$firstname$lastname&year=$year&month=$month&sort=runningtime&order=$sorthdr_runtime$dolink\" title=\"$s2\">$sortimg_runtime</a>";
$link_date = "<a class=n href=\"$WS_SELF?user=$firstname$lastname&year=$year&month=$month&sort=timestamp&order=$sorthdr_date$dolink\" title=\"$s3\">$sortimg_date</a>";
echo<<<EOT
<tr class=t align=center>
<td $uclass width="15%"></td>
<td $yclass width="5%"></td>
<td $mclass width="5%"></td>
<td class=t width="40%" align=left>$link_title</td>
<td class=t width="15%">$link_runtime</td>
<td class=t width="20%">$link_date</td>
</tr>
EOT;
$ym = $year . "-" . $month;
$cmd = "SELECT e.id,title,runningtime,timestamp,reviewfilm FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.uid=$uid "
."AND $ws_wb AND SUBSTRING(timestamp,1,7)='$ym'";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " ORDER BY $sort $order";
$sql5 = $db->sql_query($cmd) or die($db->sql_error());
$line++;
while ($row = $db->sql_fetch_array($sql5)) {
$id = $row['id'];
$title = $row['title'];
$runningtime = $row['runningtime'];
$timestamp = $row['timestamp'];
$reviewfilm = FixAReviewValue($row['reviewfilm']);
$line++;
if ($line % 2)
$thisclass = 'class=l';
else
$thisclass = 'class=o';
list($tdate, $ttime) = explode(' ',$timestamp);
list($tyear, $tmonth, $tday) = explode('-', $tdate);
list($thour, $tmin, $tsec) = explode(':',$ttime);
$tm = mktime($thour, $tmin, $tsec, $tmonth, $tday, $tyear);
$dt = fix88595(ucwords(strftimeReplacement($lang['SHORTDATEFORMAT'], $tm)));
if ($ws_title) {
$title = addslashes($title);
$mouse = mouseover($id, $title, 1, $reviewfilm);
} else
$mouse = $title;
echo<<<EOT
<tr valign=middle align=center>
<td $uclass width="15%"></td>
<td $yclass width="5%"></td>
<td $mclass width="5%"></td>
<td $thisclass width="40%" align=left>$mouse</td>
<td $thisclass width="15%">$runningtime</td>
<td $thisclass width="20%">$dt</td>
</tr>
EOT;
}
$db->sql_freeresult($sql5);
echo<<<EOT
<tr>
<td $uclass></td>
<td $yclass></td>
<td $mclass></td>
<td class=t colspan=3> </td>
</tr>
<tr class=line><td colspan=$numcols></td></tr>
EOT;
$line++;
return;
}
function mouseover($id, $title, $doimage, $topline) {
#
# $doimage controls whether we do the image in the mouseover, or as the thing we're mousing over
# 1 = do the image in the mouseover, 0 = this is what we are mousing over
#
global $db, $DVD_TABLE, $DVD_EVENTS_TABLE, $DVD_USERS_TABLE, $lang, $watched, $handleadult, $IsPrivate, $ws_wb, $ColScheme, $getimages, $img_webpath;
$mouseline = 1;
$cmd = "SELECT DISTINCT * FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e WHERE e.id=d.id AND e.id='$id' AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " GROUP BY e.uid";
$sql6 = $db->sql_query($cmd) or die($db->sql_error());
$unique = $db->sql_numrows($sql6);
$db->sql_freeresult($sql6);
$cmd = "SELECT firstname, lastname, timestamp FROM $DVD_TABLE d, $DVD_EVENTS_TABLE e, $DVD_USERS_TABLE u WHERE e.id=d.id AND e.uid=u.uid AND e.id='$id' AND $ws_wb";
if (($handleadult == 2) || (($handleadult == 1) && !$IsPrivate))
$cmd .= " AND isadulttitle=0";
$cmd .= " ORDER BY CONCAT(lastname,' ',firstname),timestamp DESC";
$sql7 = $db->sql_query($cmd) or die($db->sql_error());
$times = $db->sql_numrows($sql7);
$rs = $times+1;
if ($getimages == 3)
$thumbname = "$img_webpath[$id]f.jpg";
else
$thumbname = PhyspathToWebpath(resize_jpg($id, "f", 60, 100));
$mouse = "<a href=\"index.php?mediaid=$id&action=show\"";
$mouse .= " onmouseover=\"";
$title = preg_replace("/&/", "&", $title);
$mousetitle = preg_replace("/\'/", "'", $title);
$mousetitle = preg_replace('/\\\"/', """, $mousetitle);
$who = addslashes($lang['WS']['WHO']);