commit for holidays and news management.
authortipaul <tipaul>
Fri, 3 Mar 2006 16:35:21 +0000 (16:35 +0000)
committertipaul <tipaul>
Fri, 3 Mar 2006 16:35:21 +0000 (16:35 +0000)
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.

koha-tmpl/intranet-tmpl/prog/en/intranet-main.tmpl
koha-tmpl/intranet-tmpl/prog/en/tools/holidays.tmpl [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/en/tools/koha-news.tmpl [new file with mode: 0644]
tools/exceptionHolidays.pl [new file with mode: 0755]
tools/holidays.pl [new file with mode: 0755]
tools/koha-news.pl [new file with mode: 0755]
tools/newHolidays.pl [new file with mode: 0755]
updater/updatedatabase

index d2653eb..9ad6b65 100644 (file)
                <li><a href="/cgi-bin/koha/admin/systempreferences.pl">System Preferences</a></li><li><a href="/cgi-bin/koha/barcodes/barcodes.pl">Barcodes generator</a></li></ul></li>
 
 </ul>
-
+<div id="news">
+       <h1>News</h1>
+       <!-- TMPL_LOOP name="koha_news" -->
+                       <table>
+                               <tr>
+                               <th>
+                                       <!-- TMPL_VAR NAME="title" --></th>
+                                       <td>
+                                       <!-- TMPL_VAR NAME="new" --> 
+                                       </td>
+                               <td>
+                                               <!-- TMPL_VAR NAME="newdate" --> 
+                                       </td>
+                               </tr>
+                       </table>
+       <!-- /TMPL_LOOP -->
+</div>
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
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 (file)
index 0000000..bcc7877
--- /dev/null
@@ -0,0 +1,214 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->\r
+<!-- TMPL_INCLUDE NAME="holidays-top.inc" -->\r
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->\r
+<!-- TMPL_INCLUDE NAME="menus.inc" -->\r
+<!-- TMPL_INCLUDE NAME="menu-admin.inc" -->\r
+\r
+<!-- ******************************** FLAT PANELS ******************************************* -->\r
+<!-- *****           Makes all the flat panel to deal with holidays                     ***** -->\r
+<!-- **************************************************************************************** -->\r
+\r
+<!-- ********************** Panel for showing already loaded holidays *********************** -->\r
+<div class="panel" style="position:absolute;background-color:#CCCCCC" id="showHoliday">\r
+       <form action="/cgi-bin/koha/tools/exceptionHolidays.pl" method="post" style="display:inline">\r
+               <p onclick="javascript: hidePanel('showHoliday');hidePanel('information')" style="cursor:pointer">\r
+                       Hide Details\r
+                       <img src="<!-- TMPL_VAR NAME="themelang" -->/images/signClose.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle">\r
+               </p>\r
+               <p>\r
+                       <label>Day name</label>\r
+                       <input type="text" size="20" id="showDayname" name="showDayname" readonly\r
+                                                  style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       <input type="hidden" name="showWeekday"/>\r
+               </p>\r
+               <p>\r
+                       <label>Library</label>\r
+                       <input type="text" size="20" id="showBranchName" name="showBranchName" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+               </p>\r
+               <div style="display:inline">\r
+                       Day <input type="text" size="2" id="showDay" name="showDay" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       Month <input type="text" size="2" id="showMonth" name="showMonth" readonly\r
+                                                       style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       Year <input type="text" size="4" id="showYear" name="showYear" readonly\r
+                                                      style="background-color:#FFFFFF;color:Black;font-size:10px;"/>           \r
+               </div>\r
+           <p>Add a description to holiday day.</p>\r
+               <p>\r
+                       <textarea rows="2" cols="40" id="showDescription" name="showDescription"></textarea>    \r
+               </p>\r
+               <div id="exceptionPosibility" style="position:static">\r
+                       <input type="radio" name="showOperation" value="exception"> Generate an exception to this holiday\r
+                       <img src="<!-- TMPL_VAR NAME="themelang" -->/images/more.gif" hspace="0" vspace="0" border="0"   style="vertical-align:middle;cursor:pointer"\r
+                                       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.')">\r
+                       <br>\r
+               </div>\r
+               <input type="radio" name="showOperation" value="delete" checked> Delete this holiday.\r
+               <img src="<!-- TMPL_VAR NAME="themelang" -->/images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer"\r
+                       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.')">\r
+               <p>\r
+                       <input type="submit" name="submit" id="submit" value="Save">\r
+                       <input type="button" name="cancel2" id="cancel2" value="Cancel" onclick="javascript: hidePanel('showHoliday');hidePanel('information')">\r
+               </p>\r
+       </form>\r
+</div>\r
+\r
+<!-- ***************************** Panel to deal with new holidays **********************  -->\r
+<div class="panel" style="position:absolute;background-color:#CCCCCC" id="newHoliday">\r
+       <form action="/cgi-bin/koha/tools/newHolidays.pl" method="post" style="display:inline">\r
+               <h2>\r
+                       Add new holiday\r
+               </h2>\r
+               <p>\r
+                       <label>Day name</label>\r
+                       <input type="text" size="20" id="newDayname" name="newDayname" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       <input type="hidden" name="newWeekday"/>\r
+               </p>\r
+               <p>\r
+                       <label>Library</label>\r
+                       <input type="text" size="20" id="newBranchName" name="newBranchName" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+               </p>\r
+               <div style="display:inline">\r
+                       Day <input type="text" size="2" id="newDay" name="newDay" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       Month <input type="text" size="2" id="newMonth" name="newMonth"  readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+                       Year <input type="text" size="4" id="newYear" name="newYear" readonly style="background-color:#FFFFFF;color:Black;font-size:10px;"/>\r
+               </div>\r
+               <p>\r
+                       <label>Add a description to holiday day</label>\r
+                       <textarea rows="2" cols="40" id="newDescription" name="newDescription"></textarea>\r
+               </p>\r
+                       <input type="radio" name="newOperation" value="holiday" checked> Holiday only on this day.\r
+                       <img src="<!-- TMPL_VAR NAME="themelang" -->/images/more.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle;cursor:pointer"\r
+                       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.')">\r
+                       <br>\r
+                       <input type="radio" name="newOperation" value="weekday"> Holiday repeated every same day of the week\r
+                       <img src="<!-- TMPL_VAR NAME="themelang" -->/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.')">\r
+                       <br>\r
+                       <input type="radio" name="newOperation" value="repeatable">Holiday repeated yearly on the same date.\r
+                       <img src="<!-- TMPL_VAR NAME="themelang" -->/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.')">\r
+                       <p>\r
+                               <input type="submit" name="submit" id="submit" value="Save"/>\r
+                               <input type="button" name="cancel2" id="cancel2" value="Cancel" onclick="javascript: hidePanel('newHoliday');hidePanel('information')">\r
+                       </p>\r
+       </form>\r
+</div>\r
+\r
+\r
+<!-- *************************************************************************************** -->\r
+<!-- ******                          END OF FLAT PANELS                               ****** -->\r
+<!-- *************************************************************************************** -->\r
+\r
+\r
+\r
+<!-- *************************************************************************************** -->\r
+<!-- ******                     START OF INFORMATION PANEL                            ****** -->\r
+<!-- *************************************************************************************** -->\r
+\r
+<div class="information" style="position:absolute" id="information" onclick="javascript: hidePanel('information')" onblur="javascript: hidePanel('information')">\r
+       <table>\r
+               <tr>\r
+                       <td valign="top">\r
+                               <img src="<!-- TMPL_VAR NAME="themelang" -->/images/info.gif" hspace="0" vspace="0" border="0" style="vertical-align:middle">\r
+                       </td>\r
+                       <td valign="top">\r
+                               <p id="explanation" style="display:inline;align:justify"></p>\r
+                       </td>\r
+               </tr>\r
+       </table>\r
+</div>\r
+\r
+<!-- ************************************************************************************** -->\r
+<!-- ******                      END OF INFORMATION PANEL                            ****** -->\r
+<!-- ************************************************************************************** -->\r
+\r
+\r
+\r
+<h1>Define the holidays for branch <!-- TMPL_VAR name="BRANCHES" --></h1>\r
+       <ul>\r
+               <li>Search in the calendar the day you want to set as holiday.</li>\r
+               <li>Complete the information in the right area.</li>\r
+               <li>Once you finish the steps above, click Save.</li>\r
+       </ul>\r
+       <p>\r
+               <span class="normalday">Working day</span>\r
+               <span class="holiday">Unique holiday</span>\r
+               <span class="repeatableday">Repetible holiday</span>\r
+               <span class="exception">Holiday exception</span>\r
+       </p>\r
+\r
+<!-- ************************************************************************************** -->\r
+<!-- ******                              MAIN SCREEN CODE                            ****** -->\r
+<!-- ************************************************************************************** -->\r
+<h2>Calendar information</h2>\r
+<div id="calendar-container">\r
+<script type="text/javascript">\r
+       /* Creates all the structures to deal with all diferents kinds of holidays */\r
+       var week_days = new Array();\r
+       var holidays = new Array();\r
+       var exception_holidays = new Array();\r
+       var day_month_holidays = new Array();\r
+       var hola= "<!-- TMPL_VAR NAME="code" -->";\r
+       <!-- TMPL_LOOP NAME="WEEK_DAYS_LOOP" -->\r
+       week_days["<!-- TMPL_VAR NAME="KEY" -->"] = {title:"<!-- TMPL_VAR NAME="TITLE" -->", description:"<!-- TMPL_VAR NAME="DESCRIPTION" -->"};\r
+       <!-- /TMPL_LOOP -->\r
+       <!-- TMPL_LOOP NAME="HOLIDAYS_LOOP" -->\r
+       holidays["<!-- TMPL_VAR NAME="KEY" -->"] = {title:"<!-- TMPL_VAR NAME="TITLE" -->", description:"<!-- TMPL_VAR NAME="DESCRIPTION" -->"};\r
+       <!-- /TMPL_LOOP -->\r
+       <!-- TMPL_LOOP NAME="EXCEPTION_HOLIDAYS_LOOP" -->\r
+       exception_holidays["<!-- TMPL_VAR NAME="KEY" -->"] = {title:"<!-- TMPL_VAR NAME="TITLE" -->", description:"<!-- TMPL_VAR NAME="DESCRIPTION" -->"};\r
+       <!-- /TMPL_LOOP -->\r
+       <!-- TMPL_LOOP NAME="DAY_MONTH_HOLIDAYS_LOOP" -->\r
+       day_month_holidays["<!-- TMPL_VAR NAME="KEY" -->"] = {title:"<!-- TMPL_VAR NAME="TITLE" -->", description:"<!-- TMPL_VAR NAME="DESCRIPTION" -->"};\r
+       <!-- /TMPL_LOOP -->\r
+\r
+       /* This function gives css clases to each kind of day */\r
+       function dateStatusHandler(date) {\r
+               var day = date.getDate();\r
+               var month = date.getMonth() + 1;\r
+               var year = date.getFullYear();\r
+               var weekDay = date.getDay();\r
+               var dayMonth = month + '/' + day;\r
+               var dateString = year + '/' + month + '/' + day;\r
+               if (exception_holidays[dateString] != null) {\r
+                       return 'exception';\r
+               } else if ((week_days[weekDay] != null) || (day_month_holidays[dayMonth] != null)) {\r
+                       return 'repeatableday';\r
+               } else if (holidays[dateString] != null) {\r
+                       return 'holiday';\r
+               } else {\r
+                       return 'normalday';\r
+               }\r
+       }\r
+\r
+       /* This function is in charge of showing the correct panel considering the kind of holiday */\r
+       function dateChanged(calendar) {\r
+               var day = calendar.date.getDate();\r
+               var month = calendar.date.getMonth() + 1;\r
+               var year = calendar.date.getFullYear();\r
+               var weekDay = calendar.date.getDay();\r
+               var dayName = calendar.date.print('%A');\r
+               var dayMonth = month + '/' + day;\r
+               var dateString = year + '/' + month + '/' + day;\r
+               if (calendar.dateClicked) {\r
+                       if (holidays[dateString] != null) {\r
+                               showHoliday(0, dayName, day, month, year, weekDay, holidays[dateString].title,  holidays[dateString].description);\r
+                       } else if (exception_holidays[dateString] != null) {\r
+                               showHoliday(0, dayName, day, month, year, weekDay, exception_holidays[dateString].title, exception_holidays[dateString].description);\r
+                       } else if (week_days[weekDay] != null) {\r
+                               showHoliday(1, dayName, day, month, year, weekDay, week_days[weekDay].title,    week_days[weekDay].description);\r
+                       } else if (day_month_holidays[dayMonth] != null) {\r
+                               showHoliday(1, dayName, day, month, year, weekDay, day_month_holidays[dayMonth].title, day_month_holidays[dayMonth].description);\r
+                       } else {\r
+                               newHoliday(dayName, day, month, year, weekDay);\r
+                       }\r
+               }\r
+       };\r
+       Calendar.setup(\r
+               {\r
+                       flat : "calendar-container",\r
+                       flatCallback : dateChanged,\r
+                       dateStatusFunc : dateStatusHandler\r
+               }\r
+       );\r
+</script>\r
+</div>\r
+<!-- TMPL_INCLUDE NAME="holidays-bottom.inc" -->\r
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 (file)
index 0000000..6cab008
--- /dev/null
@@ -0,0 +1,101 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->\r
+<!-- TMPL_INCLUDE NAME="holidays-top.inc" -->\r
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->\r
+<!-- TMPL_INCLUDE NAME="menus.inc" -->\r
+<!-- TMPL_INCLUDE NAME="menu-admin.inc" -->\r
+\r
+<div id="koha-news_main">\r
+       <h1> OPAC & KOHA News</h1>\r
+       <!-- TMPL_IF name="add_form" -->\r
+               <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" >\r
+                       <input type="hidden" name="op" value="<!-- TMPL_VAR NAME="op" -->" />\r
+                       <input type="hidden" name="id" value="<!-- TMPL_VAR NAME="id" -->" />\r
+                       <p>\r
+                       <select name="lang">\r
+                               <option value="koha">Librarian interface</option>\r
+                               <!-- TMPL_LOOP name="lang_list" -->\r
+                                       <!-- TMPL_IF name="selected" -->\r
+                                               <option value="<!-- TMPL_VAR name="language" -->" selected>\r
+                                       <!-- TMPL_ELSE -->\r
+                                               <option value="<!-- TMPL_VAR name="language" -->">\r
+                                       <!-- /TMPL_IF -->\r
+                                               <!-- TMPL_VAR name="language" -->\r
+                                       </option>\r
+                               <!-- /TMPL_LOOP" -->\r
+                       </select>\r
+                       </p>\r
+                       <p>\r
+                               <label>Title</label>\r
+                               <input size="30" type="text" name="title" value="<!-- TMPL_VAR NAME="title" -->" />\r
+                       </p>\r
+                       <p>News</p>\r
+                       <textarea name="new" cols="35" rows="4"><!-- TMPL_VAR NAME="new" --></textarea>\r
+                       <p>\r
+                               <input class="button" type="submit" value="Save" />\r
+                               <input class="button" type="button" value="Cancel" onclick="window.location.href='/cgi-bin/koha/tools/opac-news.pl'" />\r
+                       </p>\r
+               </form>\r
+       <!-- TMPL_ELSE -->\r
+               <div id="koha-news_filter">\r
+                       <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" />\r
+                       <label>Language</label>\r
+                       <select name="lang">\r
+                       <option value="">All</option>\r
+                       <option value="koha">Librarian interface</option>\r
+                               <!-- TMPL_LOOP name="lang_list" -->\r
+                                       <!-- TMPL_IF name="selected" -->\r
+                                               <option value="<!-- TMPL_VAR name="language" -->" selected />\r
+                                       <!-- TMPL_ELSE -->\r
+                                               <option value="<!-- TMPL_VAR name="language" -->" />\r
+                                       <!-- /TMPL_IF -->\r
+                                               <!-- TMPL_VAR name="language" -->\r
+                                       </option>\r
+                               <!-- /TMPL_LOOP" -->\r
+                       </select>\r
+                       <input type="submit" class="button" value="Filter">\r
+                       </form>\r
+               </div>\r
+               <!-- TMPL_IF NAME="opac_news_count" -->\r
+               <div id="koha-news_list">\r
+                       <form name="del_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl" onsubmit="return confirm('Are you sure you want to delete the selected news?')">\r
+                               <table>\r
+                                       <tr>\r
+                                               <th></th>\r
+                                               <th>Language</th>\r
+                                               <th>Date</th>\r
+                                               <th>Title</th>\r
+                                               <th>News</th>\r
+                                               <th></th>\r
+                                       </tr>\r
+                                       <!-- TMPL_LOOP NAME="opac_news" -->\r
+                                               <tr>\r
+                                                       <td>\r
+                                                               <input type="checkbox" name="ids" value="<!-- TMPL_VAR NAME="idnew" -->" />\r
+                                                       </td>\r
+                                                       <td><!-- TMPL_VAR NAME="lang" --></td>\r
+                                                       <td><!-- TMPL_VAR NAME="newdate" --></td>\r
+                                                       <td><!-- TMPL_VAR NAME="title" --></td>\r
+                                                       <td><!-- TMPL_VAR NAME="new" --></td>\r
+                                                       <td>\r
+                                                               <a href="/cgi-bin/koha/tools/koha-news.pl?op=add_form&id=<!-- TMPL_VAR NAME="idnew" -->">Edit</a>\r
+                                                       </td>\r
+                                               </tr>\r
+                                       <!-- /TMPL_LOOP -->\r
+                               </table>\r
+                               <p>\r
+                                       <input type="hidden" name="op" value="del" />\r
+                                       <input type="submit" class="button" value="Delete selected" />\r
+                               </p>\r
+                       </form>\r
+               <!-- TMPL_ELSE -->\r
+                       <p>No news loaded</p>\r
+               <!-- /TMPL_IF -->\r
+               <form name="add_form" method="post" action="/cgi-bin/koha/tools/koha-news.pl">\r
+                       <input type="hidden" name="op" value="add_form" />\r
+                       <input type="submit" class="button" value="Add news" />\r
+               </form>\r
+       </div>\r
+       <!-- /TMPL_IF -->\r
+\r
+</div>\r
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->\r
diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl
new file mode 100755 (executable)
index 0000000..ed5e976
--- /dev/null
@@ -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 (executable)
index 0000000..f4b5c79
--- /dev/null
@@ -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 (executable)
index 0000000..ccf455d
--- /dev/null
@@ -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 (executable)
index 0000000..9a8345c
--- /dev/null
@@ -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");
index 7384058..7721788 100755 (executable)
@@ -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.
 #