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

(-)a/C4/Items.pm (-1 / +90 lines)
Lines 461-466 my %default_values_for_mod_from_marc = ( Link Here
461
    location             => undef, 
461
    location             => undef, 
462
    permanent_location   => undef,
462
    permanent_location   => undef,
463
    materials            => undef, 
463
    materials            => undef, 
464
    new                  => undef,
464
    notforloan           => 0,
465
    notforloan           => 0,
465
    paidfor              => undef, 
466
    paidfor              => undef, 
466
    price                => undef, 
467
    price                => undef, 
Lines 2147-2153 sub _koha_new_item { Link Here
2147
            enumchron           = ?,
2148
            enumchron           = ?,
2148
            more_subfields_xml  = ?,
2149
            more_subfields_xml  = ?,
2149
            copynumber          = ?,
2150
            copynumber          = ?,
2150
            stocknumber         = ?
2151
            stocknumber         = ?,
2152
            new                 = ?
2151
          ";
2153
          ";
2152
    my $sth = $dbh->prepare($query);
2154
    my $sth = $dbh->prepare($query);
2153
    my $today = C4::Dates->today('iso');
2155
    my $today = C4::Dates->today('iso');
Lines 2190-2195 sub _koha_new_item { Link Here
2190
            $item->{'more_subfields_xml'},
2192
            $item->{'more_subfields_xml'},
2191
            $item->{'copynumber'},
2193
            $item->{'copynumber'},
2192
            $item->{'stocknumber'},
2194
            $item->{'stocknumber'},
2195
            $item->{'new'},
2193
    );
2196
    );
2194
2197
2195
    my $itemnumber;
2198
    my $itemnumber;
Lines 2870-2873 sub PrepareItemrecordDisplay { Link Here
2870
    };
2873
    };
2871
}
2874
}
2872
2875
2876
=head2 columns
2877
2878
  my @columns = C4::Items::columns();
2879
2880
Returns an array of items' table columns on success,
2881
and an empty array on failure.
2882
2883
=cut
2884
2885
sub columns {
2886
    # Pure ANSI SQL goodness.
2887
    my $sql = 'SELECT * FROM items WHERE 1=0;';
2888
2889
    # Get the database handle.
2890
    my $dbh = C4::Context->dbh;
2891
2892
    # Run the SQL statement to load STH's readonly properties.
2893
    my $sth = $dbh->prepare($sql);
2894
    my $rv = $sth->execute();
2895
2896
    # This only fails if the table doesn't exist.
2897
    # This will always be called AFTER an install or upgrade,
2898
    # so borrowers will exist!
2899
    my @data;
2900
    if ($sth->{NUM_OF_FIELDS}>0) {
2901
        @data = @{$sth->{NAME}};
2902
    }
2903
    else {
2904
        @data = ();
2905
    }
2906
    return @data;
2907
}
2908
2909
sub ToggleNewStatus {
2910
    my ( $params ) = @_;
2911
    my @rules = @{ $params->{rules} };
2912
    my $report_only = $params->{report_only};
2913
2914
    my $dbh = C4::Context->dbh;
2915
    my @errors;
2916
    my @items_columns = C4::Items::columns;
2917
    my $report;
2918
    for my $rule ( @rules ) {
2919
        my $duration = $rule->{duration};
2920
        my $conditions = $rule->{conditions};
2921
        my $substitutions = $rule->{substitutions};
2922
        my @params;
2923
2924
        my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |;
2925
        for my $condition ( @$conditions ) {
2926
            if ( grep {/^$condition->{field}$/} @items_columns ) {
2927
                if ( $condition->{value} =~ /\|/ ) {
2928
                    my @values = split /\|/, $condition->{value};
2929
                    $query .= qq| AND $condition->{field} IN (|
2930
                        . join( ',', ('?') x scalar @values )
2931
                        . q|)|;
2932
                    push @params, @values;
2933
                } else {
2934
                    $query .= qq| AND $condition->{field} = ?|;
2935
                    push @params, $condition->{value};
2936
                }
2937
            }
2938
        }
2939
        if ( defined $duration ) {
2940
            $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |;
2941
            push @params, $duration;
2942
        }
2943
        my $sth = $dbh->prepare($query);
2944
        $sth->execute( @params );
2945
        while ( my $values = $sth->fetchrow_hashref ) {
2946
            my $biblionumber = $values->{biblionumber};
2947
            my $itemnumber = $values->{itemnumber};
2948
            my $item = C4::Items::GetItem( $itemnumber );
2949
            for my $substitution ( @$substitutions ) {
2950
                next unless $substitution->{field};
2951
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2952
                    unless $report_only;
2953
                push @{ $report->{$itemnumber} }, $substitution;
2954
            }
2955
        }
2956
    }
2957
2958
    return $report;
2959
}
2960
2961
2873
1;
2962
1;
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 917-922 CREATE TABLE `deleteditems` ( Link Here
917
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
917
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
918
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
918
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
919
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
919
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
920
  `new` VARCHAR(32) DEFAULT NULL, -- new flag
920
  PRIMARY KEY  (`itemnumber`),
921
  PRIMARY KEY  (`itemnumber`),
921
  KEY `delitembarcodeidx` (`barcode`),
922
  KEY `delitembarcodeidx` (`barcode`),
922
  KEY `delitemstocknumberidx` (`stocknumber`),
923
  KEY `delitemstocknumberidx` (`stocknumber`),
Lines 1211-1216 CREATE TABLE `items` ( -- holdings/item information Link Here
1211
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1212
  `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h)
1212
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1213
  `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t)
1213
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1214
  `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i)
1215
  `new` VARCHAR(32) DEFAULT NULL, -- new flag
1214
  PRIMARY KEY  (`itemnumber`),
1216
  PRIMARY KEY  (`itemnumber`),
1215
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1217
  UNIQUE KEY `itembarcodeidx` (`barcode`),
1216
  KEY `itemstocknumberidx` (`stocknumber`),
1218
  KEY `itemstocknumberidx` (`stocknumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+18 lines)
