Merge branch 'bug_9850' into 3.14-master
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / serials / subscription-add.tt
1 [% INCLUDE 'doc-head-open.inc' %]
2 <title>Koha &rsaquo; Serials &rsaquo; [% IF ( modify ) %][% bibliotitle |html %] &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</title>
3 [% INCLUDE 'doc-head-close.inc' %]
4 [% INCLUDE 'calendar.inc' %]
5 <style type="text/css">
6 fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
7 .yui-u li p label.widelabel {
8     width: 300px;  /* not enough for IE7 apparently */
9 }
10 </style>
11 <script type="text/javascript">
12 //<![CDATA[
13
14 // the english words used in display purposes
15 var text = new Array(_("Number"),_("Volume"),_("Issue"),_("Month"),_("Week"),_("Starting with:"),_("Rollover at:"),_("Choose Hemisphere:"),_("Northern"),_("Southern"),
16 _("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"),_("Season"),_("Year"));
17 var weekno_label = _("Week # ");
18 var is_season = 0;
19 var is_hemisphere = 1;
20 var irregular_issues;   // will hold irregularity object.
21
22 function formatDate(myDate) {
23     var d = new Array( myDate.getFullYear(), myDate.getMonth() + 1 ,myDate.getDate());
24     if(d[1].toString().length == 1) { d[1] = '0'+d[1] };
25     if(d[2].toString().length == 1) { d[2] = '0'+d[2] };
26     [% IF ( dateformat_us ) %]
27         return(d[1] + '/' + d[2] + '/' + d[0]) ;
28     [% ELSIF ( dateformat_metric ) %]
29         return(d[2] + '/' + d[1] + '/' + d[0]) ;
30     [% ELSE %]
31         return(''+d[0] + '-' + d[1] + '-' + d[2]) ;
32     [% END %]    
33 }
34
35 Date.prototype.addDays = function(days) {
36     this.setDate(this.getDate()+days);
37 }
38
39 function getWeeksArray(startDate,periodicity) {
40 // returns an array of syspref-formatted dates starting at the first day of startDate's year.
41 // This prediction method will not accurately predict irregularites beyond the first year.
42 // FIXME : Should replace with ajax query to get the first Monday of the year so that week numbers have correct dates.
43     var incr=1;
44     if(periodicity==3) {  // 1/2 wks
45         incr=2;
46     } else if(periodicity == 4) { // 1/3 wks
47         incr=3;
48     }
49     var weeksArray = new Array;
50     var jan01 = new Date();
51     jan01.setDate(1);
52     jan01.setMonth(0);
53     jan01.setFullYear(startDate.getFullYear());
54     for(var i=0;i<52;i++) {
55         weeksArray[i] = formatDate(jan01) + ' ' + weekno_label + (i + 1);
56         jan01.addDays( 7 ); 
57     }
58     return weeksArray;
59 }
60
61 function YMDaToYWDa(S) {
62     with (new Date(Date.UTC(S[0], S[1] - 1, S[2]))) {
63         var DoW = getUTCDay();
64         setUTCDate(getUTCDate() - (DoW + 6) % 7 + 3);
65         var ms = valueOf();
66         setUTCMonth(0, 4);
67         var WN = Math.round((ms - valueOf()) / 604800000) + 1;
68         return [getUTCFullYear(), WN, DoW == 0 ? 7 : DoW];
69     }
70 }
71 function dayofyear(d) { // d is a Date object
72 var yn = d.getFullYear();
73 var mn = d.getMonth();
74 var dn = d.getDate();
75 var d1 = new Date(yn,0,1,12,0,0); // noon on Jan. 1
76 var d2 = new Date(yn,mn,dn,12,0,0); // noon on input date
77 var ddiff = Math.round((d2-d1)/864e5);
78 return ddiff+1;
79 }
80
81
82 // create irregularity object.
83 function IrregularPattern() {
84         this.months = new Array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
85         this.seasons = new Array(_("Autumn"),_("Winter"),_("Spring"),_("Summer"),_("Fall"));
86     this.daynames = new Array(_("Monday"),_("Tuesday"),_("Wednesday"),_("Thursday"),_("Friday"),_("Saturday"),_("Sunday"));
87     // create weeks irregularity selection array:
88     this.firstissue = new Date();
89     this.firstissue.setDate(1);
90     this.firstissue.setMonth(0);
91     [% IF ( firstacquiyear ) %] // it's a mod, we already have a start date.
92         this.firstissue.setFullYear( [% firstacquiyear %] );
93     [% END %]
94         this.weeks = getWeeksArray(this.firstissue); 
95
96     this.numskipped = 0;
97     // init:
98         var irregular = '[% irregularity %]';
99     this.skipped = irregular.split(',');
100 }
101
102 IrregularPattern.prototype.update = function() {
103                 this.skipped= new Array;
104                 var cnt = 0;
105                 // daily periodicity, we interpret irregular array as which days of week to skip.
106                 // else if weekly periodicity, week numbers (starting from 01 Jan) to skip.
107         // else  irregular array is list of issues to skip
108                 var summary_str = '';
109                 this.numskipped = 0;
110         if(document.f.irregularity_select) {
111             //$("#irregularity_select option:selected").each(...); //jquery can combine both conditionals and the for loop
112             for( var i in document.f.irregularity_select.options ) {
113                 if( document.f.irregularity_select.options[i].selected ) {
114                     this.skipped[cnt] = document.f.irregularity_select.options[i].value ;
115                     summary_str += document.f.irregularity_select.options[i].text + "\n" ;
116                                     cnt++;
117                                     this.numskipped++;
118                             }
119                     }
120                     var summary = document.getElementById("irregularity_summary");
121                     if(summary) {
122                             summary.value = summary_str;
123                             summary.rows= ( cnt > 6 ) ? cnt : 6 ; // textarea will bre resized, but not more than 6 lines will show.
124                     }
125         }
126 }
127
128 IrregularPattern.prototype.irregular = function(index) { 
129         for( var i in this.skipped) {
130                         if( this.skipped[i] == index) {
131                                 return true;
132                         }
133         }
134         return false;
135 }
136
137 function init_pattern() {
138         irregular_issues = new IrregularPattern();
139 }
140 function reset_pattern() {
141         document.getElementById("numberpattern").value = '';
142     document.getElementById("irregularity").innerHTML = '';
143         init_pattern();
144         reset_num_pattern();
145 }
146
147 // common pre defined number patterns
148 function reset_num_pattern() {
149 var patternchoice = document.getElementById("numberpattern").value;
150     switch(patternchoice){
151     case "2":
152         document.f.add1.value=1;
153         document.f.add2.value=1;
154         document.f.add3.value=1;
155         document.f.every1.value=12;
156         document.f.every2.value=1;
157         document.f.every3.value=1;
158         document.f.whenmorethan1.value=9999999;
159         document.f.whenmorethan2.value=12;
160         document.f.whenmorethan3.value=4;
161         document.f.setto1.value=0;
162         document.f.setto2.value=1;
163         document.f.setto3.value=1;
164         document.f.lastvalue1.value=1;
165         document.f.lastvalue2.value=1;
166         document.f.lastvalue3.value=1;
167         document.f.numberingmethod.value=_("Vol {X}, No {Y}, Issue {Z}");
168         moreoptions(text[1],text[0],text[2]);
169         display_table(0); // toggle info box on (1) or off (0)
170         break;
171     case "3":
172         document.f.add1.value=1;
173         document.f.add2.value=1;
174         document.f.add3.value='';
175         document.f.every1.value=12;
176         document.f.every2.value=1;
177         document.f.every3.value='';
178         document.f.whenmorethan1.value=9999999;
179         document.f.whenmorethan2.value=12;
180         document.f.whenmorethan3.value='';
181         document.f.setto1.value=0;
182         document.f.setto2.value=1;
183         document.f.setto3.value='';
184         document.f.lastvalue1.value=1;
185         document.f.lastvalue2.value=1;
186         document.f.lastvalue3.value='';
187         document.f.numberingmethod.value=_("Vol {X}, No {Y}");
188         moreoptions(text[1],text[0]);
189         display_table(0);
190         break;
191     case "4":
192         document.f.add1.value=1;
193         document.f.add2.value=1;
194         document.f.add3.value='';
195         document.f.every1.value=12;
196         document.f.every2.value=1;
197         document.f.every3.value='';
198         document.f.whenmorethan1.value=9999999;
199         document.f.whenmorethan2.value=12;
200         document.f.whenmorethan3.value='';
201         document.f.setto1.value=0;
202         document.f.setto2.value=1;
203         document.f.setto3.value='';
204         document.f.lastvalue1.value=1;
205         document.f.lastvalue2.value=1;
206         document.f.lastvalue3.value='';
207         document.f.numberingmethod.value=_("Vol {X}, Issue {Y}");
208         moreoptions(text[1],text[2]);
209         display_table(0);
210         break;
211     case "5":
212 //        var d = new Date(document.f.firstacquidate.value);
213 //        var smonth = d.getMonth();
214         document.f.add1.value=1;
215         document.f.add2.value=1;
216         document.f.add3.value='';
217         document.f.every1.value=12;
218         document.f.every2.value=1;
219         document.f.every3.value='';
220         document.f.whenmorethan1.value=9999999;
221         document.f.whenmorethan2.value=12;
222         document.f.whenmorethan3.value='';
223         document.f.setto1.value=0;
224         document.f.setto2.value=1;
225         document.f.setto3.value='';
226         document.f.numberingmethod.value=_("No {X}, Issue {Y}");
227         moreoptions(text[0],text[2]);
228         display_table(0);
229         break;
230     case "6":
231         var d = new Date(document.f.firstacquidate.value);
232         var sYear = d.getFullYear();
233         moreoptions_seasons(text[15],sYear);
234         var d = new Date(document.f.firstacquidate.value);
235         var sYear = d.getFullYear();
236         document.f.add1.value=1;
237         document.f.add2.value='1';
238         document.f.add3.value='';
239         document.f.every1.value=4;
240         document.f.every2.value='1';
241         document.f.every3.value='';
242         document.f.whenmorethan1.value=9999999;
243         document.f.whenmorethan2.value='4';
244         document.f.whenmorethan3.value='';
245         document.f.setto1.value=0;
246         document.f.setto2.value='1';
247         document.f.setto3.value='';
248         document.f.periodicity.value='8';
249         document.f.numberingmethod.value=_("{Y} {X}");
250         moreoptions_seasons(text[15],sYear);
251         document.f.lastvalue1temp.value=document.f.lastvalue1.value=sYear;
252         display_table(0);
253         is_season = 1;
254         break;
255     case "7":
256         display_table(1);
257         document.getElementById("more_options").innerHTML = '';
258         document.f.irreg_check.value=1; 
259         break;
260     case "8":  // Year/Number
261         var d = (document.f.firstacquidate.value) ? new Date( document.f.firstacquidate.value) : new Date() ;
262         var sYear = d.getFullYear();
263         document.f.add1.value=1;
264         document.f.add2.value=1;
265         document.f.add3.value='';
266         document.f.every1.value=12;
267         document.f.every2.value=1;
268         document.f.every3.value='';
269         document.f.whenmorethan1.value=9999999;
270         document.f.whenmorethan2.value=12;
271         document.f.whenmorethan3.value='';
272         document.f.setto1.value=0;
273         document.f.setto2.value=1;
274         document.f.setto3.value='';
275         document.f.lastvalue1.value=sYear;
276           switch (document.f.periodicity.value){
277             case 1:              
278               var doy = dayofyear(d);
279               document.f.lastvalue2.value=doy; 
280               document.f.whenmorethan2.value=365; 
281               break;      
282             case 12:     
283               var doy = dayofyear(d);
284               document.f.lastvalue2.value=doy*2; 
285               document.f.whenmorethan2.value=730; 
286               break;      
287             case 2:
288             case 3:
289             case 4:
290               var YWDa = YMDaToYWDa(d);
291               document.f.lastvalue2.value=YWDA[1]/(document.f.periodicity.value-1); 
292               break;      
293             case 5:
294               var smonth = d.getMonth();
295               document.f.lastvalue2.value=smonth;
296               break;      
297             case 6:
298               var smonth = d.getMonth();
299               document.f.lastvalue2.value=smonth/2;
300               document.f.whenmorethan2.value=6;
301               break;      
302             case 7:
303             case 8:      
304               var smonth = d.getMonth();
305               document.f.lastvalue2.value=smonth/3;
306               document.f.whenmorethan2.value=4;
307               break;      
308             case 9:                        
309               var smonth = d.getMonth();
310               document.f.lastvalue2.value=smonth/6;
311               document.f.whenmorethan2.value=2;
312               break;      
313             default:
314           } 
315         document.f.lastvalue3.value='';
316         document.f.numberingmethod.value=_("{X} / {Y}");
317         moreoptions(text[16],text[0]);
318      //   document.f.lastvalue1temp.value=sYear;
319      //   document.f.lastvalue2temp.value=document.f.lastvalue2.value;
320         display_table(0);
321         break;
322     default:
323         document.f.add1.value=1;
324         document.f.add2.value='';
325         document.f.add3.value='';
326         document.f.every1.value=1;
327         document.f.every2.value='';
328         document.f.every3.value='';
329         document.f.whenmorethan1.value=9999999;
330         document.f.whenmorethan2.value='';
331         document.f.whenmorethan3.value='';
332         document.f.setto1.value=0;
333         document.f.setto2.value='';
334         document.f.setto3.value='';
335         document.f.lastvalue1.value=1;
336         document.f.lastvalue2.value='';
337         document.f.lastvalue3.value='';
338         document.f.numberingmethod.value='{X}';
339 //        moreoptions_daily_check(text[0]);
340         moreoptions(text[0]);
341         document.f.irreg_check.value=1;
342         display_table(0);
343         break;
344     }
345 }
346
347 function display_table(n) {
348     if(n==1){
349         document.getElementById("basetable").style.display = 'block';
350     } else if(n==0){
351         document.getElementById("basetable").style.display = 'none';
352     } else {
353                 var disp_val = ( document.getElementById("basetable").style.display == 'none' ) ? 'block' : 'none' ;
354                         document.getElementById("basetable").style.display = disp_val;
355         }
356 }
357
358 function set_num_pattern_from_template_vars() {
359         if(!document.getElementById("numberpattern")){ return false; }
360     document.getElementById("numberpattern").value = '[% numberpattern %]';
361     reset_num_pattern();
362     
363     document.f.add1.value='[% add1 %]';
364     document.f.add2.value='[% add2 %]';
365     document.f.add3.value='[% add3 %]';
366     document.f.every1.value='[% every1 %]';
367     document.f.every2.value='[% every2 %]';
368     document.f.every3.value='[% every3 %]';
369     document.f.whenmorethan1.value='[% whenmorethan1 %]';
370     document.f.whenmorethan2.value='[% whenmorethan2 %]';
371     document.f.whenmorethan3.value='[% whenmorethan3 %]';
372     document.f.setto1.value='[% setto1 %]';
373     document.f.setto2.value='[% setto2 %]';
374     document.f.setto3.value='[% setto3 %]';
375     document.f.lastvalue1.value='[% lastvalue1 %]';
376     document.f.lastvalue2.value='[% lastvalue2 %]';
377     document.f.lastvalue3.value='[% lastvalue3 %]';
378     document.f.numberingmethod.value='[% numberingmethod %]';
379
380     var more_strY;
381     var more_strZ;
382     [% IF ( add2 ) %]
383     if([% add2 %] > 0){
384         more_strY="Y";
385     }
386     [% END %]
387     [% IF ( add3 ) %]
388     if([% add3 %] > 0){
389         more_strZ="Z";
390     }
391     [% END %]
392     document.f.lastvalue1temp.value='[% lastvalue1 %]';
393     if(more_strY){
394         document.f.lastvalue2temp.value='[% lastvalue2 %]';
395     document.f.whenmorethan2temp.value='[% whenmorethan2 %]';
396     }
397     if(more_strZ){
398         document.f.lastvalue3temp.value='[% lastvalue3 %]';
399     document.f.whenmorethan3temp.value='[% whenmorethan3 %]';
400     }
401 }
402
403 // a pre check with more options to see if 'number' and '1/day' are chosen
404 function moreoptions_daily_check(x) {
405     var periodicity = document.f.periodicity.value;
406     var errortext='';
407     if(periodicity == 1){ // i.e. daily
408         document.getElementById("irregularity").innerHTML = '';
409         errortext =_("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
410         for(var j=0;j<irregular_issues.daynames.length;j++){
411             errortext +="<input type='checkbox' name='irregular' id='irregular"+(j+1)+"' value='"+(j+1)+"' />"+irregular_issues.daynames[j]+" &nbsp; ";
412         }
413         var error = errortext;
414         moreoptions(x);
415         document.getElementById("irregularity").innerHTML = error;
416     } else {
417         document.getElementById("irregularity").innerHTML = '';
418         document.getElementById("more_options").innerHTML = '';
419         moreoptions(x);
420     }
421 }
422
423 // to dispaly the more options section
424 function moreoptions(x,y,z){
425 document.getElementById("irregularity").innerHTML = '';
426 document.getElementById("more_options").innerHTML = '';
427 var textbox = '';
428     // alert("X: "+x+"Y: "+y+"Z: "+z);
429     if(x){
430         textbox +="<table id='irregularity_table'>\n<tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
431         if(y){
432             textbox +="<th>"+y+"<\/th>";
433             if(z){
434                 textbox +="<th>"+z+"<\/th>";
435             }
436         }
437         textbox +="<\/tr>\n";
438         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/td><td><input type='text' name='lastvalue1temp' id='lastvalue1temp' size='4' onkeyup='moreoptionsupdate(this)' value=\"" + document.f.lastvalue1.value +  "\" /><\/td>\n";
439         if(y){
440             textbox +="<td><input type=\"text\" name=\"lastvalue2temp\" id=\"lastvalue2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue2.value + "\" /><\/td>\n";
441             if(z){
442                 textbox +="<td><input type=\"text\" name=\"lastvalue3temp\" id=\"lastvalue3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this)\" value=\"" + document.f.lastvalue3.value + "\" /><\/td>\n";
443             }
444         }
445         textbox +="<\/tr>\n";
446         if(y){
447             textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
448             textbox +="<td>&nbsp;<\/td>\n";
449             textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
450             if(z){
451                 textbox +="<td><input type=\"text\" name=\"whenmorethan3temp\" id=\"whenmorethan3temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
452             }
453             textbox +="<\/tr>";
454         } else {
455           textbox +="<tr> <td>"+_("issues expected")+"<\/td><td><input type=\"text\" name=\"issuesexpected1temp\" id=\"issuesexpected1temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,0)\" value=\"" + document.f.issuesexpected1.value + "\" ><\/td><\/tr>";
456         }
457         textbox +="<\/table>\n";
458     }
459     document.getElementById("more_options").innerHTML = textbox;
460 }
461
462 function hemispheres(chosen){
463 var selbox = document.getElementById("season1");
464     if(selbox){
465     var selboxselected = selbox.options[selbox.selectedIndex].value;
466     selbox.options.length = 0;
467
468     if ( (chosen == "1") || ( ! (chosen) && is_hemisphere == 1 )) {
469         selbox.options[selbox.options.length] = new Option(text[11],'1');
470         selbox.options[selbox.options.length] = new Option(text[12],'2');
471         selbox.options[selbox.options.length] = new Option(text[13],'3');
472         selbox.options[selbox.options.length] = new Option(text[14],'4');
473         is_hemisphere = 1;
474         selbox.options[selboxselected-1].selected = true;
475     }
476
477     if ( (chosen == "2") || ( ! (chosen) && is_hemisphere == 2 )) {
478         selbox.options[selbox.options.length] = new Option(text[13],'1');
479         selbox.options[selbox.options.length] = new Option(text[10],'2');
480         selbox.options[selbox.options.length] = new Option(text[11],'3');
481         selbox.options[selbox.options.length] = new Option(text[12],'4');
482         is_hemisphere = 2;
483         selbox.options[selboxselected-1].selected = true;
484     }
485     }
486 }
487
488 // to display the more options section for seasons
489 function moreoptions_seasons(x,y){
490 // x = 'Season'.  y = 'Year'.
491 document.getElementById("irregularity").innerHTML = '';
492 document.getElementById("more_options").innerHTML = '';
493 var textbox = '';
494     //alert("X: "+x+"Year: "+y);
495     if(x){
496         var hemi_select = parseInt('[% hemisphere %]');
497         textbox +="<li><label for=\"hemisphere\">"+ text[7]  +"<\/label><select name=\"hemisphere\" id=\"hemisphere\" onchange=\"hemispheres(this.options[this.selectedIndex].value)\">";
498         for(var i = 1; i <= 2; i++){
499             textbox +="<option value='"+i+"'";
500             if(i == hemi_select){
501                 textbox += " selected "
502             }
503             textbox +=">"+text[i+7]+"<\/option>";
504         }
505         textbox +="<\/li>\n";
506         textbox +="<table id=\"seasonal_irregularity\"><tr><th>&nbsp;<\/th><th>"+x+"<\/th>";
507         textbox +="<th>"+text[16]+"<\/th>";
508         textbox +="<\/tr>\n";
509         textbox +="<tr><th scope=\"row\">"+text[5]+"<\/th><td><select name=\"lastvalue2temp\" id=\"lastvalue2temp\" id=\"season1\" onchange=\"moreoptionsupdate(this)\">";
510         for(var j = 1; j <= 4; j++){
511             textbox +="<option value='"+j+"'>"+text[j+9]+"<\/option>";
512         }
513         textbox +="<\/select><\/td>";
514         var isyr = irregular_issues.firstissue;
515         textbox += "<td>" + irregular_issues.firstissue.getFullYear() + "<\/td><\/tr>\n";
516         textbox +="<tr><th scope=\"row\">"+text[6]+"<\/th>";
517         textbox +="<td><input type=\"text\" name=\"whenmorethan2temp\" id=\"whenmorethan2temp\" size=\"4\" onkeyup=\"moreoptionsupdate(this,1)\"><\/td>\n";
518         textbox +="<\/tr><\/table>\n";
519     }
520     document.getElementById("more_options").innerHTML = textbox;
521 }
522
523 function irregularity_check(){
524     document.f.irreg_check.value = 1; // Irregularity button now pushed
525     var periodicity = document.f.periodicity.value;
526         var rollover = document.f.issuesexpected1.value;
527     if( (document.f.whenmorethan2) && ( document.f.whenmorethan2.value > 0) ){
528       rollover = document.f.whenmorethan2.value;
529     }
530     if((document.f.whenmorethan3) && document.f.whenmorethan3.value > 0 ){
531         // FIXME: Irregularity check assumes that the full prediction pattern repeats each year.
532                 //  In cases where the outermost periodicity is > 1 year,  
533                 //  e.g. where a volume spans two years, the irregularity check will be incorrect, 
534         // but you can safely ignore the check, submit the form, and the prediction pattern should be correct.
535                 //  a way to distinguish between these two cases is needed.
536                 rollover = document.f.whenmorethan3.value * document.f.whenmorethan2.value;
537     }
538     var error='';
539     var toobig;
540     var expected; 
541     var errortext = "<b>"+_("Warning irregularity detected")+"</b><br \/>";
542     switch(periodicity){
543     case "12":
544         if(rollover < 730) expected =730;
545         if(rollover > 730) {
546             expectedover=730;
547             toobig=1;
548         }
549         break;
550     case "1":
551         if(rollover < 365) expected =365;
552         if(rollover > 365) {
553             expectedover=365;
554             toobig=1;
555         }
556         break;
557     case "2":
558         if(rollover < 52) expected =52;
559         if(rollover > 52){
560             expectedover=52;
561             toobig=1;
562         }
563         break;
564     case "3":
565         if(rollover < 26) expected =26;
566         if(rollover > 26){
567             expectedover=26;
568             toobig=1;
569         }
570         break;
571     case "4":
572         if(rollover < 17) expected =17;
573         if(rollover > 17){
574             expectedover=17;
575             toobig=1;
576         }
577         break;
578     case "5":
579         if(rollover < 12) expected =12;
580         if(rollover > 12){
581             expectedover=12;
582             toobig=1;
583         }
584         break;
585     case "6":
586         if(rollover < 6) expected =6;
587         if(rollover > 6){
588             expectedover=6;
589             toobig=1;
590         }
591         break;
592     case "7":
593         if(rollover < 4) expected =4;
594         if(rollover > 4){
595             expectedover=4;
596             toobig=1;
597         }
598         break;
599     case "8":
600         if(rollover < 4) expected =4;
601         if(rollover > 4){
602             expectedover=4;
603             toobig=1;
604         }
605         break;
606     case "9":
607         if(rollover < 2) expected =2;
608         if(rollover > 2){
609             expectedover=2;
610             toobig=1;
611         }
612         break;
613     case "10":
614         if(rollover < 1) expected =1;
615         if(rollover > 1){
616             expectedover=1;
617             toobig=1;
618         }
619         break;
620     default:
621         break;
622     }
623     if(expected){
624         if(expected == 365 || expected==730){  // what about leap years ?
625                         // FIXME:  We interpret irregularity as which days per week for periodicity==1.
626                         //  We need two cases: one in which we're published n days/week, in which case irregularity should be per week,
627                         //  and a regular daily pub, where irregularity should be per year.
628             errortext += _("Please indicate which days of the week you DO NOT expect to receive issues.")+"<br \/>";
629         } else {
630             errortext +=expected+_(" issues expected, ")+rollover+_(" were entered.")+"<br \/>"+_("Please indicate which date(s) an issue is not expected")+"<br \/>";
631             irregular_issues.numskipped = expected - rollover;
632                 }
633         errortext +="<select multiple id=\"irregularity_select\" name=\"irregularity_select\" onchange=\"irregular_issues.update();\">\n";
634                 errortext +=irregular_options(periodicity);
635                 errortext += "<\/select>\n <textarea rows=\"6\" width=\"18\" id=\"irregularity_summary\" name=\"irregularity_summary\" value=\"foo\"><\/textarea>";
636         error=errortext;
637     }
638     if(toobig){
639         errortext +=expectedover+_(" issues expected, ")+rollover+_(" were entered")+"<p class=\"warning\">"+_("You seem to have indicated more issues per year than expected.<\/p>");
640         error=errortext;
641     }
642     if(error.length ==0){
643         error=_("No irregularities noticed");
644     }
645         display_example(expected);
646     document.getElementById("irregularity").innerHTML = error;
647         irregular_issues.update();
648 }
649
650 function irregular_options(periodicity){
651     var titles;
652     var count;
653     var errortext='';
654     var numberpattern = document.getElementById('numberpattern').value;
655     if(periodicity == 1) {
656         expected = 7;
657         titles = irregular_issues.daynames;
658         count = 1;
659     }
660     if(periodicity == 2 || periodicity == 3 || periodicity == 4) { 
661         titles = irregular_issues.weeks;
662                 count = 1;
663         if(periodicity==3) {  // 1/2 wks
664             expected = 26;
665         } else if(periodicity == 4) { // 1/3 wks
666             expected = 17;
667         } else {
668             expected = 52;
669         }
670     }
671     if(periodicity == 5 || periodicity == 6 || periodicity == 7 || periodicity == 8 || periodicity == 9) {
672         if(periodicity == 8 && numberpattern==8) {
673             is_season = 1; // setting up from edit page
674         } 
675         if(is_season){
676             titles = irregular_issues.seasons;
677             expected = 4;
678             if(is_hemisphere == 2){
679                 count = 2;
680             } else {
681                 count = 1;
682             }
683         } else {
684             titles = irregular_issues.months;
685             expected = 12;
686             count = 1;
687         }
688     }
689         if( !expected) {
690                 return '';   // don't know how to deal with irregularity.
691         }       
692     for(var j=0;j<expected;j++){   // rch - changed frrom (1..expected).
693         if(isArray(titles)){
694             if(count>expected){
695                 count = count-expected;
696             }
697             if(is_season && is_hemisphere == 1){
698                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j]+"<\/option>\n";
699 // alert("value: "+((count*3)-2)+" title: "+titles[j]);
700             } else if(is_season && is_hemisphere == 2){
701                 errortext +="<option value='"+((count*3)-2)+"'>"+titles[j-1]+"<\/option>\n";
702 // alert("value: "+((count*3)-2)+" title: "+titles[j-1]);
703             } else {  // all non-seasonal periodicities:
704                 var incr=1; // multiplier for ( 1/n weeks)  patterns; in this case the irreg calc relies on the week# , not the issue#.
705                 if(periodicity==3) {  // 1/2 wks
706                     incr=2;
707                 } else if(periodicity == 4) { // 1/3 wks
708                     incr=3;
709                 }
710                 errortext += "<option value='" + (1+j*incr) ;  
711                                 if(irregular_issues.irregular(1+incr*j)) {
712                                         errortext += "' selected='selected" ;
713                                 }
714                                 errortext += "'>"+titles[incr*j]+"<\/option>\n";
715             }
716             count++;
717         } else { 
718             errortext +="<option value='"+j+"'>"+titles+" "+j+"<\/option>\n";
719         }
720     }
721     return errortext;
722 }
723
724
725 function display_example(expected){
726     var startfrom1 = parseInt(document.f.lastvalue1.value);
727     var startfrom2 = parseInt(document.f.lastvalue2.value);
728     var startfrom3 = parseInt(document.f.lastvalue3.value);
729     var every1 = parseInt(document.f.every1.value);
730     var every2 = parseInt(document.f.every2.value);
731     var every3 = parseInt(document.f.every3.value);
732     var numberpattern = document.f.numberingmethod.value;
733     var whenmorethan2 = parseInt(document.f.whenmorethan2.value);
734     var whenmorethan3 = parseInt(document.f.whenmorethan3.value);
735     var setto2 = parseInt(document.f.setto2.value);
736     var setto3 = parseInt(document.f.setto3.value);
737     var displaytext = _("Based on the information entered, the Numbering Pattern will look like this: ") + "<br \/><ul class=\"numpattern_preview\">";
738     if(startfrom3>0){
739         var count=startfrom3-1;
740         var count2=startfrom2;
741         for(var i = 0 ; i < 12; i++){
742             if(count>=whenmorethan3){
743                 count=setto3;
744                 if(count2>=whenmorethan2){
745                     startfrom1++;
746                     count2=setto2;
747                 } else {
748                     count2++;
749                 }
750             } else {
751                 count++;
752             }
753             displaytext += '<li>' + numberpattern.replace(/{Z}/,count) + '<\/li>\n';
754             displaytext = displaytext.replace(/{Y}/,count2);
755             displaytext = displaytext.replace(/{X}/,startfrom1);
756
757         }
758     }
759     if(startfrom2>0 && !startfrom3){
760         var count=startfrom2-1;
761         for(var i=0;i<12;i++){
762             if(count>=whenmorethan2){
763                 startfrom1++;
764                 count=setto2;
765             } else {
766                 count++;
767             }
768
769             if(is_season){
770                 if(is_hemisphere == 2){
771                     if(count == 1) {
772                         displaytext += numberpattern.replace(/{Y}/,text[count+12])+'\n';
773                     } else {
774                         displaytext += numberpattern.replace(/{Y}/,text[count+8])+'\n';
775                     }
776                 } else {
777                 displaytext += numberpattern.replace(/{Y}/,text[count+10])+'\n';
778                 }
779             } else {
780                 displaytext += numberpattern.replace(/{Y}/,count)+'\n';
781             }
782             displaytext = displaytext.replace(/{X}/,startfrom1)+'<br \/>\n';
783         }
784     }
785     if(startfrom1>0 && !startfrom2 && !startfrom3){
786         var offset=eval(document.f.issuesexpected1.value);
787         if (!offset){
788             offset = 12 
789         }
790         for(var i=startfrom1;i<(startfrom1+offset);i+=every1){
791             displaytext += numberpattern.replace(/{X}/,i)+'<br \/>\n';
792         }
793     }
794    //  displaytext = "<div style='padding: 5px; background-color: #CCCCCC'>"+displaytext+"<\/div>";
795     document.getElementById("displayexample").innerHTML = displaytext;
796 }
797
798 function isArray(obj) {
799 if (obj.constructor.toString().indexOf("Array") == -1)
800     return false;
801 else
802     return true;
803 }
804
805 function moreoptionsupdate(inputfield,rollover){
806     fieldname = inputfield.name;
807     // find parent element in base table by stripping 'temp' from element name.
808     basefield = document.getElementById(fieldname.slice(0,-4));
809     var fieldnumber = fieldname.slice(-5,-4);
810
811     basefield.value = inputfield.value;
812     var patternchoice = document.getElementById("numberpattern").value;
813     switch(patternchoice){
814     case "2":
815     case "4":
816     case "5":
817     case "8": // Year, Number.  -- Why not just use Vol, Number withvol==year??
818                 //  FIXME: this my conflict with innerloop calc below.
819        if (document.f.lastvalue2temp.value > 0){document.f.innerloop1.value = document.f.lastvalue2temp.value - 1;}
820       break;   
821     }  
822     if(basefield.name.slice(0,-1) == 'lastvalue' || 'whenmorethan' ) {
823         // The enumeration string is held in a positional numeral notation with three positions, X,Y,Z.
824         // The last values lastvalue1, lastvalue2,lastvalue3 should match the last received serial's X,Y,Z enumeration.
825         // make array indexes start with 1 for consistency with variable names.
826         var innerloop = new Array( undefined, document.getElementById('innerloop1'), document.getElementById('innerloop2'), document.getElementById('innerloop3') );
827         var lastvalue = new Array( undefined, document.getElementById('lastvalue1').value *1 , document.getElementById('lastvalue2').value *1 , document.getElementById('lastvalue3').value *1  );
828         var every = new Array( undefined, document.getElementById('every1').value *1 , document.getElementById('every2').value *1 , document.getElementById('every3').value *1  );
829         var add = new Array( undefined, document.getElementById('add1').value *1 , document.getElementById('add2').value *1 , document.getElementById('add3').value *1  );
830         var whenmorethan = new Array( undefined, document.getElementById('whenmorethan1').value *1 , document.getElementById('whenmorethan2').value *1 , document.getElementById('whenmorethan3').value *1  );
831         
832        if(rollover){
833        // calculate rollover  for higher level of periodicity.
834        // if there are two levels of periodicity, (e.g. vol{X},num{Y},issue{Z}, then every1=every2*whenmorethan2 / add2 .
835           for(var N=3;N>1;N--){
836             if( add[N] > 0){
837                 var addN = (add[N]) ? add[N] : 1 ;
838                 var everyN = (document.getElementById('every'+N)) ? document.getElementById('every'+N).value : 1 ;
839                 document.getElementById('every'+(N-1)).value = whenmorethan[N] * everyN / addN ;
840             }
841           }
842         }
843         innerloop[3].value = ( every[3] > 1 ) ? lastvalue[3] % every[3] : 0 ;
844         innerloop[2].value = ( every[2] > 1 ) ? lastvalue[3] - 1 : 0 ;
845         innerloop[1].value = ( every[1] > 1 ) ? 
846                                     ( whenmorethan[3] > 0 ) ?  (lastvalue[2] - 1) * every[2] + 1* innerloop[2].value 
847                                                             : lastvalue[2] - 1
848                                                : 0 ;
849     }
850      //FIXME : add checks for innerloop || lastvalue .gt. rollover  
851 }
852
853
854 function check_input(e){
855     var unicode=e.charCode? e.charCode : e.keyCode
856     if (unicode!=8 && unicode !=46 && unicode!=9 && unicode !=13){ // if key isn't backspace or delete
857         if (unicode<48||unicode>57) { // if not a number
858             alert(_("Needs to be entered in digit form -eg 10"));
859             return false // disable key press
860         }
861     }
862 }
863
864 function addbiblioPopup(biblionumber) {
865         var destination = "/cgi-bin/koha/cataloguing/addbiblio.pl?mode=popup";
866         if(biblionumber){ destination += "&biblionumber="+biblionumber; }
867  window.open(destination,'AddBiblioPopup','width=1024,height=768,toolbar=no,scrollbars=yes');
868 }
869
870 function Plugin(f)
871 {
872          window.open('subscription-bib-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
873 }
874
875 function FindAcqui(f)
876 {
877          window.open('acqui-search.pl','FindASupplier','width=800,height=400,toolbar=no,scrollbars=yes');
878 }
879
880 function Find_ISSN(f)
881 {
882          window.open('issn-search.pl','FindABibIndex','width=800,height=400,toolbar=no,scrollbars=yes');
883 }
884
885
886 function Check(f) {
887     if (f.aqbooksellerid.value.length==0) {
888         input_box = confirm(_("If you wish to claim late or missing issues you must link this subscription to a vendor. Click OK to ignore or Cancel to return and enter a vendor"));
889                 if (input_box==true) {
890                 }
891                 else {
892                         return false;
893                 }
894     }
895         if (f.biblionumber.value.length==0) {
896         alert(_("You must choose or create a biblio"));
897     } else if(f.startdate.value.length != 0 && f.sublength.value > 0) {
898         if (f.irreg_check.value == 1) {
899             document.f.submit();
900         } else {
901             if(f.numbering_pattern.value == ''){
902                 alert(_("Please choose a numbering pattern"));
903             } else {
904                 alert(_("Please check for irregularity by clicking 'Test Prediction Pattern'"));
905             }
906         }
907     } else {
908         alert(_("You must choose a start date and a subscription length"));
909     }
910         if(irregular_issues.numskipped < irregular_issues.skipped.length ) {
911                 alert(_("You have not accounted for all missing issues."));
912         }
913     return false;
914 }
915
916 $(document).ready(function() {
917     init_pattern();
918     // http://jqueryui.com/demos/datepicker/#date-range
919     var dates = $( "#histstartdate, #histenddate" ).datepicker({
920         changeMonth: true,
921         numberOfMonths: 1,
922         onSelect: function( selectedDate ) {
923             var option = this.id == "histstartdate" ? "minDate" : "maxDate",
924                 instance = $( this ).data( "datepicker" );
925                 date = $.datepicker.parseDate(
926                     instance.settings.dateFormat ||
927                     $.datepicker._defaults.dateFormat,
928                     selectedDate, instance.settings );
929             dates.not( this ).datepicker( "option", option, date );
930         }
931     });
932
933     [% IF ( manualhistory ) %] $("#subscription_form_history").show();[% END %]
934         $("#cancel_manual_history").click(function(){
935                 $("#subscription_form_history").hide();
936         $("#manuallist").removeAttr("checked");
937         });
938         $("#manuallist").click( function(){
939                 if($(this).attr("checked")){
940                         $("#subscription_form_history").show();
941                 } else {
942                         $("#subscription_form_history").hide();
943                 }
944         }
945         );
946    //  $(".widelabel").attr("width", "300px");  // labels stay skinny in IE7 anyway.
947 [% IF ( modify ) %]
948     set_num_pattern_from_template_vars();
949     [% IF ( hemisphere ) %]
950         is_hemisphere = [% hemisphere %] ;
951     hemispheres();
952     [% END %]
953 [% END %]
954 [% IF ( irregularity ) %]
955     irregularity_check();
956 [% END %]
957     $('#numberpattern').change( function() { 
958         reset_num_pattern(); 
959     });
960
961     var node;
962     [% FOREACH field IN dont_export_field_loop %]
963         node = $("#[% field.fieldid %]");
964         if ( $(node).is('input') || $(node).is('textarea') ) {
965             $(node).val("");
966         } else if ( $(node).is('select') ) {
967             $(node).find("option:first").attr('selected','selected');
968         }
969     [% END %]
970 });
971 //]]>
972 </script>
973 </head>
974 <body id="ser_subscription-add" class="ser">
975 [% INCLUDE 'header.inc' %]
976 [% INCLUDE 'serials-search.inc' %]
977
978 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; [% IF ( modify ) %]<a href="/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=[% subscriptionid %]"><i>[% bibliotitle |html %]</i></a> &rsaquo; Modify subscription[% ELSE %]New subscription[% END %]</div>
979
980 <div id="doc3" class="yui-t7">
981    
982    <div id="bd">
983 <h1>[% IF ( modify ) %] Modify subscription for <i>[% bibliotitle |html %]</i>[% ELSE %]Add a new subscription[% END %]</h1>
984    <div class="yui-g">
985     <form method="post" name="f" action="/cgi-bin/koha/serials/subscription-add.pl">
986 [% IF ( modify ) %]
987         <input type="hidden" name="op" value="modsubscription" />
988         <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
989 [% ELSE %]
990         <input type="hidden" name="op" value="addsubscription" />
991 [% END %]
992 <input type="hidden" name="user" value="[% loggedinusername %]" />
993 <input type="hidden" name="irreg_check" value="0" />
994 <input type="hidden" name="issuesexpected1" id="issuesexpected1" value="0" />
995
996         <div class="yui-u first">
997     <fieldset id="subscription_add_information" class="rows">
998         <legend>Subscription details</legend>
999         <ol>
1000             [% IF ( subscriptionid ) %]
1001         <li><span class="label">Subscription #</span> [% subscriptionid %]</li>
1002         [% END %]
1003         <li>
1004             <label for="aqbooksellerid">Vendor: </label>
1005             <input type="text" name="aqbooksellerid" id="aqbooksellerid" value="[% aqbooksellerid %]" size="8" /> (<input type="text" name="aqbooksellername" value="[% aqbooksellername %]" disabled="disabled" readonly="readonly" />) <a href="#" onclick="FindAcqui(f)">Search for a vendor</a>
1006         </li>
1007         <li>
1008             <label for="biblionumber" class="required" title="Subscriptions must be associated with a bibliographic record">Biblio:</label>
1009             
1010                 <input type="text" name="biblionumber" id="biblionumber" value="[% bibnum %]" size="8" /> 
1011                 (<input type="text" name="title" value="[% bibliotitle %]" disabled="disabled" readonly="readonly" />) <span class="required" title="Subscriptions must be associated with a bibliographic record">Required</span>
1012                <div class="inputnote"> <a href="#" onclick="Plugin(f)">Search for Biblio</a>
1013                     [% IF ( CAN_user_editcatalogue ) %] 
1014                        [% IF ( modify ) %]
1015                        | <a href="#" onclick="addbiblioPopup([% bibnum %]); return false;">Edit biblio</a>
1016                        [% ELSE %]
1017                        | <a href="#" onclick="addbiblioPopup(); return false;">Create Biblio</a>
1018                        [% END %]
1019                     [% END %]
1020                </div>
1021             
1022         </li>
1023         <li class="radio">
1024             [% IF ( serialsadditems ) %]
1025                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1" checked="checked" /><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1026                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial </label></p>
1027             [% ELSE %]
1028                 <p><input type="radio" id="serialsadditems-yes" name="serialsadditems" value="1"/><label class="widelabel" for="serialsadditems-yes">create an item record when receiving this serial</label></p>
1029                 <p><input type="radio" id="serialsadditems-no" name="serialsadditems" value="0" checked="checked" /><label class="widelabel" for="serialsadditems-no">do not create an item record when receiving this serial</label></p>
1030             [% END %]
1031         </li>
1032         <li>
1033             <label for="branchcode">Library:</label>
1034             
1035                 <select name="branchcode" id="branchcode" style="width: 20em;">
1036                     [% UNLESS ( Independantbranches ) %]<option value="">None</option>[% END %]
1037                     [% FOREACH branchloo IN branchloop %][% IF ( branchloo.selected ) %]<option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
1038                                 [% ELSE %]
1039                                 <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
1040                                 [% END %]
1041                     [% END %]
1042                 </select> (select a library)
1043             
1044         </li>
1045         <li>
1046             <label for="location">Location:</label>
1047             <select name="location" id="location">
1048                 <option value="">None</option>
1049                 [% FOREACH locations_loo IN locations_loop %][% IF ( locations_loo.selected ) %]<option value="[% locations_loo.authorised_value %]" selected="selected">[% locations_loo.lib %]</option>[% ELSE %]<option value="[% locations_loo.authorised_value %]">[% locations_loo.lib %]</option>[% END %][% END %]
1050             </select>
1051         </li>
1052          <li>
1053             <label for="callnumber">Call number:</label>
1054             <input type="text" name="callnumber" id="callnumber" value="[% callnumber %]" size="20" />
1055         </li>
1056         <li>
1057             <label for="graceperiod">Grace period:</label> <input type="text" name="graceperiod" id="graceperiod" value="[% graceperiod %]" size="5"/> day(s)
1058         </li>
1059         <li>
1060             <label for="notes">OPAC note:</label>
1061             <textarea name="notes" id="notes" cols="30" rows="2">[% notes %]</textarea>
1062         </li>
1063         <li>
1064             <label for="internalnotes">Nonpublic note:</label>
1065             <textarea name="internalnotes" id="internalnotes" cols="30" rows="2">[% internalnotes %]</textarea>
1066         </li>
1067         <li>
1068             
1069                [% IF ( letterloop ) %]
1070             <label for="letter">Patron notification: </label>
1071                            <select name="letter" id="letter">
1072                     <option value="">None</option>
1073                 [% FOREACH letterloo IN letterloop %]
1074                                 [% IF ( letterloo.selected ) %]
1075                     <option value="[% letterloo.value %]" selected="selected">[% letterloo.lettername %]</option>
1076 [% ELSE %]
1077                     <option value="[% letterloo.value %]">[% letterloo.lettername %]</option>
1078 [% END %]
1079                 [% END %]
1080                 </select> 
1081                 <div class="hint">Select a notice and subscribers will be notified when new issues are received.</div>
1082                 [% ELSE %]
1083             <span class="label">Patron notification: </span>
1084                                 <div class="hint">To notify patrons of new serial issues, you must <a href="/cgi-bin/koha/tools/letter.pl">define a notice</a>.</div>
1085                                 [% END %]
1086         </li>
1087                 <li>
1088                          <label class="widelabel" for="staffdisplaycount">Number of issues to display to staff: </label>
1089                          <input type="text" name="staffdisplaycount" id="staffdisplaycount" value="[% staffdisplaycount %]" size="4"/>
1090                  </li>
1091                  <li>
1092             <label class="widelabel" for="opacdisplaycount">Number of issues to display in OPAC: </label>
1093                         <input type="text" name="opacdisplaycount" id="opacdisplaycount" value="[% opacdisplaycount %]" size="4"/>
1094                 </li>
1095         </ol>
1096         </fieldset>
1097         </div>
1098         
1099 <div class="yui-u">
1100 <div id="subscription_form_history" style="display:none"><h3 style="display:inline">Subscription history</h3> <a href="#" id="cancel_manual_history">[cancel manual history]</a>
1101         <p>Hint: you can update the serial history manually. This can be useful for an old subscription or to clean the existing history. Modify these fields with care, as future serial receive will continue to update them automatically.</p>
1102         <fieldset class="rows">
1103             <ol>
1104                 <li>
1105                 <label for="histstartdate">Subscription start date: </label>
1106                 <input type="text" name="histstartdate" id="histstartdate" value="[% histstartdate %]" /><div class="hint"> (start date of the 1st subscription)</div>
1107                 </li>
1108                 <li>
1109                 <label for="histenddate">Subscription end date: </label>
1110                 <input type="text" name="histenddate" id="histenddate" value="[% histenddate %]" /> <div class="hint">(if empty, subscription is still active)</div>
1111                 </li>
1112                 <li>
1113                 <label for="recievedlist">Received issues: </label>
1114                 <textarea name="recievedlist" id="recievedlist" cols="60" rows="5">[% recievedlist %]</textarea>
1115                 </li>
1116                 <li>
1117                 <label for="missinglist">Missing issues: </label>
1118                 <textarea name="missinglist" id="missinglist" cols="60" rows="5">[% missinglist %]</textarea>
1119                 </li>
1120                 <li>
1121                 <label for="opacnote">Note for OPAC: </label>
1122                 <textarea name="opacnote" id="opacnote" cols="60" rows="5">[% opacnote %]</textarea>
1123                 </li>
1124                 <li>
1125                 <label for="librariannote">Note for staff: </label>
1126                 <textarea name="librariannote" id="librariannote" cols="60" rows="5">[% librariannote %]</textarea>
1127                 </li>
1128             </ol>
1129         </fieldset>
1130     <fieldset class="action"><input type="submit" value="Save subscription history"  /></fieldset>
1131 </div>
1132
1133 <div id="subscription_form_planning">
1134         <fieldset class="rows">
1135         <legend>Serials planning</legend>
1136     <ol>
1137         <li>
1138            <label for="acqui_date"> First issue publication date:</label>
1139                 [% IF ( modify ) %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" disabled="disabled" />
1140                 [% ELSE %]<input type="text" name="firstacquidate" value="[% firstacquidate %]"  size="13" maxlength="10" id="acqui_date" class="datepicker" />[% END %]
1141         </li>
1142            [% IF ( modify ) %]<li><label for="next_acqui_date"> Next issue publication date:</label>
1143                 <input type="text" name="nextacquidate" value="[% nextacquidate %]" size="13" maxlength="10" id="next_acqui_date" class="datepicker" />
1144                 </li>[% END %]
1145                 
1146         <li>
1147             <label for="periodicity" class="required">Frequency:</label>
1148                 <select name="periodicity" size="1" id="periodicity" onchange="javascript:document.getElementsByName('manualhist')[0].checked=(this.value==1); reset_num_pattern();">
1149                 <option value="" selected="selected">-- please choose --</option>
1150                 [% IF ( periodicity16 ) %]
1151                 <option value="16" selected="selected">Without periodicity</option>
1152                 [% ELSE %]
1153                     <option value="16">Without periodicity</option>
1154                 [% END %]
1155                 [% IF ( periodicity48 ) %]
1156                 <option value="48" selected="selected">Unknown</option>
1157                 [% ELSE %]
1158                 <option value="48">Unknown</option>
1159                 [% END %]
1160                 [% IF ( periodicity32 ) %]
1161                 <option value="32" selected="selected">Irregular</option>
1162                 [% ELSE %]
1163                     <option value="32">Irregular</option>
1164                 [% END %]
1165
1166                 [% IF ( periodicity12 ) %]
1167                     <option value="12" selected="selected">2/day</option>
1168                 [% ELSE %]
1169                     <option value="12">2/day</option>
1170                 [% END %]
1171                 [% IF ( periodicity1 ) %]
1172                     <option value="1" selected="selected">daily (n/week)</option>
1173                 [% ELSE %]
1174                     <option value="1">daily (n/week)</option>
1175                 [% END %]
1176                 [% IF ( periodicity2 ) %]
1177                     <option value="2" selected="selected">1/week</option>
1178                 [% ELSE %]
1179                     <option value="2">1/week</option>
1180                 [% END %]
1181                 [% IF ( periodicity3 ) %]
1182                     <option value="3" selected="selected">1/2 weeks </option>
1183                 [% ELSE %]
1184                     <option value="3">1/2 weeks </option>
1185                 [% END %]
1186                 [% IF ( periodicity4 ) %]
1187                     <option value="4" selected="selected">1/3 weeks</option>
1188                 [% ELSE %]
1189                     <option value="4">1/3 weeks</option>
1190                 [% END %]
1191                 [% IF ( periodicity5 ) %]
1192                     <option value="5" selected="selected">1/month</option>
1193                 [% ELSE %]
1194                     <option value="5">1/month</option>
1195                 [% END %]
1196                 [% IF ( periodicity6 ) %]
1197                     <option value="6" selected="selected">1/2 months (6/year)</option>
1198                 [% ELSE %]
1199                     <option value="6">1/2 months (6/year)</option>
1200                 [% END %]
1201                 [% IF ( periodicity7 ) %]
1202                     <option value="7" selected="selected">1/3 months (1/quarter)</option>
1203                 [% ELSE %]
1204                     <option value="7">1/3 months (1/quarter)</option>
1205                 [% END %]
1206                 <!-- periodicity8 is 1/quarter, exactly like periodicity7 but will use it for seasonal option -->
1207                 [% IF ( periodicity8 ) %]
1208                     <option value="8" selected="selected">1/quarter (seasonal)</option>
1209                 [% ELSE %]
1210                     <option value="8">1/quarter (seasonal)</option>
1211                 [% END %]
1212                 [% IF ( periodicity13 ) %]
1213                     <option value="13" selected="selected">1/4 months (3/year)</option>
1214                 [% ELSE %]
1215                     <option value="13">1/4 months (3/year)</option>
1216                 [% END %]
1217
1218                 [% IF ( periodicity9 ) %]
1219                     <option value="9" selected="selected">2/years</option>
1220                 [% ELSE %]
1221                     <option value="9">2/year</option>
1222                 [% END %]
1223                 [% IF ( periodicity10 ) %]
1224                     <option value="10" selected="selected">1/year</option>
1225                 [% ELSE %]
1226                     <option value="10">1/year</option>
1227                 [% END %]
1228                 [% IF ( periodicity11 ) %]
1229                     <option value="11" selected="selected">1/2 years</option>
1230                 [% ELSE %]
1231                     <option value="11">1/2 years</option>
1232                 [% END %]
1233                 </select> <span class="required">Required</span></li>
1234                 <li>
1235                     <label for="manuallist"> Manual history:</label>
1236                     [% IF ( manualhistory ) %]
1237                         <input type="checkbox" name="manualhist" id="manuallist" value="1" checked="checked" />
1238                     [% ELSE %]
1239                         <input type="checkbox" name="manualhist" id="manuallist" value="1" />
1240                     [% END %]
1241                 </li>
1242         <li>
1243            <label for="numberpattern"> Numbering pattern:</label>
1244             
1245                 <select name="numbering_pattern" size="1" id="numberpattern" >
1246                     <option value="" selected="selected">-- please choose --</option>
1247                     [% IF ( numberpattern1 ) %]
1248                         <option value="1" selected="selected">Number</option>
1249                     [% ELSE %]
1250                         <option value="1">Number</option>
1251                     [% END %]
1252                     [% IF ( numberpattern2 ) %]
1253                         <option value="2" selected="selected">Volume, number, issue</option>
1254                     [% ELSE %]
1255                         <option value="2">Volume, number, issue</option>
1256                     [% END %]
1257                     [% IF ( numberpattern3 ) %]
1258                         <option value="3" selected="selected">Volume, number</option>
1259                     [% ELSE %]
1260                         <option value="3">Volume, number</option>
1261                     [% END %]
1262                     [% IF ( numberpattern4 ) %]
1263                         <option value="4" selected="selected">Volume, issue</option>
1264                     [% ELSE %]
1265                         <option value="4">Volume, issue</option>
1266                     [% END %]
1267                     [% IF ( numberpattern5 ) %]
1268                         <option value="5" selected="selected">Number, issue</option>
1269                     [% ELSE %]
1270                         <option value="5">Number, issue</option>
1271                     [% END %]
1272                     [% IF ( numberpattern6 ) %]
1273                         <option value="6" selected="selected">Seasonal only</option>
1274                     [% ELSE %]
1275                         <option value="6">Seasonal only</option>
1276                     [% END %]
1277                     [% IF ( numberpattern8 ) %]
1278                         <option value="8" selected="selected">Year/Number</option>
1279                     [% ELSE %]
1280                         <option value="8">Year/Number</option>
1281                     [% END %]          
1282                     [% IF ( numberpattern7 ) %]
1283                         <option value="7" selected="selected">None of the above</option>
1284                     [% ELSE %]
1285                         <option value="7">None of the above</option>
1286                     [% END %]
1287                 </select>
1288         </li>
1289                 <li id="more_options"></li>
1290                 <li id="irregularity"></li>
1291                    <li id="displayexample"></li>
1292         <li>
1293            <label for="from" class="required"> Subscription start date:</label>
1294                 <input type="text" name="startdate" value="[% startdate %]" size="13" maxlength="10" id="from" class="datepickerfrom" />
1295             <span class="required">Required</span>
1296         </li>
1297         <li>
1298             <label for="subtype" class="required">Subscription length:</label>
1299             
1300                 <select name="subtype" id="subtype">
1301                     [% IF ( subtype_monthlength ) %]<option value="monthlength" selected="selected">[% ELSE %]<option value="monthlength">[% END %] Number of months</option>
1302                     [% IF ( subtype_numberlength ) %]<option value="numberlength" selected="selected">[% ELSE %]<option value="numberlength">[% END %] Number of issues</option>
1303                     [% IF ( subtype_weeklength ) %]<option value="weeklength" selected="selected">[% ELSE %]<option value="weeklength">[% END %] Number of weeks</option>
1304                 </select>
1305                 <input type="text" id="numberlength" name="sublength" value="[% sublength %]" size="3" onkeypress="return check_input(event)" /> (enter amount in numerals)
1306             <span class="required">Required</span>
1307         </li>
1308         <li>
1309            <label for="to"> Subscription end date:</label>
1310                 <input type="text" name="enddate" value="[% enddate %]" size="13" maxlength="10" id="to" class="datepickerto" />
1311         </li>
1312     <li><label for="numberingmethod">Numbering formula:</label> <input type="text" name="numberingmethod" id="numberingmethod" value="[% numberingmethod %]" />
1313     </li>
1314     </ol>
1315         </fieldset>
1316
1317         <fieldset class="action">
1318     <input type="button" class="action_test" value="Test prediction pattern" onclick="javascript:irregularity_check()" />
1319     <input type="button" class="action_reset" value="Reset pattern" onclick="javascript:reset_pattern()" />
1320     <input type="button" class="action_save"  value="Save subscription" onclick="Check(this.form)" accesskey="w" />
1321         </fieldset>
1322     <fieldset class="action">
1323     <input type="button" class="action_advanced" value="Show/Hide advanced pattern" onclick="javascript:display_table()" />
1324     </fieldset>
1325            <div id="basetable"  style="display: none;">
1326             <table class="small">
1327                 <tr><th colspan="4">Advanced prediction pattern</th></tr>
1328                                 <tr>
1329                     <th>&nbsp;</th>
1330                     <th>X</th>
1331                     <th>Y</th>
1332                     <th>Z</th>
1333                 </tr>
1334                 <tr>
1335                     <td>Add</td>
1336                     <td>
1337                         <input type="text" name="add1" id="add1" value="[% add1 %]" />
1338                     </td>
1339                     <td>
1340                         <input type="text" name="add2" id="add2" value="[% add2 %]" />
1341                     </td>
1342                     <td>
1343                         <input type="text" name="add3" id="add3" value="[% add3 %]" />
1344                     </td>
1345                 </tr>
1346                 <tr>
1347                     <td>once every</td>
1348                     <td><input type="text" name="every1" id="every1" value="[% every1 %]" /></td>
1349                     <td><input type="text" name="every2" id="every2" value="[% every2 %]" /></td>
1350                     <td><input type="text" name="every3" id="every3" value="[% every3 %]" /></td>
1351                 </tr>
1352                 <tr>
1353                     <td>When more than</td>
1354                     <td><input type="text" name="whenmorethan1" id="whenmorethan1" value="[% whenmorethan1 %]" /></td>
1355                     <td><input type="text" name="whenmorethan2" id="whenmorethan2" value="[% whenmorethan2 %]" /></td>
1356                     <td><input type="text" name="whenmorethan3" id="whenmorethan3" value="[% whenmorethan3 %]" /></td>
1357                 </tr>
1358                 <tr>
1359                     <td>inner counter</td>
1360                     <td><input type="text" name="innerloop1" id="innerloop1" value="[% innerloop1 %]" /></td>
1361                     <td><input type="text" name="innerloop2" id="innerloop2" value="[% innerloop2 %]" /></td>
1362                     <td><input type="text" name="innerloop3" id="innerloop3" value="[% innerloop3 %]" /></td>
1363                 </tr>
1364                 <tr>
1365                     <td>Set back to</td>
1366                     <td><input type="text" name="setto1" id="setto1" value="[% setto1 %]" /></td>
1367                     <td><input type="text" name="setto2" id="setto2" value="[% setto2 %]" /></td>
1368                     <td><input type="text" name="setto3" id="setto3" value="[% setto3 %]" /></td>
1369                 </tr>
1370                 <tr>
1371                     <td>
1372                         [% IF ( modify ) %]
1373                             Last value
1374                         [% ELSE %]
1375                             Begins with
1376                         [% END %]
1377                     </td>
1378                     <td><input type="text" name="lastvalue1" id="lastvalue1" value="[% lastvalue1 %]" /></td>
1379                     <td><input type="text" name="lastvalue2" id="lastvalue2" value="[% lastvalue2 %]" /></td>
1380                     <td><input type="text" name="lastvalue3" id="lastvalue3" value="[% lastvalue3 %]" /></td>
1381                 </tr>
1382             </table>
1383         </div>
1384
1385 </div>
1386 </div>
1387 </form>
1388 </div>
1389
1390 </div>
1391
1392 [% INCLUDE 'intranet-bottom.inc' %]