Bug 11277: fix errors with search facet links in Bootstrap theme

This patch fixes the following rwo errors:

  1. When selecting 'show more' above a facet, the advanced search page
     is displayed.
  2. When restricting search on a library facet, all the biblio records
     of this library are returned.

The patch fixes the way URL are encoded with TT filter. See:

http://search.cpan.org/~abw/Template-Toolkit-2.25/lib/Template/Manual/Filters.pod#url

Signed-off-by: Liz Rea <liz@catalyst.net.nz>

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Patch works nicely. Tests done:
- 'More' link on facets redirects to advanced search before applying
  the patch. After appyling the link works correctly.
- In my tests, the facet links themselves worked nicely, limiting the
  search as expected.
- Availability search works ok for me with patch applied.
- Also made sure to click on some links containing diacritcts (German
  umlauts).

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 4e64ea8870cca3715f838ae3b577cb05da2f7879)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11249: Add Db indexes on borrowers names

The borrowers search is by default on columns surname, firstname,
othernames and cardnumber.

(See C4::Members::_express_member_find).

Adding DB indexes will really increase the query speed.

This patch adds DB indexes on surname, firstname, othernames (cardnumber
has already an index).

Those indexes must be defined with a size because columns are mediumtext.

Test plan :
Test with mysql client :
mysql> explain select * from borrowers where surname like 'A%';
+----+-------------+-----------+-------+---------------+-------------+---------+------+------+-------------+
| id | select_type | table     | type  | possible_keys | key         | key_len | ref  | rows | Extra       |
+----+-------------+-----------+-------+---------------+-------------+---------+------+------+-------------+
|  1 | SIMPLE      | borrowers | range | surname_idx   | surname_idx | 767     | NULL |  395 | Using where |
+----+-------------+-----------+-------+---------------+-------------+---------+------+------+-------------+
=> key show the index is used

Signed-off-by: Mathieu Saby <mathieu.saby@univ-rennes2.fr>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described, changes from updatedatabase and in kohastructure match.
I think deletedborrowers can be left out, as it's not queried when doing
patron searches. Patron deletes still work as expected.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 19b5c9b4cecf935c1cf17649796debe80ae7b3a8)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11249: DBRev 3.14.02.001

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 7518: regression test double-quote in search operand

Under certain circumstances, namely where QueryParser is off,
QueryWeightFields is on, and QueryFuzzy and QueryAutoTruncate are
off, a search with a double-quote embedded in it can fail: for
example

    web application

would return results where

    web "application

does not.

This patch adds an automated regression test.

To test:

[1] Apply this patch and run prove -v t/db_dependent/Search.t;
    two tests should fail.
[2] After applying the main patch that fixes the bug, the
    prove -v  t/db_dependent/Search.t should succeed.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 437f06624759c464d667107d9f73ec05283f6892)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 7518: certain searches with quotation marks don't work

Under certain circumstance, a search term without quotation marks
returns the expected results while the same search with a
double quote embedded in it would fail.

Koha should ignore the quotation marks and return results anyway.

This appears when  QueryWeightFields syspref is activated (and
QueryAutoTruncate is off), as field weighting builds a complex CCL
query using double quotes around search words.  This patch simply
replaces double quotes in search words by a space.

Test plan :
- Set QueryAutoTruncate off (you may also need to set QueryFuzzy to off)
- Set QueryWeightFields off
- Perform a serch on two words where you have results, like : centre "ville
=> you get results
- Set QueryWeightFields on
- Perform same serch
=> you get the same results

Signed-off-by: Leila <koha.aixmarseille@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 868855df4b674b495966c022392068c2fdd3a35f)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11279: regression test for picking random quote

This patch adds new tests based on the db_dependent tests in
t/db_dependent/Koha.t for GetDailyQuote().

Tests run on an empty database and don't require Test::Deep.

Tests will fail before applying the patch for 11297, but will
pass after applying the patch.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit f874eec0793f83c3c0f1461fecb878ca57ed701b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11279: Improve how a new quote of the day is selected

