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
|
#!/usr/bin/perl -w
# This code is a part of Slash, and is released under the GPL.
# Copyright 1997-2001 by Open Source Development Network. See README
# and COPYING for more information, or see http://slashcode.com/.
# $Id: sections.pl,v 1.5.2.4 2001/12/17 17:55:38 pudge Exp $
use strict;
use Slash;
use Slash::Display;
use Slash::Utility;
#################################################################
sub main {
my $user = getCurrentUser();
my $form = getCurrentForm();
my $op = $form->{op};
my $seclev = $user->{seclev};
if ($seclev < 100) {
my $rootdir = getCurrentStatic('rootdir');
redirect("$rootdir/users.pl");
return;
}
header(getData('head'), 'admin');
if ($op eq 'rmsub' && $seclev >= 100) { # huh?
} elsif ($form->{addsection}) {
titlebar('100%', getData('addhead'));
editSection();
} elsif ($form->{deletesection} || $form->{deletesection_cancel} || $form->{deletesection_confirm}) {
delSection($form->{section});
listSections($user);
} elsif ($op eq 'editsection' || $form->{editsection}) {
titlebar('100%', getData('edithead'));
editSection($form->{section});
} elsif ($form->{savesection}) {
titlebar('100%', getData('savehead'));
saveSection($form->{section});
listSections($user);
} elsif ((! defined $op || $op eq 'list') && $seclev >= 500) {
titlebar('100%', getData('listhead'));
listSections($user);
}
footer();
}
#################################################################
sub listSections {
my($user) = @_;
my $slashdb = getCurrentDB();
if ($user->{section}) {
editSection($user->{section});
return;
}
slashDisplay('listSections', {
sections => $slashdb->getSectionTitle()
});
}
#################################################################
sub delSection {
my($section) = @_;
my $slashdb = getCurrentDB();
my $form = getCurrentForm();
if ($form->{deletesection}) {
slashDisplay('delSection', {
section => $section
});
} elsif ($form->{deletesection_cancel}) {
slashDisplay('delSectCancel', {
section => $section
});
} elsif ($form->{deletesection_confirm}) {
slashDisplay('delSectConfirm', {
section => $section,
title => "Deleted $section Section",
width => '100%'
});
$slashdb->deleteSection($section);
}
}
#################################################################
sub editSection {
my($section) = @_;
my $slashdb = getCurrentDB();
my $user = getCurrentUser();
my $form = getCurrentForm();
my(@blocks, $this_section);
if ($form->{addsection}) {
$this_section = {};
} else {
$this_section = $slashdb->getSection($section);
my $blocks = $slashdb->getSectionBlock($section);
for (@$blocks) {
my $block = $blocks[@blocks] = {};
@{$block}{qw(section bid ordernum title portal url)} = @$_;
$block->{title} =~ s/<(.*?)>//g;
}
}
my $qid = createSelect('qid', $slashdb->getPollQuestions(),
$this_section->{qid}, 1);
my $isolate = createSelect('isolate', $slashdb->getDescriptions('isolatemodes'),
$this_section->{isolate}, 1);
my $issue = createSelect('issue', $slashdb->getDescriptions('issuemodes'),
$this_section->{issue}, 1);
slashDisplay('editSection', {
section => $section,
this_section => $this_section,
qid => $qid,
isolate => $isolate,
issue => $issue,
blocks => \@blocks,
topics => $slashdb->getSectionTopicsNamesBySection($section),
});
}
#################################################################
sub saveSection {
my($section) = @_;
my $slashdb = getCurrentDB();
my $form = getCurrentForm();
# Non alphanumerics are not allowed in the section key.
# And I don't see a reason for underscores either, but
# dashes should be allowed.
$section =~ s/[^A-Za-z0-9\-]//g;
my($count, $ok1, $ok2) = $slashdb->setSection(
@{$form}{qw(section qid title issue isolate artcount)}
);
unless ($ok1) {
print getData('insert', { section => $section });
}
unless ($ok2) {
print getData('update', { section => $section });
}
}
#################################################################
createEnvironment();
main();
1;
|