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 (-33 / +55 lines)
Lines 47-69 my $image_limit = C4::Context->preference('ImageLimit') || ''; Link Here
47
my $errstr = '';        # NOTE: For error codes see error-messages.inc
47
my $errstr = '';        # NOTE: For error codes see error-messages.inc
48
48
49
if ($op eq 'upload') {
49
if ($op eq 'upload') {
50
    if (!$upload_file) {
50
    # Checking for duplicate image name
51
        warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
51
    my $duplicate;
52
        $errstr = 301;
52
    my $dbh = C4::Context->dbh;
53
        $template->param(
53
    my $query = "SELECT image_name FROM creator_images";
54
            IMPORT_SUCCESSFUL => 0,
54
    my $sth = $dbh->prepare($query);
55
            SOURCE_FILE => $source_file,
55
    $sth->execute();
56
            IMAGE_NAME => $image_name,
56
    my $image_names = $sth->fetchall_arrayref;
57
            TABLE => $table,
57
    foreach my $img ( @{$image_names} ) {
58
            error => $errstr,
58
        if ( $img->[0] eq $image_name ) {
59
        );
59
            $duplicate = 1;
60
            warn sprintf('Image name already exists.');
61
            $errstr = 304;
62
            $template->param(
63
                IMPORT_SUCCESSFUL => 0,
64
                SOURCE_FILE => $source_file,
65
                IMAGE_NAME => $image_name,
66
                TABLE => $table,
67
                error => $errstr,
68
            );
69
        }
60
    }
70
    }
61
    else {
71
    unless ($duplicate) {
62
        my $image = Graphics::Magick->new;
72
        if (!$upload_file) {
63
        eval{$image->Read($cgi->tmpFileName($file_name));};
73
            warn sprintf('An error occurred while attempting to upload file %s.', $source_file);
64
        if ($@) {
74
            $errstr = 301;
65
            warn sprintf('An error occurred while creating the image object: %s',$@);
66
            $errstr = 202;
67
            $template->param(
75
            $template->param(
68
                IMPORT_SUCCESSFUL => 0,
76
                IMPORT_SUCCESSFUL => 0,
69
                SOURCE_FILE => $source_file,
77
                SOURCE_FILE => $source_file,
Lines 73-103 if ($op eq 'upload') { Link Here
73
            );
81
            );
74
        }
82
        }
75
        else {
83
        else {
76
            my $errstr = '';
84
            my $image = Graphics::Magick->new;
77
            my $size = $image->Get('filesize');
85
            eval{$image->Read($cgi->tmpFileName($file_name));};
78
            $errstr =  302 if $size > 500000;
86
            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
87
                warn sprintf('An error occurred while creating the image object: %s',$@);
80
            my $err = put_image($image_name, $image->ImageToBlob()) || '0';
88
                $errstr = 202;
81
            $errstr = 101 if $err == 1;
82
            $errstr = 303 if $err == 202;
83
            if ($errstr) {
84
                $template->param(
89
                $template->param(
85
                    IMPORT_SUCCESSFUL => 0,
90
                    IMPORT_SUCCESSFUL => 0,
86
                    SOURCE_FILE => $source_file,
91
                    SOURCE_FILE => $source_file,
87
                    IMAGE_NAME => $image_name,
92
                    IMAGE_NAME => $image_name,
88
                    TABLE => $table,
93
                    TABLE => $table,
89
                    error => $errstr,
94
                    error => $errstr,
90
                    image_limit => $image_limit,
91
                );
95
                );
92
            }
96
            }
93
            else {
97
            else {
94
                $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name"));  # refresh table data after successfully performing save operation
98
                my $errstr = '';
95
                $template->param(
99
                my $size = $image->Get('filesize');
96
                    IMPORT_SUCCESSFUL => 1,
100
                $errstr =  302 if $size > 500000;
97
                    SOURCE_FILE => $source_file,
101
                $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,
102
                my $err = put_image($image_name, $image->ImageToBlob()) || '0';
99
                    TABLE => $table,
103
                $errstr = 101 if $err == 1;
100
                );
104
                $errstr = 303 if $err == 202;
105
                if ($errstr) {
106
                    $template->param(
107
                        IMPORT_SUCCESSFUL => 0,
108
                        SOURCE_FILE => $source_file,
109
                        IMAGE_NAME => $image_name,
110
                        TABLE => $table,
111
                        error => $errstr,
112
                        image_limit => $image_limit,
113
                    );
114
                }
115
                else {
116
                    $table = html_table($display_columns->{'image'}, get_image(undef, "image_id, image_name"));  # refresh table data after successfully performing save operation
117
                    $template->param(
118
                        IMPORT_SUCCESSFUL => 1,
119
                        SOURCE_FILE => $source_file,
120
                        IMAGE_NAME => $image_name,
121
                        TABLE => $table,
122
                    );
123
                }
101
            }
124
            }
102
        }
125
        }
103
    }
126
    }
104
- 

Return to bug 17181