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

(-)a/acqui/add_order_fields.pl (-123 lines)
Lines 1-123 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2014 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use CGI;
21
use C4::Auth;
22
use C4::Koha;
23
use C4::Output;
24
use Koha::AdditionalField;
25
26
my $input = new CGI;
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
30
        template_name   => "acqui/add_order_fields.tt",
31
        query           => $input,
32
        type            => "intranet",
33
        authnotrequired => 0,
34
        flagsrequired   => { acquisition => '*' },
35
        debug           => 1,
36
    }
37
);
38
39
my $op = $input->param('op') // 'list';
40
my $field_id = $input->param('field_id');
41
my @messages;
42
43
if ( $op eq 'add' ) {
44
    my $name = $input->param('name') // q{};
45
    my $authorised_value_category = $input->param('authorised_value_category') // q{};
46
    my $marcfield = $input->param('marcfield') // q{};
47
    if ( $field_id and $name ) {
48
        my $updated = 0;
49
        eval {
50
            my $af = Koha::AdditionalField->new({
51
                id => $field_id,
52
                name => $name,
53
                authorised_value_category => $authorised_value_category,
54
                marcfield => $marcfield,
55
            });
56
            $updated = $af->update;
57
        };
58
        push @messages, {
59
            code => 'update',
60
            number => $updated,
61
        };
62
    } elsif ( $name ) {
63
        my $inserted = 0;
64
        eval {
65
            my $af = Koha::AdditionalField->new({
66
                tablename => 'aqorders',
67
                name => $name,
68
                authorised_value_category => $authorised_value_category,
69
                marcfield => $marcfield,
70
            });
71
            $inserted = $af->insert;
72
        };
73
        push @messages, {
74
            code => 'insert',
75
            number => $inserted,
76
        };
77
    } else {
78
        push @messages, {
79
            code => 'insert',
80
            number => 0,
81
        };
82
    }
83
    $op = 'list';
84
}
85
86
if ( $op eq 'delete' ) {
87
    my $deleted = 0;
88
    eval {
89
        my $af = Koha::AdditionalField->new( { id => $field_id } );
90
        $deleted = $af->delete;
91
        $deleted = 0 if $deleted eq '0E0';
92
    };
93
    push @messages, {
94
        code => 'delete',
95
        number => $deleted,
96
    };
97
    $op = 'list';
98
}
99
100
if ( $op eq 'add_form' ) {
101
    my $categories = C4::Koha::GetAuthorisedValueCategories();
102
    my $field;
103
    if ( $field_id ) {
104
        $field = Koha::AdditionalField->new( { id => $field_id } )->fetch;
105
    }
106
107
    $template->param(
108
        field => $field,
109
        categories => $categories,
110
    );
111
}
112
113
if ( $op eq 'list' ) {
114
    my $fields = Koha::AdditionalField->all( { tablename => 'aqorders' } );
115
    $template->param( fields => $fields );
116
}
117
118
$template->param(
119
    op => $op,
120
    messages => \@messages,
121
);
122
123
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/acqui/neworderempty.pl (-16 / +19 lines)
Lines 301-325 my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); Link Here
301
301
302
# Get additional fields
302
# Get additional fields
303
my $record;
303
my $record;
304
my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
304
my $available_additional_fields = Koha::AdditionalField->all( { tablename => 'aqorders' } );
305
foreach my $af (@$additional_fields) {
305
my $additional_field_values = {};
306
    if (!$af->{authorised_value_category} && $af->{marcfield}) {
306
307
        # Try to retrieve authorised values category from MARC framework
307
if ( $ordernumber ) {
308
        my ($field, $subfield) = split /\$/, $af->{marcfield};
308
    $additional_field_values = Koha::AdditionalField->fetch_all_values( {
309
        my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield);
309
        tablename => 'aqorders',
310
        if ($category) {
310
        record_id => $ordernumber,
311
            $af->{authorised_value_category} = $category;
311
    } )->{$ordernumber};
312
} elsif ( $biblionumber ) {
313
    foreach my $af (@$additional_fields) {
314
        if ($af->{marcfield}) {
315
            $record //= GetMarcBiblio($biblionumber);
316
            my ($field, $subfield) = split /\$/, $af->{marcfield};
317
            $additional_field_values->{ $af->{name} } = $record->subfield($field, $subfield);
312
        }
318
        }
313
    }
319
    }
314
    if ($ordernumber) {
315
        $af->fetch_values({record_id => $ordernumber});
316
    } elsif ($biblionumber && $af->{marcfield}) {
317
        $record //= GetMarcBiblio($biblionumber);
318
        my ($field, $subfield) = split /\$/, $af->{marcfield};
319
        $af->{values}->{'new'} = $record->subfield($field, $subfield);
320
    }
321
}
320
}
322
$template->param(additional_fields => $additional_fields);
321
322
$template->param(
323
    available_additional_fields => $available_additional_fields,
324
    additional_field_values => $additional_field_values
325
);
323
326
324
# fill template
327
# fill template
325
$template->param(
328
$template->param(
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt (-165 lines)
Lines 1-165 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisitions &rsaquo; Manage new fields for order lines
3
  [% IF op == "list" %] &rsaquo; List of fields
4
  [% ELSIF op == "add_form" %]
5
    [% IF field %] &rsaquo; Modify field
6
    [% ELSE %] &rsaquo; Add field
7
    [% END %]
8
  [% END %]
9
</title>
10
[% INCLUDE 'doc-head-close.inc' %]
11
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
12
[% INCLUDE "datatables.inc" %]
13
<script type="text/javascript">
14
//<![CDATA[
15
  $(document).ready(function(){
16
17
    $("#fieldst").dataTable($.extend(true, {}, dataTablesDefaults, {
18
        'bAutoWidth': false,
19
        'sDom': 't<"bottom pager"ilpf>',
20
        'sPaginationType': 'four_button',
21
        'aLengthMenu': [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
22
        'iDisplayLength': 20,
23
        'aaSorting': [[ 0, "asc" ]],
24
    }));
25
26
    $(".confirmdelete").click(function(){
27
      return confirm(_("Are you sure you want to delete this field?"));
28
    });
29
30
    $("#add_field").on('submit', function(){
31
        if ( $("#marcfield").val().length > 0
32
            && $("select[name='authorised_value_category']" ).val().length > 0 ) {
33
            alert("You cannot select an authorised value category and a marcfield");
34
            return false;
35
        }
36
        return true;
37
    });
38
  });
39
//]]>
40
</script>
41
</head>
42
43
<body id="acq_add_fields" class="acq">
44
  [% INCLUDE 'header.inc' %]
45
  [% INCLUDE 'acquisitions-search.inc' %]
46
47
  <div id="breadcrumbs">
48
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; Manage new fields for order lines
49
  </div>
50
51
  <div id="doc3" class="yui-t2">
52
  <div id="bd">
53
  <div id="yui-main">
54
  <div class="yui-b">
55
  [% IF op == 'list' %]
56
    <div id="toolbar" class="btn-toolbar">
57
      <a class="btn btn-small" id="newfields" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form"><i class="icon-plus"></i> New field</a>
58
    </div>
59
  [% END %]
60
61
  [% IF messages %]
62
    [% FOR message IN messages %]
63
      [% IF message.code == 'insert' %]
64
        [% IF message.number > 0 %]
65
          <div class="dialog message">The field has been inserted</div>
66
        [% ELSE %]
67
          <div class="dialog alert">The field has not been inserted (name still exist?)</div>
68
        [% END %]
69
      [% ELSIF message.code == 'update' %]
70
        [% IF message.number > 0 %]
71
          <div class="dialog message">The field has been updated</div>
72
        [% ELSE %]
73
          <div class="dialog alert">The field has not been updated (name still exist?)</div>
74
        [% END %]
75
      [% ELSIF message.code == 'delete' %]
76
        [% IF message.number > 0 %]
77
          <div class="dialog message">The field has been deleted</div>
78
        [% ELSE %]
79
          <div class="dialog alert">The field has not been deleted</div>
80
        [% END %]
81
      [% END %]
82
    [% END %]
83
  [% END %]
84
85
  [% IF op == 'list' %]
86
    <h3>Additional fields for order lines</h3>
87
    [% IF fields %]
88
      <table id="fieldst">
89
        <thead>
90
          <tr>
91
            <th>Name</th>
92
            <th>Authorised value category</th>
93
            <th>MARC field</th>
94
            <th>Actions</th>
95
          </tr>
96
        </thead>
97
        <tbody>
98
          [% FOR field IN fields %]
99
            <tr>
100
              <td>[% field.name %]</td>
101
              <td>[% field.authorised_value_category %]</td>
102
              <td>[% field.marcfield %]</td>
103
              <td>
104
                <a href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form&amp;field_id=[% field.id %]" title="Edit this field">Edit</a>
105
                <a class="confirmdelete" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=delete&amp;field_id=[% field.id %]" title="Delete this field">Delete</a>
106
              </td>
107
            </tr>
108
          [% END %]
109
        </tbody>
110
      </table>
111
    [% ELSE %]
112
      There is no field defined.
113
    [% END %]
114
  [% ELSIF op == 'add_form' %]
115
    [% IF field %]
116
      <h3>Modify field</h3>
117
    [% ELSE %]
118
      <h3>Add field</h3>
119
    [% END %]
120
    <form action="/cgi-bin/koha/acqui/add_order_fields.pl" name="add_form" id="add_field" method="post">
121
      <fieldset class="rows">
122
        <ol>
123
          <li>
124
            <label for="name" class="required">Name: </label>
125
            <input type="text" name="name" id="name" value="[% field.name | html %]" />
126
          </li>
127
          <li>
128
            <label for="av">Authorised value category: </label>
129
            <select name="authorised_value_category">
130
              <option value="">None</option>
131
              [% FOR category IN categories %]
132
                [% IF field.authorised_value_category == category %]
133
                  <option value="[% category %]" selected="selected">[% category %]</option>
134
                [% ELSE %]
135
                  <option value="[% category %]">[% category %]</option>
136
                [% END %]
137
              [% END %]
138
            </select>
139
          </li>
140
          <li>
141
            <label for="marcfield">MARC field: </label>
142
            <input type="text" name="marcfield" id="marcfield" value="[% field.marcfield| html %]" />
143
            <span class="hint">Use this syntax: XXX$y</span>
144
          </li>
145
        </ol>
146
      </fieldset>
147
      <fieldset class="action">
148
        [% IF field %]
149
          <input type="hidden" name="field_id" value="[% field.id %]" />
150
        [% END %]
151
        <input type="hidden" name="op" value="add" />
152
        <input type="submit" value="Save" />
153
        <a href="/cgi-bin/koha/acqui/add_order_fields.pl" class="cancel">Cancel</a>
154
      </fieldset>
155
    </form>
156
  [% END %]
157
158
  </div>
159
  </div>
160
161
<div class="yui-b">
162
[% INCLUDE 'acquisitions-menu.inc' %]
163
</div>
164
</div>
165
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt (-1 / +1 lines)
Lines 97-102 Link Here
97
        [% END %]
97
        [% END %]
98
        <ul>
98
        <ul>
99
            [% WRAPPER table_option value="aqbasket" %]Order baskets[% END %]
99
            [% WRAPPER table_option value="aqbasket" %]Order baskets[% END %]
100
            [% WRAPPER table_option value="aqorders" %]Order lines[% END %]
100
            [% WRAPPER table_option value="subscription" %]Subscriptions[% END %]
101
            [% WRAPPER table_option value="subscription" %]Subscriptions[% END %]
101
        </ul>
102
        </ul>
102
    [% ELSIF op == 'list' %]
103
    [% ELSIF op == 'list' %]
103
- 

Return to bug 11844