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

(-)a/C4/Items.pm (-1 / +90 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
                next unless $substitution->{field};
2900
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2901
                    unless $report_only;
2902
                push @{ $report->{$itemnumber} }, $substitution;
2903
            }
2904
        }
2905
    }
2906
2907
    return $report;
2908
}
2909
2910
2822
1;
2911
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/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 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