Bugzilla – Attachment 84325 Details for
Bug 17047
Mana Knowledge Base : Data sharing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17047: SQL reports management with Mana-KB
Bug-17047-SQL-reports-management-with-Mana-KB.patch (text/plain), 135.13 KB, created by
Alex Arnaud
on 2019-01-23 09:27:58 UTC
(
hide
)
Description:
Bug 17047: SQL reports management with Mana-KB
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2019-01-23 09:27:58 UTC
Size:
135.13 KB
patch
obsolete
>From 77bf3f0807144b4f24525a0510f15e21ee809780 Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Wed, 8 Mar 2017 15:46:24 +0000 >Subject: [PATCH] Bug 17047: SQL reports management with Mana-KB > >Includes: > >* code factorization >Some code from subscription & Mana-KB has been factorized in order to speed-up next developments > >* SytemPreferences: >Mana Activation: > - add a value "no, let me think about it", that is the default value. > - as long as this value is selected, messages ask if user want to activate it ( in Administration and Add-subscription(page 2) ) >AutoShareWithMana > - Add the syspref AutoShareWithMana: user can automatically share infos with Mana-KB (not set by default) > >* Interface : > - On mana-search, rows are now sorted by date of last import, then by number of users > - Windows redesigned to improve the user experience > >* New Feature : report a mistake. > - people can now report an invalid data (wrong, obsolete,...) > - if a data is reported as invalid many time, it will appear differently > - Added few tooltip (to explain the fields last import, nb of users, to explain the new feature) > - When reporting a data as invalid, a comment can also be added. Koha will then display comments related to data in result lists > >* API (svc/mana) > - add svc/mana/addvaluetofield: allows to ask mana incrementing a field of a resource > - no hardcoding for resources in the code of api (api needs to be called with a ressourcename) > >* New feature : SQL report sharing > - Create Koha::Report.pm and Koha::Reports.pm, objects class for Reports > - New feature: share reports with Mana-KB > - New feature: search report in Mana-KB with keywords > - New feature: load reports from Mana-KB > >Test plan: > 1 - Apply Patch + update database > 2 - Copy the three lines about mana config in etc/koha-conf.xml in ../etc/koha-conf.xml (after <backupdir> for example) > <!-- URL of the mana KB server --> > <!-- alternative value http://mana-test.koha-community.org to query the test server --> > <mana_config>https://mana-kb.koha-community.org</mana_config> > 3 - Check Mana syspref and AutoShareWithMana syspref are not activated > 4 - Search the syspref ManaToken and follow the instructions > 5 - subscriptions > - Try create a new subscription for a first serial => Mana-KB shouldn't show you anything (except if the base hase been filled) > - Share this serial with Mana-KB (on the serial individual's page there must be a Share button) > - Try to create a new subscription for serial nr1 => a message should appear when you click on "next", click on "use", the fields should automaticaly appear > - Activate AutoShareWithMana => Subscriptions > - Create a new subscription for a second serial > - There shouldn't be any Share button > - Create a second subscription => the message should appear, click again on use > > 6 - SQL Report > - Create a new SQL report, without notes. > - On the table with all report (reports > use saved), there should be the action "Share" > - If you click on share, you have an error message > - Create a new report, with a title and notes longer than 20 characters > - You can share it with mana => you will have a success message > - On (report > use saved), there must be a message inviting you to search on Mana-KB for more results, enter a few word from title, notes, type of the report you shared, it should appear. You can use it, it will load it into your report list. > > 7 - Report mistakes. > - On any table containing Mana-KB search results, you can report a mistake and add a comment. > > 8 - For each previous test, try to send wrong data, to delete the security token, to send nothing: it should show a correct warning message. > >Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Rebased-by: Alex Arnaud <alex.arnaud@biblibre.com> (2018-07-04) >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/Reports/Guided.pm | 1 + > C4/Serials.pm | 7 + > Koha/Report.pm | 57 ++++ > Koha/Reports.pm | 6 + > Koha/SharedContent.pm | 196 +++++++++--- > Koha/Subscription.pm | 14 +- > Koha/Subscription/Numberpatterns.pm | 34 ++- > debian/templates/koha-conf-site.xml.in | 3 + > etc/koha-conf.xml | 4 + > .../mysql/atomicupdate/mana_01-add_mana_id.perl | 13 + > .../mana_01-add_mana_id_in_subscription.sql | 1 - > .../atomicupdate/mana_02-add_Mana_syspref.sql | 2 +- > .../atomicupdate/mana_03-add_mana_autoshare.sql | 2 + > .../mysql/atomicupdate/mana_04-add_mana_token.sql | 2 + > installer/data/mysql/atomicupdate/skeleton.perl | 2 +- > installer/data/mysql/kohastructure.sql | 2 + > installer/data/mysql/sysprefs.sql | 2 +- > koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js | 18 ++ > .../intranet-tmpl/prog/css/src/staff-global.scss | 6 + > .../intranet-tmpl/prog/en/includes/calendar.inc | 2 +- > .../includes/mana-subscription-search-result.inc | 46 --- > koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc | 44 +++ > .../en/includes/mana/mana-report-search-result.inc | 81 +++++ > .../mana/mana-subscription-search-result.inc | 92 ++++++ > .../prog/en/includes/reports-toolbar.inc | 138 +++++++++ > .../prog/en/includes/serials-toolbar.inc | 53 +++- > .../prog/en/modules/admin/admin-home.tt | 7 +- > .../prog/en/modules/admin/preferences.tt | 1 + > .../en/modules/admin/preferences/web_services.pref | 17 +- > .../en/modules/mana/mana-report-search-result.tt | 1 + > .../mana/mana-subscription-search-result.tt | 1 + > .../en/modules/reports/guided_reports_start.tt | 170 ++++++++++- > .../serials/mana-subscription-search-result.tt | 1 - > .../prog/en/modules/serials/serials-search.tt | 3 +- > .../prog/en/modules/serials/subscription-add.tt | 25 +- > .../prog/en/modules/serials/subscription-detail.tt | 9 +- > koha-tmpl/intranet-tmpl/prog/js/serials-toolbar.js | 3 + > .../intranet-tmpl/prog/js/subscription-add.js | 44 ++- > reports/guided_reports.pl | 19 +- > serials/serials-collection.pl | 2 +- > serials/serials-search.pl | 5 +- > serials/subscription-add.pl | 69 ++--- > serials/subscription-detail.pl | 48 +-- > svc/mana/increment | 48 +++ > svc/mana/search | 37 ++- > svc/mana/share | 69 +++++ > svc/mana/token | 55 ++++ > svc/mana/use | 22 +- > t/db_dependent/Koha/SharedContent.t | 227 +++++++++++++- > t/db_dependent/Koha/Subscription.t | 4 +- > t/db_dependent/Koha/Subscription/Numberpatterns.t | 97 ++++++ > t/db_dependent/Serials.t | 2 +- > t/db_dependent/Serials/GetFictiveIssueNumber.t | 332 ++++++++++++++------- > 53 files changed, 1778 insertions(+), 368 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id.perl > delete mode 100644 installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql > create mode 100644 installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql > create mode 100644 installer/data/mysql/atomicupdate/mana_04-add_mana_token.sql > create mode 100644 koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js > delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-subscription-search-result.tt > delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt > create mode 100755 svc/mana/increment > create mode 100755 svc/mana/share > create mode 100755 svc/mana/token > create mode 100644 t/db_dependent/Koha/Subscription/Numberpatterns.t > >diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm >index f8d98e6..c4d783f 100644 >--- a/C4/Reports/Guided.pm >+++ b/C4/Reports/Guided.pm >@@ -33,6 +33,7 @@ use C4::Log; > > use Koha::AuthorisedValues; > use Koha::Patron::Categories; >+use Koha::SharedContent; > > BEGIN { > require Exporter; >diff --git a/C4/Serials.pm b/C4/Serials.pm >index f300c12..e929e21 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -35,6 +35,7 @@ use Koha::DateUtils; > use Koha::Serial; > use Koha::Subscriptions; > use Koha::Subscription::Histories; >+use Koha::SharedContent; > > use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); > >@@ -280,6 +281,12 @@ sub GetSubscription { > }); > $subscription->{additional_fields} = $additional_field_values->{$subscriptionid}; > >+ if ( my $mana_id = $subscription->{mana_id} ) { >+ my $mana_subscription = Koha::SharedContent::get_entity_by_id( >+ 'subscription', $mana_id, {usecomments => 1}); >+ $subscription->{comments} = $mana_subscription->{data}->{comments}; >+ } >+ > return $subscription; > } > >diff --git a/Koha/Report.pm b/Koha/Report.pm >index 3be4415..0458480 100644 >--- a/Koha/Report.pm >+++ b/Koha/Report.pm >@@ -20,6 +20,8 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use JSON; >+use Koha::Reports; > > use base qw(Koha::Object); > >@@ -33,6 +35,61 @@ Koha::Report - Koha Report Object class > > =cut > >+=head3 get_search_info >+ >+Return search info >+ >+=cut >+ >+sub get_search_info { >+ my $self = shift; >+ my $sub_mana_info = { 'query' => shift }; >+ return $sub_mana_info; >+} >+ >+=head3 get_sharable_info >+ >+Return properties that can be shared. >+ >+=cut >+ >+sub get_sharable_info { >+ my $self = shift; >+ my $shared_report_id = shift; >+ my $report = Koha::Reports->find($shared_report_id); >+ my $sub_mana_info = { >+ 'savedsql' => $report->savedsql, >+ 'report_name' => $report->report_name, >+ 'notes' => $report->notes, >+ 'report_group' => $report->report_group, >+ 'type' => $report->type, >+ }; >+ return $sub_mana_info; >+} >+ >+=head3 new_from_mana >+ >+Clear a Mana report to be imported in Koha? >+ >+=cut >+ >+sub new_from_mana { >+ my $self = shift; >+ my $data = shift; >+ >+ $data->{mana_id} = $data->{id}; >+ >+ delete $data->{exportemail}; >+ delete $data->{kohaversion}; >+ delete $data->{creationdate}; >+ delete $data->{lastimport}; >+ delete $data->{id}; >+ delete $data->{nbofusers}; >+ delete $data->{language}; >+ >+ Koha::Report->new($data)->store; >+} >+ > =head3 _type > > Returns name of corresponding DBIC resultset >diff --git a/Koha/Reports.pm b/Koha/Reports.pm >index ca687a3..fc2be72 100644 >--- a/Koha/Reports.pm >+++ b/Koha/Reports.pm >@@ -55,4 +55,10 @@ sub object_class { > return 'Koha::Report'; > } > >+=head1 AUTHOR >+ >+Kyle M Hall <kyle@bywatersolutions.com> >+ >+=cut >+ > 1; >diff --git a/Koha/SharedContent.pm b/Koha/SharedContent.pm >index e0c512b..587285d 100644 >--- a/Koha/SharedContent.pm >+++ b/Koha/SharedContent.pm >@@ -22,69 +22,191 @@ use JSON; > use HTTP::Request; > use LWP::UserAgent; > >-our $MANA_IP = "http://10.25.159.107:5000"; >+use Koha::Serials; >+use Koha::Reports; >+use C4::Context; > >-sub manaRequest { >+=head1 DESCRIPTION >+ >+Package for accessing shared content via Mana >+ >+=head2 Package Functions >+ >+=cut >+ >+=head3 process_request >+ >+=cut >+ >+sub process_request { > my $mana_request = shift; > my $result; >- > $mana_request->content_type('application/json'); > my $userAgent = LWP::UserAgent->new; >- my $response = $userAgent->request($mana_request); >- >- if ( $response->code ne "204" ) { >- $result = from_json( $response->decoded_content ); >+ if ( $mana_request->method eq "POST" ){ >+ my $content; >+ if ($mana_request->content) {$content = from_json( $mana_request->content )}; >+ $content->{securitytoken} = C4::Context->preference("ManaToken"); >+ $mana_request->content( to_json($content) ); > } >+ >+ my $response = $userAgent->request($mana_request); >+ >+ eval { $result = from_json( $response->decoded_content, { utf8 => 1} ); }; > $result->{code} = $response->code; >+ if ( $@ ){ >+ $result->{msg} = $@; >+ } >+ if ($response->is_error){ >+ $result->{msg} = "An error occurred, mana server returned: " . $response->message; >+ } >+ return $result ; >+} >+ >+=head3 increment_entity_value >+ >+=cut > >- return $result if ( $response->code =~ /^2..$/ ); >+sub increment_entity_value { >+ return process_request(build_request('increment', @_)); > } > >-sub manaNewUserPatchRequest { >- my $resource = shift; >- my $id = shift; >+=head3 send_entity >+ >+=cut >+ >+sub send_entity { >+ my ($lang, $loggedinuser, $resourceid, $resourcetype, $content) = @_; > >- my $url = "$MANA_IP/$resource/$id.json/newUser"; >- my $request = HTTP::Request->new( PATCH => $url ); >+ unless ( $content ) { >+ $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype); >+ } >+ >+ my $result = process_request(build_request('post', $resourcetype, $content)); > >- return manaRequest($request); >+ if ( $result and ($result->{code} eq "200" or $result->{code} eq "201") ) { >+ my $packages = "Koha::".ucfirst($resourcetype)."s"; >+ my $resource = $packages->find($resourceid); >+ eval { $resource->set( { mana_id => $result->{id} } )->store }; >+ } >+ return $result; > } > >-sub manaPostRequest { >- my $resource = shift; >- my $content = shift; >+=head3 prepare_entity_data >+ >+=cut > >- my $url = "$MANA_IP/$resource.json"; >- my $request = HTTP::Request->new( POST => $url ); >+sub prepare_entity_data { >+ my ($lang, $loggedinuser, $ressourceid, $ressourcetype) = @_; >+ $lang ||= C4::Context->preference('language'); > >- $content->{bulk_import} = 0; >- my $json = to_json( $content, { utf8 => 1 } ); >- $request->content($json); >+ my $mana_email; >+ if ( $loggedinuser ne 0 ) { >+ my $borrower = Koha::Patrons->find($loggedinuser); >+ $mana_email = $borrower->first_valid_email_address >+ || Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail >+ } >+ $mana_email = C4::Context->preference('KohaAdminEmailAddress') >+ if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); > >- return manaRequest($request); >+ my %versions = C4::Context::get_versions(); >+ >+ my $mana_info = { >+ language => $lang, >+ kohaversion => $versions{'kohaVersion'}, >+ exportemail => $mana_email >+ }; >+ >+ my $ressource_mana_info; >+ my $packages = "Koha::".ucfirst($ressourcetype)."s"; >+ my $package = "Koha::".ucfirst($ressourcetype); >+ $ressource_mana_info = $package->get_sharable_info($ressourceid); >+ $ressource_mana_info = { %$ressource_mana_info, %$mana_info }; >+ >+ return $ressource_mana_info; >+} >+ >+=head3 get_entity_by_id >+ >+=cut >+ >+sub get_entity_by_id { >+ return process_request(build_request('getwithid', @_)); >+} >+ >+=head3 search_entities >+ >+=cut >+ >+sub search_entities { >+ return process_request(build_request('get', @_)); > } > >-sub manaGetRequestWithId { >+=head3 build_request >+ >+=cut >+ >+sub build_request { >+ my $type = shift; > my $resource = shift; >- my $id = shift; >+ my $mana_url = get_sharing_url(); >+ >+ if ( $type eq 'get' ) { >+ my $params = shift; >+ $params = join '&', >+ map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () } >+ keys %$params; >+ my $url = "$mana_url/$resource.json?$params"; >+ return HTTP::Request->new( GET => $url ); >+ } >+ >+ if ( $type eq 'getwithid' ) { >+ my $id = shift; >+ my $params = shift; >+ $params = join '&', >+ map { defined $params->{$_} ? $_ . "=" . $params->{$_} : () } >+ keys %$params; >+ >+ my $url = "$mana_url/$resource/$id.json?$params"; >+ return HTTP::Request->new( GET => $url ); >+ } >+ >+ if ( $type eq 'post' ) { >+ my $content = shift; > >- my $url = "$MANA_IP/$resource/$id.json"; >- my $request = HTTP::Request->new( GET => $url ); >+ my $url = "$mana_url/$resource.json"; >+ my $request = HTTP::Request->new( POST => $url ); > >- return manaRequest($request); >+ my $json = to_json( $content, { utf8 => 1 } ); >+ $request->content($json); >+ >+ return $request; >+ } >+ >+ if ( $type eq 'increment' ) { >+ my $id = shift; >+ my $field = shift; >+ my $step = shift; >+ my $param; >+ >+ $param->{step} = $step || 1; >+ $param->{id} = $id; >+ $param->{resource} = $resource; >+ $param = join '&', >+ map { defined $param->{$_} ? $_ . "=" . $param->{$_} : () } >+ keys %$param; >+ my $url = "$mana_url/$resource/$id.json/increment/$field?$param"; >+ my $request = HTTP::Request->new( POST => $url ); >+ >+ } > } > >-sub manaGetRequest { >- my $resource = shift; >- my $parameters = shift; >+=head3 get_sharing_url > >- $parameters = join '&', >- map { defined $parameters->{$_} ? $_ . "=" . $parameters->{$_} : () } >- keys %$parameters; >- my $url = "$MANA_IP/$resource.json?$parameters"; >- my $request = HTTP::Request->new( GET => $url ); >+=cut > >- return manaRequest($request); >+sub get_sharing_url { >+ return C4::Context->config('mana_config'); > } > > 1; >diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm >index 4991eb4..570ae1f 100644 >--- a/Koha/Subscription.pm >+++ b/Koha/Subscription.pm >@@ -125,13 +125,15 @@ sub frequency { > return Koha::Subscription::Frequency->_new_from_dbic($frequency_rs); > } > >-=head3 type >+=head3 get_search_info > > =cut > > sub get_search_info { >+ my $self=shift; > my $searched_sub_id = shift; > my $biblio = Koha::Biblios->find( { 'biblionumber' => $searched_sub_id } ); >+ return unless $biblio; > my $biblioitem = > Koha::Biblioitems->find( { 'biblionumber' => $searched_sub_id } ); > >@@ -144,7 +146,12 @@ sub get_search_info { > return $sub_mana_info; > } > >+=head3 get_sharable_info >+ >+=cut >+ > sub get_sharable_info { >+ my $self = shift; > my $shared_sub_id = shift; > my $subscription = Koha::Subscriptions->find($shared_sub_id); > my $biblio = Koha::Biblios->find( $subscription->biblionumber ); >@@ -189,6 +196,11 @@ sub get_sharable_info { > return $sub_mana_info; > } > >+ >+=head3 _type >+ >+=cut >+ > sub _type { > return 'Subscription'; > } >diff --git a/Koha/Subscription/Numberpatterns.pm b/Koha/Subscription/Numberpatterns.pm >index 638e028..440489e 100644 >--- a/Koha/Subscription/Numberpatterns.pm >+++ b/Koha/Subscription/Numberpatterns.pm >@@ -32,7 +32,7 @@ Koha::SubscriptionNumberpatterns - Koha SubscriptionNumberpattern object set cla > > =cut > >-=head3 uniqeLabel >+=head3 uniqueLabel > > =cut > >@@ -52,6 +52,38 @@ sub uniqueLabel { > return $label; > } > >+=head3 new_or_existing >+ >+=cut >+ >+sub new_or_existing { >+ my ($self, $params) = @_; >+ >+ my $params_np; >+ if ( $params->{'numbering_pattern'} eq 'mana' ) { >+ foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1 >+ numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2 >+ label3 add3 every3 whenmorethan3 setto3 numbering3/) { >+ $params_np->{$_} = $params->{$_} if $params->{$_}; >+ } >+ >+ my $existing = Koha::Subscription::Numberpatterns->search($params_np)->next(); >+ >+ if ($existing) { >+ return $existing->id; >+ } >+ >+ $params_np->{label} = Koha::Subscription::Numberpatterns->uniqueLabel($params->{'patternname'}); >+ $params_np->{description} = $params->{'sndescription'}; >+ >+ >+ my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params_np)->store(); >+ return $subscription_np->id; >+ } >+ >+ return $params->{'numbering_pattern'}; >+} >+ > =head3 type > > =cut >diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in >index d2e3815..cc26a39 100644 >--- a/debian/templates/koha-conf-site.xml.in >+++ b/debian/templates/koha-conf-site.xml.in >@@ -285,6 +285,9 @@ __END_SRU_PUBLICSERVER__ > <logdir>__LOG_DIR__</logdir> > <docdir>/usr/share/doc/koha-common</docdir> > <backupdir>/var/spool/koha/__KOHASITE__</backupdir> >+ <!-- URL of the mana KB server --> >+ <!-- alternative value http://mana-test.koha-community.org to query the test server --> >+ <mana_config>https://mana-kb.koha-community.org</mana_config> > <!-- Enable the two following to allow superlibrarians to download > database and configuration dumps (respectively) from the Export > tool --> >diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml >index 452c7e0..b6c9d52 100644 >--- a/etc/koha-conf.xml >+++ b/etc/koha-conf.xml >@@ -153,6 +153,10 @@ __PAZPAR2_TOGGLE_XML_POST__ > <!-- Path to the config file for SMS::Send --> > <sms_send_config>__KOHA_CONF_DIR__/sms_send/</sms_send_config> > >+ <!-- URL of the mana KB server --> >+ <!-- alternative value http://mana-test.koha-community.org to query the test server --> >+ <mana_config>http://mana-kb.koha-community.org</mana_config> >+ > <!-- Configuration for Plack --> > <plack_max_requests>50</plack_max_requests> > <plack_workers>2</plack_workers> >diff --git a/installer/data/mysql/atomicupdate/mana_01-add_mana_id.perl b/installer/data/mysql/atomicupdate/mana_01-add_mana_id.perl >new file mode 100644 >index 0000000..1e5fdbd >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/mana_01-add_mana_id.perl >@@ -0,0 +1,13 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ if( !column_exists( 'subscription', 'mana_id' ) ) { >+ $dbh->do( "ALTER TABLE subscription ADD mana_id int(11) NULL DEFAULT NULL" ); >+ } >+ >+ if( !column_exists( 'saved_sql', 'mana_id' ) ) { >+ $dbh->do( "ALTER TABLE saved_sql ADD mana_id int(11) NULL DEFAULT NULL" ); >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 17047 - Add column mana_id in subscription and saved_sql tables)\n"; >+} >diff --git a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql b/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql >deleted file mode 100644 >index 5c590d1..0000000 >--- a/installer/data/mysql/atomicupdate/mana_01-add_mana_id_in_subscription.sql >+++ /dev/null >@@ -1 +0,0 @@ >-ALTER TABLE subscription ADD mana_id int(11); >diff --git a/installer/data/mysql/atomicupdate/mana_02-add_Mana_syspref.sql b/installer/data/mysql/atomicupdate/mana_02-add_Mana_syspref.sql >index 38d7ffb..dda85a5 100644 >--- a/installer/data/mysql/atomicupdate/mana_02-add_Mana_syspref.sql >+++ b/installer/data/mysql/atomicupdate/mana_02-add_Mana_syspref.sql >@@ -1 +1 @@ >-INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('Mana', '1', 'request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.', NULL, 'YesNo'); >+INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('Mana','2', 0|1|2,'request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','Choice'); >diff --git a/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql b/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql >new file mode 100644 >index 0000000..a8b3519 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/mana_03-add_mana_autoshare.sql >@@ -0,0 +1,2 @@ >+INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+('AutoShareWithMana','','','defines datas automatically shared with mana','multiple'); >diff --git a/installer/data/mysql/atomicupdate/mana_04-add_mana_token.sql b/installer/data/mysql/atomicupdate/mana_04-add_mana_token.sql >new file mode 100644 >index 0000000..3c94ccd >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/mana_04-add_mana_token.sql >@@ -0,0 +1,2 @@ >+INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+('ManaToken','',NULL,'Security token used for authentication on Mana KB service (anti spam)','Textarea'); >diff --git a/installer/data/mysql/atomicupdate/skeleton.perl b/installer/data/mysql/atomicupdate/skeleton.perl >index 66e599c..c63e6eb 100644 >--- a/installer/data/mysql/atomicupdate/skeleton.perl >+++ b/installer/data/mysql/atomicupdate/skeleton.perl >@@ -1,4 +1,4 @@ >-$DBversion = 'XXX'; # will be replaced by the RM >+$DBversion = 'XXX'; > if( CheckVersion( $DBversion ) ) { > # you can use $dbh here like: > # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 2575d5b..a3e1be5 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1462,6 +1462,7 @@ CREATE TABLE saved_sql ( -- saved sql reports > report_area varchar(6) default NULL, > report_group varchar(80) default NULL, > report_subgroup varchar(80) default NULL, >+ `mana_id` int(11) NULL DEFAULT NULL, > PRIMARY KEY (`id`), > KEY sql_area_group_idx (report_group, report_subgroup), > KEY boridx (`borrowernumber`) >@@ -2127,6 +2128,7 @@ CREATE TABLE `subscription` ( -- information related to the subscription > `reneweddate` date default NULL, -- date of last renewal for the subscription > `itemtype` VARCHAR( 10 ) NULL, > `previousitemtype` VARCHAR( 10 ) NULL, >+ `mana_id` int(11) NULL DEFAULT NULL, > PRIMARY KEY (`subscriptionid`), > KEY `by_biblionumber` (`biblionumber`), > CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 535223b..f94efd6 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -66,6 +66,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('AutoCreateAuthorities','0',NULL,'Automatically create authorities that do not exist when cataloging records.','YesNo'), > ('AutoEmailOpacUser','0',NULL,'Sends notification emails containing new account details to patrons - when account is created.','YesNo'), > ('AutoEmailPrimaryAddress','OFF','email|emailpro|B_email|cardnumber|OFF','Defines the default email address where \'Account Details\' emails are sent.','Choice'), >+('AutoShareWithMana','subscription','','defines datas automatically shared with mana','multiple'), > ('AutoLocation','0',NULL,'If ON, IP authentication is enabled, blocking access to the staff client from unauthorized IP addresses','YesNo'), > ('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'), > ('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'), >@@ -275,7 +276,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('LocalHoldsPriorityPatronControl', 'PickupLibrary', 'HomeLibrary|PickupLibrary', 'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.', 'Choice'), > ('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'), > ('Mana','1',NULL,'request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana.','YesNo'), >-('hide_marc','0',NULL,'If ON, disables display of MARC fields, subfield codes & indicators (still shows data)','YesNo'), > ('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'), > ('MARCAuthorityControlField008','|| aca||aabn | a|a d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'), > ('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. "MARC21" or "UNIMARC". {FIELD} = field number, eg. "000" or "048". {LANG} = user language, eg. "en" or "fi-FI"', 'free'), >diff --git a/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js b/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js >new file mode 100644 >index 0000000..0e9b2e2 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/lib/jquery/activatemana.js >@@ -0,0 +1,18 @@ >+$(document).ready(function(){ >+ $("#activatemana").on("click", function(){ >+ var mylastname = $("#lastname").val() >+ var myfirstname = $("#firstname").val() >+ var myemail = $("#email").val() >+ $.ajax( { >+ type: "POST", >+ url: "/cgi-bin/koha/svc/mana/token", >+ data: { lastname: mylastname, firstname: myfirstname, email: myemail}, >+ dataType: "json", >+ }) >+ .done(function(result){ >+ $("#pref_ManaToken").val(result.token); >+ $("#pref_ManaToken").trigger("input"); >+ }); >+ return false; >+ }); >+}); >diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >index ebe2ca7..2a70eff 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >+++ b/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss >@@ -717,6 +717,12 @@ ol { > background-color: #FFD000 !important; > } > >+.warned-row, >+.warned-row td { background-color: #FF9000 !important } >+ >+.high-warned-row, >+.high-warned-row td { background-color: #FF0000 !important } >+ > tbody { > tr { > &:nth-child(odd) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >index 1d06bca..9314a75 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >@@ -118,7 +118,7 @@ jQuery(function($){ > dayNamesMin: [_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa")], > weekHeader: _("Wk"), > dateFormat: "[% IF ( dateformat == "us" ) %]mm/dd/yy[% ELSIF ( dateformat == "metric" ) %]dd/mm/yy[% ELSIF ( dateformat == "dmydot" ) %]dd.mm.yy[% ELSE %]yy-mm-dd[% END %]", >- firstDay: [% Koha.Preference('CalendarFirstDayOfWeek') | html %], >+ firstDay: '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]', > isRTL: [% IF ( bidi ) %]true[% ELSE %]false[% END %], > showMonthAfterYear: false, > yearSuffix: ''}; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc >deleted file mode 100644 >index 4ce9b9b..0000000 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana-subscription-search-result.inc >+++ /dev/null >@@ -1,46 +0,0 @@ >-[% USE KohaDates %] >-<table id="mana_results_datatable"> >- <thead> >- <tr> >- <th>ISSN</th> >- <th class="anti-the">Title</th> >- <th>Frequency</th> >- <th>Numbering pattern</th> >- <th class="NoSort">Number of users</th> >- <th class="title-string">Last Import</th> >- [% UNLESS search_only %] >- <th class="NoSort">Actions</th> >- [% END %] >- </tr> >- </thead> >- <tfoot> >- <tr> >- <td><input type="text" class="dt-filter" data-column_num="0" placeholder="Search ISSN" /></td> >- <td><input type="text" class="dt-filter" data-column_num="1" placeholder="Search title" /></td> >- <td><input type="text" class="dt-filter" data-column_num="2" placeholder="Search frequency" /></td> >- <td><input type="text" class="dt-filter" data-column_num="3" placeholder="Search numbering pattern" /></td> >- <td></td> >- <td><input type="text" class="dt-filter" data-column_num="5" placeholder="Search last import" /></td> >- [% UNLESS search_only %] >- <td></td> >- [% END %] >- </tr> >- </tfoot> >- <tbody> >- [% FOREACH subscription IN subscriptions %] >- [% UNLESS subscription.cannotdisplay %] >- <tr id="row[% subscription.subscriptionid %]"> >- <td>[% IF ( subscription.issn ) %][% subscription.issn %][% END %]</td> >- <td>[% subscription.title %]</a></td> >- <td>[% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %]</td> >- <td>[% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %]</td> >- <td>[% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %]</td> >- <td><span title="[% subscription.lastimport %]">[% subscription.lastimport | $KohaDates %]</span></td> >- [% UNLESS search_only %] >- <td><a style="cursor:pointer" onclick="mana_use([% subscription.id %])"> <i class="fa fa-inbox"></i> Use</a></td> >- [% END %] >- </tr> >- [% END %] >- [% END %] >- </tbody> >-</table> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc >new file mode 100644 >index 0000000..04e4181 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc >@@ -0,0 +1,44 @@ >+<script type="text/JavaScript"> >+//<![CDATA[ >+$(document).ready(function() { >+ function mana_increment(mana_id, resource, fieldvalue, stepvalue = 1) { >+ $.ajax( { >+ type: "POST", >+ url: "/cgi-bin/koha/svc/mana/increment", >+ data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue}, >+ datatype: "json", >+ }) >+ } >+ >+ function mana_comment( target_id, manamsg, resource_type ) { >+ $.ajax( { >+ type: "POST", >+ url: "/cgi-bin/koha/svc/mana/share", >+ data: {message: manamsg, resource: resource_type , resource_id: target_id}, >+ datatype: "json", >+ }) >+ } >+ >+ $(document).on('click', 'ul li.mana-comment', function() { >+ id = $(this).attr('data-id'); >+ mana_increment(id, 'resource_comment', 'nb'); >+ }); >+ >+ $(document).on('click', 'ul li.mana-other-comment', function() { >+ $('#mana-comment-box').modal('show'); >+ }); >+ >+ $(document).on('click', '#mana-send-comment', function() { >+ var resource_type = $('#mana-resource').val(); >+ var resource_id = $('#mana-resource-id').val(); >+ var comment = $("#mana-comment").val(); >+ mana_comment(resource_id, comment, resource_type); >+ $("#mana-comment-box").modal("hide"); >+ }); >+ >+ $(document).on('click', '#mana-comment-close', function() { >+ $("#mana-comment-box").modal("hide"); >+ }); >+}); >+//]]> >+</script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc >new file mode 100644 >index 0000000..b95600c >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-report-search-result.inc >@@ -0,0 +1,81 @@ >+[% USE KohaDates %] >+[% USE Koha %] >+[% USE AuthorisedValues %] >+[% USE Branches %] >+ >+<script type="text/javascript"> >+//<![CDATA[ >+$(document).ready(function() { >+ $(document).on('click', 'button.mana-use', function() { >+ id = $(this).attr('id'); >+ mana_use(id.substr(9)); >+ }); >+ >+ $(document).on('change', 'select.mana-actions', function() { >+ report_id = $(this).attr('id').substr(13); >+ if ($(this).val() == 'other') { >+ $('input#selected_id').val(report_id); >+ $('#comment_box').modal('show'); >+ } else { >+ comment_id = $(this).val(); >+ mana_increment(comment_id, 'resource_comment', 'nb'); >+ } >+ }); >+}); >+//]]> >+</script> >+[% INCLUDE 'mana.inc' %] >+ >+[% IF statuscode == "200" AND reports %] >+ <table id="mana_results_datatable" width=100%> >+ <thead> >+ <tr> >+ <th>Report Name</th> >+ <th class="anti-the" width=35%>Notes</th> >+ <th>Type</th> >+ <th title="number of libraries using this pattern"># of users</th> >+ <th class="title-string" title="last time a library used this pattern">Last import</th> >+ <th> Comments </th> >+ [% UNLESS search_only %] >+ <th class="NoSort">Actions</th> >+ [% END %] >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH report IN reports %] >+ [% UNLESS report.cannotdisplay %] >+ [% IF report.nbofcomment > highWarned %] >+ <tr id="row[% report.id %]" class = "high-warned-row"> >+ [% ELSIF report.nbofcomment > warned %] >+ <tr id="row[% report.id %]" class = "warned-row"> >+ [% ELSIF report.nbofcomment > lowWarned %] >+ <tr id="row[% report.id %]" class = "highlighted-row"> >+ [% END %] >+ <input hidden class="rowid" value="[% report.id %]"> >+ <td>[% IF ( report.report_name ) %][% report.report_name %][% END %]</td> >+ <td title="[% report.savedsql |html %]"><div> >+ [% IF report.notes.length > 200 %] >+ [% report.notes.substr(0,200) %]<a class="showbutton">Show More</a></div><div hidden> >+ [% END %] >+ [% report.notes %] >+ [% IF report.notes.length > 200 %] >+ <a class="hidebutton">Show Less</a></div> </td> >+ [% END %] >+ <td> [% report.type %] </td> >+ <td>[% IF ( report.nbofusers ) %][% report.nbofusers %][% END %]</td> >+ <td><span title="[% report.lastimport %]">[% report.lastimport | $KohaDates %]</span></td> >+ <td>[% FOREACH comment IN report.comments %][% comment.message %] ([% comment.nb %]) <br>[% END %]</td> >+ >+ [% UNLESS search_only %] >+ <td> >+ <button class="mana-use" id="mana-use-[% report.id %]"><i class="fa fa-inbox"></i> Use</button> >+ </td> >+ [% END %] >+ </tr> >+ [% END %] >+ [% END %] >+ </tbody> >+ </table> >+[% ELSE %] >+ <h4> [% msg %] statuscode: [% statuscode %]</h4> >+[% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc >new file mode 100644 >index 0000000..34c3f42 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-subscription-search-result.inc >@@ -0,0 +1,92 @@ >+[% USE KohaDates %] >+[% USE Koha %] >+[% USE AuthorisedValues %] >+[% USE Branches %] >+[% INCLUDE 'mana.inc' %] >+<script type="text/javascript"> >+//<![CDATA[ >+$(document).ready(function() { >+ $(document).on('click', 'button.mana-use', function() { >+ id = $(this).attr('id'); >+ mana_use(id.substr(9)); >+ }); >+}); >+//]]> >+</script> >+ >+[% IF statuscode == "200" %] >+ <table id="mana_results_datatable" width=100%> >+ <thead> >+ <tr> >+ <th>ISSN</th> >+ <th class="anti-the" width=50%>Title</th> >+ <th> Published by </th> >+ <th>Frequency</th> >+ <th>Numbering pattern</th> >+ <th title="number of libraries using this pattern"># of users</th> >+ <th class="title-string" title="last time a library used this pattern">Last import</th> >+ <th> Comments </th> >+ [% UNLESS search_only %] >+ <th class="NoSort">Actions</th> >+ [% END %] >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH subscription IN subscriptions %] >+ [% UNLESS subscription.cannotdisplay %] >+ [% IF subscription.nbofcomment > highWarned %] >+ <tr id="row[% subscription.subscriptionid %]" class = "high-warned-row" title="this resource has been reported more than [% highWarned %] times, take care!"> >+ [% ELSIF subscription.nbofcomment > warned %] >+ <tr id="row[% subscription.subscriptionid %]" class = "warned-row" title="this resource has been reported more than [% warned %] times, take care!"> >+ [% ELSIF subscription.nbofcomment > lowWarned %] >+ <tr id="row[% subscription.subscriptionid %]" class = "highlighted-row" title="this resource has been reported more than [% lowWarned %] times, take care!"> >+ [% END %] >+ <input hidden class="rowid" value="[% subscription.id %]"> >+ <td>[% IF ( subscription.issn ) %][% subscription.issn %][% END %]</td> >+ <td>[% subscription.title %]</a></td> >+ <td>[% IF ( subscription.publishercode ) %][% subscription.publishercode %][% END %]</td> >+ <td>[% IF ( subscription.sfdescription ) %][% subscription.sfdescription %][% END %]</td> >+ <td>[% IF ( subscription.numberingmethod ) %][% subscription.numberingmethod %][% END %]</td> >+ <td>[% IF ( subscription.nbofusers ) %][% subscription.nbofusers %][% END %]</td> >+ <td><span title="[% subscription.lastimport %]">[% subscription.lastimport | $KohaDates %]</span></td> >+ <td>[% FOREACH comment IN subscription.comments %][% comment.message %] ([% comment.nb %]) <br>[% END %]</td> >+ >+ [% UNLESS search_only %] >+ <td> >+ <button class="mana-use" id="mana-use-[% subscription.id %]"><i class="fa fa-inbox"></i> Use</button> >+ <select class="mana-actions" id="mana-actions-[% subscription.id %]"> >+ <option selected disabled>Report mistake</option> >+ [% FOREACH comment IN subscription.comments %] >+ <option value="[% comment.id %]"> [% comment.message %] ([% comment.nb %])</option> >+ [% END %] >+ <option>other</option> >+ </select> >+ <button hidden class="actionreport2" hidden> Cancel</button> >+ </td> >+ [% END %] >+ </tr> >+ [% END %] >+ [% END %] >+ </tbody> >+ </table> >+[% ELSE %] >+ <h4>Mana search fails with the code: [% statuscode %] </h4> >+[% END %] >+ >+<div id="comment_box" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="display: none;"> >+ <div class="modal-dialog modal-lg" style="width: 30%"> >+ <div class="modal-content" style=""> >+ <div class="modal-header"> >+ <button type="button" id="commentCloseButton" class="closebtn" aria-hidden="true">Ã</button> >+ <h3 id="mana_submit_comment"> Please enter a new commment (max 35 caracters)</h3> >+ </div> >+ <div class="modal-body"> >+ <form> >+ <input hidden id="selected_id" value=""> >+ <input type="text" id="manamsg"> Comment: >+ </form> >+ <button id="CommentButton"> Comment </button> >+ </div> >+ </div> >+ </div> >+</div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >index 83ad6af..9a2c4bb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >@@ -6,6 +6,9 @@ > <ul class="dropdown-menu"> > <li id="newmenuc"><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Build%20new">New guided report</a> </li> > <li id="newsql"><a href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create%20report%20from%20SQL">New SQL report</a> </li> >+ [% IF Koha.Preference('Mana')==1 %] >+ <li id="newsql"><a href="" data-toggle="modal" data-target="#mana_search_result">New SQL from Mana</a> </li> >+ [% END %] > </ul> > </div> > [% END %] >@@ -47,6 +50,40 @@ > </div> > [% END %] > >+ [% IF ( mana_id && Koha.Preference('Mana') == 1 ) %] >+ <div class="btn-group"> >+ <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"> Report mistake <span class="caret"></span></button> >+ <ul class="dropdown-menu"> >+ [% FOREACH c IN mana_comments %] >+ <li class="mana-comment" data-id="[% c.id %]"> >+ <a href="#">[% c.message %] ([% c.nb %])</a> >+ </li> >+ [% END %] >+ <li role="separator" class="divider"></li> >+ <li class="mana-other-comment"><a href="#">Other</a> </li> >+ </ul> >+ </div> >+ >+ <div id="mana-comment-box" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="display: none;"> >+ <div class="modal-dialog modal-lg" style="width: 30%"> >+ <div class="modal-content" style=""> >+ <div class="modal-header"> >+ <button type="button" id="mana-comment-close" class="closebtn" aria-hidden="true">Ã</button> >+ <h3 id="mana_submit_comment"> Please enter a new commment (max 35 caracters)</h3> >+ </div> >+ <div class="modal-body"> >+ <input hidden id="mana-resource" value="report"> >+ <input hidden id="mana-resource-id" value="[% mana_id %]"> >+ <div> >+ <input type="text" maxlength="35" size="35" id="mana-comment"> >+ </div> >+ <button id="mana-send-comment"> Comment </button> >+ </div> >+ </div> >+ </div> >+ </div> >+ [% END %] >+ > [% IF ( execute ) %] > [% BLOCK params %] > [%- FOREACH param IN sql_params %]&sql_params=[% param | uri %][% END %] >@@ -77,3 +114,104 @@ > > [% END %] > </div> >+ >+[% IF Koha.Preference('Mana')==1 %] >+ <div id="mana_search_result" class="modal fade container-fluid" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="width: 100%; left:0%; margin-left: auto; display: none;"> >+ <div class="modal-dialog modal-lg"> >+ <div class="modal-content"> >+ <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">Ã</button> >+ <h3 id="mana_search_result_label"> Mana Search</h3> >+ </div> >+ <div> >+ <form id="search_form" style="margin-left: 5%"> >+ Please enter a few key words: >+ <input type=text id=mana_search_field> >+ <input type=button class="mana_search_button" value="Search"> >+ </form> >+ <div class="modal-body"> >+ </div> >+ </div> >+ </div> >+ </div> >+ </div> >+[% END %] >+ >+<script type="text/javascript"> >+ function mana_use( mana_id ){ >+ $.ajax( { >+ type:"POST", >+ url: "/cgi-bin/koha/svc/mana/use", >+ data: {id:mana_id, resource: 'report', saveinbase: 1}, >+ dataType: "json", >+ }) >+ .done( function (result){ >+ if ( result.errmsg ){ >+ alert( result.errmsg ); >+ } >+ else{ >+ window.location = ("/cgi-bin/koha/reports/guided_reports.pl?reports=").concat(result.id).concat("&phase=Show%20SQL&mana_success=1&phase=Edit%20SQL"); >+ } >+ }) >+ .fail( function ( foo, msg, longmsg, bla ){ >+ }); >+ } >+ >+ function mana_search( textquery ){ >+ $.ajax({ >+ type: "POST", >+ url: "/cgi-bin/koha/svc/mana/search", >+ data: {biblionumber: $("#biblionumber").val(), resource: 'report', id: textquery, usecomments: 1}, >+ dataType: "html", >+ }) >+ .done( function( result ) { >+ $("#mana_search_result .modal-body").html(result); >+ $("#mana_search_result_label").text(_("Results from Mana Knowledge Base")); >+ $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults,{ >+ "sPaginationType":"four_button", >+ "autoWidth": false, >+ "columnDefs": [ >+ { "width": "35%", "targets": 1 } >+ ], >+ "aoColumnDefs": [ >+ { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, >+ { "sType": "title-string", "aTargets" : [ "title-string" ] }, >+ { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } >+ ] >+ })); >+ if($("td.dataTables_empty").length == 0){ >+ $("#mana_search").show(); >+ } >+ >+ $( "select[class='actionreport1']" ).show(); >+ $( "button[class='actionreport2']" ).hide(); >+ >+ $(".showbutton").on("click", function(){ >+ $(this).parent().hide(); >+ $(this).parent().next().show(); >+ }); >+ >+ $("a[class='hidebutton']").on("click", function(){ >+ $(this).parent().hide(); >+ $(this).parent().prev().show(); >+ }); >+ >+ $("#commentCloseButton").on("click", function(){ >+ $("#comment_box").modal("hide"); >+ }); >+ >+ $(".actionreport1").on("click", function(){ >+ $("#selectedcomment").val($(this).val()); >+ $(this).parent("select").hide(); >+ $(this).parent("select").next().show(); >+ }); >+ >+ $(".actionreport2").on("click", function(){ >+ $(this).hide(); >+ $(this).prev().show(); >+ mana_increment($("#selectedcomment").val(), 'resource_comment', 'nb', -1); >+ }); >+ }).fail( function( result ){ >+ }); >+ } >+</script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc >index 484a988..4bba329 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc >@@ -7,11 +7,11 @@ > [% ELSE %] > <div class="btn-group"><a id="newsubscription" class="btn btn-default btn-sm" href="/cgi-bin/koha/serials/subscription-add.pl"><i class="fa fa-plus"></i> New subscription</a></div> > [% END %] >- [% IF Koha.Preference('Mana') %] >+ [% IF Koha.Preference('Mana') and Koha.Preference('AutoShareWithMana').grep('subscription').size == 0 %] > [% IF one_language_enabled==0 or mana_id %] >- <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-small"><i class="fa fa-share-alt"></i> Share</a></div> >+ <div class="btn-group"><a data-toggle="modal" data-toggle="tooltip" title="Share the subscription with other librairies. Your email address will be associated to your sharing." data-target="#mana_share_modal" class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div> > [% ELSE %] >- <div class="btn-group" data-toggle="tooltip" title="Your email address will be associated to your sharing."><a class="btn btn-small" onclick="share()"><i class="fa fa-share-alt"></i> Share</a></div> >+ <div class="btn-group" id="mana-subscription-share" data-toggle="tooltip" title="Share the subscription with other libraries. Your email address will be associated to your sharing."><a class="btn btn-default btn-sm"><i class="fa fa-share-alt"></i> Share</a></div> > [% END %] > [% END %] > [% END %] >@@ -60,6 +60,40 @@ > [% END %] > [% END %] > [% END %] >+ >+ [% IF ( mana_id && Koha.Preference('Mana') == 1 ) %] >+ <div class="btn-group"> >+ <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"> Report mistake <span class="caret"></span></button> >+ <ul class="dropdown-menu"> >+ [% FOREACH c IN mana_comments %] >+ <li class="mana-comment" data-id="[% c.id %]"> >+ <a href="#">[% c.message %] ([% c.nb %])</a> >+ </li> >+ [% END %] >+ <li role="separator" class="divider"></li> >+ <li class="mana-other-comment"><a href="#">Other</a> </li> >+ </ul> >+ </div> >+ >+ <div id="mana-comment-box" class="modal" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="display: none;"> >+ <div class="modal-dialog modal-lg" style="width: 30%"> >+ <div class="modal-content" style=""> >+ <div class="modal-header"> >+ <button type="button" id="mana-comment-close" class="closebtn" aria-hidden="true">Ã</button> >+ <h3 id="mana_submit_comment"> Please enter a new commment (max 35 caracters)</h3> >+ </div> >+ <div class="modal-body"> >+ <input hidden id="mana-resource" value="subscription"> >+ <input hidden id="mana-resource-id" value="[% mana_id %]"> >+ <div> >+ <input type="text" maxlength="35" size="35" id="mana-comment"> >+ </div> >+ <button id="mana-send-comment"> Comment </button> >+ </div> >+ </div> >+ </div> >+ </div> >+ [% END %] > </div> > [% ELSIF CAN_user_serials_create_subscription %] > <div id="toolbar" class="btn-toolbar"> >@@ -80,18 +114,17 @@ > <div class="modal-body"> > [% IF (mana_id) %] > <div class="alert"> >- <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwide it will do nothing.</p> >+<h1>[% (mana_id) %]</h1> >+ <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwise it will do nothing.</p> > </div> > [% END %] > [% IF ( languages_loop ) %] > [% UNLESS ( one_language_enabled ) %] > <div class="rows"> >- <p>The frequency and the numberpattern of [% bibliotitle %] are :</p> >- <ol> >- <li><span class="label">Frequency : </span> >+ <li><span class="label">Frequency: </span> > [% frequency.description %] > </li> >- <li><span class="label">Number pattern : </span> >+ <li><span class="label">Number pattern: </span> > [% numberpattern.label %] > </li> > </ol> >@@ -99,7 +132,7 @@ > <div class="rows"> > <form method="get" id="mana_share_form" action="/cgi-bin/koha/serials/subscription-detail.pl" class="validated" > > <fieldset> >- <label for="mana_language">Language of your sharing :</label> >+ <label for="mana_language">Language:</label> > <select id="mana_language" name="mana_language"> > [% FOREACH languages_loo IN languages_loop %] > [% IF ( languages_loo.group_enabled ) %] >@@ -162,7 +195,7 @@ > [% IF one_language_enabled==0 %] > <button type="submit" form="mana_share_form" class="btn btn-primary">Share</button> > [% ELSE %] >- <div class="btn-group"><a class="btn btn-primary" onclick="share()">Share</a></div> >+ <div class="btn-group" id="mana-subscription-share"><a class="btn btn-primary">Share</a></div> > [% END %] > </div> > </div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >index 8d935ca..e1e7767 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >@@ -13,7 +13,12 @@ > <div class="main container-fluid"> > <div class="row"> > <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2"> >- >+ [% IF ( Koha.Preference('Mana') == 2) %] >+ <fieldset> >+ <p><center> You haven't decided if you want to activate Mana Knowlede Base, please let us know by clicking<center></p> >+ <a href=/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=request+to+mana+webservice><center>Here</center></a> >+ </fieldset> >+ [% END %] > <h1>Koha administration</h1> > <div class="row"> > <div class="col-md-6 sysprefs"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >index 6cc0570..d9d705c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences.tt >@@ -197,6 +197,7 @@ > [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %] > [% Asset.js("js/ajax.js") | $raw %] > [% Asset.js("js/pages/preferences.js") | $raw %] >+ [% Asset.js("lib/jquery/activatemana.js") | $raw %] > [%# Add WYSIWYG editor for htmlarea system preferences %] > [% INCLUDE 'wysiwyg-systempreferences.inc' %] > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref >index 5d133c6..fe4a942 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref >@@ -63,9 +63,20 @@ Web services: > - > - pref: Mana > choices: >- yes: Enable >- no: Disable >- - request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana. >+ 0: Disable >+ 1: Enable >+ 2: No, let me think about it >+ - request to Mana Webservice. Mana centralize commun information between other Koha to facilitate the creation of new subscriptions, vendors, report queries etc... You can search, share, import and comment the content of Mana. The informations shared with Mana KB are shared under the CC-0 license. More infos about CC-0 license on https://creativecommons.org/choose/zero/ >+ - >+ - "Security token used to authenticate on mana:" >+ - pref: ManaToken >+ class: Text >+ - <br> You need a security token to authenticate on Mana. If this sytem preference is empty, please fill in the following form, you will receive an email to confirm and activate your token. <br> <form> First name <input name="firstname" type="text" id="firstname"> <br> Last name <input name="lastname" type=text id=lastname> <br> Email address <input name="email" type=text id=email><br> <input type=submit id=activatemana value="Send"></form> >+ - >+ - 'Fields automatically shared with mana' >+ - pref: AutoShareWithMana >+ multiple: >+ subscription: Subscriptions > Reporting: > - > - Only return >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt >new file mode 100644 >index 0000000..a2a9298 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-report-search-result.tt >@@ -0,0 +1 @@ >+[% INCLUDE 'mana/mana-report-search-result.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-subscription-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-subscription-search-result.tt >new file mode 100644 >index 0000000..0c44f7a >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/mana/mana-subscription-search-result.tt >@@ -0,0 +1 @@ >+[% INCLUDE 'mana/mana-subscription-search-result.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >index 18410c2..17d3ccb 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt >@@ -135,6 +135,13 @@ canned reports and writing custom SQL reports.</p> > </div> > [% END %] > >+[% IF report_converted %] >+ <div class="dialog message"> >+ The report "[% report_converted %]" has been converted. >+ </div> >+[% END %] >+ >+ > [% IF ( saved1 ) %] > [% IF ( savedreports ) %]<h1>Saved reports</h1> > >@@ -169,6 +176,15 @@ canned reports and writing custom SQL reports.</p> > <option value="">All</option> > </select> > </div> >+<div style="display:inline-block"> >+ [% IF manamsg %] >+ <div id="mana_search" class="dialog message"> >+ <p> [% manamsg %] </p> >+ </div> >+ [% END %] >+ >+</script> >+ > <form action="/cgi-bin/koha/reports/guided_reports.pl" id="reports_form" method="post"> > <input type="hidden" name="phase" value="Delete Multiple" /> > <table id="table_reports"> >@@ -204,23 +220,24 @@ canned reports and writing custom SQL reports.</p> > <tbody> > [% FOREACH savedreport IN savedreports %] > [% UNLESS ( loop.odd ) %]<tr class="odd">[% ELSE %]<tr>[% END %] >- <td> >+ <td class="report_checkbox"> > [% IF ( CAN_user_reports_delete_reports ) %] <!-- not break CSS --> > <input type="checkbox" name="ids" value="[% savedreport.id | html %]" /> > [% END %] >+ <input hidden class="report_sql" value="[% savedreport.savedsql |html %]"> > </td> >- <td><label for="ids">[% savedreport.id | html %]</label></td> >- <td> >+ <td class="report_id"><label for="ids">[% savedreport.id | html %]</label></td> >+ <td class="report_name"> > [% IF ( savedreport.report_name ) %] > [% savedreport.report_name | html %] > [% ELSE %] > [ no name ] > [% END %] > </td> >- <td>[% savedreport.type | html %]</td> >- <td>[% savedreport.groupname | html %]</td> >+ <td class="report_type">[% savedreport.type | html %]</td> >+ <td class="report_group">[% savedreport.groupname | html %]</td> > <td>[% savedreport.subgroupname | html %]</td> >- <td>[% savedreport.notes | html %]</td> >+ <td class="report_notes">[% savedreport.notes | html %]</td> > <td>[% savedreport.borrowersurname | html %][% IF ( savedreport.borrowerfirstname ) %], [% savedreport.borrowerfirstname | html %][% END %] ([% savedreport.borrowernumber | html %])</td> > <td><span title="[% savedreport.date_created | html %]">[% savedreport.date_created | $KohaDates %]</span></td> > <td><span title="[% savedreport.last_modified | html %]">[% savedreport.last_modified | $KohaDates with_hours => 1 %]</span></td> >@@ -267,6 +284,9 @@ canned reports and writing custom SQL reports.</p> > <li><a href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | uri %]&phase=Edit%20SQL"><i class="fa fa-pencil"></i> Edit</a></li> > <li><a title="Duplicate this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?phase=Create report from SQL&sql=[% savedreport.savedsql |uri %]&reportname=[% savedreport.report_name |uri %]&notes=[% savedreport.notes |uri %]"><i class="fa fa-copy"></i> Duplicate</a></li> > [% END %] >+ [% IF (Koha.Preference('Mana') == 1) %] >+ <li><a class="ShareButton" data-toggle="modal" href="#mana_share_report" title="Share your report with Mana Knowledge Base"><i class="fa fa-share-alt"></i> Share</a></li> >+ [% END %] > <li><a href="/cgi-bin/koha/tools/scheduler.pl?id=[% savedreport.id | uri %]"><i class="fa fa-clock-o"></i> Schedule</a></li> > [% IF ( CAN_user_reports_delete_reports ) %] > <li><a class="confirmdelete" title="Delete this saved report" href="/cgi-bin/koha/reports/guided_reports.pl?reports=[% savedreport.id | html %]&phase=Delete%20Saved"><i class="fa fa-trash"></i> Delete</a></li> >@@ -279,6 +299,7 @@ canned reports and writing custom SQL reports.</p> > [% END %] > </tbody> > </table> >+</div> > [% IF ( CAN_user_reports_delete_reports ) %] > <fieldset class="action"> > <input type="submit" value="Delete selected" /> >@@ -319,6 +340,113 @@ canned reports and writing custom SQL reports.</p> > [% END %] > [% END %] > >+<div id="mana_share_report" class="modal fade" tabindex="-1" role="dialog" arialabelledby="mana_share_modal_label" style="display: none;"> >+ <div class="modal-dialog"> >+ <div class="modal-content"> >+ <div class="modal-header"> >+ <h3 id="mana_share_modal_label">Share with Mana</h3> >+ </div> >+ <div class="modal-body"> >+ [% IF (mana_id) %] >+ <div class="alert"> >+ <p>Your subscription is already linked with a Mana subscription model. Share it if you have made modifications, otherwise it will do nothing.</p> >+ </div> >+ [% END %] >+ <div id="note-error" class="alert alert-danger" role="alert"> >+ Please enter a report name and descriptive note before sharing (minimum 20 characters) >+ </div> >+ [% IF ( languages_loop ) %] >+ [% UNLESS ( one_language_enabled ) %] >+ <div class="shared_infos rows"> >+ <li> <span class="label">Id: </span><div id="shared_id"></div> >+ </li> >+ <li> <span class="label">Name: </span><div id="shared_name"></div> >+ </li> >+ <li> <span class="label">SQL: </span><div id="shared_sql"></div> >+ </li> >+ <li> <span class="label">Group: </span><div id="shared_group"></div> >+ </li> >+ <li> <span class="label">Type: </span><div id="shared_type"></div> >+ </li> >+ <li> <span class="label">Notes: </span><div id="shared_notes"></div> >+ </li> >+ >+ </div> >+ <div class="rows"> >+ <form method="post" id="mana_share_form" action="/cgi-bin/koha/reports/guided_reports.pl?phase=Share" class="validated" > >+ <input type="hidden" name="phase" value="Share"> >+ >+ <fieldset class="shared_infos"> >+ <label for="mana_language">Language:</label> >+ <select id="mana_language" name="mana_language"> >+ [% FOREACH languages_loo IN languages_loop %] >+ [% IF ( languages_loo.group_enabled ) %] >+ [% IF ( languages_loo.plural ) %] >+ [% FOREACH sublanguages_loo IN languages_loo.sublanguages_loop %] >+ [% IF ( sublanguages_loo.enabled ) %] >+ [% IF ( sublanguages_loo.sublanguage_current ) %] >+ <option value="[% languages_loo.rfc4646_subtag %]" selected> >+ [% sublanguages_loo.native_description %] >+ [% sublanguages_loo.script_description %] >+ [% sublanguages_loo.region_description %] >+ >+ [% sublanguages_loo.variant_description %] >+ ([% sublanguages_loo.rfc4646_subtag %]) >+ </option> >+ [% ELSE %] >+ <option value="[% languages_loo.rfc4646_subtag %]"> >+ [% sublanguages_loo.native_description %] >+ [% sublanguages_loo.script_description %] >+ [% sublanguages_loo.region_description %] >+ [% sublanguages_loo.variant_description %] >+ ([% sublanguages_loo.rfc4646_subtag %]) >+ </option> >+ [% END %] >+ [% END %] >+ [% END %] >+ [% ELSE %] >+ [% IF ( languages_loo.group_enabled ) %] >+ [% IF ( languages_loo.current ) %] >+ <option value="[% languages_loo.rfc4646_subtag %]" selected> >+ [% IF ( languages_loo.native_description ) %] >+ [% languages_loo.native_description %] >+ [% ELSE %] >+ [% languages_loo.rfc4646_subtag %] >+ [% END %] >+ </option> >+ [% ELSE %] >+ <option value="[% languages_loo.rfc4646_subtag %]"> >+ [% IF ( languages_loo.native_description ) %] >+ [% languages_loo.native_description %] >+ [% ELSE %] >+ [% languages_loo.rfc4646_subtag %] >+ [% END %] >+ </option> >+ [% END %] >+ [% END %] >+ [% END %] >+ [% END %] >+ [% END %] >+ </select> >+ <input type="hidden" id="reportid" name="reportid" value="[% savedreport.id %]"/> >+ </fieldset> >+ </form> >+ </div> >+ [% END %] >+ [% END %] >+ </div> >+ <div class="modal-footer"> >+ <button class="btn" id="ManaCloseButton" data-dismiss="modal" aria-hidden="true">Close</button> >+ [% IF one_language_enabled==0 %] >+ <button id="ManaShareButton" type="submit" form="mana_share_form" class="btn btn-primary shared_infos">Share</button> >+ [% ELSE %] >+ <div id="ManaShareButton" class="btn-group"><a class="btn btn-primary shared_infos">Share</a></div> >+ [% END %] >+ </div> >+ </div> >+ </div> >+</div> >+ > > [% IF ( build1 ) %] > [% IF ( cache_error) %] >@@ -944,6 +1072,7 @@ canned reports and writing custom SQL reports.</p> > [% Asset.js("lib/d3c3/d3.min.js") | $raw %] > [% Asset.js("lib/d3c3/c3.min.js") | $raw %] > [% INCLUDE 'calendar.inc' %] >+ [% INCLUDE 'mana.inc' %] > [% IF ( saved1 ) %] > [% INCLUDE 'datatables.inc' %] > [% INCLUDE 'columns_settings.inc' %] >@@ -1151,6 +1280,30 @@ canned reports and writing custom SQL reports.</p> > window.history.back(); > }); > >+ $(".mana_search_button").on("click",function(){ >+ mana_search($("#mana_search_field").val()); >+ }); >+ >+ $(".ShareButton").on("click", function(){ >+ $("#note-error").hide(); >+ if($(this).closest("tr").find(".report_notes").text().length < 20 || $(this).closest("tr").find(".report_name").text().length < 20){ >+ $(".shared_infos").hide(); >+ $("#note-error").show(); >+ } >+ else{ >+ $("#shared_id").html($(this).closest("tr").find(".report_id").text()); >+ $("#shared_name").html($(this).closest("tr").find(".report_name").text()); >+ $("#shared_sql").html($(this).closest("tr").find(".report_sql").val()); >+ $("#shared_type").html($(this).closest("tr").find(".report_type").text()); >+ $("#shared_group").html($(this).closest("tr").find(".report_group").text()); >+ $("#shared_notes").html($(this).closest("tr").find(".report_notes").text()); >+ } >+ }); >+ >+ $("#ManaCloseButton").on("click", function() { >+ $(".shared_infos").show(); >+ }); >+ > $("#addColumn").on("click",function(){ > addColumn(); > }); >@@ -1341,7 +1494,12 @@ canned reports and writing custom SQL reports.</p> > $(".delete").on("click",function(){ > return confirmDelete(MSG_CONFIRM_DELETE); > }); >+ >+ $('div#ManaShareButton').click(function() { >+ window.location="/cgi-bin/koha/reports/guided_reports.pl?phase=Share"; >+ }); > }); >+ > function addColumn() { > $("#availableColumns option:selected").clone().appendTo("#selectedColumns").attr("selected", "selected"); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt >deleted file mode 100644 >index 0afe02c..0000000 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/mana-subscription-search-result.tt >+++ /dev/null >@@ -1 +0,0 @@ >-[% INCLUDE 'mana-subscription-search-result.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >index 1886094..adc7428 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt >@@ -297,7 +297,7 @@ > </ul> > [% IF mana %] > <div id="mana"> >- [% INCLUDE 'mana-subscription-search-result.inc' %] >+ [% INCLUDE 'mana/mana-subscription-search-result.inc' %] > </div> > [% ELSE %] > <div id="opened"> >@@ -421,6 +421,7 @@ > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'calendar.inc' %] > [% INCLUDE 'datatables.inc' %] >+ [% INCLUDE 'mana.inc' %] > <script> > var subscriptionid = "[% subscriptionid | html %]"; > var MSG_CLOSE_SUBSCRIPTION = _("Are you sure you want to close this subscription?"); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >index 3b3a32c..a7bb471 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt >@@ -10,7 +10,7 @@ > <style type="text/css"> > fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ > .yui-u li p label.widelabel { >- width: 300px; /* not enough for IE7 apparently */ >+width: 300px; /* not enough for IE7 apparently */ > } > </style> > </head> >@@ -214,8 +214,15 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ > > <div id="page_2"> > <div class="col-md-6"> >- <div id="mana_search" class="dialog message"> >- <p>Frequency and Numbering pattern have been already proposed for this subscription on Mana. To show results, click <a style="cursor:pointer" data-toggle="modal" data-target="#mana_search_result">Here</a></p> >+ [% IF ( Koha.Preference('Mana') == 2) %] >+ <fieldset> >+ <p><center>You haven't activated the Mana Knowledge Base, click >+ <a href=/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=request+to+mana+webservice>here</a> >+ to configure.</center></p> >+ </fieldset> >+ [% END %] >+ >+ <div hidden id="mana_search" class="dialog message"> > </div> > <div id="subscription_form_planning"> > <fieldset class="rows"> >@@ -490,7 +497,7 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ > <fieldset class="action"> > <input type="button" id="subscription_add_previous" value="<< Previous" style="float:left;"/> > <input id="testpatternbutton" type="button" value="Test prediction pattern" /> >- <input type="submit" onclick="removeDisabledAttr()" value="Save subscription" style="float:right;" accesskey="w"/> >+ <input id="save-subscription" type="submit" value="Save subscription" style="float:right;" accesskey="w"/> > </fieldset> > </div> > </div> >@@ -500,23 +507,20 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ > </div> > </form> > </div> >- <div id="mana_search_result" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="width: 90%; left:5%; margin-left: auto; display: none;"> >+ <div id="mana_search_result" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mana_search_result_label" style="width: 100%; left:0%; margin-left: auto; display: none;"> > <div class="modal-dialog modal-lg"> > <div class="modal-content"> > <div class="modal-header"> >+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">Ã</button> > <h3 id="mana_search_result_label"></h3> > </div> > <div class="modal-body"> >- </div> >- <div class="modal-footer"> >- <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> >- </div> >- </div> > </div> > </div> > > [% MACRO jsinclude BLOCK %] > [% INCLUDE 'calendar.inc' %] >+ [% INCLUDE 'datatables.inc' %] > <script type="text/javascript"> > var subscriptionid = "[% subscriptionid | html %]"; > var irregularity = "[% irregularity | html %]"; >@@ -525,6 +529,7 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ > [% FOREACH field IN dont_export_field_loop %] > tags.push("[% field.fieldid | html %]"); > [% END %] >+ var mana_enabled = [% Koha.Preference('Mana') %] > var MSG_LINK_TO_VENDOR = _("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"); > var MSG_LINK_BIBLIO = _("You must choose or create a bibliographic record"); > var MSG_REQUIRED_SUB_LENGTH = _("You must choose a subscription length or an end date."); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >index fd50f2f..141b63a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt >@@ -29,7 +29,7 @@ > <div class="col-sm-10 col-sm-push-2"> > <main> > >- [% INCLUDE 'serials-toolbar.inc' mana_id = mana_id %] >+ [% INCLUDE 'serials-toolbar.inc' %] > > <h1>Subscription for [% bibliotitle | html %] [% IF closed %](closed)[% END %]</h1> > [% IF ( abouttoexpire ) %] >@@ -62,11 +62,7 @@ > [% IF mana_code.defined %] > <div id="alert-community" class="dialog message"> > <p> >- [% IF (mana_code == 201) %] >- The export is done, thank you for your contribution. >- [% ELSIF (mana_code == 200) %] >- The model already exists on Mana, thank you for your contribution. >- [% END %] >+ [% mana_code %] > </p> > </div> > [% END %] >@@ -480,6 +476,7 @@ > var MSG_REOPEN_SUBSCRIPTION = _("Are you sure you want to reopen this subscription?"); > var CONFIRM_DELETE_SUBSCRIPTION = _("Are you sure you want to delete this subscription?"); > </script> >+ [% INCLUDE 'mana.inc' %] > [% Asset.js("js/serials-toolbar.js") | $raw %] > [% INCLUDE 'datatables.inc' %] > [% Asset.js("lib/jquery/plugins/treetable/jquery.treetable.js") | $raw %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/serials-toolbar.js b/koha-tmpl/intranet-tmpl/prog/js/serials-toolbar.js >index 1f181c2..9a3a5f1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/serials-toolbar.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/serials-toolbar.js >@@ -40,4 +40,7 @@ function popup(subscriptionid) { > popup( subscriptionid ); > return false; > }); >+ $("#mana-subscription-share").click(function() { >+ window.location="subscription-detail.pl?subscriptionid=" + subscriptionid + "&op=share"; >+ }); > }); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >index df26753..da8abd1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js >@@ -393,28 +393,42 @@ function show_page_2() { > } > > function mana_search() { >+ $("#mana_search").html("<p>" + _("Mana kb is being asked for your subscription..") + "</p>"); >+ $("#mana_search").show(); >+ > $.ajax({ > type: "POST", > url: "/cgi-bin/koha/svc/mana/search", >- data: {biblionumber : $("#biblionumber").val()}, >+ data: {id: $("#biblionumber").val(), resource: 'subscription', usecomments: 1}, > dataType: "html", > }) > .done( function( result ) { >- $("#mana_search_result .modal-body").html(result); >- $("#mana_search_result_label").text("Results from Mana"); >+ $("#mana_search_result .modal-body").html(result); >+ $("#mana_search_result_label").text(_("Results from Mana Knowledge Base")); > $("#mana_results_datatable").dataTable($.extend(true, {}, dataTablesDefaults, { > "sPaginationType": "four_button", >+ "order":[[4, "desc"], [5, "desc"]], >+ "autoWidth": false, >+ "columnDefs": [ >+ { "width": "35%", "targets": 1 } >+ ], > "aoColumnDefs": [ > { 'bSortable': false, "bSearchable": false, 'aTargets': [ 'NoSort' ] }, > { "sType": "title-string", "aTargets" : [ "title-string" ] }, > { 'sType': "anti-the", 'aTargets' : [ 'anti-the'] } > ] > })); >- if($("td.dataTables_empty").length == 0){ >- $("#mana_search").show(); >+ if( $("#mana_results_datatable").length && $("td.dataTables_empty").length == 0){ >+ $("#mana_search").html("<p>" + _("Subscription found on Mana Knowledge Base:") + "</p><p> <a style='cursor:pointer' data-toggle='modal' data-target='#mana_search_result'>" + _("Quick fill") + "</a></p>"); > } >- }).fail(function(result){ >- }); >+ else if ( $("#mana_results_datatable").length ){ >+ $("#mana_search").html("<p>" + _("No subscription found on Mana Knowledge Base :(") + "</p><p>" + _(" Please feel free to share you pattern with all others librarians once you are done") + "</p>"); >+ } >+ else{ >+ $("#mana_search").html( result ); >+ } >+ $("#mana_search").show(); >+ }) > } > > function mana_use(mana_id){ >@@ -423,7 +437,7 @@ function mana_use(mana_id){ > $.ajax( { > type: "POST", > url: "/cgi-bin/koha/svc/mana/use", >- data: {id : mana_id}, >+ data: {id: mana_id, resource: 'subscription'}, > dataType: "json", > }) > .done(function(result){ >@@ -492,11 +506,8 @@ function mana_use(mana_id){ > }); > } > >-function removeDisabledAttr() { >- $('select:disabled').removeAttr('disabled'); >-} >- > $(document).ready(function() { >+ mana_search(); > $("#displayexample").hide(); > $("#mana_search_result").modal("hide"); > $("#aqbooksellerid").on('keypress', function(e) { >@@ -606,9 +617,9 @@ $(document).ready(function() { > }); > $("#subscription_add_next").on("click",function(){ > if ( Check_page1() ){ >- [% IF Koha.Preference('Mana') %] >+ if ( mana_enabled ) { > mana_search(); >- [% END %] >+ } > show_page_2(); > } > }); >@@ -636,4 +647,7 @@ $(document).ready(function() { > e.preventDefault(); > testPredictionPattern(); > }); >-}); >\ No newline at end of file >+ $('#save-subscription').on("click", function(e){ >+ $('select:disabled').removeAttr('disabled'); >+ }); >+}); >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index 24dd108..511d939 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -38,6 +38,7 @@ use Koha::AuthorisedValues; > use Koha::BiblioFrameworks; > use Koha::Libraries; > use Koha::Patron::Categories; >+use Koha::SharedContent; > > =head1 NAME > >@@ -145,6 +146,7 @@ elsif ( $phase eq 'Build new' ) { > } > } > $template->param( >+ 'manamsg' => $input->param('manamsg') || '', > 'saved1' => 1, > 'savedreports' => $reports, > 'usecache' => $usecache, >@@ -180,6 +182,10 @@ elsif ( $phase eq 'Show SQL'){ > 'notes' => $report->notes, > 'sql' => $report->savedsql, > 'showsql' => 1, >+ 'mana_success' => $input->param('mana_success'), >+ 'mana_success' => scalar $input->param('mana_success'), >+ 'mana_id' => $report->{mana_id}, >+ 'mana_comments' => $report->{comments} > ); > } > >@@ -198,6 +204,8 @@ elsif ( $phase eq 'Edit SQL'){ > 'public' => $report->public, > 'usecache' => $usecache, > 'editsql' => 1, >+ 'mana_id' => $report->{mana_id}, >+ 'mana_comments' => $report->{comments} > ); > } > >@@ -547,7 +555,7 @@ elsif ( $phase eq 'Build report' ) { > > elsif ( $phase eq 'Save' ) { > # Save the report that has just been built >- my $area = $input->param('area'); >+ my $area = $input->param('area'); > my $sql = $input->param('sql'); > my $type = $input->param('type'); > $template->param( >@@ -651,6 +659,7 @@ elsif ( $phase eq 'Save Report' ) { > cache_expiry => $cache_expiry, > public => $public, > } ); >+ > logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog"); > $template->param( > 'save_successful' => 1, >@@ -668,6 +677,14 @@ elsif ( $phase eq 'Save Report' ) { > } > } > >+elsif ($phase eq 'Share'){ >+ my $result = Koha::SharedContent::send_entity($input->param('mana_language'), $borrowernumber, scalar $input->param('reportid'), 'report'); >+ if ( $result ) { >+ print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=".$result->{msg}); >+ }else{ >+ print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved&manamsg=noanswer"); >+ } >+} > elsif ($phase eq 'Run this report'){ > # execute a saved report > my $limit = $input->param('limit') || 20; >diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl >index 7622e7e..e5adb36 100755 >--- a/serials/serials-collection.pl >+++ b/serials/serials-collection.pl >@@ -85,7 +85,7 @@ if($op eq 'gennext' && @subscriptionid){ > ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate}); > > ## We generate the next publication date >- my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); >+ $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); > my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1); > my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate; > ## Creating the new issue >diff --git a/serials/serials-search.pl b/serials/serials-search.pl >index d6cb85c..5d23f21 100755 >--- a/serials/serials-search.pl >+++ b/serials/serials-search.pl >@@ -96,14 +96,16 @@ for my $field ( @$additional_fields ) { > > my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; > my @subscriptions; >+my $mana_statuscode; > if ($searched){ > if ($mana) { >- my $result = Koha::SharedContent::manaGetRequest("subscription",{ >+ my $result = Koha::SharedContent::search_entities("subscription",{ > title => $title, > issn => $ISSN, > ean => $EAN, > publisher => $publisher > }); >+ $mana_statuscode = $result->{code}; > @subscriptions = @{ $result->{data} }; > } > else { >@@ -127,6 +129,7 @@ if ($searched){ > if ($mana) { > $template->param( > subscriptions => \@subscriptions, >+ statuscode => $mana_statuscode, > total => scalar @subscriptions, > title_filter => $title, > ISSN_filter => $ISSN, >diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl >index 71166b8..2edb78d 100755 >--- a/serials/subscription-add.pl >+++ b/serials/subscription-add.pl >@@ -292,35 +292,9 @@ sub _guess_enddate { > return $enddate; > } > >-sub manage_subscription_numbering_pattern_id { >- my $params; >- if ( $query->param('numbering_pattern') eq 'mana' ) { >- foreach (qw/numberingmethod label1 add1 every1 whenmorethan1 setto1 >- numbering1 label2 add2 every2 whenmorethan2 setto2 numbering2 >- label3 add3 every3 whenmorethan3 setto3 numbering3/) { >- $params->{$_} = $query->param($_) if $query->param($_); >- } >- >- my $existing = Koha::Subscription::Numberpatterns->search($params)->next(); >- >- if ($existing) { >- return $existing->id; >- } >- >- $params->{label} = Koha::Subscription::Numberpattern->uniqueLabel($query->param('patternname')); >- $params->{description} = $query->param('sndescription'); >- >- >- my $subscription_np = Koha::Subscription::Numberpattern->new()->set($params)->store(); >- return $subscription_np->id; >- } >- >- return $query->param('numbering_pattern'); >-} >- >-sub manage_subscription_frequencies_id { >- my $periodicity; >- if ( $query->param('frequency') eq 'mana' ) { >+sub redirect_add_subscription { >+ my $periodicity = $query->param('frequency'); >+ if ($periodicity eq 'mana') { > my $subscription_freq = Koha::Subscription::Frequency->new()->set( > { > description => $query->param('sfdescription'), >@@ -331,15 +305,7 @@ sub manage_subscription_frequencies_id { > )->store(); > $periodicity = $subscription_freq->id; > } >- else { >- $periodicity = $query->param('frequency'); >- } >- return $periodicity; >-} >- >-sub redirect_add_subscription { >- my $periodicity = manage_subscription_frequencies_id(); >- my $numberpattern = manage_subscription_numbering_pattern_id(); >+ my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing({ $query->Vars }); > > my $auser = $query->param('user'); > my $branchcode = $query->param('branchcode'); >@@ -379,10 +345,7 @@ sub redirect_add_subscription { > my $mana_id; > if ( $query->param('mana_id') ne "" ) { > $mana_id = $query->param('mana_id'); >- Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id); >- } >- else { >- $mana_id = undef; >+ Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers"); > } > > my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } ); >@@ -406,7 +369,10 @@ sub redirect_add_subscription { > $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, > $skip_serialseq, $itemtype, $previousitemtype, $mana_id > ); >- >+ if ( (C4::Context->preference('Mana')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){ >+ my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription'); >+ $template->param( mana_msg => $result->{msg} ); >+ } > my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); > insert_additional_fields( $additional_fields, $biblionumber, $subscriptionid ); > >@@ -434,8 +400,19 @@ sub redirect_mod_subscription { > ? output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } ) > : $firstacquidate; > >- my $periodicity = manage_subscription_frequencies_id(); >- my $numberpattern = manage_subscription_numbering_pattern_id(); >+ my $periodicity = $query->param('frequency'); >+ if ($periodicity eq 'mana') { >+ my $subscription_freq = Koha::Subscription::Frequency->new()->set( >+ { >+ description => $query->param('sfdescription'), >+ unit => $query->param('unit'), >+ unitsperissue => $query->param('unitsperissue'), >+ issuesperunit => $query->param('issuesperunit'), >+ } >+ )->store(); >+ $periodicity = $subscription_freq->id; >+ } >+ my $numberpattern = Koha::Subscription::Numberpatterns->new_or_existing({ $query->Vars }); > > my $subtype = $query->param('subtype'); > my $sublength = $query->param('sublength'); >@@ -466,7 +443,7 @@ sub redirect_mod_subscription { > my $mana_id; > if ( defined( $query->param('mana_id') ) ) { > $mana_id = $query->param('mana_id'); >- Koha::SharedContent::manaNewUserPatchRequest("subscription",$mana_id); >+ Koha::SharedContent::increment_entity_value("subscription",$mana_id, "nbofusers"); > } > else { > $mana_id = undef; >diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl >index 7f6f026..451e5a6 100755 >--- a/serials/subscription-detail.pl >+++ b/serials/subscription-detail.pl >@@ -33,11 +33,7 @@ use Koha::Acquisition::Bookseller; > use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/; > use Carp; > >-use LWP::UserAgent; > use Koha::SharedContent; >-use Koha::Patrons; >-use Koha::Subscriptions; >-use Koha::Libraries; > > my $query = new CGI; > my $op = $query->param('op') || q{}; >@@ -66,7 +62,6 @@ my ($template, $loggedinuser, $cookie) > debug => 1, > }); > >- > my $subs = GetSubscription($subscriptionid); > > output_and_exit( $query, $cookie, $template, 'unknown_subscription') >@@ -104,44 +99,10 @@ if ($op eq 'del') { > } > } > elsif ( $op and $op eq "share" ) { >- my $mana_language; >- if ( $query->param('mana_language') ) { >- $mana_language = $query->param('mana_language'); >- } >- else { >- $mana_language = C4::Context->preference('language'); >- } >- >- my $mana_email; >- if ( $loggedinuser ne 0 ) { >- my $borrower = Koha::Patrons->find($loggedinuser); >- $mana_email = $borrower->email >- if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); >- $mana_email = $borrower->emailpro >- if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); >- $mana_email = >- Koha::Libraries->find( C4::Context->userenv->{'branch'} )->branchemail >- if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); >- } >- $mana_email = C4::Context->preference('KohaAdminEmailAddress') >- if ( ( not defined($mana_email) ) or ( $mana_email eq '' ) ); >- my %versions = C4::Context::get_versions(); >- >- my $mana_info = { >- language => $mana_language, >- kohaversion => $versions{'kohaVersion'}, >- exportemail => $mana_email >- }; >- my $sub_mana_info = Koha::Subscription::get_sharable_info($subscriptionid); >- $sub_mana_info = { %$sub_mana_info, %$mana_info }; >- my $result = Koha::SharedContent::manaPostRequest( "subscription", >- $sub_mana_info ); >- if ( $result->{code} eq "200" and $result->{code} eq "201" ) { >- my $subscription = Koha::Subscriptions->find($subscriptionid); >- $subscription->set( { mana_id => $result->{id} } )->store; >- $subs->{mana_id} = $result->{id}; >- } >- $template->param( mana_code => $result->{code} ); >+ my $mana_language = $query->param('mana_language'); >+ my $result = Koha::SharedContent::send_entity($mana_language, $loggedinuser, $subscriptionid, 'subscription'); >+ $template->param( mana_code => $result->{msg} ); >+ $subs->{mana_id} = $result->{id}; > } > > my $hasRouting = check_routing($subscriptionid); >@@ -210,6 +171,7 @@ $template->param( > default_bib_view => $default_bib_view, > orders_grouped => $orders_grouped, > (uc(C4::Context->preference("marcflavour"))) => 1, >+ mana_comments => $subs->{comments}, > ); > > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/svc/mana/increment b/svc/mana/increment >new file mode 100755 >index 0000000..5b58496 >--- /dev/null >+++ b/svc/mana/increment >@@ -0,0 +1,48 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 BibLibre Baptiste Wojtkowski >+# >+# 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>. >+# >+ >+use Modern::Perl; >+ >+use Koha::SharedContent; >+use C4::Auth qw(check_cookie_auth); >+ >+use CGI; >+use JSON; >+ >+ >+my $input = new CGI; >+binmode STDOUT, ":encoding(UTF-8)"; >+print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); >+ >+my ( $auth_status, $sessionID ) = >+ check_cookie_auth( $input->cookie('CGISESSID'), >+ { serials => 'create_subscription' } ); >+ >+if ( $auth_status ne "ok" ) { >+ exit 0; >+} >+my $result = Koha::SharedContent::increment_entity_value( >+ scalar $input->param('resource'), >+ scalar $input->param('id'), >+ scalar $input->param('field'), >+ scalar $input->param('step') >+); >+ >+return $result; >diff --git a/svc/mana/search b/svc/mana/search >index 0f58c84..a89e54c 100755 >--- a/svc/mana/search >+++ b/svc/mana/search >@@ -18,8 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > # > >-use strict; >-use warnings; >+use Modern::Perl; > > use Koha::SharedContent; > use Koha::Subscription; >@@ -39,9 +38,16 @@ if ( $auth_status ne "ok" ) { > exit 0; > } > >+my $templatename; >+if ($input->param( "resource" ) eq 'report') { >+ $templatename = "mana/mana-report-search-result.tt"; >+} else { >+ $templatename = "mana/mana-subscription-search-result.tt"; >+} >+ > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > { >- template_name => "serials/mana-subscription-search-result.tt", >+ template_name => $templatename, > query => $input, > type => "intranet", > authnotrequired => 0, >@@ -52,11 +58,26 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-my $biblionumber = $input->param('biblionumber'); >+my ($identifier, $sub_mana_info); >+$identifier = $input->param('id'); >+$template->param( lowWarned => 5, warned => 10, highWarned => 20); >+my $package = "Koha::".ucfirst($input->param( 'resource' )); >+$sub_mana_info = $package->get_search_info($identifier); >+ >+$sub_mana_info->{ usecomments } = $input->param('usecomments'); >+my $resourcename = $input->param('resource'); >+my $result = Koha::SharedContent::search_entities( $resourcename, $sub_mana_info); >+my $nbofcomment; >+foreach my $resource (@{ $result->{data} }){ >+ $nbofcomment = 0; >+ foreach my $comment (@{ $resource->{comments} }){ >+ $nbofcomment += $comment->{nb}; >+ } >+ $resource->{nbofcomment} = $nbofcomment; >+} > >-my $sub_mana_info = Koha::Subscription::get_search_info($biblionumber); >-my $result = >- Koha::SharedContent::manaGetRequest( "subscription", $sub_mana_info ); >-$template->param( subscriptions => $result->{data} ); >+$template->param( $input->param('resource')."s" => $result->{data} ); >+$template->param( statuscode => $result->{code} ); >+$template->param( msg => $result->{msg} ); > > output_with_http_headers $input, $cookie, $template->output, 'json'; >diff --git a/svc/mana/share b/svc/mana/share >new file mode 100755 >index 0000000..508eec2 >--- /dev/null >+++ b/svc/mana/share >@@ -0,0 +1,69 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 BibLibre Baptiste Wojtkowski >+# >+# 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>. >+# >+ >+use Modern::Perl; >+ >+use Koha::SharedContent; >+use C4::Auth qw(check_cookie_auth); >+ >+use CGI; >+use JSON; >+ >+ >+my $input = new CGI; >+binmode STDOUT, ":encoding(UTF-8)"; >+print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); >+ >+my ( $auth_status, $sessionID ) = >+ check_cookie_auth( $input->cookie('CGISESSID'), >+ { serials => 'create_subscription' } ); >+ >+if ( $auth_status ne "ok" ) { >+ exit 0; >+} >+ >+ >+my $content; >+$content->{resource_id} = $input->param("resource_id"); >+$content->{resource_type} = $input->param("resource"); >+$content->{message} = $input->param("message"); >+Koha::SharedContent::send_entity('', undef, undef, 'resource_comment', $content); >+my $package = "Koha::".ucfirst($input->param('resource')); >+my $resource; >+my $result; >+eval{ >+ $result = Koha::SharedContent::get_entity_by_id( >+ scalar $input->param('resource'), >+ scalar $input->param('id') >+ ); >+}; >+if ( $@ or $result->{code} == 500 ){ >+ $resource->{errmsg} = "Error: mana access got broken, please try again later\n\n ( error: $@ )"; >+} >+else{ >+ if ( $input->param( 'saveinbase' )) { >+ $resource = { id => $package->new_from_mana($result->{data})->id }; >+ } >+ else{ >+ $resource = $result->{data}; >+ } >+} >+ >+print(to_json($resource)); >diff --git a/svc/mana/token b/svc/mana/token >new file mode 100755 >index 0000000..3ea6254 >--- /dev/null >+++ b/svc/mana/token >@@ -0,0 +1,55 @@ >+#!/usr/bin/perl >+ >+# Copyright 2016 BibLibre Baptiste Wojtkowski >+# >+# 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>. >+# >+ >+ >+use Modern::Perl; >+ >+use Koha::SharedContent; >+use C4::Auth qw(check_cookie_auth); >+ >+use CGI; >+use JSON; >+ >+my $input = new CGI; >+binmode STDOUT, ":encoding(UTF-8)"; >+print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); >+ >+my ( $auth_status, $sessionID ) = >+ check_cookie_auth( $input->cookie('CGISESSID'), >+ { serials => 'create_subscription' } ); >+ >+if ( $auth_status ne "ok" ) { >+ exit 0; >+} >+ >+my $mana_ip = C4::Context->config('mana_config'); >+ >+my $url = "$mana_ip/getsecuritytoken"; >+my $request = HTTP::Request->new( POST => $url ); >+ >+my $content; >+$content->{ firstname }= $input->param("firstname"); >+$content->{ lastname }= $input->param("lastname"); >+$content->{ email }= $input->param("email"); >+my $json = to_json( $content, { utf8 => 1 } ); >+$request->content($json); >+my $result = Koha::SharedContent::process_request($request); >+ >+print(to_json($result)); >diff --git a/svc/mana/use b/svc/mana/use >index a2f2e44..f08e9d1 100755 >--- a/svc/mana/use >+++ b/svc/mana/use >@@ -18,11 +18,11 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > # > >-use strict; >-use warnings; >+use Modern::Perl; > > use Koha::SharedContent; > use C4::Auth qw(check_cookie_auth); >+use Koha::Report; > > use CGI; > use JSON; >@@ -40,9 +40,17 @@ if ( $auth_status ne "ok" ) { > exit 0; > } > >-my $result = Koha::SharedContent::manaGetRequestWithId("subscription", $input->param('id') ); >+my $result = Koha::SharedContent::get_entity_by_id( >+ scalar $input->param('resource'), >+ scalar $input->param('id') >+); >+my $package = "Koha::".ucfirst($input->param('resource')); >+my $resource; > >-my $subscription; >-$subscription = $result->{data}; >- >-print(to_json($subscription)); >+if ( $input->param( 'saveinbase' )) { >+ $resource = { id => $package->new_from_mana($result->{data})->id }; >+} >+else{ >+ $resource = $result->{data}; >+} >+print(to_json($resource)); >diff --git a/t/db_dependent/Koha/SharedContent.t b/t/db_dependent/Koha/SharedContent.t >index 3784028..44c9f78 100644 >--- a/t/db_dependent/Koha/SharedContent.t >+++ b/t/db_dependent/Koha/SharedContent.t >@@ -20,10 +20,233 @@ > use Modern::Perl; > > use t::lib::TestBuilder; >-use Test::More tests => 1; >+use t::lib::Mocks; >+use Test::MockModule; >+use Test::MockObject; >+use Test::More tests => 44; > use Koha::Database; >+use Koha::Patrons; >+use Koha::Subscriptions; >+ >+use HTTP::Status qw(:constants :is status_message); > > use_ok('Koha::SharedContent'); > > my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; # mode insertion >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new(); >+ >+my $want_error = 0; >+my $post_request = 0; >+my $query = {}; >+ >+t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar'); >+ >+is(Koha::SharedContent::get_sharing_url(), 'https://foo.bar', 'Mana URL'); >+ >+my $result = Koha::SharedContent::search_entities('report', $query); >+ok($result->{msg} =~ /Can\'t connect to foo.bar:443$/, 'Unable to connect'); >+is($result->{code}, 500, 'Code is 500'); >+ >+my $ua = Test::MockModule->new('LWP::UserAgent'); >+$ua->mock('request', sub { >+ return mock_response(); >+}); >+ >+$want_error = 1; >+$query = {query => 'foo', usecomments => 1}; >+$result = Koha::SharedContent::search_entities('report', $query); >+ok($result->{msg} =~ /^Error thrown by decoded_content/, 'Error in decoded_content'); >+is($result->{code}, 500, 'Code is 500'); >+ >+$want_error = 0; >+$query = {title => 'foo', usecomments => 1}; >+$result = Koha::SharedContent::search_entities('subscription', $query); >+is($result->{code}, 200, 'search_entities success'); >+ >+$result = Koha::SharedContent::get_entity_by_id('subscription', 23); >+is($result->{code}, 200, 'get_entity_by_id success'); >+ >+my $params = { >+ title => 'The English historical review', >+ issn => '0013-8266', >+ ean => '', >+ publishercode => 'Longman' >+}; >+ >+# Search a subscription. >+my $request = Koha::SharedContent::build_request('get', 'subscription', $params); >+is($request->method, 'GET', 'Get subscription - Method is get'); >+ >+my %query = $request->uri->query_form; >+is($query{title}, 'The English historical review', 'Check title'); >+is($query{issn}, '0013-8266', 'Check issn'); >+is($query{ean}, '', 'Check ean'); >+is($query{publishercode}, 'Longman', 'Check publisher'); >+ >+is($request->uri->path, '/subscription.json', 'Path is subscription'); >+ >+# Get a report by id. >+$request = Koha::SharedContent::build_request('getwithid', 'report', 26); >+is($request->method, 'GET', 'Get with id - Method is get'); >+ >+is($request->uri->path, '/report/26.json', 'Path is report/26.json'); >+ >+# Share a report. >+my $content = { >+ 'kohaversion' => '17.06.00.008', >+ 'language' => 'fr-FR', >+ 'notes' => 'some notes', >+ 'report_group' => '', >+ 'exportemail' => 'xx@xx.com', >+ 'report_name' => 'A useless report', >+ 'savedsql' => 'SELECT * FROM ITEMS', >+ 'type' => undef >+}; >+ >+$request = Koha::SharedContent::build_request('post', 'report', $content); >+is($request->method, 'POST', 'Share report - Method is post'); >+ >+is($request->uri->path, '/report.json', 'Path is report.json'); >+ >+# prepare shared data >+my $loggedinuser = $builder->build({ >+ source => 'Borrower', >+ value => { >+ email => '', >+ emailpro => '', >+ B_email => '' >+ } >+}); >+ >+my $library = $builder->build({ >+ source => 'Branch', >+}); >+ >+my $biblio = $builder->build({ >+ source => 'Biblio', >+}); >+ >+my $biblioitem = $builder->build({ >+ source => 'Biblioitem', >+ value => { >+ biblionumber => $biblio->{biblionumber} >+ } >+}); >+ >+my $subscriptionFrequency = $builder->build({ >+ source => 'SubscriptionFrequency' >+}); >+ >+my $subscriptionNumberpattern = $builder->build({ >+ source => 'SubscriptionNumberpattern' >+}); >+ >+my $subscription = $builder->build({ >+ source => 'Subscription', >+ value => { >+ biblionumber => $biblio->{biblionumber}, >+ periodicity => $subscriptionFrequency->{id}, >+ numberpattern => $subscriptionNumberpattern->{id}, >+ mana_id => undef >+ } >+}); >+ >+C4::Context->_new_userenv('xxx'); >+C4::Context->set_userenv(0,0,0, >+ $loggedinuser->{firstname}, >+ $loggedinuser->{surname}, >+ $library->{branchcode}, >+ 'Midway Public Library', '', '', ''); >+ >+t::lib::Mocks::mock_preference('language', 'en'); >+ >+$post_request = 1; >+$result = Koha::SharedContent::send_entity('en', $loggedinuser->{borrowernumber}, $subscription->{subscriptionid}, 'subscription'); >+is($result->{code}, 200, 'send_entity success'); >+ >+my $s = Koha::Subscriptions->find($subscription->{subscriptionid}); >+is($s->mana_id, 5, 'Mana id is set'); >+ >+my $data = Koha::SharedContent::prepare_entity_data( >+ '', >+ $loggedinuser->{borrowernumber}, >+ $subscription->{subscriptionid}, >+ 'subscription' >+); >+ >+is($data->{language}, 'en', 'Language is set to default'); >+my $branch = Koha::Libraries->find($library->{branchcode}); >+is($data->{exportemail}, $branch->branchemail, 'Email is set with the userenv branch one'); >+is($data->{title}, $biblio->{title}, 'Shared title'); >+is($data->{sfdescription}, $subscriptionFrequency->{description}, 'Shared sfdescription'); >+is($data->{unit}, $subscriptionFrequency->{unit}, 'Shared unit'); >+is($data->{unitsperissue}, $subscriptionFrequency->{unitsperissue}, 'Shared unitsperissue'); >+is($data->{issuesperunit}, $subscriptionFrequency->{issuesperunit}, 'Shared issuesperunit'); >+ >+is($data->{label}, $subscriptionNumberpattern->{label}, 'Shared np label'); >+is($data->{sndescription}, $subscriptionNumberpattern->{description}, 'Shared np description'); >+is($data->{numberingmethod}, $subscriptionNumberpattern->{numberingmethod}, 'Shared numberingmethod'); >+is($data->{label1}, $subscriptionNumberpattern->{label1}, 'Shared label1'); >+is($data->{add1}, $subscriptionNumberpattern->{add1}, 'Shared add1'); >+is($data->{every1}, $subscriptionNumberpattern->{every1}, 'Shared every1'); >+is($data->{whenmorethan1}, $subscriptionNumberpattern->{whenmorethan1}, 'Shared whenmorethan1'); >+is($data->{setto1}, $subscriptionNumberpattern->{setto1}, 'Shared setto1'); >+is($data->{numbering1}, $subscriptionNumberpattern->{numbering1}, 'Shared numbering1'); >+is($data->{issn}, $biblioitem->{issn}, 'Shared ISSN'); >+is($data->{ean}, $biblioitem->{ean}, 'Shared EAN'); >+is($data->{publishercode}, $biblioitem->{publishercode}, 'Shared publishercode'); >+ >+sub mock_response { >+ my $response = Test::MockObject->new(); >+ >+ if ($want_error) { >+ $response->mock('code', sub { >+ return 500; >+ }); >+ $response->mock('is_error', sub { >+ return 0; >+ }); >+ $response->mock('decoded_content', sub { >+ die 'Error thrown by decoded_content'; >+ }); >+ } elsif ( $post_request ) { >+ $response->mock('code', sub { >+ return 200; >+ }); >+ $response->mock('is_error', sub { >+ return 0; >+ }); >+ $response->mock('decoded_content', sub { >+ return '{"code": "200", "msg": "foo", "id": "5"}'; >+ }); >+ } else { >+ $response->mock('code', sub { >+ return 200; >+ }); >+ $response->mock('is_error', sub { >+ return 0; >+ }); >+ $response->mock('decoded_content', sub { >+ return ''; >+ }); >+ } >+} >+ >+# Increment request. >+$request = Koha::SharedContent::build_request('increment', >+ 'subscription', >+ 12, >+ 'foo'); >+ >+is($request->method, 'POST', 'Increment subscription - Method is post'); >+ >+%query = $request->uri->query_form; >+is($query{id}, 12, 'Check id'); >+is($query{step}, 1, 'Step is default'); >+is($query{resource}, 'subscription', 'Check ressource'); >+ >+is($request->uri->path, '/subscription/12.json/increment/foo', 'Path is subscription'); >+ >+$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Subscription.t b/t/db_dependent/Koha/Subscription.t >index c378917..fadaae7 100644 >--- a/t/db_dependent/Koha/Subscription.t >+++ b/t/db_dependent/Koha/Subscription.t >@@ -31,7 +31,6 @@ use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; >-my $builder = t::lib::TestBuilder->new; > > use_ok('Koha::Subscription'); > >@@ -150,6 +149,7 @@ my $ref = { > 'unit' => $sub_freq_1->{unit}, > 'unitsperissue' => $sub_freq_1->{unitsperissue}, > 'issuesperunit' => $sub_freq_1->{issuesperunit}, >+ 'label' => $sub_np_1->{label}, > 'sndescription' => $sub_np_1->{description}, > 'numberingmethod' => $sub_np_1->{numberingmethod}, > 'label' => $sub_np_1->{label}, >@@ -176,7 +176,7 @@ my $ref = { > 'publishercode' => $bi_1->{publishercode} > }; > >-is_deeply( Koha::Subscription::get_sharable_info( $sub_1->{subscriptionid} ), >+is_deeply( Koha::Subscription->get_sharable_info( $sub_1->{subscriptionid} ), > $ref, "get_sharable_info function is ok" ); > > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Subscription/Numberpatterns.t b/t/db_dependent/Koha/Subscription/Numberpatterns.t >new file mode 100644 >index 0000000..6aa26c4 >--- /dev/null >+++ b/t/db_dependent/Koha/Subscription/Numberpatterns.t >@@ -0,0 +1,97 @@ >+#!/usr/bin/perl >+ >+# Copyright 2017 BibLibre >+# >+# 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>. >+ >+use Modern::Perl; >+ >+use t::lib::TestBuilder; >+use Test::More tests => 6; >+use Koha::Database; >+ >+use_ok('Koha::Subscription::Numberpatterns'); >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $builder = t::lib::TestBuilder->new; >+ >+my $dbh = C4::Context->dbh; >+$dbh->do('DELETE FROM subscription_numberpatterns'); >+ >+my $numberpattern = $builder->build({ >+ source => 'SubscriptionNumberpattern', >+ value => { >+ label => 'Volume, Number, Issue', >+ description => 'Volume Number Issue 1', >+ numberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}', >+ label1 => 'Volume', >+ add1 => '1', >+ every1 => '48', >+ whenmorethan1 => '99999', >+ setto1 => '1', >+ numbering1 => undef, >+ label2 => 'Number', >+ add2 => '1', >+ every2 => '4', >+ whenmorethan2 => '12', >+ setto2 => '1', >+ numbering2 => undef, >+ label3 => 'Issue', >+ add3 => '1', >+ every3 => '1', >+ whenmorethan3 => '4', >+ setto3 => '1', >+ numbering3 => undef >+ } >+}); >+ >+my $search_ok = { >+ umberingmethod => 'Vol.{X}, Number {Y}, Issue {Z}', >+ label1 => 'Volume', add1 => '1', every1 => '48', >+ whenmorethan1 => '99999', setto1 => '1', >+ label2 => 'Number', add2 => '1', every2 => '4', >+ whenmorethan2 => '12', setto2 => '1', >+ label3 => 'Issue', add3 => '1', every3 => '1', >+ whenmorethan3 => '4', setto3 => '1', >+ numbering_pattern => 'mana' >+}; >+ >+my $number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_ok); >+is($number_pattern_id, $numberpattern->{id}, 'new_or_existing method should find the existing number pattern'); >+ >+$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing({numbering_pattern => 1}); >+is($number_pattern_id, 1, 'new_or_existing method should return passed numbering_pattern'); >+ >+my $search_not_ok = { >+ patternname => 'Number', >+ sndescription => 'Simple Numbering method', >+ numberingmethod => 'No.{X}', >+ label1 => 'Number', >+ add1 => 1, >+ every1 => 1, >+ whenmorethan1 => 99999, >+ setto1 => 1, >+ numbering_pattern => 'mana' >+}; >+ >+$number_pattern_id = Koha::Subscription::Numberpatterns->new_or_existing($search_not_ok); >+my $new_number_pattern = Koha::Subscription::Numberpatterns->find($number_pattern_id); >+is($new_number_pattern->label, 'Number'); >+is($new_number_pattern->description, 'Simple Numbering method'); >+is($new_number_pattern->numberingmethod, 'No.{X}'); >+ >+$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t >index 35e5a64..127c426 100755 >--- a/t/db_dependent/Serials.t >+++ b/t/db_dependent/Serials.t >@@ -283,7 +283,7 @@ my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscrip > ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); > my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); > ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid ); >-my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); >+$frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); > my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1); > my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 ); > # Add 14 serials >diff --git a/t/db_dependent/Serials/GetFictiveIssueNumber.t b/t/db_dependent/Serials/GetFictiveIssueNumber.t >index e944de9..1ad66b2 100644 >--- a/t/db_dependent/Serials/GetFictiveIssueNumber.t >+++ b/t/db_dependent/Serials/GetFictiveIssueNumber.t >@@ -1,126 +1,232 @@ > #!/usr/bin/perl > >-use C4::Context; >-use Test::More tests => 18; >+# This test deals with GetFictiveIssueNumber (from C4::Serials) >+ > use Modern::Perl; >+use Test::More tests => 5; >+ >+use Koha::Database; >+use C4::Serials; >+use C4::Serials::Frequency; > >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; > my $dbh = C4::Context->dbh; >-$dbh->{RaiseError} = 1; >-$dbh->{AutoCommit} = 0; > >-use C4::Serials::Frequency; >-use C4::Serials; >+subtest 'Tests for irregular frequency' => sub { >+ plan tests => 2; > >-# TEST CASE - 1 issue per day, no irregularities >-my $frequency = { >- description => "One issue per day", >- unit => 'day', >- issuesperunit => 1, >- unitsperissue => 1, >-}; >+ # Add a frequency >+ my $freq_irr = AddSubscriptionFrequency({ >+ description => "Irregular", >+ unit => undef, >+ }); > >-my $subscription = { >- firstacquidate => '1970-01-01', >- irregularity => '', >- countissuesperunit => 1, >-}; >-my $issueNumber; >- >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); >-is( $issueNumber, '1' ); >- >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); >-is( $issueNumber, '2' ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); >-is( $issueNumber, '3' ); >- >-# TEST CASE - 2 issues per day, no irregularity >-$frequency = { >- description => "Two issues per day", >- unit => 'day', >- issuesperunit => 2, >- unitsperissue => 1, >+ # Test it >+ my $subscription = { >+ periodicity => $freq_irr, >+ firstacquidate => '1972-02-07', >+ }; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-12-31'), undef, 'Irregular: should be undef' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-12-31'), undef, 'Irregular: still undef' ); > }; >-$subscription = { >- firstacquidate => '1970-01-01', >- irregularity => '', >- countissuesperunit => 1, >-}; >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); >-is( $issueNumber, '1' ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); >-is( $issueNumber, '3' ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); >-is( $issueNumber, '5' ); >- >-$subscription->{countissuesperunit} = 2; >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); >-is( $issueNumber, '2' ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); >-is( $issueNumber, '4' ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); >-is( $issueNumber, '6' ); >- >-# TEST CASE - 1 issue every 2 days, no irregularity >-$frequency = { >- description => "one issue every two days", >- unit => 'day', >- issuesperunit => 1, >- unitsperissue => 2, >+ >+subtest 'Tests for yearly frequencies' => sub { >+ plan tests => 10; >+ >+ # First add a few frequencies >+ my $freq_1i_1y = AddSubscriptionFrequency({ >+ description => "1 issue per year", >+ unit => 'year', >+ issuesperunit => 1, >+ unitsperissue => 1, >+ }); >+ my $freq_1i_3y = AddSubscriptionFrequency({ >+ description => "1 issue per 3 years", >+ unit => 'year', >+ issuesperunit => 1, >+ unitsperissue => 3, >+ }); >+ my $freq_5i_1y = AddSubscriptionFrequency({ >+ description => "5 issues per year", >+ unit => 'year', >+ issuesperunit => 5, >+ unitsperissue => 1, >+ }); >+ my $freq_366i_1y = AddSubscriptionFrequency({ >+ description => "366 issue per year", >+ unit => 'year', >+ issuesperunit => 366, >+ unitsperissue => 1, >+ }); >+ >+ # TEST CASE - 1 issue per year >+ my $subscription = { >+ periodicity => $freq_1i_1y, >+ firstacquidate => '1972-02-10', >+ countissuesperunit => 1, >+ }; >+ >+ my $frequency = GetSubscriptionFrequency($freq_1i_1y); >+ >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-09', $frequency), 1, 'Feb 9 still 1' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-10', $frequency), 2, 'Feb 10 goes to 2' ); >+ >+ # TEST CASE - 1 issue per 3 years >+ $subscription->{periodicity} = $freq_1i_3y; >+ $subscription->{firstacquidate} = '1972-02-20'; >+ $frequency = GetSubscriptionFrequency($freq_1i_3y); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-19', $frequency), 1, 'Feb 19, 1975 still 1' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1975-02-20', $frequency), 2, 'Feb 20, 1975 goes to 2' ); >+ >+ # TEST CASE - 5 issues per year >+ $subscription->{periodicity} = $freq_5i_1y; >+ $subscription->{firstacquidate} = '1972-02-29'; #leap year >+ $subscription->{countissuesperunit} = 1; >+ $frequency = GetSubscriptionFrequency($freq_5i_1y); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-11', $frequency), 1, 'May 11 still 1' ); >+ $subscription->{countissuesperunit} = 2; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-12', $frequency), 2, 'May 12 goes to 2' ); >+ $subscription->{countissuesperunit} = 5; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 5, 'Feb 27 should still be 5' ); >+ $subscription->{countissuesperunit} = 1; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 6, 'Feb 28 goes to 6' ); >+ >+ # TEST CASE - 366 issues per year (hypothetical example) >+ # Testing prevention of divide by zero >+ $subscription->{periodicity} = $freq_366i_1y; >+ $subscription->{firstacquidate} = '1972-02-29'; #leap year >+ $subscription->{countissuesperunit} = 366; >+ $frequency = GetSubscriptionFrequency($freq_366i_1y); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-27', $frequency), 366, 'Feb 27 still at 366' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-02-28', $frequency), 732, 'Feb 28 goes to 732' ); >+ > }; >-$subscription = { >- firstacquidate => '1970-01-01', >- irregularity => '', >- countissuesperunit => 1, >+ >+subtest 'Tests for monthly frequencies' => sub { >+ plan tests => 8; >+ >+ # First add a few frequencies >+ my $freq_1i_5m = AddSubscriptionFrequency({ >+ description => "1 issue per 5 months", >+ unit => 'month', >+ issuesperunit => 1, >+ unitsperissue => 5, >+ }); >+ my $freq_4i_1m = AddSubscriptionFrequency({ >+ description => "4 issue per month", >+ unit => 'month', >+ issuesperunit => 4, >+ unitsperissue => 1, >+ }); >+ >+ # TEST CASE - 1 issue per 5 months >+ my $subscription = { >+ periodicity => $freq_1i_5m, >+ firstacquidate => '1972-02-10', >+ countissuesperunit => 1, >+ }; >+ my $frequency = GetSubscriptionFrequency($freq_1i_5m); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-09', $frequency), 1, 'Jul 9 still 1' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-07-10', $frequency), 2, 'Jul 10 goes to 2' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-09', $frequency), 3, 'May 9 still 3' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1973-05-10', $frequency), 4, 'May 10 goes to 4' ); >+ >+ # TEST CASE - 4 issue per 1 months >+ $subscription = { >+ periodicity => $freq_4i_1m, >+ firstacquidate => '1972-02-22', >+ countissuesperunit => 1, >+ }; >+ $frequency = GetSubscriptionFrequency($freq_4i_1m); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-28', $frequency), 1, 'Feb 28 still 1' ); >+ $subscription->{countissuesperunit} = 2; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-29', $frequency), 2, 'Feb 29 goes to 2' ); >+ $subscription->{countissuesperunit} = 4; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-21', $frequency), 4, 'Mar 21 still 4' ); >+ $subscription->{countissuesperunit} = 1; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-22', $frequency), 5, 'Mar 22 goes to 5' ); >+ > }; >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); >-is( $issueNumber, 1 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); >-is( $issueNumber, 1 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-03', $frequency ); >-is( $issueNumber, 2 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-04', $frequency ); >-is( $issueNumber, 2 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-05', $frequency ); >-is( $issueNumber, 3 ); >- >-# TEST CASE - 1 issue per week, no irregularity >-$frequency = { >- description => "one issue per week", >- unit => 'week', >- issuesperunit => 1, >- unitsperissue => 1, >+ >+subtest 'Tests for weekly frequencies' => sub { >+ plan tests => 4; >+ >+ # First add a few frequencies >+ my $freq_1i_7w = AddSubscriptionFrequency({ >+ description => "1 issue per 7 weeks", >+ unit => 'week', >+ issuesperunit => 1, >+ unitsperissue => 7, >+ }); >+ my $freq_3i_1w = AddSubscriptionFrequency({ >+ description => "3 issues per week", >+ unit => 'week', >+ issuesperunit => 3, >+ unitsperissue => 1, >+ }); >+ >+ # TEST CASE - 1 issue per 7 weeks >+ my $subscription = { >+ periodicity => $freq_1i_7w, >+ firstacquidate => '1972-02-10', >+ countissuesperunit => 1, >+ }; >+ my $frequency = GetSubscriptionFrequency($freq_1i_7w); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-29', $frequency), 1, 'Mar 29 still 1' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-30', $frequency), 2, 'Mar 30 goes to 2' ); >+ >+ # TEST CASE - 3 issue per 1 week >+ $subscription = { >+ periodicity => $freq_3i_1w, >+ firstacquidate => '1972-02-03', >+ countissuesperunit => 1, >+ }; >+ $subscription->{countissuesperunit} = 3; >+ $frequency = GetSubscriptionFrequency($freq_3i_1w); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-09', $frequency), 3, 'Feb 9 still 3' ); >+ $subscription->{countissuesperunit} = 1; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-02-10', $frequency), 4, 'Feb 10 goes to 4' ); > }; >-$subscription = { >- firstacquidate => '1970-01-01', >- irregularity => '', >- countissuesperunit => 1, >+ >+subtest 'Tests for dayly frequencies' => sub { >+ plan tests => 4; >+ >+ # First add a few frequencies >+ my $freq_1i_12d = AddSubscriptionFrequency({ >+ description => "1 issue per 12 days", >+ unit => 'day', >+ issuesperunit => 1, >+ unitsperissue => 12, >+ }); >+ my $freq_3i_1d = AddSubscriptionFrequency({ >+ description => "3 issues per day", >+ unit => 'day', >+ issuesperunit => 3, >+ unitsperissue => 1, >+ }); >+ >+ # TEST CASE - 1 issue per 12 days >+ my $subscription = { >+ periodicity => $freq_1i_12d, >+ firstacquidate => '1972-03-16', >+ countissuesperunit => 1, >+ }; >+ my $frequency = GetSubscriptionFrequency($freq_1i_12d); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-27', $frequency), 1, 'Mar 27 still 1' ); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-03-28', $frequency), 2, 'Mar 28 goes to 2' ); >+ >+ # TEST CASE - 3 issue per day >+ $subscription = { >+ periodicity => $freq_3i_1d, >+ firstacquidate => '1972-04-23', >+ countissuesperunit => 1, >+ }; >+ $subscription->{countissuesperunit} = 3; >+ $frequency = GetSubscriptionFrequency($freq_3i_1d); >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-01', $frequency), 27, 'May 1 still 27' ); >+ $subscription->{countissuesperunit} = 1; >+ is( C4::Serials::GetFictiveIssueNumber($subscription, '1972-05-02', $frequency), 28, 'May 2 goes to 28' ); > }; >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-01', $frequency ); >-is( $issueNumber, 1 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-02', $frequency ); >-is( $issueNumber, 1 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-08', $frequency ); >-is( $issueNumber, 2 ); >-$issueNumber = >- C4::Serials::GetFictiveIssueNumber( $subscription, '1970-01-15', $frequency ); >-is( $issueNumber, 3 ); >- >-$dbh->rollback; >+ >+$schema->storage->txn_rollback; >-- >2.7.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 17047
:
56175
|
56176
|
56177
|
56178
|
56179
|
56180
|
56181
|
59728
|
59729
|
59931
|
61905
|
62045
|
62046
|
62047
|
62048
|
62049
|
62050
|
62051
|
62052
|
62053
|
62054
|
62075
|
62465
|
62475
|
62485
|
62540
|
62542
|
62543
|
62544
|
62545
|
62546
|
62547
|
62548
|
62549
|
62550
|
62551
|
62552
|
62553
|
62589
|
62591
|
62592
|
62593
|
62594
|
62595
|
62596
|
62597
|
62598
|
62599
|
62603
|
62604
|
62605
|
62606
|
62607
|
62768
|
63476
|
63601
|
63618
|
63619
|
63620
|
63621
|
63622
|
63623
|
64484
|
64530
|
64618
|
64619
|
64620
|
64621
|
64622
|
64623
|
64624
|
64625
|
64626
|
64627
|
64628
|
64629
|
64630
|
64631
|
64632
|
64633
|
64634
|
64635
|
64636
|
64637
|
64638
|
64639
|
64640
|
64641
|
64642
|
64643
|
64648
|
64649
|
64650
|
64651
|
64652
|
64653
|
64654
|
64706
|
64962
|
65058
|
65059
|
65060
|
65061
|
65062
|
65063
|
65064
|
65065
|
65773
|
66667
|
66668
|
66987
|
67003
|
67004
|
67005
|
67006
|
67009
|
67010
|
67011
|
67012
|
67013
|
67014
|
67015
|
67016
|
67017
|
67018
|
67019
|
67020
|
67021
|
67022
|
67023
|
69034
|
69035
|
69036
|
69037
|
69038
|
69039
|
69040
|
69041
|
69091
|
70203
|
70204
|
70205
|
70206
|
70208
|
70209
|
70210
|
70211
|
70561
|
70874
|
72660
|
72661
|
72662
|
72663
|
72664
|
72665
|
72666
|
72667
|
72668
|
72669
|
72670
|
73699
|
73737
|
73738
|
73739
|
73740
|
73741
|
73742
|
73743
|
73744
|
73745
|
73746
|
73747
|
73748
|
73975
|
73976
|
73977
|
73978
|
73979
|
73980
|
73981
|
73982
|
73983
|
73984
|
73985
|
73986
|
76673
|
76674
|
76675
|
76676
|
76677
|
76678
|
76679
|
76680
|
76681
|
76682
|
76683
|
76684
|
78215
|
78216
|
78217
|
78218
|
78219
|
78220
|
78221
|
78222
|
78223
|
78224
|
78225
|
78226
|
78227
|
78228
|
78229
|
79868
|
79869
|
79870
|
79871
|
79872
|
79874
|
79877
|
79878
|
79879
|
79880
|
79881
|
79882
|
79883
|
79884
|
79885
|
79886
|
79887
|
79888
|
79922
|
79923
|
79924
|
79925
|
79926
|
79927
|
79928
|
79929
|
79930
|
79931
|
79932
|
79933
|
79934
|
79935
|
79936
|
79937
|
79938
|
79939
|
80183
|
80184
|
80185
|
80186
|
80187
|
80188
|
80189
|
80190
|
80191
|
80192
|
80193
|
80194
|
80195
|
80196
|
80197
|
80198
|
80199
|
80200
|
80471
|
80472
|
80473
|
80907
|
80908
|
80909
|
80910
|
80911
|
80912
|
80913
|
80914
|
80915
|
80916
|
80917
|
80918
|
80919
|
80920
|
80921
|
80922
|
80923
|
80924
|
81935
|
81936
|
81937
|
81938
|
81939
|
81940
|
81941
|
81942
|
81943
|
81944
|
81945
|
81946
|
81947
|
81948
|
81949
|
81950
|
81951
|
81952
|
81968
|
83863
|
83864
|
83865
|
83866
|
83867
|
83868
|
83869
|
83870
|
83871
|
83872
|
83873
|
83874
|
83875
|
83876
|
83877
|
83878
|
83879
|
83880
|
83881
|
83892
|
83893
|
83894
|
83895
|
83896
|
83897
|
83898
|
83899
|
83900
|
83901
|
83902
|
83903
|
83904
|
83905
|
83906
|
83907
|
83908
|
83909
|
83910
|
83911
|
83912
|
84142
|
84145
|
84210
|
84260
|
84261
|
84262
|
84263
|
84264
|
84265
|
84323
|
84324
| 84325 |
84326
|
84327
|
84328
|
84329
|
84332