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

(-)a/admin/authorised_values.pl (-44 / +53 lines)
Lines 102-160 if ($op eq 'add_form') { Link Here
102
    my $imageurl     = $input->param( 'imageurl' ) || '';
102
    my $imageurl     = $input->param( 'imageurl' ) || '';
103
	$imageurl = '' if $imageurl =~ /removeImage/;
103
	$imageurl = '' if $imageurl =~ /removeImage/;
104
    my $duplicate_entry = 0;
104
    my $duplicate_entry = 0;
105
    my $bad_chars = 0;
105
106
106
    if ( $id ) { # Update
107
    if ( $new_authorised_value =~ /^[a-zA-Z0-9\-_]+$/ ) {
107
        my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id='$id' ");
108
        if ( $id ) { # Update
108
        $sth->execute();
109
            my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id='$id' ");
109
        my ($category, $authorised_value) = $sth->fetchrow_array();
110
            $sth->execute();
110
        if ( $authorised_value ne $new_authorised_value ) {
111
            my ($category, $authorised_value) = $sth->fetchrow_array();
112
            if ( $authorised_value ne $new_authorised_value ) {
113
                my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
114
                    "WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' and id<>$id");
115
                $sth->execute();
116
                ($duplicate_entry) = $sth->fetchrow_array();
117
                warn "**** duplicate_entry = $duplicate_entry";
118
            }
119
            unless ( $duplicate_entry ) {
120
                my $sth=$dbh->prepare( 'UPDATE authorised_values
121
                                          SET category         = ?,
122
                                              authorised_value = ?,
123
                                              lib              = ?,
124
                                              lib_opac         = ?,
125
                                              imageurl         = ?
126
                                          WHERE id=?' );
127
                my $lib = $input->param('lib');
128
                my $lib_opac = $input->param('lib_opac');
129
                undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
130
                undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
131
                $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);          
132
                print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>";
133
                exit;
134
            }
135
        }
136
        else { # Insert
111
            my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
137
            my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
112
                "WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' and id<>$id");
138
                "WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' ");
113
            $sth->execute();
139
            $sth->execute();
114
            ($duplicate_entry) = $sth->fetchrow_array();
140
            ($duplicate_entry) = $sth->fetchrow_array();
115
            warn "**** duplicate_entry = $duplicate_entry";
141
            unless ( $duplicate_entry ) {
142
                my $sth=$dbh->prepare( 'INSERT INTO authorised_values
143
                                        ( id, category, authorised_value, lib, lib_opac, imageurl )
144
                                        values (?, ?, ?, ?, ?, ?)' );
145
                my $lib = $input->param('lib');
146
                my $lib_opac = $input->param('lib_opac');
147
                undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
148
                undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
149
                $sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
150
                print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>";
151
                exit;
152
            }
116
        }
153
        }
117
        unless ( $duplicate_entry ) {
154
        if ( $duplicate_entry ) {       
118
            my $sth=$dbh->prepare( 'UPDATE authorised_values
155
            $template->param(duplicate_category => $new_category,
119
                                      SET category         = ?,
156
                             duplicate_value =>  $new_authorised_value,
120
                                          authorised_value = ?,
157
                             else => 1);
121
                                          lib              = ?,
158
            default_form();
122
                                          lib_opac         = ?,
123
                                          imageurl         = ?
124
                                      WHERE id=?' );
125
            my $lib = $input->param('lib');
126
            my $lib_opac = $input->param('lib_opac');
127
            undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
128
            undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
129
            $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);          
130
            print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>";
131
            exit;
132
        }
159
        }
133
    }
160
    }
134
    else { # Insert
161
    else {
135
        my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
162
        $template->param(rejected_category => $new_category,
136
            "WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' ");
163
                         rejected_value =>  $new_authorised_value,
137
        $sth->execute();
138
        ($duplicate_entry) = $sth->fetchrow_array();
139
        unless ( $duplicate_entry ) {
140
            my $sth=$dbh->prepare( 'INSERT INTO authorised_values
141
                                    ( id, category, authorised_value, lib, lib_opac, imageurl )
142
                                    values (?, ?, ?, ?, ?, ?)' );
143
    	    my $lib = $input->param('lib');
144
    	    my $lib_opac = $input->param('lib_opac');
145
    	    undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
146
    	    undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
147
    	    $sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
148
    	    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>";
149
    	    exit;
150
        }
151
    }
152
    if ( $duplicate_entry ) {       
153
        $template->param(duplicate_category => $new_category,
154
                         duplicate_value =>  $new_authorised_value,
155
                         else => 1);
164
                         else => 1);
156
        default_form();
165
        default_form();
157
     }           
166
    }
158
	
167
	
159
################## DELETE_CONFIRM ##################################
168
################## DELETE_CONFIRM ##################################
160
# called by default form, used to confirm deletion of data in DB
169
# called by default form, used to confirm deletion of data in DB
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-3 / +5 lines)
Lines 67-74 Link Here
67
        <li>
67
        <li>
68
            <label for="authorised_value">Authorized value</label>
68
            <label for="authorised_value">Authorized value</label>
69
     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
69
     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
70
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" />
70
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" /> <span class="hint">Allowed characters : letters, numbers, dash and underscore</span></li>
71
        </li>
72
        <li>
71
        <li>
73
            <label for="lib">Description</label>
72
            <label for="lib">Description</label>
74
            <input type="text" name="lib" id="lib" value="[% lib %]" maxlength="80" />
73
            <input type="text" name="lib" id="lib" value="[% lib %]" maxlength="80" />
Lines 182-187 Link Here
182
<div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
181
<div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
183
</div>
182
</div>
184
[% END %]
183
[% END %]
184
[% IF ( rejected_category ) %]
185
<div class="dialog alert">Could not add value &quot;[% rejected_value %]&quot; for category &quot;[% rejected_category %]&quot; &mdash; the value can only contain the following characters: letters, numbers, - and _
186
</div>
187
[% END %]
185
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category"><label for="searchfield">Show Category: </label>[% tab_list %] <input type="submit" value="Submit" /></form>
188
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category"><label for="searchfield">Show Category: </label>[% tab_list %] <input type="submit" value="Submit" /></form>
186
[% IF ( category == 'Bsort1' ) %]
189
[% IF ( category == 'Bsort1' ) %]
187
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
190
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
188
- 

Return to bug 7013