If there is a gap in the id sequence for the quotes table, it
is possible that no new quote will be selected. This will happen
particularly when a lot of the older quotes with low ids have been
deleted.

This patch improves the selection of a new quote.

To test:
- Load sample quotes
- Delete the first half of the quotes.
  Note: With 34 quotes, delete the quotes with ids from 1-17
- Activate the QuoteOfTheDay system preference
- Check if a quote is displayed in OPAC
- Reload the page a few times, no quote should be displayed
  Note: make sure you don't have a quote with the current
  date in your quotes table before running those tests
- Run 'perl t/db_dependent/Koha.t'
  Note: requires sample quotes!
- Apply patch
- Reload the OPAC start page
- Verify a quote was now picked
- Run 'perl t/db/dependent/Koha.t' again - all tests should still pass

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

Patch modified to use "LIMIT 1 OFFSET ?" rather than "LIMIT ?, 1"; the
latter construction does not work in PostgreSQL.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5a3db23362eb076a2f6d5a87f87b29f4a436a14f)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11279: (follow-up) remove unnecessary check on number of quotes

It is not necessary to process the case where the number of quotes
is just one, as int(rand(1)) will always produce 0, which is a valid
offset.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 8ee6e4290e2d1ca4fea53363b7ca3275cb0e6f58)
Bug 11417: make sure remove_unused_authorities.pl accepts --test

This patches adds support for the --test option, as well as a
short message telling the user the script is running in test mode.

Test plan :
- Launch the script with -h to see the help
- Launch the script with --test and --aut with an authtypecode
  that is used in your instance
- Make sure it does the same thing as launching it with -t
- Launch the script for real and make sure it still works as
  expected, deleting unused authorities.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 6657860010ef27792251596590c1471ad5d08ad8)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11228: Improve hint on patron notification when adding/editing subscriptions

The hint was not quite correct, as it said patrons on the routing list
would be informed, but it's only the patrons that have subscribed to
email notifications in the OPAC who will receive the email when a
new serial issue is received.

To test:
- Add a new subscription, find the hint about patron notification on the form
- Apply patch
- Refresh page
- Verify the new hint text makes sense and is correct

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 53495aab241cef4202eac372e85e6f3d09aa873d)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11179: make OPAC course details page display status of checked out items correctly

If an item is listed for a course and is checked out, the item will
still show as being available from the course details page which lists
all the items that are part of a course. This is due to the way the
course reserves system handles items and issues separately, while
item-status.inc assumes the due date has been embedded in items.datedue

Test Plan:
1) Create a course
2) Add an item to that course
3) Check the item out to a patron
4) View the course details from the opac
5) Note the status says "Available"
6) Apply this patch
7) Repeat step 4
8) Note the status no longer says "Available"

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit dc5e4e5b631116ce7ce16143ba56c5eb0385d986)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11179: (follow-up) apply fix to Boostrap theme

This follow-up applies the same fix to the Bootstrap theme. This patch
also includes the changes to item-status.inc in the Bootstrap theme
which were made to the prog theme in Bug 10820: display item status as
lost if item is both lost and on loan.

Signed-off-by: Liz Rea <liz@catalyst.net.nz>
Bootstrap theme looking so nice. Also the patch works.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 78b73c3fffc6f5125a688e91582da92287fbbef2)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Conflicts:
	koha-tmpl/opac-tmpl/bootstrap/en/includes/item-status.inc
Bug 11179: (follow-up) add comment to item-status.inc

This patch adds a comment to item-status.inc to describe
the parameters it can accept.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit ec7fff647d547c9ff5adadcb4c1cb35bc4ea7baf)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8921: make koha-common*.deb depend on cron-daemon

Trivial patch to add 'cron-daemon' as dependency for the koha-common
package. 'cron' is usually pulled in any minimal Ubuntu/Debian
install, but in some circumstances (using debootstrap) it might be
absent.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
No entry in debian/control yet, but
according to comments in the file this file is generated
from control.in - so this should be ok.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit e52b493611766b61a0018350adc590ab07e9c94b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11403: Add missing help file to new Renew page

