bug 7494: optional checkout-time fallback search for a book

When issuing a book, some libraries want to issue by title or other details.
This patch adds a systempreference and code that allows it.

To test:
1) scan a patron card or enter a surname to start checking out;
2) enter title or other keywords;
3) the circulation screen should display a warning allowing to choose between copies.

Signed-off-by: MJ Ray <mjr@phonecoop.coop>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
bug 7494: (follow-up) tweak description of itemBarcodeFallbackSearch syspref

Thanks to MJ Ray for helping with the wordsmithing on #koha.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
bug 7494: DBRev 3.13.00.015'

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10462: Some optimizations in Z3950 search paving the way for enhancements

Refactors Z3950Search.
Disable batch record counts for z3950 records.

Test plan:
Do various Z3950 searches on multiple targets from Cataloging and Acquisition.
Behavior should not have changed.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10462: Followup for showing multiple ISBNs in Z3950 response

As Jonathan correctly noted, the new Z3950 response only showed one isbn
although more isbn numbers could be in the record and would be imported.
To resolve this display problem, I traverse them all now in the updated
routine _isbn_show. There is no change in the imported records.
Note that before this patch TransformMarcToKoha did put all isbn numbers in
one field, separated by pipes (for display only). This behavior is restored
now. The three regexes on the individual isbn numbers now seem to be
overkill, but I left them there for completeness.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested this on a fresh French install under UNIMARC with BNF server.
Tested it too for MARC21.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10462: QA Followup to resolve LCCN mixup and remove hardcoded marc tags

This patch corrects the mixup for LC call number and control number.

Further, as suggested by Galen, it would be better to not introduce hardcoded
tags in the Z3950Search subs in Breeding.pm.
This patch resolves that by calling TransformMarcToKohaOneField.
Note that this only involves changes to _addrowdata and _isbn_show. These
subs are only used in building the displayed results table.

Additionally, for French UNIMARC installs publicationyear is used to fill
the Date column (copyrightdate is not used in those installs). The edition
statement is only used in unimarc_lecture_pub not in unimarc_complet.

Test plan:
Do some Z3950 searches and look for values in all result columns.
For MARC21 on LOC (and/or others):
  Look for isbn 9780415964845 (check LCCN).
  Look for author Rowling.
For UNIMARC on BNF2 (and/or others):
  On BNF2 look for isbn 2070518426: result contains date and multiple isbn's.
  Look for title: Guide des candidats aux emplois de commissaire de police.
  Third result show edition statement (if you use 205$a with pub install).
  Note that there are no results with LCCN here (just as before).

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested for MARC21 and UNIMARC (French lecture_pub install).

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10462: (follow-up) remove some undefined variable warning noise

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10621: use correct from-address for subscription alert emails

From-address and to-address were the same (patron's email) for
subscription alerts. This patch changes 'from' the branch or
kohaadminemailaddress

To test
- add a subscription in staff/serials in case you don't have any
- enable patron notifications or the subscription
- in the OPAC, subscribe to the serial
- in staff/serial, receive an issue of the serial

Before applying the patch, the email that is supposed to be sent
has the patron's email as 'from' and 'to' (and is likely to fail).

If you follow the steps after applying the patch, the email alert
should have the 'from' address of the patron's branch or
kohaadminemiladdress -- which should also work fine with the MTA/SMTP
you have set up for messaging.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10463: ensure that Quote of the Day feature selects random quotes

When the Quote of the Day tool selects a new new quote, it updates the
timestamp and does not take the timezone into account.  Thus the time is
set to +4 hours (e.g. 2013-06-11 13:33:48 when the time is 2013-06-11
        09:33:48).  It then repeats the same quote every day.

To replicate:

Set Administration >> System preferences >> OPAC preferences >> Features
>> QuoteOfTheDay to Enable

In Home >> Tools >> Quote Editor, add several quotes.

In the opac, refresh the home page. You should get a quote of the day at
the top.

mysql> select * from quotes;

Note the timestamp of the quote selected by the tool. It will not match
the date on the machine (unless your server's timezone is set to UTC).

If you change the date to the previous date and refresh the opac, the
tool wlill select another quote, which will not change unless forced.

Test Plan:
1) Remove all your quotes and import a fresh set
2) Enable the quote of the day and view the opac
3) Look at your quotes table and note the timestamp is incorrect
4) Repeat steps 1 and 2
5) Look at your quotes table and note the timestamp is now correct

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10070: fix saving searches with non-ASCII characters to anonymous search history

To test
1/ logout
2/ search "bar" (added to the history)
3/ search "féé" => history is empty

Apply patch
1/ logout
2/ search "bar" (added to the history)
3/ search "féé" => added to the history

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
use JSON rather than Storable for the OPAC search history cookie

To test:

Exercise the OPAC search history functionality, after
turning on the EnableOpacSearchHistory syspref:

- Clear the KohaOpacRecentSearches cookie
- As an anonymous user, conduct a variety of searches,
  including ones that include non-ASCII characters
- Check the search history and verified that all searches
  are listed
- Log into the OPAC
- Verify that current and past searches are listed in
  search history.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
do some validation of the KohaOpacRecentSearches cookie

Add validation of the value of the KohaOpacRecentSearches.  In
particular, this patch avoids the generation of an internal server
error when the OPAC is presented with an old cookie that uses the
old Storable-based serialization.

This patch also moves parsing of the cookie value into a
new routine in C4::Auth, ParseSearchHistoryCookie, and adds
a test case.

To test (in conjunction with the previous patch):

Exercise the OPAC search history functionality, after
turning on the EnableOpacSearchHistory syspref:

