/
page_modules.php
1874 lines (1442 loc) · 61.8 KB
/
page_modules.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
<?
// Encoding: UTF-8
require_once("common.php");
function styleConfig(){
echo '<div class="beta_box">';
div_open("beta_header");
echo "Personlig stilvalg - under utprøving! (beta)";
div_close();
echo'<div id="testediv"> </div>';
echo'<div id="xhrfeedback"> </div>';
h3("Velg en stil");
form_start_custom("styleedit", "javascript:changeUserStyle('modules/styleService.php')", "POST");
?>
<select id="userStyles">
<option value="NULL">Velg stilark</option>
<option value="NULL">Gå tilbake til standard</option>
</select>
<script type="text/javascript">
fetchStyles('modules/styleService.php');
</script>
<?php
form_submit("submit", "Bruk valgt stil");
form_end();
h3("Legg opp en ny stil");
form_start_custom("styleadd", "javascript:addUserStyle('modules/styleService.php')", "POST");
form_textfield2("Navn", "styleName", ""); br();
form_textfield2("URL", "styleURL", ""); br();
form_submit("submit", "Legg opp stil"); br();
form_end();
h3("Stiler du kan slette");
echo ("(Disse er lagt opp av deg og ikke i bruk av noen andre for øyeblikket.)");
div_open("", "", "deleteStyleList");
div_close();
div_close();
}
// Module om Calcuttagutta
function mcg(){
// Om Calcuttagutta
echo '<table class="default_table">';
echo "<tr><td colspan=2><div class=\"default_header\">Om Calcuttagutta</div>";
echo '</td></tr><tr><td>Vi er en gjeng med gutter og jenter som skriver om alt mellom himmel og jord, anført av sjefsskribent Tor. Teknologien tar Are og Anders seg av; Calcuttagutta hviler på kilovis med spaghettikode kokt i PHP og en SQL-database.';
echo '<br/><br/>For en introduksjon til Calcuttagutta anbefaler vi Tors artikkel <a href="http://www.calcuttagutta.com/index.php?m_c=va&articleid=4287">An introduction to Calcuttagutta</a>.';
echo '</td></tr><tr><td><div class="default_header">Diverse</div>';
echo '<br/>Vi har en butikk på cafepress.com: <a href="http://www.cafepress.com/calcuttagutta">http://www.cafepress.com/calcuttagutta</a>';
echo '<br><br>Liste over alle avstemninger finner du her: <a href="index.php?m_c=module_oldpolls">Gamle avstemninger</a>';
echo '</td></tr></table>';
echo '';
}
function module_birthday(){
$today = date("m-d");
$query = "SELECT username, firstname FROM user WHERE birthdate LIKE '%" . $today . "'";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if($num_results > 0){
echo '<div class="poll">';
echo '<div class="pollheader">';
echo 'Bursdagsbarn!</div>';
echo '<div class="birthdaylink">';
while($row = DB_next_row($result)){
echo '<a href="index.php?m_c=mvp&username=' . $row['username'] . '">' . $row['firstname'] . '</a><br/>';
}
echo '</div> Hipp hurra, gratulerer med dagen!';
echo '</div>';
}
}
function module_recentarticles(){
/*
$today = date("m-d");
$LIMIT = 10;
$query = "SELECT articleid, title FROM articles WHERE comment_to IS NULL AND is_draft IS NULL ORDER BY DATE_POSTED DESC, TIME_POSTED DESC LIMIT " . $LIMIT . ";";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if($num_results > 0){
echo '<div class="recentarticles_header">';
echo $LIMIT . ' siste artikler</div>';
echo '<div class="recentarticles_links">';
while($row = DB_next_row($result)){
echo '<div class="recentarticles_link"><a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '">' . $row['title'] . '</a></div>';
}
echo '</div>';
}
*/
echo '<div class="recentarticles">';
echo '<div class="rss_feed"><a href="rss.xml">RSS-mating</a></div>';
echo '</div>';
}
function module_admin(){
// adminpage, stop here if not logged in/right access-level
if (!isValidAdmin()) {
echo (getString("not_valid_admin", "Administratorside, du må logge inn for å få tilgang her"));
return;
}
if (isset($_REQUEST['admin_action']))
$action = $_REQUEST['admin_action'];
else
$action = "";
if($action == "confirmpurge"){
$articleid = $_REQUEST['purgeid'];
echo '<div class="default_header">Bekreft sletting av fil ' . $articleid . '</div>';
form_start_post();
form_hidden("m_c", "module_admin");
form_hidden("admin_action", "deleteforgood");
form_hidden("purgeid", $articleid);
form_submit("submit", "Ja, slett filen for godt");
form_end();
}else if($action == "deleteforgood"){
$articleid = $_REQUEST['purgeid'];
$query = "DELETE FROM articles WHERE articleid = " . $articleid . ";";
$result = DB_update($query);
if($result){
global $logtype;
write_log_entry($_SESSION['valid_user'], $logtype['user'], "admin_purgedfile,");
echo '<div class="default_header">Filen er slettet.</div>';
}else{
echo '<div class="default_header">Sletting mislyktes.</div>';
}
}else if($action == "showfile"){
$articleid = $_REQUEST['articleid'];
$query = "SELECT * FROM articles WHERE articleid =" . $articleid . " AND (is_draft IS NULL OR is_draft=0);";
$result = DB_get_table($query);
$num_results = DB_rows_affected($query);
$row = DB_next_row($result);
echo "<div class=\"header2\">" . $row['title'] . "</div>";
echo "<div class=\"metatext\">";
echo "<span class='author'>Forfatter: ";
if(isset($row['author_username'])){
echo '<a href="index.php?m_c=mvp&username=';
echo $row['author_username'] . '">' . stripslashes($row['author']) . '</a>';
}else{
echo stripslashes($row['author']);
}
echo ', ';
if($row['author_username']){
echo " (" . stripslashes($row['author_username']) . ").</span>";
}else{
echo " (" . $unknown_author . ").</span>";
}
echo "<span class=\"time\">Lagt opp: " . make_date($row['date_posted']) . ", " . make_time($row['time_posted']) . "</span></div>";
echo "<div class=\"textbody\">" . stripslashes(nl2br($row['body'])) . "</div>";
}else if($action == "showstats"){
$query = "SELECT articleid, author, view_count, title FROM articles WHERE view_count > 0 ORDER BY view_count DESC;";
$result = DB_get_table($query);
$num_rows = DB_rows_affected($result);
echo '<table class="default_table">';
echo "<tr>";
echo '<td>Artikkel-ID</td><td>Tittel</td><td>Forfatter</td>';
echo '<td>Antall visninger</td></tr>';
while($row = DB_next_row($result)){
echo "<tr>";
echo '<td>' . $row['articleid'] . '</td><td>' . $row['title'] . '</td><td>' . $row['author'] . '</td>';
echo '<td>' . $row['view_count'] . '</td><td>';
form_start_get();
form_hidden("m_c", "m_va");
form_hidden("articleid", $row['articleid']);
form_submit("submit", "Les artikkel");
form_end();
echo '</td></tr>';
}
echo '</table>';
}else if($action == "undelete"){
$articleid = $_REQUEST['articleid'];
$query = "UPDATE articles SET is_deleted = NULL WHERE articleid = " . $articleid . ";";
$result = DB_update($query);
echo $query;
if($result){
global $logtype;
write_log_entry($_SESSION['valid_user'], $logtype['user'], "admin_restoredfile,");
echo "Vellykket gjenoppretting.";
}else{
echo "Gjenoppretting mislyktes.";
}
}else if($action == "listdeleted"){
$query = "SELECT time, comment_to, articleid, title, author, ip FROM articles,eventlog WHERE articleid = itemid AND is_deleted IS NOT NULL;";
$result = DB_get_table($query);
$num_rows = DB_rows_affected($result);
echo '<table class="default_table">';
echo "<tr>";
echo '<td>Artikkel-ID</td><td>Kommentar til</td><td>Tittel</td><td>Forfatter</td>';
echo '<td>IP</td><td>Tidspunkt</td></tr>';
while($row = DB_next_row($result)){
echo "<tr>";
echo '<td>' . $row['articleid'] . '</td><td>' . $row['comment_to'] . '</td><td>' . $row['title'] . '</td><td>' . $row['author'] . "</td><td>" . $row['ip'] . '</td><td>'. $row['time'] . '</td>';
echo '<td>';
form_start_post();
form_hidden("m_c", "module_admin");
form_hidden("admin_action", "confirmpurge");
form_hidden("purgeid", $row['articleid']);
form_submit("submit", "Slett for godt");
form_end();
echo '</td><td>';
form_start_get();
form_hidden("m_c", "module_admin");
form_hidden("admin_action", "showfile");
form_hidden("articleid", $row['articleid']);
form_submit("submit", "Les");
form_end();
echo '</td><td>';
form_start_get();
form_hidden("m_c", "module_admin");
form_hidden("admin_action", "undelete");
form_hidden("articleid", $row['articleid']);
form_submit("submit", "Gjenoppliv");
form_end();
echo '</td><td>';
echo '</td></tr>';
}
echo '</table>';
}else if($action == "viewlog"){
$type = $_REQUEST['type'];
$date = $_REQUEST['date'];
global $logtype;
if(isset($type)){
$sqldate = $_REQUEST['year'] . "-" . $_REQUEST['month'] . "-" . $_REQUEST['day'];
$sqldate = date("Y-m-d",strtotime($sqldate) );
$query = "SELECT * FROM eventlog WHERE time LIKE '" . $sqldate . "%' AND log_type=" . $type . ";";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
$types_array = array_flip($logtype);
echo '<table class="default_table">';
echo '<tr><td>Event ID</td><td>Logtype</td><td>Affected item-ID</td><td>Resp. user</td><td>Description</td><td>IP</td><td>Time</td></tr>';
while($row = DB_next_row($result)){
echo '<tr>';
echo '<td>' . $row["eventid"] . '</td><td>'. $types_array[$row["log_type"]] . '</td><td>' . $row["itemid"] . '</td><td>' . $row["username"] . '</td>';
echo '<td>' . $row["event_type"] . '</td><td>' . $row["ip"] . '</td><td>' . $row["time"] . '</td></tr>';
}
echo '</table>';
}else{
form_start_post();
echo 'Type of log-entry:';
echo '<select name="type" >';
;
foreach($logtype as $id => $logtypes){
echo '<option value="' . $logtypes . '">' . $id . '</option>\n';
}
echo '</select>';
echo '<br/>For this day: ';
form_datewidget(date("Y-m-d"));
form_hidden("m_c", "module_admin");
form_hidden("admin_action", "viewlog");
form_submit("Submit", "Vis");
form_end();
}
}else{
echo '<div class="default_list"><a href="index.php?m_c=module_admin&page_title=Slettede_filer&admin_action=listdeleted">Vis slettede filer</a>';
echo '<br/><a href="index.php?m_c=module_admin&page_title=Stat&admin_action=showstats">Vis statistikk</a>';
echo '<br/><a href="index.php?m_c=module_files&page_title=Filadmin">Fil(bilde)admin</a>';
echo '<br/><a href="index.php?m_c=module_user_admin&page_title=User+administration">Brukeradmin</a>';
echo '<br/><a href="index.php?m_c=module_admin&page_title=User+administration&admin_action=viewlog">Logger</a>';
echo '<br><a href="index.php?m_c=module_register_form&page_title=Register<+new+user">Registrer en ny bruker</a>';
echo '<br><a href="index.php?m_c=module_admininput&page_title=Admininput">Legg inn en artikkel</a>';
echo '<br><a href="index.php?m_c=module_polladmin&page_title=Polladmin">Administrer polls</a>';
echo '<br><a href="index.php?m_c=module_categoryadmin&page_title=Categoryadmin">Opprett, slett og endre kategorier</a>';
echo '<br><a href="index.php?m_c=showSettingsGUI">' . getString("admin_edit_settings", "Innstillinger") . '</a>';
echo '</div>';
}
}
function module_categoryadmin(){
// adminpage, stop here if not logged in/right access-level
if (!isValidAdmin()) {
echo (getString("not_valid_admin", "Administratorside, du må logge inn for å få tilgang her"));
return;
}
// Check whether user has sent category creation data
if(isset($_REQUEST['action'])) $action = $_REQUEST['action'];
else $action ="";
if ($action == "createcategory"){
if (isset($_REQUEST['categoryname'])){
$insertquery = "INSERT INTO category (name) VALUES ('" . $_REQUEST['categoryname'] . "')";
$insertresult = DB_insert($insertquery);
if ($insertresult)
echo "Category " . $_REQUEST['categoryname'] . " added.<br/>";
else
echo "Adding category failed.<br/>";
}
} else if ($action == "deletecategory"){
if (isset($_REQUEST['categoryid'])){
if (isset($_REQUEST['confirmdeletecategory'])){
$deletequery = "DELETE FROM category WHERE categoryid = " . $_REQUEST['categoryid'] . ";";
$deleteresult = DB_update($deletequery);
if ($deleteresult){
echo "Category deleted.<br/>";
}else{
echo "Deletion failed. Maybe there are existing articles in this category?<br/>";
}
}else{
echo "Please confirm that you wish to delete category " . $_REQUEST['categoryname'] . ". Click anywhere else to abort.<br/>";
form_start_post();
form_hidden("m_c", "module_categoryadmin");
form_hidden("action", "deletecategory");
form_hidden("categoryid", $_REQUEST['categoryid']);
form_hidden("confirmdeletecategory", "1");
form_submit("submit", "Confirm deletion");
form_end();
br();
}
}
} else if ($action == "editcategory"){
if (isset($_REQUEST['categoryid'])){
if(isset($_REQUEST['confirmeditcategory'])){
$updatequery = "UPDATE category SET name = '" . $_REQUEST['categoryname'] . "' WHERE categoryid = " . $_REQUEST['categoryid'] . ";";
$updateresult = DB_insert($updatequery);
if ($updateresult)
echo "Category " . $_REQUEST['categoryname'] . " updated.<br/><br/>";
else
echo "Updating category failed.<br/><br/>";
}else{
form_start_post();
echo("Category name:");
br();
form_textfield("categoryname",$_REQUEST['categoryname']);
form_hidden("m_c", "module_categoryadmin");
form_hidden("action", "editcategory");
form_hidden("categoryid", $_REQUEST['categoryid']);
form_hidden("confirmeditcategory", "1");
form_submit("submit", "Save edit");
form_end();
br();br();
}
}
}
// Query for existing categories
$query = "SELECT categoryid, name FROM category;";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if($num_results == 0)
echo "No existing categories.";
else
echo "Existing categories:";
table_open();
while ($row = DB_next_row($result)){
tr_open();
td_open(1); echo $row['categoryid']; td_close();
td_open(1); echo $row['name']; td_close();
td_open(1);
form_start_post();
form_hidden("m_c", "module_categoryadmin");
form_hidden("action", "editcategory");
form_hidden("categoryname", $row['name']);
form_hidden("categoryid", $row['categoryid']);
form_submit("submit", "Edit");
form_end();
td_close();
td_open(1);
form_start_post();
form_hidden("m_c", "module_categoryadmin");
form_hidden("action", "deletecategory");
form_hidden("categoryname", $row['name']);
form_hidden("categoryid", $row['categoryid']);
form_submit("submit", "Delete");
form_end();
td_close();
tr_close();
}
table_close();
echo "<br/>Create new category<br/>";
form_start_post();
echo "Name: "; form_textfield("categoryname", "");
form_hidden("m_c", "module_categoryadmin");
form_hidden("action", "createcategory");
form_submit("submit", "Create");
form_end();
}
function module_files(){
// Switch case on REQUEST['files_action'].
// action == no set -display images
// action == delete image, get image ID and ask for confirmation
// action == delete image confirmed, get image ID and delete it
// action == upload. Upload image and return ID and URL.
// adminpage, stop here if not logged in/right access-level
if (!isValidAdmin()) {
echo (getString("not_valid_admin", "Administratorside, du må logge inn for å få tilgang her"));
return;
}
$action = $_REQUEST['files_action'];
if ($action == "confirmdelete"){
$query = "SELECT username FROM user WHERE picture=" . $_REQUEST['fileid'] . ";";
$result = DB_get_table($query);
if($result){
while($row = DB_next_row($result)){
$query = "UPDATE user SET picture = NULL where username='" . $row['username'] . "'";
$result = DB_update($query);
if(!$result){
echo "Kunne ikke nullstille bildefeltet i brukertabellen.";
return;
}
}
}
$querydelete = "DELETE FROM files WHERE picid =" . $_REQUEST['fileid'];
$result = DB_update($querydelete);
if(!$result){
echo "Bildet ble ikke slettet.";
}else{
echo "Fil slettet.";
}
}else if ($action == "delete"){
echo "Bekreft sletting av fil med id " . $_REQUEST['fileid'] . ".";
form_start_post();
form_hidden("fileid", $_REQUEST['fileid']);
form_hidden("files_action", "confirmdelete");
form_hidden("m_c", "module_files");
form_submit("submit", "Slett filen");
form_end();
}else if ($action == "upload"){
}else if ($action == "viewfile"){
$query = "SELECT username FROM user WHERE picture=" . $_REQUEST['fileid'] . ";";
$result = DB_get_table($query);
if(strstr($_REQUEST['filetype'], 'image') != false){
echo '<img class="image_admin" src="mod_pic.php?id=' . $_REQUEST['fileid']. '" alt="' . $result['firstname'] . '" /><br/>';
form_start_post();
form_hidden("fileid", $_REQUEST['fileid']);
form_hidden("files_action", "delete");
form_hidden("m_c", "module_files");
form_submit("submit", "Delete file");
form_end();
echo "<br/>";
if($result){
echo "File linked to in these user's profiles (deleting will set the concerned field to NULL):<br/>";
while($row = DB_next_row($result)){
echo $row['username'] . '<br/>';
}
}
}else{
echo "Kan ikke vise filtypen.";
}
}else{
$query = "SELECT picid, description, filetype, pic_width, pic_height, size FROM files";
$result = DB_get_table($query);
echo '<table class="default_table">';
echo '<tr>';
echo '<td>File ID</td>';
echo '<td>Description</td>';
echo '<td>File type</td>';
echo '<td>Picture size</td>';
echo '<td>Size (KB)</td>';
echo '<td>Edit</td>';
echo '</tr>';
$num_rows = DB_rows_affected($result);
if($num_rows < 1)
echo '<tr><td colspan=6>Ingen filer i databasen.</td></tr>';
while($row = DB_next_row($result)){
echo '<tr>';
echo '<td>' . $row['picid'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['filetype'] . '</td>';
echo '<td>' . $row['pic_width'] . ' x ' . $row['pic_height'] . '</td>';
echo '<td>'; printf ("%u", ($row['size'] / 1024)); echo '</td>';
echo '<td>';
form_start_post();
form_hidden("fileid", $row['picid']);
form_hidden("files_action", "viewfile");
form_hidden("filetype", $row['filetype']);
form_submit("submit", "View file");
form_hidden("m_c","module_files");
form_end();
form_start_post();
form_hidden("fileid", $row['picid']);
form_hidden("files_action", "delete");
form_hidden("m_c", "module_files");
form_submit("submit", "Delete file");
form_end();
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
}
function module_listusers(){
echo "<!-- start module listusers -->";
echo '<div class="userlist">';
echo '<div class="userlist_heading">Spaltister</div>';
// Old query, giving a list of all users with article-creation permissions
// $query = "SELECT firstname, username FROM user WHERE may_post=1 ORDER BY firstname, username";
// New query - all writers active during last X days
// and top X writers
$query = "SELECT distinct u.firstname, a.username FROM (
(SELECT author_username username, count(author_username) AS sum_posts
FROM articles
WHERE comment_to IS NULL
GROUP BY author_username
ORDER BY sum_posts DESC
LIMIT 5)
UNION
(SELECT author_username username, count(author_username) AS sum_posts
FROM articles
WHERE comment_to IS NULL
AND DATE_SUB(CURDATE(), INTERVAL 14 DAY) <= date_posted
GROUP BY author_username
ORDER BY sum_posts DESC)
) AS a, user u WHERE a.username=u.username;";
$result = DB_get_table($query);
echo '<div class="userlist_links">';
while($row = DB_next_row($result)){
if($row['username'] == "admin"){
;
}else{
echo '<a href="index.php?m_c=mvp&username=' . $row['username'] . '">';
if(strlen($row['firstname']) > 1){
echo $row['firstname'] ."<br/></a>";
}else{
echo $row['username'] ."<br/></a> ";
}
}
}
echo '</div>';
echo '<div class="viewmemberlist"><a href="index.php?m_c=module_memberlist">Medlemsliste</a></div>';
echo '</div>';
}
// module flashforum archive
function mfa(){
//module flashforum archive
global $months;
$monthkeys = array_keys($months);
$START_YEAR = 2005;
$END_YEAR = date("Y");
echo '<table class="default_table">';
echo '<tr><td colspan=2 class="default_header">Lynforumarkiv</td></tr>';
echo '<form method="post" action="index.php">';
form_hidden("m_c", "mfa");
echo '<tr><td>Velg år</td><td>';
if(isset($_REQUEST['mfa_y']))
form_select_number("mfa_y",$START_YEAR,$END_YEAR,$_REQUEST['mfa_y']);
else
form_select_number("mfa_y",$START_YEAR,$END_YEAR,date("y"));
echo '</td></tr>';
echo '<tr><td>Velg måned</td><td>';
if(isset($_REQUEST['mfa_m']))
form_dropdown("mfa_m", $monthkeys, $months,$_REQUEST['mfa_m'] - 1);
else
form_dropdown("mfa_m", $monthkeys, $months,date(m) - 1);
echo '</td></tr>';
echo '<tr><td colspan=2>'; form_submit("mfa_s", "Vis"); echo '</td></tr></form>';
if(isset($_REQUEST['mfa_y']) && isset($_REQUEST['mfa_m'])){
if(strlen($_REQUEST['mfa_m']) == 1){
$month = "0" . $_REQUEST['mfa_m'];
}
$year = $_REQUEST['mfa_y'];
$query = "SELECT * FROM flashforum WHERE time_posted LIKE '" . $year . "-" . $month . "%';";
$result = DB_get_table($query);
echo '<tr><td colspan=2 class="default_header">Lynformposter fra ' . $months[$_REQUEST['mfa_m']] . ' ' . $_REQUEST['mfa_y'] . '</td></tr>';
$num_res = DB_rows_affected($result);
if($num_res == 0){
echo '<tr><td colspan=2 class="default_cursive">Ingen lynforumposter fra ' . $months[$_REQUEST['mfa_m']] . ' ' . $_REQUEST['mfa_y'] . '.</td></tr>';
}
while($row = DB_next_row($result)){
$date = date_nor_sql(substr($row['time_posted'],0,10));
echo '<tr><td colspan=2 class="commentscell"><div class="commentmetatext"><span class="commentauthor">' . $row['author']. "</span>, ";
echo '<span class="commentdate">' . substr($date,0,5) . '</span> ';
echo '<span class="commenttime">' . substr($row['time_posted'],11,5) . '</span></div>';
echo '<div class="textbody_comment">' . $row['message'] . "</div></td></tr>";
}
}else{
}
echo '</table>';
}
function module_flashforum(){
echo "<!-- start module flashforum -->";
global $flashformid;
$thisdate = "";
if(isset($_REQUEST['quickpassword']))
$quickpassword = $_REQUEST['quickpassword'];
else
$quickpassword = "";
if(isset($_REQUEST['message']))
$message = $_REQUEST['message'];
if(isset($_REQUEST['deleteflash']))
$deleteflash = $_REQUEST['deleteflash'];
if(isset($_REQUEST['deleteflash'])){
if(isset($_SESSION['valid_admin']) && isset($_REQUEST['dfc'])){
$query = "DELETE FROM flashforum WHERE postid=" . $_REQUEST['deleteflash'] . ";";
$result = DB_update($query);
if($result){
global $logtype;
write_log_entry($_REQUEST['deleteflash'], $logtype['flashforum'], "del_flashpost,");
}
}else{
echo '<a href="index.php?deleteflash=' . $_REQUEST['deleteflash'] . '&dfc=1">Bekreft sletting</a><br/>';
}
}
echo '<div class="flashforum"><div class="flashforumheader">Lynforum</div>';
echo '<div class="flashforumlist">';
// Insert new message into the database if the spampassword is correct
if (isset($message) && !isset($REQUEST['showall']) && ($flashformid == $_REQUEST['flashformidvar'])) {
if(stristr($quickpassword, "hurra") == FALSE){
echo "<b>Du må fylle inn spampassordet.</b>";
if (isset($_REQUEST['author'])){
$author = $_REQUEST['author'];
}else{
$author = "Ditt navn";
}
$retry = $message;
}else{
$flashformid++;
$_SESSION['flashformid'] = $flashformid;
if(($_REQUEST['author'] != "Ditt navn") && (strlen($_REQUEST['message'])>5) && (strlen($_REQUEST['author']) > 1)){
// Insert new msg into DB if possible
$author = $_REQUEST['author']; $message = $_REQUEST['message'];
if(strlen($author) > 15)
$author = substr($author, 0, 15);
if(strlen($message) > 200)
$message = substr($message, 0,200);
if(isset($_SESSION['valid_user'])){
$query = "INSERT INTO flashforum VALUES ('', '" . strip_tags($author) . "', '', '" . strip_tags($message, "<a>") . "', NOW(),'" . $_SESSION['valid_user'] . "');";
}else{
$query = "INSERT INTO flashforum VALUES ('', '" . strip_tags($author) . "', '', '" . strip_tags($message, "<a>") . "', NOW(),'');";
}
$result = DB_insert($query);
if(!$result)
echo "Whups, melding ikke lagret.<br/>";
else{
global $logtype;
write_log_entry(mysql_insert_id(), $logtype['flashforum'], "new_flashpost,");
}
}else{
echo "<b>Navn og beskjed må fylles inn.</b><br/>";
}
}
}
if(isset($_REQUEST['showall'])){
// Display current articles
$query = "SELECT postid, author,message,UNIX_TIMESTAMP(time_posted) as time_posted FROM flashforum ORDER BY time_posted DESC";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if(!$num_results > 0){
echo "Tomt for øyeblikket.<hr/>";
}else{
$i=0;
while($num_results > 0 && ($row = DB_next_row($result)) && $i<100){
if(date("d/m",$row['time_posted']) != $thisdate ){
if(date("d/m",$row['time_posted']) == date("d/m")){
$thisdate = date("d/m",$row['time_posted']);
echo '<div class="flashdate">I dag:</div>';
}else{
$thisdate = date("d/m",$row['time_posted']);
echo '<div class="flashdate">'. $thisdate . '</div>';
}
}
$i++;
echo '<div class="flashpost"><span class="flashauthor">' . $row['author'] . ': </span>' . htmlwrap($row['message'],20) . ' ('. date("H:i",$row['time_posted']);
if(isset($_SESSION['valid_admin'])){
echo ', <a href="index.php?deleteflash=' . $row['postid'] . '">slett</a>';
}
echo ")</div>"; }
}
}else{
// Display current articles
$query = "SELECT postid, author,message,UNIX_TIMESTAMP(time_posted) as time_posted FROM flashforum ORDER BY time_posted DESC";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if(!$num_results > 0){
echo "Tomt for øyeblikket.<br/>";
}else{
$i=0;
while($num_results > 0 && ($row = DB_next_row($result)) && $i<10){
if(date("d/m",$row['time_posted']) != $thisdate ){
if(date("d/m",$row['time_posted']) == date("d/m")){
$thisdate = date("d/m",$row['time_posted']);
echo '<div class="flashdate">I dag:</div>';
}else{
$thisdate = date("d/m",$row['time_posted']);
echo '<div class="flashdate">'. $thisdate . '</div>';
}
}
$i++;
echo '<div class="flashpost"><span class="flashauthor">' . $row['author'] . ': </span>' . htmlwrap(createLinks($row['message']),20) . ' ('. date("H:i",$row['time_posted']);
if(isset($_SESSION['valid_admin'])){
echo ', <a href="index.php?deleteflash=' . $row['postid'] . '">slett</a>';
}
echo ")</div>"; }
}
}
?>
</div>
<form method="get" action="index.php">
<?php
if(isset($_SESSION['valid_user'])){
echo '<input style="width:140px" type="text" name="author" value=' . $_SESSION['user_firstname'] . ' /><br/>';
echo 'Hipp, hipp, <input size="5" readonly type="textfield" name="quickpassword" value="hurra"/>!';
}else{
if (isset($retry)){
echo '<input style="width:140px" type="text" name="author" onFocus="this.value=wipeOut(this.value);" value="' . $author . '" /><br/>';
} else {
echo '<input style="width:140px" type="text" name="author" onFocus="this.value=wipeOut(this.value);" value="Ditt navn" /><br/>';
}
echo 'Hipp, hipp, <input size="5" type="textfield" name="quickpassword" />!';
}
?>
<?php
if(isset($retry)){
?>
<input onKeyDown="limitText(this.form.message,this.form.countdown,180);"
onKeyUp="limitText(this.form.message,this.form.countdown,180);" style="width:140px" type="text" name="message" onFocus="this.value=wipeOut(this.value);" value="<?php echo $retry; ?>" />
<?php
} else {
?>
<input onKeyDown="limitText(this.form.message,this.form.countdown,180);"
onKeyUp="limitText(this.form.message,this.form.countdown,180);" style="width:140px" type="text" name="message" onFocus="this.value=wipeOut(this.value);" value="Maks 180 tegn" />
<?php
}
?>
<input class="nice1" type="submit" name="submit" value="Post" style="width:80px">
<input readonly type="text" name="countdown" size="3" value="180" style="width:30px">
<input type="hidden" value="<? echo $flashformid; ?>" name="flashformidvar">
</form>
<br/><a href="index.php?showall=1">Vis siste 100</a>
<br/><a href="index.php?m_c=mfa">Arkiv</a>
<br/><a href="rss.xml?type=flash">RSS</a>
</div>
<?
}
function module_archive(){
echo "<!-- start archive -->";
global $months;
$query = "SELECT DATE_FORMAT(date_posted, '%m') AS Maned, DATE_FORMAT(date_posted, '%c') AS ManedUtenNull, DATE_FORMAT(date_posted, '%Y') AS Ar FROM articles WHERE comment_to IS NULL AND is_draft IS NULL GROUP BY DATE_FORMAT(date_posted, '%m %Y') ORDER BY date_posted DESC;";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
echo '<div class="archive">';
echo '<div class="archive_heading">Arkiv</div>';
if(!$num_results > 0){
echo "Ingen artikler i arkivet.<br/>";
}else{
echo '<div class="archive_list">';
while($row = DB_next_row($result)){
echo '<a href="index.php?searchtype=bymonth&m_c=module_article_search&month=' . $row['Maned'] . '&year=' . $row['Ar'] . '">' . substr($months[$row['ManedUtenNull']],0,3) . ' ' . $row['Ar'] . '</a><br/>';
}
echo '</div>';
}
echo '</div>';
}
function mvp(){
echo "<!-- start view profile -->";
$username = $_REQUEST['username'];
if(!isset($username)){
echo "Ingen gyldig bruker angitt.";
}else{
$query = "SELECT may_post, username, firstname, lastname, webpage, description, birthdate, picture FROM user WHERE username='" . $username . "';";
$query_articles = "SELECT articleid, title, date_posted FROM articles WHERE (date_posted <= '" . date("Y-m-d") . "' OR (time_posted <= '" . date("H:i") . "' AND date_posted <= '" . date("Y-m-d") . "')) AND author_username ='" . $username . "' AND is_deleted IS NULL AND comment_to IS NULL AND (is_draft = 0 OR is_draft IS NULL) ORDER BY date_posted DESC, time_posted DESC";
debug($query_articles);
$result = searchDB($query);
if(!$result){
echo "Fant ikke $username i databasen.";
}else{
echo '<table class="default_table">';
if ($result['picture'] <> "") {
echo "<tr><td><div class=\"default_header\">";
if($result['may_post'] == 1)
echo "Spaltistside: ";
else
echo "Medlemsside: ";
echo $result['firstname'] . " " . $result['lastname'] . " " . "(" . $result['username'] . ")</div></td>";
echo '<td><div class="user_picture"><img src="mod_pic.php?id=' . $result['picture'] . '" alt="' . $result['firstname'] . '" /></div></td>';
echo "</tr>";
} else {
echo "<tr><td colspan=2><div class=\"default_header\">";
if($result['may_post'] == 1)
echo "Spaltistside: ";
else
echo "Medlemsside: ";
echo $result['firstname'] . " " . $result['lastname'] . " " . "(" . $result['username'] . ")</div></td></tr>";
}
// Bad code; edit_profile introduces 1851 instead of 0000 in the DB for no birthdate given
if(!strstr($result['birthdate'], "0000") && !strstr($result['birthdate'], "1851"))
echo "<tr><td>Fødselsdato </td><td>" . date_nor_sql($result['birthdate']) . "</td></tr>";
if(strlen($result['webpage']) > 1){
if(substr($result['webpage'], 0, 4) == "http")
echo "<tr><td>Webside</td><td> <a href=\"" . $result['webpage'] . "\" target=\"_blank\">" . $result['webpage'] . "</a></td></tr>";
else
echo "<tr><td>Webside</td><td> <a href=\"http://" . $result['webpage'] . "\" target=\"_blank\">http://" . $result['webpage'] . "</a></td></tr>";
}
/* Output user statistics */
$statquery = "SELECT COUNT(articleid) AS count FROM articles WHERE is_draft IS NULL AND comment_to IS NULL AND is_deleted IS NULL AND author_username='" . $result['username'] . "';";
$article_count = DB_search($statquery);
if($article_count['count'] > 0)
echo "<tr><td>Artikler</td><td>". $article_count['count']. "</td></tr>";
$statquery = "SELECT COUNT(articleid) AS count FROM articles WHERE is_draft IS NULL AND comment_to IS NOT NULL AND is_deleted IS NULL AND author_username='" . $result['username'] . "';";
$comment_count = DB_search($statquery);
if($comment_count['count'] > 0)
echo "<tr><td>Kommentarer</td><td>". $comment_count['count']. "</td></tr>";
$statquery = "SELECT COUNT(postid) AS count FROM flashforum WHERE author_username='" . $result['username'] . "';";
$flash_count = DB_search($statquery);
if($flash_count['count'] > 0)
echo "<tr><td>Lynforumposter</td><td>". $flash_count['count']. "</td></tr>";
if(strlen($result['description']) > 1)