-
Notifications
You must be signed in to change notification settings - Fork 8
/
admin.pl
executable file
·1733 lines (1448 loc) · 51.1 KB
/
admin.pl
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
#!/usr/bin/perl -w
###############################################################################
# admin.pl - this code runs the site's administrative tasks page
#
# Copyright (C) 1997 Rob "CmdrTaco" Malda
# malda@slashdot.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
# $Id$
###############################################################################
use strict;
use lib '../';
use vars '%I';
use Date::Manip;
use Image::Size;
use Slash;
sub main {
*I = getSlashConf();
getSlash();
getSection('admin');
my($tbtitle);
if ($I{F}{op} =~ /^preview|edit$/ && $I{F}{title}) {
# Show submission title on browser's titlebar.
$tbtitle = $I{F}{title};
$tbtitle =~ s/"/'/g;
$tbtitle = " - \"$tbtitle\"";
# Undef the form title value if we have SID defined since the editor
# will have to get it from the database anyways.
undef $I{F}{title} if $I{F}{sid} && $I{F}{op} eq 'edit';
}
header("backSlash $I{U}{tzcode} $I{U}{offset}$tbtitle", 'admin');
# Admin Menu
print "<P> </P>" unless $I{U}{aseclev};
my $op = $I{F}{op};
if (!$I{U}{aseclev}) {
titlebar('100%', 'back<I>Slash</I> Login');
adminLoginForm();
} elsif ($op eq 'logout') {
$I{dbh}->do('DELETE FROM sessions WHERE aid=' . $I{dbh}->quote($I{U}{aid}));
titlebar('100%', 'back<I>Slash</I> Buh Bye');
adminLoginForm();
} elsif ($I{F}{topicdelete}) {
topicDelete();
topicEd();
} elsif ($I{F}{topicsave}) {
topicSave();
topicEd();
} elsif ($I{F}{topiced} || $op eq 'topiced' || $I{F}{topicnew}) {
topicEd();
} elsif ($op eq 'save') {
saveStory();
} elsif ($op eq 'update') {
updateStory();
} elsif ($op eq 'list') {
titlebar('100%', 'Story List', 'c');
listStories();
} elsif ($op eq 'delete') {
rmStory($I{F}{sid});
listStories();
} elsif ($op eq 'preview') {
editstory('');
} elsif ($op eq 'edit') {
editstory($I{F}{sid});
} elsif ($op eq 'topics') {
listtopics($I{U}{aseclev});
} elsif ($op eq 'colored' || $I{F}{colored} || $I{F}{colorrevert} || $I{F}{colorpreview}) {
colorEdit($I{U}{aseclev});
} elsif ($I{F}{colorsave} || $I{F}{colorsavedef} || $I{F}{colororig}) {
colorSave();
colorEdit($I{U}{aseclev});
} elsif($I{F}{blockdelete_cancel} || $op eq "blocked") {
blockEdit($I{U}{aseclev},$I{F}{bid});
} elsif($I{F}{blocknew}) {
blockEdit($I{U}{aseclev});
} elsif($I{F}{blocked1}) {
blockEdit($I{U}{aseclev}, $I{F}{bid1});
} elsif($I{F}{blocked2}) {
blockEdit($I{U}{aseclev}, $I{F}{bid2});
} elsif($I{F}{blocksave} || $I{F}{blocksavedef}) {
blockSave($I{F}{thisbid});
blockEdit($I{U}{aseclev}, $I{F}{thisbid});
} elsif($I{F}{blockrevert}) {
blockRevert($I{F}{thisbid});
blockEdit($I{U}{aseclev}, $I{F}{thisbid});
} elsif($I{F}{blockdelete}) {
blockEdit($I{U}{aseclev},$I{F}{thisbid});
} elsif($I{F}{blockdelete1}) {
blockEdit($I{U}{aseclev},$I{F}{bid1});
} elsif($I{F}{blockdelete2}) {
blockEdit($I{U}{aseclev},$I{F}{bid2});
} elsif($I{F}{blockdelete_confirm}) {
blockDelete($I{F}{deletebid});
blockEdit($I{U}{aseclev});
} elsif ($op eq 'authors') {
authorEdit($I{F}{thisaid});
} elsif ($I{F}{authoredit}) {
authorEdit($I{F}{myaid});
} elsif ($I{F}{authornew}) {
authorEdit();
} elsif ($I{F}{authordelete}) {
authorDelete($I{F}{myaid});
} elsif ($I{F}{authordelete_confirm} || $I{F}{authordelete_cancel}) {
authorDelete($I{F}{thisaid});
authorEdit();
} elsif ($I{F}{authorsave}) {
authorSave();
authorEdit($I{F}{myaid});
} elsif ($op eq 'vars') {
varEdit($I{F}{name});
} elsif ($op eq 'varsave') {
varSave();
varEdit($I{F}{name});
} elsif ($op eq "listfilters") {
titlebar("100%","List of comment filters","c");
listFilters();
} elsif ($I{F}{editfilter}) {
titlebar("100%","Edit Comment Filter","c");
editFilter($I{F}{filter_id});
} elsif ($I{F}{updatefilter}) {
updateFilter("update");
} elsif ($I{F}{newfilter}) {
updateFilter("new");
} elsif ($I{F}{deletefilter}) {
updateFilter("delete");
} else {
titlebar('100%', 'Story List', 'c');
listStories();
}
writelog('admin', $I{U}{aid}, $op, $I{F}{sid});
# Display who is logged in right now.
footer();
# zero the refresh flag
# and undef sid sequence array
if ($I{story_refresh}) {
$I{story_refresh} = 0;
# garbage collection
undef $I{sid_array};
}
# zero the order count
$I{StoryCount} = 0;
}
##################################################################
# Misc
sub adminLoginForm {
print "\n<!-- begin admin login form -->\n<CENTER>",
$I{query}->startform(-method => 'POST', -action => $ENV{SCRIPT_NAME}),
$I{query}->hidden(-name => 'op', -default => 'adminlogin', -override => 1),
'<TABLE><TR><TD ALIGN="RIGHT">Login</TD>
<TD>', $I{query}->textfield(-name => 'aaid'), "</TD></TR>",
'<TR><TD ALIGN="RIGHT">Password</TD>
<TD>', $I{query}->password_field(-name => 'apasswd'),"</TD></TR>",
'<TD> </TD><TD><INPUT TYPE="SUBMIT" VALUE="Login"></TD>
</TR></TABLE>',
$I{query}->endform,
"</CENTER>\n<!-- end admin login form -->\n";
}
##################################################################
# Variables Editor
sub varEdit {
my($name) = @_;
print qq[\n<!-- begin variables editor form -->\n<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">\n];
selectGeneric('vars', 'name', 'name', 'name', $name);
my($value, $desc) = sqlSelect('value,description',
'vars', "name='$name'");
print "Next<BR>\n",
formLabel('Variable Name'),
$I{query}->textfield(-name => 'thisname', -default => $name),
formLabel('Value'),
$I{query}->textfield(-name => 'value',-default => $value),
formLabel('Description'),
$I{query}->textfield(-name => 'desc', -default => $desc, -size => 60),
qq'<INPUT TYPE="SUBMIT" VALUE="varsave" NAME="op">
</FORM><!-- end variables editor form -->\n';
}
##################################################################
sub varSave {
if ($I{F}{thisname}) {
my($exists) = sqlSelect('count(*)', 'vars',
"name='$I{F}{thisname}'"
);
if ($exists == 0) {
sqlInsert('vars', { name => $I{F}{thisname} });
print "Inserted $I{F}{thisname}<BR>\n";
}
if($I{F}{desc}) {
print "Saved $I{F}{thisname}<BR>\n";
sqlUpdate("vars", {
value => $I{F}{value},
description => $I{F}{desc}
}, "name=" . $I{dbh}->quote($I{F}{thisname})
);
} else {
print "<B>Deleted $I{F}{thisname}!</B><BR>\n";
$I{dbh}->do("DELETE from vars WHERE name='$I{F}{thisname}'");
}
}
}
##################################################################
# Author Editor
sub authorEdit {
my ($aid) = @_;
return if $I{U}{aseclev} < 500;
$aid ||= $I{U}{aid};
$aid = '' if $I{F}{authornew};
my ($name,$url,$email,$quote,$copy,$pwd,$seclev,$section);
print qq!<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">!;
selectGeneric('authors', 'myaid', 'aid', 'aid', $aid);
if($aid) {
($name,$url,$email,$quote,$copy,$pwd,$seclev,$section) =
sqlSelect('name,url,email,quote,copy,pwd,seclev,section', 'authors','aid ='. $I{dbh}->quote($aid));
}
for ($quote, $copy) {
$_ = stripByMode($_, 'literal', 1);
}
print <<EOT;
<INPUT TYPE="submit" VALUE="Select Author" NAME="authoredit"><BR>
<TABLE BORDER="0">
<TR>
<TD>Aid</TD><TD><INPUT TYPE="text" NAME="thisaid" VALUE="$aid"></TD>
</TR>
<TR>
<TD>Name</TD><TD><INPUT TYPE="text" NAME="name" VALUE="$name"></TD>
</TR>
<TR>
<TD>URL</TD><TD><INPUT TYPE="text" NAME="url" VALUE="$url"></TD>
</TR>
<TR>
<TD>Email</TD><TD><INPUT TYPE="text" NAME="email" VALUE="$email"></TD>
</TR>
<TR>
<TD>Quote</TD><TD><TEXTAREA NAME="quote" COLS="50" ROWS="4">$quote</TEXTAREA></TD>
</TR>
<TR>
<TD>Copy</TD><TD><TEXTAREA NAME="copy" COLS="50" ROWS="5">$copy</TEXTAREA></TD>
</TR>
<TR>
<TD>Passwd</TD><TD><INPUT TYPE="password" NAME="pwd" VALUE="$pwd"></TD>
</TR>
<TR>
<TD>Seclev</TD><TD><INPUT TYPE="text" NAME="seclev" VALUE="$seclev"></TD>
</TR>
</TABLE>
Restrict to Section
EOT
selectSection('section', $section) ;
print <<EOT;
<TABLE BORDER="0">
<TR>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Save Author" NAME="authorsave"></TD>
EOT
print <<EOT if ! $I{F}{authornew};
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Create Author" NAME="authornew"></TD>
EOT
print <<EOT if (! $I{F}{authornew} && $aid ne $I{U}{aid}) ;
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Delete Author" NAME="authordelete"></TD>
EOT
print qq|\t</TR>\n</TABLE>\n</FORM>\n|;
}
##################################################################
sub authorSave {
return if $I{U}{aseclev} < 500;
if ($I{F}{thisaid}) {
my($exists) = sqlSelect('count(*)', 'authors',
'aid=' . $I{dbh}->quote($I{F}{thisaid})
);
if (!$exists) {
sqlInsert('authors', { aid => $I{F}{thisaid}});
print "Inserted $I{F}{thisaid}<BR>";
}
if ($I{F}{thisaid}) {
print "Saved $I{F}{thisaid}<BR>";
sqlUpdate('authors',{
name => $I{F}{name},
pwd => $I{F}{pwd},
email => $I{F}{email},
url => $I{F}{url},
seclev => $I{F}{seclev},
copy => $I{F}{copy},
quote => $I{F}{quote},
section => $I{F}{section}
}, 'aid=' . $I{dbh}->quote($I{F}{thisaid})
);
} else {
print "<B>Deleted $I{F}{thisaid}!</B><BR>";
$I{dbh}->do('DELETE from authors WHERE aid='
. $I{dbh}->quote($I{F}{thisaid})
);
}
}
}
##################################################################
sub authorDelete {
return if $I{U}{aseclev} < 500;
my $aid = shift;
print qq|<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">|;
print <<EOT if $I{F}{authordelete};
<B>Do you really want to delete $aid?</B><BR>
<INPUT TYPE="HIDDEN" VALUE="$aid" NAME="thisaid">
<INPUT TYPE="SUBMIT" VALUE="Cancel delete $aid" NAME="authordelete_cancel">
<INPUT TYPE="SUBMIT" VALUE="Delete $aid" NAME="authordelete_confirm">
EOT
if ($I{F}{authordelete_confirm}) {
$I{dbh}->do('DELETE from authors WHERE aid=' . $I{dbh}->quote($aid));
print "<B>Deleted $aid!</B><BR>" if ! DBI::errstr;
}
elsif($I{F}{authordelete_cancel}) {
print "<B>Canceled Deletion of $aid!</B><BR>";
}
}
##################################################################
# Block Editing and Saving
# 020300 PMG modified the heck out of this code to allow editing
# of sectionblock values retrieve, title, url, rdf, section
# to display a different form according to the type of block we're dealing with
# based on value of new column in blocks "type". Added description field to use
# as information on the block to help the site editor get a feel for what the block
# is for, etc...
sub blockEdit {
my($seclev, $bid) = @_;
return if $seclev < 500;
my($hidden_bid) = "";
my($title,$url,$rdf,$ordernum,$retrieve,$section,$portal,$saveflag,$isabid);
titlebar("100%","Site Block Editor","c");
print <<EOT;
<!-- begin block editing form -->
<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">
EOT
if(! $I{F}{blockdelete} && ! $I{F}{blockdelete1} && ! $I{F}{blockdelete2}) {
print <<EOT;
<P>Select a block to edit.
<UL>
<LI>You can only edit static blocks.</LI>
<LI>Blocks that are portald type blocks are written by portald</LI>
</UL>
</P>
<TABLE>
<TR>
<TD><B>Static Blocks</B></TD><TD>
EOT
# get the static blocks
selectGeneric('blocks', 'bid1', 'bid', 'bid', $bid, "$seclev >= seclev and type != 'portald'");
print qq[</TD><TD><INPUT TYPE="SUBMIT" VALUE="Edit Block" NAME="blocked1"></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Delete Block" NAME="blockdelete1"></TD>\n\t</TR>\n];
# get the portald blocks
print qq[\t<TR><TD><B>Portald Blocks</B></TD><TD>];
selectGeneric('blocks', 'bid2', 'bid', 'bid', $bid, "$seclev >= seclev and type = 'portald'");
print qq[</TD><TD><INPUT TYPE="SUBMIT" VALUE="Edit Block" NAME="blocked2"></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Delete Block" NAME="blockdelete2"></TD>\n\t</TR>\n</TABLE>\n];
}
if($I{F}{blockdelete} || $I{F}{blockdelete1} || $I{F}{blockdelete2}) {
print <<EOT;
<INPUT TYPE="HIDDEN" NAME="deletebid" VALUE="$bid">
<TABLE BORDER="0">
<TR>
<TD><B>Do you really want to delete Block $bid?</B></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Cancel Delete of $bid" NAME="blockdelete_cancel"></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Really Delete $bid!" NAME="blockdelete_confirm"></TD>
</TR>
</TABLE>
EOT
}
# if the pulldown has been selected and submitted
# or this is a block save and the block is a portald block
# or this is a block edit via sections.pl
if (! $I{F}{blocknew} && $bid ) {
($isabid,$title,$url,$rdf,$ordernum,$retrieve,$section,$portal) = sqlSelect('bid,title,url,rdf,ordernum,retrieve,section,portal', 'sectionblocks', "bid='$bid'");
if ($isabid) {
$title = qq[<TR>\n\t\t<TD><B>Title</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="title" VALUE="$title"></TD>\n\t</TR>];
$url = qq[<TR>\n\t\t<TD><B>URL</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="url" VALUE="$url"></TD>\n\t</TR>];
$rdf = qq[<TR>\n\t\t<TD><B>RDF</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="rdf" VALUE="$rdf"></TD>\n\t</TR>];
$section = qq[<TR>\n\t\t<TD><B>Section</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="10" NAME="section" VALUE="$section"></TD>\n\t</TR>];
$ordernum = "NA" if $ordernum eq '';
$ordernum = qq[<TR>\n\t\t<TD><B>Ordernum</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="3" NAME="ordernum" VALUE="$ordernum"></TD>\n\t</TR>];
my $checked = "CHECKED" if $retrieve == 1;
$retrieve = qq[<TR>\n\t\t<TD><B>Retrieve</B></TD><TD COLSPAN="2"><INPUT TYPE="CHECKBOX" VALUE="1" NAME="retrieve" $checked></TD>\n\t</TR>];
$checked = "";
$checked = "CHECKED" if $portal == 1;
$portal = qq[<TR>\n\t\t<TD><B>Portal - check if this is a slashbox.</B></TD><TD COLSPAN="2"><INPUT TYPE="CHECKBOX" VALUE="1" NAME="portal" $checked></TD>\n\t</TR>];
$saveflag = qq[<INPUT TYPE="HIDDEN" NAME="save_existing" VALUE="1">];
$checked = "";
}
}
# if this is a new block, we want an empty form
else {
$title = qq[<TR>\n\t\t<TD><B>Title</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="title" VALUE=""></TD>\n\t</TR>];
$url = qq[<TR>\n\t\t<TD><B>URL</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="url" VALUE=""></TD>\n\t</TR>];
$rdf = qq[<TR>\n\t\t<TD><B>RDF</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="70" NAME="rdf" VALUE=""></TD>\n\t</TR>];
$section = qq[<TR>\n\t\t<TD><B>Section</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="10" NAME="section" VALUE=""></TD>\n\t</TR>];
$ordernum = qq[<TR>\n\t\t<TD><B>Ordernum</B></TD><TD COLSPAN="2"><INPUT TYPE="TEXT" SIZE="3" NAME="ordernum" VALUE=""></TD>\n\t</TR>];
$retrieve = qq[<TR>\n\t\t<TD><B>Retrieve</B></TD><TD COLSPAN="2"><INPUT TYPE="CHECKBOX" VALUE="1" NAME="retrieve"></TD>\n\t</TR>];
$portal = qq[<TR>\n\t\t<TD><B>Portal - check if this is a slashbox. </B></TD><TD COLSPAN="2"><INPUT TYPE="CHECKBOX" VALUE="1" NAME="portal"></TD>\n\t</TR>];
$saveflag = qq[<INPUT TYPE="HIDDEN" NAME="save_new" VALUE="1">];
}
my($block, $bseclev, $type, $description) =
sqlSelect('block,seclev,type,description', 'blocks', "bid='$bid'") if $bid;
my $description_ta = stripByMode($description, 'literal', 1);
$block = stripByMode($block, 'literal', 1);
# main table
print <<EOT;
<TABLE BORDER="0">
EOT
# if there's a block description, print it
print <<EOT if ($description);
<TR>
<TD COLSPAN="3">
<TABLE BORDER="2" CELLPADDING="4" CELLSPACING="0" BGCOLOR="$I{fg}[1]" WIDTH="80%">
<TR>
<TD BGCOLOR="$I{bg}[2]"><BR><B>Block ID: $bid</B><BR>
<P>$description</P><BR>
</TD>
</TR>
</TABLE>
<BR>
</TD>
</TR>
EOT
# print the form if this is a new block, submitted block, or block edit via sections.pl
print <<EOT if ( (! $I{F}{blockdelete_confirm} && $bid) || $I{F}{blocknew}) ;
<TR>
<TD><B>Block ID</B></TD>
<TD><INPUT TYPE="TEXT" NAME="thisbid" VALUE="$bid"></TD>
</TR>
$title
<TR>
<TD><B>Seclev</B></TD><TD><INPUT TYPE="TEXT" NAME="bseclev" VALUE="$bseclev" SIZE="6"></TD>
</TR>
<TR>
<TD><B>Type</B></TD><TD><INPUT TYPE="TEXT" NAME="type" VALUE="$type" SIZE="10"></TD>
</TR>
$section
$ordernum
$portal
$retrieve
$url
$rdf
$saveflag
<TR>
<TD VALIGN="TOP"><B>Description</B></TD>
<TD ALIGN="left" COLSPAN="2">
<TEXTAREA ROWS="6" COLS="70" NAME="description">$description_ta</TEXTAREA>
</TD>
</TR>
<TR>
<TD VALIGN="TOP"><B>Block</B><BR>
<P>
<INPUT TYPE="SUBMIT" VALUE="Save Block" NAME="blocksave"><BR>
<INPUT TYPE="SUBMIT" NAME="blockrevert" VALUE="Revert to default">
<BR><INPUT TYPE="SUBMIT" NAME="blocksavedef" VALUE="Save as default">
(Make sure this is what you want!)
</P>
</TD>
<TD ALIGN="left" COLSPAN="2">
<TEXTAREA ROWS="15" COLS="100" NAME="block">$block</TEXTAREA>
</TD>
</TR>
EOT
# print the delete button if this is anything other than
# a new form, or initial submission from author menu
print <<EOT if (! $I{F}{blocknew} && $I{F}{blockdelete_cancel} && ! $I{F}{blockdelete} && ! $I{F}{blockdelete1} && ! $I{F}{blockdelete2});
<TR>
<TD COLSPAN="3">
<INPUT TYPE="SUBMIT" VALUE="Delete Block" NAME="blockdelete"></P>
</TD>
</TR>
EOT
# print the new block if this isn't already a new block
print <<EOT if (! $I{F}{blocknew});
<TR>
<TD COLSPAN="3">
<INPUT TYPE="SUBMIT" VALUE="Create a new block" NAME="blocknew"></P>
</TD>
</TR>
EOT
print <<EOT;
</TABLE>
</FORM>
<!-- end block editing form -->
EOT
my $c = sqlSelectMany('section', 'sectionblocks', "bid='$bid'");
while (my($section) = $c->fetchrow) {
print <<EOT;
<B><A HREF="$I{rootdir}/sections.pl?section=$section&op=editsection">$section</A></B>
(<A HREF="$I{rootdir}/users.pl?op=preview&bid=$bid">preview</A>)
EOT
}
$c->finish;
}
##################################################################
sub blockRevert {
my $bid = shift;
return if $I{U}{aseclev} < 500;
$I{dbh}->do("update blocks set block = blockbak where bid = '$bid'");
}
##################################################################
sub blockSave {
my $bid = shift;
return if $I{U}{aseclev} < 500;
if ($bid) {
my ($rows) = sqlSelect('count(*)', 'blocks', 'bid=' . $I{dbh}->quote($bid));
if ($I{F}{save_new} && $rows > 0) {
print qq[<P><B>This block, $bid, already exists! <BR>Hit the "back" button, and try another bid (look at the blocks pulldown to see if you are using an existing one.)</P>];
return;
}
if ($rows == 0) {
sqlInsert('blocks', { bid => $bid, seclev => 500 });
sqlInsert('sectionblocks', { bid => $bid });
print "Inserted $bid<BR>";
}
my ($portal,$retrieve) = (0,0);
# this is to make sure that a static block doesn't get
# saved with retrieve set to true
$I{F}{retrieve} = 0 if $I{F}{type} ne 'portald';
print "Saved $bid<BR>";
$I{F}{block} = autoUrl($I{F}{section}, $I{F}{block});
if ($rows == 0 || $I{F}{blocksavedef}) {
sqlUpdate('blocks', {
seclev => $I{F}{bseclev},
block => $I{F}{block},
blockbak => $I{F}{block},
description => $I{F}{description},
type => $I{F}{type},
}, 'bid=' . $I{dbh}->quote($bid)
);
} else {
sqlUpdate('blocks', {
seclev => $I{F}{bseclev},
block => $I{F}{block},
description => $I{F}{description},
type => $I{F}{type},
}, 'bid=' . $I{dbh}->quote($bid)
);
}
sqlUpdate('sectionblocks', {
ordernum=> $I{F}{ordernum},
title => $I{F}{title},
url => $I{F}{url},
rdf => $I{F}{rdf},
section => $I{F}{section},
retrieve=> $I{F}{retrieve},
portal => $I{F}{portal},
}, 'bid=' . $I{dbh}->quote($bid)
);
}
}
##################################################################
sub blockDelete {
my $bid = shift;
return if $I{U}{aseclev} < 500;
print "<B>Deleted $bid!</B><BR>";
$I{dbh}->do('DELETE from blocks WHERE bid=' . $I{dbh}->quote($bid));
$I{dbh}->do('DELETE from sectionblocks WHERE bid=' . $I{dbh}->quote($bid));
}
##################################################################
sub colorEdit {
return if $I{U}{aseclev} < 500;
my $colorblock;
$I{F}{color_block} ||= 'colors';
if($I{F}{colorpreview}) {
$colorblock =
"$I{F}{fg0},$I{F}{fg1},$I{F}{fg2},$I{F}{fg3},$I{F}{bg0},$I{F}{bg1},$I{F}{bg2},$I{F}{bg3}";
my $colorblock_clean = $colorblock;
# the #s will break the url
$colorblock_clean =~ s/#//g;
print <<EOT
<br>
<a href="$I{rootdir}/index.pl?colorblock=$colorblock_clean">
<p><b>Click here to see the site in these colors!</a></b>
(Hit the <b>"back"</b> button to get back to this page.)</p>
EOT
} else {
($colorblock) = sqlSelect('block', 'blocks', "bid='$I{F}{color_block}'");
}
my @colors = split m/,/, $colorblock;
$I{fg} = [@colors[0..3]];
$I{bg} = [@colors[4..7]];
print "<P>You may need to reload the page a couple of times to see a change in the color scheme.
<BR>If you can restart the webserver, that's the quickest way to see your changes.</P>";
titlebar("100%","Site Color Editor","c");
print <<EOT;
<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">
<P>Shown are the site colors. If you make a change to any one of them,
you will need to restart the webserver for the change(s) to show up.</P>
<P>Note: make sure you use a valid color value, or the color will not work properly.</P>
Select the color block to edit:
EOT
selectGeneric('blocks', 'color_block', 'bid', 'bid', $I{F}{color_block}, "type = 'color'");
print <<EOT;
<INPUT TYPE="submit" name="colored" value="Edit Colors">
EOT
print <<EOT if $I{F}{color_block};
<TABLE BORDER="0">
<TR>
<TD>Foreground color 0 \$I{fg}[0]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="fg0" VALUE="$colors[0]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[0]">Foreground color 0 \$I{fg}[0]</FONT></TD>
<TD BGCOLOR="$colors[0]"> </TD>
</TR>
<TR>
<TD>Foreground color 1 \$I{fg}[1]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="fg1" VALUE="$colors[1]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[1]">Foreground color 1 \$I{fg}[1]</FONT></TD>
<TD BGCOLOR="$colors[1]"> </TD>
</TR>
<TR>
<TD>Foreground color 2 \$I{fg}[2]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="fg2" VALUE="$colors[2]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[2]">Foreground color 2 \$I{fg}[2]</FONT></TD>
<TD BGCOLOR="$colors[2]"> </TD>
</TR>
<TR>
<TD>Foreground color 3 \$I{fg}[3]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="fg3" VALUE="$colors[3]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[3]">Foreground color 3 \$I{fg}[3]</FONT></TD>
<TD BGCOLOR="$colors[3]"> </TD>
</TD>
<TR>
<TD>Background color 0 \$I{bg}[0]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="bg0" VALUE="$colors[4]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[4]">Background color 0 \$I{bg}[0]</FONT></TD>
<TD BGCOLOR="$colors[4]"> </TD>
</TR>
<TR>
<TD>Background color 1 \$I{bg}[1]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="bg1" VALUE="$colors[5]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[5]">Background color 1 \$I{bg}[1]</FONT></TD>
<TD BGCOLOR="$colors[5]"> </TD>
</TD>
<TR>
<TD>Background color 2 \$I{bg}[2]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="bg2" VALUE="$colors[6]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[6]">Background color 2 \$I{bg}[2]</FONT></TD>
<TD BGCOLOR="$colors[6]"> </TD>
</TR>
<TR>
<TD>Background color 3 \$I{bg}[3]</TD>
<TD><INPUT TYPE="TEXT" WIDTH="12" NAME="bg3" VALUE="$colors[7]"></TD>
<TD><FONT FACE="ARIAL,HELVETICA" SIZE="+1" COLOR="$colors[7]">Background color 3 \$I{bg}[3]</FONT></TD>
<TD BGCOLOR="$colors[7]"> </TD>
</TR>
<TR>
<TD><INPUT TYPE="SUBMIT" NAME="colorpreview" VALUE="Preview"></TD>
<TD><INPUT TYPE="SUBMIT" NAME="colorsave" VALUE="Save Colors"></TD>
<TD><INPUT TYPE="SUBMIT" NAME="colorrevert" VALUE="Revert to saved"></TD>
<TD><INPUT TYPE="SUBMIT" NAME="colororig" VALUE="Revert to default">
<BR><INPUT TYPE="SUBMIT" NAME="colorsavedef" VALUE="Save as default">
(Make sure this is what you want!)
</TD>
</TR>
</TABLE>
</FORM>
EOT
}
##################################################################
sub colorSave {
return if $I{U}{aseclev} < 500;
my $colorblock =
"$I{F}{fg0},$I{F}{fg1},$I{F}{fg2},$I{F}{fg3},$I{F}{bg0},$I{F}{bg1},$I{F}{bg2},$I{F}{bg3}";
$I{F}{color_block} ||= 'colors';
if($I{F}{colorsave}) {
# save into colors and colorsback
sqlUpdate('blocks', {
block => $colorblock,
}, "bid = '$I{F}{color_block}'"
);
}
elsif($I{F}{colorsavedef}) {
# save into colors and colorsback
sqlUpdate('blocks', {
block => $colorblock,
blockbak => $colorblock,
}, "bid = '$I{F}{color_block}'"
);
}
elsif($I{F}{colororig}) {
# reload original version of colors
$I{dbh}->do("update blocks set block = blockbak where bid = '$I{F}{color_block}'");
}
}
##################################################################
# Topic Editor
sub topicEd {
return if $I{U}{aseclev} < 1;
my ($tid, $width, $height, $alttext, $image, @available_images);
opendir(DIR,"$I{basedir}/images/topics");
@available_images = grep(!/^\./, readdir(DIR));
closedir(DIR);
print <<EOT;
<!-- begin topic editor form -->
<FORM ACTION="$ENV{SCRIPT_NAME}" METHOD="POST">
EOT
selectGeneric('topics', 'nexttid', 'tid', 'tid', $I{F}{nexttid});
print '<INPUT TYPE="SUBMIT" NAME="topiced" VALUE="Select topic"><BR>';
print '<INPUT TYPE="SUBMIT" NAME="topicnew" VALUE="Create new topic"><BR>';
if(! $I{F}{topicdelete}) {
if(! $I{F}{topicnew}) {
($tid, $width, $height, $alttext, $image) =
sqlSelect( 'tid,width,height,alttext,image', 'topics', "tid='$I{F}{nexttid}'");
} else {
($tid, $width, $height, $alttext, $image) = ('new topic','','','','');
}
print qq'<BR>Image as seen: <BR><BR><IMG SRC="$I{imagedir}/topics/$image" ALT="$alttext" WIDTH="$width" HEIGHT="$height">'
if ( $I{F}{nexttid} && ! $I{F}{topicnew} && ! $I{F}{topicdelete});
print <<EOT;
<BR><BR>Tid<BR><INPUT TYPE="TEXT" NAME="tid" VALUE="$tid"><BR>
<BR>Dimensions (leave blank to determine automatically)<BR>
Width: <INPUT TYPE="TEXT" NAME="width" VALUE="$width" SIZE="4">
Height: <INPUT TYPE="TEXT" NAME="height" VALUE="$height" SIZE="4"><BR>
<BR>Alt Text<BR>
<INPUT TYPE="TEXT" NAME="alttext" VALUE="$alttext"><BR>
<BR>Image<BR>
EOT
if (@available_images) {
print qq|<SELECT name="image">|;
print qq|<OPTION value="">Select an image</OPTION>| if $I{F}{topicnew};
for(@available_images) {
my ($selected);
$selected = "SELECTED" if ($_ eq $image);
print qq|<OPTION value="$_" $selected>$_</OPTION>\n|;
$selected = '';
}
print '</SELECT>';
} else {
# If we don't have images in the proper place, print a message
# and use a regular text input field.
print <<EOT;
<P>No images were found in the topic images directory (<basedir>/images/topics).<BR>
<INPUT TYPE="TEXT" NAME="image" VALUE="$image"><BR><BR>
EOT
}
print <<EOT;
<INPUT TYPE="SUBMIT" NAME="topicsave" VALUE="Save Topic">
<INPUT TYPE="SUBMIT" NAME="topicdelete" VALUE="Delete Topic">
EOT
}
print qq|</FORM>\n<!-- end topic editor form -->\n|;
}
##################################################################
sub topicDelete {
my $tid = shift || $I{F}{tid};
print "<B>Deleted $tid!</B><BR>";
$I{dbh}->do('DELETE from topics WHERE tid=' . $I{dbh}->quote($tid));
$I{F}{tid} = '';
}
##################################################################
sub topicSave {
if ($I{F}{tid}) {
my($rows) = sqlSelect('count(*)', 'topics', 'tid=' . $I{dbh}->quote($I{F}{tid}));
if (!$I{F}{width} && !$I{F}{height}) {
@{ $I{F} }{'width', 'height'} = imgsize("$I{basedir}/images/topics/$I{F}{image}");
}
if($rows == 0 ) {
sqlInsert('topics', {
tid => $I{F}{tid},
image => $I{F}{image},
alttext => $I{F}{alttext},
width => $I{F}{width},
height => $I{F}{height}
}
);
}
sqlUpdate('topics', {
image => $I{F}{image},
alttext => $I{F}{alttext},
width => $I{F}{width},
height => $I{F}{height}
}, 'tid=' . $I{dbh}->quote($I{F}{tid})
);
}
print "<B>Saved $I{F}{tid}!</B><BR>" if ! DBI::errstr;
$I{F}{nexttid} = $I{F}{tid};
}
##################################################################
sub listtopics {
my($seclev) = @_;
my $cursor = $I{dbh}->prepare('SELECT tid,image,alttext,width,height
FROM topics
ORDER BY tid');
titlebar('100%', 'Topic Lister');
my $x = 0;
$cursor->execute;
print qq[\n<!-- begin listtopics -->\n<TABLE WIDTH="600" ALIGN="CENTER">];
while (my($tid, $image, $alttext, $width, $height) = $cursor->fetchrow) {
if ($x == 0) {
print "<TR>\n";
} elsif ($x++ % 6) {
print "</TR><TR>\n";
}
print qq!\t<TD ALIGN="CENTER">\n!;
if ($seclev > 500) {
print qq[\t\t<A HREF="$ENV{SCRIPT_NAME}?op=topiced&nexttid=$tid">];
} else {
print qq[\t\t<A NAME="">];
}
print qq[<IMG SRC="$I{imagedir}/topics/$image" ALT="$alttext"
WIDTH="$width" HEIGHT="$height" BORDER="0"><BR>$tid</A>\n\t</TD>\n];
}
$cursor->finish();
print "</TR></TABLE>\n<!-- end listtopics -->\n";
}
##################################################################
# autoUrl & Helper Functions
# Image Importing, Size checking, File Importing etc
sub getUrlFromTitle {
my($title) = @_;
my($section, $sid) = sqlSelect('section,sid', 'stories',
qq[title like "\%$title%"],
'order by time desc LIMIT 1'
);
return "$I{rootdir}/article.pl?sid=$sid";
}
##################################################################
sub importImage {
# Check for a file upload
my $section = $_[0];
my $filename = $I{query}->param('importme');
my $tf = getsiddir() . $filename;
$tf =~ s|/|~|g;
$tf = "$section~$tf";
if ($filename) {
local *IMAGE;
system("mkdir /tmp/slash");
open(IMAGE, ">>/tmp/slash/$tf");
my $buffer;
while (read $filename, $buffer, 1024) {
print IMAGE $buffer;
}
close IMAGE;
} else {
return "<image:not found>";
}
use imagesize;
my($w, $h) = imagesize::imagesize("/tmp/slash/$tf");
return qq[<IMG SRC="$I{rootdir}/$section/] . getsiddir() . $filename
. qq[" WIDTH="$w" HEIGHT="$h" ALT="$section">];
}
##################################################################
sub importFile {
# Check for a file upload
my $section = $_[0];
my $filename = $I{query}->param('importme');
my $tf = getsiddir() . $filename;
$tf =~ s|/|~|g;
$tf = "$section~$tf";
if ($filename) {