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

(-)a/C4/Calendar.pm (+72 lines)
Lines 514-519 sub delete_holiday { Link Here
514
    }
514
    }
515
    return $self;
515
    return $self;
516
}
516
}
517
=head2 delete_holiday_range
518
519
    delete_holiday_range(day => $day,
520
                   month => $month,
521
                   year => $year);
522
523
Delete a holiday range of dates for $self->{branchcode}.
524
525
C<$day> Is the day month to make the date to delete.
526
527
C<$month> Is month to make the date to delete.
528
529
C<$year> Is year to make the date to delete.
530
531
=cut
532
533
sub delete_holiday_range {
534
    my $self = shift;
535
    my %options = @_;
536
537
    my $dbh = C4::Context->dbh();
538
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
539
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
540
}
541
542
=head2 delete_holiday_range_repeatable
543
544
    delete_holiday_range_repeatable(day => $day,
545
                   month => $month);
546
547
Delete a holiday for $self->{branchcode}.
548
549
C<$day> Is the day month to make the date to delete.
550
551
C<$month> Is month to make the date to delete.
552
553
=cut
554
555
sub delete_holiday_range_repeatable {
556
    my $self = shift;
557
    my %options = @_;
558
559
    my $dbh = C4::Context->dbh();
560
    my $sth = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)");
561
    $sth->execute($self->{branchcode}, $options{day}, $options{month});
562
}
563
564
=head2 delete_exception_holiday_range
565
566
    delete_exception_holiday_range(weekday => $weekday
567
                   day => $day,
568
                   month => $month,
569
                   year => $year);
570
571
Delete a holiday for $self->{branchcode}.
572
573
C<$day> Is the day month to make the date to delete.
574
575
C<$month> Is month to make the date to delete.
576
577
C<$year> Is year to make the date to delete.
578
579
=cut
580
581
sub delete_exception_holiday_range {
582
    my $self = shift;
583
    my %options = @_;
584
585
    my $dbh = C4::Context->dbh();
586
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
587
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
588
}
517
589
518
=head2 isHoliday
590
=head2 isHoliday
519
591
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt (-7 / +29 lines)
Lines 197-203 Link Here
197
			$(this).parent().find(".hint").toggle(); return false;
197
			$(this).parent().find(".hint").toggle(); return false;
198
		});
198
		});
199
        $("#dateofrange").datepicker();
199
        $("#dateofrange").datepicker();
200
        $("#datecancelrange").datepicker();
200
		$("#dateofrange").each(function () { this.value = "" });
201
		$("#dateofrange").each(function () { this.value = "" });
202
        $("#datecancelrange").each(function () { this.value = "" });