This patch adds a help file to the Renew page found under
Circulation.

To test:

* Go to Circulation > Renew
* Click the help link
* Confirm text and manual link are correct.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit e8808dfd527b2b461485507fe508928bb84b7f82)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11445: regression test for duplicate hold notifications

This patch implements a regression test for verifying that
duplicate hold notifications aren't sent if ModReserveAffect() is
called repeatedly (as might happen if a circ operator accidentally
checks in an item and confirms its hold more than once).

Note that the test depends on the fact that _koha_notify_reserve()
defaults to sending a HOLD_PRINT letter if the borrower has not
specified an email or SMS hold notification.

To test:

[1] Run prove -v t/db_dependent/Reserves.t
[2] The 'patron not notified a second time (bug 11445)' test
    should fail.
[3] Apply the main patch and run prove -v t/db_dependent/Reserves.t
    again.  This time all tests should pass.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
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>
(cherry picked from commit 2b6a20c509801b9eeb562aa6fd404546d6ba84df)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11445: avoid sending duplicate hold waiting notifications

This patch fixes a problem where a patron could receive duplicate
hold waiting notifications.  For example, this could happen if a
circ operator checked in an item more than once and confirmed the
same hold each time.

To test:

[1] Set up a test patron that received hold waiting notifications.
[2] Put an item on hold for the patron, then check the item in
    and confirm the hold.  Verify that a hold notification is
    sent (or inspect the message_queue table).
[3] Check the item in again and confirm the hold again.  A duplicate
    hold notification will be generated.
[4] Apply the patch.
[5] Repeat steps 2 and 3.  This time, only one notification should be
    generated.
[6] Verify that prove -v t/db_dependent/Reserves.t passes.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Works as described.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit fe08a0ef97ad2fbab72b857d61bec364fd93d9e9)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11188 - Make gather_print_notices.pl die on failed open()

Problem:
If you tell gather_print_notices.pl to write output to a location
you do not have write access to, it will silently fail to write the
data, but still mark unsent messages as sent.

Solution:
This patch adds two lines of defense:
1. Check that the location given for the output is writable
2. use "open() or die" instead of just "open()" when writing the
   output
The first measure should catch most of the potential errors, but
I guess a directory can be writable, but the open() still can fail
because the disk is full or something similar.

To test:
- Make sure you have some unsent messages in the message_queue table,
  that do not have an email adress
- Apply the patch
- Run the script, pointing at a location you do not have access to
  write to. Check that the script exits with an appropriate error
  message, and that the unsent messages are still unsent. Do this
  both with and without the -s option.
- To fake passing the first line of defence, comment out line 62
  and put this in instead:
  if ( !$output_directory || !-d $output_directory ) {
- Run the script again as above, check you get an appropriate
  error and that the message queue is not touched
- Reset line 62 to how it was
- Run the script against a directory you do have access to write to
  and check that output is produced as expected and that messages
  are marked as sent
- Sign off

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Works as described.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit e8a24c35f64cb461a80f768b505bbf16c49dfeff)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11075: 'select all' for export no longer clears renew checkboxes

If circulation exports are enabled (by turning on ExportWithCsvProfile),
the table on the checkout page includes three columns of checkboxes --
'renew', 'checkin', and 'export'.

For each loan, the renew and checkout links should behave like radio
buttons, but the state of the export checkbox is meant to be independent
of the renew and checkin checkboxes.

However, if the 'select all' link in the export column is clicked,
active renew checkboxes are toggled off.

The desired behavior is that clicking the select all link in the export
column should only affect checkboxes in that column.  This patch
implements this behavior.

Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script - one line JavaScript change.
Works as described.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 4a0f630f7f8c7f3c402defa5837bc470510ebb07)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 11402: make Labels::_guide_box return undef if undefned data is passed

That's it. A guide box cannot be created if invalid data is passed.

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script, includes new unit tests.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 4720cbc4145223f1ffd653efdefd1a4f724d3144)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>