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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patroncards-errors.inc (-1 / +2 lines)
Lines 29-34 Link Here
29
        Image exceeds 500KB. Please resize and import again.
29
        Image exceeds 500KB. Please resize and import again.
30
        [% ELSIF ( error == 303 ) %]
30
        [% ELSIF ( error == 303 ) %]
31
        The database image quota currently only allows a maximum of [% image_limit %] images to be stored at any one time. Please delete one or more images to free up quota space.
31
        The database image quota currently only allows a maximum of [% image_limit %] images to be stored at any one time. Please delete one or more images to free up quota space.
32
        [% ELSIF ( error == 304 ) %]
33
        An image with the name '[% IMAGE_NAME %]' already exists.
32
        [% ELSIF ( error == 401 ) %]
34
        [% ELSIF ( error == 401 ) %]
33
        An error has occurred and the item(s) was not added to batch [% batch_id %]. Please have your system administrator check the error log for details.
35
        An error has occurred and the item(s) was not added to batch [% batch_id %]. Please have your system administrator check the error log for details.
34
        [% ELSIF ( error == 402 ) %]
36
        [% ELSIF ( error == 402 ) %]
Lines 39-45 Link Here
39
        An error has occurred and batch [% batch_id %] was not deleted.  Please have your system administrator check the error log for details.
41
        An error has occurred and batch [% batch_id %] was not deleted.  Please have your system administrator check the error log for details.
40
        [% ELSIF ( error == 405 ) %]
42
        [% ELSIF ( error == 405 ) %]
41
        An error has occurred and batch [% batch_id %] not fully de-duplicated.
43
        An error has occurred and batch [% batch_id %] not fully de-duplicated.
42
        [% ELSE %]
43
        [% END %]
44
        [% END %]
44
  </p>
45
  </p>
45
</div>
46
</div>
(-)a/patroncards/image-manage.pl (-26 / +47 lines)
Lines 14-19 use C4::Output; Link Here
14
use C4::Debug;
14
use C4::Debug;
15
use C4::Creators;
15
use C4::Creators;
16
use C4::Patroncards;
16
use C4::Patroncards;
17
use Data::Dumper;
17
18
18
my $cgi = CGI->new;
19
my $cgi = CGI->new;
19
20
Lines 47-55 my $image_limit = C4::Context->preference('ImageLimit') || ''; Link Here
47
my $errstr = '';        # NOTE: For error codes see error-messages.inc
48
my $errstr = '';        # NOTE: For error codes see error-messages.inc
48
49
49
if ($op eq 'upload') {
50
if ($op eq 'upload') {
50
    if (!$upload_file) {
51
    # Checking for duplicate image name
51
        warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
52
    my $duplicate;
52
        $errstr = 301;
53
    my $dbh = C4::Context->dbh;
54
    my $query = "SELECT COUNT(*) FROM creator_images WHERE image_name=?";
55
    my $sth = $dbh->prepare($query);
56
    $sth->execute($image_name);
57
    my $count = $sth->fetchrow_arrayref;
58
    if ( $count->[0] > 0 ) {
59
        $duplicate = 1;
60
        warn sprintf('Image name already exists.');
61
        $errstr = 304;
53
        $template->param(
62
        $template->param(
54
            IMPORT_SUCCESSFUL => 0,
63
            IMPORT_SUCCESSFUL => 0,
55
            SOURCE_FILE => $source_file,
64
            SOURCE_FILE => $source_file,
Lines 58-69 if ($op eq 'upload') { Link Here
58
            error => $errstr,
67
            error => $errstr,
59
        );
68
        );
60
    }
69
    }
61
    else {
70
    unless ($duplicate) {
62
        my $image = Graphics::Magick->new;
71
        if (!$upload_file) {
63
        eval{$image->Read($cgi->tmpFileName($file_name));};
72
            warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
64
        if ($@) {
73
            $errstr = 301;
65
            warn sprintf('An error occurred while creating the image object: %s',$@);
66
            $errstr = 202;
67
            $template->param(
74
            $template->param(
68
                IMPORT_SUCCESSFUL => 0,
75
                IMPORT_SUCCESSFUL => 0,
69
                SOURCE_FILE => $source_file,
76
                SOURCE_FILE => $source_file,
Lines 73-103 if ($op eq 'upload') { Link Here
73
            );
80
            );
74
        }
81
        }
75
        else {
82
        else {
76
            my $errstr = '';
83
            my $image = Graphics::Magick->new;
77
            my $size = $image->Get('filesize');
84
            eval{$image->Read($cgi->tmpFileName($file_name));};
78
            $errstr =  302 if $size > 500000;
85
            if ($@) {
79
            $image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
86
                warn sprintf('An error occurred while creating the image object: %s',$@);
80
            my $err = put_image($image_name, $image->ImageToBlob()) || '0';
87
                $errstr = 202;
81
            $errstr = 101 if $err == 1;
82
            $errstr = 303 if $err == 202;
83
            if ($errstr) {
84
                $template->param(
88
                $template->param(
85
                    IMPORT_SUCCESSFUL => 0,
89
                    IMPORT_SUCCESSFUL => 0,
86
                    SOURCE_FILE => $source_file,
90
                    SOURCE_FILE => $source_file,
87
                    IMAGE_NAME => $image_name,
91
                    IMAGE_NAME => $image_name,
88
                    TABLE => $table,
92
                    TABLE => $table,
89
                    error => $errstr,
93
                    error => $errstr,
90
                    image_limit => $image_limit,
91
                );
94
                );
92
            }
95
            }
93
            else {
96
            else {
94
                $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name"));  # refresh table data after successfully performing save operation
97
                my $errstr = '';
95
                $template->param(
98
                my $size = $image->Get('filesize');
96
                    IMPORT_SUCCESSFUL => 1,
99
                $errstr =  302 if $size > 500000;
97
                    SOURCE_FILE => $source_file,
100
                $image->Set(magick => 'png'); # convert all images to png as this is a lossless format which is important for resizing operations later on
98
                    IMAGE_NAME => $image_name,
101
                my $err = put_image($image_name, $image->ImageToBlob()) || '0';
99
                    TABLE => $table,
102
                $errstr = 101 if $err == 1;
100
                );
103
                $errstr = 303 if $err == 202;
104
                if ($errstr) {
105
                    $template->param(
106
                        IMPORT_SUCCESSFUL => 0,
107
                        SOURCE_FILE => $source_file,
108
                        IMAGE_NAME => $image_name,
109
                        TABLE => $table,
110
                        error => $errstr,
111
                        image_limit => $image_limit,
112
                    );
113
                }
114
                else {
115
                    $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name"));  # refresh table data after successfully performing save operation
116
                    $template->param(
117
                        IMPORT_SUCCESSFUL => 1,
118
                        SOURCE_FILE => $source_file,
119
                        IMAGE_NAME => $image_name,
120
                        TABLE => $table,
121
                    );
122
                }
101
            }
123
            }
102
        }
124
        }
103
    }
125
    }
104
- 

Return to bug 17181