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

(-)a/cataloguing/value_builder/upload.pl (-132 / +21 lines)
Lines 4-9 Link Here
4
4
5
# This file is part of Koha.
5
# This file is part of Koha.
6
#
6
#
7
# Copyright (C) 2015 Rijksmuseum
7
# Copyright (C) 2011-2012 BibLibre
8
# Copyright (C) 2011-2012 BibLibre
8
#
9
#
9
# Koha is free software; you can redistribute it and/or modify it
10
# Koha is free software; you can redistribute it and/or modify it
Lines 20-164 Link Here
20
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22
22
use Modern::Perl;
23
use Modern::Perl;
23
use CGI qw/-utf8/;
24
24
25
use C4::Auth;
25
# This plugin does not use the plugin launcher. It refers to tools/upload.pl.
26
use C4::Context;
26
# That script and template support using it as a plugin.
27
use C4::Output;
27
28
use C4::UploadedFiles;
28
# If the plugin is called with the pattern [id=some_hashvalue] in the
29
# corresponding field, it starts the upload script as a search, providing
30
# the possibility to delete the uploaded file. If the field is empty, you
31
# can upload a new file.
29
32
30
my $builder = sub {
33
my $builder = sub {
31
    my ( $params ) = @_;
34
    my ( $params ) = @_;
32
    my $function_name = $params->{id};
35
    return <<"SCRIPT";
33
    my $res           = "
36
<script type=\"text/javascript\">
34
    <script type=\"text/javascript\">
37
        function Click$params->{id}(event) {
35
        function Click$function_name(event) {
36
            var index = event.data.id;
38
            var index = event.data.id;
37
            var id = document.getElementById(index).value;
39
            var str = document.getElementById(index).value;
38
            var IsFileUploadUrl=0;
40
            var myurl, term;
39
            if (id.match(/opac-retrieve-file/)) {
41
            if( str && str.match(/id=([0-9a-f]+)/) ) {
40
                IsFileUploadUrl=1;
42
                term = RegExp.\$1;
41
            }
43
                myurl = '../tools/upload.pl?op=search&index='+index+'&term='+term+'&plugin=1';
42
            if(id.match(/id=([0-9a-f]+)/)){
43
                id = RegExp.\$1;
44
            }
45
            var newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=upload.pl&index=\"+index+\"&id=\"+id+\"&from_popup=0\"+\"&IsFileUploadUrl=\"+IsFileUploadUrl, 'upload', 'width=600,height=400,toolbar=false,scrollbars=no');
46
            newin.focus();
47
        }
48
    </script>
49
";
50
    return $res;
51
};
52
53
my $launcher = sub {
54
    my ( $params ) = @_;
55
    my $input = $params->{cgi};
56
    my $index = $input->param('index');
57
    my $id = $input->param('id');
58
    my $delete = $input->param('delete');
59
    my $uploaded_file = $input->param('uploaded_file');
60
    my $from_popup = $input->param('from_popup');
61
    my $isfileuploadurl = $input->param('IsFileUploadUrl');
62
    my $dangling = C4::UploadedFiles::DanglingEntry($id,$isfileuploadurl);
63
    my $template_name;
64
    if ($delete || ($id && ($dangling==0 || $dangling==1))) {
65
        $template_name = "upload_delete_file.tt";
66
    }
67
    else {
68
        $template_name = "upload.tt";
69
    }
70
71
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
72
        {   template_name   => "cataloguing/value_builder/$template_name",
73
            query           => $input,
74
            type            => "intranet",
75
            authnotrequired => 0,
76
            flagsrequired   => { editcatalogue => '*' },
77
            debug           => 1,
78
        }
79
    );
80
81
    if ($dangling==2) {
82
        $template->param( dangling => 1 );
83
    }
84
85
    # Dealing with the uploaded file
86
    my $dir = $input->param('uploadcategory');
87
    if ($uploaded_file and $dir) {
88
        my $fh = $input->upload('uploaded_file');
89
90
        $id = C4::UploadedFiles::UploadFile($uploaded_file, $dir, $fh->handle);
91
        my $OPACBaseURL = C4::Context->preference('OPACBaseURL') // '';
92
        $OPACBaseURL =~ s#/$##;
93
        if (!$OPACBaseURL) {
94
            $template->param(MissingURL => 1);
95
        }
96
        if($id && $OPACBaseURL) {
97
            my $return = "$OPACBaseURL/cgi-bin/koha/opac-retrieve-file.pl?id=$id";
98
            $template->param(
99
                success => 1,
100
                return => $return,
101
                uploaded_file => $uploaded_file,
102
            );
103
        } else {
104
            $template->param(error => 1);
105
        }
106
    } elsif ($delete || ($id && ($dangling==0 || $dangling==1))) {
107
        # If there's already a file uploaded for this field,
108
        # We handle its deletion
109
        if ($delete) {
110
            if(C4::UploadedFiles::DelUploadedFile($id)==0) {;
111
                $template->param(error => 1);
112
            } else {
44
            } else {
113
                $template->param(success => 1);
45
                myurl = '../tools/upload.pl?op=new&index='+index+'&plugin=1';
114
            }
46
            }
47
            window.open( myurl, 'tag_editor', 'width=800,height=400,toolbar=false,scrollbars=yes' );
115
        }
48
        }
116
    } else {
49
</script>
117
        my $upload_path = C4::Context->config('upload_path');
50
SCRIPT
118
        if ($upload_path) {
119
            my $filefield = CGI::filefield(
120
                -name => 'uploaded_file',
121
                -size => 50,
122
            );
123
            $template->param(
124
                filefield => $filefield,
125
                uploadcategories => C4::UploadedFiles::getCategories(),
126
            );
127
        } else {
128
            $template->param( error_upload_path_not_configured => 1 );
129
        }
130
131
        if (!$uploaded_file && !$dir && $from_popup) {
132
            $template->param(error_nothing_selected => 1);
133
        }
134
        elsif (!$uploaded_file && $dir) {
135
            $template->param(error_no_file_selected => 1);
136
        }
137
        if ($uploaded_file and not $dir) {
138
            $template->param(error_no_dir_selected => 1);
139
        }
140
141
    }
142
143
    $template->param(
144
        index => $index,
145
        id => $id,
146
    );
147
148
    output_html_with_http_headers $input, $cookie, $template->output;
149
};
51
};
150
52
151
return { builder => $builder, launcher => $launcher };
53
return { builder => $builder };
152
153
1;
154
155
__END__
156
157
=head1 upload.pl
158
159
This plugin allows to upload files on the server and reference it in a marc
160
field.
161
162
It uses config variable upload_path and pref OPACBaseURL.
163
164
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/file-upload.js (+32 lines)
Line 0 Link Here
1
function AjaxUpload ( input, progressbar, xtra, callback ) {
2
    // input and progressbar are jQuery objects
3
    // callback is the callback function for completion
4
    var formData= new FormData();
5
    $.each( input.prop('files'), function( dx, file ) {
6
        formData.append( "uploadfile", file );
7
    });
8
    var xhr= new XMLHttpRequest();
9
    var url= '/cgi-bin/koha/tools/upload-file.pl?' + xtra;
10
    progressbar.val( 0 );
11
    progressbar.next('.fileuploadpercent').text( '0' );
12
    xhr.open('POST', url, true);
13
    xhr.upload.onprogress = function (e) {
14
        var p = Math.round( (e.loaded/e.total) * 100 );
15
        progressbar.val( p );
16
        progressbar.next('.fileuploadpercent').text( p );
17
    }
18
    xhr.onload = function (e) {
19
        var data = JSON.parse( xhr.responseText );
20
        if( data.status == 'done' ) {
21
            progressbar.val( 100 );
22
            progressbar.next('.fileuploadpercent').text( '100' );
23
        }
24
        callback( data.status, data.fileid, data.errors );
25
    }
26
    xhr.onerror = function (e) {
27
        // Probably only fires for network failure
28
        alert('An error occurred while uploading.');
29
    }
30
    xhr.send( formData );
31
    return xhr;
32
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt (-8 / +31 lines)
Lines 1-22 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Circulation &rsaquo; Offline circulation file upload</title>
2
<title>Koha &rsaquo; Circulation &rsaquo; Offline circulation file upload</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'file-upload.inc' %]
4
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
6
<script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
6
<script type="text/javascript">
7
<script type="text/javascript">
7
//<![CDATA[
8
//<![CDATA[
9
var xhr;
8
$(document).ready(function(){
10
$(document).ready(function(){
9
    $("#enqueuefile").hide();
11
    $("#enqueuefile").hide();
10
    $("#processfile").hide();
12
    $("#processfile").hide();
11
});
13
});
12
14
13
function CheckUpload(f){
15
function StartUpload() {
14
    if (f.fileToUpload.value == ""){
16
    if( $('#fileToUpload').prop('files').length == 0 ) return;
15
        alert(_("Please choose a file to upload"));
17
    $('#fileuploadform input.submit').prop('disabled',true);
18
    $("#fileuploadfailed").hide();
19
    $("#processfile").hide();
20
    $("#fileuploadstatus").show();
21
    $("form#processfile #uploadedfileid").val('');
22
    $("form#enqueuefile #uploadedfileid").val('');
23
    xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
24
}
25
26
function cbUpload( status, fileid ) {
27
    if( status=='done' ) {
28
        $("form#processfile #uploadedfileid").val( fileid );
29
        $("form#enqueuefile #uploadedfileid").val( fileid );
30
        $('#fileToUpload').prop('disabled',true);
31
        $("#processfile").show();
32
        $("#enqueuefile").show();
16
    } else {
33
    } else {
17
        return ajaxFileUpload()
34
        $("#fileuploadstatus").hide();
35
        $("#fileuploadfailed").show();
36
        $("#fileuploadfailed").text( _("Upload status: ") +
37
            ( status=='failed'? _("Failed"):
38
            ( status=='denied'? _("Denied"): status ))
39
        );
18
    }
40
    }
19
    return false;
20
}
41
}
21
42
22
function CheckForm(f) {
43
function CheckForm(f) {
Lines 25-30 function CheckForm(f) { Link Here
25
    } else {
46
    } else {
26
        $("#fileuploadstatus").hide();
47
        $("#fileuploadstatus").hide();
27
        $("#fileuploadform").slideUp();
48
        $("#fileuploadform").slideUp();
49
        $("#mainformsubmit").prop('disabled',true);
50
        $("#queueformsubmit").prop('disabled',true);
28
        return submitBackgroundJob(f);
51
        return submitBackgroundJob(f);
29
    }
52
    }
30
    return false;
53
    return false;
Lines 70-79 function CheckForm(f) { Link Here
70
		<fieldset class="brief">
93
		<fieldset class="brief">
71
       <ol><li><label for="fileToUpload">Choose .koc file: </label>
94
       <ol><li><label for="fileToUpload">Choose .koc file: </label>
72
       <input type="file" id="fileToUpload" size="50" name="fileToUpload" /></li></ol>
95
       <input type="file" id="fileToUpload" size="50" name="fileToUpload" /></li></ol>
73
	   <fieldset class="action"><input type="button" class="submit" value="Upload file" onclick="CheckUpload(this.form);" /></fieldset>
96
       <fieldset class="action"><input type="button" class="submit" value="Upload file" onclick="StartUpload();return false;" /></fieldset>
74
	   </fieldset>
97
	   </fieldset>
75
     </form>
98
     </form>
76
     <div id="fileuploadstatus" style="display:none">Upload progress: <div id="fileuploadprogress"></div> <span id="fileuploadpercent">0</span>%</div>
99
     <div id="fileuploadstatus" style="display:none">Upload progress: <progress id="fileuploadprogress" min="0" max="100" value="0"></progress> <span class="fileuploadpercent">0</span>%</div>
77
     <div id="fileuploadfailed" style="display:none"></div>
100
     <div id="fileuploadfailed" style="display:none"></div>
78
   </div>
101
   </div>
79
102
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-7 / +57 lines)
Lines 1-14 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Stage MARC records for import</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Stage MARC records for import</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'file-upload.inc' %]
4
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
6
<script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
7
6
<style type="text/css">
8
<style type="text/css">
7
	#uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