Lines 7912-7917 if ( CheckVersion($DBversion) ) { Link Here
7912
    SetVersion($DBversion);
7912
    SetVersion($DBversion);
7913
}
7913
}
7914
7914
7915
7916
7917
7918
7919
7920
7921
$DBversion = "3.15.00.XXX";
7922
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
7923
    $dbh->do(q{
7924
        ALTER TABLE `items` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`;
7925
    });
7926
    $dbh->do(q{
7927
        ALTER TABLE `deleteditems` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`;
7928
    });
7929
    print "Upgrade to $DBversion done (Bug 11012: Adds field 'new' in items and deleteditems tables)\n";
7930
    SetVersion($DBversion);
7931
}
7932
7915
=head1 FUNCTIONS
7933
=head1 FUNCTIONS
7916
7934
7917
=head2 TableExists($table)
7935
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+29 lines)
Lines 2719-2721 span.browse-button { Link Here
2719
#merge_table tr.active td {
2719
#merge_table tr.active td {
2720
    background-color: #FFFFCC;
2720
    background-color: #FFFFCC;
2721
}
2721
}
2722
2723
/* Tools > toggle_new_status */
2724
div.rules {
2725
    display: block;
2726
}
2727
div#new_rule, div.rule {
2728
    background-color: #F4F8F9;
2729
    border: 2px solid #B9D8D9;
2730
    border-radius: 5px;
2731
    margin: .3em;
2732
    padding: .3em;
