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

(-)a/C4/Items.pm (-1 / +89 lines)
Lines 455-460 my %default_values_for_mod_from_marc = ( Link Here
455
    location             => undef, 
455
    location             => undef, 
456
    permanent_location   => undef,
456
    permanent_location   => undef,
457
    materials            => undef, 
457
    materials            => undef, 
458
    new                  => undef,
458
    notforloan           => 0,
459
    notforloan           => 0,
459
    paidfor              => undef, 
460
    paidfor              => undef, 
460
    price                => undef, 
461
    price                => undef, 
Lines 2104-2110 sub _koha_new_item { Link Here
2104
            enumchron           = ?,
2105
            enumchron           = ?,
2105
            more_subfields_xml  = ?,
2106
            more_subfields_xml  = ?,
2106
            copynumber          = ?,
2107
            copynumber          = ?,
2107
            stocknumber         = ?
2108
            stocknumber         = ?,
2109
            new                 = ?
2108
          ";
2110
          ";
2109
    my $sth = $dbh->prepare($query);
2111
    my $sth = $dbh->prepare($query);
2110
    my $today = C4::Dates->today('iso');
2112
    my $today = C4::Dates->today('iso');
Lines 2147-2152 sub _koha_new_item { Link Here
2147
            $item->{'more_subfields_xml'},
2149
            $item->{'more_subfields_xml'},
2148
            $item->{'copynumber'},
2150
            $item->{'copynumber'},
2149
            $item->{'stocknumber'},
2151
            $item->{'stocknumber'},
2152
            $item->{'new'},
2150
    );
2153
    );
2151
2154
2152
    my $itemnumber;
2155
    my $itemnumber;
Lines 2819-2822 sub PrepareItemrecordDisplay { Link Here
2819
    };
2822
    };
2820
}
2823
}
2821
2824
2825
=head2 columns
2826
2827
  my @columns = C4::Items::columns();
