From a717c6ed4b4d290363eb034cb1205b47a42b05f8 Mon Sep 17 00:00:00 2001 From: Martin Persson Date: Sat, 12 Dec 2015 21:18:27 +0100 Subject: [PATCH] Bug 15326: Add CMS feature INCOMPLETE - For evaluation purposes only! --- Koha/CmsPage.pm | 53 +++++ Koha/CmsPages.pm | 200 +++++++++++++++++ .../mysql/atomicupdate/bug15326-add_cms_pages.sql | 17 ++ installer/data/mysql/kohastructure.sql | 23 ++ installer/data/mysql/userpermissions.sql | 1 + .../intranet-tmpl/prog/en/includes/permissions.inc | 1 + .../prog/en/modules/tools/cmspages.tt | 238 +++++++++++++++++++++ .../prog/en/modules/tools/tools-home.tt | 5 + .../opac-tmpl/bootstrap/en/includes/masthead.inc | 14 ++ .../opac-tmpl/bootstrap/en/includes/navigation.inc | 10 +- .../bootstrap/en/modules/opac-cmspages.tt | 89 ++++++++ koha-tmpl/opac-tmpl/bootstrap/less/opac.less | 40 +++- opac/opac-cmspages.pl | 52 +++++ opac/opac-main.pl | 6 +- t/Pages.t | 31 +++ t/db_dependent/Pages.t | 93 ++++++++ tools/cmspages.pl | 90 ++++++++ 17 files changed, 959 insertions(+), 4 deletions(-) create mode 100644 Koha/CmsPage.pm create mode 100644 Koha/CmsPages.pm create mode 100644 installer/data/mysql/atomicupdate/bug15326-add_cms_pages.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-cmspages.tt create mode 100755 opac/opac-cmspages.pl create mode 100644 t/Pages.t create mode 100644 t/db_dependent/Pages.t create mode 100755 tools/cmspages.pl diff --git a/Koha/CmsPage.pm b/Koha/CmsPage.pm new file mode 100644 index 0000000..fd5b52a --- /dev/null +++ b/Koha/CmsPage.pm @@ -0,0 +1,53 @@ +package Koha::CmsPage; + +# Copyright Halland County Library 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw( Koha::Object ); + +=head1 NAME + +Koha::CmsPage - Koha Page Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'CmsPage'; +} + +=head1 AUTHOR + +Martin Persson +Halland County Library + +=cut + +1; diff --git a/Koha/CmsPages.pm b/Koha/CmsPages.pm new file mode 100644 index 0000000..b49881e --- /dev/null +++ b/Koha/CmsPages.pm @@ -0,0 +1,200 @@ +package Koha::CmsPages; + +# Copyright Halland County Library 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp qw( carp ); + +use Koha::Database; +use Koha::CmsPage; + +use base qw( Koha::Objects ); + +=head1 NAME + +Koha::CmsPage - Koha CMS Page Object Class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'CmsPage'; +} + +sub object_class { + return 'Koha::CmsPage'; +} + +=head3 add +Adds a new page to the CMS database based on the input data. +=cut + +sub add { + my ( $self, $input ) = @_; +warn "input: ", scalar $input->param('location'); + carp( 'Koha::CmsPages::add() undefined parameter: input' ) unless defined $input; + my $data = { + parent => scalar $input->param( 'parent' ) eq '' ? undef : scalar $input->param( 'parent' ), + location => scalar $input->param( 'location' ) eq '' ? undef : scalar $input->param( 'location'), + branchcode => scalar $input->param( 'branchcode' ) eq '' ? undef : scalar $input->param( 'branchcode' ), + lang => scalar $input->param( 'lang' ), + sortorder => scalar $input->param( 'sortorder' ), + title => scalar $input->param( 'title' ), + title_link => scalar $input->param( 'title_link' ), + publish => defined (scalar $input->param( 'publish' )), + content => scalar $input->param( 'content' ) + }; + + if (defined $input->param( 'id' )) { + $data->{'id'} = scalar $input->param( 'id' ); + } + + my $new_page = $self->_resultset()->update_or_create( $data, { key => 'primary' }); + + return $new_page; +} + +=head3 list + +Lists pages based input filtering paramters for location, branch and language. + +=cut + +sub list { + my ( $self, $id, $disp, $branch, $lang ) = @_; + + my $filter = { }; + $filter->{'location'} = $disp unless not defined $disp; + $filter->{'branch'} = $branch unless not defined $branch; + $filter->{'lang'} = $lang unless not defined $lang; + + my $pages = $self->_resultset()->search( undef, { + order_by => { + -asc => [qw/parent location branchcode lang sortorder/] + }, where => $filter + } ); + + my $page_list = []; + my $parent_list = []; + my %index; + my $data; + while ( my $page = $pages->next ) { + my $new_page = { + id => scalar $page->id, + parent => scalar $page->parent, + branchcode => scalar $page->branchcode, + lang => scalar $page->lang, + title_link => scalar $page->title_link, + title => scalar $page->title, + sortorder => scalar $page->sortorder, + location => scalar $page->location, + publish => scalar $page->publish, + content => scalar $page->content, + }; + push(@{ $page_list }, $new_page ); + + # If requested id, store in 'data' output (used for editing a page): + if ( defined $id && $id eq $new_page->{'id'} ) { + $data = $new_page; + } else { + push(@{ $parent_list }, $new_page ); + } + $index{ $page->id } = $new_page; + } + + # Replace parent id with a hash with id and title_link in it. + foreach my $page (@{ $page_list }) { + my $old_id = $page->{'parent'}; + my $parent = { id => $old_id }; + $parent->{'title_link'} = $index{ $old_id }->{'title_link'} unless not defined $old_id; + $page->{'parent'} = $parent; + } + + return ( $page_list, $parent_list, $data ); +} + +=head3 page + +Retrieves all data to show a single CMS page. + +=cut + +sub page { + my ( $self, $id ) = @_; + + carp( 'Missing CMS page id parameter in Koha::Pages::page' ) unless defined $id; + + # Probably want to merge these to a single query: + my $top_links = $self->_resultset()->search( + { parent => undef }, { qw/id title_link/ }); + + my $page_links = $self->_resultset()->search( + { parent => $id }, { qw/id title_link/ }); + + my $page_data = $self->_resultset()->find( $id ); + + return ( $top_links, $page_links, $page_data ); +} + +=head3 child_links + +Lists pages which are children of a specific id (or undef for root). + +=cut + +sub child_links { + my ( $self, $id ) = @_; + + # 'id' can be undefined if listing top-level links. + my $rs = $self->_resultset()->search({ parent => $id }, + { columns => [qw/id title_link/] } ); + + return $rs; +} + +=head3 remove + +Removes a page identified by id from the CMS database. + +=cut + +sub remove { + my ( $self, @ids ) = @_; + + carp( 'Koha::CmsPages::remove() undefined parameter ids' ) unless @ids; + + my $pages = $self->_resultset()->search({ id => \@ids }); + $pages->delete; +} + +=head1 AUTHOR + +Martin Persson +Halland County Library + +=cut + +1; diff --git a/installer/data/mysql/atomicupdate/bug15326-add_cms_pages.sql b/installer/data/mysql/atomicupdate/bug15326-add_cms_pages.sql new file mode 100644 index 0000000..74c45f7 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug15326-add_cms_pages.sql @@ -0,0 +1,17 @@ + CREATE TABLE `cms_pages` ( + `id` int(6) NOT NULL AUTO_INCREMENT, + `parent` int(6) DEFAULT NULL, + `branchcode` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + `lang` varchar(25) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', + `title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `title_link` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, + `sortorder` int(3) NOT NULL DEFAULT 0, + `location` tinyint(1) DEFAULT NULL, + `publish` tinyint(1) NOT NULL DEFAULT 0, + `content` text COLLATE utf8_unicode_ci, + PRIMARY KEY (`id`), + INDEX `parent_index` (`parent`), + INDEX `lang_index` (`lang`), + INDEX `branchcode_index` (`branchcode`), + CONSTRAINT `cmspages_branchcode_ibfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index c293b79..3dcd4b7 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4099,6 +4099,29 @@ CREATE TABLE IF NOT EXISTS club_fields ( CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +-- +-- Table structure for table 'cms_pages', used for CMS functionality. +-- + +DROP TABLE IF EXISTS `cms_pages`; + CREATE TABLE `cms_pages` ( + `id` int(6) NOT NULL AUTO_INCREMENT, + `parent` int(6) DEFAULT NULL, + `branchcode` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + `lang` varchar(25) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', + `title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `title_link` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, + `sortorder` int(3) NOT NULL DEFAULT 0, + `location` tinyint(1) DEFAULT NULL, + `publish` tinyint(1) NOT NULL DEFAULT 0, + `content` text COLLATE utf8_unicode_ci, + PRIMARY KEY (`id`), + INDEX `parent_index` (`parent`), + INDEX `lang_index` (`lang`), + INDEX `branchcode_index` (`branchcode`), + CONSTRAINT `pages_branchcode_ibfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; diff --git a/installer/data/mysql/userpermissions.sql b/installer/data/mysql/userpermissions.sql index 172f4c6..7aee13f 100644 --- a/installer/data/mysql/userpermissions.sql +++ b/installer/data/mysql/userpermissions.sql @@ -59,6 +59,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'), (13, 'upload_general_files', 'Upload any file'), (13, 'upload_manage', 'Manage uploaded files'), + (13, 'edit_pages', 'Create, edit and delete CMS pages for OPAC and staff interfaces'), (15, 'check_expiration', 'Check the expiration of a serial'), (15, 'claim_serials', 'Claim missing serials'), (15, 'create_subscription', 'Create a new subscription'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index 7c6275a..aacd57b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -58,6 +58,7 @@ [%- CASE 'delete_anonymize_patrons' -%]Delete old borrowers and anonymize circulation history (deletes borrower reading history) [%- CASE 'edit_calendar' -%]Define days when the library is closed [%- CASE 'edit_news' -%]Write news for the OPAC and staff interfaces + [%- CASE 'edit_pages' -%]Create, edit and delete CMS pages for OPAC and staff interfaces [%- CASE 'edit_notice_status_triggers' -%]Set notice/status triggers for overdue items [%- CASE 'edit_notices' -%]Define notices [%- CASE 'edit_patrons' -%]Perform batch modification of patrons diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt new file mode 100644 index 0000000..99f539d --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt @@ -0,0 +1,238 @@ +[% USE KohaDates %] +[% USE Koha %] +[% SET link_opac_base = Koha.Preference( 'OPACBaseURL' ) %] +[% SET link_opac = link_opac_base _ '/cgi-bin/koha/opac-cmspages.pl' %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Tools › Pages +[% INCLUDE 'doc-head-close.inc' %] +[% IF ( opac_page_count ) %] + + [% INCLUDE 'datatables.inc' %] + +[% END %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'cat-search.inc' %] + + +[% IF ( form ) %]
[% ELSE %]
[% END %] +
+
+
+ +[% UNLESS ( link_opac_base && link_self) %] +
+ [% UNLESS ( link_opac_base ) %] + Warning: Preference OPACBaseURL not set, some links might not work!
+ [% END %] + [% UNLESS ( link_self ) %] + Warning: Variable link_self not set, some links might not work!
+ [% END %] +[% END %] +[% UNLESS ( form ) %] + [% IF error_message == 'title_missing' %] +
Error: Required page title missing!
+ [% END %] + +[% END %] +
DEBUG: [% debug %]
+
DEBUG2: data.location: [% data.location %] data.branchcode: [% data.branchcode %]
+[% IF ( form ) %] +
+ + +
+ Page +
    +
  1. + + +
  2. +
  3. + + +
  4. +
  5. + +
    LANG: [% lang %]
    + +
  6. +
  7. + + +
  8. +
  9. + + Required +
  10. +
  11. + + +
  12. +
  13. + + +
  14. +
  15. + + +
  16. +
  17. + +
  18. +