2733
}
2734
2735
div.duration, div.blocks {
2736
    border: 2px solid #B9D8D9;
2737
    border-radius: 5px 5px 5px 5px;
2738
    margin: .3em;
2739
    padding: 0 .3em .3em .3em;
2740
}
2741
2742
div.duration h5, div.blocks h5 {
2743
    padding-bottom: 4px;
2744
    padding-left: 0.2em;
2745
    background-color: #E6F0F2;
2746
    border-radius: 1px;
2747
}
2748
div.duration span, div.blocks div {
2749
    display:block;
2750
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt (+45 lines)
Line 0 Link Here
1
[% INCLUDE 'help-top.inc' %]
2
<h1>Toggle new status configuration</h1>
3
4
<p>This configuration page allows to configure the rules for the toggle new status cronjob script.</p>
5
6
<p>Libraries can manage the 'new' status for items. With this script, it will be possible to:<p>
7
<ul>
8
  <li>know easily what are the new items in the catalogue.</li>
9
  <li>display an icon in the search results for new items.</li>
10
  <li>configure issuing rules depending the 'new' status.</li>
11
  <li>get a RSS/Atom feeds on these new items.</li>
12
</ul>
13
14
<h3>How to work the configuration page?</h3>
15
<p>There are 3 values to define:</p>
16
<h4>The duration</h4>
17
<p>This value corresponds to the duration an item is considered as new.</p>
18
<h4>The conditions</h4>
19
<p>Conditions should be defined if you want to test some values before to substitute fields in the items.</p>
20
<p>They are cumulatives but you can separate with a pipe '|' for a field with several values.</p>
21
<h4>The substitutions</h4>
22
<p>Substitutions are changes to apply to the matching items.</p>
23
<p>At least one substitution must be defined, else there is no sense to launch the script.</p>
24
<p>If the value is an empty string, the field will be deleted.</p>
25
<h3>Examples</h3>
26
<p>You want to remove the items.new value for items created 10 days ago:</p>
27
<ul>
28
  <li>Duration: 10 days</li>
29
  <li>No condition</li>
30
  <li>Substitution: items.new = '' (no value in the input)</li>
31
</ul>
32
33
<p>You want to change the items.ccode=1 to items.ccode=2 for items created 7 days ago.
34
<ul>
35
  <li>Duration: 7 days</li>
36
  <li>Condition: items.ccode = 1</li>
37
  <li>Substitution: items.ccode = 2</li>
38
</ul>
39
40
<h3>How to execute the cronjob script?</h3>
41
<p>The cronjob script is misc/cronjobs/toggle_new_status.pl.</p>
42
<p>Try the -h parameter in order to see the help.</p>
43
<p>Without any parameter, the script will be launched in a dry-run mode. If the -c (or --confirm) flag is given, the script will apply the changes.</p>
44
45
[% INCLUDE 'help-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt (+294 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
        $("#rules").hide();
31
        $("#norules").show();
32
    }
33
    $(link).parent().remove();
34
  }
35
36
  function clone_block(block) {
37
    var new_block = $(block).clone(1);
38
    clear_inputs(block, new_block);
39
    $(new_block).find('a.remove_block').show();
40
    var blocks = $(block).parent();
41
    $(blocks).append(new_block);
42
    $(blocks).find('a.remove_block').click(function(){
43
      remove_block_action($(this));
44
    }).show();
45
  }
46
47
  $(document).ready(function() {
48
    $("#new_rule a.remove_rule").hide();
49
    $("#new_rule a.remove_block").hide();
50
    $("#rules a.remove_block").click(function(){
51
      remove_block_action($(this));
52
    });
53
    $("#rules a.remove_rule").click(function(){
54
      remove_rule_action($(this));
55
    });
56
57
    var unique_id = $("div.rule").length + 1;
58
    $("a.add_rule").click(function(){
59
      var rule = $("#new_rule");
60
      var new_rule = $(rule).clone(1);
61
      $(new_rule).removeAttr('id');
62
      $(new_rule).attr('class', 'rule');
63
      clear_inputs(rule, new_rule);
64
      $(new_rule).find("select[name='condition_field']").attr('name', 'condition_field_' + unique_id);
65
      $(new_rule).find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
66
      $(new_rule).find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
67
      $(new_rule).find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
68
      $(new_rule).find("input[name='duration']").attr('name', 'duration_' + unique_id);
69
      $(new_rule).find("input[name='unique_id']").val(unique_id);
70
71
      $("#rules").append(new_rule);
72
73
      if( $("#rules").find("div.rule").length > 0 ) {
74
          $("#rules").show();
75
          $("#norules").hide();
76
      }
77
      if( $("#rules").find(".conditions > .condition").length > 1 ) {
78
79
      }
80
      if( $("#rules").find(".conditions > .condition").length > 1 ) {
81
82
      }
83
      $(new_rule).find('a.remove_rule').click(function(){
84
        remove_rule_action( $(this) );
85
      }).show();
86
      $(new_rule).find('a.add_rule').remove();
87
      unique_id++;
88
    });
89
90
    $("a.add_block").click(function(){
91
      clone_block( $(this).parent() );
92
    });
93
94
    if( $("#rules").find("div.rule").length < 1 ) {
95
        $("#rules").hide();
96
        $("#norules").show();
97
    }
98
99
    $("#rules .rule .blocks").each(function(){
100
      if ( $(this).find(".block").length == 1 ) {
101
        $(this).find("a.remove_block").hide();
102
      }
103
    });
104
105
    [% IF op == 'edit_form' %]
106
      [% IF rules.size > 0 %]
107
        $("#norules").hide();
108
      [% ELSE %]
109
        $("#rules").show();
110
      [% END %]
111
    [% END %]
112
  });
