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

(-)a/admin/authorised_values.pl (-45 / +54 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=? ");
109
        my ($category, $authorised_value) = $sth->fetchrow_array();
110
            $sth->execute($id);
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 = ? AND authorised_value = ? and id<>?");
115
                $sth->execute($new_category, $new_authorised_value, $id);
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 = ? AND authorised_value = ? ");
113
            $sth->execute();
139
            $sth->execute($new_category, $new_authorised_value);
114
            ($duplicate_entry) = $sth->fetchrow_array();
140
            ($duplicate_entry) = $sth->fetchrow_array();
115
            warn "**** duplicate_entry = $duplicate_entry";
141
            unless ( $duplicate_entry ) {
116
        }
142
                my $sth=$dbh->prepare( 'INSERT INTO authorised_values
117
        unless ( $duplicate_entry ) {
143
                                        ( id, category, authorised_value, lib, lib_opac, imageurl )
118
            my $sth=$dbh->prepare( 'UPDATE authorised_values
144
                                        values (?, ?, ?, ?, ?, ?)' );
119
                                      SET category         = ?,
145
                my $lib = $input->param('lib');
120
                                          authorised_value = ?,
146
                my $lib_opac = $input->param('lib_opac');
121
                                          lib              = ?,
147
                undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
122
                                          lib_opac         = ?,
148
                undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
123
                                          imageurl         = ?
149
                $sth->execute($id, $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
124
                                      WHERE id=?' );
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>";
125
            my $lib = $input->param('lib');
151
                exit;
126
            my $lib_opac = $input->param('lib_opac');
152
            }
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
        }
153
        }
133
    }
154
        if ( $duplicate_entry ) {
134
    else { # Insert
155
            $template->param(duplicate_category => $new_category,
135
        my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
156
                             duplicate_value =>  $new_authorised_value,
136
            "WHERE category = '$new_category' AND authorised_value = '$new_authorised_value' ");
157
                             else => 1);
137
        $sth->execute();
158
            default_form();
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
        }
159
        }
151
    }
160
    }
152
    if ( $duplicate_entry ) {       
161
    else {
153
        $template->param(duplicate_category => $new_category,
162
        $template->param(rejected_category => $new_category,
154
                         duplicate_value =>  $new_authorised_value,
163
                         rejected_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 (-8 / +34 lines)
Lines 18-23 Link Here
18
18
19
<script type="text/JavaScript" language="JavaScript">
19
<script type="text/JavaScript" language="JavaScript">
20
//<![CDATA[
20
//<![CDATA[
21
    function CheckAttributeTypeForm(f) {
22
        var ok=1;
23
        var _alertString="";
24
        var alertString2;
25
        
26
        var patt=/^[a-zA-Z0-9\-_]+$/g;
27
        
28
        if (f.authorised_value.value.length==0) {
29
            _alertString += "\n- " + _("Authorized value missing");
30
        }
31
        else if (! patt.test(f.authorised_value.value) ) {
32
            _alertString += "\n- " + _("The authorized value can only contain the following characters: letters, numbers, - and _");
33
        }
34
        if (_alertString.length==0) {
35
            document.Aform.submit();
36
        } else {
37
            alertString2  = _("Form not submitted because of the following problem(s)");
38
            alertString2 += "\n------------------------------------------------------------------------------------\n";
39
            alertString2 += _alertString;
40
            alert(alertString2);
41
        }
42
    }
43
21
     $(document).ready(function() {
44
     $(document).ready(function() {
22
        $('#icons > ul').tabs();
45
        $('#icons > ul').tabs();
23
     });
46
     });
Lines 51-56 Link Here
51
	   [% IF ( action_add_category ) %]New category[% END %]
74
	   [% IF ( action_add_category ) %]New category[% END %]
52
	</h1>
75
	</h1>
53
76
77
    [% IF ( duplicate_category ) %]
78
    <div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
79
    </div>
80
    [% END %]
81
    [% IF ( rejected_category ) %]
82
    <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 _
83
    </div>
84
    [% END %]
85
54
    [% IF ( action_modify ) %]<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>[% END %]
86
    [% IF ( action_modify ) %]<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>[% END %]
55
87
56
	<form action="[% script_name %]" name="Aform" method="post">
88
	<form action="[% script_name %]" name="Aform" method="post">
Lines 67-74 Link Here
67
        <li>
99
        <li>
68
            <label for="authorised_value">Authorized value</label>
100
            <label for="authorised_value">Authorized value</label>
69
     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
101
     [% 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" />
102
            <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>
103
        <li>
73
            <label for="lib">Description</label>
104
            <label for="lib">Description</label>
74
            <input type="text" name="lib" id="lib" value="[% lib %]" maxlength="80" />
105
            <input type="text" name="lib" id="lib" value="[% lib %]" maxlength="80" />
Lines 115-121 Link Here
115
  
146
  
116
        </fieldset>
147
        </fieldset>
117
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
148
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
118
        <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
149
        <input type="button" value="Save" onclick="CheckAttributeTypeForm(this.form)" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
119
    </form>
150
    </form>
120
[% END %]
151
[% END %]
121
152
Lines 178-187 Link Here
178
<h1>Authorized values</h1>
209
<h1>Authorized values</h1>
179
<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>
210
<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>
180
211
181
[% IF ( duplicate_category ) %]
182
<div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
183
</div>
184
[% 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>
212
<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' ) %]
213
[% IF ( category == 'Bsort1' ) %]
187
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
214
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
188
- 

Return to bug 7013