View | Details | Raw Unified | Return to bug 16519
Collapse All | Expand All

(-)a/opac/opac-addbybiblionumber.pl (-141 / +98 lines)
Lines 1-8 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
#script to provide virtualshelf management
4
#
5
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2016 Koha Development Team
6
#
5
#
7
# This file is part of Koha.
6
# This file is part of Koha.
8
#
7
#
Lines 19-26 Link Here
19
# You should have received a copy of the GNU General Public License
18
# You should have received a copy of the GNU General Public License
20
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
20
22
use strict;
21
use Modern::Perl;
23
use warnings;
24
22
25
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
26
use C4::Biblio;
24
use C4::Biblio;
Lines 29-208 use C4::Auth; Link Here
29
27
30
use Koha::Virtualshelves;
28
use Koha::Virtualshelves;
31
29
32
our $query        	= new CGI;
30
my $query           = new CGI;
33
our @biblionumber 	= $query->param('biblionumber');
31
my @biblionumbers   = $query->multi_param('biblionumber');
34
our $selectedshelf 	= $query->param('selectedshelf');
32
my $selectedshelf   = $query->param('selectedshelf');
35
our $newshelf 		= $query->param('newshelf');
33
my $newshelf        = $query->param('newshelf');
36
our $shelfnumber  	= $query->param('shelfnumber');
34
my $shelfnumber     = $query->param('shelfnumber');
37
our $newvirtualshelf	= $query->param('newvirtualshelf');
35
my $newvirtualshelf = $query->param('newvirtualshelf');
38
our $category     	= $query->param('category');
36
my $category        = $query->param('category');
39
our $authorized          = 1;
37
my ( $errcode, $authorized ) = ( 0, 1 );
40
our $errcode		= 0;
38
my @biblios;
41
our @biblios = ();
42
39
43
# if virtualshelves is disabled, leave immediately
40
# if virtualshelves is disabled, leave immediately
44
if ( ! C4::Context->preference('virtualshelves') ) {
41
if ( !C4::Context->preference('virtualshelves') ) {
45
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
42
    print $query->redirect("/cgi-bin/koha/errors/404.pl");
46
    exit;
43
    exit;
47
}
44
}
48
45
49
if (scalar(@biblionumber) == 1) {
46
if ( scalar(@biblionumbers) == 1 ) {
50
    @biblionumber = (split /\//,$biblionumber[0]);
47
    @biblionumbers = ( split /\//, $biblionumbers[0] );
51
}
48
}
52
49
53
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54
    {
51
    {   template_name   => "opac-addbybiblionumber.tt",
55
        template_name   => "opac-addbybiblionumber.tt",
56
        query           => $query,
52
        query           => $query,
57
        type            => "opac",
53
        type            => "opac",
58
        authnotrequired => 0,
54
        authnotrequired => 0,
59
    }
55
    }
60
);
56
);
61
57
62
if( $newvirtualshelf) {
58
if ($newvirtualshelf) {
63
    HandleNewVirtualShelf();
59
    if ($loggedinuser > 0
64
    exit if $authorized;
60
        and (  $category == 1
65
    ShowTemplate(); #error message
61
            or $category == 2 and $loggedinuser > 0 && C4::Context->preference('OpacAllowPublicListCreation') )
66
}
62
      ) {
67
elsif($shelfnumber) {
63
        my $shelf = eval { Koha::Virtualshelf->new( { shelfname => $newvirtualshelf, category => $category, owner => $loggedinuser, } )->store; };
68
    HandleShelfNumber();
69
    exit if $authorized;
70
    ShowTemplate(); #error message
71
}
72
elsif($selectedshelf) {
73
    HandleSelectedShelf();
74
    LoadBib() if $authorized;
75
    ShowTemplate();
76
}
77
else {
78
    HandleSelect();
79
    LoadBib() if $authorized;
80
    ShowTemplate();
81
}
82
#end
83
84
sub HandleNewVirtualShelf {
85
    if ( $loggedinuser > 0 and
86
        (
87
            $category == 1
88
                or $category == 2 and $loggedinuser>0 && C4::Context->preference('OpacAllowPublicListCreation')
89
        )
90
    ) {
91
        my $shelf = eval {
92
            Koha::Virtualshelf->new(
93
                {
94
                    shelfname => $newvirtualshelf,
95
                    category => $category,
96
                    owner => $loggedinuser,
97
                }
98
            )->store;
99
        };
100
        if ( $@ or not $shelf ) {
64
        if ( $@ or not $shelf ) {
65
            $errcode    = 1;
101
            $authorized = 0;
66
            $authorized = 0;
102
            $errcode = 1;
67
        } else {
103
            return;
68
            for my $biblionumber (@biblionumbers) {
104
        }
69
                $shelf->add_biblio( $biblionumber, $loggedinuser );
70
            }
105
71
106
        for my $bib (@biblionumber) {
72
            #Reload the page where you came from
107
            $shelf->add_biblio( $bib, $loggedinuser );
73
            print $query->header;
74
            print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
75
            exit;
108
        }
76
        }
109
110
        #Reload the page where you came from
111
        print $query->header;
112
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
113
    }
77
    }
114
}
78
} elsif ($shelfnumber) {
115
116
sub HandleShelfNumber {
117
    my $shelfnumber = $query->param('shelfnumber');
79
    my $shelfnumber = $query->param('shelfnumber');
118
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
80
    my $shelf       = Koha::Virtualshelves->find($shelfnumber);
119
    if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
81
    if ( $shelf->can_biblios_be_added($loggedinuser) ) {
120
        for my $bib (@biblionumber) {
82
        for my $biblionumber (@biblionumbers) {
121
            $shelf->add_biblio( $bib, $loggedinuser );
83
            $shelf->add_biblio( $biblionumber, $loggedinuser );
122
        }
84
        }
85
123
        #Close this page and return
86
        #Close this page and return
124
        print $query->header;
87
        print $query->header;
125
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
88
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
89
        exit;
126
    } else {
90
    } else {
127
        # TODO
91
        $authorized = 0;
128
    }
92
    }
129
}
93
} elsif ($selectedshelf) {
130
131
sub HandleSelectedShelf {
132
    my $shelfnumber = $query->param('selectedshelf');
94
    my $shelfnumber = $query->param('selectedshelf');
133
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
95
    my $shelf       = Koha::Virtualshelves->find($shelfnumber);
134
    if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
96
    if ( $shelf->can_biblios_be_added($loggedinuser) ) {
97
        $template->param(
98
            singleshelf => 1,
99
            shelfnumber => $shelf->shelfnumber,
100
            shelfname   => $shelf->shelfname,
101
        );
102
    } else {
103
        $authorized = 0;
104
    }
105
} else {
106
    if ( $loggedinuser > 0 ) {
107
        my $private_shelves = Koha::Virtualshelves->search(
108
            {   category => 1,
109
                owner    => $loggedinuser,
110
            },
111
            { order_by => 'shelfname' }
112
        );
113
        my $shelves_shared_with_me = Koha::Virtualshelves->search(
114
            {   category                            => 1,
115
                'virtualshelfshares.borrowernumber' => $loggedinuser,
116
                -or                                 => {
117
                    allow_add => 1,
118
                    owner     => $loggedinuser,
119
                }
120
            },
121
            { join => 'virtualshelfshares', }
122
        );
123
        my $public_shelves = Koha::Virtualshelves->search(
124
            {   category => 2,
125
                -or      => {
126
                    allow_add => 1,
127
                    owner     => $loggedinuser,
128
                }
129
            },
130
            { order_by => 'shelfname' }
131
        );
135
        $template->param(
132
        $template->param(
136
            singleshelf               => 1,
133
            private_shelves                => $private_shelves,
137
            shelfnumber               => $shelf->shelfnumber,
134
            private_shelves_shared_with_me => $shelves_shared_with_me,
138
            shelfname                 => $shelf->shelfname,
135
            public_shelves                 => $public_shelves,
139
        );
136
        );
140
    } else {
137
    } else {
141
        # TODO
138
        $authorized = 0;
142
    }
139
    }
143
}
140
}
144
141
145
sub HandleSelect {
142
if ($authorized) {
146
    return unless $authorized= $loggedinuser>0;
143
    for my $biblionumber (@biblionumbers) {
147
    my $private_shelves = Koha::Virtualshelves->search(
144
        my $data = GetBiblioData($biblionumber);
148
        {
145
        push(
149
            category => 1,
146
            @biblios,
150
            owner => $loggedinuser,
147
            {   biblionumber => $biblionumber,
151
        },
148
                title        => $data->{'title'},
152
        { order_by => 'shelfname' }
149
                author       => $data->{'author'},
153
    );
154
    my $shelves_shared_with_me = Koha::Virtualshelves->search(
155
        {
156
            category => 1,
157
            'virtualshelfshares.borrowernumber' => $loggedinuser,
158
            -or => {
159
                allow_add => 1,
160
                owner => $loggedinuser,
161
            }
162
        },
163
        {
164
            join => 'virtualshelfshares',
165
        }
166
    );
167
    my $public_shelves= Koha::Virtualshelves->search(
168
        {
169
            category => 2,
170
            -or => {
171
                allow_add => 1,
172
                owner => $loggedinuser,
173
            }
150
            }
174
        },
151
        );
175
        { order_by => 'shelfname' }
176
    );
177
    $template->param (
178
        private_shelves => $private_shelves,
179
        private_shelves_shared_with_me => $shelves_shared_with_me,
180
        public_shelves  => $public_shelves,
181
    );
182
}
183
184
sub LoadBib {
185
    for my $bib (@biblionumber) {
186
        my $data = GetBiblioData( $bib );
187
        push(@biblios,
188
            { biblionumber => $bib,
189
              title        => $data->{'title'},
190
              author       => $data->{'author'},
191
        } );
192
    }
152
    }
193
    $template->param(
153
    $template->param(
194
        multiple => (scalar(@biblios) > 1),
154
        multiple => ( scalar(@biblios) > 1 ),
195
    total    => scalar @biblios,
155
        total    => scalar @biblios,
196
    biblios  => \@biblios,
156
        biblios  => \@biblios,
197
    );
157
    );
198
}
199
158
200
sub ShowTemplate {
159
    $template->param(
201
    $template->param (
160
        newshelf => $newshelf || 0,
202
    newshelf => $newshelf||0,
161
        OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
203
    authorized	=> $authorized,
204
    errcode		=> $errcode,
205
    OpacAllowPublicListCreation => C4::Context->preference('OpacAllowPublicListCreation'),
206
    );
162
    );
207
    output_html_with_http_headers $query, $cookie, $template->output;
208
}
163
}
164
$template->param( authorized => $authorized, errcode => $errcode, );
165
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/virtualshelves/addbybiblionumber.pl (-124 / +87 lines)
Lines 1-9 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
#script to provide virtual shelf management
4
#
5
#
6
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2016 Koha Development Team
7
#
5
#
8
# This file is part of Koha.
6
# This file is part of Koha.
9
#
7
#
Lines 58-65 addbybiblionumber.pl Link Here
58
56
59
=cut
57
=cut
60
58
61
use strict;
59
use Modern::Perl;
62
use warnings;
63
60
64
use CGI qw ( -utf8 );
61
use CGI qw ( -utf8 );
65
use C4::Biblio;
62
use C4::Biblio;
Lines 68-87 use C4::Auth; Link Here
68
65
69
use Koha::Virtualshelves;
66
use Koha::Virtualshelves;
70
67
71
our $query           = new CGI;
68
my $query           = new CGI;
72
our @biblionumber    = HandleBiblioPars();
69
my $shelfnumber     = $query->param('shelfnumber');
73
our $shelfnumber     = $query->param('shelfnumber');
70
my $newvirtualshelf = $query->param('newvirtualshelf');
74
our $newvirtualshelf = $query->param('newvirtualshelf');
71
my $newshelf        = $query->param('newshelf');
75
our $newshelf        = $query->param('newshelf');
72
my $category        = $query->param('category');
76
our $category        = $query->param('category');
73
my $sortfield       = $query->param('sortfield');
77
our $sortfield	    = $query->param('sortfield');
78
my $confirmed       = $query->param('confirmed') || 0;
74
my $confirmed       = $query->param('confirmed') || 0;
79
our $authorized      = 1;
75
my ( $errcode, $authorized ) = ( 0, 1 );
80
our $errcode	    = 0;
76
my @biblionumbers = $query->multi_param('biblionumber');
77
78
if ( @biblionumbers == 0 && $query->param('biblionumbers') ) {
79
    my $str = $query->param('biblionumbers');
80
    @biblionumbers = split '/', $str;
81
} elsif ( @biblionumbers == 1 && $biblionumbers[0] =~ /\// ) {
82
    @biblionumbers = split '/', $biblionumbers[0];
83
}
81
84
82
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
83
    {
86
    {   template_name   => "virtualshelves/addbybiblionumber.tt",
84
        template_name   => "virtualshelves/addbybiblionumber.tt",
85
        query           => $query,
87
        query           => $query,
86
        type            => "intranet",
88
        type            => "intranet",
87
        authnotrequired => 0,
89
        authnotrequired => 0,
Lines 89-243 our ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
89
    }
91
    }