113
//]]>
114
</script>
115
</head>
116
<body id="tools_toggle_new_status" class="tools">
117
[% INCLUDE 'header.inc' %]
118
[% INCLUDE 'cat-search.inc' %]
119
<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>
120
121
<div id="doc3" class="yui-t2">
122
  <div id="bd">
123
    <div id="yui-main">
124
      <div class="yui-b">
125
        <h3>Toggle new status</h3>
126
        <div id="toolbar" class="btn-toolbar">
127
          <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>
128
        </div>
129
        [% FOR message IN messages %]
130
          [% IF message.type == "error" %]
131
            <div class="dialog error">
132
          [% END %]
133
          [% IF message.code == "unable_to_load_configuration" %]
134
            An error occurs: Unable to load the configuration.
135
          [% END %]
136
          </div>
137
        [% END %]
138
139
        [% IF op == 'edit_form' %]
140
          <form method="post" action="/cgi-bin/koha/tools/toggle_new_status.pl">
141
            <div id="edit_rules">
142
              <h4>List of rules</h4>
143
                <div id="rules">
144
                [% FOR rule IN rules %]
145
                  [% SET id = loop.count %]
146
                  <div class="rule">
147
                    <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled -->
148
                    <div class="duration">
149
                      <h5>Duration</h5>
150
                      <input type="text" value="[% rule.duration %]" name="duration_[% id %]" /> days
151
                    </div>
152
                    <div class="blocks">
153
                      <h5>Conditions</h5>
154
                      [% FOR condition IN rule.conditions %]
155
                        <div class="block">
156
                          <select name="condition_field_[% id %]">
157
                            <option value="">Choose a field name</option>
158
                            [% FOR field IN item_fields %]
159
                              [% IF condition.field == field %]
160
                                <option value="[% field %]" selected="selected">items.[% field %]</option>
161
                              [% ELSE %]
162
                                <option value="[% field %]">items.[% field %]</option>
163
                              [% END %]
164
                            [% END %]
165
                          </select>
166
                          =
167
                          <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" />
168
                          <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a>
169
                          <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a>
170
                        </div>
171
                      [% END %]
172
                    </div>
173
                    <div class="blocks">
174
                      <h5>Substitutions</h5>
175
                      [% FOR substitution IN rule.substitutions %]
176
                        <div class="block">
177
                          <select name="substitution_field_[% id %]">
178
                            <option value="">Choose a field name</option>
179
                            [% FOR field IN item_fields %]
180
                              [% IF substitution.field == field %]
181
                                <option value="[% field %]" selected="selected">items.[% field %]</option>
182
                              [% ELSE %]
183
                                <option value="[% field %]">items.[% field %]</option>
184
                              [% END %]
185
                            [% END %]
186
                          </select>
187
                          =
188
                          <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" />
189
                          <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a>
190
                          <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a>
191
                        </div>
192
                      [% END %]
193
                    </div>
194
                    <a class="remove_rule" style="cursor:pointer">Remove this rule</a>
195
                  </div>
196
                [% END %]
197
                </div>