9
    #fileuploadstatus,#fileuploadfailed,#fileuploadcancel,#jobpanel,#jobstatus,#jobfailed { display : none; }
8
	#fileuploadstatus,#jobstatus { margin:.4em; }
10
	#fileuploadstatus,#jobstatus { margin:.4em; }
9
    #fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }</style>
11
    #fileuploadprogress,#jobprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
12
</style>
13
10
<script type="text/javascript">
14
<script type="text/javascript">
11
//<![CDATA[
15
//<![CDATA[
16
var xhr;
12
$(document).ready(function(){
17
$(document).ready(function(){
13
	$("#processfile").hide();
18
	$("#processfile").hide();
14
    $("#record_type").change(function() {
19
    $("#record_type").change(function() {
Lines 27-33 function CheckForm(f) { Link Here
27
    }
32
    }
28
    return false;
33
    return false;
29
}
34
}
30
35
function StartUpload() {
36
    if( $('#fileToUpload').prop('files').length == 0 ) return;
37
    $('#fileuploadbutton').hide();
38
    $("#fileuploadfailed").hide();
39
    $("#processfile").hide();
40
    $("#fileuploadstatus").show();
41
    $("#uploadedfileid").val('');
42
    xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
43
    $("#fileuploadcancel").show();
44
}
45
function CancelUpload() {
46
    if( xhr ) xhr.abort();
47
    $("#fileuploadstatus").hide();
48
    $('#fileuploadbutton').show();
49
    $("#fileuploadcancel").hide();
50
    $("#fileuploadfailed").show();
51
    $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
52
}
53
function cbUpload( status, fileid ) {
54
    if( status=='done' ) {
55
        $("#uploadedfileid").val( fileid );
56
        $('#fileToUpload').prop('disabled',true);
57
        $('#fileuploadbutton').prop('disabled',true);
58
        $('#fileuploadbutton').show();
59
        $("#fileuploadcancel").hide();
60
        $("#processfile").show();
61
    } else {
62
        $('#fileuploadbutton').show();
63
        $("#fileuploadcancel").hide();
64
        $("#fileuploadstatus").hide();
65
        $("#fileuploadfailed").show();
66
        $("#fileuploadfailed").text( _("Upload status: ") +
67
            ( status=='failed'? _("Failed"):
68
            ( status=='denied'? _("Denied"): status ))
69
        );
70
    }
71
}
31
//]]>
72
//]]>
32
</script>
73
</script>
33
</head>
74
</head>
Lines 90-100 function CheckForm(f) { Link Here
90
		<input type="file" id="fileToUpload" name="fileToUpload" />
131
		<input type="file" id="fileToUpload" name="fileToUpload" />
91
        </div>	</li>
132
        </div>	</li>
92
</ol>
133
</ol>
93
        <fieldset class="action"><button class="submit" onclick="return ajaxFileUpload();">Upload file</button></fieldset>
134
    <fieldset class="action">
135
        <button id="fileuploadbutton" onclick="StartUpload(); return false;">Upload file</button>
136
        <button id="fileuploadcancel" onclick="CancelUpload(); return false;">Cancel</button>
137
    </fieldset>
94
</fieldset>
138
</fieldset>
95
		
139
		
96
        <div id="uploadpanel"><div id="fileuploadstatus">Upload progress: <div id="fileuploadprogress"></div> <span id="fileuploadpercent">0</span>%</div>
140
    <div id="fileuploadpanel">
97
        <div id="fileuploadfailed"></div></div>
141
        <div id="fileuploadstatus">Upload progress:
142
            <progress id="fileuploadprogress" min="0" max="100" value="0">
143
            </progress>
144
            <span class="fileuploadpercent">0</span>%
145
        </div>
146
        <div id="fileuploadfailed"></div>
147
    </div>
98
</form>
148
</form>
99
149
100
    <form method="post" id="processfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
150
    <form method="post" id="processfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload-images.tt (-6 / +39 lines)
Lines 1-14 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Upload images</title>
2
<title>Koha &rsaquo; Tools &rsaquo; Upload images</title>
3
[% INCLUDE 'doc-head-close.inc' %]
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'file-upload.inc' %]
4
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
5
<script type="text/javascript" src="[% themelang %]/js/background-job-progressbar.js"></script>
6
<script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
7
6
<style type="text/css">
8
<style type="text/css">
7
	#uploadpanel,#fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
9
    #fileuploadstatus,#fileuploadfailed,#jobpanel,#jobstatus,#jobfailed { display : none; }
8
	#fileuploadstatus,#jobstatus { margin:.4em; }
10
	#fileuploadstatus,#jobstatus { margin:.4em; }
9
    #fileuploadprogress,#jobprogress{ width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }</style>
11
    #fileuploadprogress,#jobprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
12
</style>
13
10
<script type="text/javascript">
14
<script type="text/javascript">
11
//<![CDATA[
15
//<![CDATA[
16
function StartUpload() {
17
    if( $('#fileToUpload').prop('files').length == 0 ) return;
18
    $('#uploadform button.submit').prop('disabled',true);
19
    $("#fileuploadstatus").show();
20
    $("#uploadedfileid").val('');
21
    xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
22
}
23
function cbUpload( status, fileid ) {
24
    if( status=='done' ) {
25
        $("#uploadedfileid").val( fileid );
26
        $('#fileToUpload').prop('disabled',true);
27
        $("#processfile").show();
28
    } else {
29
        $("#fileuploadstatus").hide();
30
        $("#fileuploadfailed").show();
31
        $("#fileuploadfailed").text( _("Upload status: ") +
32
            ( status=='failed'? _("Failed"):
33
            ( status=='denied'? _("Denied"): status ))
34
        );
35
        $("#processfile").hide();
36
    }
37
}
12
$(document).ready(function(){
38
$(document).ready(function(){
13
	$("#processfile").hide();
39
	$("#processfile").hide();
14
	$("#zipfile").click(function(){
40
	$("#zipfile").click(function(){
Lines 19-25 $(document).ready(function(){ Link Here
19
	});
45
	});
20
    $("#uploadfile").validate({
46
    $("#uploadfile").validate({
21
        submitHandler: function(form) {
47
        submitHandler: function(form) {
22
            ajaxFileUpload();
48
            StartUpload();
49
            return false;
23
        }
50
        }
24
    });
51
    });
25
});
52
});
Lines 76-83 $(document).ready(function(){ Link Here
76
    <fieldset class="action"><button class="submit">Upload file</button></fieldset>
103
    <fieldset class="action"><button class="submit">Upload file</button></fieldset>
77
</fieldset>
104
</fieldset>
78
105
79
        <div id="uploadpanel"><div id="fileuploadstatus">Upload progress: <div id="fileuploadprogress"></div> <span id="fileuploadpercent">0</span>%</div>
106
    <div id="uploadpanel">
80
        <div id="fileuploadfailed"></div></div>
107
        <div id="fileuploadstatus">Upload progress:
108
            <progress min="0" max="100" value="0" id="fileuploadprogress">
109
            </progress>
110
            <span class="fileuploadpercent">0</span>%
111
        </div>
112
        <div id="fileuploadfailed"></div>
113
    </div>
81
</form>
114
</form>
82
115
83
    <form method="post" id="processfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
116
    <form method="post" id="processfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt (+342 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% USE Koha %]
3
[% IF plugin %]
4
    <title>Upload plugin</title>
5
[% ELSE %]
6
    <title>Koha &rsaquo; Tools &rsaquo; Upload</title>
7
[% END %]
8
[% INCLUDE 'doc-head-close.inc' %]
9
10
[% BLOCK plugin_pars %]
11
    [% IF plugin %]
12
        <input type="hidden" name="plugin" value="1" />
13
        <input type="hidden" name="index" value="[% index %]" />
14
    [% END %]
15
[% END %]
16
17
[% BLOCK breadcrumbs %]
18
    <div id="breadcrumbs">
19
        <a href="/cgi-bin/koha/mainpage.pl">Home</a>
20
        &rsaquo;
21
        <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>
22
        &rsaquo;
23
        <a href="/cgi-bin/koha/tools/upload.pl">Upload</a>
24
        &rsaquo;
25
        <span id="lastbreadcrumb">
26
        [% IF mode=='new' || mode =='deleted'%]
27
            Add new upload or search
28
        [% ELSE %]
29
            Results
30
        [% END %]
31
        </span>
32
    </div>
33
[% END %]
34
35
[% BLOCK form_new %]
36
    <form method="post" action="[% SCRIPT_NAME %]" id="uploadfile" enctype="multipart/form-data">
37
        [% PROCESS plugin_pars %]
38
        <fieldset class="rows" id="uploadform">
39
        <legend>Upload new files</legend>
40
        <ol>
41
        <li>
42
        <div id="fileuploadform">
43
            <label for="fileToUpload">Select files: </label>
44
            <input type="file" id="fileToUpload" name="fileToUpload" multiple/>
45
        </div>
46
        </li>
47
        [% IF uploadcategories %]
48
            <li>
49
                <label for="uploadcategory">Category: </label>
50
                <select id="uploadcategory" name="uploadcategory">
51
                [% IF !plugin %]
52
                    <option value="" disabled hidden selected></option>
53
                [% END %]
54
                [% FOREACH cat IN uploadcategories %]
55
                    <option value="[% cat.code %]">[% cat.name %]</option>
56
                [% END %]
57
                </select>
58
            </li>
59
        [% END %]
60
        [% IF !plugin %]
61
            <li>
62
            [% IF uploadcategories %]
63
                <div class="hint">Note: For temporary uploads do not select a category.</div>
64
            [% ELSE %]
65
                <div class="hint">Note: No upload categories have been defined. All uploads will be marked as temporary.</div>
66
            [% END %]
67
            </li>
68
        [% END %]
69
        <li>
70
            [% IF plugin %]
71
                <input type="hidden" id="public" name="public" value="1"/>
72
            [% ELSE %]
73
                <label>&nbsp;</label>
74
                <input type="checkbox" id="public" name="public">
75
                    Allow public downloads
76
                </input>
77
            [% END %]
78
        </li>
79
        </ol>
80
        <fieldset class="action">
81
            <button id="fileuploadbutton" onclick="StartUpload(); return false;">Upload</button>
82
            <button id="fileuploadcancel" onclick="CancelUpload(); return false;">Cancel</button>
83
        </fieldset>
84
        </fieldset>
85
        <div id="fileuploadpanel">
86
            <div id="fileuploadstatus">Upload progress:
87
            <progress id="fileuploadprogress" min="0" max="100" value="0">
88
            </progress>
89
            <span class="fileuploadpercent">0</span>%
90
            </div>
91
            <div id="fileuploadfailed"></div>
92
        </div>
93
    </form>
94
[% END %]
95
96
[% BLOCK form_search %]
97
    <form method="post" id="searchfile" action="[% SCRIPT_NAME %]" enctype="multipart/form-data">
98
        [% PROCESS plugin_pars %]
99
        <input type="hidden" name="op" value="search"/>
100
        <fieldset class="rows">
101
        <legend>Search uploads by name or hashvalue</legend>
102
        <ol>
103
        <li>
104
            <label for="searchupload">Search term: </label>
105
            <input type="text" id="term" name="term" value=""/>
106
        </li>
107
        <li>
108
            <fieldset class="action">
109
                <button id="searchbutton" onclick="return CheckSearch();" class="submit">Search</button>
110
            </fieldset>
111
        </li>
112
        </ol>
113
        </fieldset>
114
    </form>
115
[% END %]
116
117
[% BLOCK submitter %]
118
    <form id="submitter" style="display:none;" method="post">
119
        [% PROCESS plugin_pars %]
120
        <input type="hidden" name="op" id="op" value=""/>
121
        <input type="hidden" name="id" id="id" value="" />
122
        <input type="hidden" name="msg" id="msg" value="" />
123
    </form>
124
[% END %]
125
126
[% BLOCK closer %]
127
    [% IF plugin %]
128
        <form id="closer">
129
            <fieldset class="action">
130
                <button onclick="window.close();return false;">Close</button>
131
            </fieldset>
132
        </form>
133
    [% END %]
134
[% END %]
135
136
[% BLOCK newsearch %]
137
    <form id="newsearch">
138
        <fieldset class="action">
139
            <button onclick="SubmitMe('new'); return false;">New search</button>
140
            [% IF plugin %]
141
                <button onclick="window.close();return false;">Close</button>
142
            [% END %]
143
        </fieldset>
144
    </form>
145
[% END %]
146
147
[% BLOCK table_results %]
148
    <table>
149
    <thead>
150
    <tr>
151
        <th>Filename</td>
152
        <th>Size</td>
153
        <th>Hashvalue</td>
154
        <th>Category</td>
155
        [% IF !plugin %]<th>Public</td>[% END %]
156
        [% IF !plugin %]<th>Temporary</td>[% END %]
157
        <th>Actions</td>
158
    </tr>
159
    </thead>
160
    <tbody>
161
    [% FOREACH record IN uploads %]
162
    <tr>
163
        <td>[% record.name %]</td>
164
        <td>[% record.filesize %]</td>
165
        <td>[% record.hashvalue %]</td>
166
        <td>[% record.categorycode %]</td>
167
        [% IF !plugin %]
168
            <td>[% IF record.public %]Yes[% ELSE %]No[% END %]</td>
169
            <td>[% IF record.permanent %]No[% ELSE %]Yes[% END %]</td>
170
        [% END %]
171
        <td>
172
            [% IF plugin %]
173
                <a href="" onclick="Choose('[% record.hashvalue %]'); return false;">Choose</a>&nbsp;
174
            [% END %]
175
            <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>
177
        </td>
178
   </tr>
179
   [% END %]
180
   </tbody>
181
   </table>
182
[% END %]
183
184
<style type="text/css">
185
    #fileuploadstatus,#fileuploadfailed { display : none; }
186
    #fileuploadstatus { margin:.4em; }
187
    #fileuploadprogress { width:150px;height:10px;border:1px solid #666;background:url('[% interface %]/[% theme %]/img/progress.png') -300px 0px no-repeat; }
188
</style>
189
190
<script type="text/javascript">
191
//<![CDATA[
192
    var errMESSAGES = [
193
        "Error 0: Not in use",
194
        _("This file already exists (in this category)."),
195
        _("File could not be created. Check permissions."),
196
        _("Your koha-conf.xml does not contain a valid upload_path."),
197
        _("No temporary directory found."),
198
        _("File could not be read."),
199
        _("File has been deleted."),
200
        _("File could not be deleted."),
201
    ];
202
//]]>
203
</script>
204
<script type="text/javascript" src="[% themelang %]/js/file-upload.js"></script>
205
<script type="text/javascript">
206
//<![CDATA[
207
function StartUpload() {
208
    if( $('#fileToUpload').prop('files').length == 0 ) return;
209
    $('#fileToUpload').prop('disabled',true);
210
    $('#fileuploadbutton').hide();
211
    $("#fileuploadcancel").show();
212
    $("#fileuploadfailed").html('');
213
    $("#myalerts").hide('');
214
    $("#myalerts").html('');
215
    $("#fileuploadstatus").show();
216
    $("#uploadedfileid").val('');
217
    $("#searchfile").hide();
218
    $("#lastbreadcrumb").text( _("Add a new upload") );
219
220
    var cat, xtra='';
221
    if( $("#uploadcategory").val() )
222
        cat = encodeURIComponent( $("#uploadcategory").val() );
223
    if( cat ) xtra= 'category=' + cat + '&';
224
    [% IF plugin %]
225
        xtra = xtra + 'public=1&temp=0';
226
    [% ELSE %]
227
        if( !cat ) xtra = 'temp=1&';
228
        if( $('#public').prop('checked') ) xtra = xtra + 'public=1';
229
    [% END %]
230
    xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), xtra, cbUpload );
231
}
232
function CancelUpload() {
233
    if( xhr ) xhr.abort();
234
    $("#fileuploadstatus").hide();
235
    $('#fileToUpload').prop('disabled', false);
236
    $('#fileuploadbutton').show();
237
    $("#fileuploadcancel").hide();
238
    $("#fileuploadfailed").show();
239
    $("#fileuploadfailed").text( _("Upload status: Cancelled ") );
240
}
241
function cbUpload( status, fileid, err ) {
242
    $('#fileToUpload').prop('disabled', false);
243
    if( status=='done' ) {
244
        var e = err? JSON.stringify(err): '';
245
        SubmitMe( 'search', fileid, e );
246
    } else {
247
        $('#fileuploadbutton').show();
248
        $("#fileuploadcancel").hide();
249
        $("#fileuploadstatus").hide();
250
        $("#fileuploadfailed").show();
251
        $("#fileuploadfailed").html( _("Upload status: ") +
252
            ( status=='failed'? _("Failed"):
253
            ( status=='denied'? _("Denied"): status ))
254
        );
255
        ShowAlerts( err );
256
    }
257
}
258
function ShowAlerts(err) {
259
    var str = '';
260
    for( var file in err ) {
261
        str= str + '<p>' + file + ': ' +
262
            errMESSAGES[ err[file] ] + '</p>';
263
    }
264
    if( str ) {
265
        $('#myalerts').html(str);
266
        $('#myalerts').show();
267
    }
268
}
269
function CheckSearch() {
270
    if( $("#term").val()=="" ) {
271
        alert( _("Please enter a search term.") );
272
        return false;
273
    }
274
    return true;
275
}
276
function SubmitMe(op, id, msg ) {
277
    $("#submitter #op").val( op );
278
    $("#submitter #id").val( id );
279
    $("#submitter #msg").val( msg );
280
    $("#submitter").submit();
281
}
282
function ClearField() {
283
    [% IF plugin %]
284
        $(window.opener.document).find('#[% index %]').val( '' );
285
    [% END %]
286
}
287
function Choose(hashval) {
288
    var res = '[% Koha.Preference('OPACBaseURL') %]';
289
    res = res.replace( /\/$/, '');
290
    res = res + '/cgi-bin/koha/opac-retrieve-file.pl?id=' + hashval;
291
    [% IF index %]
292
        $(window.opener.document).find('#[% index %]').val( res );
293
    [% END %]
294
    window.close();
295
}
296
$(document).ready(function() {
297
    [% IF msg %]
298
        ShowAlerts( [% msg %] );
299
    [% END %]
300
    $("#fileuploadcancel").hide();
301
});
302
//]]>
303
</script>
304
</head>
305
306
<body id="tools_upload" class="tools">
307
[% IF !plugin %]
308
    [% INCLUDE 'header.inc' %]
309
    [% INCLUDE 'cat-search.inc' %]
310
    [% PROCESS breadcrumbs %]
311
[% END %]
312
313
<div id="doc3" class="yui-t2">
314
   <div id="bd">
315
    <div id="yui-main">
316
    <div class="yui-b">
317
318
<h1>Upload</h1>
319
320
<div class="dialog alert" id="myalerts" style="display:none;"></div>
321
322
[% PROCESS submitter %]
323
[% IF mode == 'new' || mode == 'deleted' %]
324
    [% PROCESS form_new %]
325
    [% PROCESS form_search %]
326
    [% PROCESS closer %]
327
[% ELSIF mode == 'report' %]
328
    [% IF uploads %]
329
        <h3>Your request gave the following results:</h3>
330
        [% PROCESS table_results %]
331
        [% PROCESS closer %]
332
    [% ELSE %]
333
        <h4>Sorry, your request had no results.</h4>
334
        [% PROCESS newsearch %]
335
    [% END %]
336
[% END %]
337
338
</div>
339
</div>
340
</div>
341
342
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-retrieve-file.tt (+6 lines)
Line 0 Link Here
1
[%# This template is called only for a very simple error message %]
2
<html>
3
<body>
4
Your search [% IF hash %]for [% hash %][% END %] was not successful.
5
</body>
6
</html>
(-)a/offline_circ/enqueue_koc.pl (-3 / +3 lines)
Lines 32-38 use C4::Circulation; Link Here
32
use C4::Items;
32
use C4::Items;
33
use C4::Members;
33
use C4::Members;
34
use C4::Stats;
34
use C4::Stats;
35
use C4::UploadedFile;
35
use Koha::Upload;
36
36
37
use Date::Calc qw( Add_Delta_Days Date_to_Days );
37
use Date::Calc qw( Add_Delta_Days Date_to_Days );
38
38
Lines 60-67 my $sessionID = $cookies{'CGISESSID'}->value; Link Here
60
our $dbh = C4::Context->dbh();
60
our $dbh = C4::Context->dbh();
61
61
62
if ($fileID) {
62
if ($fileID) {
63
    my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
63
    my $upload = Koha::Upload->new->get({ id => $fileID, filehandle => 1 });
64
    my $fh = $uploaded_file->fh();
64
    my $fh = $upload->{fh};
65
    my @input_lines = <$fh>;
65
    my @input_lines = <$fh>;
66
66
67
    my $header_line = shift @input_lines;
67
    my $header_line = shift @input_lines;
(-)a/offline_circ/process_koc.pl (-4 / +4 lines)
Lines 32-38 use C4::Circulation; Link Here
32
use C4::Items;
32
use C4::Items;
33
use C4::Members;
33
use C4::Members;
34
use C4::Stats;
34
use C4::Stats;
35
use C4::UploadedFile;
35
use Koha::Upload;
36
use C4::BackgroundJob;
36
use C4::BackgroundJob;
37
37
38
use Date::Calc qw( Add_Delta_Days Date_to_Days );
38
use Date::Calc qw( Add_Delta_Days Date_to_Days );
Lines 69-79 if ($completedJobID) { Link Here
69
    $template->param(transactions_loaded => 1);
69
    $template->param(transactions_loaded => 1);
70
    $template->param(messages => $results->{results});
70
    $template->param(messages => $results->{results});
71
} elsif ($fileID) {
71
} elsif ($fileID) {
72
    my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
72
    my $upload = Koha::Upload->new->get({ id => $fileID, filehandle => 1 });
73
    my $fh = $uploaded_file->fh();
73
    my $fh = $upload->{fh};
74
    my $filename = $upload->{name};
74
    my @input_lines = <$fh>;
75
    my @input_lines = <$fh>;
75
76
76
    my $filename = $uploaded_file->name();
77
    my $job = undef;
77
    my $job = undef;
78
78
79
    if ($runinbackground) {
79
    if ($runinbackground) {
(-)a/opac/opac-retrieve-file.pl (-11 / +25 lines)
Lines 19-37 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use CGI;
21
use CGI;
22
use Encode;
22
23
24
use C4::Auth;
23
use C4::Context;
25
use C4::Context;
24
use C4::UploadedFiles;
26
use C4::Output;
27
use Koha::Upload;
25
28
26
my $input = new CGI;
29
my $input = CGI::->new;
30
my $hash = $input->param('id'); # historically called id (used in URLs?)
27
31
28
my $id = $input->param('id');
32
my $upl = Koha::Upload->new({ public => 1 });
29
my $file = C4::UploadedFiles::GetUploadedFile($id);
33
my $rec = $upl->get({ hashvalue => $hash, filehandle => 1 });
30
exit 1 if !$file || !-f $file->{filepath};
34
my $fh = $rec->{fh};
31
35
if( !$rec || !$fh ) {
32
open my $fh, '<', $file->{filepath} or die "Can't open file: $!";
36
    my ( $template, $user, $cookie ) = get_template_and_user({
33
print $input->header( C4::UploadedFiles::httpheaders( $file->{filename} ));
37
        query           => $input,
34
while(<$fh>) {
38
        template_name   => 'opac-retrieve-file.tt',
35
    print $_;
39
        type            => 'opac',
40
        authnotrequired => 1,
41
    });
42
    $template->param( hash => $hash );
43
    output_html_with_http_headers $input, $cookie, $template->output;
44
} else {
45
    my @hdr = $upl->httpheaders( $rec->{name} );
46
    print Encode::encode_utf8( $input->header( @hdr ) );
47
    while( <$fh> ) {
48
        print $_;
49
    }
50
    $fh->close;
36
}
51
}
37
close $fh;
(-)a/tools/stage-marc-import.pl (-4 / +5 lines)
Lines 39-45 use C4::Output; Link Here
39
use C4::Biblio;
39
use C4::Biblio;
40
use C4::ImportBatch;
40
use C4::ImportBatch;
41
use C4::Matcher;
41
use C4::Matcher;
42
use C4::UploadedFile;
42
use Koha::Upload;
43
use C4::BackgroundJob;
43
use C4::BackgroundJob;
44
use C4::MarcModificationTemplates;
44
use C4::MarcModificationTemplates;
45
use Koha::Plugins;
45
use Koha::Plugins;
Lines 84-91 if ($completedJobID) { Link Here
84
    my $results = $job->results();
84
    my $results = $job->results();
85
    $template->param(map { $_ => $results->{$_} } keys %{ $results });
85
    $template->param(map { $_ => $results->{$_} } keys %{ $results });
86
} elsif ($fileID) {
86
} elsif ($fileID) {
87
    my $uploaded_file = C4::UploadedFile->fetch($sessionID, $fileID);
87
    my $upload = Koha::Upload->new->get({ id => $fileID, filehandle => 1 });
88
    my $fh = $uploaded_file->fh();
88
    my $fh = $upload->{fh};
89
    my $filename = $upload->{name}; # filename only, no path
89
	my $marcrecord='';
90
	my $marcrecord='';
90
    $/ = "\035";
91
    $/ = "\035";
91
	while (<$fh>) {
92
	while (<$fh>) {
Lines 93-100 if ($completedJobID) { Link Here
93
        s/\s+$//;
94
        s/\s+$//;
94
		$marcrecord.=$_;
95
		$marcrecord.=$_;
95
	}
96
	}
97
    $fh->close;
96
98
97
    my $filename = $uploaded_file->name();
98
    my $job = undef;
99
    my $job = undef;
99
    my $dbh;
100
    my $dbh;
100
    if ($runinbackground) {
101
    if ($runinbackground) {
(-)a/tools/upload-cover-image.pl (-4 / +4 lines)
Lines 47-53 use C4::Context; Link Here
47
use C4::Auth;
47
use C4::Auth;
48
use C4::Output;
48
use C4::Output;
49
use C4::Images;
49
use C4::Images;
50
use C4::UploadedFile;
50
use Koha::Upload;
51
use C4::Log;
51
use C4::Log;
52
52
53
my $debug = 1;
53
my $debug = 1;
Lines 83-91 $template->{VARS}->{'biblionumber'} = $biblionumber; Link Here
83
my $total = 0;
83
my $total = 0;
84
84
85
if ($fileID) {
85
if ($fileID) {
86
    my $uploaded_file = C4::UploadedFile->fetch( $sessionID, $fileID );
86
    my $upload = Koha::Upload->new->get({ id => $fileID, filehandle => 1 });
87
    if ( $filetype eq 'image' ) {
87
    if ( $filetype eq 'image' ) {
88
        my $fh       = $uploaded_file->fh();
88
        my $fh       = $upload->{fh};
89
        my $srcimage = GD::Image->new($fh);
89
        my $srcimage = GD::Image->new($fh);
90
        if ( defined $srcimage ) {
90
        if ( defined $srcimage ) {
91
            my $dberror = PutImage( $biblionumber, $srcimage, $replace );
91
            my $dberror = PutImage( $biblionumber, $srcimage, $replace );
Lines 102-108 if ($fileID) { Link Here
102
        undef $srcimage;
102
        undef $srcimage;
103
    }
103
    }
104
    else {
104
    else {
105
        my $filename = $uploaded_file->filename();
105
        my $filename = $upload->{path};
106
        my $dirname = File::Temp::tempdir( CLEANUP => 1 );
106
        my $dirname = File::Temp::tempdir( CLEANUP => 1 );
107
        unless ( system( "unzip", $filename, '-d', $dirname ) == 0 ) {
107
        unless ( system( "unzip", $filename, '-d', $dirname ) == 0 ) {
108
            $error = 'UZIPFAIL';
108
            $error = 'UZIPFAIL';
(-)a/tools/upload-file.pl (-41 / +41 lines)
Lines 17-34 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
#use warnings; FIXME - Bug 2505
22
21
23
# standard or CPAN modules used
24
use IO::File;
25
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
26
use CGI::Session;
23
use CGI::Cookie;
24
use Encode;
25
use JSON;
26
use URI::Escape;
27
27
use C4::Context;
28
use C4::Context;
28
use C4::Auth qw/check_cookie_auth haspermission/;
29
use C4::Auth qw/check_cookie_auth haspermission/;
29
use CGI::Cookie; # need to check cookies before
30
use Koha::Upload;
30
                 # having CGI parse the POST request
31
use C4::UploadedFile;
32
31
33
# upload-file.pl must authenticate the user
32
# upload-file.pl must authenticate the user
34
# before processing the POST request,
33
# before processing the POST request,
Lines 36-42 use C4::UploadedFile; Link Here
36
# not authorized.  Consequently, unlike
35
# not authorized.  Consequently, unlike
37
# most of the other CGI scripts, upload-file.pl
36
# most of the other CGI scripts, upload-file.pl
38
# requires that the session cookie already
37
# requires that the session cookie already
39
# have been created.
38
# has been created.
40
39
41
my $flags_required = [
40
my $flags_required = [
42
    {circulate  => 'circulate_remaining_permissions'},
41
    {circulate  => 'circulate_remaining_permissions'},
Lines 44-95 my $flags_required = [ Link Here
44
    {tools      => 'upload_local_cover_images'}
43
    {tools      => 'upload_local_cover_images'}
45
];
44
];
46
45
47
my %cookies = fetch CGI::Cookie;
46
my %cookies = CGI::Cookie->fetch;
47
my $sid = $cookies{'CGISESSID'}->value;
48
48
49
my $auth_failure = 1;
49
my $auth_failure = 1;
50
my ( $auth_status, $sessionID ) = check_cookie_auth( $cookies{'CGISESSID'}->value );
50
my ( $auth_status, $sessionID ) = check_cookie_auth( $sid );
51
my $uid = C4::Auth::get_session($sid)->param('id');
51
foreach my $flag_required ( @{$flags_required} ) {
52
foreach my $flag_required ( @{$flags_required} ) {
52
    if ( my $flags = haspermission( C4::Context->config('user'), $flag_required ) ) {
53
    if ( my $flags = haspermission( $uid, $flag_required ) ) {
53
        $auth_failure = 0 if $auth_status eq 'ok';
54
        $auth_failure = 0 if $auth_status eq 'ok';
54
    }
55
    }
55
}
56
}
56
57
57
if ($auth_failure) {
58
if ($auth_failure) {
58
    $auth_status = 'denied' if $auth_status eq 'failed';
59
    send_reply( 'denied' );
59
    send_reply($auth_status, "");
60
    exit 0;
60
    exit 0;
61
}
61
}
62
62
63
our $uploaded_file = C4::UploadedFile->new($sessionID);
63
my $upload = Koha::Upload->new( upload_pars($ENV{QUERY_STRING}) );
64
unless (defined $uploaded_file) {
64
if( !$upload || !$upload->cgi || !$upload->count ) {
65
    # FIXME - failed to create file for some reason
65
    # not one upload succeeded
66
    send_reply('failed', '');
66
    send_reply( 'failed', undef, $upload? $upload->err: undef );
67
    exit 0;
67
} else {
68
    # in case of multiple uploads, at least one got through
69
    send_reply( 'done', $upload->result, $upload->err );
68
}
70
}
69
$uploaded_file->max_size($ENV{'CONTENT_LENGTH'}); # may not be the file size, exactly
70
71
my $query;
72
$query = new CGI \&upload_hook;
73
$uploaded_file->done();
74
send_reply('done', $uploaded_file->id());
75
76
# FIXME - if possible, trap signal caused by user cancelling upload
77
# FIXME - something is wrong during cleanup: \t(in cleanup) Can't call method "commit" on unblessed reference at /usr/local/share/perl/5.8.8/CGI/Session/Driver/DBI.pm line 130 during global destruction.
78
exit 0;
71
exit 0;
79
72
80
sub upload_hook {
73
sub send_reply {    # response will be sent back as JSON
81
    my ($file_name, $buffer, $bytes_read, $session) = @_;
74
    my ( $upload_status, $data, $error ) = @_;
82
    $uploaded_file->stash(\$buffer, $bytes_read);
75
    my $reply = CGI->new("");
83
    if ( ! $uploaded_file->name && $file_name ) { # save name on first chunk
76
    print $reply->header( -type => 'text/html', -charset => 'UTF-8' );
84
        $uploaded_file->name($file_name);
77
    print JSON::encode_json({
85
    }
78
        status => $upload_status,
79
        fileid => $data,
80
        errors => $error,
81
   });
86
}
82
}
87
83
88
sub send_reply {
84
sub upload_pars {
89
    my ($upload_status, $fileid) = @_;
85
    my ( $qstr ) = @_;
90
86
    $qstr = Encode::decode_utf8( uri_unescape( $qstr ) );
91
    my $reply = CGI->new("");
87
    # category could include a utf8 character
92
    print $reply->header(-type => 'text/html');
88
    my $rv = {};
93
    # response will be sent back as JSON
89
    foreach my $p ( qw[public category temp] ) {
94
    print '{"status":"' . $upload_status . '","fileid":"' . $fileid . '"}';
90
        if( $qstr =~ /(^|&)$p=(\w+)(&|$)/ ) {
91
            $rv->{$p} = $2;
92
        }
93
    }
94
    return $rv;
95
}
95
}
(-)a/tools/upload.pl (-1 / +101 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2015 Rijksmuseum
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw/-utf8/;
22
use JSON;
23
24
use C4::Auth;
25
use C4::Output;
26
use Koha::Upload;
27
28
my $input  = CGI::->new;
29
my $op     = $input->param('op') // 'new';
30
my $plugin = $input->param('plugin');
31
my $index  = $input->param('index');         # MARC editor input field id
32
my $term   = $input->param('term');
33
my $id     = $input->param('id');
34
my $msg    = $input->param('msg');
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {   template_name   => "tools/upload.tt",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { editcatalogue => '*' },
42
    }
43
);
44
45
$template->param(
46
    plugin => $plugin,
47
    index  => $index,
48
);
49
50
my $upar = $plugin ? { public => 1 } : {};
51
if ( $op eq 'new' ) {
52
    $template->param(
53
        mode             => 'new',
54
        uploadcategories => Koha::Upload->getCategories,
55
    );
56
    output_html_with_http_headers $input, $cookie, $template->output;
57
} elsif ( $op eq 'search' ) {
58
    my $h = $id ? { id => $id } : { term => $term };
59
    my @uploads = Koha::Upload->new($upar)->get($h);
60
    $template->param(
61
        mode    => 'report',
62
        msg     => $msg,
63
        uploads => \@uploads,
64
    );
65
    output_html_with_http_headers $input, $cookie, $template->output;
66
} elsif ( $op eq 'delete' ) {
67
68
    # delete only takes the id parameter
69
    my $upl = Koha::Upload->new($upar);
70
    my ($fn) = $upl->delete( { id => $id } );
71
    my $e = $upl->err;
72
    my $msg =
73
        $fn ? JSON::to_json( { $fn => 6 } )
74
      : $e  ? JSON::to_json($e)
75
      :       undef;
76
    $template->param(
77
        mode             => 'deleted',
78
        msg              => $msg,
79
        uploadcategories => $upl->getCategories,
80
    );
81
    output_html_with_http_headers $input, $cookie, $template->output;
82
} elsif ( $op eq 'download' ) {
83
    my $upl = Koha::Upload->new($upar);
84
    my $rec = $upl->get( { id => $id, filehandle => 1 } );
85
    my $fh  = $rec->{fh};
86
    if ( !$rec || !$fh ) {
87
        $template->param(
88
            mode             => 'new',
89
            msg              => JSON::to_json( { $id => 5 } ),
90
            uploadcategories => $upl->getCategories,
91
        );
92
        output_html_with_http_headers $input, $cookie, $template->output;
93
    } else {
94
        my @hdr = $upl->httpheaders( $rec->{name} );
95
        print Encode::encode_utf8( $input->header(@hdr) );
96
        while (<$fh>) {
97
            print $_;
98
        }
99
        $fh->close;
100
    }
101
}

Return to bug 14321