summaryrefslogtreecommitdiff
path: root/cgi-bin/artist.plx
blob: cb6ea2970f9c55f38aa623872a30d53b98f574d8 (plain)
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
#!c:/perl/bin/perl

use CGI;
use strict;
use Search;
use Globals;
use Globals qw($delim);
use Globals qw($debug);
use Globals qw(%PLATTERS);
use Globals qw($target);
use Globals qw($bgcolour);

my $query     = CGI::new();
my $artist    = $query->param( "name" );
$artist =~ s/(The |)(.*?)(, The|)/$2/;
my $reqAlbum  = $query->param( "album" );
my $inv       = $query->param( "inv" );
my $target    = $query->cookie("target");
my $webpage;

if ( $target =~ /narrow/ )
{
  $webpage = openTemplate("artistNarrow");
}
else
{
  $webpage = openTemplate("artist");
}

Search::setArtist($artist);
Search::searchFor('album');
Search::setExact(1);
if (length $inv > 0) { Search::setInv(split(',', $inv)) }
else { Search::setInv(keys %PLATTERS) }

my @albums = Search::go() unless !$artist;

my $albumlist;
my $hasMisc;
my $init;
my $index;
my $albumcount;
my $countreport;
my $firstAlbum;
foreach( @albums ) {
    my ($year, $album, $platter) = split($delim);
    my $selected;
    print "$year, $album, $platter\n" if ($debug);
    my $link = 'search.plx?artist='.makeUnNice($artist).'&album='.makeUnNice($album).
        '&exact=1&searchFor=track&inv='.$platter;

    if ($album =~ /^\Q$reqAlbum\E$/) {
        $init = $link.'&output=album';
        $selected = ' selected'; $reqAlbum = 'found';
        }

    $albumcount++;

    if ($album =~ /^Miscellany$/) {
        if (!$hasMisc) {
            $index = $link.'&output=album';
            $hasMisc = 1;
        }
    }
    else {

        $firstAlbum = $link.'&output=album' if (!$firstAlbum);
        $albumlist .= "\n<option value=\"$link\&output=album\"$selected>".makeNice($album);

    }
}

if ($hasMisc) {
    $albumlist = "<option value=\"$index\">Info & Miscellany\n$albumlist";
}
else {
    $index = '/platdoc/emptyAlbum.html' ;
    if ($firstAlbum && !$init) {
        $init = $firstAlbum;
    }
}
$albumlist = "$albumlist\n<option value=\"search.plx?artist=".makeUnNice($artist)."&exact=1&searchFor=track&output=album\">Show all";

if ($albumlist) {
    $albumlist = '<select onChange="switchAlbum(this.options[this.selectedIndex].value)">">'.$albumlist."</select></br>";
    $countreport = "$albumcount found";
}
else {
    $countreport = "None";
}

$init = $index if (!$init);

# abcmanager links
my $rejig;
my %ABCS = getABCs();
my $thisabc = $ABCS{$artist};
if ($artist =~ / / || defined $thisabc) {

    $rejig = '<img src="/platdoc/img/editbutton.png" width=32 height=32 alt="Edit" align="left"><nobr><small>Currently indexed as <br><strong>';

    if (defined $thisabc ) {
        $thisabc =~ s/\.abc.*//;
        $rejig .= makeHTML($thisabc).'</strong><br>'.
            '<a href="abcmanager.plx?artist='.makeUnNice($artist).'&action=remove">Clear</a></small></nobr>';
    }
    else {
        my $newabc = $artist;
        $newabc =~ s/(.*) (.*?)$/$2 $1/;
        $rejig .= makeHTML($artist).'</strong><br>'.
            '<a href="abcmanager.plx?artist='.makeUnNice($artist).'&abc='.makeUnNice($newabc).'&action=add">Index as '.makeHTML($newabc).'</a></small></nobr>';
    }
}
$webpage =~ s/%INDEX%/$index/g;
$webpage =~ s/%SECTIONS%/$albumlist/g;
$webpage =~ s/%COUNT%/$countreport/g;
$webpage =~ s/%ABC%/$rejig/g;

$init =~ s/'/\\'/g;
$webpage =~ s/%INIT%/$init/g;

$webpage =~ s/%ARTIST%/$artist/g;

my $urlartist =  makeUnNice($artist);
$webpage =~ s/%URLARTIST%/$urlartist/g;

$artist =~  s/'/\\'/g;
$webpage =~ s/%JSARTIST%/$artist/g;

$webpage =~ s/%BGCOLOUR%/$bgcolour/g;

print $webpage;