- As an anonymous user, conduct a variety of searches,
  including ones that include non-ASCII characters
- Check the search history and verify that all searches
  are listed
- Apply this patch and the previous one.
- Do *not* clear the KohaOpacRecentSearches cookie
- Check the search history and verify that no searches
  are listed any more
- As an anonymous user, conduct a variety of searches,
  including ones that include non-ASCII characters
- Check the search history and verify that all searches
  are listed
- Log into the OPAC
- Verify that current and past searches are listed in
  search history.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
move Auth_ParseSearchHistoryCookie.t to db_dependent directory

The actual tests in this script are not dependent on the database,
but simply loading C4::Auth requires a valid(ish) koha-conf.xml
and database.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10543: fix false warnings from checks of mandatory item fields

Under certain circumstances, when editing an item, you get a popup
warning
  "1 mandatory fields empty (highlighted)".

Even though all mandatory fields are filled in.

This occurs when there is a field with a huge content (more than 100
characters) that gets displayed in a textarea instead of input.

This patch corrects the Javascript form check by using siblings().

Also adds a more precise filter to find mandatory inputs because
looking in full page may bring unwanted results.

Test plan :
- In a framework, make sure you have in item field :
  An optional subfield (without authorised value),
  then a mandatory subfield, then an optional subfield
  next to mandatory subfield
  For example : $i (optional), $r (mandatory) and $s (optional)
- Open a biblio record and create a new item
- Enter more than 100 characters in $i, fill $r and $s
- Click "Add item"
- Edit this item
=> You get a textarea for $i
- Empty $s and Save
=> Without patch, you get a warning and form is not saved and you see that $s is yellow while it should be $r
=> With patch, form is saved
- Re-edit this item
- Empty $r and save
=> You get a warning and form is not saved

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Notes on last patch.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10543 - Unify item mandatory subfields check

Use of CheckMandatorySubfields from cataloging.js
everywhere an item cataloging form is checked for
mandatory fields.

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10543 - add mandatory subfield check to addorderiso2709.pl

When adding orders from staged file, you can create one order per
record using item form in the bottom of addorderiso2709.pl.  The
form was missing checks of mandatory item fields; this patch
adds those checks.

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>

All 3 patches pass tests and QA script.

Some additional notes on the test plan from the first patch:
It took me a while to figure out a combination of subfields
that would trigger the bug. I am not sure about the condition
that transforms the input field into a textbox as it does
not seem to happen for every field.

What worked in the end was (MARC21):
- $g cost, normal purchase price = mandatory
- $h serial enumeration/chronolgy = optional, filled with
  text over 100 characters

Checked for:
- Adding items in cataloguing
  Was able to reproduce the problem, mandatory check works
  as expected.
- Adding items from staged file in acq
  Was not able to trigger the problem, because we don't edit
  the item here, but mandatory check works as expected.
- Addings items for serial subscriptions
  Was not able to trigger the problem, because we don't edit
  the items here, but mandatory check works better as before
  as missing mandatory fields are now highlighted and weren't
  before.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10644: add unit tests for ClassSource.pm

The tests are wrapped in a database transaction.

To test:
prove t/db_dependent/ClassSource.t
t/db_dependent/ClassSource.t .. 1/24 prepare_cached(SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?) statement handle DBI::st=HASH(0x92dbedc) still Active at C4/ClassSource.pm line 249
prepare_cached(SELECT * FROM `class_sources` WHERE cn_source = ?) statement handle DBI::st=HASH(0x926876c) still Active at C4/ClassSource.pm line 137
attempting to use non-existent class sorting routine routine1
prepare_cached(SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?) statement handle DBI::st=HASH(0x92dbedc) still Active at C4/ClassSource.pm line 249
prepare_cached(SELECT * FROM `class_sources` WHERE cn_source = ?) statement handle DBI::st=HASH(0x926876c) still Active at C4/ClassSource.pm line 137
t/db_dependent/ClassSource.t .. ok
All tests successful.
Files=1, Tests=24,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.12 cusr  0.01 csys =  0.15 CPU)
Result: PASS

Signed-off-by: Srdjan <srdjan@catalyst.net.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10644: fix typos in test descriptions

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10609: Use library name rather than code in serials-collection.pl

The serials collection page displays branchcode instead of library name.
This patch uses the Branches template plugin to display the library name
instead.

Also corrected: Added missing datatables config include to prevent a
JavaScript error.

To test, view the serials collection page for a subsciption with
existing issues. Library names should be displayed instead of
branchcodes. There should be no JavaScript errors reported by the
browser.

Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works well and uses the new TT plugin for displaying the branch name.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 10666: avoid random failures of Daily quotes tests

In t/db_dependent/Koha.t, the test "Got a quote based on today's
date" is failing :

$prove t/db_dependent/Koha.t :
t/db_dependent/Koha.t .. 1/6
    #   Failed test 'Got a quote based on today's date.'
    #   at t/db_dependent/Koha.t line 126.
    # Compared $data->{"source"}
    #    got : 'Herbert Hoover'
    # expect : 'Abraham Lincoln'
    # Be sure to run this test on a clean install of sample data.
    # Looks like you failed 1 test of 4.

Looks like the wrong quote is returned by GetDailyQuote().
I'm using a databased created with the English sample SQL datas.

I think I found the cause :
The test "Got a random quote." calls GetDailyQuote('random'=>1) which
changes the quote timestamp to now. When then testing GetDailyQuote(),
this quote (which may not be the one created by test) is the most
recent quote.

This patch moves the "Got a random quote." test after "Got a quote
based on today's date" to solve the problem.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>