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

(-)a/C4/Calendar.pm (+105 lines)
Lines 45-50 BEGIN { Link Here
45
        &isHoliday
45
        &isHoliday
46
        &addDate
46
        &addDate
47
        &daysBetween
47
        &daysBetween
48
        &delete_holiday_range
49
        &delete_holiday_range_repeatable
50
        &delete_exception_holiday_range
48
    );
51
    );
49
}
52
}
50
53
Lines 529-534 sub delete_holiday { Link Here
529
    return $self;
532
    return $self;
530
}
533
}
531
534
535
=head2 delete_holiday_range
536
537
    delete_holiday_range(weekday => $weekday
538
                   day => $day,
539
                   month => $month,
540
                   year => $year);
541
542
Delete a holiday for $self->{branchcode}.
543
544
C<$weekday> Is the week day to delete.
545
546
C<$day> Is the day month to make the date to delete.
547
548
C<$month> Is month to make the date to delete.
549
550
C<$year> Is year to make the date to delete.
551
552
=cut
553
554
sub delete_holiday_range {
555
    my $self = shift @_;
556
    my %options = @_;
557
558
    my $dbh = C4::Context->dbh();
559
    my $isSingleHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
560
    $isSingleHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
561
    if ($isSingleHoliday->rows) {
562
        my $id = $isSingleHoliday->fetchrow;
563
        $isSingleHoliday->finish; # Close the last query
564
        my $deleteHoliday = $dbh->prepare("DELETE FROM special_holidays WHERE id = ?");
565
        $deleteHoliday->execute($id);
566
    }
567
}
568
569
=head2 delete_holiday_range_repeatable
570
571
    delete_holiday_range_repeatable(weekday => $weekday
572
                   day => $day,
573
                   month => $month,
574
                   year => $year);
575
576
Delete a holiday for $self->{branchcode}.
577
578
C<$weekday> Is the week day to delete.
579
580
C<$day> Is the day month to make the date to delete.
581
582
C<$month> Is month to make the date to delete.
583
584
C<$year> Is year to make the date to delete.
585
586
=cut
587
588
sub delete_holiday_range_repeatable {
589
    my $self = shift @_;
590
    my %options = @_;
591
592
    my $dbh = C4::Context->dbh();
593
    my $isDayMonthHoliday = $dbh->prepare("SELECT id FROM repeatable_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?)");
594
    $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month});
595
    if ($isDayMonthHoliday->rows) {
596
        my $id = $isDayMonthHoliday->fetchrow;
597
        $isDayMonthHoliday->finish;
598
        my $deleteHoliday = $dbh->prepare("DELETE FROM repeatable_holidays WHERE (id = ?)");
599
        $deleteHoliday->execute($id);
600
    }
601
}
602
603
=head2 delete_exception_holiday_range
604
605
    delete_exception_holiday_range(weekday => $weekday
606
                   day => $day,
607
                   month => $month,
608
                   year => $year);
