View | Details | Raw Unified | Return to bug 7351
Collapse All | Expand All

(-)a/C4/Calendar.pm (+73 lines)
Lines 515-520 sub delete_holiday { Link Here
515
    return $self;
515
    return $self;
516
}
516
}
517
517
518
=head2 delete_holiday_range
519
520
    delete_holiday_range(day => $day,
521
                   month => $month,
522
                   year => $year);
523
524
Delete a holiday range of dates for $self->{branchcode}.
525
526
C<$day> Is the day month to make the date to delete.
527
528
C<$month> Is month to make the date to delete.
529
530
C<$year> Is year to make the date to delete.
531
532
=cut
533
534
sub delete_holiday_range {
535
    my $self = shift;
536
    my %options = @_;
537
538
    my $dbh = C4::Context->dbh();
539
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
540
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
541
}
542
543
=head2 delete_holiday_range_repeatable
544
545
    delete_holiday_range_repeatable(day => $day,
546
                   month => $month);
547
548
Delete a holiday for $self->{branchcode}.
549
550
C<$day> Is the day month to make the date to delete.
551
552
C<$month> Is month to make the date to delete.
553
554
=cut
555
556
sub delete_holiday_range_repeatable {
557
    my $self = shift;
558
    my %options = @_;
559
560
    my $dbh = C4::Context->dbh();
561
    my $sth = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)");
562
    $sth->execute($self->{branchcode}, $options{day}, $options{month});
563
}
564
565
=head2 delete_exception_holiday_range
566
567
    delete_exception_holiday_range(weekday => $weekday
568
                   day => $day,
569
                   month => $month,
570
                   year => $year);
571
572
Delete a holiday for $self->{branchcode}.
573
574
C<$day> Is the day month to make the date to delete.
575
576
C<$month> Is month to make the date to delete.
577
578
C<$year> Is year to make the date to delete.
579
580
=cut
581
582
sub delete_exception_holiday_range {
583
    my $self = shift;
584
    my %options = @_;
585
586
    my $dbh = C4::Context->dbh();
587
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
588
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
589
}
590
518
=head2 isHoliday
591
=head2 isHoliday
519
592
520
    $isHoliday = isHoliday($day, $month $year);
593
    $isHoliday = isHoliday($day, $month $year);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt (-5 / +36 lines)
Lines 83-90 Link Here
83
	function Help() {
83
	function Help() {
84
		newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
84
		newin=window.open("/cgi-bin/koha/help.pl","KohaHelp",'width=600,height=600,toolbar=false,scrollbars=yes');
85
	}
85
	}