198
                <div id="norules">
199
                  There is no rule defined.
200
                </div>
201
              <fieldset class="action">
202
                <input type="hidden" name="op" value="update" />
203
                <a class="cancel" href="/cgi-bin/koha/tools/toggle_new_status.pl">Cancel</a>
204
                <input type="submit" value="Submit theses rules" />
205
              </fieldset>
206
            </div>
207
          </form>
208
          <h4>Add a new rule</h4>
209
          <div id="new_rule">
210
            <input type="hidden" name="unique_id" />
211
            <div class="duration">
212
              <h5>Duration</h5>
213
              <input type="text" value="" name="duration" /> days
214
            </div>
215
            <div class="blocks">
216
              <h5>Conditions</h5>
217
              <div class="block">
218
                <select name="condition_field">
219
                  <option value="">Choose a field name</option>
220
                  [% FOR field IN item_fields %]
221
                    <option value="[% field %]">items.[% field %]</option>
222
                  [% END %]
223
                </select>
224
                =
225
                <input type="text" value="" name="condition_value" />
226
                <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a>
227
                <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a>
228
              </div>
229
            </div>
230
            <div class="blocks">
231
              <h5>Substitutions</h5>
232
              <div class="block">
233
                <select name="substitution_field">
234
                  <option value="">Choose a field name</option>
235
                  [% FOR field IN item_fields %]
236
                    <option value="[% field %]">items.[% field %]</option>
237
                  [% END %]
238
                </select>
239
                =
240
                <input type="text" value="" name="substitution_value" />
241
                <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a>
242
                <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a>
243
              </div>
244
            </div>
245
          <a class="add_rule" style="cursor:pointer">Add this rule</a>
246
          <a class="remove_rule" style="cursor:pointer">Remove this rule</a>
247
          </div>
248
        [% ELSIF rules and op == 'show' %]
249
          <div id="rules">
250
            <h4>List of rules</h4>
251
            [% FOR rule IN rules %]
252
              <div class="rule">
253
                <div class="duration">
254
                  <h5>Duration</h5>
255
                  [% IF rule.duration.defined and rule.duration.length > 0 %]
256
                    [% rule.duration %] days
257
                  [% ELSE %]
258
                    There is no duration for this rule.
259
                  [% END %]
260
                </div>
261
                <div class="blocks">
262
                  <h5>Conditions</h5>
263
                  [% FOR condition IN rule.conditions %]
264
                    [% IF condition.field %]
265
                      <div class="block">
266
                        [% condition.field %] = [% condition.value %]
267
                      </div>
268
                    [% ELSE %]
269
                      There is no condition for this rule.
270
                    [% END %]
271
                  [% END %]
272
                </div>
273
                <div class="blocks">
274
                  <h5>Substitutions</h5>
275
                  [% FOR substitution IN rule.substitutions %]
276
                    <div class="block">
277
                      [% substitution.field %] = [% substitution.value %]
278
                    </div>
279
                  [% END %]
280
                </div>
281
              </div>
282
            [% END %]
283
          </div>
284
        [% ELSE %]
285
          There is no rule defined. Please click on the edit button.
286
        [% END %]
287
288
      </div>
289
    </div>
290
  <div class="yui-b noprint">
291
    [% INCLUDE 'tools-menu.inc' %]
292
  </div>
293
</div>
294
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+5 lines)
Lines 122-127 Link Here
122
    <dd>Modify items in a batch</dd>
122
    <dd>Modify items in a batch</dd>
123
    [% END %]
123
    [% END %]
124
    
124
    
125
    [% IF ( CAN_user_tools_items_batchmod ) %]
126
      <dt><a href="/cgi-bin/koha/tools/toggle_new_status.pl">Toggle new status</a></dt>
127
      <dd>Toggle the "new" status for items</dd>
128
    [% END %]
129
125
    [% IF ( CAN_user_tools_export_catalog ) %]
130
    [% IF ( CAN_user_tools_export_catalog ) %]
126
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
131
    <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt>
127
    <dd>Export bibliographic, holdings, and authority records</dd>
132
    <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