609
610
Delete a holiday for $self->{branchcode}.
611
612
C<$weekday> Is the week day to delete.
613
614
C<$day> Is the day month to make the date to delete.
615
616
C<$month> Is month to make the date to delete.
617
618
C<$year> Is year to make the date to delete.
619
620
=cut
621
622
sub delete_exception_holiday_range {
623
    my $self = shift @_;
624
    my %options = @_;
625
626
    my $dbh = C4::Context->dbh();
627
    my $isDayMonthHoliday = $dbh->prepare("SELECT id FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
628
    $isDayMonthHoliday->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
629
    if ($isDayMonthHoliday->rows) {
630
        my $id = $isDayMonthHoliday->fetchrow;
631
        $isDayMonthHoliday->finish;
632
        my $deleteExceptions = $dbh->prepare("DELETE FROM special_holidays WHERE (id = ?)");
633
        $deleteExceptions->execute($id);
634
    }
635
}
636
532
=head2 isHoliday
637
=head2 isHoliday
533
638
534
    $isHoliday = isHoliday($day, $month $year);
639
    $isHoliday = isHoliday($day, $month $year);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt (-6 / +37 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 205-218 Link Here
205
				<input type="radio" name="showOperation" id="showOperationExc" value="exception" /> <label for="showOperationExc">Generate an exception for this repeated holiday.</label>
220
				<input type="radio" name="showOperation" id="showOperationExc" value="exception" /> <label for="showOperationExc">Generate an exception for this repeated holiday.</label>
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
			</li>
224
			<li class="radio"><input type="radio" name="newOperation" id="newOperationFieldException" value="exceptionrange" />
225
				<label for="newOperationFieldException">Exceptions on a range</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 / +87 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 36-48 if ($description) { Link Here
36
} else {
39
} else {
37
    $description = '';
40
    $description = '';
38
}   
41
}   
39
42
my @dateend = split(/[\/-]/, $datecancelrange);
43
if (C4::Context->preference("dateformat") eq "metric") {
44
    $day1 = $dateend[0];
45
    $month1 = $dateend[1];
46
    $year1 = $dateend[2];
47
}elsif (C4::Context->preference("dateformat") eq "us") {
48
    $month1 = $dateend[0];
49
    $day1 = $dateend[1];
50
    $year1 = $dateend[2];
51
} else {
52
    $year1 = $dateend[0];
53
    $month1 = $dateend[1];
54
    $day1 = $dateend[2];
55
}
40
if ($input->param('showOperation') eq 'exception') {
56
if ($input->param('showOperation') eq 'exception') {
41
	$calendar->insert_exception_holiday(day => $day,
57
	$calendar->insert_exception_holiday(day => $day,
42
										month => $month,
58
										month => $month,
43
									    year => $year,
59
									    year => $year,
44
						                title => $title,
60
						                title => $title,
45
						                description => $description);
61
						                description => $description);
62
} elsif ($input->param('showOperation') eq 'exceptionrange' ) {
63
        #Make an array with holiday's days
64
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
65
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
66
        my @holiday_list = ();
67
68
        for (my $dt = $first_dt->clone();
69
            $dt <= $end_dt;
70
            $dt->add(days => 1) )
71
            {
72
            push @holiday_list, $dt->clone();
73
            }
74
75
        foreach my $date (@holiday_list){
76
            $calendar->insert_exception_holiday(
77
                day         => $date->{local_c}->{day},
78
                month       => $date->{local_c}->{month},
79
                year       => $date->{local_c}->{year},
80
                title       => $title,
81
                description => $description
82
                );
83
        }
46
} elsif ($input->param('showOperation') eq 'edit') {
84
} elsif ($input->param('showOperation') eq 'edit') {
47
    if($holidaytype eq 'weekday') {
85
    if($holidaytype eq 'weekday') {
48
      $calendar->ModWeekdayholiday(weekday => $weekday,
86
      $calendar->ModWeekdayholiday(weekday => $weekday,
Lines 71-75 if ($input->param('showOperation') eq 'exception') { Link Here
71
	                          day => $day,
109
	                          day => $day,
72
  	                          month => $month,
110
  	                          month => $month,
73
				              year => $year);
111
				              year => $year);
112
}elsif ($input->param('showOperation') eq 'deleterange') {
113
    if ($year1 && $month1 && $day1){
114
        #Make an array with holiday's days
115
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
116
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
117
        my @holiday_list = ();
118
        for (my $dt = $first_dt->clone(); $dt <= $end_dt; $dt->add(days => 1) ){
119
            push @holiday_list, $dt->clone();
120
        }
121
        foreach my $date (@holiday_list){
122
            $calendar->delete_holiday_range(weekday => $weekday,
123
                                            day => $date->{local_c}->{day},
124
                                            month => $date->{local_c}->{month},
125
                                            year => $date->{local_c}->{year});
126
            }
127
    }
128
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
129
    if ($year1 && $month1 && $day1){
130
        #Make an array with holiday's days
131
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
132
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
133
        my @holiday_list = ();
134
        for (my $dt = $first_dt->clone(); $dt <= $end_dt; $dt->add(days => 1) ){
135
            push @holiday_list, $dt->clone();
136
        }
137
        foreach my $date (@holiday_list){
138
           $calendar->delete_holiday_range_repeatable(weekday => $weekday,
139
                                         day => $date->{local_c}->{day},
140
                                         month => $date->{local_c}->{month});
141
        }
142
    }
143
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
144
    if ($year1 && $month1 && $day1){
145
        #Make an array with holiday's days
146
        my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
147
        my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
148
        my @holiday_list = ();
149
        for (my $dt = $first_dt->clone(); $dt <= $end_dt; $dt->add(days => 1) ){
150
            push @holiday_list, $dt->clone();
151
        }
152
        foreach my $date (@holiday_list){
153
           $calendar->delete_exception_holiday_range(weekday => $weekday,
154
                                         day => $date->{local_c}->{day},
155
                                         month => $date->{local_c}->{month});
156
        }
157
    }
74
}
158
}
75
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
159
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
(-)a/tools/newHolidays.pl (-2 lines)
Lines 146-150 sub add_holiday { Link Here
146
                );
146
                );
147
            }
147
            }
148
        }
148
        }
149
    }
150
}
149
}
151
- 

Return to bug 7351