+
+
Cancel
+
+ [% ELSE %] +
+
+ + + + + + + + + +
+
+ [% IF ( page_list_count ) %] +
+ + + + + + + + + + + + + + + [% FOREACH page_lis IN page_list %] + + + + + + + + + + + + + + [% END %] +
 Pub.ParentLoc.Lib.Lang.Num.Link titlePage title  
+ + [% IF ( page_lis.publish ) %]Yes[% ELSE %]No[% END %][% page_lis.parent.title_link %][% SWITCH page_lis.display %] + [% CASE "0" %] + OPAC + [% CASE "1" %] + Staff interface + [% CASE "" %] + All + [% END %] + [% IF ( page_lis.branch == "" ) %] + All + [% ELSE %][% page_lis.branchname %] + [% END %][% IF ( page_lis.langcode == "" ) %]All[% ELSE %] + [% page_lis.langcode %][% END %][% page_lis.sortorder %][% page_lis.title_link %][% page_lis.title %]EditView
+ +
+
+ [% ELSE %] +

No pages exists

+ [% END %] + [% END %] +
+
+[% UNLESS ( form ) %] +
+ [% INCLUDE 'tools-menu.inc' %] +
+[% END %] +
+[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt index 4c8cca9..22efd3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt @@ -94,6 +94,11 @@
Write news for the OPAC and staff interfaces
[% END %] + [% IF ( CAN_user_tools_edit_pages ) %] +
Pages
+
Create and edit additional content pages
+ [% END %] + [% IF ( CAN_user_tools_schedule_tasks ) %]
Task scheduler
Schedule tasks to run
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc index e2ff5fa..94ba131 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc @@ -291,6 +291,20 @@ [% END %]
+
+ [% IF ( cms_nav_top ) %] +
    + [% WHILE ( cms_item = cms_nav_top.next ) %] + [% IF ( cms_item.id == cms_page.id ) %] +
  • + [% ELSE %] +
  • + [% END %] + [% cms_item.title_link %]
  • + [% END %] +
+ [% END %] +
[% END # / OpacPublic %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/navigation.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/navigation.inc index 1926c1e..89921a0 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/navigation.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/navigation.inc @@ -1,4 +1,12 @@ -
[% OpacNav %]
+
+[% IF ( cms_nav_left ) %] + +[% END %] +[% OpacNav %]
[% IF IsPatronPage %]
[% INCLUDE usermenu.inc %]
[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-cmspages.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-cmspages.tt new file mode 100644 index 0000000..9bc3e35 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-cmspages.tt @@ -0,0 +1,89 @@ +[% USE Koha %] +[% USE Branches %] +[% INCLUDE 'doc-head-open.inc' %] +[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %][% IF (cms_page.title) %] - [% cms_page.title %][% ELSE %] catalog[% END%] +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %][% END %] + +[% INCLUDE 'bodytag.inc' bodyid='opac-cmspages' %] +[% INCLUDE 'masthead.inc' %] + +
+ + + [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] + [% IF ( loggedinusername ) %] +
+ [% ELSE %] +
+ [% END %] + [% ELSE %] +
+ [% END %] + +
+ [% IF ( OpacNav || OpacNavBottom ) %] +
+ +
+ [% END %] + + [% IF ( OpacNav || OpacNavBottom ) %] +
+ [% ELSE %] +
+ [% END %] + [% cms_page.content %] + [% IF ( OpacMainUserBlock ) %]
[% OpacMainUserBlock %]
[% END %] +
+ + [% IF ( ( Koha.Preference( 'opacuserlogin' ) == 1 ) || OpacNavRight ) %] +
+ [% IF Koha.Preference( 'opacuserlogin' ) == 1 %] + [% UNLESS ( loggedinusername ) %] + [% UNLESS ( casAuthentication || shibbolethAuthentication ) %] +
+
+ +
+ Log in to your account: + + +
+ +
+ [% IF PatronSelfRegistration && PatronSelfRegistrationDefaultCategory %]

Don't have an account? Register here.

[% END %] +
+ [% IF Koha.Preference( 'NoLoginInstructions' ) %] +
+ [% Koha.Preference( 'NoLoginInstructions' ) %] +
+ [% END %] +
+
+ [% END # /casAuthentication %] + [% IF persona %] + Sign in with your email + [% END # /persona %] + [% END # / loggedinusername %] + [% END # /opacuserlogin %] + [% IF ( OpacNavRight ) %] +
+ [% OpacNavRight %] +
+ [% END # /OpacNavRight %] +
+ [% END # /opacuserlogin || OpacNavRight %] + +
+
+
+ +[% INCLUDE 'opac-bottom.inc' %] +[% BLOCK jsinclude %][% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less index 63961e8..0f8340b 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/less/opac.less +++ b/koha-tmpl/opac-tmpl/bootstrap/less/opac.less @@ -199,7 +199,7 @@ td { } #moresearches { - margin: .5em 0; + margin: .5em 0 .5em 0; padding: 0 .8em; li { display: inline; @@ -211,13 +211,49 @@ td { } ul { margin : 0; + display: inline; } + display: inline; } #moresearches li:last-child:after { content : ""; } +#cms_nav_top { + li { + margin-bottom: -1em; + display: inline; + white-space: nowrap; + border-top-left-radius: 5px; + border-top-right-radius: 5px; + background-color: #eee; + border: 1px solid #D2D2CF; + border-bottom: none; + padding: 0.1em 0.8em 0em 0.8em; + font-weight: bold; + font-size: 1.2em; + border-bottom: 1px solid #D2D2CF; + a { + text-decoration: none; + } + &.cms_nav_top_active { + background-color: #fff; + border-bottom: 1px solid #FFF; + } + } + ul { + margin: 0; + display: inline; + } + display: inline; +} + +ul#cms_nav_left { + list-style-type: none; + padding: 0; +} + #news { margin : .5em 0; } @@ -378,7 +414,7 @@ td { border: 1px solid #D2D2CF; .border-radius-all(7px); .shadowed; - margin-top : 0.5em; + margin-top : 1px; margin-bottom: 0.5em; } diff --git a/opac/opac-cmspages.pl b/opac/opac-cmspages.pl new file mode 100755 index 0000000..eaace18 --- /dev/null +++ b/opac/opac-cmspages.pl @@ -0,0 +1,52 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright Halland County Library 2015 +# +# 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 . + +use Modern::Perl; +use CGI; +use C4::Auth; +use C4::Output; +use C4::Languages qw( getTranslatedLanguages accept_language ); +use Koha::CmsPages; + +my $input = new CGI; +my $id = scalar $input->param( 'id' ) // ''; +my $lang = scalar $input->param( 'lang' ) // ''; +my $branch = scalar $input->param( 'branch' ) // ''; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "opac-cmspages.tt", + type => "opac", + query => $input, + authnotrequired => ( C4::Context->preference( "OpacPublic" ) ? 1 : 0 ), + flagsrequired => { borrow => 1 }, + } +); + +my ( $theme, $news_lang, $availablethemes ) = C4::Templates::themelanguage( + C4::Context->config( 'opachtdocs'), 'opac-cmspages.tt', 'opac', $input ); + +my ($cms_nav_top, $cms_nav_left, $cms_data) = Koha::CmsPages->page( $id ); +$template->param( + cms_page => $cms_data, + cms_nav_top => $cms_nav_top, + cms_nav_left => $cms_nav_left, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/opac/opac-main.pl b/opac/opac-main.pl index 2f1f18c..6c8b746 100755 --- a/opac/opac-main.pl +++ b/opac/opac-main.pl @@ -25,6 +25,7 @@ use C4::Output; use C4::NewsChannels; # GetNewsToDisplay use C4::Languages qw(getTranslatedLanguages accept_language); use C4::Koha qw( GetDailyQuote ); +use Koha::CmsPages qw( list ); my $input = new CGI; my $dbh = C4::Context->dbh; @@ -70,7 +71,10 @@ $template->param( daily_quote => $quote, ); -# If GoogleIndicTransliteration system preference is On Set parameter to load Google's javascript in OPAC search screens +$template->param( + cms_nav_top => Koha::CmsPages->child_links( undef ), +); + if (C4::Context->preference('GoogleIndicTransliteration')) { $template->param('GoogleIndicTransliteration' => 1); } diff --git a/t/Pages.t b/t/Pages.t new file mode 100644 index 0000000..5e6d463 --- /dev/null +++ b/t/Pages.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Carp; +use Test::More tests => 2; +use Data::Dumper::Concise; + +BEGIN { + use_ok('C4::Content'); +} + +my $src = [ + { id => '1', parent => '' }, + { id => '2', parent => '1' }, + { id => '3', parent => '1' }, + { id => '4', parent => '2' }, + { id => '5', parent => '2' }, +]; + +my $expected = [ + { id => '1', children => [ + { id => '2', children => [ + { id => '4', children => [] }, + { id => '5', children => [] } ] + }, + { id => '3', children => [] } ] + }, +]; + +my $output = C4::Content::_SQLToPerl($src); +is_deeply($output, $expected); diff --git a/t/db_dependent/Pages.t b/t/db_dependent/Pages.t new file mode 100644 index 0000000..2c98c38 --- /dev/null +++ b/t/db_dependent/Pages.t @@ -0,0 +1,93 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# Copyright Halland County Library 2015. +# +# 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 . + +use Modern::Perl; + +use Test::More tests => 2; +use Test::Warn; +use Data::Dumper::Concise; + +use C4::Context; +use Koha::Database; +use t::lib::TestBuilder; + +BEGIN { + use_ok('Koha::Objects'); + use_ok('Koha::CmsPages'); +} + +my $builder = t::lib::TestBuilder->new(); + +# Start transaction +my $dbh = C4::Context->dbh; +$dbh->{ AutoCommit } = 0; +$dbh->{ RaiseError } = 1; +$dbh->do( 'DELETE FROM items' ); +$dbh->do( 'DELETE FROM borrowers' ); +$dbh->do( 'DELETE FROM branches' ); +$dbh->do( 'DELETE FROM cms_pages' ); + +my $branchcode = $builder->build({ source => 'Branch' }); + +my $page10 = $builder->build({ + source => 'CmsPage', + value => { + parent => undef, + title_link => 'page 10', + title => 'full page 10', + published => 1, + sortorder => 1, + } +}); +my $page11 = $builder->build({ + source => 'CmsPage', + value => { + parent => $page10->{'id'}, + title_link => 'subpage 11', + title => 'full subpage 11', + published => 1, + sortorder => 0, + } +}); +my $page12 = $builder->build({ + source => 'CmsPage', + value => { + parent => $page10->{'id'}, + title_link => 'subpage 12', + title => 'full subpage 12', + published => 1, + sortorder => 1, + } +}); +my $page20 = $builder->build({ + source => 'CmsPage', + value => { + parent => undef, + title_link => 'page 20', + title => 'full page 20', + published => 0, + sortorder => 2, + } +}); + +my $result = Koha::CmsPages->child_links( undef ); +is_deeply( $result, [ $page10, $page20 ]); + +$dbh->rollback(); + +1; diff --git a/tools/cmspages.pl b/tools/cmspages.pl new file mode 100755 index 0000000..314724a --- /dev/null +++ b/tools/cmspages.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Script to manage CMS pages. +# Copyright (C) 2015 Halland County Library +# +# 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 . + +use Modern::Perl; +use CGI qw( -utf8 ); +use C4::Auth; +use C4::Output; +use C4::Languages qw( getTranslatedLanguages ); +use Koha::Database; +use Koha::CmsPages; + +my $link_self = '/cgi-bin/koha/tools/cmspages.pl'; + +my $cgi = new CGI; +my $op = scalar $cgi->param( 'op' ) // ''; +my $id = scalar $cgi->param( 'id' ) // ''; +my $lang = scalar $cgi->param( 'lang' ) // ''; +my $branch = scalar $cgi->param( 'branch' ) // ''; +my $disp = scalar $cgi->param( 'disp' ) // ''; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user({ + template_name => 'tools/cmspages.tt', + query => $cgi, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { tools => 'edit_pages' }, +}); + +# Filter selection +$template->param( + lang => $lang, + branch => $branch, + disp => $disp +); + +my $schema = Koha::Database->new->schema; +my @branches = $schema->resultset( 'Branch' )->all; +$template->param( branch_list => @branches ); + +my $lang_list = getTranslatedLanguages; + +# List all pages, if id is set generate parent page list and data. +my ( $page_list, $parent_list, $page_data ) = Koha::CmsPages->list( $id ); + +$template->param( + page_list_count => scalar $page_list, + page_list => $page_list, + parent_list => $parent_list, + data => $page_data, + lang_list => $lang_list +); + +# Used for adding or editing a page. +if ( $op eq 'form' ) { + $template->param( + form => 1, + id => $id, + op => 'add' + ); +} + +if ( $op eq 'add' ) { + Koha::CmsPages->add( $cgi ); + print $cgi->redirect( $link_self ); + +} elsif ( $op eq 'del' ) { + # param => multi_param; no list-ctx warnings + Koha::CmsPages->remove( $cgi->multi_param( 'ids' ) ); + print $cgi->redirect( $link_self ); +} + +$template->param( link_self => $link_self ); +output_html_with_http_headers $cgi, $cookie, $template->output; -- 2.1.4