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

(-)a/Koha/Upload.pm (-8 / +8 lines)
Lines 170-176 sub get { Link Here
170
    my ( @rv, $res);
170
    my ( @rv, $res);
171
    foreach my $r ( @$temp ) {
171
    foreach my $r ( @$temp ) {
172
        undef $res;
172
        undef $res;
173
        foreach( qw[id hashvalue filesize categorycode public permanent] ) {
173
        foreach( qw[id hashvalue filesize uploadcategorycode public permanent] ) {
174
            $res->{$_} = $r->{$_};
174
            $res->{$_} = $r->{$_};
175
        }
175
        }
176
        $res->{name} = $r->{filename};
176
        $res->{name} = $r->{filename};
Lines 340-347 sub _done { Link Here
340
sub _register {
340
sub _register {
341
    my ( $self, $filename, $size ) = @_;
341
    my ( $self, $filename, $size ) = @_;
342
    my $dbh= C4::Context->dbh;
342
    my $dbh= C4::Context->dbh;
343
    my $sql= "INSERT INTO uploaded_files (hashvalue, filename, dir, filesize,
343
    my $sql= 'INSERT INTO uploaded_files (hashvalue, filename, dir, filesize,
344
        owner, categorycode, public, permanent) VALUES (?,?,?,?,?,?,?,?)";
344
        owner, uploadcategorycode, public, permanent) VALUES (?,?,?,?,?,?,?,?)';
345
    my @pars= (
345
    my @pars= (
346
        $self->{files}->{$filename}->{hash},
346
        $self->{files}->{$filename}->{hash},
347
        $filename,
347
        $filename,
Lines 361-384 sub _lookup { Link Here
361
    my ( $self, $params ) = @_;
361
    my ( $self, $params ) = @_;
362
    my $dbh = C4::Context->dbh;
362
    my $dbh = C4::Context->dbh;
363
    my $sql = q|
363
    my $sql = q|
364
SELECT id,hashvalue,filename,dir,filesize,categorycode,public,permanent
364
SELECT id,hashvalue,filename,dir,filesize,uploadcategorycode,public,permanent
365
FROM uploaded_files
365
FROM uploaded_files
366
    |;
366
    |;
367
    my @pars;
367
    my @pars;
368
    if( $params->{id} ) {
368
    if( $params->{id} ) {
369
        return [] if $params->{id} !~ /^\d+(,\d+)*$/;
369
        return [] if $params->{id} !~ /^\d+(,\d+)*$/;
370
        $sql.= "WHERE id IN ($params->{id})";
370
        $sql.= 'WHERE id IN ('.$params->{id}.')';
371
        @pars = ();
371
        @pars = ();
372
    } elsif( $params->{hashvalue} ) {
372
    } elsif( $params->{hashvalue} ) {
373
        $sql.= "WHERE hashvalue=?";
373
        $sql.= 'WHERE hashvalue=?';
374
        @pars = ( $params->{hashvalue} );
374
        @pars = ( $params->{hashvalue} );
375
    } elsif( $params->{term} ) {
375
    } elsif( $params->{term} ) {
376
        $sql.= "WHERE (filename LIKE ? OR hashvalue LIKE ?)";
376
        $sql.= 'WHERE (filename LIKE ? OR hashvalue LIKE ?)';
377
        @pars = ( '%'.$params->{term}.'%', '%'.$params->{term}.'%' );
377
        @pars = ( '%'.$params->{term}.'%', '%'.$params->{term}.'%' );
378
    } else {
378
    } else {
379
        return [];
379
        return [];
380
    }
380
    }
381
    $sql.= $self->{public}? " AND public=1": '';
381
    $sql.= $self->{public}? ' AND public=1': '';
382
    $sql.= ' ORDER BY id';
382
    $sql.= ' ORDER BY id';
383
    my $temp= $dbh->selectall_arrayref( $sql, { Slice => {} }, @pars );
383
    my $temp= $dbh->selectall_arrayref( $sql, { Slice => {} }, @pars );
384
    return $temp;
384
    return $temp;
(-)a/installer/data/mysql/atomicupdate/14321b_category.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE uploaded_files CHANGE COLUMN categorycode uploadcategorycode tinytext;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 3359-3365 CREATE TABLE uploaded_files ( Link Here
3359
    dir TEXT NOT NULL,
3359
    dir TEXT NOT NULL,
3360
    filesize int(11),
3360
    filesize int(11),
3361
    dtcreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3361
    dtcreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3362
    categorycode tinytext,
3362
    uploadcategorycode tinytext,
3363
    owner int(11),
3363
    owner int(11),
3364
    public tinyint,
3364
    public tinyint,
3365
    permanent tinyint,
3365
    permanent tinyint,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt (-4 / +23 lines)
Lines 70-78 Link Here
70
            [% IF plugin %]
70
            [% IF plugin %]
71
                <input type="hidden" id="public" name="public" value="1"/>
71
                <input type="hidden" id="public" name="public" value="1"/>
72
            [% ELSE %]
72
            [% ELSE %]
73
                <label>&nbsp;</label>
73
                <label id="public_cb">Allow public downloads:</label>
74
                <input type="checkbox" id="public" name="public">
74
                <input type="checkbox" id="public" name="public">
75
                    Allow public downloads
76
                </input>
75
                </input>
77
            [% END %]
76
            [% END %]
78
        </li>
77
        </li>
Lines 133-138 Link Here
133
    [% END %]
132
    [% END %]
134
[% END %]
133
[% END %]
135
134
135
[% BLOCK back %]
136
    [% IF !plugin %]
137
        <form id="back">
138
            <fieldset class="action">
139
                <button class="submit">Back</button>
140
            </fieldset>
141
        </form>
142
    [% END %]
143
[% END %]
144
136
[% BLOCK newsearch %]
145
[% BLOCK newsearch %]
137
    <form id="newsearch">
146
    <form id="newsearch">
138
        <fieldset class="action">
147
        <fieldset class="action">
Lines 163-169 Link Here
163
        <td>[% record.name %]</td>
172
        <td>[% record.name %]</td>
164
        <td>[% record.filesize %]</td>
173
        <td>[% record.filesize %]</td>
165
        <td>[% record.hashvalue %]</td>
174
        <td>[% record.hashvalue %]</td>
166
        <td>[% record.categorycode %]</td>
175
        <td>[% record.uploadcategorycode %]</td>
167
        [% IF !plugin %]
176
        [% IF !plugin %]
168
            <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
177
            <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
169
            <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
178
            <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
Lines 173-179 Link Here
173
                <a href="" onclick="Choose('[% record.hashvalue %]'); return false;">Choose</a>&nbsp;
182
                <a href="" onclick="Choose('[% record.hashvalue %]'); return false;">Choose</a>&nbsp;
174
            [% END %]
183
            [% END %]
175
            <a href="" onclick="SubmitMe( 'download', [% record.id %] ); return false;">Download</a>&nbsp;
184
            <a href="" onclick="SubmitMe( 'download', [% record.id %] ); return false;">Download</a>&nbsp;
176
            <a href="" onclick="ClearField(); SubmitMe( 'delete', [% record.id %] ); return false;">Delete</a>
185
            <a href="" onclick="DeleteEntry( [% record.id %] ); return false;">Delete</a>
177
        </td>
186
        </td>
178
   </tr>
187
   </tr>
179
   [% END %]
188
   [% END %]
Lines 279-284 function SubmitMe(op, id, msg ) { Link Here
279
    $("#submitter #msg").val( msg );
288
    $("#submitter #msg").val( msg );
280
    $("#submitter").submit();
289
    $("#submitter").submit();
281
}
290
}
291
function DeleteEntry(id) {
292
    if( !confirm( _("Do you really want to delete this upload?") ))
293
        return false;
294
    ClearField();
295
    SubmitMe( 'delete', id );
296
}
282
function ClearField() {
297
function ClearField() {
283
    [% IF plugin %]
298
    [% IF plugin %]
284
        $(window.opener.document).find('#[% index %]').val( '' );
299
        $(window.opener.document).find('#[% index %]').val( '' );
Lines 298-303 $(document).ready(function() { Link Here
298
        ShowAlerts( [% msg %] );
313
        ShowAlerts( [% msg %] );
299
    [% END %]
314
    [% END %]
300
    $("#fileuploadcancel").hide();
315
    $("#fileuploadcancel").hide();
316
    $("#public_cb").click(function() {
317
        $("#public").click();
318
    });
301
});
319
});
302
//]]>
320
//]]>
303
</script>
321
</script>
Lines 329-334 $(document).ready(function() { Link Here
329
        <h3>Your request gave the following results:</h3>
347
        <h3>Your request gave the following results:</h3>
330
        [% PROCESS table_results %]
348
        [% PROCESS table_results %]
331
        [% PROCESS closer %]
349
        [% PROCESS closer %]
350
        [% PROCESS back %]
332
    [% ELSE %]
351
    [% ELSE %]
333
        <h4>Sorry, your request had no results.</h4>
352
        <h4>Sorry, your request had no results.</h4>
334
        [% PROCESS newsearch %]
353
        [% PROCESS newsearch %]
(-)a/t/db_dependent/Upload.t (-4 / +3 lines)
Lines 96-102 sub test01 { Link Here
96
    is( $upl->count, 2, 'Count returns 2 also' );
96
    is( $upl->count, 2, 'Count returns 2 also' );
97
    foreach my $r ( $upl->get({ id => $res }) ) {
97
    foreach my $r ( $upl->get({ id => $res }) ) {
98
        if( $r->{name} eq 'file1' ) {
98
        if( $r->{name} eq 'file1' ) {
99
            is( $r->{categorycode}, 'A', 'Check category A' );
99
            is( $r->{uploadcategorycode}, 'A', 'Check category A' );
100
            is( $r->{filesize}, 6000, 'Check size of file1' );
100
            is( $r->{filesize}, 6000, 'Check size of file1' );
101
        } elsif( $r->{name} eq 'file2' ) {
101
        } elsif( $r->{name} eq 'file2' ) {
102
            is( $r->{filesize}, 8000, 'Check size of file2' );
102
            is( $r->{filesize}, 8000, 'Check size of file2' );
Lines 115-121 sub test02 { Link Here
115
    is( $upl->count, 1, 'Upload 2 includes one file' );
115
    is( $upl->count, 1, 'Upload 2 includes one file' );
116
    my $res= $upl->result;
116
    my $res= $upl->result;
117
    my $r = $upl->get({ id => $res, filehandle => 1 });
117
    my $r = $upl->get({ id => $res, filehandle => 1 });
118
    is( $r->{categorycode}, 'B', 'Check category B' );
118
    is( $r->{uploadcategorycode}, 'B', 'Check category B' );
119
    is( $r->{public}, 1, 'Check public == 1' );
119
    is( $r->{public}, 1, 'Check public == 1' );
120
    is( ref($r->{fh}) eq 'IO::File' && $r->{fh}->opened, 1, 'Get returns a file handle' );
120
    is( ref($r->{fh}) eq 'IO::File' && $r->{fh}->opened, 1, 'Get returns a file handle' );
121
}
121
}
Lines 125-131 sub test03 { Link Here
125
    my $cgi= $upl->cgi;
125
    my $cgi= $upl->cgi;
126
    is( $upl->count, 1, 'Upload 3 includes one temporary file' );
126
    is( $upl->count, 1, 'Upload 3 includes one temporary file' );
127
    my $r = $upl->get({ id => $upl->result });
127
    my $r = $upl->get({ id => $upl->result });
128
    is( $r->{categorycode}, 'koha_upload', 'Check category temp file' );
128
    is( $r->{uploadcategorycode}, 'koha_upload', 'Check category temp file' );
129
}
129
}
130
130
131
sub test04 { # Fail on a file already there
131
sub test04 { # Fail on a file already there
132
- 

Return to bug 14321