2828
2829
Returns an array of items' table columns on success,
2830
and an empty array on failure.
2831
2832
=cut
2833
2834
sub columns {
2835
    # Pure ANSI SQL goodness.
2836
    my $sql = 'SELECT * FROM items WHERE 1=0;';
2837
2838
    # Get the database handle.
2839
    my $dbh = C4::Context->dbh;
2840
2841
    # Run the SQL statement to load STH's readonly properties.
2842
    my $sth = $dbh->prepare($sql);
2843
    my $rv = $sth->execute();
2844
2845
    # This only fails if the table doesn't exist.
2846
    # This will always be called AFTER an install or upgrade,
2847
    # so borrowers will exist!
2848
    my @data;
2849
    if ($sth->{NUM_OF_FIELDS}>0) {
2850
        @data = @{$sth->{NAME}};
2851
    }
2852
    else {
2853
        @data = ();
2854
    }
2855
    return @data;
2856
}
2857
2858
sub ToggleNewStatus {
2859
    my ( $params ) = @_;
2860
    my @rules = @{ $params->{rules} };
2861
    my $report_only = $params->{report_only};
2862
2863
    my $dbh = C4::Context->dbh;
2864
    my @errors;
2865
    my @items_columns = C4::Items::columns;
2866
    my $report;
2867
    for my $rule ( @rules ) {
2868
        my $duration = $rule->{duration};
2869
        my $conditions = $rule->{conditions};
2870
        my $substitutions = $rule->{substitutions};
2871
        my @params;
2872
2873
        my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |;
2874
        for my $condition ( @$conditions ) {
2875
            if ( grep {/^$condition->{field}$/} @items_columns ) {
2876
                if ( $condition->{value} =~ /\|/ ) {
2877
                    my @values = split /\|/, $condition->{value};
2878
                    $query .= qq| AND $condition->{field} IN (|
2879
                        . join( ',', ('?') x scalar @values )
2880
                        . q|)|;
2881
                    push @params, @values;
2882
                } else {
2883
                    $query .= qq| AND $condition->{field} = ?|;
2884
                    push @params, $condition->{value};
2885
                }
2886
            }
2887
        }
2888
        if ( defined $duration ) {
2889
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
2890
            push @params, $duration;
2891
        }
2892
        my $sth = $dbh->prepare($query);
2893
        $sth->execute( @params );
2894
        while ( my $values = $sth->fetchrow_hashref ) {
2895
            my $biblionumber = $values->{biblionumber};
2896
            my $itemnumber = $values->{itemnumber};
2897
            my $item = C4::Items::GetItem( $itemnumber );
2898
            for my $substitution ( @$substitutions ) {
2899
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2900
                    unless $report_only;
2901
                push @{ $report->{$itemnumber} }, $substitution;
2902
            }
2903
        }
2904
    }
2905
2906
    return $report;
2907
}
2908
2909
2822
1;
2910
1;
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 891-896 CREATE TABLE `deleteditems` ( Link Here
891
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
891
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
892
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
892
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
893
  `marc` longblob, -- unused in Koha
893
  `marc` longblob, -- unused in Koha
894
  `new` VARCHAR(32) DEFAULT NULL, -- new flag
894
  PRIMARY KEY  (`itemnumber`),
895
  PRIMARY KEY  (`itemnumber`),
895
  KEY `delitembarcodeidx` (`barcode`),
896
  KEY `delitembarcodeidx` (`barcode`),
896
  KEY `delitemstocknumberidx` (`stocknumber`),
897
  KEY `delitemstocknumberidx` (`stocknumber`),
Lines 1182-1187 CREATE TABLE `items` ( -- holdings/item information Link Here
1182
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1183
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1183
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1184
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1184
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1185
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1186
  `new` VARCHAR(32) DEFAULT NULL, -- new flag
1185
  PRIMARY KEY  (`itemnumber`),
1187
  PRIMARY KEY  (`itemnumber`),
1186
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1188
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1187
  KEY `itemstocknumberidx` (`stocknumber`),
1189
  KEY `itemstocknumberidx` (`stocknumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+19 lines)
Lines 7169-7174 if ( CheckVersion($DBversion) ) { Link Here
7169
    SetVersion ($DBversion);
7169
    SetVersion ($DBversion);
7170
}
7170
}
7171
7171
7172
7173
7174
7175
7176
7177
7178
7179
$DBversion = "3.13.00.XXX";
7180
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7181
    $dbh->do(q{
7182
        ALTER TABLE `items` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`;
7183
    });
7184
    $dbh->do(q{
7185
        ALTER TABLE `deleteditems` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`;
7186
    });
7187
    print "Upgrade to $DBversion done (Bug 11012: Adds field 'new' in items and deleteditems tables)\n";
7188
    SetVersion($DBversion);
7189
}
7190
7172
=head1 FUNCTIONS
7191
=head1 FUNCTIONS
7173
7192
7174
=head2 TableExists($table)
7193
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+29 lines)
Lines 2659-2661 span.browse-button { Link Here
2659
    float: right;
2659
    float: right;
2660
    padding-right: 1em;
2660
    padding-right: 1em;
2661
}
2661
}
2662
2663
/* Tools > toggle_new_status */
2664
div.rules {
2665
    display: block;
2666
}
2667
div#new_rule, div.rule {
2668
    background-color: #F4F8F9;
2669
    border: 2px solid #B9D8D9;
2670
    border-radius: 5px;
2671
    margin: .3em;
2672
    padding: .3em;
2673
}
2674
2675
div.duration, div.blocks {
2676
    border: 2px solid #B9D8D9;
2677
    border-radius: 5px 5px 5px 5px;
2678
    margin: .3em;
2679
    padding: 0 .3em .3em .3em;
2680
}
2681
2682
div.duration h5, div.blocks h5 {
2683
    padding-bottom: 4px;
2684
    padding-left: 0.2em;
2685
    background-color: #E6F0F2;
2686
    border-radius: 1px;
2687
}
2688
div.duration span, div.blocks div {
2689
    display:block;
2690
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt (+282 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Toggle new status</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">//<![CDATA[
5
  function clear_inputs(node, new_node) {
6
    var selects = $(node).find("select");
7
    $(selects).each(function(i) {
8
      var select = this;
9
      $(new_node).find("select").eq(i).val($(select).val());
10
    });
11
    var inputs = $(node).find("input");
12
    $(inputs).each(function(i) {
13
      var input = this;
14
      $(new_node).find("input").eq(i).val($(input).val());
15
    });
16
  }
17
18
  function remove_block_action( link ) {
19
    var blocks = $(link).parent().parent();
20
    if( $(blocks).find(".block").length > 2 ) {
21
      $(blocks).find("a.remove_block").show();
22
    } else {
23
      $(blocks).find("a.remove_block").hide();
24
    }
25
    $(link).parent().remove();
26
  }
27
28
  function remove_rule_action( link ) {
29
    if( $("#rules").find("div.rule").length < 2 ) {
30
        $("#edit_rules").hide();
31
    }
32
    $(link).parent().remove();
33
  }
34
35
  function clone_block(block) {
36
    var new_block = $(block).clone(1);
37
    clear_inputs(block, new_block);
38
    $(new_block).find('a.remove_block').show();
39
    var blocks = $(block).parent();
40
    $(blocks).append(new_block);
41
    $(blocks).find('a.remove_block').click(function(){
42
      remove_block_action($(this));
43
    }).show();
44
  }
45
46
  $(document).ready(function() {
47
    $("#new_rule a.remove_rule").hide();
48
    $("#new_rule a.remove_block").hide();
49
    $("#rules a.remove_block").click(function(){
50
      remove_block_action($(this));
51
    });
52
    $("#rules a.remove_rule").click(function(){
53
      remove_rule_action($(this));
54
    });
55
56
    var unique_id = $("div.rule").length + 1;
57
    $("a.add_rule").click(function(){
58
      var rule = $("#new_rule");
59
      var new_rule = $(rule).clone(1);
60
      $(new_rule).removeAttr('id');
61
      $(new_rule).attr('class', 'rule');
62
      clear_inputs(rule, new_rule);
63
      $(new_rule).find("select[name='condition_field']").attr('name', 'condition_field_' + unique_id);
64
      $(new_rule).find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
65
      $(new_rule).find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
66
      $(new_rule).find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
67
      $(new_rule).find("input[name='duration']").attr('name', 'duration_' + unique_id);
68
      $(new_rule).find("input[name='unique_id']").val(unique_id);
69
70
      $("#rules").append(new_rule);
71
72
      if( $("#rules").find("div.rule").length > 0 ) {
73
          $("#edit_rules").show();
74
      }
75
      if( $("#rules").find(".conditions > .condition").length > 1 ) {
76
77
      }
78
      if( $("#rules").find(".conditions > .condition").length > 1 ) {
79
80
      }
81
      $(new_rule).find('a.remove_rule').click(function(){
82
        remove_rule_action( $(this) );
83
      }).show();
84
      unique_id++;
85
    });
86
87
    $("a.add_block").click(function(){
88
      clone_block( $(this).parent() );
89
    });
90
91
    if( $("#rules").find("div.rule").length < 1 ) {
92
        $("#edit_rules").hide();
93
    }
94
95
    $("#rules .rule .blocks").each(function(){
96
      if ( $(this).find(".block").length == 1 ) {
97
        $(this).find("a.remove_block").hide();
98
      }
99
    });
100
  });
101
//]]>
102
</script>
103
</head>
104
<body id="tools_toggle_new_status" class="tools">
105
[% INCLUDE 'header.inc' %]
106
[% INCLUDE 'cat-search.inc' %]
107
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/tools/toggle_new_status.pl">Toggle new status</a></div>
108
109
<div id="doc3" class="yui-t2">
110
  <div id="bd">
111
    <div id="yui-main">
112
      <div class="yui-b">
113
        <h3>Toggle new status</h3>
114
        <div id="toolbar" class="btn-toolbar">
115
          <a class="btn btn-small" id="newentry" href="/cgi-bin/koha/tools/toggle_new_status.pl?op=edit_form"><i class="icon-plus"></i> Edit</a>
116
        </div>
117
        [% FOR message IN messages %]
118
          [% IF message.type == "error" %]
119
            <div class="dialog error">
120
          [% END %]
121
          [% IF message.code == "unable_to_load_configuration" %]
122
            An error occurs: Unable to load the configuration.
123
          [% END %]
124
          </div>
125
        [% END %]
126
127
        [% IF op == 'edit_form' %]
128
          <form method="post" action="/cgi-bin/koha/tools/toggle_new_status.pl">
129
            <div id="edit_rules">
130
              <div id="rules">
131
                <h4>List of rules</h4>
132
                [% FOR rule IN rules %]
133
                  <div class="rule">
134
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
135
                    <div class="duration">
136
                      <h5>Duration</h5>
137
                      <input type="text" value="[% rule.duration %]" name="duration_[% loop.count %]" required="required" /> days
138
                    </div>
139
                    <div class="blocks">
140
                      <h5>Conditions</h5>
141
                      (they are cumulatives but you can separate with a pipe '|' for a field with several values):
142
                      [% FOR condition IN rule.conditions %]
143
                        <div class="block">
144
                          <select name="condition_field_[% loop.count %]">
145
                            <option value="">Choose a field name</option>
146
                            [% FOR field IN item_fields %]
147
                              [% IF condition.field == field %]
148
                                <option value="[% field %]" selected="selected">items.[% field %]</option>
149
                              [% ELSE %]
150
                                <option value="[% field %]">items.[% field %]</option>
151
                              [% END %]
152
                            [% END %]
153
                          </select>
154
                          =
155
                          <input type="text" value="[% condition.value %]" name="condition_value_[% loop.count %]" />
156
                          <a class="add_block" style="cursor:pointer">Add</a>
157
                          <a class="remove_block" style="cursor:pointer">Remove</a>
158
                        </div>
159
                      [% END %]
160
                    </div>
161
                    <div class="blocks">
162
                      <h5>Substitutions</h5>
163
                      If the value is an empty string, the field will be deleted.
164
                      [% FOR substitution IN rule.substitutions %]
165
                        <div class="block">
166
                          <select name="substitution_field_[% loop.count %]">
167
                            <option value="">Choose a field name</option>
168
                            [% FOR field IN item_fields %]
169
                              [% IF substitution.field == field %]
170
                                <option value="[% field %]" selected="selected">items.[% field %]</option>
171
                              [% ELSE %]
172
                                <option value="[% field %]">items.[% field %]</option>
173
                              [% END %]
174
                            [% END %]
175
                          </select>
176
                          =
177
                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% loop.count %]" />
178
                          <a class="add_block" style="cursor:pointer">Add</a>
179
                          <a class="remove_block" style="cursor:pointer">Remove</a>
180
                        </div>
181
                      [% END %]
182
                    </div>
183
                    <a class="remove_rule" style="cursor:pointer">Remove</a>
184
                  </div>
185
                [% END %]
186
              </div>
187
              <fieldset class="action">
188
                <input type="hidden" name="op" value="update" />
189
                <a class="cancel" href="/cgi-bin/koha/tools/toggle_new_status.pl">Cancel</a>
190
                <input type="submit" value="Submit" />
191
              </fieldset>
192
            </div>
193
          </form>
194
          <h4>Add a new rule</h4>
195
          <div id="new_rule">
196
            <input type="hidden" name="unique_id" />
197
            <div class="duration">
198
              <h5>Duration</h5>
199
              <input type="text" value="" name="duration" required="required" /> days
200
            </div>
201
            <div class="blocks">
202
              <h5>Conditions</h5>
203
              (they are cumulatives but you can separate with a pipe '|' for a field with several values).
204
              <div class="block">
205
                <select name="condition_field">
206
                  <option value="">Choose a field name</option>
207
                  [% FOR field IN item_fields %]
208
                    <option value="[% field %]">items.[% field %]</option>
209
                  [% END %]
210
                </select>
211
                =
212
                <input type="text" value="" name="condition_value" />
213
                <a class="add_block" style="cursor:pointer">Add</a>
214
                <a class="remove_block" style="cursor:pointer">Remove</a>
215
              </div>
216
            </div>
217
            <div class="blocks">
218
              <h5>Substitutions</h5>
219
              If the value is an empty string, the field will be deleted.
220
              <div class="block">
221
                <select name="substitution_field">
222
                  <option value="">Choose a field name</option>
223
                  [% FOR field IN item_fields %]
224
                    <option value="[% field %]">items.[% field %]</option>
225
                  [% END %]
226
                </select>
227
                =
228
                <input type="text" value="" name="substitution_value" />
229
                <a class="add_block" style="cursor:pointer">Add</a>
230
                <a class="remove_block" style="cursor:pointer">Remove</a>
231
              </div>
232
            </div>
233
          <a class="add_rule" style="cursor:pointer">Add</a>
234
          <a class="remove_rule" style="cursor:pointer">Remove</a>
235
          </div>
236
        [% ELSIF rules and op == 'show' %]
237
          <div id="rules">
238
            <h4>List of rules</h4>
239
            [% FOR rule IN rules %]
240
              <div class="rule">
241
                <div class="duration">
242
                  <h5>Duration</h5>
243
                  [% rule.duration %] days
244
                </div>
245
                <div class="blocks">
246
                  <h5>Conditions</h5>
247
                  [% FOR condition IN rule.conditions %]
248
                    [% IF condition.field %]
249
                      <div class="block">
250
                        [% condition.field %] = [% condition.value %]
251
                      </div>
252
                    [% ELSE %]
253
                      There is no condition for this rule.
254
                    [% END %]
255
                  [% END %]
256
                </div>
257
                <div class="blocks">
258
                  <h5>Substitutions</h5>
259
                  [% FOR substitution IN rule.substitutions %]
260
                    [% IF substitution.field %]
261
                      <div class="block">
262
                        [% substitution.field %] = [% substitution.value %]
263
                      </div>
264
                    [% ELSE %]
265
                      There is no substitution for this rule.
266
                    [% END %]
267
                  [% END %]
268
                </div>
269
              </div>
270
            [% END %]
271
          </div>
272
        [% ELSE %]
273
          There is no rule defined. Please click on the edit button.
274
        [% END %]
275
276
      </div>
277
    </div>
278
  <div class="yui-b noprint">
279
    [% INCLUDE 'tools-menu.inc' %]
280
  </div>
281
</div>
282
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+5 lines)
Lines 117-122 Link Here
117
    <dd>Modify items in a batch</dd>
117
    <dd>Modify items in a batch</dd>
118
    [% END %]
118
    [% END %]
119
    
119
    
120
    [% IF ( CAN_user_tools_items_batchmod ) %]
121
      <dt><a href="/cgi-bin/koha/tools/toggle_new_status.pl">Toggle new status</a></dt>
122
      <dd>Toggle the "new" status for items</dd>
123
    [% END %]
124
120
    [% IF ( CAN_user_tools_export_catalog ) %]
125
    [% IF ( CAN_user_tools_export_catalog ) %]
121
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
126
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
122
    <dd>Export bibliographic, holdings, and authority records</dd>
127
    <dd>Export bibliographic, holdings, and authority records</dd>
(-)a/misc/cronjobs/toggle_new_status.pl (+106 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Getopt::Long;
6
use Pod::Usage;
7
use JSON;
8
9
use C4::Context;
10
use C4::Items;
11
12
# Getting options
13
my ( $verbose, $help, $confirm );
14
my $result = GetOptions(
15
    'h|help'    => \$help,
16
    'v|verbose' => \$verbose,
17
    'c|confirm' => \$confirm,
18
);
19
20
pod2usage(1) if $help;
21
$verbose = 1 unless $confirm;
22
23
# Load configuration from the syspref
24
my $syspref_content = C4::Context->preference('toggle_new_status_configuration');
25
my $rules = eval { JSON::from_json( $syspref_content ) };
26
pod2usage({ -message => "Unable to load the configuration : $@", -exitval => 1 })
27
    if $@;
28
29
my $report = C4::Items::ToggleNewStatus( { rules => $rules, report_only => not $confirm } );
30
31
if ( $verbose ) {
32
    if ( $report ) {
33
        say "Item to modify:";
34
        while ( my ( $itemnumber, $substitutions ) = each %$report ) {
35
            for my $substitution ( @$substitutions ) {
36
                if ( defined $substitution->{value} and $substitution->{value} ne q|| ) {
37
                   say "\titemnumber $itemnumber: $substitution->{field}=$substitution->{value}";
38
                } else {
39
                   say "\titemnumber $itemnumber: field $substitution->{field} to delete";
40
                }
41
            }
42
        }
43
    } else {
44
        say "There is no item to modify";
45
    }
46
}
47
48
exit(0);
49
50
__END__
51
52
=head1 NAME
53
54
toggle_new_status.pl
55
56
=head1 SYNOPSIS
57
58
./toggle_new_status.pl -h
59
60
Toggle recent acquisitions status.
61
Use this script to delete "new" status for items.
62
63
=head1 OPTIONS
64
65
=over 8
66
67
=item B<-h|--help>
68
69
Prints this help message.
70
71
=item B<-v|--verbose>
72
73
Set the verbose flag.
74
75
=item B<-c|--confirm>
76
77
The script will modify the items.
78
79
=back
80
81
=head1 AUTHOR
82
83
Jonathan Druart <jonathan.druart@biblibre.com>
84
85
=head1 COPYRIGHT
86
87
Copyright 2013 BibLibre
88
89
=head1 LICENSE
90
91
This file is part of Koha.
92
93
Koha is free software; you can redistribute it and/or modify it
94
under the terms of the GNU General Public License as published by
95
the Free Software Foundation; either version 3 of the License, or
96
(at your option) any later version.
97
98
Koha is distributed in the hope that it will be useful, but
99
WITHOUT ANY WARRANTY; without even the implied warranty of
100
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101
GNU General Public License for more details.
102
103
You should have received a copy of the GNU General Public License
104
along with Koha; if not, see <http://www.gnu.org/licenses>.
105
106
=cut
(-)a/tools/toggle_new_status.pl (-1 / +116 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
=head1 NAME
21
22
toggle_new_status.pl: Update new status for items.
23
24
=cut
25
26
=head1 DESCRIPTION
27
28
This script allows a user to update the new status for items.
29
30
=cut
31
32
use Modern::Perl;
33
34
use CGI;
35
use JSON qw( to_json from_json );
36
37
use C4::Auth;
38
use C4::Context;
39
use C4::Items;
40
use C4::Output;
41
use C4::Koha;
42
43
my $cgi = new CGI;
44
45
# open template
46
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47
    {
48
        template_name   => "tools/toggle_new_status.tt",
49
        query           => $cgi,
50
        type            => "intranet",
51
        authnotrequired => 0,
52
        flagsrequired   => { tools => 'items_batchmod' },
53
    }
54
);
55
56
my $op = $cgi->param('op') // 'show';
57
58
my $syspref_name = q|toggle_new_status_configuration|;
59
if ( $op eq 'update' ) {
60
    my @rules;
61
    my @unique_ids = $cgi->param('unique_id');
62
    for my $unique_id ( @unique_ids ) {
63
        my @substitution_fields = $cgi->param("substitution_field_$unique_id");
64
        my @substitution_values = $cgi->param("substitution_value_$unique_id");
65
        my @condition_fields = $cgi->param("condition_field_$unique_id");
66
        my @condition_values = $cgi->param("condition_value_$unique_id");
67
        my $rule = {
68
            substitutions => [],
69
            conditions => [],
70
        };
71
        for my $value ( @substitution_values ) {
72
            my $field = shift @substitution_fields;
73
            last unless $field;
74
            push @{ $rule->{substitutions} }, { field => $field, value => $value };
75
        }
76
        push @{ $rule->{substitutions} }, {}
77
            unless @{ $rule->{substitutions} };
78
        for my $value ( @condition_values ) {
79
            my $field = shift @condition_fields;
80
            last unless $field;
81
            push @{ $rule->{conditions} }, { field => $field, value => $value };
82
        }
83
        push @{ $rule->{conditions} }, {}
84
            unless @{ $rule->{conditions} };
85
        $rule->{duration} = $cgi->param("duration_$unique_id");
86
        push @rules, $rule;
87
    }
88
    my $syspref_content = to_json( \@rules );
89
    C4::Context->set_preference($syspref_name, $syspref_content);
90
91
    $op = 'show';
92
}
93
94
my @messages;
95
my $syspref_content = C4::Context->preference($syspref_name);
96
my $rules;
97
$rules = eval { JSON::from_json( $syspref_content ) }
98
    if $syspref_content;
99
if ( $@ ) {
100
    push @messages, {
101
        type => 'error',
102
        code => 'unable_to_load_configuration'
103
    };
104
    $template->param( messages => \@messages );
105
    output_html_with_http_headers $cgi, $cookie, $template->output;
106
    exit;
107
}
108
109
$template->param(
110
    op => $op,
111
    messages => \@messages,
112
    item_fields => [ C4::Items::columns ],
113
    rules => $rules,
114
);
115
116
output_html_with_http_headers $cgi, $cookie, $template->output;

Return to bug 11023