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