From 2373f47a76fa8249d9700321eebe713214707afa Mon Sep 17 00:00:00 2001 From: tipaul Date: Fri, 3 Mar 2006 16:35:21 +0000 Subject: [PATCH] commit for holidays and news management. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Contrib from Tümer Garip (from Turkey) : * holiday : in /tools/ the holiday.pl script let you define holidays (days where the library is closed), branch by branch. You can define 3 types of holidays : - single day : only this day is closed - repet weekly (like "sunday") : the day is holiday every week - repet yearly (like "July, 4") : this day is closed every year. You can also put exception : - sunday is holiday, but "2006 March, 5th" the library will be open The holidays are used for return date calculation : the return date is set to the next date where the library is open. A systempreference (useDaysMode) set ON (Calendar) or OFF (Normal) the calendar calculation. --- .../intranet-tmpl/prog/en/intranet-main.tmpl | 18 +- .../intranet-tmpl/prog/en/tools/holidays.tmpl | 214 ++++++++++++++++++ .../prog/en/tools/koha-news.tmpl | 101 +++++++++ tools/exceptionHolidays.pl | 38 ++++ tools/holidays.pl | 103 +++++++++ tools/koha-news.pl | 98 ++++++++ tools/newHolidays.pl | 43 ++++ updater/updatedatabase | 53 ++++- 8 files changed, 663 insertions(+), 5 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/holidays.tmpl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/tools/koha-news.tmpl create mode 100755 tools/exceptionHolidays.pl create mode 100755 tools/holidays.pl create mode 100755 tools/koha-news.pl create mode 100755 tools/newHolidays.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/intranet-main.tmpl b/koha-tmpl/intranet-tmpl/prog/en/intranet-main.tmpl index d2653eb6f6..9ad6b65784 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/intranet-main.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/intranet-main.tmpl @@ -70,5 +70,21 @@
  • System Preferences
  • Barcodes generator
  • - +
    +

    News

    + + + + + + + +
    + + + + +
    + +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/holidays.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/holidays.tmpl new file mode 100644 index 0000000000..bcc7877bb4 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/holidays.tmpl @@ -0,0 +1,214 @@ + + + + + + + + + + + +
    +
    +

    + Hide Details + /images/signClose.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle"> +

    +

    + + + +

    +

    + + +

    +
    + Day + Month + Year +
    +

    Add a description to holiday day.

    +

    + +

    +
    + Generate an exception to this holiday + /images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer" + onclick="javascript: additionalInformation('You can make an exception for this holiday rule. This means that you will be able to say for a repeatable holiday, that there is one of those days that is going to be an exception.')"> +
    +
    + Delete this holiday. + /images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer" + onclick="javascript: additionalInformation('This will delete this holiday rule. In case it is a repeatable holiday, this option checks for posible exceptions. In case those exists, this option take care of set this exceptions to regular holidays.')"> +

    + + +

    +
    +
    + + +
    +
    +

    + Add new holiday +

    +

    + + + +

    +

    + + +

    +
    + Day + Month + Year +
    +

    + + +

    + Holiday only on this day. + /images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer" + onclick="javascript: additionalInformation('This will take this date to make it holiday just for this time. Through this option, you can set a single holiday. For example, suppose you are in August 1st, and only for this year you want to make it holiday.')"> +
    + Holiday repeated every same day of the week + /images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer" onclick="javascript: additionalInformation('This will take this week day and make it holiday. No matter what date it is, this option will repeat this rule for every week. For example, if this date correspond to a saturday, every saturdays will be holidays.')"> +
    + Holiday repeated yearly on the same date. + /images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer" onclick="javascript: additionalInformation('This will take this day and month as a reference to make it holiday. Through this option, you can repeat this rule for every year. For example, if this date correspond to a August 1st, every August 1st will be holiday, no matter what year you are.')"> +

    + + +

    +
    +
    + + + + + + + + + + + + +
    + + + + + +
    + /images/info.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle"> + +

    +
    +
    + + + + + + + +

    Define the holidays for branch

    + +

    + Working day + Unique holiday + Repetible holiday + Holiday exception +

    + + + + +

    Calendar information

    +
    + +
    + diff --git a/koha-tmpl/intranet-tmpl/prog/en/tools/koha-news.tmpl b/koha-tmpl/intranet-tmpl/prog/en/tools/koha-news.tmpl new file mode 100644 index 0000000000..6cab008a9e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/tools/koha-news.tmpl @@ -0,0 +1,101 @@ + + + + + + +
    +

    OPAC & KOHA News

    + +
    + " /> + " /> +

    + +

    +

    + + " /> +

    +

    News

    + +

    + + +

    +
    + +
    +
    + + + +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + +
    LanguageDateTitleNews
    + " /> + + ">Edit +
    +

    + + +

    +
    + +

    No news loaded

    + +
    + + +
    +
    + + +
    + diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl new file mode 100755 index 0000000000..ed5e976d0c --- /dev/null +++ b/tools/exceptionHolidays.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use strict; +use CGI; + +use C4::Auth; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Database; +use HTML::Template; +use C4::Calendar; + +my $input = new CGI; +my $dbh = C4::Context->dbh(); + +my $branchcode = $input->param('showBranchName'); +my $weekday = $input->param('showWeekday'); +my $day = $input->param('showDay'); +my $month = $input->param('showMonth'); +my $year = $input->param('showYear'); +my $title = $input->param('showTitle'); +my $description = $input->param('showDescription'); + +my $calendar = C4::Calendar->new(branchcode => $branchcode); + +if ($input->param('showOperation') eq 'exception') { + $calendar->insert_exception_holiday(day => $day, + month => $month, + year => $year, + title => $title, + description => $description); +} elsif ($input->param('showOperation') eq 'delete') { + $calendar->delete_holiday(weekday => $weekday, + day => $day, + month => $month, + year => $year); +} +print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode"); diff --git a/tools/holidays.pl b/tools/holidays.pl new file mode 100755 index 0000000000..f4b5c7909a --- /dev/null +++ b/tools/holidays.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl +#####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG +use strict; +use CGI; + +use C4::Auth; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Database; +use HTML::Template; +use C4::Calendar; + +my $input = new CGI; +#my $branch = $input->param('branch'); +my $branch=C4::Context->preference('defaultbranch') || $input->param('branch'); +my $dbh = C4::Context->dbh(); +# Get the template to use +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "tools/holidays.tmpl", + type => "intranet", + query => $input, + authnotrequired => 0, + flagsrequired => {parameters => 1}, + debug => 1, + }); + +# Set all the branches. +my $branches = $dbh->prepare("select branchcode, branchname from branches"); +$branches->execute; +# It creates a list of branches +my %list; +while (my ($branchcode, $branchname) = $branches->fetchrow) { + $list{$branchcode} = $branchname; +} +my @listValues = keys(%list); +if (!defined($branch)) { + $branch =$listValues[4]; +} +my $branchesList = CGI::scrolling_list(-name => 'branch', + -values => \@listValues, + -labels => \%list, + -size => 1, + -default => [$branch], + -multiple => 0, + -id => "branch", + -onChange => "changeBranch()"); + +$branches->finish; + +# Get all the holidays +warn "BRANCH : $branch"; +my $calendar = C4::Calendar->new(branchcode => $branch); +my $week_days_holidays = $calendar->get_week_days_holidays(); +my @week_days; +foreach my $weekday (keys %$week_days_holidays) { +warn "WEEK DAY : $weekday"; + my %week_day; + %week_day = (KEY => $weekday, + TITLE => $week_days_holidays->{$weekday}{title}, + DESCRIPTION => $week_days_holidays->{$weekday}{description}); + push @week_days, \%week_day; +} + +my $day_month_holidays = $calendar->get_day_month_holidays(); +my @day_month_holidays; +foreach my $monthDay (keys %$day_month_holidays) { + my %day_month; + %day_month = (KEY => $monthDay, + TITLE => $day_month_holidays->{$monthDay}{title}, + DESCRIPTION => $day_month_holidays->{$monthDay}{description}); + push @day_month_holidays, \%day_month; +} + +my $exception_holidays = $calendar->get_exception_holidays(); +my @exception_holidays; +foreach my $yearMonthDay (keys %$exception_holidays) { + my %exception_holiday; + %exception_holiday = (KEY => $yearMonthDay, + TITLE => $exception_holidays->{$yearMonthDay}{title}, + DESCRIPTION => $exception_holidays->{$yearMonthDay}{description}); + push @exception_holidays, \%exception_holiday; +} + +my $single_holidays = $calendar->get_single_holidays(); +my @holidays; +foreach my $yearMonthDay (keys %$single_holidays) { + my %holiday; + %holiday = (KEY => $yearMonthDay, + TITLE => $single_holidays->{$yearMonthDay}{title}, + DESCRIPTION => $single_holidays->{$yearMonthDay}{description}); + push @holidays, \%holiday; +} + +# Replace the template values with the real ones +$template->param(BRANCHES => $branchesList); +$template->param(WEEK_DAYS_LOOP => \@week_days); +$template->param(HOLIDAYS_LOOP => \@holidays); +$template->param(EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays); +$template->param(DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays); +$template->param(branch => $branch); + +# Shows the template with the real values replaced +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/tools/koha-news.pl b/tools/koha-news.pl new file mode 100755 index 0000000000..ccf455d26b --- /dev/null +++ b/tools/koha-news.pl @@ -0,0 +1,98 @@ +#!/usr/bin/perl + +# Script to manage the opac news. +# written 11/04 +# Castañeda, Carlos Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina +# Modified to include news to KOHA intranet - tgarip@neu.edu.tr NEU library -Cyprus +# Copyright 2000-2002 Katipo Communications +# +# 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 2 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., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use CGI; + +use C4::Auth; +use C4::Koha; +use C4::Context; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::NewsChannels; +use HTML::Template; + +my $cgi = new CGI; + +my $id = $cgi->param('id'); +my $title = $cgi->param('title'); +my $new = $cgi->param('new'); +my $lang = $cgi->param('lang'); +my $new_detail = get_opac_new($id); + +my ($template, $borrowernumber, $cookie) + = get_template_and_user({template_name => "tools/koha-news.tmpl", + query => $cgi, + type => "intranet", + authnotrequired => 0, + flagsrequired => {management => 1}, + debug => 1, + }); + +# get lang list +my @lang_list; + +foreach my $language (getalllanguages()) { + push @lang_list, { language => $language, + selected => ($new_detail->{lang} eq $language?1:0), + }; +} +$template->param(lang_list => \@lang_list); + +my $op = $cgi->param('op'); + +if ($op eq 'add_form') { + $template->param(add_form => 1); + if ($id) { + $template->param(op => 'edit'); + $template->param($new_detail); + $template->param(id => $new_detail->{'idnew'}); + } else { + $template->param(op => 'add'); + } + +} elsif ($op eq 'add') { + + add_opac_new($title, $new, $lang); + print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl'); + +} elsif ($op eq 'edit') { + + upd_opac_new($id, $title, $new, $lang); + print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl'); + +} elsif ($op eq 'del') { + my @ids = $cgi->param('ids'); + del_opac_new(join ",", @ids); + print $cgi->redirect('/cgi-bin/koha/tools/koha-news.pl'); + +} else { + + my ($opac_news_count, $opac_news) = &get_opac_news(undef, $lang); + $template->param($lang => 1); + $template->param(opac_news => $opac_news); + $template->param(opac_news_count => $opac_news_count); + +} + +output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl new file mode 100755 index 0000000000..9a8345c985 --- /dev/null +++ b/tools/newHolidays.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl + +use strict; +use CGI; + +use C4::Auth; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::Database; +use HTML::Template; +use C4::Calendar; + +my $input = new CGI; +my $dbh = C4::Context->dbh(); + +my $branchcode = $input->param('newBranchName'); +my $weekday = $input->param('newWeekday'); +my $day = $input->param('newDay'); +my $month = $input->param('newMonth'); +my $year = $input->param('newYear'); +my $title = $input->param('newTitle'); +my $description = $input->param('newDescription'); + +my $calendar = C4::Calendar->new(branchcode => $branchcode); + +if ($input->param('newOperation') eq 'weekday') { + $calendar->insert_week_day_holiday(weekday => $weekday, + title => $title, + description => $description); +} elsif ($input->param('newOperation') eq 'repeatable') { + $calendar->insert_day_month_holiday(day => $day, + month => $month, + title => $title, + description => $description); +} elsif ($input->param('newOperation') eq 'holiday') { + $calendar->insert_single_holiday(day => $day, + month => $month, + year => $year, + title => $title, + description => $description); + +} +print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode"); diff --git a/updater/updatedatabase b/updater/updatedatabase index 7384058926..77217884a9 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -93,6 +93,35 @@ my %requiretables = ( KEY borrowernumber (borrowernumber), KEY type (type,externalid) )", + opac_news => "( + `idnew` int(10) unsigned NOT NULL auto_increment, + `title` varchar(250) NOT NULL default '', + `new` text NOT NULL, + `lang` varchar(4) NOT NULL default '', + `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, + PRIMARY KEY (`idnew`) + )", + repeatable_holidays => "( + `id` int(11) NOT NULL auto_increment, + `branchcode` varchar(4) NOT NULL default '', + `weekday` smallint(6) default NULL, + `day` smallint(6) default NULL, + `month` smallint(6) default NULL, + `title` varchar(50) NOT NULL default '', + `description` text NOT NULL, + PRIMARY KEY (`id`) + )", + special_holidays => "( + `id` int(11) NOT NULL auto_increment, + `branchcode` varchar(4) NOT NULL default '', + `day` smallint(6) NOT NULL default '0', + `month` smallint(6) NOT NULL default '0', + `year` smallint(6) NOT NULL default '0', + `isexception` smallint(1) NOT NULL default '1', + `title` varchar(50) NOT NULL default '', + `description` text NOT NULL, + PRIMARY KEY (`id`) + )", overduerules =>"(`branchcode` varchar(255) NOT NULL default '', `categorycode` char(2) NOT NULL default '', `delay1` int(4) default '0', @@ -913,7 +942,7 @@ foreach my $table ( keys %indexes ) { if ($existingindexes{$key_name} eq 1) { # print "$key_name existing"; } else { - print "Creating $key_name in $table\n"; + print "\tCreating index $key_name in $table\n"; my $sql; if ($row->{indexname} eq 'PRIMARY') { $sql = "alter table $table ADD PRIMARY KEY ($row->{content})"; @@ -944,7 +973,7 @@ foreach my $table ( keys %foreign_keys ) { if ($stat->{'Comment'} =~/$foreign_table/) { # print "$foreign_table existing\n"; } else { - print "Creating $foreign_table in $table\n"; + print "\tCreating foreign key $foreign_table in $table\n"; # first, drop any orphan value in child table if ($row->{onDelete} ne "RESTRICT") { my $sql = "delete from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})"; @@ -1038,11 +1067,12 @@ $sth = $dbh->prepare("show table status"); $sth->execute; while ( my $table = $sth->fetchrow_hashref ) { if ($table->{Engine} ne 'InnoDB') { - $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb"); +# $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb"); print "moving $table->{Name} to InnoDB\n"; } unless ($table->{Collation} =~ /^utf8/) { - $dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); + #$dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); +# $dbh->do("ALTER TABLE $table->{Name} CONVERT TO CHARACTER SET utf8"); # FIXME : maybe a ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 would be better, def char set seems to work fine. If any problem encountered, let's try with convert ! print "moving $table->{Name} to utf8\n"; } else { @@ -1241,6 +1271,21 @@ sub MARCgetitem { exit; # $Log$ +# Revision 1.130 2006/03/03 16:35:21 tipaul +# commit for holidays and news management. +# +# Contrib from Tümer Garip (from Turkey) : +# * holiday : +# in /tools/ the holiday.pl script let you define holidays (days where the library is closed), branch by branch. You can define 3 types of holidays : +# - single day : only this day is closed +# - repet weekly (like "sunday") : the day is holiday every week +# - repet yearly (like "July, 4") : this day is closed every year. +# +# You can also put exception : +# - sunday is holiday, but "2006 March, 5th" the library will be open +# +# The holidays are used for return date calculation : the return date is set to the next date where the library is open. A systempreference (useDaysMode) set ON (Calendar) or OFF (Normal) the calendar calculation. +# # Revision 1.129 2006/02/27 18:19:33 hdl # New table used in overduerules.pl tools page. # -- 2.39.5