86
	$(document).ready(function() {
87
86
87
    $(document).ready(function() {
88
[% IF ( dateformat_metric ) %]		$.tablesorter.addParser({ // http://tablesorter.com/docs/example-parsers.html
88
[% IF ( dateformat_metric ) %]		$.tablesorter.addParser({ // http://tablesorter.com/docs/example-parsers.html
89
			id: 'shortDates',
89
			id: 'shortDates',
90
			is: function(s){
90
			is: function(s){
Lines 129-134 Link Here
129
			$(this).parent().find(".hint").toggle(); return false;
129
			$(this).parent().find(".hint").toggle(); return false;
130
		});
130
		});
131
		$("#dateofrange").each(function () { this.value = "" });
131
		$("#dateofrange").each(function () { this.value = "" });
132
		$("#datecancelrange").each(function () { this.value = "" });
132
	});
133
	});
133
//]]>
134
//]]>
134
</script>
135
</script>
Lines 185-191 Link Here
185
				<input type="hidden" id="showBranchName" name="showBranchName" />
186
				<input type="hidden" id="showBranchName" name="showBranchName" />
186
			</li>
187
			</li>
187
			<li>
188
			<li>
188
				<strong>Date:</strong>
189
				<strong>From Date:</strong>
189
				<span id="showDaynameOutput"></span>, 
190
				<span id="showDaynameOutput"></span>, 
190
				
191
				
191
				[% 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>[% ELSE %]<span id="showYearOutput"></span>/<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>[% END %]
192
				[% 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>[% ELSE %]<span id="showYearOutput"></span>/<span id="showMonthOutput"></span>/<span id="showDayOutput"></span>[% END %]
Lines 196-201 Link Here
196
				<input type="hidden" id="showMonth" name="showMonth" />
197
				<input type="hidden" id="showMonth" name="showMonth" />
197
				<input type="hidden" id="showYear" name="showYear" />
198
				<input type="hidden" id="showYear" name="showYear" />
198
			</li>
199
			</li>
200
			<li class="dateinsert">
201
				<b>To Date : </b>
202
				<input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange %]" />
203
				<img src="[% themelang %]/lib/calendar/cal.gif" id="datecancelrange_button" alt="Show Calendar" />
204
				<script language="JavaScript" type="text/javascript">
205
				Calendar.setup(
206
					{
207
					inputField : "datecancelrange",
208
					ifFormat : "[% DHTMLcalendar_dateformat %]",
209
					button : "datecancelrange_button"
210
					}
211
				);
212
				</script>
213
			</li>
199
			<li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
214
			<li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
200
		    <!-- showTitle is necessary for exception radio button to work properly --> 
215
		    <!-- showTitle is necessary for exception radio button to work properly --> 
201
				<label for="showDescription">Description:</label>
216
				<label for="showDescription">Description:</label>
Lines 206-218 Link Here
206
				<a href="#" class="helptext">[?]</a>
221
				<a href="#" class="helptext">[?]</a>
207
				<div class="hint">You can make an exception for this holiday rule. This means that you will be able to say that for a repeatable holiday there is one day which is going to be an exception.</div>
222
				<div class="hint">You can make an exception for this holiday rule. This means that you will be able to say that for a repeatable holiday there is one day which is going to be an exception.</div>
208
			</div></li>
223
			</div></li>
224
			<li class="radio"><input type="radio" name="showOperation" id="showOperationExcRange" value="exceptionrange" />
225
				<label for="newOperationFieldException">Generate exceptions on a range of dates.</label>.
226
				<a href="#" class="helptext">[?]</a>
227
				<div class="hint">You can make an exception on a range of dates repeated yearly.</div>
228
			</li>
209
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
229
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
210
				<a href="#" class="helptext">[?]</a>
230
				<a href="#" class="helptext">[?]</a>
211
				<div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for posible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
231
				<div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for posible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
232
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDelRange" value="deleterange" /><label for="showOperationDelRange" id="showOperationDelLabelRange">Delete the single holidays on a range</label>.
233
				<a href="#" class="helptext">[?]</a>
234
				<div class="hint">This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted</div>
235
			</li>
236
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeat" value="deleterangerepeat" /><label for="showOperationDelRangeRepeat" id="showOperationDelLabelRangeRepeat">Delete the repeated holidays on a range</label>.
237
				<a href="#" class="helptext">[?]</a>
238
				<div class="hint">This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not exceptions</div>
239
			</li>
240
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeatExcept" value="deleterangerepeatexcept" /><label for="showOperationDelRangeRepeatExcept" id="showOperationDelLabelRangeRepeatExcept">Delete the exceptions on a range</label>.
241
				<a href="#" class="helptext">[?]</a>
242
				<div class="hint">This will delete the exceptions inside a given range. Be carefull about your scope range if it is oversized you could slow down koha</div>
243
			</li>
212
			<li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
244
			<li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
213
						<a href="#" class="helptext">[?]</a>
245
				<a href="#" class="helptext">[?]</a>
214
						<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>
246
				<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>
215
216
			</ol>
247
			</ol>
217
			<fieldset class="action">
248
			<fieldset class="action">
218
				<input type="submit" name="submit" value="Save" />
249
				<input type="submit" name="submit" value="Save" />
(-)a/tools/exceptionHolidays.pl (-3 / +72 lines)
Lines 7-13 use CGI; Link Here
7
7
8
use C4::Auth;
8
use C4::Auth;
9
use C4::Output;
9
use C4::Output;
10
10
use DateTime;
11
11
12
use C4::Calendar;
12
use C4::Calendar;
13
13
Lines 19-28 my $weekday = $input->param('showWeekday'); Link Here
19
my $day = $input->param('showDay');
19
my $day = $input->param('showDay');
20
my $month = $input->param('showMonth');
20
my $month = $input->param('showMonth');
21
my $year = $input->param('showYear');
21
my $year = $input->param('showYear');
22
my $day1;
23
my $month1;
24
my $year1;
22
my $title = $input->param('showTitle');
25
my $title = $input->param('showTitle');
23
my $description = $input->param('showDescription');
26
my $description = $input->param('showDescription');
24
my $holidaytype = $input->param('showHolidayType');
27
my $holidaytype = $input->param('showHolidayType');
25
28
my $datecancelrange = $input->param('datecancelrange');
26
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
29
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
27
my $isodate = C4::Dates->new($calendardate, 'iso');
30
my $isodate = C4::Dates->new($calendardate, 'iso');
28
$calendardate = $isodate->output('syspref');
31
$calendardate = $isodate->output('syspref');
Lines 35-48 if ($description) { Link Here
35
    $description =~ s/\n/\\n/g;
38
    $description =~ s/\n/\\n/g;
36
} else {
39
} else {
37
    $description = '';
40
    $description = '';
38
}   
41
}
42
# We format the date
43
my @dateend = split(/[\/-]/, $datecancelrange);
44
if (C4::Context->preference("dateformat") eq "metric") {
45
    $day1 = $dateend[0];
46
    $month1 = $dateend[1];
47
    $year1 = $dateend[2];
48
}elsif (C4::Context->preference("dateformat") eq "us") {
49
    $month1 = $dateend[0];
50
    $day1 = $dateend[1];
51
    $year1 = $dateend[2];
52
} else {
53
    $year1 = $dateend[0];
54
    $month1 = $dateend[1];
55
    $day1 = $dateend[2];
56
}
39
57
58
# We make an array with holiday's days
59
my @holiday_list;
60
if ($year1 && $month1 && $day1){
61
            my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
62
            my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
63
64
            for (my $dt = $first_dt->clone();
65
                $dt <= $end_dt;
66
                $dt->add(days => 1) )
67
                {
68
                push @holiday_list, $dt->clone();
69
                }
70
}
40
if ($input->param('showOperation') eq 'exception') {
71
if ($input->param('showOperation') eq 'exception') {
41
	$calendar->insert_exception_holiday(day => $day,
72
	$calendar->insert_exception_holiday(day => $day,
42
										month => $month,
73
										month => $month,
43
									    year => $year,
74
									    year => $year,
44
						                title => $title,
75
						                title => $title,
45
						                description => $description);
76
						                description => $description);
77
} elsif ($input->param('showOperation') eq 'exceptionrange' ) {
78
        if (@holiday_list){
79
            foreach my $date (@holiday_list){
80
                $calendar->insert_exception_holiday(
81
                    day         => $date->{local_c}->{day},
82
                    month       => $date->{local_c}->{month},
83
                    year       => $date->{local_c}->{year},
84
                    title       => $title,
85
                    description => $description
86
                    );
87
            }
88
        }
46
} elsif ($input->param('showOperation') eq 'edit') {
89
} elsif ($input->param('showOperation') eq 'edit') {
47
    if($holidaytype eq 'weekday') {
90
    if($holidaytype eq 'weekday') {
48
      $calendar->ModWeekdayholiday(weekday => $weekday,
91
      $calendar->ModWeekdayholiday(weekday => $weekday,
Lines 71-75 if ($input->param('showOperation') eq 'exception') { Link Here
71
	                          day => $day,
114
	                          day => $day,
72
  	                          month => $month,
115
  	                          month => $month,
73
				              year => $year);
116
				              year => $year);
117
}elsif ($input->param('showOperation') eq 'deleterange') {
118
    if (@holiday_list){
119
        foreach my $date (@holiday_list){
120
            $calendar->delete_holiday_range(weekday => $weekday,
121
                                            day => $date->{local_c}->{day},
122
                                            month => $date->{local_c}->{month},
123
                                            year => $date->{local_c}->{year});
124
            }
125
    }
126
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
127
    if (@holiday_list){
128
        foreach my $date (@holiday_list){
129
           $calendar->delete_holiday_range_repeatable(weekday => $weekday,
130
                                         day => $date->{local_c}->{day},
131
                                         month => $date->{local_c}->{month});
132
        }
133
    }
134
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
135
    if (@holiday_list){
136
        foreach my $date (@holiday_list){
137
           $calendar->delete_exception_holiday_range(weekday => $weekday,
138
                                         day => $date->{local_c}->{day},
139
                                         month => $date->{local_c}->{month},
140
                                         year => $date->{local_c}->{year});
141
        }
142
    }
74
}
143
}
75
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
144
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
(-)a/tools/newHolidays.pl (-42 / +35 lines)
Lines 56-61 if ($description) { Link Here
56
	$description = '';
56
	$description = '';
57
}
57
}
58
58
59
# We make an array with holiday's days
60
my @holiday_list;
61
if ($year1 && $month1 && $day1){
62
            my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
63
            my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
64
65
            for (my $dt = $first_dt->clone();
66
                $dt <= $end_dt;
67
                $dt->add(days => 1) )
68
                {
69
                push @holiday_list, $dt->clone();
70
                }
71
}
72
59
if($allbranches) {
73
if($allbranches) {
60
	my $branch;
74
	my $branch;
61
	my @branchcodes = split(/\|/, $input->param('branchCodes')); 
75
	my @branchcodes = split(/\|/, $input->param('branchCodes')); 
Lines 100-149 sub add_holiday { Link Here
100
		}
114
		}
101
115
102
	} elsif ( $newoperation eq 'holidayrange' ) {
116
	} elsif ( $newoperation eq 'holidayrange' ) {
103
        #Make an array with holiday's days
117
        if (@holiday_list){
104
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
118
            foreach my $date (@holiday_list){
105
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
119
                unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
106
        my @holiday_list = ();
120
                    $calendar->insert_single_holiday(
107
121
                        day         => $date->{local_c}->{day},
108
        for (my $dt = $first_dt->clone();
122
                        month       => $date->{local_c}->{month},
109
            $dt <= $end_dt;
123
                        year        => $date->{local_c}->{year},
110
            $dt->add(days => 1) )
124
                        title       => $title,
111
            {
125
                        description => $description
112
            push @holiday_list, $dt->clone();
126
                    );
113
            }
127
                }
114
115
        foreach my $date (@holiday_list){
116
            unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
117
            $calendar->insert_single_holiday(
118
                day         => $date->{local_c}->{day},
119
                month       => $date->{local_c}->{month},
120
                year        => $date->{local_c}->{year},
121
                title       => $title,
122
                description => $description
123
                );
124
            }
128
            }
125
        }
129
        }
126
    } elsif ( $newoperation eq 'holidayrangerepeat' ) {
130
    } elsif ( $newoperation eq 'holidayrangerepeat' ) {
127
        #Make an array with holiday's days
131
        if (@holiday_list){
128
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
132
            foreach my $date (@holiday_list){
129
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
133
                unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
130
        my @holiday_list = ();
134
                    $calendar->insert_day_month_holiday(
131
135
                        day         => $date->{local_c}->{day},
132
        for (my $dt = $first_dt->clone();
136
                        month       => $date->{local_c}->{month},
133
            $dt <= $end_dt;
137
                        title       => $title,
134
            $dt->add(days => 1) )
138
                        description => $description
135
            {
139
                    );
136
            push @holiday_list, $dt->clone();
140
                }
137
            }
138
139
        foreach my $date (@holiday_list){
140
            unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) {
141
            $calendar->insert_day_month_holiday(
142
                day         => $date->{local_c}->{day},
143
                month       => $date->{local_c}->{month},
144
                title       => $title,
145
                description => $description
146
                );
147
            }
141
            }
148
        }
142
        }
149
    }
143
    }
150
- 

Return to bug 7351