90
);
92
);
91
93
92
if( $newvirtualshelf) {
94
if ($newvirtualshelf) {
93
    HandleNewVirtualShelf();
94
    exit if $authorized;
95
    ShowTemplate(); #error message
96
}
97
elsif($shelfnumber && $confirmed) {
98
    HandleShelfNumber();
99
    exit if $authorized;
100
    ShowTemplate(); #error message
101
}
102
elsif($shelfnumber) { #still needs confirmation
103
    HandleSelectedShelf();
104
    LoadBib() if $authorized;
105
    ShowTemplate();
106
}
107
else {
108
    HandleSelect();
109
    LoadBib();
110
    ShowTemplate();
111
}
112
#end
113
114
sub HandleBiblioPars {
115
    my @bib= $query->multi_param('biblionumber');
116
    if(@bib==0 && $query->param('biblionumbers')) {
117
        my $str= $query->param('biblionumbers');
118
        @bib= split '/', $str;
119
    }
120
    elsif(@bib==1 && $bib[0]=~/\//) {
121
        @bib= split '/', $bib[0];
122
    }
123
    return @bib;
124
}
125
126
sub HandleNewVirtualShelf {
127
    my $shelf = eval {
95
    my $shelf = eval {
128
        Koha::Virtualshelf->new(
96
        Koha::Virtualshelf->new(
129
            {
97
            {
130
                shelfname => $newvirtualshelf,
98
                shelfname => $newvirtualshelf,
131
                category => $category,
99
                category  => $category,
132
                sortfield => $sortfield,
100
                sortfield => $sortfield,
133
                owner => $loggedinuser,
101
                owner     => $loggedinuser,
134
            }
102
            }
135
        )->store;
103
        )->store;
136
    };
104
    };
137
    if ( $@ or not $shelf ) {
105
    if ( $@ or not $shelf ) {
138
        $authorized = 0;
139
        $errcode    = 1;
106
        $errcode    = 1;
140
        return;
107
        $authorized = 0;
141
    }
108
    } else {
109
110
        for my $biblionumber (@biblionumbers) {
111
            $shelf->add_biblio( $biblionumber, $loggedinuser );
112
        }
142
113
143
    for my $bib (@biblionumber){
114
        #Reload the page where you came from
144
        $shelf->add_biblio( $bib, $loggedinuser );
115
        print $query->header;
116
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
117
        exit;
145
    }
118
    }
146
    #Reload the page where you came from
147
    print $query->header;
148
    print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"window.opener.location.reload(true);self.close();\"></body></html>";
149
}
150
119
151
sub HandleShelfNumber {
120
} elsif ( $shelfnumber && $confirmed ) {
152
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
121
    my $shelf = Koha::Virtualshelves->find($shelfnumber);
153
    if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
122
    if ( $shelf->can_biblios_be_added($loggedinuser) ) {
154
        for my $bib (@biblionumber){
123
        for my $biblionumber (@biblionumbers) {
155
            $shelf->add_biblio( $bib, $loggedinuser );
124
            $shelf->add_biblio( $biblionumber, $loggedinuser );
156
        }
125
        }
126
157
        #Close this page and return
127
        #Close this page and return
158
        print $query->header;
128
        print $query->header;
159
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
129
        print "<html><meta http-equiv=\"refresh\" content=\"0\" /><body onload=\"self.close();\"></body></html>";
130
        exit;
131
    } else {
132
        $errcode    = 2;    #no perm
133
        $authorized = 0;
160
    }
134
    }
161
    else {
162
        $errcode=2; #no perm
163
    }
164
}
165
135
166
sub HandleSelectedShelf {
136
} elsif ($shelfnumber) {    #still needs confirmation
167
    my $shelf = Koha::Virtualshelves->find( $shelfnumber );
137
    my $shelf = Koha::Virtualshelves->find($shelfnumber);
168
    if($authorized = $shelf->can_biblios_be_added( $loggedinuser ) ) {
138
    if ( $shelf->can_biblios_be_added($loggedinuser) ) {
139
169
        #confirm adding to specific shelf
140
        #confirm adding to specific shelf
170
        $template->param(
141
        $template->param(
171
        singleshelf               => 1,
142
            singleshelf => 1,
172
        shelfnumber               => $shelf->shelfnumber,
143
            shelfnumber => $shelf->shelfnumber,
173
        shelfname                 => $shelf->shelfname,
144
            shelfname   => $shelf->shelfname,
174
        );
145
        );
146
    } else {
147
        $authorized = 0;
148
        $errcode    = 2;    #no perm
175
    }
149
    }
176
    else {
177
    $errcode=2; #no perm
178
    }
179
}
180
150
181
sub HandleSelect {
151
} else {
182
    my $private_shelves = Koha::Virtualshelves->search(
152
    my $private_shelves = Koha::Virtualshelves->search(
183
        {
153
        {   category => 1,
184
            category => 1,
154
            owner    => $loggedinuser,
185
            owner => $loggedinuser,
186
        },
155
        },
187
        { order_by => 'shelfname' }
156
        { order_by => 'shelfname' }
188
    );
157
    );
189
    my $shelves_shared_with_me = Koha::Virtualshelves->search(
158
    my $shelves_shared_with_me = Koha::Virtualshelves->search(
190
        {
159
        {   category                            => 1,
191
            category => 1,
192
            'virtualshelfshares.borrowernumber' => $loggedinuser,
160
            'virtualshelfshares.borrowernumber' => $loggedinuser,
193
            -or => {
161
            -or                                 => {
194
                allow_add => 1,
162
                allow_add => 1,
195
                owner => $loggedinuser,
163
                owner     => $loggedinuser,
196
            }
164
            }
197
        },
165
        },
198
        {
166
        { join => 'virtualshelfshares', }
199
            join => 'virtualshelfshares',
200
        }
201
    );
167
    );
202
    my $public_shelves= Koha::Virtualshelves->search(
168
    my $public_shelves = Koha::Virtualshelves->search(
203
        {
169
        {   category => 2,
204
            category => 2,
170
            -or      => {
205
            -or => {
206
                allow_add => 1,
171
                allow_add => 1,
207
                owner => $loggedinuser,
172
                owner     => $loggedinuser,
208
            }
173
            }
209
        },
174
        },
210
        { order_by => 'shelfname' }
175
        { order_by => 'shelfname' }
211
    );
176
    );
212
    $template->param (
177
    $template->param(
213
        private_shelves => $private_shelves,
178
        private_shelves                => $private_shelves,
214
        private_shelves_shared_with_me => $shelves_shared_with_me,
179
        private_shelves_shared_with_me => $shelves_shared_with_me,
215
        public_shelves  => $public_shelves,
180
        public_shelves                 => $public_shelves,
216
    );
181
    );
217
}
218
182
219
sub LoadBib {
220
    my @biblios;
221
    for my $bib (@biblionumber) {
222
        my $data = GetBiblioData($bib);
223
    push(@biblios,
224
        { biblionumber => $bib,
225
          title        => $data->{'title'},
226
          author       => $data->{'author'},
227
    } );
228
    }
229
    $template->param(
230
        multiple => (scalar(@biblios) > 1),
231
    total    => scalar @biblios,
232
    biblios  => \@biblios,
233
    );
234
}
183
}
235
184
236
sub ShowTemplate {
185
my @biblios;
237
    $template->param (
186
for my $biblionumber (@biblionumbers) {
238
    newshelf => $newshelf||0,
187
    my $data = GetBiblioData($biblionumber);
239
    authorized	=> $authorized,
188
    push(
240
    errcode		=> $errcode,
189
        @biblios,
190
        {   biblionumber => $biblionumber,
191
            title        => $data->{'title'},
192
            author       => $data->{'author'},
193
        }
241
    );
194
    );
242
    output_html_with_http_headers $query, $cookie, $template->output;
243
}
195
}
244
- 
196
$template->param(
197
    multiple => ( scalar(@biblios) > 1 ),
198
    total    => scalar @biblios,
199
    biblios  => \@biblios,
200
);
201
202
$template->param(
203
    newshelf => $newshelf || 0,
204
    authorized => $authorized,
205
    errcode    => $errcode,
206
);
207
output_html_with_http_headers $query, $cookie, $template->output;

Return to bug 16519