Bugzilla – Attachment 54318 Details for
Bug 17015
New Koha Calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17015 - New koha calendar
Bug-17015---New-koha-calendar.patch (text/plain), 73.99 KB, created by
Mehdi Hamidi
on 2016-08-11 18:52:29 UTC
(
hide
)
Description:
Bug 17015 - New koha calendar
Filename:
MIME Type:
Creator:
Mehdi Hamidi
Created:
2016-08-11 18:52:29 UTC
Size:
73.99 KB
patch
obsolete
>From 329fc26247b39f5524820445f2ad6c5395d54f53 Mon Sep 17 00:00:00 2001 >From: mehdi <mehdi@inlibro.com> >Date: Tue, 9 Aug 2016 15:03:29 -0400 >Subject: [PATCH] Bug 17015 - New koha calendar > >--- > .../atomicupdate/bug_17015_add_holidaytype.sql | 9 + > .../prog/en/modules/tools/discrete_calendar.tt | 749 +++++++++++++++++++++ > .../prog/en/modules/tools/tools-home.tt | 15 +- > misc/cronjobs/add_days_discrete_calendar.pl | 119 ++++ > misc/generate_discrete_calendar.pl | 172 +++++ > tools/discrete_calendar.pl | 476 +++++++++++++ > 6 files changed, 1535 insertions(+), 5 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_17015_add_holidaytype.sql > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt > create mode 100755 misc/cronjobs/add_days_discrete_calendar.pl > create mode 100755 misc/generate_discrete_calendar.pl > create mode 100755 tools/discrete_calendar.pl > >diff --git a/installer/data/mysql/atomicupdate/bug_17015_add_holidaytype.sql b/installer/data/mysql/atomicupdate/bug_17015_add_holidaytype.sql >new file mode 100644 >index 0000000..7eb97ee >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_17015_add_holidaytype.sql >@@ -0,0 +1,9 @@ >+CREATE TABLE `discrete_calendar` ( >+ `date` datetime not NULL, >+ `branchcode` varchar(10) NOT NULL, >+ `isopened` tinyint(1) DEFAULT 1, >+ `holidaytype` varchar(1) default '', >+ `note` varchar(30) DEFAULT NULL, >+ `openhour` time, >+ `closehour` time, >+ PRIMARY KEY (`branchcode`,`date`)); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt >new file mode 100644 >index 0000000..a3c8e24 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt >@@ -0,0 +1,749 @@ >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Tools › [% branchname %] calendar</title> >+[% INCLUDE 'doc-head-close.inc' %] >+[% INCLUDE 'calendar.inc' %] >+<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" /> >+<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css"> >+<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script> >+[% INCLUDE 'datatables.inc' %] >+<script type="text/javascript"> >+//<![CDATA[ >+ var weekdays = new Array(_("Sundays"),_("Mondays"),_("Tuesdays"),_("Wednesdays"),_("Thursdays"),_("Fridays"),_("Saturdays")); >+ $("#jcalendar-container").datepicker({dateFormat:'mm/dd/yy', minDate: new Date(15,10,14) }); >+ /* Creates all the structures to deal with all different kinds of holidays */ >+ var week_days = new Array(); >+ var holidays = new Array(); >+ var day_month_holidays = new Array(); >+ var datesInfos = new Array(); >+ [% FOREACH WEEK_DAYS_LOO IN week_days %] >+ week_days["[% WEEK_DAYS_LOO.weekday %]"] = {title:"[% WEEK_DAYS_LOO.note %]"}; >+ [% END %] >+ [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %] >+ holidays["[% HOLIDAYS_LOO.date %]"] = {outputdate: "[% HOLIDAYS_LOOP.outputdate %]", title:"[% HOLIDAYS_LOO.note %]"}; >+ [% END %] >+ [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN repeatable_holidays %] >+ day_month_holidays["[%DAY_MONTH_HOLIDAYS_LOO.month%]/[% DAY_MONTH_HOLIDAYS_LOO.day %]"] = {title:"[% DAY_MONTH_HOLIDAYS_LOO.note %]"}; >+ [% END %] >+ [% FOREACH date IN datesInfos %] >+ datesInfos["[% date.date %]"] = {title : "[% date.note %]", outputdate : "[% date.outputdate %]", holidaytype:"[% date.holidaytype %]", openhour: "[% date.openhour %]", closehour: "[% date.closehour %]"}; >+ [% END %] >+ >+ function holidayOperation(formObject, opType) { >+ var op = document.getElementsByName('operation'); >+ op[0].value = opType; >+ formObject.submit(); >+ } >+ >+ // This function shows the "Show Holiday" panel // >+ function showHoliday (dayName, day, month, year, weekDay, title, holidayType) { >+ $("#newHoliday").slideUp("fast"); >+ $("#showHoliday").slideDown("fast"); >+ $("#copyHoliday").slideUp("fast"); >+ $('#showDaynameOutput').html(dayName); >+ $('#showDayname').val(dayName); >+ $('#showBranchNameOutput').html($("#branch :selected").text()); >+ $('.showHoliday #BranchName').val($("#branch").val()); >+ $('#showDayOutput').html(day); >+ $('.showHoliday #Day').val(day); >+ $('.showHoliday #Month').val(month); >+ $('.showHoliday #Year').val(year); >+ $('#showMonthOutput').html(month); >+ $('#showYearOutput').html(year); >+ $('.showHoliday #Weekday').val(weekDay); >+ $('.showHoliday #Title').val(title); >+ $('#HolidayType').val(holidayType); >+ >+ if(holidayType == 'weekday') { >+ $("#showOperationDelLabel").html(_("Delete this holiday.")); >+ $("#holtype").attr("class","key repeatableweekly").html(_("Holiday repeating weekly")); >+ } else if(holidayType == 'daymonth') { >+ $("#showOperationDelLabel").html(_("Delete this holiday.")); >+ $("#holtype").attr("class","key repeatableyearly").html(_("Holiday repeating yearly")); >+ } else if(holidayType == 'float') { >+ $("#showOperationDelLabel").html(_("Delete this holiday.")); >+ $("#holtype").attr("class","key float").html(_("Floating holiday")); >+ } else if(holidayType == 'N') { >+ $("#showOperationDelLabel").html(_("Delete this holiday.")); >+ $("#holtype").attr("class","key exception").html(_("Needs validation")); >+ } else { >+ $("#showOperationDelLabel").html(_("Delete this holiday.")); >+ $("#holtype").attr("class","key holiday").html(_("Unique holiday")); >+ } >+ } >+ >+ // This function shows the "Add Holiday" panel // >+ function newHoliday (dayName, day, month, year, weekDay) { >+ $("#showHoliday").slideUp("fast"); >+ $("#copyHoliday").slideUp("fast"); >+ $("#newHoliday").slideDown("fast"); >+ $("#newDaynameOutput").html(dayName); >+ $("#newDayname").val(dayName); >+ $("#newBranchNameOutput").html($('#branch :selected').text()); >+ $(".newHoliday ,#BranchName").val($('#branch').val()); >+ $("#newDayOutput").html(day); >+ $(".newHoliday #Day").val(day); >+ $(".newHoliday #Month").val(month); >+ $(".newHoliday #Year").val(year); >+ $("#newMonthOutput").html(month); >+ $("#newYearOutput").html(year); >+ $(".newHoliday, #Weekday").val(weekDay); >+ } >+ >+ function copyHoliday() { >+ $("#copyHoliday").slideDown("fast"); >+ $("#newHoliday").slideUp("fast"); >+ $("#showHoliday").slideUp("fast"); >+ $(".copyHoliday #showBranchNameOutput").html($('#branch :selected').text()); >+ $(".copyHoliday #newBranch").val($('#branch').val()); >+ } >+ >+ function hidePanel(aPanelName) { >+ $("#"+aPanelName).slideUp("fast"); >+ } >+ >+ function changeBranch () { >+ var branch = $("#branch option:selected").val(); >+ location.href='/cgi-bin/koha/tools/discrete_calendar.pl?branch=' + branch + '&calendardate=' + "[% calendardate %]"; >+ } >+ >+ function Help() { >+ newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes'); >+ } >+ >+ /* This function gives css clases to each kind of day */ >+ function dateStatusHandler(date) { >+ date = getSeparetedDate(date); >+ var day = date.day; >+ var month = date.month; >+ var year = date.year; >+ var weekDay = date.weekDay; >+ var dayName = weekdays[weekDay]; >+ var dayMonth = date.dayMonth; >+ var dateString = date.dateString; >+ >+ if (datesInfos[dateString] && datesInfos[dateString].holidaytype =='W'){ >+ return [true, "repeatableweekly", _("Weekly holiday: %s").format(datesInfos[dateString].title)]; >+ } else if (datesInfos[dateString] && datesInfos[dateString].holidaytype == 'R') { >+ return [true, "repeatableyearly", _("Yearly holiday: %s").format(datesInfos[dateString].title)]; >+ } else if (datesInfos[dateString] && datesInfos[dateString].holidaytype == 'N') { >+ return [true, "exception", _("Need validation: %s").format(datesInfos[dateString].title)]; >+ } else if (datesInfos[dateString] && datesInfos[dateString].holidaytype == 'F') { >+ return [true, "float", _("Floating holiday: %s").format(datesInfos[dateString].title)]; >+ } else if (datesInfos[dateString] && datesInfos[dateString].holidaytype == 'E') { >+ return [true, "holiday", _("Single holiday: %s").format(datesInfos[dateString].title)]; >+ } else { >+ return [true, "normalday", _("Normal day")]; >+ } >+ } >+ >+ /* This function is in charge of showing the correct panel considering the kind of holiday */ >+ function dateChanged(calendar) { >+ calendar = getSeparetedDate(calendar); >+ var day = calendar.day; >+ var month = calendar.month; >+ var year = calendar.year; >+ var weekDay = calendar.weekDay; >+ var dayName = weekdays[weekDay]; >+ var dayMonth = calendar.dayMonth; >+ var dateString = calendar.dateString; >+ //set value of form hidden field fromDate >+ document.getElementById('fromDate').value = dateString; >+ if (datesInfos[dateString].holidaytype =='E') { >+ showHoliday(dayName, day, month, year, weekDay, datesInfos[dateString].title,'ymd'); >+ showDateInfo(dateString); >+ } else if (datesInfos[dateString].holidaytype =='W') { >+ showHoliday(dayName, day, month, year, weekDay, datesInfos[dateString].title, 'weekday'); >+ showDateInfo(dateString); >+ } else if (datesInfos[dateString].holidaytype =='R') { >+ showHoliday(dayName, day, month, year, weekDay, datesInfos[dateString].title, 'daymonth'); >+ showDateInfo(dateString); >+ } else if (datesInfos[dateString].holidaytype =='F') { >+ showHoliday(dayName, day, month, year, weekDay, datesInfos[dateString].title, 'float'); >+ showDateInfo(dateString); >+ } else if (datesInfos[dateString].holidaytype =='N') { >+ showHoliday(dayName, day, month, year, weekDay, datesInfos[dateString].title, 'N'); >+ showDateInfo(dateString); >+ }else { >+ newHoliday(dayName, day, month, year, weekDay); >+ showDateInfo(dateString); >+ } >+ }; >+ >+ function showDateInfo (date){ >+ $("#dateInfo").css('visibility', 'visible'); >+ document.getElementById('openHour').value =datesInfos[date].openhour; >+ document.getElementById('closeHour').value =datesInfos[date].closehour; >+ $('#openHour').timepicker({ >+ timeFormat: 'HH:mm:ss', >+ interval: 15, >+ minTime: '05', >+ maxTime: '23:45', >+ defaultTime: datesInfos[date].openhour, >+ startTime: '05:00', >+ dynamic: false, >+ dropdown: true, >+ scrollbar: true >+ }); >+ $('#closeHour').timepicker({ >+ timeFormat: 'HH:mm:ss', >+ interval: 15, >+ minTime: '05', >+ maxTime: '11:45pm', >+ defaultTime: datesInfos[date].closehour, >+ startTime: '05:00', >+ dynamic: false, >+ dropdown: true, >+ scrollbar: true >+ }); >+ document.getElementById('closeHour').value =datesInfos[date].closehour; >+ document.getElementById('date').innerHTML = datesInfos[date].outputdate; >+ //FIXME >+ if (datesInfos[date].holidaytype !=''){ >+ var type = datesInfos[date].holidaytype; >+ $('#holidayType option[value="'+ type +'"]').attr('selected', true) >+ }else{ >+ $('#holidayType option[value="none"]').attr('selected', true) >+ } >+ $(".dateDetailsPanel ,#BranchName").val($('#branch').val()); >+ >+ } >+ function getSeparetedDate(date){ >+ var mydate = new Array(); >+ var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); >+ var month = ((date.getMonth()+1) < 10 ? '0' : '') + (date.getMonth() +1); >+ var year = date.getFullYear(); >+ var weekDay = date.getDay(); >+ var dayMonth = (date.getMonth()+1) + '/' + date.getDate(); >+ var dateString = year + '-' + month + '-' + day; >+ mydate = {dateObj : date, date : date ,dateString : dateString, dayMonth: dayMonth, weekDay: weekDay, year: year, month: month, day: day}; >+ >+ return mydate; >+ } >+ >+ function validateForm(form){ >+ >+ if(form =='copyHoliday' && document.getElementById('from_copyTo').value){ >+ var from_DateFrom = new Date(document.getElementById('from_copyFrom').value); >+ var from_DateTo = new Date(document.getElementById('from_copyTo').value); >+ var to_DateFrom = new Date(document.getElementById('to_copyFrom').value); >+ var to_DateTo = new Date(document.getElementById('to_copyTo').value); >+ var from_start = Math.floor( from_DateFrom.getTime() / (3600*24*1000)); //days as integer from.. >+ var from_end = Math.floor( from_DateTo.getTime() / (3600*24*1000)); //days as integer from.. >+ var to_start = Math.floor( to_DateFrom.getTime() / (3600*24*1000)); //days as integer from.. >+ var to_end = Math.floor( to_DateTo.getTime() / (3600*24*1000)); //days as integer from.. >+ var from_daysDiff = from_end - from_start; >+ var to_daysDiff = to_end - to_start; >+ if(from_daysDiff == to_daysDiff || from_daysDiff ==1){ >+ document.getElementById('daysnumber').value = to_daysDiff; >+ return true; >+ }else{ >+ alert("You have to pick the same number of days if you choose 2 ranges"); >+ return false; >+ } >+ }else if (form =='changeHours'){ >+ var openhour = document.getElementById('openHour').value; >+ var closehour = document.getElementById('closeHour').value;; >+ var fromDate = document.getElementById('fromDate').value; >+ var toDate = document.getElementById('toDate').value; >+ var message = "You are changing the"; >+ if (openhour) message = message +" open hour to " + openhour + ", "; >+ if (closehour) message = message +" close hour to " + closehour + ", "; >+ if (fromDate) message = message + "From " + fromDate; >+ if (toDate) message = message + "To " + toDate; >+ message+="\n Would you like to continue?"; >+ return confirm(message); >+ }else{ >+ return 1; >+ } >+ } >+ >+ //Check if date range have the same opening, closing hours and holiday type if there's one. >+ function checkRange(date){ >+ date = new Date(date); >+ document.getElementById('toDate').value = getSeparetedDate(date).dateString; >+ var fromDate = new Date($("#jcalendar-container").datepicker("getDate")); >+ var sameHoliday =true; >+ var sameOpenHours =true; >+ var sameCloseHours =true; >+ for (var i = fromDate; i < date ; i.setDate(i.getDate() + 1)) { >+ var myDate1 = getSeparetedDate(i); >+ var date1 = myDate1.dateString; >+ var holidayType1 = datesInfos[date1].holidaytype; >+ var openhours1 = datesInfos[date1].openhour; >+ var closehours1 = datesInfos[date1].closehour; >+ for (var j = fromDate; j < date ; j.setDate(j.getDate() + 1)) { >+ var myDate2 = getSeparetedDate(j); >+ var date2 = myDate2.dateString; >+ var holidayType2 = datesInfos[date2].holidaytype; >+ var openhours2 = datesInfos[date2].openhour; >+ var closehours2 = datesInfos[date2].closehour; >+ >+ if (sameHoliday && holidayType1 != holidayType2){ >+ document.getElementById('holidayType').innerHTML = ''; >+ sameHoliday=false; >+ } >+ if(sameOpenHours && (openhours1 != openhours2)){ >+ document.getElementById('openHour').value =''; >+ sameOpenHours=false; >+ } >+ if(sameCloseHours && (closehours1 != closehours2)){ >+ document.getElementById('closeHour').value =''; >+ sameCloseHours=false; >+ } >+ } >+ if (!sameOpenHours && !sameCloseHours && !sameHoliday){ >+ return false; >+ } >+ } >+ return true; >+} >+ $(document).ready(function() { >+ $(".hint").hide(); >+ $("#branch").change(function(){ >+ changeBranch(); >+ }); >+ $("#holidayweeklyrepeatable>tbody>tr").each(function(){ >+ var first_td = $(this).find('td').first(); >+ first_td.html(weekdays[first_td.html()]); >+ }); >+ $("a.helptext").click(function(){ >+ $(this).parent().find(".hint").toggle(); return false; >+ }); >+ $("#dateofrange").datepicker(); >+ $("#datecancelrange").datepicker(); >+ $("#dateofrange").each(function () { this.value = "" }); >+ $("#datecancelrange").each(function () { this.value = "" }); >+ //Copy holidays From >+ $("#from_copyFromDp").datepicker(); >+ $("#from.copyToDp").datepicker(); >+ $("#from_copyFromDp").each(function () { this.value = "" }); >+ $("#copyToDp").each(function () { this.value = "" }); >+ //Copy holidays To >+ $("#to_copyFromDp").datepicker(); >+ $("#to_copyToDp").datepicker(); >+ $("#to_copyFromDp").each(function () { this.value = "" }); >+ $("#to_copyToDp").each(function () { this.value = "" }); >+ $("#jcalendar-container").datepicker({ >+ beforeShowDay: function(thedate) { >+ return dateStatusHandler(thedate); >+ }, >+ onSelect: function(dateText, inst) { >+ dateChanged($(this).datepicker("getDate")); >+ }, >+ defaultDate: new Date("[% keydate %]"), >+ minDate: new Date("[% minDate %]"), >+ maxDate: new Date("[% maxDate %]") >+ }); >+ $("#dateofrange, #datecancelrange").change(function(){ >+ checkRange($(this).datepicker("getDate")); >+ }); >+ $("#from_copyFromDp").change(function(){ >+ document.getElementById('from_copyFrom').value = getSeparetedDate($(this).datepicker("getDate")).dateString; >+ }); >+ $("#from_copyToDp").change(function(){ >+ document.getElementById('from_copyTo').value = getSeparetedDate($(this).datepicker("getDate")).dateString; >+ }); >+ $("#to_copyFromDp").change(function(){ >+ document.getElementById('to_copyFrom').value = getSeparetedDate($(this).datepicker("getDate")).dateString; >+ }); >+ $("#to_copyToDp").change(function(){ >+ document.getElementById('to_copyTo').value = getSeparetedDate($(this).datepicker("getDate")).dateString; >+ }); >+ $(".hidePanel").on("click",function(){ >+ if( $(this).hasClass("showHoliday") ){ >+ hidePanel("showHoliday"); >+ }if ($(this).hasClass('newHoliday')) { >+ hidePanel("newHoliday"); >+ }else { >+ hidePanel("copyHoliday"); >+ } >+ }) >+ }); >+//]]> >+</script> >+<!-- Datepicker colors --> >+<style type="text/css"> .key { padding : 3px; white-space:nowrap; line-height:230%; } >+.ui-datepicker { font-size : 150%; } >+.ui-datepicker th, .ui-datepicker .ui-datepicker-title select { font-size : 80%; } >+.ui-datepicker td a { padding : .5em; } >+.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { font-size : 80%; } >+.key { padding : 3px; white-space:nowrap; line-height:230%; } >+.normalday { background-color : #EDEDED; color : Black; border : 1px solid #BCBCBC; } >+.ui-datepicker-unselectable { padding :.5em; white-space:nowrap;} >+.ui-state-disabled { padding :.5em; white-space:nowrap;} >+.exception { background-color : #b3d4ff; color : Black; border : 1px solid #BCBCBC; } >+.float { background-color : #66ff33; color : Black; border : 1px solid #BCBCBC; } >+.holiday { background-color : #ffaeae; color : Black; border : 1px solid #BCBCBC; } >+.repeatableweekly { background-color : #FFFF99; color : Black; border : 1px solid #BCBCBC; } >+.repeatableyearly { background-color : #FFCC66; color : Black; border : 1px solid #BCBCBC; } >+td.exception a.ui-state-default { background: #b3d4ff none; color : Black; border : 1px solid #BCBCBC; } >+td.float a.ui-state-default { background: #66ff33 none; color : Black; border : 1px solid #BCBCBC; } >+td.holiday a.ui-state-default { background: #ffaeae none; color : Black; border : 1px solid #BCBCBC; } >+td.repeatableweekly a.ui-state-default { background: #FFFF99 none; color : Black; border : 1px solid #BCBCBC; } >+td.repeatableyearly a.ui-state-default { background: #FFCC66 none; color : Black; border : 1px solid #BCBCBC; } >+.information { z-index : ; background-color : #DCD2F1; width : 300px; display : none; border : 1px solid #000000; color : #000000; font-size : 8pt; font-weight : bold; background-color : #FFD700; cursor : pointer; padding : 2px; } >+.panel { z-index : 1; display : none; border : 3px solid #CCC; padding : 3px; margin-top: .3em; background-color: #FEFEFE; } fieldset.brief { border : 0; margin-top: 0; } >+#showHoliday { margin : .5em 0; } h1 select { width: 20em; } div.yui-b fieldset.brief ol { font-size:100%; } div.yui-b fieldset.brief li, div.yui-b fieldset.brief li.radio { padding:0.2em 0; } .help { margin:.3em 0;border:1px solid #EEE;padding:.3em .7em; font-size : 90%; } #holidayweeklyrepeatable, #holidaysyearlyrepeatable, #holidaysunique, #holidayexceptions { font-size : 90%; margin-bottom : 1em;} .calendar td, .calendar th, .calendar .button, .calendar tbody .day { padding : .7em; font-size: 110%; } .calendar { width: auto; border : 0; } >+.copyHoliday form li{ display:table-row } .copyHoliday form li b, .copyHoliday form li input{ display:table-cell; margin-bottom: 2px; } >+</style> >+</head> >+<body id="tools_holidays" class="tools"> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'cat-search.inc' %] >+ >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › [% branchname %] calendar</div> >+ >+<div id="doc3" class="yui-t1"> >+ >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ <h2>[% branchname %] calendar</h2> >+ <div class="yui-g"> >+ <div class="yui-u first"> >+ <label for="branch">Define the holidays for:</label> >+ <select id="branch" name="branch"> >+ [% FOREACH branchloo IN branchloop %] >+ [% IF ( branchloo.selected ) %] >+ <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option> >+ [% ELSE %] >+ <option value="[% branchloo.value %]">[% branchloo.branchname %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ >+ <h3>Calendar information</h3> >+ <form style="display :flex" method="get" onsubmit="return validateForm('changeHours')"> >+ <div id="jcalendar-container" style="display:inline-block"> >+ </div> >+ >+ <div class="dateDetailsPanel" id="dateInfo" style="margin:0 auto;display:inline-block; visibility:hidden;"> >+ <table style="display :flex"> >+ <tr> >+ <th>Date</th> >+ <th id="date"></th> >+ </tr> >+ <tr> >+ <th>Holiday type</th> >+ <th id="holidayType"> >+ <select name ='holidayType'> >+ <option value="none">Not a holiday</option> >+ <option value="R">Fixed</option> >+ <option value="E">Exception</option> >+ <option value="W">Weekly</option> >+ <option value="F">Floating</option> >+ <option value="N">Need validation</option> >+ </select> >+ </th> >+ </tr> >+ <tr> >+ <th>Open hour</th> >+ <th><input type="text" name="openHour" id='openHour' style="display :flex"></th> >+ </tr> >+ <tr> >+ <th>Close hour</th> >+ <th><input type="text" name="closeHour" id='closeHour' style="display :flex"></th> >+ </tr> >+ </table> >+ <input type="hidden" name="action" value="hourschange"> >+ <input type="hidden" name="branch" value="[%branch%]"> >+ <input type="hidden" name="fromDate" id='fromDate'> >+ <input type="hidden" name="toDate" id='toDate'> >+ <input type="hidden" id="BranchName" name="BranchName" /> >+ <input type="submit" name="submit" value="Update"> >+ </div> >+ </form> >+ <input type="button" name="name" value="Copy holiday" onclick="copyHoliday()"/> >+ <!-- ******************************** FLAT PANELS ******************************************* --> >+ <!-- ***** Makes all the flat panel to deal with holidays ***** --> >+ <!-- **************************************************************************************** --> >+ >+ <!-- ********************** Panel for showing already loaded holidays *********************** --> >+ <div class="panel showHoliday" id="showHoliday"> >+ <form method="post"> >+ <input type="hidden" id="HolidayType" name="HolidayType" value="" /> >+ <fieldset class="brief"> >+ <h3>Edit this holiday</h3> >+ <span id="holtype"></span> >+ <ol> >+ <li> >+ <strong>Library:</strong> <span id="showBranchNameOutput"></span> >+ <input type="hidden" id="BranchName" name="BranchName" /> >+ </li> >+ <li> >+ <strong>From date:</strong> >+ <span id="showDaynameOutput"></span>, >+ >+ [% IF ( dateformat == "us" ) %]<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "metric") %]<span id="showDayOutput"></span>/<span id="showMonthOutput"></span>/<span id="showYearOutput"></span>[% ELSIF ( dateformat == "dmydot") %]<span id="showDayOutput"></span>.<span id="showMonthOutput"></span>.<span id="showYearOutput"></span>[% ELSE %]<span id="showYearOutput"></span>/<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>[% END %] >+ >+ <input type="hidden" id="showDayname" name="showDayname" /> >+ <input type="hidden" id="Weekday" name="Weekday" /> >+ <input type="hidden" id="Day" name="Day" /> >+ <input type="hidden" id="Month" name="Month" /> >+ <input type="hidden" id="Year" name="Year" /> >+ </li> >+ <li class="dateinsert"> >+ <b>To Date : </b> >+ <input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange %]" class="datepicker"/> >+ </li> >+ <li><label for="Title">Title: </label><input type="text" name="Title" id="Title" size="35" /></li> >+ <!-- Title is necessary for exception radio button to work properly --> >+ <li class="radio"><input type="radio" name="Operation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label> >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">This will delete this holiday only.</div></li> >+ <li class="radio"><input type="radio" name="Operation" id="showOperationDel" value="deleteType" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday type</label> >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">This will delete all the holidays of this type expect floats. If it's a weekly holiday on the Mondays, this will remove all the upcoming Mondays holidays. If it's a yearly holiday on 25 December, >+ this will delete all the upcoming holidays on the 25 December</div></li> >+ <li class="radio"><input type="radio" name="Operation" id="showOperationDelRange" value="deleterange" /> <label for="showOperationDelRange" id="showOperationDelLabelRange">Delete the single holidays on a range</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">This will delete all the holidays between two given dates.</div> >+ </li> >+ <li class="radio"><input type="radio" name="Operation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label> >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">This will save changes to the holiday's title and description. If the information for a repeatable holiday is modified, it affects all of the dates on which the holiday is repeated.</div></li> >+ </ol> >+ <fieldset class="action"> >+ <input type="hidden" name="action" value="edit"> >+ <input type="submit" name="submit" value="Save" /> >+ <a href="#" class="cancel hidePanel showHoliday">Cancel</a> >+ </fieldset> >+ </fieldset> >+ </form> >+ </div> >+ >+ <div class="panel copyHoliday" id="copyHoliday"> >+ <form method="post" onsubmit="return validateForm('copyHoliday')"> >+ <input type="hidden" id="HolidayType" name="HolidayType" value="" /> >+ <fieldset class="brief"> >+ <h2>Copy holiday</h2> >+ <span id="holtype"></span> >+ <ol> >+ <li> >+ <strong>Library:</strong> <span id="showBranchNameOutput"></span> >+ <input type="hidden" id="newBranch" name="newBranch" /> >+ </li> >+ <li> >+ <h3>Copy from :</h3> >+ </li> >+ <li class="dateinsert"> >+ <b>From Date : </b> >+ <input type="text" id="from_copyFromDp" size="20" value="[% from_copyFrom %]" class="datepicker"/> >+ <b>To Date : </b> >+ <input type="text" id="from_copyToDp" size="20" value="[% from_copyTo %]" class="datepicker"/> >+ </li> >+ <li> >+ <h3>Apply To : </h3> >+ </li> >+ <li class="dateinsert"> >+ <b>From Date : </b> >+ <input type="text" id="to_copyFromDp" size="20" value="[% to_copyFrom %]" class="datepicker"/> >+ <b>To Date : </b> >+ <input type="text" id="to_copyToDp" size="20" value="[% to_copyTo %]" class="datepicker"/> >+ </li> >+ >+ </ol> >+ <fieldset class="action"> >+ <input type="hidden" name="from_copyFrom" id='from_copyFrom' value=""> >+ <input type="hidden" name="from_copyTo" id='from_copyTo'value=""> >+ <input type="hidden" name="to_copyFrom" id='to_copyFrom'value=""> >+ <input type="hidden" name="to_copyTo" id='to_copyTo'value=""> >+ <input type="hidden" name="daysnumber" id='daysnumber'value=""> >+ <input type="hidden" name="branch" value="[%branch%]"> >+ <input type="hidden" name="action" value="copy"> >+ <input type="submit" name="submit" value="Save" /> >+ <a href="#" class="cancel hidePanel copyHoliday">Cancel</a> >+ </fieldset> >+ </fieldset> >+ </form> >+ >+ <form method="post"> >+ <fieldset class="brief"> >+ <h2>Copy entire calendar</h2> >+ <input type="submit" name="name" value="Copy this calendar to"/> >+ <select id="branchCopy" name="branchCopy"> >+ [% FOREACH branchloo IN branchloop %] >+ <option value="[% branchloo.value %]">[% branchloo.branchname %]</option> >+ [% END %] >+ </select> >+ <input type="hidden" name="branch" value="[%branch%]"/> >+ <input type="hidden" name="action" value="copy"/> >+ <input type="hidden" name="operation" value="copyBranch"/> >+ </fieldset> >+ </form> >+ </div> >+ >+ <!-- ***************************** Panel to deal with new holidays ********************** --> >+ <div class="panel newHoliday" id="newHoliday"> >+ <form method="post"> >+ <input type="hidden" name="branchCodes" id="branchCodes" value="[% branchcodes %]" /> >+ <fieldset class="brief"> >+ <h3>Add new holiday</h3> >+ <ol> >+ <li> >+ <strong>Library:</strong> >+ <span id="newBranchNameOutput"></span> >+ <input type="hidden" id="BranchName" name="BranchName" /> >+ </li> >+ <li> >+ <strong>From date:</strong> >+ <span id="newDaynameOutput"></span>, >+ >+ [% IF ( dateformat == "us" ) %]<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "metric" ) %]<span id="newDayOutput"></span>/<span id="newMonthOutput"></span>/<span id="newYearOutput"></span>[% ELSIF ( dateformat == "dmydot" ) %]<span id="newDayOutput"></span>.<span id="newMonthOutput"></span>.<span id="newYearOutput"></span>[% ELSE %]<span id="newYearOutput"></span>/<span id="newMonthOutput"></span>/<span id="newDayOutput"></span>[% END %] >+ >+ <input type="hidden" id="newDayname" name="showDayname" /> >+ <input type="hidden" id="Weekday" name="Weekday" /> >+ <input type="hidden" id="Day" name="Day" /> >+ <input type="hidden" id="Month" name="Month" /> >+ <input type="hidden" id="Year" name="Year" /> >+ </li> >+ <li class="dateinsert"> >+ <b>To date: </b> >+ <input type="text" id="dateofrange" name="dateofrange" size="20" value="[% dateofrange %]" class="datepicker" /> >+ </li> >+ <li><label for="title">Title: </label><input type="text" name="Title" id="title" size="35" /></li> >+ <li class="radio"><input type="radio" name="Operation" id="newOperationOnce" value="holiday" checked="checked" /> >+ <label for="newOperationOnce">Holiday only on this day</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">Make a single holiday. For example, selecting August 1, 2012 will make it a holiday, but will not affect August 1 in other years.</div> >+ </li> >+ <li class="radio"><input type="radio" name="Operation" id="newOperationDay" value="weekday" /> >+ <label for="newOperationDay">Holiday repeated every same day of the week</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">Make this weekday a holiday, every week. For example, if your library is closed on Saturdays, use this option to make every Saturday a holiday.</div> >+ </li> >+ <li class="radio"><input type="radio" name="Operation" id="newOperationYear" value="repeatable" /> >+ <label for="newOperationYear">Holiday repeated yearly on the same date</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">This will take this day and month as a reference to make it a holiday. Through this option, you can repeat this rule for every year. For example, selecting August 1 will make August 1 a holiday every year.</div> >+ </li> >+ <li class="radio"><input type="radio" name="Operation" id="newOperationField" value="holidayrange" /> >+ <label for="newOperationField">Holidays on a range</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">Make a single holiday on a range. For example, selecting August 1, 2012 and August 10, 2012 will make all days between August 1 and 10 a holiday, but will not affect August 1-10 in other years.</div> >+ </li> >+ <li class="radio"><input type="radio" name="Operation" id="newOperationFieldyear" value="holidayrangerepeat" /> >+ <label for="newOperationFieldyear">Holidays repeated yearly on a range</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1, 2012 and August 10, 2012 will make all days between August 1 and 10 a holiday, and will affect August 1-10 in other years.</div> >+ </li> >+ <li class="radio"> >+ <input type="checkbox" name="allBranches" id="allBranches" /> >+ <label for="allBranches">Copy to all libraries</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">If checked, this holiday will be copied to all libraries. If the holiday already exists for a library, no change is made.</div> >+ </li></ol> >+ <fieldset class="action"> >+ <input type="hidden" name="action" value="add"> >+ <input type="submit" name="submit" value="Save" /> >+ <a href="#" class="cancel hidePanel newHoliday">Cancel</a> >+ </fieldset> >+ </fieldset> >+ </form> >+ </div> >+ >+ <!-- *************************************************************************************** --> >+ <!-- ****** END OF FLAT PANELS ****** --> >+ <!-- *************************************************************************************** --> >+ >+<!-- ************************************************************************************** --> >+<!-- ****** MAIN SCREEN CODE ****** --> >+<!-- ************************************************************************************** --> >+ >+</div> >+<div class="yui-u"> >+<div class="help"> >+<h4>Hints</h4> >+ <ul> >+ <li>Search in the calendar the day you want to set as holiday.</li> >+ <li>Click the date to add or edit a holiday.</li> >+ <li>Specify how the holiday should repeat.</li> >+ <li>Click Save to finish.</li> >+ </ul> >+<h4>Key</h4> >+ <p> >+ <span class="key normalday">Working day</span> >+ <span class="key holiday">Unique holiday</span> >+ <span class="key repeatableweekly">Holiday repeating weekly</span> >+ <span class="key repeatableyearly">Holiday repeating yearly</span> >+ <span class="key exception">Need validation</span> >+ <span class="key float">Floating holiday</span> >+ </p> >+</div> >+<div id="holiday-list"> >+ >+[% IF ( week_days ) %] >+<h3>Weekly - Repeatable holidays</h3> >+<table id="holidayweeklyrepeatable"> >+<thead> >+<tr> >+ <th class="repeatableweekly">Day of week</th> >+ <th class="repeatableweekly">Title</th> >+</tr> >+</thead> >+<tbody> >+ [% FOREACH WEEK_DAYS_LOO IN week_days %] >+ <tr> >+ <td>[% WEEK_DAYS_LOO.weekday %]</td> >+ </td> >+ <td>[% WEEK_DAYS_LOO.note %]</td> >+ </tr> >+ [% END %] >+</tbody> >+</table> >+[% END %] >+ >+[% IF ( repeatable_holidays ) %] >+<h3>Yearly - Repeatable holidays</h3> >+<table id="holidaysyearlyrepeatable"> >+<thead> >+<tr> >+ [% IF ( dateformat == "metric" ) %] >+ <th class="repeatableyearly">Day/month</th> >+ [% ELSE %] >+ <th class="repeatableyearly">Month/day</th> >+ [% END %] >+ <th class="repeatableyearly">Title</th> >+</tr> >+</thead> >+<tbody> >+ [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN repeatable_holidays %] >+ <tr> >+ <td><span title="[% DAY_MONTH_HOLIDAYS_LOO.DATE_SORT %]">[%DAY_MONTH_HOLIDAYS_LOO.month%]/[% DAY_MONTH_HOLIDAYS_LOO.day %]</span></td> >+ <td>[% DAY_MONTH_HOLIDAYS_LOO.note %]</td> >+ </tr> >+ [% END %] >+</tbody> >+</table> >+[% END %] >+ >+[% IF ( HOLIDAYS_LOOP ) %] >+<h3>Unique upcoming holidays</h3> >+<table id="holidaysunique"> >+<thead> >+<tr> >+ <th class="holiday">Date</th> >+ <th class="holiday">Title</th> >+</tr> >+</thead> >+<tbody> >+ [% FOREACH HOLIDAYS_LOO IN HOLIDAYS_LOOP %] >+<tr> >+ <td><a href="/cgi-bin/koha/tools/discrete_calendarte_holiday.pl?branch=[% branch %]&calendardate=[% HOLIDAYS_LOO.date %]"><span title="[% HOLIDAYS_LOO.DATE_SORT %]">[% HOLIDAYS_LOO.outputdate %]</span></a></td> >+ <td>[% HOLIDAYS_LOO.note %]</td> >+</tr> >+ [% END %] >+</tbody> >+</table> >+[% END %] >+</div> >+</div> >+</div> >+</div> >+</div> >+ >+<div class="yui-b noprint"> >+[% INCLUDE 'tools-menu.inc' %] >+</div> >+</div> >+[% 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 09bc4b6..a4b808b 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 >@@ -24,7 +24,7 @@ > <dt><a href="/cgi-bin/koha/reviews/reviewswaiting.pl">Comments</a> [% IF ( pendingcomments ) %]<span class="holdcount"><a href="/cgi-bin/koha/reviews/reviewswaiting.pl">[% pendingcomments %]</a></span>[% END %]</dt> > <dd>Moderate patron comments. </dd> > [% END %] >- >+ > [% IF ( CAN_user_tools_import_patrons ) %] > <dt><a href="/cgi-bin/koha/tools/import_borrowers.pl">Import patrons</a></dt> > <dd>Import patron data</dd> >@@ -39,7 +39,7 @@ > <dt><a href="/cgi-bin/koha/tools/overduerules.pl">Overdue notice/status triggers</a></dt> > <dd>Set notice/status triggers for overdue items</dd> > [% END %] >- >+ > [% IF ( CAN_user_tools_label_creator ) %] > <dt><a href="/cgi-bin/koha/patroncards/home.pl">Patron card creator</a></dt> > <dd>Create printable patron cards</dd> >@@ -74,6 +74,11 @@ > <dd>Define days when the library is closed</dd> > [% END %] > >+ [% IF ( CAN_user_tools_edit_calendar ) %] >+ <dt><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Discrete calendar</a></dt> >+ <dd>Define days when the library is closed</dd> >+ [% END %] >+ > [% IF ( CAN_user_tools_manage_csv_profiles ) %] > <dt><a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a></dt> > <dd>Manage CSV export profiles</dd> >@@ -93,7 +98,7 @@ > <dt><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></dt> > <dd>Schedule tasks to run</dd> > [% END %] >- >+ > [% IF ( CAN_user_tools_edit_quotes ) %] > <dt><a href="/cgi-bin/koha/tools/quotes.pl">Edit quotes for QOTD feature</a></dt> > <dd>Quote editor for Quote-of-the-day feature in OPAC</dd> >@@ -118,7 +123,7 @@ > <dt><a href="/cgi-bin/koha/tools/batchMod.pl?del=1">Batch item deletion</a></dt> > <dd>Delete a batch of items</dd> > [% END %] >- >+ > [% IF ( CAN_user_tools_items_batchmod ) %] > <dt><a href="/cgi-bin/koha/tools/batchMod.pl">Batch item modification</a></dt> > <dd>Modify items in a batch</dd> >@@ -153,7 +158,7 @@ > <dt><a href="/cgi-bin/koha/labels/label-home.pl">Label creator</a></dt> > <dd>Create printable labels and barcodes from catalog data</dd> > [% END %] >- >+ > [% IF ( CAN_user_tools_label_creator ) %] > <dt><a href="/cgi-bin/koha/labels/spinelabel-home.pl">Quick spine label creator</a></dt> > <dd>Enter a barcode to generate a printable spine label. For use with dedicated label printers</dd> >diff --git a/misc/cronjobs/add_days_discrete_calendar.pl b/misc/cronjobs/add_days_discrete_calendar.pl >new file mode 100755 >index 0000000..9a6023a >--- /dev/null >+++ b/misc/cronjobs/add_days_discrete_calendar.pl >@@ -0,0 +1,119 @@ >+#!/usr/bin/perl >+ >+# >+# This script adds one day into discrete_calendar table based on the same day from the week before >+# >+use strict; >+use warnings; >+use DateTime; >+use DateTime::Format::Strptime; >+use Getopt::Long; >+use C4::Context; >+ >+# Options >+my $help = 0; >+GetOptions ( >+ 'help|?|h' => \$help); >+ >+my $usage = << 'ENDUSAGE'; >+ >+This script adds days into discrete_calendar table based on the same day from the week before. >+ >+Examples : >+ The latest date on discrete_calendar is : 28-07-2017 >+ The current date : 01-08-2016 >+ The dates that will be added are : 29-07-2017, 30-07-2017, 31-07-2017, 01-08-2017 >+Open close exemples : >+ Date added is : 29-07-2017 >+ Opening/closing hours will be base on : 22-07-2017 (- 7 days) >+ Library open or closed will be based on : 29-07-2017 (- 1 year) >+This script has the following parameters: >+ -h --help: this message >+ >+PS: This is for testing purposes, the method of knowing whether it's opened or not may be changed. >+ >+ENDUSAGE >+my $dbh = C4::Context->dbh; >+my $query = "select distinct weekday(date), note from discrete_calendar where holidaytype='W'"; >+my $stmt = $dbh->prepare($query); >+$stmt->execute(); >+my @week_days_discrete; >+while (my ($weekday,$note) = $stmt->fetchrow_array){ >+ push @week_days_discrete, {weekday => $weekday, note => $note}; >+} >+ >+exit; >+ >+if ($help) { >+ print $usage; >+ exit; >+} >+#getting the all the branches >+my $selectBranchesSt = 'SELECT branchcode FROM branches'; >+my $selectBranchesSth = $dbh->prepare($selectBranchesSt); >+$selectBranchesSth->execute(); >+my @branches = (); >+while ( my $branchCode = $selectBranchesSth->fetchrow_array ) { >+ >+ push @branches,$branchCode; >+} >+ >+#get the latest date in the table >+$query = "select max(date) from discrete_calendar"; >+$stmt = $dbh->prepare($query); >+$stmt->execute(); >+my $latestedDate = $stmt->fetchrow_array; >+my $parser = DateTime::Format::Strptime->new( >+ pattern => '%Y-%m-%d %H:%M:%S', >+ on_error => 'croak', >+); >+$latestedDate = $parser->parse_datetime($latestedDate); >+ >+my $endDate = DateTime->today; >+$endDate->add(years => 1, days=>1); >+my $newDay = $latestedDate->clone(); >+$endDate->add(days => 20); >+for ($newDay->add(days => 1);$newDay <= $endDate;$newDay->add(days => 1)){ >+ my $lastWeekDay = $newDay->clone(); >+ $lastWeekDay->add(days=> -8); >+ my $dayOfWeek = $lastWeekDay->day_of_week; >+ # Representation fix >+ # DateTime object dow (1-7) where Monday is 1 >+ # Arrays are 0-based where 0 = Sunday, not 7. >+ $dayOfWeek -= 1 unless $dayOfWeek == 7; >+ $dayOfWeek = 0 if $dayOfWeek == 7; >+ >+ #getting the close and opening hour of the same day from last week >+ my $openhour = "select openhour from openinghours where weekcode=?"; >+ $stmt = $dbh->prepare($openhour); >+ $stmt->execute($dayOfWeek); >+ $openhour = $stmt->fetchrow_array; >+ >+ my $closehour = "select closehour from openinghours where weekcode=?"; >+ $stmt = $dbh->prepare($closehour); >+ $stmt->execute($dayOfWeek); >+ $closehour = $stmt->fetchrow_array; >+ >+ #checking if it was open on the same day from last year >+ my $yearAgo = $newDay->clone(); >+ $yearAgo = $yearAgo->add(years => -1); >+ my $last_year = 'select isopened,holidaytype,note from discrete_calendar where date=? and branchcode=?'; >+ my $add_Day = 'INSERT INTO discrete_calendar (date,branchcode,isopened,openhour,closehour) VALUES (?,?,?,?,?)'; >+ >+ #insert into discrete_calendar for each branch >+ foreach my $branchCode(@branches){ >+ $stmt = $dbh->prepare($last_year); >+ $stmt->execute($yearAgo,$branchCode); >+ my ($isOpened, $holidaytype, $note) = $stmt->fetchrow_array; >+ if ($holidaytype && $holidaytype eq "W" || $holidaytype eq 'E'){ >+ $isOpened = 1; >+ $note =''; >+ }elsif ($holidaytype && $holidaytype eq "F"){ >+ $holidaytype = 'N'; >+ } >+ $holidaytype = '' if $isOpened; >+ my $add_Day = 'INSERT INTO discrete_calendar (date,branchcode,isopened,holidaytype, note,openhour,closehour) VALUES (?,?,?,?,?,?,?)'; >+ $stmt = $dbh->prepare($add_Day); >+ $stmt->execute($newDay,$branchCode,$isOpened,$holidaytype,$note, $openhour,$closehour); >+ } >+} >diff --git a/misc/generate_discrete_calendar.pl b/misc/generate_discrete_calendar.pl >new file mode 100755 >index 0000000..5f5f5f0 >--- /dev/null >+++ b/misc/generate_discrete_calendar.pl >@@ -0,0 +1,172 @@ >+#!/usr/bin/perl >+ >+# >+# Script that fills the discrete_calendar table with dates, using the other date-related tables >+# >+use strict; >+use warnings; >+use DateTime; >+use DateTime::Format::Strptime; >+use Getopt::Long; >+use C4::Context; >+ >+# Options >+my $generate = 0; >+my $help = 0; >+my $daysInFuture = 365; >+GetOptions ( >+ 'days|?|d=i' => \$daysInFuture, >+ 'generate' => \$generate, >+ 'help|?|h' => \$help); >+my $usage = << 'ENDUSAGE'; >+ >+Script that manages the discrete_calendar table. >+ >+This script has the following parameters : >+ --days --d : how many days in the future will be created, by default it's 365 >+ -h --help: this message >+ --generate: fills discrete_calendar table with dates from the last two years and the next one >+ >+ENDUSAGE >+ >+if ($help) { >+ print $usage; >+ exit; >+} >+#if ($generate) { >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $currentDate = DateTime->today; >+ >+ # two years ago >+ my $startDate = DateTime->new( >+ day => $currentDate->day(), >+ month => $currentDate->month(), >+ year => $currentDate->year()-2, >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ >+ # a year into the future >+ my $endDate = DateTime->new( >+ day => $currentDate->day(), >+ month => $currentDate->month(), >+ year => $currentDate->year(), >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ $endDate->add(days=> $daysInFuture); >+ >+ # finds branches; >+ my $selectBranchesSt = 'SELECT branchcode FROM branches'; >+ my $selectBranchesSth = $dbh->prepare($selectBranchesSt); >+ $selectBranchesSth->execute(); >+ my @branches = (); >+ while ( my $branchCode = $selectBranchesSth->fetchrow_array ) { >+ >+ push @branches,$branchCode; >+ } >+ >+ # finds what days are closed for each branch >+ my %repeatableHolidaysPerBranch = (); >+ my %specialHolidaysPerBranch = (); >+ my $selectWeeklySt; >+ my $selectWeeklySth; >+ >+ >+ foreach my $branch (@branches){ >+ >+ $selectWeeklySt = 'SELECT weekday, title, day, month FROM repeatable_holidays WHERE branchcode = ?'; >+ $selectWeeklySth = $dbh->prepare($selectWeeklySt); >+ $selectWeeklySth->execute($branch); >+ >+ my @weeklyHolidays = (); >+ >+ while ( my ($weekDay, $title, $day, $month) = $selectWeeklySth->fetchrow_array ) { >+ push @weeklyHolidays,{weekday => $weekDay, title => $title, day => $day, month => $month}; >+ >+ } >+ >+ $repeatableHolidaysPerBranch{$branch} = \@weeklyHolidays; >+ >+ my $selectSpecialHolidayDateSt = 'SELECT day,month,year,title FROM special_holidays WHERE branchcode = ? AND isexception = 0'; >+ my $specialHolidayDatesSth = $dbh->prepare($selectSpecialHolidayDateSt); >+ $specialHolidayDatesSth -> execute($branch); >+ # Tranforms dates from specialHolidays table in DateTime for our new table >+ my @specialHolidayDates = (); >+ while ( my ($day, $month, $year, $title) = $specialHolidayDatesSth->fetchrow_array ) { >+ >+ my $specialHolidayDate = DateTime->new( >+ day => $day, >+ month => $month, >+ year => $year, >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ push @specialHolidayDates,{date=>$specialHolidayDate, title=> $title}; >+ } >+ >+ $specialHolidaysPerBranch{$branch} = \@specialHolidayDates; >+ } >+ # Fills table with dates and sets 'isopened' according to the branch's weekly restrictions (repeatable_holidays) >+ my $insertDateSt; >+ my $insertDateSth; >+ >+ # Loop that does everything in the world >+ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)){ >+ foreach my $branch (@branches){ >+ my $dayOfWeek = $tempDate->day_of_week; >+ # Representation fix >+ # DateTime object dow (1-7) where Monday is 1 >+ # Arrays are 0-based where 0 = Sunday, not 7. >+ $dayOfWeek -=1 unless $dayOfWeek ==7; >+ $dayOfWeek =0 if $dayOfWeek ==7; >+ >+ my $openhour = "select openhour from openinghours where branchcode=? and weekcode=?"; >+ my $stmt = $dbh->prepare($openhour); >+ $stmt->execute($branch,$dayOfWeek); >+ $openhour = $stmt->fetchrow_array; >+ my $closehour = "select closehour from openinghours where branchcode=? and weekcode=?"; >+ $stmt = $dbh->prepare($closehour); >+ $stmt->execute($branch,$dayOfWeek); >+ $closehour = $stmt->fetchrow_array; >+ >+ # Finds closed days >+ my $isOpened =1; >+ my $specialDescription = ""; >+ my $holidaytype =''; >+ $dayOfWeek = $tempDate->day_of_week; >+ foreach my $holidayWeekDay (@{$repeatableHolidaysPerBranch{$branch}}){ >+ if($holidayWeekDay->{weekday} && $dayOfWeek == $holidayWeekDay->{weekday}){ >+ $isOpened = 0; >+ $specialDescription = $holidayWeekDay->{title}; >+ $holidaytype = 'W'; >+ }elsif($holidayWeekDay->{day} && $holidayWeekDay->{month}){ >+ my $date = DateTime->new( >+ day => $holidayWeekDay->{day}, >+ month => $holidayWeekDay->{month}, >+ year => $tempDate->year(), >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ >+ if ($tempDate == $date) { >+ $isOpened = 0; >+ $specialDescription = $holidayWeekDay->{title}; >+ $holidaytype = 'R'; >+ } >+ } >+ } >+ >+ foreach my $specialDate (@{$specialHolidaysPerBranch{$branch}}){ >+ if($tempDate->datetime() eq $specialDate->{date}->datetime() ){ >+ $isOpened = 0; >+ $specialDescription = $specialDate->{title}; >+ $holidaytype = 'E'; >+ } >+ } >+ #final insert statement >+ >+ $insertDateSt = 'INSERT INTO discrete_calendar (date,branchcode,isopened,holidaytype,note,openhour,closehour) VALUES (?,?,?,?,?,?,?)'; >+ $insertDateSth = $dbh->prepare($insertDateSt); >+ $insertDateSth->execute($tempDate,$branch,$isOpened,$holidaytype,$specialDescription,$openhour,$closehour); >+ } >+ } >+#} >diff --git a/tools/discrete_calendar.pl b/tools/discrete_calendar.pl >new file mode 100755 >index 0000000..abfa6be >--- /dev/null >+++ b/tools/discrete_calendar.pl >@@ -0,0 +1,476 @@ >+#!/usr/bin/perl >+ >+# 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>. >+ >+#####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG >+use strict; >+use warnings; >+ >+use CGI qw ( -utf8 ); >+use DateTime; >+use DateTime::Format::Strptime; >+ >+use C4::Auth; >+use C4::Branch; # GetBranches >+use C4::Output; >+use Koha::DateUtils; >+ >+my $input = new CGI; >+my $today = DateTime->today; >+my $dbh = C4::Context->dbh(); >+ >+my $branchcode = $input->param('BranchName'); >+my $weekday = $input->param('Weekday'); >+my $day = $input->param('Day'); >+my $month = $input->param('Month'); >+my $year = $input->param('Year'); >+my $dateofrange = $input->param('dateofrange'); >+my $holidaytype = $input->param('HolidayType'); >+my $allbranches = $input->param('allBranches'); >+my $operation = $input->param('Operation'); >+my $title = $input->param('Title'); >+my $first_dt = DateTime->new(year => $year, month => $month, day => $day) if $year && $month && $day; >+my $end_dt = eval { dt_from_string( $dateofrange ); }; >+ >+my $query; >+my $stmt; >+my $action = $input->param('action') || ''; >+# Get the template to use >+my ($template, $loggedinuser, $cookie) >+ = get_template_and_user({template_name => "tools/discrete_calendar.tt", >+ type => "intranet", >+ query => $input, >+ authnotrequired => 0, >+ flagsrequired => {tools => 'edit_calendar'}, >+ debug => 1, >+ }); >+my $branch= $input->param('branch') || C4::Context->userenv->{'branch'}; >+ >+ >+ >+# calendardate - date passed in url for human readability (syspref) >+# if the url has an invalid date default to 'now.' >+my $calendarinput_dt = eval { dt_from_string( scalar $input->param('calendardate') ); } || dt_from_string; >+my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } ); >+ >+if($action eq 'add'){ >+ if($allbranches) { >+ my $branch; >+ my @branchcodes = split(/\|/, $input->param('branchCodes')); >+ foreach $branch (@branchcodes) { >+ add_Holiday($operation, $branch, $weekday, $day, $month, $title); >+ } >+ } else { >+ add_Holiday($operation, $branchcode, $weekday, $day, $month, $title); >+ } >+}elsif($action eq 'copy'){ >+ >+ if($operation eq 'copyBranch'){ >+ copyToBranch(); >+ }else{ >+ copyHoliday($branch); >+ } >+}elsif($action eq 'hourschange'){ >+ changeHours(); >+}elsif( $action eq 'edit'){ >+ delete_holidays($branchcode, $weekday, $day, $month); >+} >+sub isOpened{ >+ my ($branchcode, $date) = @_; >+ my $query = "select isopened from discrete_calendar where branchcode=? and date=?"; >+ my $stmt = $dbh->prepare($query); >+ $stmt->execute($branchcode, $date); >+ my $isopened = $stmt->fetchrow_array; >+ >+ return $isopened; >+} >+ >+sub add_Holiday{ >+ my ($operation, $branchcode, $weekday, $day, $month, $title) = @_; >+ my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } ); >+ >+ if($operation eq 'holiday'){ >+ if (isOpened($branchcode,$startDate)) { >+ insert_single_day($branchcode, $title); >+ } >+ }elsif($operation eq 'weekday'){ >+ if (isOpened($branchcode,$startDate)) { >+ insert_weekday_day($branchcode, $weekday, $title); >+ } >+ }elsif($operation eq 'repeatable'){ >+ if (isOpened($branchcode,$startDate)) { >+ insert_yearly_holiday($branchcode, $day, $month, $title); >+ } >+ }elsif($operation eq 'holidayrange'){ >+ insert_range_holiday($branchcode, $title); >+ }elsif($operation eq 'holidayrangerepeat'){ >+ insert_range_holiday_repeat($branchcode, $title); >+ } >+} >+ >+sub insert_single_day{ >+ my ($branchcode,$title) = @_; >+ my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $query = "update discrete_calendar set isOpened=0, note=?, holidaytype='E' where branchcode=? and isOpened=1 and date=? and date>=?"; >+ my $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title, $branchcode, $startDate, $today); >+} >+ >+sub insert_weekday_day{ >+ my ($branchcode, $weekday, $title) = @_; >+ $weekday+=1; >+ my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $today = DateTime->today; >+ my $query = "update discrete_calendar set isOpened=0, note=?, holidaytype='W' where branchcode=? and isOpened=1 and DAYOFWEEK(date)=? and date >=?"; >+ my $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title,$branchcode,$weekday,$today); >+} >+ >+sub insert_yearly_holiday{ >+ my ($branchcode, $day, $month, $title) = @_; >+ my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $today = DateTime->today; >+ my $query = "update discrete_calendar set isOpened=0, note=?, holidaytype='R' where branchcode=? and isOpened=1 and MONTH(date)=? and DAY(date)=? and date >=?"; >+ my $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title,$branchcode,$month,$day,$today); >+} >+ >+sub insert_range_holiday{ >+ my ($branchcode, $title) = @_; >+ my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } ); >+ my $query = "update discrete_calendar set isOpened=0, note=?, holidaytype='E' where branchcode=? and isOpened=1 and (date between ? and ?)"; >+ my $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title,$branchcode, $startDate, $endDate); >+} >+ >+sub insert_range_holiday_repeat{ >+ my ($branchcode, $title) = @_; >+ my $parser = DateTime::Format::Strptime->new( >+ pattern => '%m-%d', >+ on_error => 'croak', >+ ); >+ my $startDate = $parser->format_datetime($first_dt); >+ my $endDate = $parser->format_datetime($end_dt); >+ my $today = DateTime->today; >+ my $query = "update discrete_calendar set isOpened=0, note=?, holidaytype='R' where branchcode=? and isOpened=1 and (DATE_FORMAT(date,'\%m-\%d') BETWEEN ? AND ? ) and date > ?"; >+ my $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title,$branchcode, $startDate, $endDate,$today); >+} >+ >+sub copyHoliday{ >+ # ADD BRANCH CODE TO QUEIRES >+ my ($branch) = @_; >+ my $from_copyFrom = $input->param('from_copyFrom') || ''; >+ my $from_copyTo = $input->param('from_copyTo') || ''; >+ my $to_copyFrom = $input->param('to_copyFrom') || ''; >+ my $to_copyTo = $input->param('to_copyTo') || ''; >+ my $daysnumber= $input->param('daysnumber'); >+ my $copyFromType = $from_copyFrom && !$from_copyTo ? 'oneDay': 'range'; >+ >+ if ($copyFromType eq 'oneDay'){ >+ $query = "select isopened,holidaytype,note, openhour, closehour from discrete_calendar where date=? and branchcode=?"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($from_copyFrom,$branch); >+ >+ my @data = $stmt->fetchrow_array; >+ push @data, $to_copyFrom; >+ push @data, $to_copyTo if $to_copyTo; >+ push @data, $branch; >+ $query = "update discrete_calendar set isopened=?, holidaytype=?, note=?, openhour=?, closehour=? where date=? and branchcode=?"; >+ $query = "update discrete_calendar set isopened=?, holidaytype=?, note=?, openhour=?, closehour=? where date between ? and ? and branchcode=?" if $to_copyTo; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute(@data); >+ >+ }else{ >+ my $parser = DateTime::Format::Strptime->new( >+ pattern => '%Y-%m-%d', >+ on_error => 'croak', >+ ); >+ my $startDate = $parser->parse_datetime($from_copyFrom); >+ my $endDate = $parser->parse_datetime($from_copyTo); >+ >+ if($daysnumber ==6){ >+ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)){ >+ $query = "select DAYOFWEEK(date),isopened,holidaytype,note, openhour, closehour from discrete_calendar where date=? and branchcode=?"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($tempDate,$branch); >+ my @data = $stmt->fetchrow_array; >+ my $weekday = shift @data; >+ >+ push @data ,($to_copyFrom, $to_copyTo, $weekday,$branch); >+ $query ="update discrete_calendar set isopened=?, holidaytype=?, note=?, openhour=?, closehour=? where date between ? and ? and DAYOFWEEK(date)=? and branchcode=?"; >+ >+ $stmt = $dbh->prepare($query); >+ $stmt->execute(@data); >+ } >+ }else{ >+ my $to_startDate = $parser->parse_datetime($to_copyFrom); >+ my $to_endDate = $parser->parse_datetime($to_copyTo); >+ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)){ >+ >+ $query = "select isopened,holidaytype,note, openhour, closehour from discrete_calendar where date=? and branchcode=?"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($tempDate, $branch); >+ my @data = $stmt->fetchrow_array; >+ >+ push @data ,($to_startDate, $branch); >+ $query ="update discrete_calendar set isopened=?, holidaytype=?, note=?, openhour=?, closehour=? where date=? and branchcode=?"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute(@data); >+ $to_startDate->add(days =>1); >+ } >+ } >+ >+ >+} >+} >+sub copyToBranch{ >+ my $newBranch = $input->param('newBranch'); >+ $query = "select isopened, holidaytype, note,openhour, closehour, date from discrete_calendar where branchcode=?"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($branch); >+ my @data; >+ while (@data = $stmt->fetchrow_array) { >+ push @data, $newBranch; >+ $query = "update discrete_calendar set isopened=?, holidaytype=?, note=?, openhour=?, closehour=? where date=? and branchcode=?"; >+ my $newstmt = $dbh->prepare($query); >+ $newstmt->execute(@data); >+ } >+ >+} >+ >+sub delete_holidays{ >+ my ($branchcode, $weekday, $day, $month) = @_; >+ $weekday+=1; >+ my $startDate = DateTime->new(year => $year, month => $month, day => $day); >+ my $endDate = dt_from_string( scalar $input->param('datecancelrange') ) || '' if $input->param('datecancelrange'); >+ my $query; >+ my $stmt; >+ >+ if($operation eq 'edit'){ >+ edit_holiday($branchcode, $title, $weekday, $day, $month); >+ }else{ >+ if($operation eq 'delete'){ >+ $query = "update discrete_calendar set isOpened=1, holidaytype='', note='' where branchcode=? and date=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($branchcode, $startDate); >+ }elsif($operation eq 'deleterange'){ >+ $startDate = output_pref( { dt => $startDate, dateonly => 1, dateformat => 'iso' } ); >+ $endDate = output_pref( { dt => $endDate, dateonly => 1, dateformat => 'iso' } ); >+ $query = "update discrete_calendar set isOpened=1, holidaytype='', note='' where branchcode=? and (date between ? and ?) and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($branchcode, $startDate, $endDate); >+ }else{ >+ if($holidaytype eq 'weekday') { >+ #This one deletes a weekly repeated holiday from the full table >+ $query = "update discrete_calendar set isOpened=1, holidaytype='', note='' where branchcode=? and holidaytype='W' and DAYOFWEEK(date)=? and date >=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($branchcode,$weekday,$today); >+ }elsif($holidaytype eq 'daymonth'){ >+ #This one deletes a given holiday day and repeats for the ful calendar ex: 03 august of every year in the table >+ $query = "update discrete_calendar set isOpened=1, holidaytype='', note='' where branchcode=? and MONTH(date)=? and DAY(date)=? and date >=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($branchcode, $month, $day, $today); >+ } >+ } >+ } >+} >+ >+sub edit_holiday{ >+ my ($branchcode, $title, $weekday, $day, $month) = @_; >+ my $today = DateTime->today; >+ my $startDate = DateTime->new(year => $year, month => $month, day => $day); >+ my $query; >+ my $stmt; >+ >+ if($holidaytype eq 'weekday') { >+ #This one deletes a weekly repeated holiday from the full table >+ $query = "update discrete_calendar set note=? where branchcode=? and DAYOFWEEK(date)=? and date >=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title, $branchcode,$weekday,$today); >+ } elsif ($holidaytype eq 'daymonth') { >+ #This one deletes a given holiday day and repeats for the ful calendar ex: 03 august of every year in the table >+ $query = "update discrete_calendar set note=? where branchcode=? and MONTH(date)=? and DAY(date)=? and date >=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ $stmt->execute($title, $branchcode, $month, $day, $today); >+ } elsif ($holidaytype eq 'ymd' || $holidaytype eq 'float' || $holidaytype eq 'N') { >+ #This one deletes only a holiday based on a given date >+ $query = "update discrete_calendar set note=? where branchcode=? and date=? and isopened=0"; >+ $stmt = $dbh->prepare($query); >+ >+ $stmt->execute($title,$branchcode, $startDate); >+ } >+} >+ >+sub changeHours{ >+ my @params; >+ my $openhour = $input->param('openHour') || ''; >+ my $closehour = $input->param('closeHour') || ''; >+ my $fromDate = $input->param('fromDate') || ''; >+ my $toDate = $input->param('toDate') || ''; >+ my $holidaytype = $input->param('holidayType') || ''; >+ my $isopened = 0; >+ >+ if( $holidaytype eq 'none'){ >+ $isopened = 1; >+ $holidaytype=''; >+ } >+ if($openhour && $closehour){ >+ $query = "update discrete_calendar set openhour=?, closehour=?, isopened =?, holidaytype=? where branchcode=?"; >+ push @params, ($openhour, $closehour, $isopened, $holidaytype, $branchcode); >+ }elsif($openhour && !$closehour){ >+ $query = "update discrete_calendar set openhour=?, isopened =?, holidaytype=? where branchcode=?"; >+ push @params, ($openhour, $isopened, $holidaytype, $branchcode); >+ }elsif(!$openhour && $closehour){ >+ $query = "update discrete_calendar set closehour=?, isopened =?, holidaytype=? where branchcode=?"; >+ push @params,($closehour, $isopened, $holidaytype, $branchcode); >+ } >+ if ($toDate && $fromDate) { >+ $query .= " and date between ? and ?"; >+ push @params, ($fromDate, $toDate); >+ } else { >+ $query .= " and date=?"; >+ push @params, $fromDate; >+ } >+ >+ $stmt = $dbh->prepare($query); >+ $stmt->execute(@params); >+} >+# keydate - date passed to calendar.js. calendar.js does not process dashes within a date. >+ >+my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } ); >+$keydate =~ s/-/\//g; >+ >+# Set all the branches. >+my $onlymine = >+ ( C4::Context->preference('IndependentBranches') >+ && C4::Context->userenv >+ && !C4::Context->IsSuperLibrarian() >+ && C4::Context->userenv->{branch} ? 1 : 0 ); >+if ( $onlymine ) { >+ $branch = C4::Context->userenv->{'branch'}; >+} >+my $branchname = GetBranchName($branch); >+my $branches = GetBranches($onlymine); >+my @branchloop; >+for my $thisbranch ( >+ sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } >+ keys %{$branches} ) { >+ push @branchloop, >+ { value => $thisbranch, >+ selected => $thisbranch eq $branch, >+ branchname => $branches->{$thisbranch}->{'branchname'}, >+ }; >+} >+ >+# branches calculated - put branch codes in a single string so they can be passed in a form >+my $branchcodes = join '|', keys %{$branches}; >+ >+# check if it's changing hours >+ >+ >+# Get all the holidays >+ >+#discrete_calendar weekdays >+$query = "select distinct DAYOFWEEK(date), note from discrete_calendar where branchcode =? and holidaytype='W' order by DAYOFWEEK(date)"; >+$stmt = $dbh->prepare($query); >+$stmt->execute($branch); >+my @week_days; >+while (my ($weekday,$note) = $stmt->fetchrow_array){ >+ push @week_days, {weekday => ($weekday-1), note => $note}; >+} >+ >+#discrete_calendar repeatable >+$query = "select distinct day(date), month(date) from discrete_calendar where branchcode =? and holidaytype='R'"; >+$stmt = $dbh->prepare($query); >+$stmt->execute($branch); >+my @repeatable_holidays; >+while (my ($day, $month, $note) = $stmt->fetchrow_array){ >+ push @repeatable_holidays, {day=> $day, month => $month , note => $note}; >+} >+ >+#single hildays (exceptions) >+$query = "select DATE(date), note from discrete_calendar where branchcode =? and holidaytype='E'"; >+$stmt = $dbh->prepare($query); >+ >+$stmt->execute($branch); >+ >+my @single_holidays; >+while (my ($date,$note) = $stmt->fetchrow_array){ >+ my $outputdate = dt_from_string($date); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @single_holidays, {date => $date, outputdate => $outputdate, note => $note}; >+} >+#Calendar maximum date >+my $minDate; >+$query = "select distinct DATE(date) from discrete_calendar where date = (select min(date) from discrete_calendar)"; >+$stmt = $dbh->prepare($query); >+$stmt->execute(); >+$minDate = $stmt->fetchrow_array; >+#Calendar minimum date >+my $maxDate; >+$query = "select distinct DATE(date) from discrete_calendar where date = (select max(date) from discrete_calendar)"; >+$stmt = $dbh->prepare($query); >+$stmt->execute(); >+$maxDate = $stmt->fetchrow_array; >+ >+my @datesInfos =(); >+$query = "select DATE(date), holidaytype, openhour, closehour, note from discrete_calendar where branchcode=?"; >+$stmt = $dbh->prepare($query); >+$stmt->execute($branch); >+while (my ($date, $holidaytype, $openhour, $closehour, $note) = $stmt->fetchrow_array){ >+ my $outputdate = dt_from_string($date); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @datesInfos, {date=> $date, outputdate => $outputdate, holidaytype => $holidaytype , openhour => $openhour, closehour => $closehour, note => $note}; >+} >+ >+#Not finished yet >+my $timeFormat = C4::Context->preference('TimeFormat') || '24hr'; >+if($timeFormat eq '24hr'){ >+ $timeFormat = 'HH:mm:ss'; >+}else{ >+ $timeFormat = 'HH:mm:ss'; >+} >+$template->param( >+ branchloop => \@branchloop, >+ HOLIDAYS_LOOP => \@single_holidays, >+ calendardate => $calendardate, >+ keydate => $keydate, >+ branchcodes => $branchcodes, >+ branch => $branch, >+ branchname => $branchname, >+ branch => $branch, >+ week_days => \@week_days, >+ repeatable_holidays => \@repeatable_holidays, >+ minDate => $minDate, >+ maxDate => $maxDate, >+ datesInfos => \@datesInfos, >+ timeFormat => $timeFormat, >+); >+ >+# Shows the template with the real values replaced >+output_html_with_http_headers $input, $cookie, $template->output; >-- >1.9.1
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 17015
:
53859
|
54318
|
54419
|
59166
|
59167
|
59168
|
59169
|
59170
|
59171
|
59267
|
59268
|
59269
|
59270
|
59271
|
59463
|
59516
|
59517
|
59518
|
59519
|
59520
|
59561
|
59562
|
59586
|
59587
|
59888
|
59889
|
60902
|
60903
|
60904
|
60905
|
60906
|
60986
|
61737
|
62375
|
62376
|
62380
|
63257
|
63282
|
63362
|
63363
|
63364
|
63365
|
63366
|
63367
|
64235
|
65073
|
65074
|
65075
|
65076
|
65077
|
67721
|
67722
|
67723
|
67724
|
67725
|
67879
|
67929
|
67930
|
67931
|
67932
|
67933
|
67934
|
68392
|
68393
|
68394
|
68395
|
68396
|
68397
|
71634
|
71635
|
71636
|
71637
|
71638
|
72890
|
73145
|
74859
|
74860
|
74861
|
74862
|
74863
|
74864
|
74865
|
74866
|
75444
|
75479
|
76594
|
77249
|
77250
|
77607
|
77608
|
77609
|
77610
|
77611
|
77612
|
77613
|
77770
|
77771
|
77772
|
77773
|
77774
|
79035
|
80523
|
80524
|
80525
|
80526
|
80527
|
80528
|
80529
|
80530
|
80531
|
80532
|
80533
|
80534
|
80535
|
83547
|
85394
|
85677
|
85678
|
85679
|
85680
|
85681
|
85682
|
85683
|
85684
|
85685
|
85686
|
85687
|
85688
|
85689
|
85690
|
85691
|
92595
|
92596
|
92597
|
92598
|
100079
|
110383
|
110384
|
110386
|
110387
|
110388
|
110389
|
113541
|
113905
|
115501
|
115502
|
115503
|
115504
|
115505
|
115506
|
115507
|
115508
|
115509
|
115510
|
115511
|
118554
|
118555
|
118556
|
118557
|
118558
|
118559
|
119095
|
119097
|
119099
|
119100
|
119101
|
119102
|
131619
|
131620
|
131621
|
131622
|
131623
|
131624
|
131625
|
131626
|
131634
|
131635
|
131636
|
131637
|
131638
|
131639
|
131640
|
131641
|
131667
|
132199
|
133596
|
133597
|
133598
|
133599
|
133600
|
133601
|
133602
|
133603
|
133604
|
133605
|
133678
|
137219
|
137220
|
137221
|
137222
|
137223
|
137224
|
137225
|
137226
|
137227
|
137228
|
137229
|
139378
|
139379
|
139380
|
139381
|
139382
|
139599
|
139600
|
139601
|
139602
|
139603
|
139851
|
140150
|
141176
|
144257
|
144258
|
144259
|
144260
|
144261
|
144262
|
144264
|
144268
|
144269
|
144270
|
144271
|
144272
|
144273
|
151438
|
151439
|
151440
|
151441
|
151442
|
151443
|
151444
|
151445
|
151446
|
151447
|
151448
|
151449
|
151450
|
156340
|
156341
|
156342
|
156343
|
156344
|
156345
|
156346
|
156347
|
156348
|
156349
|
156350
|
156351
|
156352
|
156353
|
156354
|
156355
|
157656
|
157657
|
157658
|
157659
|
157660
|
157661
|
157662
|
157663
|
157664
|
157665
|
157666
|
157667
|
157668
|
157669
|
157670
|
157671
|
157672
|
167805
|
167806
|
167807
|
167808
|
167809