201
        $("#jcalendar-container").datepicker({
203
        $("#jcalendar-container").datepicker({
202
          beforeShowDay: function(thedate) {
204
          beforeShowDay: function(thedate) {
203
            var day = thedate.getDate();
205
            var day = thedate.getDate();
Lines 276-282 td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9 Link Here
276
				<input type="hidden" id="showBranchName" name="showBranchName" />
278
				<input type="hidden" id="showBranchName" name="showBranchName" />
277
			</li>
279
			</li>
278
			<li>
280
			<li>
279
				<strong>Date:</strong>
281
				<strong>From Date:</strong>
280
				<span id="showDaynameOutput"></span>, 
282
				<span id="showDaynameOutput"></span>, 
281
				
283
				
282
				[% 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 %]
284
				[% 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 287-292 td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9 Link Here
287
				<input type="hidden" id="showMonth" name="showMonth" />
289
				<input type="hidden" id="showMonth" name="showMonth" />
288
				<input type="hidden" id="showYear" name="showYear" />
290
				<input type="hidden" id="showYear" name="showYear" />
289
			</li>
291
			</li>
292
            <li class="dateinsert">
293
                <b>To Date : </b>
294
                <input type="text" id="datecancelrange" name="datecancelrange" size="20" value="[% datecancelrange %]" class="datepicker"/>
295
            </li>
290
			<li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
296
			<li><label for="showTitle">Title: </label><input type="text" name="showTitle" id="showTitle" size="35" /></li>
291
		    <!-- showTitle is necessary for exception radio button to work properly --> 
297
		    <!-- showTitle is necessary for exception radio button to work properly --> 
292
				<label for="showDescription">Description:</label>
298
				<label for="showDescription">Description:</label>
Lines 297-309 td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9 Link Here
297
				<a href="#" class="helptext">[?]</a>
303
				<a href="#" class="helptext">[?]</a>
298
				<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>
304
				<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>
299
			</div></li>
305
			</div></li>
306
            <li class="radio"><input type="radio" name="showOperation" id="showOperationExcRange" value="exceptionrange" />
307
                <label for="newOperationFieldException">Generate exceptions on a range of dates.</label>
308
                <a href="#" class="helptext">[?]</a>
309
                <div class="hint">You can make an exception on a range of dates repeated yearly.</div>
310
            </li>
300
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
311
			<li class="radio"><input type="radio" name="showOperation" id="showOperationDel" value="delete" /> <label for="showOperationDel" id="showOperationDelLabel">Delete this holiday</label>
301
				<a href="#" class="helptext">[?]</a>
312
				<a href="#" class="helptext">[?]</a>
302
				<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>
313
				<div class="hint">This will delete this holiday rule. If it is a repeatable holiday, this option checks for possible exceptions. If an exception exists, this option will remove the exception and set the date to a regular holiday.</div></li>
314
            <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>.
315
                <a href="#" class="helptext">[?]</a>
316
                <div class="hint">This will delete the single holidays rules only. The repeatable holidays and exceptions will not be deleted.</div>
317
            </li>
318
            <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>.
319
                <a href="#" class="helptext">[?]</a>
320
                <div class="hint">This will delete the repeated holidays rules only. The repeatable holidays will be deleted but not the exceptions.</div>
321
            </li>
322
            <li class="radio"><input type="radio" name="showOperation" id="showOperationDelRangeRepeatExcept" value="deleterangerepeatexcept" /> <label for="showOperationDelRangeRepeatExcept" id="showOperationDelLabelRangeRepeatExcept">Delete the exceptions on a range</label>.
323
                <a href="#" class="helptext">[?]</a>
324
                <div class="hint">This will delete the exceptions inside a given range. Be careful about your scope range if it is oversized you could slow down Koha.</div>
325
            </li>
303
			<li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
326
			<li class="radio"><input type="radio" name="showOperation" id="showOperationEdit" value="edit" checked="checked" /> <label for="showOperationEdit">Edit this holiday</label>
304
						<a href="#" class="helptext">[?]</a>
327
                <a href="#" class="helptext">[?]</a>
305
						<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>
328
                <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>
306
307
			</ol>
329
			</ol>
308
			<fieldset class="action">
330
			<fieldset class="action">
309
				<input type="submit" name="submit" value="Save" />
331
				<input type="submit" name="submit" value="Save" />
Lines 363-374 td.repeatableyearly a.ui-state-default, .repeatableyearly { background: #FFFF9 Link Here
363
            <li class="radio"><input type="radio" name="newOperation" id="newOperationField" value="holidayrange" />
385
            <li class="radio"><input type="radio" name="newOperation" id="newOperationField" value="holidayrange" />
364
                            <label for="newOperationField">Holidays on a range</label>.
386
                            <label for="newOperationField">Holidays on a range</label>.
365
                            <a href="#" class="helptext">[?]</a>
387
                            <a href="#" class="helptext">[?]</a>
366
                            <div class="hint">Make a single holiday on a range. For example, selecting August 1st, 2012  and August 10st, 2012 will make all days between 1st and 10st holiday, but will not affect August 1st-10st in other years.</div>
388
                            <div class="hint">Make a single holiday on a range. For example, selecting August 1st, 2012  and August 10st, 2012 will make all days between 1st and 10st holiday, but will not affect August 1-10 in other years.</div>
367
                            </li>
389
                            </li>
368
            <li class="radio"><input type="radio" name="newOperation" id="newOperationFieldyear" value="holidayrangerepeat" />
390
            <li class="radio"><input type="radio" name="newOperation" id="newOperationFieldyear" value="holidayrangerepeat" />
369
                            <label for="newOperationFieldyear">Holidays repeated yearly on a range</label>.
391
                            <label for="newOperationFieldyear">Holidays repeated yearly on a range</label>.
370
                            <a href="#" class="helptext">[?]</a>
392
                            <a href="#" class="helptext">[?]</a>
371
                            <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1st, 2012  and August 10st, 2012 will make all days between 1st and 10st holiday, and will affect August 1st-10st in other years.</div>
393
                            <div class="hint">Make a single holiday on a range repeated yearly. For example, selecting August 1st, 2012  and August 10st, 2012 will make all days between 1st and 10st holiday, and will affect August 1-10 in other years.</div>
372
                            </li>
394
                            </li>
373
				<li class="radio">
395
				<li class="radio">
374
				<input type="checkbox" name="allBranches" id="allBranches" />
396
				<input type="checkbox" name="allBranches" id="allBranches" />
(-)a/tools/exceptionHolidays.pl (-2 / +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 37-48 if ($description) { Link Here
37
    $description = '';
40
    $description = '';
38
}   
41
}   
39
42
43
# We format the date
44
my @dateend = split(/[\/-]/, $datecancelrange);
45
if (C4::Context->preference("dateformat") eq "metric") {
46
    $day1 = $dateend[0];
47
    $month1 = $dateend[1];
48
    $year1 = $dateend[2];
49
}elsif (C4::Context->preference("dateformat") eq "us") {
50
    $month1 = $dateend[0];
51
    $day1 = $dateend[1];
52
    $year1 = $dateend[2];
53
} else {
54
    $year1 = $dateend[0];
55
    $month1 = $dateend[1];
56
    $day1 = $dateend[2];
57
}
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
}
40
if ($input->param('showOperation') eq 'exception') {
72
if ($input->param('showOperation') eq 'exception') {
41
	$calendar->insert_exception_holiday(day => $day,
73
	$calendar->insert_exception_holiday(day => $day,
42
										month => $month,
74
										month => $month,
43
									    year => $year,
75
									    year => $year,
44
						                title => $title,
76
						                title => $title,
45
						                description => $description);
77
						                description => $description);
78
} elsif ($input->param('showOperation') eq 'exceptionrange' ) {
79
        if (@holiday_list){
80
            foreach my $date (@holiday_list){
81
                $calendar->insert_exception_holiday(
82
                    day         => $date->{local_c}->{day},
83
                    month       => $date->{local_c}->{month},
84
                    year       => $date->{local_c}->{year},
85
                    title       => $title,
86
                    description => $description
87
                    );
88
            }
89
        }
46
} elsif ($input->param('showOperation') eq 'edit') {
90
} elsif ($input->param('showOperation') eq 'edit') {
47
    if($holidaytype eq 'weekday') {
91
    if($holidaytype eq 'weekday') {
48
      $calendar->ModWeekdayholiday(weekday => $weekday,
92
      $calendar->ModWeekdayholiday(weekday => $weekday,
Lines 71-75 if ($input->param('showOperation') eq 'exception') { Link Here
71
	                          day => $day,
115
	                          day => $day,
72
  	                          month => $month,
116
  	                          month => $month,
73
				              year => $year);
117
				              year => $year);
118
}elsif ($input->param('showOperation') eq 'deleterange') {
119
    if (@holiday_list){
120
        foreach my $date (@holiday_list){
121
            $calendar->delete_holiday_range(weekday => $weekday,
122
                                            day => $date->{local_c}->{day},
123
                                            month => $date->{local_c}->{month},
124
                                            year => $date->{local_c}->{year});
125
            }
126
    }
127
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
128
    if (@holiday_list){
129
        foreach my $date (@holiday_list){
130
           $calendar->delete_holiday_range_repeatable(weekday => $weekday,
131
                                         day => $date->{local_c}->{day},
132
                                         month => $date->{local_c}->{month});
133
        }
134
    }
135
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
136
    if (@holiday_list){
137
        foreach my $date (@holiday_list){
138
           $calendar->delete_exception_holiday_range(weekday => $weekday,
139
                                         day => $date->{local_c}->{day},
140
                                         month => $date->{local_c}->{month},
141
                                         year => $date->{local_c}->{year});
142
        }
143
    }
74
}
144
}
75
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
145
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