Bugzilla – Attachment 26817 Details for
Bug 11023
Automatic item modification by age (Was "Toggle new status for items")
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11023: Toggle "new" status
Bug-11023-Toggle-new-status.patch (text/plain), 31.02 KB, created by
Jonathan Druart
on 2014-04-04 14:25:13 UTC
(
hide
)
Description:
Bug 11023: Toggle "new" status
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-04-04 14:25:13 UTC
Size:
31.02 KB
patch
obsolete
>From 21e23eece788dd5bad0892933ff71712c2bdc457 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Wed, 25 Sep 2013 16:45:14 +0200 >Subject: [PATCH] Bug 11023: Toggle "new" status >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds: >- a new DB field items.new. >- a new page to configure this new status > (tools/toggle_new_status.pl). >- a new cronjob script (misc/cronjob/toggle_new_status.pl). > >Why this status is useful for some libraries ? >The use cases are: >- to know easily what are the new items (with a simple sql query). >- to display an icon in the search results. >- issuing rules can be adapt for new items. Automatically (using the > cronjob script), the status change (depending the configuration) and > the item can be issued, for example. >- a RSS/Atom feeds can be created on these new items. > >Test plan: >- log in with a librarian having the tools > items_batchmod permission. >- navigate to Home > Tools > Toggle new status >- click on the edit button >- there are 3 "blocks": > * duration: the duration during an item is considered as new. > * conditions: the status will change only if the conditions are meet. > * substitutions: if there is no substitution, no action will be done. > You can add some change to apply to the matching items. > E.g. ccode=3 > new='' > If the value is an empty string (in other words, the input does not > contain anything), the field will be deleted. > You can create as many rules as you want. >- test the interface : add/remove rule, conditions, substitutions, > submit the form, edit, etc. > (There is a looot of JS everywhere, so certainly a looot of bugs...). >- when you have your rules defined, you can now launch the cronjob > script without any parameter. > A report will be displayed with the matching itemnumber and the > substitutions to apply. Verify results are consistent. >- launch the script with the -c argument and verify values have been > modified depending the substitution rules. > >Signed-off-by: juliette et rémy <juliette.levast@iepg.fr> >--- > C4/Items.pm | 91 +++++- > installer/data/mysql/kohastructure.sql | 2 + > installer/data/mysql/updatedatabase.pl | 17 ++ > .../intranet-tmpl/prog/en/css/staff-global.css | 29 ++ > .../en/modules/help/tools/toggle_new_status.tt | 45 +++ > .../prog/en/modules/tools/toggle_new_status.tt | 294 ++++++++++++++++++++ > .../prog/en/modules/tools/tools-home.tt | 5 + > misc/cronjobs/toggle_new_status.pl | 106 +++++++ > tools/toggle_new_status.pl | 116 ++++++++ > 9 files changed, 704 insertions(+), 1 deletion(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt > create mode 100755 misc/cronjobs/toggle_new_status.pl > create mode 100755 tools/toggle_new_status.pl > >diff --git a/C4/Items.pm b/C4/Items.pm >index 12dce85..942f3ee 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -461,6 +461,7 @@ my %default_values_for_mod_from_marc = ( > location => undef, > permanent_location => undef, > materials => undef, >+ new => undef, > notforloan => 0, > paidfor => undef, > price => undef, >@@ -2147,7 +2148,8 @@ sub _koha_new_item { > enumchron = ?, > more_subfields_xml = ?, > copynumber = ?, >- stocknumber = ? >+ stocknumber = ?, >+ new = ? > "; > my $sth = $dbh->prepare($query); > my $today = C4::Dates->today('iso'); >@@ -2190,6 +2192,7 @@ sub _koha_new_item { > $item->{'more_subfields_xml'}, > $item->{'copynumber'}, > $item->{'stocknumber'}, >+ $item->{'new'}, > ); > > my $itemnumber; >@@ -2870,4 +2873,90 @@ sub PrepareItemrecordDisplay { > }; > } > >+=head2 columns >+ >+ my @columns = C4::Items::columns(); >+ >+Returns an array of items' table columns on success, >+and an empty array on failure. >+ >+=cut >+ >+sub columns { >+ # Pure ANSI SQL goodness. >+ my $sql = 'SELECT * FROM items WHERE 1=0;'; >+ >+ # Get the database handle. >+ my $dbh = C4::Context->dbh; >+ >+ # Run the SQL statement to load STH's readonly properties. >+ my $sth = $dbh->prepare($sql); >+ my $rv = $sth->execute(); >+ >+ # This only fails if the table doesn't exist. >+ # This will always be called AFTER an install or upgrade, >+ # so borrowers will exist! >+ my @data; >+ if ($sth->{NUM_OF_FIELDS}>0) { >+ @data = @{$sth->{NAME}}; >+ } >+ else { >+ @data = (); >+ } >+ return @data; >+} >+ >+sub ToggleNewStatus { >+ my ( $params ) = @_; >+ my @rules = @{ $params->{rules} }; >+ my $report_only = $params->{report_only}; >+ >+ my $dbh = C4::Context->dbh; >+ my @errors; >+ my @items_columns = C4::Items::columns; >+ my $report; >+ for my $rule ( @rules ) { >+ my $duration = $rule->{duration}; >+ my $conditions = $rule->{conditions}; >+ my $substitutions = $rule->{substitutions}; >+ my @params; >+ >+ my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |; >+ for my $condition ( @$conditions ) { >+ if ( grep {/^$condition->{field}$/} @items_columns ) { >+ if ( $condition->{value} =~ /\|/ ) { >+ my @values = split /\|/, $condition->{value}; >+ $query .= qq| AND $condition->{field} IN (| >+ . join( ',', ('?') x scalar @values ) >+ . q|)|; >+ push @params, @values; >+ } else { >+ $query .= qq| AND $condition->{field} = ?|; >+ push @params, $condition->{value}; >+ } >+ } >+ } >+ if ( defined $duration ) { >+ $query .= q| AND TO_DAYS(NOW()) - TO_DAYS(dateaccessioned) >= ? |; >+ push @params, $duration; >+ } >+ my $sth = $dbh->prepare($query); >+ $sth->execute( @params ); >+ while ( my $values = $sth->fetchrow_hashref ) { >+ my $biblionumber = $values->{biblionumber}; >+ my $itemnumber = $values->{itemnumber}; >+ my $item = C4::Items::GetItem( $itemnumber ); >+ for my $substitution ( @$substitutions ) { >+ next unless $substitution->{field}; >+ C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber ) >+ unless $report_only; >+ push @{ $report->{$itemnumber} }, $substitution; >+ } >+ } >+ } >+ >+ return $report; >+} >+ >+ > 1; >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 3cf9c65..b65e00d 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -917,6 +917,7 @@ CREATE TABLE `deleteditems` ( > `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) > `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) > `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) >+ `new` VARCHAR(32) DEFAULT NULL, -- new flag > PRIMARY KEY (`itemnumber`), > KEY `delitembarcodeidx` (`barcode`), > KEY `delitemstocknumberidx` (`stocknumber`), >@@ -1211,6 +1212,7 @@ CREATE TABLE `items` ( -- holdings/item information > `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) > `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) > `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) >+ `new` VARCHAR(32) DEFAULT NULL, -- new flag > PRIMARY KEY (`itemnumber`), > UNIQUE KEY `itembarcodeidx` (`barcode`), > KEY `itemstocknumberidx` (`stocknumber`), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 062ecc1..588fc2c 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -8083,6 +8083,23 @@ if ( CheckVersion($DBversion) ) { > SetVersion($DBversion); > } > >+ >+ >+ >+ >+ >+$DBversion = "3.15.00.XXX"; >+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { >+ $dbh->do(q{ >+ ALTER TABLE `items` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`; >+ }); >+ $dbh->do(q{ >+ ALTER TABLE `deleteditems` ADD `new` VARCHAR(32) NULL AFTER `stocknumber`; >+ }); >+ print "Upgrade to $DBversion done (Bug 11012: Adds field 'new' in items and deleteditems tables)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css >index 4279ad9..0c9a277 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css >+++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css >@@ -2725,3 +2725,32 @@ span.browse-button { > font-size:0.8em; > padding:0.5em; > } >+ >+/* Tools > toggle_new_status */ >+div.rules { >+ display: block; >+} >+div#new_rule, div.rule { >+ background-color: #F4F8F9; >+ border: 2px solid #B9D8D9; >+ border-radius: 5px; >+ margin: .3em; >+ padding: .3em; >+} >+ >+div.duration, div.blocks { >+ border: 2px solid #B9D8D9; >+ border-radius: 5px 5px 5px 5px; >+ margin: .3em; >+ padding: 0 .3em .3em .3em; >+} >+ >+div.duration h5, div.blocks h5 { >+ padding-bottom: 4px; >+ padding-left: 0.2em; >+ background-color: #E6F0F2; >+ border-radius: 1px; >+} >+div.duration span, div.blocks div { >+ display:block; >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt >new file mode 100644 >index 0000000..0bb591f >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/tools/toggle_new_status.tt >@@ -0,0 +1,45 @@ >+[% INCLUDE 'help-top.inc' %] >+<h1>Toggle new status configuration</h1> >+ >+<p>This configuration page allows to configure the rules for the toggle new status cronjob script.</p> >+ >+<p>Libraries can manage the 'new' status for items. With this script, it will be possible to:<p> >+<ul> >+ <li>know easily what are the new items in the catalogue.</li> >+ <li>display an icon in the search results for new items.</li> >+ <li>configure issuing rules depending the 'new' status.</li> >+ <li>get a RSS/Atom feeds on these new items.</li> >+</ul> >+ >+<h3>How to work the configuration page?</h3> >+<p>There are 3 values to define:</p> >+<h4>The duration</h4> >+<p>This value corresponds to the duration an item is considered as new.</p> >+<h4>The conditions</h4> >+<p>Conditions should be defined if you want to test some values before to substitute fields in the items.</p> >+<p>They are cumulatives but you can separate with a pipe '|' for a field with several values.</p> >+<h4>The substitutions</h4> >+<p>Substitutions are changes to apply to the matching items.</p> >+<p>At least one substitution must be defined, else there is no sense to launch the script.</p> >+<p>If the value is an empty string, the field will be deleted.</p> >+<h3>Examples</h3> >+<p>You want to remove the items.new value for items created 10 days ago:</p> >+<ul> >+ <li>Duration: 10 days</li> >+ <li>No condition</li> >+ <li>Substitution: items.new = '' (no value in the input)</li> >+</ul> >+ >+<p>You want to change the items.ccode=1 to items.ccode=2 for items created 7 days ago. >+<ul> >+ <li>Duration: 7 days</li> >+ <li>Condition: items.ccode = 1</li> >+ <li>Substitution: items.ccode = 2</li> >+</ul> >+ >+<h3>How to execute the cronjob script?</h3> >+<p>The cronjob script is misc/cronjobs/toggle_new_status.pl.</p> >+<p>Try the -h parameter in order to see the help.</p> >+<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> >+ >+[% INCLUDE 'help-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt >new file mode 100644 >index 0000000..d1a0d2e >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt >@@ -0,0 +1,294 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Tools › Toggle new status</title> >+[% INCLUDE 'doc-head-close.inc' %] >+<script type="text/javascript">//<![CDATA[ >+ function clear_inputs(node, new_node) { >+ var selects = $(node).find("select"); >+ $(selects).each(function(i) { >+ var select = this; >+ $(new_node).find("select").eq(i).val($(select).val()); >+ }); >+ var inputs = $(node).find("input"); >+ $(inputs).each(function(i) { >+ var input = this; >+ $(new_node).find("input").eq(i).val($(input).val()); >+ }); >+ } >+ >+ function remove_block_action( link ) { >+ var blocks = $(link).parent().parent(); >+ if( $(blocks).find(".block").length > 2 ) { >+ $(blocks).find("a.remove_block").show(); >+ } else { >+ $(blocks).find("a.remove_block").hide(); >+ } >+ $(link).parent().remove(); >+ } >+ >+ function remove_rule_action( link ) { >+ if( $("#rules").find("div.rule").length < 2 ) { >+ $("#rules").hide(); >+ $("#norules").show(); >+ } >+ $(link).parent().remove(); >+ } >+ >+ function clone_block(block) { >+ var new_block = $(block).clone(1); >+ clear_inputs(block, new_block); >+ $(new_block).find('a.remove_block').show(); >+ var blocks = $(block).parent(); >+ $(blocks).append(new_block); >+ $(blocks).find('a.remove_block').click(function(){ >+ remove_block_action($(this)); >+ }).show(); >+ } >+ >+ $(document).ready(function() { >+ $("#new_rule a.remove_rule").hide(); >+ $("#new_rule a.remove_block").hide(); >+ $("#rules a.remove_block").click(function(){ >+ remove_block_action($(this)); >+ }); >+ $("#rules a.remove_rule").click(function(){ >+ remove_rule_action($(this)); >+ }); >+ >+ var unique_id = $("div.rule").length + 1; >+ $("a.add_rule").click(function(){ >+ var rule = $("#new_rule"); >+ var new_rule = $(rule).clone(1); >+ $(new_rule).removeAttr('id'); >+ $(new_rule).attr('class', 'rule'); >+ clear_inputs(rule, new_rule); >+ $(new_rule).find("select[name='condition_field']").attr('name', 'condition_field_' + unique_id); >+ $(new_rule).find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id); >+ $(new_rule).find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id); >+ $(new_rule).find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id); >+ $(new_rule).find("input[name='duration']").attr('name', 'duration_' + unique_id); >+ $(new_rule).find("input[name='unique_id']").val(unique_id); >+ >+ $("#rules").append(new_rule); >+ >+ if( $("#rules").find("div.rule").length > 0 ) { >+ $("#rules").show(); >+ $("#norules").hide(); >+ } >+ if( $("#rules").find(".conditions > .condition").length > 1 ) { >+ >+ } >+ if( $("#rules").find(".conditions > .condition").length > 1 ) { >+ >+ } >+ $(new_rule).find('a.remove_rule').click(function(){ >+ remove_rule_action( $(this) ); >+ }).show(); >+ $(new_rule).find('a.add_rule').remove(); >+ unique_id++; >+ }); >+ >+ $("a.add_block").click(function(){ >+ clone_block( $(this).parent() ); >+ }); >+ >+ if( $("#rules").find("div.rule").length < 1 ) { >+ $("#rules").hide(); >+ $("#norules").show(); >+ } >+ >+ $("#rules .rule .blocks").each(function(){ >+ if ( $(this).find(".block").length == 1 ) { >+ $(this).find("a.remove_block").hide(); >+ } >+ }); >+ >+ [% IF op == 'edit_form' %] >+ [% IF rules.size > 0 %] >+ $("#norules").hide(); >+ [% ELSE %] >+ $("#rules").show(); >+ [% END %] >+ [% END %] >+ }); >+//]]> >+</script> >+</head> >+<body id="tools_toggle_new_status" class="tools"> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'cat-search.inc' %] >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/tools/toggle_new_status.pl">Toggle new status</a></div> >+ >+<div id="doc3" class="yui-t2"> >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ <h3>Toggle new status</h3> >+ <div id="toolbar" class="btn-toolbar"> >+ <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> >+ </div> >+ [% FOR message IN messages %] >+ [% IF message.type == "error" %] >+ <div class="dialog error"> >+ [% END %] >+ [% IF message.code == "unable_to_load_configuration" %] >+ An error occurs: Unable to load the configuration. >+ [% END %] >+ </div> >+ [% END %] >+ >+ [% IF op == 'edit_form' %] >+ <form method="post" action="/cgi-bin/koha/tools/toggle_new_status.pl"> >+ <div id="edit_rules"> >+ <h4>List of rules</h4> >+ <div id="rules"> >+ [% FOR rule IN rules %] >+ [% SET id = loop.count %] >+ <div class="rule"> >+ <input type="hidden" name="unique_id" value="[% loop.count %]" /> <!-- FIXME on update, the unique_id should be filled --> >+ <div class="duration"> >+ <h5>Duration</h5> >+ <input type="text" value="[% rule.duration %]" name="duration_[% id %]" /> days >+ </div> >+ <div class="blocks"> >+ <h5>Conditions</h5> >+ [% FOR condition IN rule.conditions %] >+ <div class="block"> >+ <select name="condition_field_[% id %]"> >+ <option value="">Choose a field name</option> >+ [% FOR field IN item_fields %] >+ [% IF condition.field == field %] >+ <option value="[% field %]" selected="selected">items.[% field %]</option> >+ [% ELSE %] >+ <option value="[% field %]">items.[% field %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ = >+ <input type="text" value="[% condition.value %]" name="condition_value_[% id%]" /> >+ <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a> >+ <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a> >+ </div> >+ [% END %] >+ </div> >+ <div class="blocks"> >+ <h5>Substitutions</h5> >+ [% FOR substitution IN rule.substitutions %] >+ <div class="block"> >+ <select name="substitution_field_[% id %]"> >+ <option value="">Choose a field name</option> >+ [% FOR field IN item_fields %] >+ [% IF substitution.field == field %] >+ <option value="[% field %]" selected="selected">items.[% field %]</option> >+ [% ELSE %] >+ <option value="[% field %]">items.[% field %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ = >+ <input type="text" value="[% substitution.value %]" name="substitution_value_[% id %]" /> >+ <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a> >+ <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a> >+ </div> >+ [% END %] >+ </div> >+ <a class="remove_rule" style="cursor:pointer">Remove this rule</a> >+ </div> >+ [% END %] >+ </div> >+ <div id="norules"> >+ There is no rule defined. >+ </div> >+ <fieldset class="action"> >+ <input type="hidden" name="op" value="update" /> >+ <a class="cancel" href="/cgi-bin/koha/tools/toggle_new_status.pl">Cancel</a> >+ <input type="submit" value="Submit theses rules" /> >+ </fieldset> >+ </div> >+ </form> >+ <h4>Add a new rule</h4> >+ <div id="new_rule"> >+ <input type="hidden" name="unique_id" /> >+ <div class="duration"> >+ <h5>Duration</h5> >+ <input type="text" value="" name="duration" /> days >+ </div> >+ <div class="blocks"> >+ <h5>Conditions</h5> >+ <div class="block"> >+ <select name="condition_field"> >+ <option value="">Choose a field name</option> >+ [% FOR field IN item_fields %] >+ <option value="[% field %]">items.[% field %]</option> >+ [% END %] >+ </select> >+ = >+ <input type="text" value="" name="condition_value" /> >+ <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a> >+ <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a> >+ </div> >+ </div> >+ <div class="blocks"> >+ <h5>Substitutions</h5> >+ <div class="block"> >+ <select name="substitution_field"> >+ <option value="">Choose a field name</option> >+ [% FOR field IN item_fields %] >+ <option value="[% field %]">items.[% field %]</option> >+ [% END %] >+ </select> >+ = >+ <input type="text" value="" name="substitution_value" /> >+ <a class="add_block" style="cursor:pointer"><i class="icon-plus"></i></a> >+ <a class="remove_block" style="cursor:pointer"><i class="icon-remove"></i></a> >+ </div> >+ </div> >+ <a class="add_rule" style="cursor:pointer">Add this rule</a> >+ <a class="remove_rule" style="cursor:pointer">Remove this rule</a> >+ </div> >+ [% ELSIF rules and op == 'show' %] >+ <div id="rules"> >+ <h4>List of rules</h4> >+ [% FOR rule IN rules %] >+ <div class="rule"> >+ <div class="duration"> >+ <h5>Duration</h5> >+ [% IF rule.duration.defined and rule.duration.length > 0 %] >+ [% rule.duration %] days >+ [% ELSE %] >+ There is no duration for this rule. >+ [% END %] >+ </div> >+ <div class="blocks"> >+ <h5>Conditions</h5> >+ [% FOR condition IN rule.conditions %] >+ [% IF condition.field %] >+ <div class="block"> >+ [% condition.field %] = [% condition.value %] >+ </div> >+ [% ELSE %] >+ There is no condition for this rule. >+ [% END %] >+ [% END %] >+ </div> >+ <div class="blocks"> >+ <h5>Substitutions</h5> >+ [% FOR substitution IN rule.substitutions %] >+ <div class="block"> >+ [% substitution.field %] = [% substitution.value %] >+ </div> >+ [% END %] >+ </div> >+ </div> >+ [% END %] >+ </div> >+ [% ELSE %] >+ There is no rule defined. Please click on the edit button. >+ [% END %] >+ >+ </div> >+ </div> >+ <div class="yui-b noprint"> >+ [% INCLUDE 'tools-menu.inc' %] >+ </div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >index 4ab38c9..79911d3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >@@ -122,6 +122,11 @@ > <dd>Modify items in a batch</dd> > [% END %] > >+ [% IF ( CAN_user_tools_items_batchmod ) %] >+ <dt><a href="/cgi-bin/koha/tools/toggle_new_status.pl">Toggle new status</a></dt> >+ <dd>Toggle the "new" status for items</dd> >+ [% END %] >+ > [% IF ( CAN_user_tools_export_catalog ) %] > <dt><a href="/cgi-bin/koha/tools/export.pl">Export data</a></dt> > <dd>Export bibliographic, holdings, and authority records</dd> >diff --git a/misc/cronjobs/toggle_new_status.pl b/misc/cronjobs/toggle_new_status.pl >new file mode 100755 >index 0000000..3ed3e46 >--- /dev/null >+++ b/misc/cronjobs/toggle_new_status.pl >@@ -0,0 +1,106 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use Getopt::Long; >+use Pod::Usage; >+use JSON; >+ >+use C4::Context; >+use C4::Items; >+ >+# Getting options >+my ( $verbose, $help, $confirm ); >+my $result = GetOptions( >+ 'h|help' => \$help, >+ 'v|verbose' => \$verbose, >+ 'c|confirm' => \$confirm, >+); >+ >+pod2usage(1) if $help; >+$verbose = 1 unless $confirm; >+ >+# Load configuration from the syspref >+my $syspref_content = C4::Context->preference('toggle_new_status_configuration'); >+my $rules = eval { JSON::from_json( $syspref_content ) }; >+pod2usage({ -message => "Unable to load the configuration : $@", -exitval => 1 }) >+ if $@; >+ >+my $report = C4::Items::ToggleNewStatus( { rules => $rules, report_only => not $confirm } ); >+ >+if ( $verbose ) { >+ if ( $report ) { >+ say "Item to modify:"; >+ while ( my ( $itemnumber, $substitutions ) = each %$report ) { >+ for my $substitution ( @$substitutions ) { >+ if ( defined $substitution->{value} and $substitution->{value} ne q|| ) { >+ say "\titemnumber $itemnumber: $substitution->{field}=$substitution->{value}"; >+ } else { >+ say "\titemnumber $itemnumber: field $substitution->{field} to delete"; >+ } >+ } >+ } >+ } else { >+ say "There is no item to modify"; >+ } >+} >+ >+exit(0); >+ >+__END__ >+ >+=head1 NAME >+ >+toggle_new_status.pl >+ >+=head1 SYNOPSIS >+ >+./toggle_new_status.pl -h >+ >+Toggle recent acquisitions status. >+Use this script to delete "new" status for items. >+ >+=head1 OPTIONS >+ >+=over 8 >+ >+=item B<-h|--help> >+ >+Prints this help message. >+ >+=item B<-v|--verbose> >+ >+Set the verbose flag. >+ >+=item B<-c|--confirm> >+ >+The script will modify the items. >+ >+=back >+ >+=head1 AUTHOR >+ >+Jonathan Druart <jonathan.druart@biblibre.com> >+ >+=head1 COPYRIGHT >+ >+Copyright 2013 BibLibre >+ >+=head1 LICENSE >+ >+This file is part of Koha. >+ >+Koha is free software; you can redistribute it and/or modify it >+under the terms of the GNU General Public License as published by >+the Free Software Foundation; either version 3 of the License, or >+(at your option) any later version. >+ >+Koha is distributed in the hope that it will be useful, but >+WITHOUT ANY WARRANTY; without even the implied warranty of >+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+GNU General Public License for more details. >+ >+You should have received a copy of the GNU General Public License >+along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=cut >diff --git a/tools/toggle_new_status.pl b/tools/toggle_new_status.pl >new file mode 100755 >index 0000000..9b7bf02 >--- /dev/null >+++ b/tools/toggle_new_status.pl >@@ -0,0 +1,116 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Copyright 2013 BibLibre >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+toggle_new_status.pl: Update new status for items. >+ >+=cut >+ >+=head1 DESCRIPTION >+ >+This script allows a user to update the new status for items. >+ >+=cut >+ >+use Modern::Perl; >+ >+use CGI; >+use JSON qw( to_json from_json ); >+ >+use C4::Auth; >+use C4::Context; >+use C4::Items; >+use C4::Output; >+use C4::Koha; >+ >+my $cgi = new CGI; >+ >+# open template >+my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >+ { >+ template_name => "tools/toggle_new_status.tt", >+ query => $cgi, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { tools => 'items_batchmod' }, >+ } >+); >+ >+my $op = $cgi->param('op') // 'show'; >+ >+my $syspref_name = q|toggle_new_status_configuration|; >+if ( $op eq 'update' ) { >+ my @rules; >+ my @unique_ids = $cgi->param('unique_id'); >+ for my $unique_id ( @unique_ids ) { >+ my @substitution_fields = $cgi->param("substitution_field_$unique_id"); >+ my @substitution_values = $cgi->param("substitution_value_$unique_id"); >+ my @condition_fields = $cgi->param("condition_field_$unique_id"); >+ my @condition_values = $cgi->param("condition_value_$unique_id"); >+ my $rule = { >+ substitutions => [], >+ conditions => [], >+ }; >+ for my $value ( @substitution_values ) { >+ my $field = shift @substitution_fields; >+ last unless $field; >+ push @{ $rule->{substitutions} }, { field => $field, value => $value }; >+ } >+ push @{ $rule->{substitutions} }, {} >+ unless @{ $rule->{substitutions} }; >+ for my $value ( @condition_values ) { >+ my $field = shift @condition_fields; >+ last unless $field; >+ push @{ $rule->{conditions} }, { field => $field, value => $value }; >+ } >+ push @{ $rule->{conditions} }, {} >+ unless @{ $rule->{conditions} }; >+ $rule->{duration} = $cgi->param("duration_$unique_id"); >+ push @rules, $rule; >+ } >+ my $syspref_content = to_json( \@rules ); >+ C4::Context->set_preference($syspref_name, $syspref_content); >+ >+ $op = 'show'; >+} >+ >+my @messages; >+my $syspref_content = C4::Context->preference($syspref_name); >+my $rules; >+$rules = eval { JSON::from_json( $syspref_content ) } >+ if $syspref_content; >+if ( $@ ) { >+ push @messages, { >+ type => 'error', >+ code => 'unable_to_load_configuration' >+ }; >+ $template->param( messages => \@messages ); >+ output_html_with_http_headers $cgi, $cookie, $template->output; >+ exit; >+} >+ >+$template->param( >+ op => $op, >+ messages => \@messages, >+ item_fields => [ C4::Items::columns ], >+ rules => $rules, >+); >+ >+output_html_with_http_headers $cgi, $cookie, $template->output; >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11023
:
21926
|
21932
|
21982
|
21983
|
22004
|
22386
|
22734
|
22735
|
24068
|
24069
|
24070
|
24146
|
24147
|
24148
|
25767
|
25833
|
26817
|
26818
|
26819
|
26820
|
26821
|
26822
|
26855
|
27810
|
29216
|
29217
|
29218
|
29219
|
29220
|
29221
|
29222
|
31820
|
31821
|
31822
|
33226
|
33227
|
33228
|
33229
|
33230
|
33231
|
33232
|
33233
|
33234
|
33235
|
34782
|
34783
|
34784
|
34785
|
34786
|
34787
|
34788
|
34789
|
34790
|
34791
|
34870
|
34871
|
34872
|
34873
|
34874
|
34875
|
34876
|
34877
|
34878
|
34879
|
34880
|
34881
|
34882
|
34883
|
35375
|
35376
|
41147
|
41148