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